Update DataRecursiveASTVisitor so that it visits attributes.

llvm-svn: 198249
This commit is contained in:
DeLesley Hutchins 2013-12-30 21:03:02 +00:00
parent 00b9b695c4
commit bb79c338ed
3 changed files with 38 additions and 5 deletions

View File

@ -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>::TraverseTypeLoc(TypeLoc TL) {
}
// 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>::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<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;
}

View File

@ -642,7 +642,9 @@ bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
// Define the Traverse*Attr(Attr* A) methods
#define VISITORCLASS RecursiveASTVisitor
#include "clang/AST/AttrVisitor.inc"
#undef VISITORCLASS
template<typename Derived>

View File

@ -1620,7 +1620,7 @@ void EmitClangAttrASTVisitor(RecordKeeper &Records, raw_ostream &OS) {
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(RecordKeeper &Records, raw_ostream &OS) {
// 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"