r198249 - Update DataRecursiveASTVisitor so that it visits attributes.

DeLesley Hutchins delesley at google.com
Mon Dec 30 13:03:02 PST 2013


Author: delesley
Date: Mon Dec 30 15:03:02 2013
New Revision: 198249

URL: http://llvm.org/viewvc/llvm-project?rev=198249&view=rev
Log:
Update DataRecursiveASTVisitor so that it visits attributes.

Modified:
    cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
    cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h?rev=198249&r1=198248&r2=198249&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h Mon Dec 30 15:03:02 2013
@@ -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<Derived>::T
 }
 
 
+// Define the Traverse*Attr(Attr* A) methods
+#define VISITORCLASS DataRecursiveASTVisitor
+#include "clang/AST/AttrVisitor.inc"
+#undef VISITORCLASS
+
 template<typename Derived>
 bool DataRecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
   if (!D)
@@ -566,10 +589,18 @@ bool DataRecursiveASTVisitor<Derived>::T
   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<CLASS##Decl*>(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;
 }
 

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=198249&r1=198248&r2=198249&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Dec 30 15:03:02 2013
@@ -642,7 +642,9 @@ bool RecursiveASTVisitor<Derived>::Trave
 
 
 // Define the Traverse*Attr(Attr* A) methods
+#define VISITORCLASS RecursiveASTVisitor
 #include "clang/AST/AttrVisitor.inc"
+#undef VISITORCLASS
 
 
 template<typename Derived>

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=198249&r1=198248&r2=198249&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Mon Dec 30 15:03:02 2013
@@ -1620,7 +1620,7 @@ void EmitClangAttrASTVisitor(RecordKeepe
       continue;
 
     OS << "template <typename Derived>\n"
-       << "bool RecursiveASTVisitor<Derived>::Traverse"
+       << "bool VISITORCLASS<Derived>::Traverse"
        << R.getName() << "Attr(" << R.getName() << "Attr *A) {\n"
        << "  if (!getDerived().VisitAttr(A))\n"
        << "    return false;\n"
@@ -1643,7 +1643,7 @@ void EmitClangAttrASTVisitor(RecordKeepe
 
   // Write generic Traverse routine
   OS << "template <typename Derived>\n"
-     << "bool RecursiveASTVisitor<Derived>::TraverseAttr(Attr *A) {\n"
+     << "bool VISITORCLASS<Derived>::TraverseAttr(Attr *A) {\n"
      << "  if (!A)\n"
      << "    return true;\n"
      << "\n"





More information about the cfe-commits mailing list