From 885d0d2ff563d0cc0a72ab471d5a8e34015f0485 Mon Sep 17 00:00:00 2001 From: Liran Zvibel Date: Mon, 26 May 2014 21:06:11 +0300 Subject: [PATCH 1/2] Add location information to ArgumentList, AtAttribute and ModuleDeclaration Amending previous commit --- std/d/ast.d | 6 ++++++ std/d/parser.d | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/std/d/ast.d b/std/d/ast.d index 8549aa0..8490f50 100644 --- a/std/d/ast.d +++ b/std/d/ast.d @@ -469,6 +469,8 @@ public: } mixin OpEquals; /** */ AssignExpression[] items; + /** */ size_t startLocation; + /** */ size_t endLocation; } /// @@ -745,6 +747,8 @@ public: /** */ FunctionCallExpression functionCallExpression; /** */ ArgumentList argumentList; /** */ Token identifier; + /** */ size_t startLocation; + /** */ size_t endLocation; mixin OpEquals; } @@ -1978,6 +1982,8 @@ public: mixin (visitIfNotNull!(moduleName)); } /** */ IdentifierChain moduleName; + /** */ size_t startLocation; + /** */ size_t endLocation; mixin OpEquals; } diff --git a/std/d/parser.d b/std/d/parser.d index ad47494..08da2e0 100644 --- a/std/d/parser.d +++ b/std/d/parser.d @@ -273,7 +273,11 @@ alias core.sys.posix.stdio.fileno fileno; ArgumentList parseArgumentList() { mixin(traceEnterAndExit!(__FUNCTION__)); - return parseCommaSeparatedRule!(ArgumentList, AssignExpression)(true); + size_t startLocation = current().index; + auto ret= parseCommaSeparatedRule!(ArgumentList, AssignExpression)(true); + ret.startLocation = startLocation; + ret.endLocation = current().index; + return ret; } /** @@ -717,7 +721,9 @@ alias core.sys.posix.stdio.fileno fileno; { mixin(traceEnterAndExit!(__FUNCTION__)); auto node = allocate!AtAttribute; - if (expect(tok!"@") is null) return null; + auto start = expect(tok!"@"); + if (start is null) return null; + node.startLocation = start.index; switch (current.type) { case tok!"identifier": @@ -735,6 +741,7 @@ alias core.sys.posix.stdio.fileno fileno; error(`"(", or identifier expected`); return null; } + node.endLocation = current().index; return node; } @@ -3601,9 +3608,11 @@ invariant() foo(); ModuleDeclaration parseModuleDeclaration() { auto node = allocate!ModuleDeclaration; - expect(tok!"module"); + auto start = expect(tok!"module"); node.moduleName = parseIdentifierChain(); - expect(tok!";"); + auto end = expect(tok!";"); + node.startLocation = start.index; + node.endLocation = end.index; return node; } From e99bf1f616b8d6beeec67a836d2838541214a8d2 Mon Sep 17 00:00:00 2001 From: Liran Zvibel Date: Mon, 26 May 2014 21:35:39 +0300 Subject: [PATCH 2/2] Add declaration attributes to the relevant FunctionAttributes object --- std/d/ast.d | 1 + std/d/parser.d | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/std/d/ast.d b/std/d/ast.d index 8490f50..94e0e1d 100644 --- a/std/d/ast.d +++ b/std/d/ast.d @@ -1531,6 +1531,7 @@ public: /** */ FunctionBody functionBody; /** */ MemberFunctionAttribute[] memberFunctionAttributes; /** */ string comment; + /** */ Attribute[] attributes; mixin OpEquals; } diff --git a/std/d/parser.d b/std/d/parser.d index 08da2e0..a3e99d9 100644 --- a/std/d/parser.d +++ b/std/d/parser.d @@ -1790,7 +1790,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c; if (peekIs(tok!"=")) node.variableDeclaration = parseVariableDeclaration(null, true); else if (peekIs(tok!"(")) - node.functionDeclaration = parseFunctionDeclaration(null, true); + node.functionDeclaration = parseFunctionDeclaration(null, true, node.attributes); else goto type; } @@ -1811,7 +1811,7 @@ class ClassFive(A, B) : Super if (someTest()) {}}c; return null; } if (peekIs(tok!"(")) - node.functionDeclaration = parseFunctionDeclaration(type); + node.functionDeclaration = parseFunctionDeclaration(type, false, node.attributes); else node.variableDeclaration = parseVariableDeclaration(type); break; @@ -2540,7 +2540,7 @@ body {} // six * ($(RULE storageClass) | $(RULE _type)) $(LITERAL Identifier) $(RULE templateParameters) $(RULE parameters) $(RULE memberFunctionAttribute)* $(RULE constraint)? ($(RULE functionBody) | $(LITERAL ';')) * ;) */ - FunctionDeclaration parseFunctionDeclaration(Type type = null, bool isAuto = false) + FunctionDeclaration parseFunctionDeclaration(Type type = null, bool isAuto = false, Attribute[] attributes = null) { mixin(traceEnterAndExit!(__FUNCTION__)); auto node = allocate!FunctionDeclaration; @@ -2548,6 +2548,8 @@ body {} // six comment = null; MemberFunctionAttribute[] memberFunctionAttributes; + node.attributes = attributes; + if (isAuto) goto functionName;