From 4db30af1f85601a999fc4d84fc852cb0cbbec315 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 1 Nov 2016 04:29:39 +0000 Subject: [PATCH] [index] Avoid using a RecursiveASTVisitor for SyntacticFormIndexer and iterate the DesignatedInitExprs of the InitListExpr directly. This is more efficient, as per feedback by Richard. llvm-svn: 285666 --- clang/lib/Index/IndexBody.cpp | 57 +++++++++++-------------------------------- 1 file changed, 14 insertions(+), 43 deletions(-) diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp index a0e9131..3aa0152 100644 --- a/clang/lib/Index/IndexBody.cpp +++ b/clang/lib/Index/IndexBody.cpp @@ -294,48 +294,6 @@ public: // Also visit things that are in the syntactic form but not the semantic one, // for example the indices in DesignatedInitExprs. bool TraverseInitListExpr(InitListExpr *S, DataRecursionQueue *Q = nullptr) { - - class SyntacticFormIndexer : - public RecursiveASTVisitor { - IndexingContext &IndexCtx; - const NamedDecl *Parent; - const DeclContext *ParentDC; - bool Visited = false; - - public: - SyntacticFormIndexer(IndexingContext &indexCtx, - const NamedDecl *Parent, const DeclContext *DC) - : IndexCtx(indexCtx), Parent(Parent), ParentDC(DC) { } - - bool shouldWalkTypesOfTypeLocs() const { return false; } - - bool TraverseInitListExpr(InitListExpr *S, DataRecursionQueue *Q = nullptr) { - // Don't visit nested InitListExprs, this visitor will be called again - // later on for the nested ones. - if (Visited) - return true; - Visited = true; - InitListExpr *SyntaxForm = S->isSemanticForm() ? S->getSyntacticForm() : S; - if (SyntaxForm) { - for (Stmt *SubStmt : SyntaxForm->children()) { - if (!TraverseStmt(SubStmt, Q)) - return false; - } - } - return true; - } - - bool VisitDesignatedInitExpr(DesignatedInitExpr *E) { - for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) { - if (D.isFieldDesignator()) - return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), - Parent, ParentDC, SymbolRoleSet(), - {}, E); - } - return true; - } - }; - auto visitForm = [&](InitListExpr *Form) { for (Stmt *SubStmt : Form->children()) { if (!TraverseStmt(SubStmt, Q)) @@ -344,13 +302,26 @@ public: return true; }; + auto visitSyntacticDesignatedInitExpr = [&](DesignatedInitExpr *E) -> bool { + for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) { + if (D.isFieldDesignator()) + return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), + Parent, ParentDC, SymbolRoleSet(), + {}, E); + } + return true; + }; + InitListExpr *SemaForm = S->isSemanticForm() ? S : S->getSemanticForm(); InitListExpr *SyntaxForm = S->isSemanticForm() ? S->getSyntacticForm() : S; if (SemaForm) { // Visit things present in syntactic form but not the semantic form. if (SyntaxForm) { - SyntacticFormIndexer(IndexCtx, Parent, ParentDC).TraverseStmt(SyntaxForm); + for (Expr *init : SyntaxForm->inits()) { + if (auto *DIE = dyn_cast(init)) + visitSyntacticDesignatedInitExpr(DIE); + } } return visitForm(SemaForm); } -- 2.7.4