Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ script. Running the tests on Windows is not currently supported.
* [Static array initialization syntax](http://dlang.org/arrays.html#static-init-static). This syntax is ambiguous because it looks like an associative array literal.
* [Class allocators](http://dlang.org/class.html#allocators). These are deprecated in D2.
* [Class deallocators](http://dlang.org/class.html#deallocators). These are deprecated in D2.
* C-style alias syntax. For example: ```alias int F1();```
5 changes: 4 additions & 1 deletion src/dparse/ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,17 @@ final class AliasDeclaration : ASTNode
public:
override void accept(ASTVisitor visitor) const
{
mixin (visitIfNotNull!(storageClasses, type, identifierList, initializers));
mixin (visitIfNotNull!(storageClasses, type, identifierList, initializers,
parameters, memberFunctionAttributes));
}
mixin OpEquals;
/** */ StorageClass[] storageClasses;
/** */ Type type;
/** */ IdentifierList identifierList;
/** */ AliasInitializer[] initializers;
/** */ string comment;
/** */ Parameters parameters;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forget to visit the parameters

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first PR to the parser. Thanks!! (added)

/** */ MemberFunctionAttribute[] memberFunctionAttributes;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forget to visit the memberFunctionAttributes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is fixed.

}

///
Expand Down
10 changes: 10 additions & 0 deletions src/dparse/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Parser
* $(GRAMMAR $(RULEDEF aliasDeclaration):
* $(LITERAL 'alias') $(RULE aliasInitializer) $(LPAREN)$(LITERAL ',') $(RULE aliasInitializer)$(RPAREN)* $(LITERAL ';')
* | $(LITERAL 'alias') $(RULE storageClass)* $(RULE type) $(RULE identifierList) $(LITERAL ';')
* | $(LITERAL 'alias') $(RULE storageClass)* $(RULE type) $(RULE identifier) $(LITERAL '(') $(RULE parameters) $(LITERAL ')') $(memberFunctionAttribute)* $(LITERAL ';')
* ;)
*/
AliasDeclaration parseAliasDeclaration()
Expand Down Expand Up @@ -108,6 +109,15 @@ class Parser
ownArray(node.storageClasses, storageClasses);
mixin (parseNodeQ!(`node.type`, `Type`));
mixin (parseNodeQ!(`node.identifierList`, `IdentifierList`));
if (currentIs(tok!"("))
{
mixin(parseNodeQ!(`node.parameters`, `Parameters`));
StackBuffer memberFunctionAttributes;
while (moreTokens() && currentIsMemberFunctionAttribute())
if (!memberFunctionAttributes.put(parseMemberFunctionAttribute()))
return null;
ownArray(node.memberFunctionAttributes, memberFunctionAttributes);
}
}
return attachCommentFromSemicolon(node);
}
Expand Down
41 changes: 41 additions & 0 deletions test/pass_files/aliases.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,44 @@ struct S
int a;
alias a this;
}

// C-style aliases
alias int GetterType() @property;
alias int SetterType(int) @property;
alias string SetterType(int, string) @nogc;
alias string SetterType(int, string) @safe;
alias int F1();
alias @property int F2();
alias string F3();
alias nothrow @trusted uint F4();
alias int F5(Object);
alias bool F6(Object);
alias int F1();
alias int F2() pure nothrow;
alias int F3() @safe;
alias int F23() @safe pure nothrow;

// return type covariance
alias long F4();
class C {}
class D : C {}
alias C F5();
alias D F6();
alias typeof(null) F7();
alias int[] F8();
alias int* F9();

// variadic type equality
alias int F10(int);
alias int F11(int...);
alias int F12(int, ...);

// linkage equality
alias extern(C) int F13(int);
alias extern(D) int F14(int);
alias extern(Windows) int F15(int);

// ref & @property equality
alias int F16(int);
alias ref int F17(int);
alias @property int F18(int);