Alias changes

This commit is contained in:
Hackerpilot 2013-08-15 01:00:38 +00:00
parent fc7784df35
commit bace5f0a76
2 changed files with 16 additions and 12 deletions

View File

@ -284,10 +284,10 @@ class AliasDeclaration : ASTNode
public: public:
void accept(ASTVisitor visitor) void accept(ASTVisitor visitor)
{ {
//mixin (visitIfNotNull!(type, declarator, initializers)); mixin (visitIfNotNull!(type, name, initializers));
} }
/** */ Type type; /** */ Type type;
/** */ Declarator declarator; /** */ Token name;
/** */ AliasInitializer[] initializers; /** */ AliasInitializer[] initializers;
} }
@ -297,10 +297,10 @@ class AliasInitializer : ASTNode
public: public:
override void accept(ASTVisitor visitor) override void accept(ASTVisitor visitor)
{ {
mixin (visitIfNotNull!(identifier, type)); mixin (visitIfNotNull!(name, type));
} }
/** */ Token identifier; /** */ Token name;
/** */ Type type; /** */ Type type;
} }
@ -1895,14 +1895,14 @@ public:
override string toString() override string toString()
{ {
if (vararg)
return "...";
string rVal; string rVal;
rVal ~= parameterAttributes.map!(x => " " ~ getTokenValue(x)).join();
if (type !is null) if (type !is null)
rVal = type.toString() ~ " "; rVal = type.toString();
if (vararg)
rVal ~= "...";
if (name.type != TokenType.invalid) if (name.type != TokenType.invalid)
rVal ~= name.value; rVal ~= " " ~ name.value;
rVal ~= parameterAttributes.map!(x => " " ~ getTokenValue(x)).join();
return rVal; return rVal;
} }

View File

@ -111,7 +111,8 @@ struct Parser
* Parses an AliasDeclaration. * Parses an AliasDeclaration.
* *
* $(GRAMMAR $(RULEDEF aliasDeclaration): * $(GRAMMAR $(RULEDEF aliasDeclaration):
* $(LITERAL 'alias') $(LPAREN)$(RULE aliasInitializer) $(LPAREN)$(LITERAL ',') $(RULE aliasInitializer)$(RPAREN)* | $(RULE type) $(RULE declarator)$(RPAREN) $(LITERAL ';') * $(LITERAL 'alias') $(RULE aliasInitializer) $(LPAREN)$(LITERAL ',') $(RULE aliasInitializer)$(RPAREN)*
* | $(LITERAL 'alias') $(RULE type) $(LITERAL identifier) $(LITERAL ';')
* ;) * ;)
*/ */
AliasDeclaration parseAliasDeclaration() AliasDeclaration parseAliasDeclaration()
@ -136,7 +137,10 @@ struct Parser
else else
{ {
if ((node.type = parseType()) is null) return null; if ((node.type = parseType()) is null) return null;
if ((node.declarator = parseDeclarator()) is null) return null; auto ident = expect(TokenType.identifier);
if (ident is null)
return null;
node.name = *ident;
} }
if (expect(TokenType.semicolon) is null) return null; if (expect(TokenType.semicolon) is null) return null;
return node; return node;
@ -170,7 +174,7 @@ alias core.sys.posix.stdio.fileno fileno;
auto node = new AliasInitializer; auto node = new AliasInitializer;
auto i = expect(TokenType.identifier); auto i = expect(TokenType.identifier);
if (i is null) return null; if (i is null) return null;
node.identifier = *i; node.name = *i;
if (expect(TokenType.assign) is null) return null; if (expect(TokenType.assign) is null) return null;
node.type = parseType(); node.type = parseType();
return node; return node;