Author: krobelus Date: Mon Sep 11 06:12:30 2017 New Revision: 312911 URL: http://llvm.org/viewvc/llvm-project?rev=312911&view=rev Log: [AST] Make RecursiveASTVisitor visit TemplateDecls in source order
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 Modified: cfe/trunk/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Modified: cfe/trunk/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h?rev=312911&r1=312910&r2=312911&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h (original) +++ cfe/trunk/include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h Mon Sep 11 06:12:30 2017 @@ -111,8 +111,6 @@ public: return true; } - bool shouldTraverseTemplateArgumentsBeforeDecl() const { return true; } - Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); } SmallVector<Stmt *, 8> getStmtChildren(CXXOperatorCallExpr *CE) { Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=312911&r1=312910&r2=312911&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original) +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Sep 11 06:12:30 2017 @@ -537,7 +537,6 @@ private: bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue); bool PostVisitStmt(Stmt *S); - bool shouldTraverseTemplateArgumentsBeforeDecl() const { return false; } }; template <typename Derived> @@ -1691,13 +1690,8 @@ bool RecursiveASTVisitor<Derived>::Trave // 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 \ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits