diff --git a/class.dd b/class.dd index f1e4fdc95d..5e79f34e05 100644 --- a/class.dd +++ b/class.dd @@ -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. ) @@ -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) ) @@ -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 @@ -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 @@ -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 @@ -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: @@ -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: diff --git a/declaration.dd b/declaration.dd index b1f3cfd567..76a1f7a224 100644 --- a/declaration.dd +++ b/declaration.dd @@ -4,7 +4,7 @@ $(SPEC_S Declarations, $(GRAMMAR $(GNAME Declaration): - $(GLINK FuncDeclaration) + $(GLINK2 function, FuncDeclaration) $(GLINK VarDeclarations) $(GLINK AliasDeclaration) $(GLINK2 struct, AggregateDeclaration) @@ -13,16 +13,6 @@ $(GNAME Declaration): ) $(GRAMMAR -$(GNAME FuncDeclaration): - $(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK FuncDeclarator) $(GLINK2 function, FunctionBody) - -$(GNAME FuncDeclarator): - $(GLINK 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) - $(GNAME VarDeclarations): $(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK Declarators) $(D ;) $(GLINK AutoDeclaration) @@ -82,8 +72,8 @@ $(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) + $(D delegate) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) + $(D function) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT) $(GNAME Declarator): $(GLINK BasicType2)$(OPT) $(D $(LPAREN)) $(I Declarator) $(D $(RPAREN)) $(GLINK DeclaratorSuffixes)$(OPT) @@ -97,8 +87,8 @@ $(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) + $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) + $(GLINK2 template, TemplateParameters) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 template, Constraint)$(OPT) $(GNAME IdentifierList): $(I Identifier) @@ -150,59 +140,6 @@ $(GNAME Type): $(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 diff --git a/expression.dd b/expression.dd index addfea9104..986b050443 100644 --- a/expression.dd +++ b/expression.dd @@ -1295,8 +1295,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) @@ -1448,7 +1448,7 @@ $(GNAME Lambda): $(OL $(LI $(P Just one $(IDENTIFIER) is rewritten to - $(GLINK2 declaration, Parameters):) + $(GLINK2 function, Parameters):) $(D $(LPAREN)) $(IDENTIFIER) $(D $(RPAREN)) ) diff --git a/function.dd b/function.dd index f20bef7720..9449056482 100644 --- a/function.dd +++ b/function.dd @@ -2,6 +2,73 @@ Ddoc $(SPEC_S Functions, +$(GRAMMAR +$(GNAME FuncDeclaration): + $(GLINK2 declaration, StorageClasses)$(OPT) $(GLINK2 declaration, BasicType) $(GLINK FuncDeclarator) $(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) @@ -712,7 +779,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.) ------ @@ -2162,3 +2229,4 @@ Macros: TITLE=Functions WIKI=Function CATEGORY_SPEC=$0 + ASSIGNEXPRESSION=$(GLINK2 expression, AssignExpression) diff --git a/grammar.dd b/grammar.dd index 37d553442c..76817eed29 100644 --- a/grammar.dd +++ b/grammar.dd @@ -1004,16 +1004,6 @@ $(GNAME AutoDeclarationX): ) $(GRAMMAR -$(GNAME FuncDeclaration): - $(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK FuncDeclarator) $(GLINK FunctionBody) - -$(GNAME FuncDeclarator): - $(GLINK BasicType2)$(OPT) $(I Identifier) $(GLINK FuncDeclaratorSuffix) - -$(GNAME FuncDeclaratorSuffix): - $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT) - $(GLINK TemplateParameters) $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT) $(GLINK Constraint)$(OPT) - $(GNAME VarDeclarations): $(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK Declarators) $(D ;) $(GLINK AutoDeclaration) @@ -1083,7 +1073,6 @@ $(GNAME StorageClass): $(D ref) ) - $(GRAMMAR $(GNAME Initializer): $(GLINK VoidInitializer) @@ -1127,6 +1116,18 @@ $(GNAME StructMemberInitializer): $(H3 $(LNAME2 function, Function)) +$(GRAMMAR +$(GNAME FuncDeclaration): + $(GLINK StorageClasses)$(OPT) $(GLINK BasicType) $(GLINK FuncDeclarator) $(GLINK FunctionBody) + +$(GNAME FuncDeclarator): + $(GLINK BasicType2)$(OPT) $(I Identifier) $(GLINK FuncDeclaratorSuffix) + +$(GNAME FuncDeclaratorSuffix): + $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT) + $(GLINK TemplateParameters) $(GLINK Parameters) $(GLINK MemberFunctionAttributes)$(OPT) $(GLINK Constraint)$(OPT) +) + $(GRAMMAR $(GNAME Parameters): $(D $(LPAREN)) $(GLINK ParameterList)$(OPT) $(D $(RPAREN)) @@ -1176,9 +1177,7 @@ $(GNAME MemberFunctionAttribute): $(D inout) $(D shared) $(GLINK FunctionAttribute) -) -$(GRAMMAR $(GNAME DefaultInitializerExpression): $(ASSIGNEXPRESSION) $(GLINK SpecialKeyword) diff --git a/struct.dd b/struct.dd index 5f5ac81316..5d2007fbd9 100644 --- a/struct.dd +++ b/struct.dd @@ -418,8 +418,8 @@ $(SECTION3 $(LEGACY_LNAME2 StructPostblit, struct-postblit, Struct Postblits), $(GRAMMAR $(GNAME Postblit): - $(D this $(LPAREN) this $(RPAREN)) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(D ;) - $(D this $(LPAREN) this $(RPAREN)) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody) + $(D this $(LPAREN) this $(RPAREN)) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(D ;) + $(D this $(LPAREN) this $(RPAREN)) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK2 function, FunctionBody) ) $(P $(I Copy construction) is defined as initializing diff --git a/template.dd b/template.dd index 6c5c304896..4772ca6f9b 100644 --- a/template.dd +++ b/template.dd @@ -887,8 +887,8 @@ $(H2 Template Constructors) $(GRAMMAR $(GNAME ConstructorTemplate): - $(D this) $(GLINK2 template, TemplateParameters) $(GLINK2 declaration, Parameters) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(GLINK Constraint)$(OPT) $(D :) - $(D this) $(GLINK2 template, TemplateParameters) $(GLINK2 declaration, Parameters) $(GLINK2 declaration, MemberFunctionAttributes)$(OPT) $(GLINK Constraint)$(OPT) $(GLINK2 function, FunctionBody) + $(D this) $(GLINK2 template, TemplateParameters) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK Constraint)$(OPT) $(D :) + $(D this) $(GLINK2 template, TemplateParameters) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(GLINK Constraint)$(OPT) $(GLINK2 function, FunctionBody) ) $(P Templates can be used to form constructors for classes and structs. @@ -946,7 +946,7 @@ $(H2 $(LNAME2 function-templates, Function Templates)) with the same name as the template, it is a function template declaration. Alternatively, a function template declaration is a function declaration with a $(GLINK TemplateParameterList) immediately preceding the - $(GLINK2 declaration, Parameters). + $(GLINK2 function, Parameters). ) $(P A function template to compute the square of type $(I T) is: