[PATCH] D37662: [AST] Make RecursiveASTVisitor visit TemplateDecls in source order

Johannes Altmanninger via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 9 03:46:18 PDT 2017


johannes created this revision.

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.


https://reviews.llvm.org/D37662

Files:
  include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h
  include/clang/AST/RecursiveASTVisitor.h


Index: include/clang/AST/RecursiveASTVisitor.h
===================================================================
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -537,7 +537,6 @@
 
   bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
   bool PostVisitStmt(Stmt *S);
-  bool shouldTraverseTemplateArgumentsBeforeDecl() const { return false; }
 };
 
 template <typename Derived>
@@ -1691,13 +1690,8 @@
 // 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          \
Index: include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h
===================================================================
--- include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h
+++ include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h
@@ -111,8 +111,6 @@
     return true;
   }
 
-  bool shouldTraverseTemplateArgumentsBeforeDecl() const { return true; }
-
   Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); }
 
   SmallVector<Stmt *, 8> getStmtChildren(CXXOperatorCallExpr *CE) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37662.114481.patch
Type: text/x-patch
Size: 2144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170909/ce09e92b/attachment.bin>


More information about the cfe-commits mailing list