Skip to content

Commit

Permalink
[AST] Make RecursiveASTVisitor visit TemplateDecls in source order
Browse files Browse the repository at this point in the history
Summary:
This causes template arguments to be traversed before the templated
declaration, which is useful for clients that expect the nodes in
the same order as they are in the source code. Additionally, there
seems to be no good reason not to do so.

This was moved here from LexicallyOrderedRecursiveASTVisitor. The tests
still reside in LexicallyOrderedRecursiveASTVisitorTest.cpp under
VisitTemplateDecls.

Reviewers: arphaman, rsmith, klimek

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D37662

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312911 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
krobelus committed Sep 11, 2017
1 parent 889a43b commit f592eb2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
2 changes: 0 additions & 2 deletions include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class LexicallyOrderedRecursiveASTVisitor
return true;
}

bool shouldTraverseTemplateArgumentsBeforeDecl() const { return true; }

Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); }

SmallVector<Stmt *, 8> getStmtChildren(CXXOperatorCallExpr *CE) {
Expand Down
10 changes: 2 additions & 8 deletions include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ template <typename Derived> class RecursiveASTVisitor {

bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
bool PostVisitStmt(Stmt *S);
bool shouldTraverseTemplateArgumentsBeforeDecl() const { return false; }
};

template <typename Derived>
Expand Down Expand Up @@ -1691,13 +1690,8 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
// template declarations.
#define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND) \
DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, { \
if (getDerived().shouldTraverseTemplateArgumentsBeforeDecl()) { \
TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \
TRY_TO(TraverseDecl(D->getTemplatedDecl())); \
} else { \
TRY_TO(TraverseDecl(D->getTemplatedDecl())); \
TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \
} \
TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \
TRY_TO(TraverseDecl(D->getTemplatedDecl())); \
\
/* By default, we do not traverse the instantiations of \
class templates since they do not appear in the user code. The \
Expand Down

0 comments on commit f592eb2

Please sign in to comment.