Skip to content

Commit

Permalink
Merge pull request #660 from 9rnsr/fix_function
Browse files Browse the repository at this point in the history
Fix grammar around function declaration
  • Loading branch information
9rnsr committed Sep 24, 2014
2 parents 26df94a + 60f040d commit eb5700c
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 130 deletions.
26 changes: 13 additions & 13 deletions class.dd
Expand Up @@ -199,7 +199,7 @@ $(H3 $(LNAME2 member-functions, Member Functions))
)

$(P Non-static member functions can have, in addition to the usual
$(GLINK2 declaration, FunctionAttribute)s, the attributes
$(GLINK2 function, FunctionAttribute)s, the attributes
$(D const), $(D immutable), $(D shared), or $(D inout).
These attributes apply to the hidden $(I this) parameter.
)
Expand Down Expand Up @@ -287,8 +287,8 @@ $(H3 $(LNAME2 constructors, Constructors))

$(GRAMMAR
$(GNAME Constructor):
$(D this) $(GLINK2 declaration, Parameters) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(D ;)
$(D this) $(GLINK2 declaration, Parameters) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
$(D this) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(D ;)
$(D this) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
$(GLINK2 template, ConstructorTemplate)
)

Expand Down Expand Up @@ -601,8 +601,8 @@ $(H3 $(LNAME2 destructors, Destructors))

