From bb79c338edc0abd2260ba7fdcb2d60ab16e473e4 Mon Sep 17 00:00:00 2001 From: DeLesley Hutchins Date: Mon, 30 Dec 2013 21:03:02 +0000 Subject: [PATCH] Update DataRecursiveASTVisitor so that it visits attributes. llvm-svn: 198249 --- clang/include/clang/AST/DataRecursiveASTVisitor.h | 37 +++++++++++++++++++++-- clang/include/clang/AST/RecursiveASTVisitor.h | 2 ++ clang/utils/TableGen/ClangAttrEmitter.cpp | 4 +-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/DataRecursiveASTVisitor.h b/clang/include/clang/AST/DataRecursiveASTVisitor.h index 3f4df50..229989f 100644 --- a/clang/include/clang/AST/DataRecursiveASTVisitor.h +++ b/clang/include/clang/AST/DataRecursiveASTVisitor.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_AST_DATARECURSIVEASTVISITOR_H #define LLVM_CLANG_AST_DATARECURSIVEASTVISITOR_H +#include "clang/AST/Attr.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclFriend.h" @@ -174,6 +175,13 @@ public: /// otherwise (including when the argument is a Null type location). bool TraverseTypeLoc(TypeLoc TL); + /// \brief Recursively visit an attribute, by dispatching to + /// Traverse*Attr() based on the argument's dynamic type. + /// + /// \returns false if the visitation was terminated early, true + /// otherwise (including when the argument is a Null type location). + bool TraverseAttr(Attr *At); + /// \brief Recursively visit a declaration, by dispatching to /// Traverse*Decl() based on the argument's dynamic type. /// @@ -237,7 +245,17 @@ public: /// /// \returns false if the visitation was terminated early, true otherwise. bool TraverseLambdaCapture(LambdaExpr::Capture C); - + + // ---- Methods on Attrs ---- + + // \brief Visit an attribute. + bool VisitAttr(Attr *A) { return true; } + + // Declare Traverse* and empty Visit* for all Attr classes. +#define ATTR_VISITOR_DECLS_ONLY +#include "clang/AST/AttrVisitor.inc" +#undef ATTR_VISITOR_DECLS_ONLY + // ---- Methods on Stmts ---- // Declare Traverse*() for all concrete Stmt classes. @@ -552,6 +570,11 @@ bool DataRecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { } +// Define the Traverse*Attr(Attr* A) methods +#define VISITORCLASS DataRecursiveASTVisitor +#include "clang/AST/AttrVisitor.inc" +#undef VISITORCLASS + template bool DataRecursiveASTVisitor::TraverseDecl(Decl *D) { if (!D) @@ -566,10 +589,18 @@ bool DataRecursiveASTVisitor::TraverseDecl(Decl *D) { switch (D->getKind()) { #define ABSTRACT_DECL(DECL) #define DECL(CLASS, BASE) \ - case Decl::CLASS: DISPATCH(CLASS##Decl, CLASS##Decl, D); + case Decl::CLASS: \ + if (!getDerived().Traverse##CLASS##Decl(static_cast(D))) \ + return false; \ + break; #include "clang/AST/DeclNodes.inc" - } + } + // Visit any attributes attached to this declaration. + for (Decl::attr_iterator I=D->attr_begin(), E=D->attr_end(); I != E; ++I) { + if (!getDerived().TraverseAttr(*I)) + return false; + } return true; } diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index aa15f9fc..1ccb58c 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -642,7 +642,9 @@ bool RecursiveASTVisitor::TraverseTypeLoc(TypeLoc TL) { // Define the Traverse*Attr(Attr* A) methods +#define VISITORCLASS RecursiveASTVisitor #include "clang/AST/AttrVisitor.inc" +#undef VISITORCLASS template diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index be4ae62..7d45d4b 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -1620,7 +1620,7 @@ void EmitClangAttrASTVisitor(RecordKeeper &Records, raw_ostream &OS) { continue; OS << "template \n" - << "bool RecursiveASTVisitor::Traverse" + << "bool VISITORCLASS::Traverse" << R.getName() << "Attr(" << R.getName() << "Attr *A) {\n" << " if (!getDerived().VisitAttr(A))\n" << " return false;\n" @@ -1643,7 +1643,7 @@ void EmitClangAttrASTVisitor(RecordKeeper &Records, raw_ostream &OS) { // Write generic Traverse routine OS << "template \n" - << "bool RecursiveASTVisitor::TraverseAttr(Attr *A) {\n" + << "bool VISITORCLASS::TraverseAttr(Attr *A) {\n" << " if (!A)\n" << " return true;\n" << "\n" -- 2.7.4