[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
This commit is contained in:
Argyrios Kyrtzidis 2016-11-01 04:29:39 +00:00
parent 9c729067e9
commit 4db30af1f8
1 changed files with 14 additions and 43 deletions

View File

@ -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<SyntacticFormIndexer> {
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<DesignatedInitExpr>(init))
visitSyntacticDesignatedInitExpr(DIE);
}
}
return visitForm(SemaForm);
}