$(GRAMMAR
$(GNAME Destructor):
$(D ~ this ( )) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(D ;)
$(D ~ this ( )) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
$(D ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(D ;)
$(D ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
)

The garbage collector calls the destructor function when the object
Expand Down Expand Up @@ -766,8 +766,8 @@ $(H3 Static Destructors)

$(GRAMMAR
$(GNAME StaticDestructor):
$(D static ~ this ( )) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(D ;)
$(D static ~ this ( )) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
$(D static ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(D ;)
$(D static ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
)

A static destructor is defined as a special static function with the
Expand Down Expand Up @@ -826,8 +826,8 @@ $(H3 Shared Static Destructors)

$(GRAMMAR
$(GNAME SharedStaticDestructor):
$(D shared static ~ this ( )) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(D ;)
$(D shared static ~ this ( )) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
$(D shared static ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(D ;)
$(D shared static ~ this ( )) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody)
)

$(P Shared static destructors are executed at program termination
Expand All @@ -851,8 +851,8 @@ $(H3 $(LNAME2 allocators, Class Allocators))
$(B Note): Class allocators are deprecated in D2.
$(GRAMMAR
$(GNAME Allocator):
$(D new) $(GLINK2 declaration, Parameters) $(D ;)
$(D new) $(GLINK2 declaration, Parameters) $(GLINK2 function, FunctionBody)
$(D new) $(GLINK2 function, Parameters) $(D ;)
$(D new) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionBody)
)

A class member function of the form:
Expand Down Expand Up @@ -930,8 +930,8 @@ assert(foo.x == int.init); // object is still accessible

$(GRAMMAR
$(GNAME Deallocator):
$(D delete) $(GLINK2 declaration, Parameters) $(D ;)
$(D delete) $(GLINK2 declaration, Parameters) $(GLINK2 function, FunctionBody)
$(D delete) $(GLINK2 function, Parameters) $(D ;)
$(D delete) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionBody)
)

A class member function of the form:
Expand Down
134 changes: 43 additions & 91 deletions declaration.dd
Expand Up @@ -4,17 +4,17 @@ $(SPEC_S Declarations,

$(GRAMMAR
$(GNAME Declaration):
$(GLINK2 function, FuncDeclaration)
$(GLINK VarDeclarations)
$(GLINK AliasDeclaration)
$(GLINK2 struct, AggregateDeclaration)
$(GLINK2 enum, EnumDeclaration)
$(GLINK2 module, ImportDeclaration)
$(GLINK Decl)
)

$(GRAMMAR
$(GNAME Decl):
$(GNAME VarDeclarations):
$(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK Declarators) $(D ;)
$(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK Declarator) $(GLINK2 function, FunctionBody)
$(GLINK AutoDeclaration)

$(GNAME Declarators):
Expand All @@ -33,6 +33,41 @@ $(GNAME DeclaratorIdentifier):
$(I Identifier)
$(I Identifier) $(GLINK2 template, TemplateParameters)$(OPT) $(D =) $(GLINK Initializer)

$(GNAME Declarator):
$(GLINK BasicType2)$(OPT) $(D $(LPAREN)) $(I Declarator) $(D $(RPAREN)) $(GLINK DeclaratorSuffixes)$(OPT)
$(GLINK BasicType2)$(OPT) $(I Identifier) $(GLINK DeclaratorSuffixes)$(OPT)

$(GNAME Declarator2):
$(GLINK BasicType2)$(OPT) $(GLINK DeclaratorSuffixes)$(OPT)
$(GLINK BasicType2)$(OPT) $(D $(LPAREN)) $(I Declarator2) $(D $(RPAREN)) $(GLINK DeclaratorSuffixes)$(OPT)

$(GNAME DeclaratorSuffixes):
$(GLINK DeclaratorSuffix)
$(GLINK DeclaratorSuffix) $(I DeclaratorSuffixes)

$(GNAME DeclaratorSuffix):
$(D [ ])
$(D [) $(VEXPRESSION) $(D ])
$(D [) $(GLINK Type) $(D ])
$(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT)
$(GLINK2 template, TemplateParameters) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 template, Constraint)$(OPT)
)

$(GRAMMAR
$(GNAME Type):
$(GLINK TypeCtors)$(OPT) $(GLINK BasicType)
$(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK Declarator2)

$(GNAME TypeCtors):
$(GLINK TypeCtor)
$(GLINK TypeCtor) $(I TypeCtors)

$(GNAME TypeCtor):
$(D const)
$(D immutable)
$(D inout)
$(D shared)

$(GNAME BasicType):
$(GLINK BasicTypeX)
$(D .) $(GLINK IdentifierList)
Expand Down Expand Up @@ -72,30 +107,17 @@ $(GNAME BasicType2):
$(D [) $(VEXPRESSION) $(D ])
$(D [) $(VEXPRESSION) .. $(VEXPRESSION) $(D ])
$(D [) $(GLINK Type) $(D ])
$(D delegate) $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT)
$(D function) $(GLINK Parameters) $(GLINK FunctionAttributes)$(OPT)

$(GNAME Declarator):
$(GLINK BasicType2)$(OPT) $(D $(LPAREN)) $(I Declarator) $(D $(RPAREN)) $(GLINK DeclaratorSuffixes)$(OPT)
$(GLINK BasicType2)$(OPT) $(I Identifier) $(GLINK DeclaratorSuffixes)$(OPT)

$(GNAME DeclaratorSuffixes):
$(GLINK DeclaratorSuffix)
$(GLINK DeclaratorSuffix) $(I DeclaratorSuffixes)

$(GNAME DeclaratorSuffix):
$(D [ ])
$(D [) $(VEXPRESSION) $(D ])
$(D [) $(GLINK Type) $(D ])
$(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT)
$(GLINK2 template, TemplateParameters) $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT) $(GLINK2 template, Constraint)$(OPT)
$(D delegate) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT)
$(D function) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT)

$(GNAME IdentifierList):
$(I Identifier)
$(I Identifier) $(D .) $(I IdentifierList)
$(GLINK2 template, TemplateInstance)
$(GLINK2 template, TemplateInstance) $(D .) $(I IdentifierList)
)

