Add linkage attribute parsing support to alias declarations.

This commit is contained in:
Andrej Mitrovic 2014-02-11 13:22:37 +01:00
parent a5d7bf0956
commit a531013764
2 changed files with 15 additions and 2 deletions

View File

@ -346,8 +346,9 @@ class AliasDeclaration : ASTNode
public:
override void accept(ASTVisitor visitor)
{
mixin (visitIfNotNull!(type, name, initializers));
mixin (visitIfNotNull!(linkageAttribute, type, name, initializers));
}
/** */ LinkageAttribute linkageAttribute;
/** */ Type type;
/** */ Token name;
/** */ AliasInitializer[] initializers;

View File

@ -70,7 +70,7 @@ class Parser
*
* $(GRAMMAR $(RULEDEF aliasDeclaration):
* $(LITERAL 'alias') $(RULE aliasInitializer) $(LPAREN)$(LITERAL ',') $(RULE aliasInitializer)$(RPAREN)* $(LITERAL ';')
* | $(LITERAL 'alias') $(RULE type) $(LITERAL identifier) $(LITERAL ';')
* | $(LITERAL 'alias') $(RULE linkageAttribute)? $(RULE type) $(LITERAL identifier) $(LITERAL ';')
* ;)
*/
AliasDeclaration parseAliasDeclaration()
@ -78,6 +78,18 @@ class Parser
mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new AliasDeclaration;
if (expect(tok!"alias") is null) return null;
// 'alias extern(C) void function() f;' => supported in DMD and DScanner.
// 'alias f = extern(C) void function();' => not supported in both DMD and DScanner. See D Bugzilla 10471.
// 'alias extern void function() f;' => supported in DMD, not supported in DScanner since it's a storage class.
if (currentIs(tok!"extern"))
{
if (!peekIs(tok!"("))
error(`"(" expected for the linkage attribute`);
node.linkageAttribute = parseLinkageAttribute();
}
if (startsWith(tok!"identifier", tok!"="))
{
do