From 3798387c19ddf10b57502f1ba1f507815863e1c6 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Thu, 1 May 2014 15:22:13 -0700 Subject: [PATCH] Added destructors, constructors, and invariants to ctags output --- ctags.d | 25 +++++++++++++++++++ std/d/ast.d | 10 +++++--- std/d/parser.d | 67 +++++++++++++++++++++++++++----------------------- 3 files changed, 68 insertions(+), 34 deletions(-) diff --git a/ctags.d b/ctags.d index 330f5aa..97e99ea 100644 --- a/ctags.d +++ b/ctags.d @@ -90,6 +90,26 @@ class CTagsPrinter : ASTVisitor context = c; } + override void visit(const Constructor dec) + { + tagLines ~= "this\t%s\t%d;\"\tf\tarity:%d%s\n".format(fileName, + dec.line, dec.parameters.parameters.length, context); + auto c = context; + context = "\tfunction: this"; + dec.accept(this); + context = c; + } + + override void visit(const Destructor dec) + { + tagLines ~= "~this\t%s\t%d;\"\tf%s\n".format(fileName, dec.line, + context); + auto c = context; + context = "\tfunction: this"; + dec.accept(this); + context = c; + } + override void visit(const EnumDeclaration dec) { if (dec.name == tok!"") @@ -136,6 +156,11 @@ class CTagsPrinter : ASTVisitor dec.accept(this); } + override void visit(const Invariant dec) + { + tagLines ~= "invariant\t%s\t%d;\"\tv%s\n".format(fileName, dec.line, context); + } + alias visit = ASTVisitor.visit; string fileName; diff --git a/std/d/ast.d b/std/d/ast.d index 02c2134..25ac3dc 100644 --- a/std/d/ast.d +++ b/std/d/ast.d @@ -1239,7 +1239,9 @@ public: } /** */ MemberFunctionAttribute[] memberFunctionAttributes; /** */ FunctionBody functionBody; - /** */ size_t location; + /** */ size_t line; + /** */ size_t column; + /** */ size_t index; /** */ string comment; mixin OpEquals; } @@ -1780,6 +1782,8 @@ public: } /** */ BlockStatement blockStatement; /** */ string comment; + size_t line; + size_t index; mixin OpEquals; } @@ -1873,12 +1877,12 @@ final class LinkageAttribute : ASTNode public: override void accept(ASTVisitor visitor) const { - version (DIP61) mixin (visitIfNotNull!(identifier, identifierChain)); + version (DIP61) mixin (visitIfNotNull!(identifier, identifierChain)); else mixin (visitIfNotNull!(identifier)); } /** */ Token identifier; /** */ bool hasPlusPlus; - version (DIP61) /** */ IdentifierChain identifierChain; + version (DIP61) /** */ IdentifierChain identifierChain; mixin OpEquals; } diff --git a/std/d/parser.d b/std/d/parser.d index 952d20e..6169229 100644 --- a/std/d/parser.d +++ b/std/d/parser.d @@ -113,7 +113,7 @@ class Parser node.linkageAttribute = parseLinkageAttribute(); } warn("Prefer the new \"'alias' identifier '=' type ';'\" syntax" - ~ " to the old \"'alias' type identifier ';'\" syntax"); + ~ " to the old \"'alias' type identifier ';'\" syntax"); if ((node.type = parseType()) is null) return null; auto ident = expect(tok!"identifier"); if (ident is null) @@ -1976,20 +1976,23 @@ class ClassFour(A, B) if (someTest()) : Super {}}c; node.comment = comment; comment = null; if (expect(tok!"~") is null) return null; + node.index = current.index; + node.line = current.line; + node.column = current.column; if (expect(tok!"this") is null) return null; if (expect(tok!"(") is null) return null; if (expect(tok!")") is null) return null; if (currentIs(tok!";")) advance(); else - { - MemberFunctionAttribute[] memberFunctionAttributes; - while(moreTokens() && currentIsMemberFunctionAttribute()) - memberFunctionAttributes ~= parseMemberFunctionAttribute(); - node.memberFunctionAttributes = ownArray(memberFunctionAttributes); + { + MemberFunctionAttribute[] memberFunctionAttributes; + while(moreTokens() && currentIsMemberFunctionAttribute()) + memberFunctionAttributes ~= parseMemberFunctionAttribute(); + node.memberFunctionAttributes = ownArray(memberFunctionAttributes); - node.functionBody = parseFunctionBody(); - } + node.functionBody = parseFunctionBody(); + } return node; } @@ -3185,6 +3188,8 @@ interface "Four" Invariant parseInvariant() { auto node = allocate!Invariant; + node.index = current.index; + node.line = current.line; if (expect(tok!"invariant") is null) return null; if (currentIs(tok!"(")) { @@ -3414,11 +3419,11 @@ invariant() foo(); { advance(); node.hasPlusPlus = true; - version(DIP61) if (currentIs(tok!",")) - { - advance(); - node.identifierChain = parseIdentifierChain(); - } + version(DIP61) if (currentIs(tok!",")) + { + advance(); + node.identifierChain = parseIdentifierChain(); + } } expect(tok!")"); return node; @@ -4545,18 +4550,18 @@ q{(int a, ...) if (!currentIs(tok!"]")) { node.lower = parseAssignExpression(); - if (node.lower is null) - { - error("assignExpression expected"); - return null; - } + if (node.lower is null) + { + error("assignExpression expected"); + return null; + } expect(tok!".."); node.upper = parseAssignExpression(); - if (node.upper is null) - { - error("assignExpression expected"); - return null; - } + if (node.upper is null) + { + error("assignExpression expected"); + return null; + } } if (expect(tok!"]") is null) return null; return node; @@ -4810,13 +4815,13 @@ q{(int a, ...) mixin(traceEnterAndExit!(__FUNCTION__)); auto node = allocate!StructInitializer; expect(tok!"{"); - if (currentIs(tok!"}")) - advance(); - else - { - node.structMemberInitializers = parseStructMemberInitializers(); - expect(tok!"}"); - } + if (currentIs(tok!"}")) + advance(); + else + { + node.structMemberInitializers = parseStructMemberInitializers(); + expect(tok!"}"); + } return node; } @@ -6349,7 +6354,7 @@ protected: case tok!"abstract": case tok!"pure": case tok!"nothrow": - return true; + return true; mixin(BASIC_TYPE_CASES); return !peekIs(tok!"."); case tok!"case":