$(GRAMMAR
$(GNAME StorageClasses):
$(GLINK StorageClass)
$(GLINK StorageClass) $(I StorageClasses)
Expand All @@ -122,77 +144,6 @@ $(MULTICOLS 5, $(GLINK2 attribute, LinkageAttribute)
$(D nothrow)
$(D pure)
$(D ref))

$(GNAME TypeCtors):
$(GLINK TypeCtor)
$(GLINK TypeCtor) $(I TypeCtors)

$(GNAME TypeCtor):
$(D const)
$(D immutable)
$(D inout)
$(D shared)

$(GNAME Type):
$(GLINK TypeCtors)$(OPT) $(GLINK BasicType)
$(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK Declarator2)

$(GNAME Declarator2):
$(GLINK BasicType2)$(OPT) $(GLINK DeclaratorSuffixes)$(OPT)
$(GLINK BasicType2)$(OPT) $(D $(LPAREN)) $(I Declarator2) $(D $(RPAREN)) $(GLINK DeclaratorSuffixes)$(OPT)

$(GNAME Parameters):
$(D $(LPAREN)) $(GLINK ParameterList)$(OPT) $(D $(RPAREN))

$(GNAME ParameterList):
$(GLINK Parameter)
$(GLINK Parameter) $(D ,) $(I ParameterList)
$(D ...)

$(GNAME Parameter):
$(I InOut)$(OPT) $(GLINK BasicType) $(GLINK Declarator)
$(I InOut)$(OPT) $(GLINK BasicType) $(GLINK Declarator) $(D ...)
$(I InOut)$(OPT) $(GLINK BasicType) $(GLINK Declarator) = $(GLINK DefaultInitializerExpression)
$(I InOut)$(OPT) $(GLINK Type)
$(I InOut)$(OPT) $(GLINK Type) $(D ...)

$(GNAME InOut):
$(I InOutX)
$(I InOut InOutX)

$(GNAME InOutX):
$(D auto)
$(GLINK TypeCtor)
$(D final)
$(D in)
$(D lazy)
$(D out)
$(D ref)
$(D scope)

$(GNAME FunctionAttributes):
$(GLINK FunctionAttribute)
$(GLINK FunctionAttribute) $(I FunctionAttributes)

$(GNAME FunctionAttribute):
$(D nothrow)
$(D pure)
$(GLINK2 attribute, Property)

$(GNAME MemberFunctionAttributes):
$(GLINK MemberFunctionAttribute)
$(GLINK MemberFunctionAttribute) $(I MemberFunctionAttributes)

$(GNAME MemberFunctionAttribute):
$(D const)
$(D immutable)
$(D inout)
$(D shared)
$(GLINK FunctionAttribute)

$(GNAME DefaultInitializerExpression):
$(ASSIGNEXPRESSION)
$(GLINK2 traits, SpecialKeyword)
)

