From a5310137645f1173c70d98e0ce5733cca9e032b6 Mon Sep 17 00:00:00 2001 From: Andrej Mitrovic Date: Tue, 11 Feb 2014 13:22:37 +0100 Subject: [PATCH] Add linkage attribute parsing support to alias declarations. --- stdx/d/ast.d | 3 ++- stdx/d/parser.d | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/stdx/d/ast.d b/stdx/d/ast.d index 7dd5e26..b3b4b71 100644 --- a/stdx/d/ast.d +++ b/stdx/d/ast.d @@ -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; diff --git a/stdx/d/parser.d b/stdx/d/parser.d index ea93afc..0993a1f 100644 --- a/stdx/d/parser.d +++ b/stdx/d/parser.d @@ -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