$(GRAMMAR
Expand Down Expand Up @@ -344,6 +295,7 @@ $(H3 $(LNAME2 alias, Alias Declarations))
$(GRAMMAR
$(GNAME AliasDeclaration):
$(D alias) $(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK Declarators)
$(D alias) $(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK FuncDeclarator)
$(D alias) $(I AliasDeclarationX) $(D ;)

$(GNAME AliasDeclarationX):
Expand Down
6 changes: 3 additions & 3 deletions expression.dd
Expand Up @@ -1293,8 +1293,8 @@ $(GNAME FunctionLiteral):
$(GLINK Lambda)

$(GNAME ParameterAttributes):
$(GLINK2 declaration, Parameters)
$(GLINK2 declaration, Parameters) $(GLINK2 declaration, FunctionAttributes)
$(GLINK2 function, Parameters)
$(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)

$(GNAME FunctionLiteralBody):
$(GLINK2 statement, BlockStatement)
Expand Down Expand Up @@ -1447,7 +1447,7 @@ $(GNAME Lambda):

$(OL
$(LI $(P Just one $(IDENTIFIER) is rewritten to
$(GLINK2 declaration, Parameters):)
$(GLINK2 function, Parameters):)

$(D $(LPAREN)) $(IDENTIFIER) $(D $(RPAREN))
)
Expand Down
76 changes: 74 additions & 2 deletions function.dd
Expand Up @@ -2,6 +2,77 @@ Ddoc

$(SPEC_S Functions,

$(GRAMMAR
$(GNAME FuncDeclaration):
$(GLINK2 declaration, StorageClasses)$(OPT) $(GLINK2 declaration, BasicType) $(GLINK FuncDeclarator) $(GLINK FunctionBody)
$(GLINK AutoFuncDeclaration)

$(GNAME AutoFuncDeclaration):
$(GLINK2 declaration, StorageClasses) $(I Identifier) $(GLINK FuncDeclaratorSuffix) $(GLINK FunctionBody)

$(GNAME FuncDeclarator):
$(GLINK2 declaration, BasicType2)$(OPT) $(I Identifier) $(GLINK FuncDeclaratorSuffix)

$(GNAME FuncDeclaratorSuffix):
$(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT)
$(GLINK2 template, TemplateParameters) $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT) $(GLINK2 template, Constraint)$(OPT)
)

$(GRAMMAR
$(GNAME Parameters):
$(D $(LPAREN)) $(GLINK ParameterList)$(OPT) $(D $(RPAREN))

$(GNAME ParameterList):
$(GLINK Parameter)
$(GLINK Parameter) $(D ,) $(I ParameterList)
$(D ...)

$(GNAME Parameter):
$(I InOut)$(OPT) $(GLINK2 declaration, BasicType) $(GLINK2 declaration, Declarator)
$(I InOut)$(OPT) $(GLINK2 declaration, BasicType) $(GLINK2 declaration, Declarator) $(D ...)
$(I InOut)$(OPT) $(GLINK2 declaration, BasicType) $(GLINK2 declaration, Declarator) = $(GLINK DefaultInitializerExpression)
$(I InOut)$(OPT) $(GLINK2 declaration, Type)
$(I InOut)$(OPT) $(GLINK2 declaration, Type) $(D ...)

$(GNAME InOut):
$(I InOutX)
$(I InOut InOutX)

$(GNAME InOutX):
$(D auto)
$(GLINK2 declaration, TypeCtor)
$(D final)
$(D in)
$(D lazy)
$(D out)
$(D ref)
$(D scope)

$(GNAME FunctionAttributes):
$(GLINK FunctionAttribute)
$(GLINK FunctionAttribute) $(I FunctionAttributes)

$(GNAME FunctionAttribute):
$(D nothrow)
$(D pure)
$(GLINK2 attribute, Property)

$(GNAME MemberFunctionAttributes):
$(GLINK MemberFunctionAttribute)
$(GLINK MemberFunctionAttribute) $(I MemberFunctionAttributes)

$(GNAME MemberFunctionAttribute):
$(D const)
$(D immutable)
$(D inout)
$(D shared)
$(GLINK FunctionAttribute)

$(GNAME DefaultInitializerExpression):
$(ASSIGNEXPRESSION)
$(GLINK2 traits, SpecialKeyword)
)

$(GRAMMAR
$(GNAME FunctionBody):
$(GLINK2 statement, BlockStatement)
Expand All @@ -27,7 +98,7 @@ $(H4 Contracts)

$(P The $(D in) and $(D out) blocks of a function declaration specify
the pre- and post-conditions of the function. They are used in $(LINK2
contracts, Contract Programming). The code inside these blocks should
contracts.html, Contract Programming). The code inside these blocks should
not have any side-effects, including modifying function parameters
and/or return values.
)
Expand Down Expand Up @@ -712,7 +783,7 @@ void test()
------

$(P If a derived class overrides a base class member function with diferrent
$(GLINK2 declaration, FunctionAttributes), the missing attributes will be
$(GLINK FunctionAttributes), the missing attributes will be
automatically compensated by the compiler.)

------
Expand Down Expand Up @@ -2162,3 +2233,4 @@ Macros:
TITLE=Functions
WIKI=Function
CATEGORY_SPEC=$0
ASSIGNEXPRESSION=$(GLINK2 expression, AssignExpression)

0 comments on commit eb5700c

Please sign in to comment.