clang API Documentation

RecursiveASTVisitor.h
Go to the documentation of this file.
00001 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the RecursiveASTVisitor interface, which recursively
00011 //  traverses the entire AST.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
00015 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
00016 
00017 #include "clang/AST/Attr.h"
00018 #include "clang/AST/Decl.h"
00019 #include "clang/AST/DeclCXX.h"
00020 #include "clang/AST/DeclFriend.h"
00021 #include "clang/AST/DeclObjC.h"
00022 #include "clang/AST/DeclOpenMP.h"
00023 #include "clang/AST/DeclTemplate.h"
00024 #include "clang/AST/Expr.h"
00025 #include "clang/AST/ExprCXX.h"
00026 #include "clang/AST/ExprObjC.h"
00027 #include "clang/AST/NestedNameSpecifier.h"
00028 #include "clang/AST/Stmt.h"
00029 #include "clang/AST/StmtCXX.h"
00030 #include "clang/AST/StmtObjC.h"
00031 #include "clang/AST/StmtOpenMP.h"
00032 #include "clang/AST/TemplateBase.h"
00033 #include "clang/AST/TemplateName.h"
00034 #include "clang/AST/Type.h"
00035 #include "clang/AST/TypeLoc.h"
00036 
00037 // The following three macros are used for meta programming.  The code
00038 // using them is responsible for defining macro OPERATOR().
00039 
00040 // All unary operators.
00041 #define UNARYOP_LIST()                                                         \
00042   OPERATOR(PostInc) OPERATOR(PostDec) OPERATOR(PreInc) OPERATOR(PreDec)        \
00043       OPERATOR(AddrOf) OPERATOR(Deref) OPERATOR(Plus) OPERATOR(Minus)          \
00044       OPERATOR(Not) OPERATOR(LNot) OPERATOR(Real) OPERATOR(Imag)               \
00045       OPERATOR(Extension)
00046 
00047 // All binary operators (excluding compound assign operators).
00048 #define BINOP_LIST()                                                           \
00049   OPERATOR(PtrMemD) OPERATOR(PtrMemI) OPERATOR(Mul) OPERATOR(Div)              \
00050       OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) OPERATOR(Shr)    \
00051       OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) OPERATOR(GE) OPERATOR(EQ)         \
00052       OPERATOR(NE) OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) OPERATOR(LAnd)     \
00053       OPERATOR(LOr) OPERATOR(Assign) OPERATOR(Comma)
00054 
00055 // All compound assign operators.
00056 #define CAO_LIST()                                                             \
00057   OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub)        \
00058       OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor)
00059 
00060 namespace clang {
00061 
00062 // A helper macro to implement short-circuiting when recursing.  It
00063 // invokes CALL_EXPR, which must be a method call, on the derived
00064 // object (s.t. a user of RecursiveASTVisitor can override the method
00065 // in CALL_EXPR).
00066 #define TRY_TO(CALL_EXPR)                                                      \
00067   do {                                                                         \
00068     if (!getDerived().CALL_EXPR)                                               \
00069       return false;                                                            \
00070   } while (0)
00071 
00072 /// \brief A class that does preorder depth-first traversal on the
00073 /// entire Clang AST and visits each node.
00074 ///
00075 /// This class performs three distinct tasks:
00076 ///   1. traverse the AST (i.e. go to each node);
00077 ///   2. at a given node, walk up the class hierarchy, starting from
00078 ///      the node's dynamic type, until the top-most class (e.g. Stmt,
00079 ///      Decl, or Type) is reached.
00080 ///   3. given a (node, class) combination, where 'class' is some base
00081 ///      class of the dynamic type of 'node', call a user-overridable
00082 ///      function to actually visit the node.
00083 ///
00084 /// These tasks are done by three groups of methods, respectively:
00085 ///   1. TraverseDecl(Decl *x) does task #1.  It is the entry point
00086 ///      for traversing an AST rooted at x.  This method simply
00087 ///      dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
00088 ///      is the dynamic type of *x, which calls WalkUpFromFoo(x) and
00089 ///      then recursively visits the child nodes of x.
00090 ///      TraverseStmt(Stmt *x) and TraverseType(QualType x) work
00091 ///      similarly.
00092 ///   2. WalkUpFromFoo(Foo *x) does task #2.  It does not try to visit
00093 ///      any child node of x.  Instead, it first calls WalkUpFromBar(x)
00094 ///      where Bar is the direct parent class of Foo (unless Foo has
00095 ///      no parent), and then calls VisitFoo(x) (see the next list item).
00096 ///   3. VisitFoo(Foo *x) does task #3.
00097 ///
00098 /// These three method groups are tiered (Traverse* > WalkUpFrom* >
00099 /// Visit*).  A method (e.g. Traverse*) may call methods from the same
00100 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
00101 /// It may not call methods from a higher tier.
00102 ///
00103 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
00104 /// is Foo's super class) before calling VisitFoo(), the result is
00105 /// that the Visit*() methods for a given node are called in the
00106 /// top-down order (e.g. for a node of type NamespaceDecl, the order will
00107 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
00108 ///
00109 /// This scheme guarantees that all Visit*() calls for the same AST
00110 /// node are grouped together.  In other words, Visit*() methods for
00111 /// different nodes are never interleaved.
00112 ///
00113 /// Clients of this visitor should subclass the visitor (providing
00114 /// themselves as the template argument, using the curiously recurring
00115 /// template pattern) and override any of the Traverse*, WalkUpFrom*,
00116 /// and Visit* methods for declarations, types, statements,
00117 /// expressions, or other AST nodes where the visitor should customize
00118 /// behavior.  Most users only need to override Visit*.  Advanced
00119 /// users may override Traverse* and WalkUpFrom* to implement custom
00120 /// traversal strategies.  Returning false from one of these overridden
00121 /// functions will abort the entire traversal.
00122 ///
00123 /// By default, this visitor tries to visit every part of the explicit
00124 /// source code exactly once.  The default policy towards templates
00125 /// is to descend into the 'pattern' class or function body, not any
00126 /// explicit or implicit instantiations.  Explicit specializations
00127 /// are still visited, and the patterns of partial specializations
00128 /// are visited separately.  This behavior can be changed by
00129 /// overriding shouldVisitTemplateInstantiations() in the derived class
00130 /// to return true, in which case all known implicit and explicit
00131 /// instantiations will be visited at the same time as the pattern
00132 /// from which they were produced.
00133 template <typename Derived> class RecursiveASTVisitor {
00134 public:
00135   /// \brief Return a reference to the derived class.
00136   Derived &getDerived() { return *static_cast<Derived *>(this); }
00137 
00138   /// \brief Return whether this visitor should recurse into
00139   /// template instantiations.
00140   bool shouldVisitTemplateInstantiations() const { return false; }
00141 
00142   /// \brief Return whether this visitor should recurse into the types of
00143   /// TypeLocs.
00144   bool shouldWalkTypesOfTypeLocs() const { return true; }
00145 
00146   /// \brief Return whether this visitor should recurse into implicit
00147   /// code, e.g., implicit constructors and destructors.
00148   bool shouldVisitImplicitCode() const { return false; }
00149 
00150   /// \brief Return whether \param S should be traversed using data recursion
00151   /// to avoid a stack overflow with extreme cases.
00152   bool shouldUseDataRecursionFor(Stmt *S) const {
00153     return isa<BinaryOperator>(S) || isa<UnaryOperator>(S) ||
00154            isa<CaseStmt>(S) || isa<CXXOperatorCallExpr>(S);
00155   }
00156 
00157   /// \brief Recursively visit a statement or expression, by
00158   /// dispatching to Traverse*() based on the argument's dynamic type.
00159   ///
00160   /// \returns false if the visitation was terminated early, true
00161   /// otherwise (including when the argument is NULL).
00162   bool TraverseStmt(Stmt *S);
00163 
00164   /// \brief Recursively visit a type, by dispatching to
00165   /// Traverse*Type() based on the argument's getTypeClass() property.
00166   ///
00167   /// \returns false if the visitation was terminated early, true
00168   /// otherwise (including when the argument is a Null type).
00169   bool TraverseType(QualType T);
00170 
00171   /// \brief Recursively visit a type with location, by dispatching to
00172   /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
00173   ///
00174   /// \returns false if the visitation was terminated early, true
00175   /// otherwise (including when the argument is a Null type location).
00176   bool TraverseTypeLoc(TypeLoc TL);
00177 
00178   /// \brief Recursively visit an attribute, by dispatching to
00179   /// Traverse*Attr() based on the argument's dynamic type.
00180   ///
00181   /// \returns false if the visitation was terminated early, true
00182   /// otherwise (including when the argument is a Null type location).
00183   bool TraverseAttr(Attr *At);
00184 
00185   /// \brief Recursively visit a declaration, by dispatching to
00186   /// Traverse*Decl() based on the argument's dynamic type.
00187   ///
00188   /// \returns false if the visitation was terminated early, true
00189   /// otherwise (including when the argument is NULL).
00190   bool TraverseDecl(Decl *D);
00191 
00192   /// \brief Recursively visit a C++ nested-name-specifier.
00193   ///
00194   /// \returns false if the visitation was terminated early, true otherwise.
00195   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
00196 
00197   /// \brief Recursively visit a C++ nested-name-specifier with location
00198   /// information.
00199   ///
00200   /// \returns false if the visitation was terminated early, true otherwise.
00201   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
00202 
00203   /// \brief Recursively visit a name with its location information.
00204   ///
00205   /// \returns false if the visitation was terminated early, true otherwise.
00206   bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
00207 
00208   /// \brief Recursively visit a template name and dispatch to the
00209   /// appropriate method.
00210   ///
00211   /// \returns false if the visitation was terminated early, true otherwise.
00212   bool TraverseTemplateName(TemplateName Template);
00213 
00214   /// \brief Recursively visit a template argument and dispatch to the
00215   /// appropriate method for the argument type.
00216   ///
00217   /// \returns false if the visitation was terminated early, true otherwise.
00218   // FIXME: migrate callers to TemplateArgumentLoc instead.
00219   bool TraverseTemplateArgument(const TemplateArgument &Arg);
00220 
00221   /// \brief Recursively visit a template argument location and dispatch to the
00222   /// appropriate method for the argument type.
00223   ///
00224   /// \returns false if the visitation was terminated early, true otherwise.
00225   bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
00226 
00227   /// \brief Recursively visit a set of template arguments.
00228   /// This can be overridden by a subclass, but it's not expected that
00229   /// will be needed -- this visitor always dispatches to another.
00230   ///
00231   /// \returns false if the visitation was terminated early, true otherwise.
00232   // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
00233   bool TraverseTemplateArguments(const TemplateArgument *Args,
00234                                  unsigned NumArgs);
00235 
00236   /// \brief Recursively visit a constructor initializer.  This
00237   /// automatically dispatches to another visitor for the initializer
00238   /// expression, but not for the name of the initializer, so may
00239   /// be overridden for clients that need access to the name.
00240   ///
00241   /// \returns false if the visitation was terminated early, true otherwise.
00242   bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
00243 
00244   /// \brief Recursively visit a lambda capture.
00245   ///
00246   /// \returns false if the visitation was terminated early, true otherwise.
00247   bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C);
00248 
00249   /// \brief Recursively visit the body of a lambda expression.
00250   ///
00251   /// This provides a hook for visitors that need more context when visiting
00252   /// \c LE->getBody().
00253   ///
00254   /// \returns false if the visitation was terminated early, true otherwise.
00255   bool TraverseLambdaBody(LambdaExpr *LE);
00256 
00257   // ---- Methods on Attrs ----
00258 
00259   // \brief Visit an attribute.
00260   bool VisitAttr(Attr *A) { return true; }
00261 
00262 // Declare Traverse* and empty Visit* for all Attr classes.
00263 #define ATTR_VISITOR_DECLS_ONLY
00264 #include "clang/AST/AttrVisitor.inc"
00265 #undef ATTR_VISITOR_DECLS_ONLY
00266 
00267 // ---- Methods on Stmts ----
00268 
00269 // Declare Traverse*() for all concrete Stmt classes.
00270 #define ABSTRACT_STMT(STMT)
00271 #define STMT(CLASS, PARENT) bool Traverse##CLASS(CLASS *S);
00272 #include "clang/AST/StmtNodes.inc"
00273   // The above header #undefs ABSTRACT_STMT and STMT upon exit.
00274 
00275   // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
00276   bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
00277   bool VisitStmt(Stmt *S) { return true; }
00278 #define STMT(CLASS, PARENT)                                                    \
00279   bool WalkUpFrom##CLASS(CLASS *S) {                                           \
00280     TRY_TO(WalkUpFrom##PARENT(S));                                             \
00281     TRY_TO(Visit##CLASS(S));                                                   \
00282     return true;                                                               \
00283   }                                                                            \
00284   bool Visit##CLASS(CLASS *S) { return true; }
00285 #include "clang/AST/StmtNodes.inc"
00286 
00287 // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
00288 // operator methods.  Unary operators are not classes in themselves
00289 // (they're all opcodes in UnaryOperator) but do have visitors.
00290 #define OPERATOR(NAME)                                                         \
00291   bool TraverseUnary##NAME(UnaryOperator *S) {                                 \
00292     TRY_TO(WalkUpFromUnary##NAME(S));                                          \
00293     TRY_TO(TraverseStmt(S->getSubExpr()));                                     \
00294     return true;                                                               \
00295   }                                                                            \
00296   bool WalkUpFromUnary##NAME(UnaryOperator *S) {                               \
00297     TRY_TO(WalkUpFromUnaryOperator(S));                                        \
00298     TRY_TO(VisitUnary##NAME(S));                                               \
00299     return true;                                                               \
00300   }                                                                            \
00301   bool VisitUnary##NAME(UnaryOperator *S) { return true; }
00302 
00303   UNARYOP_LIST()
00304 #undef OPERATOR
00305 
00306 // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
00307 // operator methods.  Binary operators are not classes in themselves
00308 // (they're all opcodes in BinaryOperator) but do have visitors.
00309 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE)                               \
00310   bool TraverseBin##NAME(BINOP_TYPE *S) {                                      \
00311     TRY_TO(WalkUpFromBin##NAME(S));                                            \
00312     TRY_TO(TraverseStmt(S->getLHS()));                                         \
00313     TRY_TO(TraverseStmt(S->getRHS()));                                         \
00314     return true;                                                               \
00315   }                                                                            \
00316   bool WalkUpFromBin##NAME(BINOP_TYPE *S) {                                    \
00317     TRY_TO(WalkUpFrom##BINOP_TYPE(S));                                         \
00318     TRY_TO(VisitBin##NAME(S));                                                 \
00319     return true;                                                               \
00320   }                                                                            \
00321   bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
00322 
00323 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
00324   BINOP_LIST()
00325 #undef OPERATOR
00326 
00327 // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
00328 // assignment methods.  Compound assignment operators are not
00329 // classes in themselves (they're all opcodes in
00330 // CompoundAssignOperator) but do have visitors.
00331 #define OPERATOR(NAME)                                                         \
00332   GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
00333 
00334   CAO_LIST()
00335 #undef OPERATOR
00336 #undef GENERAL_BINOP_FALLBACK
00337 
00338 // ---- Methods on Types ----
00339 // FIXME: revamp to take TypeLoc's rather than Types.
00340 
00341 // Declare Traverse*() for all concrete Type classes.
00342 #define ABSTRACT_TYPE(CLASS, BASE)
00343 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
00344 #include "clang/AST/TypeNodes.def"
00345   // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
00346 
00347   // Define WalkUpFrom*() and empty Visit*() for all Type classes.
00348   bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
00349   bool VisitType(Type *T) { return true; }
00350 #define TYPE(CLASS, BASE)                                                      \
00351   bool WalkUpFrom##CLASS##Type(CLASS##Type *T) {                               \
00352     TRY_TO(WalkUpFrom##BASE(T));                                               \
00353     TRY_TO(Visit##CLASS##Type(T));                                             \
00354     return true;                                                               \
00355   }                                                                            \
00356   bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
00357 #include "clang/AST/TypeNodes.def"
00358 
00359 // ---- Methods on TypeLocs ----
00360 // FIXME: this currently just calls the matching Type methods
00361 
00362 // Declare Traverse*() for all concrete TypeLoc classes.
00363 #define ABSTRACT_TYPELOC(CLASS, BASE)
00364 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
00365 #include "clang/AST/TypeLocNodes.def"
00366   // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
00367 
00368   // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
00369   bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
00370   bool VisitTypeLoc(TypeLoc TL) { return true; }
00371 
00372   // QualifiedTypeLoc and UnqualTypeLoc are not declared in
00373   // TypeNodes.def and thus need to be handled specially.
00374   bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
00375     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
00376   }
00377   bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
00378   bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
00379     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
00380   }
00381   bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
00382 
00383 // Note that BASE includes trailing 'Type' which CLASS doesn't.
00384 #define TYPE(CLASS, BASE)                                                      \
00385   bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) {                         \
00386     TRY_TO(WalkUpFrom##BASE##Loc(TL));                                         \
00387     TRY_TO(Visit##CLASS##TypeLoc(TL));                                         \
00388     return true;                                                               \
00389   }                                                                            \
00390   bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
00391 #include "clang/AST/TypeNodes.def"
00392 
00393 // ---- Methods on Decls ----
00394 
00395 // Declare Traverse*() for all concrete Decl classes.
00396 #define ABSTRACT_DECL(DECL)
00397 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
00398 #include "clang/AST/DeclNodes.inc"
00399   // The above header #undefs ABSTRACT_DECL and DECL upon exit.
00400 
00401   // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
00402   bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
00403   bool VisitDecl(Decl *D) { return true; }
00404 #define DECL(CLASS, BASE)                                                      \
00405   bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) {                               \
00406     TRY_TO(WalkUpFrom##BASE(D));                                               \
00407     TRY_TO(Visit##CLASS##Decl(D));                                             \
00408     return true;                                                               \
00409   }                                                                            \
00410   bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
00411 #include "clang/AST/DeclNodes.inc"
00412 
00413 private:
00414   // These are helper methods used by more than one Traverse* method.
00415   bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
00416 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND)                                   \
00417   bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
00418   DEF_TRAVERSE_TMPL_INST(Class)
00419   DEF_TRAVERSE_TMPL_INST(Var)
00420   DEF_TRAVERSE_TMPL_INST(Function)
00421 #undef DEF_TRAVERSE_TMPL_INST
00422   bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
00423                                           unsigned Count);
00424   bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
00425   bool TraverseRecordHelper(RecordDecl *D);
00426   bool TraverseCXXRecordHelper(CXXRecordDecl *D);
00427   bool TraverseDeclaratorHelper(DeclaratorDecl *D);
00428   bool TraverseDeclContextHelper(DeclContext *DC);
00429   bool TraverseFunctionHelper(FunctionDecl *D);
00430   bool TraverseVarHelper(VarDecl *D);
00431   bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
00432   bool TraverseOMPLoopDirective(OMPLoopDirective *S);
00433   bool TraverseOMPClause(OMPClause *C);
00434 #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C);
00435 #include "clang/Basic/OpenMPKinds.def"
00436   /// \brief Process clauses with list of variables.
00437   template <typename T> bool VisitOMPClauseList(T *Node);
00438 
00439   struct EnqueueJob {
00440     Stmt *S;
00441     Stmt::child_iterator StmtIt;
00442 
00443     EnqueueJob(Stmt *S) : S(S), StmtIt() {}
00444   };
00445   bool dataTraverse(Stmt *S);
00446   bool dataTraverseNode(Stmt *S, bool &EnqueueChildren);
00447 };
00448 
00449 template <typename Derived>
00450 bool RecursiveASTVisitor<Derived>::dataTraverse(Stmt *S) {
00451 
00452   SmallVector<EnqueueJob, 16> Queue;
00453   Queue.push_back(S);
00454 
00455   while (!Queue.empty()) {
00456     EnqueueJob &job = Queue.back();
00457     Stmt *CurrS = job.S;
00458     if (!CurrS) {
00459       Queue.pop_back();
00460       continue;
00461     }
00462 
00463     if (getDerived().shouldUseDataRecursionFor(CurrS)) {
00464       if (job.StmtIt == Stmt::child_iterator()) {
00465         bool EnqueueChildren = true;
00466         if (!dataTraverseNode(CurrS, EnqueueChildren))
00467           return false;
00468         if (!EnqueueChildren) {
00469           Queue.pop_back();
00470           continue;
00471         }
00472         job.StmtIt = CurrS->child_begin();
00473       } else {
00474         ++job.StmtIt;
00475       }
00476 
00477       if (job.StmtIt != CurrS->child_end())
00478         Queue.push_back(*job.StmtIt);
00479       else
00480         Queue.pop_back();
00481       continue;
00482     }
00483 
00484     Queue.pop_back();
00485     TRY_TO(TraverseStmt(CurrS));
00486   }
00487 
00488   return true;
00489 }
00490 
00491 template <typename Derived>
00492 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
00493                                                     bool &EnqueueChildren) {
00494 
00495 // Dispatch to the corresponding WalkUpFrom* function only if the derived
00496 // class didn't override Traverse* (and thus the traversal is trivial).
00497 #define DISPATCH_WALK(NAME, CLASS, VAR)                                        \
00498   {                                                                            \
00499     bool (Derived::*DerivedFn)(CLASS *) = &Derived::Traverse##NAME;            \
00500     bool (Derived::*BaseFn)(CLASS *) = &RecursiveASTVisitor::Traverse##NAME;   \
00501     if (DerivedFn == BaseFn)                                                   \
00502       return getDerived().WalkUpFrom##NAME(static_cast<CLASS *>(VAR));         \
00503   }                                                                            \
00504   EnqueueChildren = false;                                                     \
00505   return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR));
00506 
00507   if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
00508     switch (BinOp->getOpcode()) {
00509 #define OPERATOR(NAME)                                                         \
00510   case BO_##NAME:                                                              \
00511     DISPATCH_WALK(Bin##NAME, BinaryOperator, S);
00512 
00513       BINOP_LIST()
00514 #undef OPERATOR
00515 
00516 #define OPERATOR(NAME)                                                         \
00517   case BO_##NAME##Assign:                                                      \
00518     DISPATCH_WALK(Bin##NAME##Assign, CompoundAssignOperator, S);
00519 
00520       CAO_LIST()
00521 #undef OPERATOR
00522     }
00523   } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
00524     switch (UnOp->getOpcode()) {
00525 #define OPERATOR(NAME)                                                         \
00526   case UO_##NAME:                                                              \
00527     DISPATCH_WALK(Unary##NAME, UnaryOperator, S);
00528 
00529       UNARYOP_LIST()
00530 #undef OPERATOR
00531     }
00532   }
00533 
00534   // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
00535   switch (S->getStmtClass()) {
00536   case Stmt::NoStmtClass:
00537     break;
00538 #define ABSTRACT_STMT(STMT)
00539 #define STMT(CLASS, PARENT)                                                    \
00540   case Stmt::CLASS##Class:                                                     \
00541     DISPATCH_WALK(CLASS, CLASS, S);
00542 #include "clang/AST/StmtNodes.inc"
00543   }
00544 
00545 #undef DISPATCH_WALK
00546 
00547   return true;
00548 }
00549 
00550 #define DISPATCH(NAME, CLASS, VAR)                                             \
00551   return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))
00552 
00553 template <typename Derived>
00554 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S) {
00555   if (!S)
00556     return true;
00557 
00558 #define DISPATCH_STMT(NAME, CLASS, VAR) DISPATCH(NAME, CLASS, VAR)
00559 
00560   if (getDerived().shouldUseDataRecursionFor(S))
00561     return dataTraverse(S);
00562 
00563   // If we have a binary expr, dispatch to the subcode of the binop.  A smart
00564   // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
00565   // below.
00566   if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
00567     switch (BinOp->getOpcode()) {
00568 #define OPERATOR(NAME)                                                         \
00569   case BO_##NAME:                                                              \
00570     DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
00571 
00572       BINOP_LIST()
00573 #undef OPERATOR
00574 #undef BINOP_LIST
00575 
00576 #define OPERATOR(NAME)                                                         \
00577   case BO_##NAME##Assign:                                                      \
00578     DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
00579 
00580       CAO_LIST()
00581 #undef OPERATOR
00582 #undef CAO_LIST
00583     }
00584   } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
00585     switch (UnOp->getOpcode()) {
00586 #define OPERATOR(NAME)                                                         \
00587   case UO_##NAME:                                                              \
00588     DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
00589 
00590       UNARYOP_LIST()
00591 #undef OPERATOR
00592 #undef UNARYOP_LIST
00593     }
00594   }
00595 
00596   // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
00597   switch (S->getStmtClass()) {
00598   case Stmt::NoStmtClass:
00599     break;
00600 #define ABSTRACT_STMT(STMT)
00601 #define STMT(CLASS, PARENT)                                                    \
00602   case Stmt::CLASS##Class:                                                     \
00603     DISPATCH_STMT(CLASS, CLASS, S);
00604 #include "clang/AST/StmtNodes.inc"
00605   }
00606 
00607   return true;
00608 }
00609 
00610 #undef DISPATCH_STMT
00611 
00612 template <typename Derived>
00613 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
00614   if (T.isNull())
00615     return true;
00616 
00617   switch (T->getTypeClass()) {
00618 #define ABSTRACT_TYPE(CLASS, BASE)
00619 #define TYPE(CLASS, BASE)                                                      \
00620   case Type::CLASS:                                                            \
00621     DISPATCH(CLASS##Type, CLASS##Type, const_cast<Type *>(T.getTypePtr()));
00622 #include "clang/AST/TypeNodes.def"
00623   }
00624 
00625   return true;
00626 }
00627 
00628 template <typename Derived>
00629 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
00630   if (TL.isNull())
00631     return true;
00632 
00633   switch (TL.getTypeLocClass()) {
00634 #define ABSTRACT_TYPELOC(CLASS, BASE)
00635 #define TYPELOC(CLASS, BASE)                                                   \
00636   case TypeLoc::CLASS:                                                         \
00637     return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
00638 #include "clang/AST/TypeLocNodes.def"
00639   }
00640 
00641   return true;
00642 }
00643 
00644 // Define the Traverse*Attr(Attr* A) methods
00645 #define VISITORCLASS RecursiveASTVisitor
00646 #include "clang/AST/AttrVisitor.inc"
00647 #undef VISITORCLASS
00648 
00649 template <typename Derived>
00650 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
00651   if (!D)
00652     return true;
00653 
00654   // As a syntax visitor, by default we want to ignore declarations for
00655   // implicit declarations (ones not typed explicitly by the user).
00656   if (!getDerived().shouldVisitImplicitCode() && D->isImplicit())
00657     return true;
00658 
00659   switch (D->getKind()) {
00660 #define ABSTRACT_DECL(DECL)
00661 #define DECL(CLASS, BASE)                                                      \
00662   case Decl::CLASS:                                                            \
00663     if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D)))    \
00664       return false;                                                            \
00665     break;
00666 #include "clang/AST/DeclNodes.inc"
00667   }
00668 
00669   // Visit any attributes attached to this declaration.
00670   for (auto *I : D->attrs()) {
00671     if (!getDerived().TraverseAttr(I))
00672       return false;
00673   }
00674   return true;
00675 }
00676 
00677 #undef DISPATCH
00678 
00679 template <typename Derived>
00680 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
00681     NestedNameSpecifier *NNS) {
00682   if (!NNS)
00683     return true;
00684 
00685   if (NNS->getPrefix())
00686     TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
00687 
00688   switch (NNS->getKind()) {
00689   case NestedNameSpecifier::Identifier:
00690   case NestedNameSpecifier::Namespace:
00691   case NestedNameSpecifier::NamespaceAlias:
00692   case NestedNameSpecifier::Global:
00693   case NestedNameSpecifier::Super:
00694     return true;
00695 
00696   case NestedNameSpecifier::TypeSpec:
00697   case NestedNameSpecifier::TypeSpecWithTemplate:
00698     TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
00699   }
00700 
00701   return true;
00702 }
00703 
00704 template <typename Derived>
00705 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
00706     NestedNameSpecifierLoc NNS) {
00707   if (!NNS)
00708     return true;
00709 
00710   if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
00711     TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
00712 
00713   switch (NNS.getNestedNameSpecifier()->getKind()) {
00714   case NestedNameSpecifier::Identifier:
00715   case NestedNameSpecifier::Namespace:
00716   case NestedNameSpecifier::NamespaceAlias:
00717   case NestedNameSpecifier::Global:
00718   case NestedNameSpecifier::Super:
00719     return true;
00720 
00721   case NestedNameSpecifier::TypeSpec:
00722   case NestedNameSpecifier::TypeSpecWithTemplate:
00723     TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
00724     break;
00725   }
00726 
00727   return true;
00728 }
00729 
00730 template <typename Derived>
00731 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
00732     DeclarationNameInfo NameInfo) {
00733   switch (NameInfo.getName().getNameKind()) {
00734   case DeclarationName::CXXConstructorName:
00735   case DeclarationName::CXXDestructorName:
00736   case DeclarationName::CXXConversionFunctionName:
00737     if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
00738       TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
00739 
00740     break;
00741 
00742   case DeclarationName::Identifier:
00743   case DeclarationName::ObjCZeroArgSelector:
00744   case DeclarationName::ObjCOneArgSelector:
00745   case DeclarationName::ObjCMultiArgSelector:
00746   case DeclarationName::CXXOperatorName:
00747   case DeclarationName::CXXLiteralOperatorName:
00748   case DeclarationName::CXXUsingDirective:
00749     break;
00750   }
00751 
00752   return true;
00753 }
00754 
00755 template <typename Derived>
00756 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
00757   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
00758     TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
00759   else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
00760     TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
00761 
00762   return true;
00763 }
00764 
00765 template <typename Derived>
00766 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
00767     const TemplateArgument &Arg) {
00768   switch (Arg.getKind()) {
00769   case TemplateArgument::Null:
00770   case TemplateArgument::Declaration:
00771   case TemplateArgument::Integral:
00772   case TemplateArgument::NullPtr:
00773     return true;
00774 
00775   case TemplateArgument::Type:
00776     return getDerived().TraverseType(Arg.getAsType());
00777 
00778   case TemplateArgument::Template:
00779   case TemplateArgument::TemplateExpansion:
00780     return getDerived().TraverseTemplateName(
00781         Arg.getAsTemplateOrTemplatePattern());
00782 
00783   case TemplateArgument::Expression:
00784     return getDerived().TraverseStmt(Arg.getAsExpr());
00785 
00786   case TemplateArgument::Pack:
00787     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
00788                                                   Arg.pack_size());
00789   }
00790 
00791   return true;
00792 }
00793 
00794 // FIXME: no template name location?
00795 // FIXME: no source locations for a template argument pack?
00796 template <typename Derived>
00797 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
00798     const TemplateArgumentLoc &ArgLoc) {
00799   const TemplateArgument &Arg = ArgLoc.getArgument();
00800 
00801   switch (Arg.getKind()) {
00802   case TemplateArgument::Null:
00803   case TemplateArgument::Declaration:
00804   case TemplateArgument::Integral:
00805   case TemplateArgument::NullPtr:
00806     return true;
00807 
00808   case TemplateArgument::Type: {
00809     // FIXME: how can TSI ever be NULL?
00810     if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
00811       return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
00812     else
00813       return getDerived().TraverseType(Arg.getAsType());
00814   }
00815 
00816   case TemplateArgument::Template:
00817   case TemplateArgument::TemplateExpansion:
00818     if (ArgLoc.getTemplateQualifierLoc())
00819       TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
00820           ArgLoc.getTemplateQualifierLoc()));
00821     return getDerived().TraverseTemplateName(
00822         Arg.getAsTemplateOrTemplatePattern());
00823 
00824   case TemplateArgument::Expression:
00825     return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
00826 
00827   case TemplateArgument::Pack:
00828     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
00829                                                   Arg.pack_size());
00830   }
00831 
00832   return true;
00833 }
00834 
00835 template <typename Derived>
00836 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
00837     const TemplateArgument *Args, unsigned NumArgs) {
00838   for (unsigned I = 0; I != NumArgs; ++I) {
00839     TRY_TO(TraverseTemplateArgument(Args[I]));
00840   }
00841 
00842   return true;
00843 }
00844 
00845 template <typename Derived>
00846 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
00847     CXXCtorInitializer *Init) {
00848   if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
00849     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
00850 
00851   if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
00852     TRY_TO(TraverseStmt(Init->getInit()));
00853   return true;
00854 }
00855 
00856 template <typename Derived>
00857 bool
00858 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
00859                                                     const LambdaCapture *C) {
00860   if (C->isInitCapture())
00861     TRY_TO(TraverseDecl(C->getCapturedVar()));
00862   return true;
00863 }
00864 
00865 template <typename Derived>
00866 bool RecursiveASTVisitor<Derived>::TraverseLambdaBody(LambdaExpr *LE) {
00867   TRY_TO(TraverseStmt(LE->getBody()));
00868   return true;
00869 }
00870 
00871 // ----------------- Type traversal -----------------
00872 
00873 // This macro makes available a variable T, the passed-in type.
00874 #define DEF_TRAVERSE_TYPE(TYPE, CODE)                                          \
00875   template <typename Derived>                                                  \
00876   bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) {                 \
00877     TRY_TO(WalkUpFrom##TYPE(T));                                               \
00878     { CODE; }                                                                  \
00879     return true;                                                               \
00880   }
00881 
00882 DEF_TRAVERSE_TYPE(BuiltinType, {})
00883 
00884 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
00885 
00886 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
00887 
00888 DEF_TRAVERSE_TYPE(BlockPointerType,
00889                   { TRY_TO(TraverseType(T->getPointeeType())); })
00890 
00891 DEF_TRAVERSE_TYPE(LValueReferenceType,
00892                   { TRY_TO(TraverseType(T->getPointeeType())); })
00893 
00894 DEF_TRAVERSE_TYPE(RValueReferenceType,
00895                   { TRY_TO(TraverseType(T->getPointeeType())); })
00896 
00897 DEF_TRAVERSE_TYPE(MemberPointerType, {
00898   TRY_TO(TraverseType(QualType(T->getClass(), 0)));
00899   TRY_TO(TraverseType(T->getPointeeType()));
00900 })
00901 
00902 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
00903 
00904 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
00905 
00906 DEF_TRAVERSE_TYPE(ConstantArrayType,
00907                   { TRY_TO(TraverseType(T->getElementType())); })
00908 
00909 DEF_TRAVERSE_TYPE(IncompleteArrayType,
00910                   { TRY_TO(TraverseType(T->getElementType())); })
00911 
00912 DEF_TRAVERSE_TYPE(VariableArrayType, {
00913   TRY_TO(TraverseType(T->getElementType()));
00914   TRY_TO(TraverseStmt(T->getSizeExpr()));
00915 })
00916 
00917 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
00918   TRY_TO(TraverseType(T->getElementType()));
00919   if (T->getSizeExpr())
00920     TRY_TO(TraverseStmt(T->getSizeExpr()));
00921 })
00922 
00923 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
00924   if (T->getSizeExpr())
00925     TRY_TO(TraverseStmt(T->getSizeExpr()));
00926   TRY_TO(TraverseType(T->getElementType()));
00927 })
00928 
00929 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
00930 
00931 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
00932 
00933 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
00934                   { TRY_TO(TraverseType(T->getReturnType())); })
00935 
00936 DEF_TRAVERSE_TYPE(FunctionProtoType, {
00937   TRY_TO(TraverseType(T->getReturnType()));
00938 
00939   for (const auto &A : T->param_types()) {
00940     TRY_TO(TraverseType(A));
00941   }
00942 
00943   for (const auto &E : T->exceptions()) {
00944     TRY_TO(TraverseType(E));
00945   }
00946 
00947   if (Expr *NE = T->getNoexceptExpr())
00948     TRY_TO(TraverseStmt(NE));
00949 })
00950 
00951 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
00952 DEF_TRAVERSE_TYPE(TypedefType, {})
00953 
00954 DEF_TRAVERSE_TYPE(TypeOfExprType,
00955                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
00956 
00957 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
00958 
00959 DEF_TRAVERSE_TYPE(DecltypeType,
00960                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
00961 
00962 DEF_TRAVERSE_TYPE(UnaryTransformType, {
00963   TRY_TO(TraverseType(T->getBaseType()));
00964   TRY_TO(TraverseType(T->getUnderlyingType()));
00965 })
00966 
00967 DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
00968 
00969 DEF_TRAVERSE_TYPE(RecordType, {})
00970 DEF_TRAVERSE_TYPE(EnumType, {})
00971 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
00972 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {})
00973 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {})
00974 
00975 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
00976   TRY_TO(TraverseTemplateName(T->getTemplateName()));
00977   TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
00978 })
00979 
00980 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
00981 
00982 DEF_TRAVERSE_TYPE(AttributedType,
00983                   { TRY_TO(TraverseType(T->getModifiedType())); })
00984 
00985 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
00986 
00987 DEF_TRAVERSE_TYPE(ElaboratedType, {
00988   if (T->getQualifier()) {
00989     TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
00990   }
00991   TRY_TO(TraverseType(T->getNamedType()));
00992 })
00993 
00994 DEF_TRAVERSE_TYPE(DependentNameType,
00995                   { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
00996 
00997 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
00998   TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
00999   TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
01000 })
01001 
01002 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
01003 
01004 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
01005 
01006 DEF_TRAVERSE_TYPE(ObjCObjectType, {
01007   // We have to watch out here because an ObjCInterfaceType's base
01008   // type is itself.
01009   if (T->getBaseType().getTypePtr() != T)
01010     TRY_TO(TraverseType(T->getBaseType()));
01011 })
01012 
01013 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
01014                   { TRY_TO(TraverseType(T->getPointeeType())); })
01015 
01016 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
01017 
01018 #undef DEF_TRAVERSE_TYPE
01019 
01020 // ----------------- TypeLoc traversal -----------------
01021 
01022 // This macro makes available a variable TL, the passed-in TypeLoc.
01023 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
01024 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
01025 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
01026 // continue to work.
01027 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE)                                       \
01028   template <typename Derived>                                                  \
01029   bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) {       \
01030     if (getDerived().shouldWalkTypesOfTypeLocs())                              \
01031       TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr())));           \
01032     TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                         \
01033     { CODE; }                                                                  \
01034     return true;                                                               \
01035   }
01036 
01037 template <typename Derived>
01038 bool
01039 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
01040   // Move this over to the 'main' typeloc tree.  Note that this is a
01041   // move -- we pretend that we were really looking at the unqualified
01042   // typeloc all along -- rather than a recursion, so we don't follow
01043   // the normal CRTP plan of going through
01044   // getDerived().TraverseTypeLoc.  If we did, we'd be traversing
01045   // twice for the same type (once as a QualifiedTypeLoc version of
01046   // the type, once as an UnqualifiedTypeLoc version of the type),
01047   // which in effect means we'd call VisitTypeLoc twice with the
01048   // 'same' type.  This solves that problem, at the cost of never
01049   // seeing the qualified version of the type (unless the client
01050   // subclasses TraverseQualifiedTypeLoc themselves).  It's not a
01051   // perfect solution.  A perfect solution probably requires making
01052   // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
01053   // wrapper around Type* -- rather than being its own class in the
01054   // type hierarchy.
01055   return TraverseTypeLoc(TL.getUnqualifiedLoc());
01056 }
01057 
01058 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
01059 
01060 // FIXME: ComplexTypeLoc is unfinished
01061 DEF_TRAVERSE_TYPELOC(ComplexType, {
01062   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
01063 })
01064 
01065 DEF_TRAVERSE_TYPELOC(PointerType,
01066                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
01067 
01068 DEF_TRAVERSE_TYPELOC(BlockPointerType,
01069                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
01070 
01071 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
01072                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
01073 
01074 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
01075                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
01076 
01077 // FIXME: location of base class?
01078 // We traverse this in the type case as well, but how is it not reached through
01079 // the pointee type?
01080 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
01081   TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
01082   TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
01083 })
01084 
01085 DEF_TRAVERSE_TYPELOC(AdjustedType,
01086                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
01087 
01088 DEF_TRAVERSE_TYPELOC(DecayedType,
01089                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
01090 
01091 template <typename Derived>
01092 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
01093   // This isn't available for ArrayType, but is for the ArrayTypeLoc.
01094   TRY_TO(TraverseStmt(TL.getSizeExpr()));
01095   return true;
01096 }
01097 
01098 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
01099   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
01100   return TraverseArrayTypeLocHelper(TL);
01101 })
01102 
01103 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
01104   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
01105   return TraverseArrayTypeLocHelper(TL);
01106 })
01107 
01108 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
01109   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
01110   return TraverseArrayTypeLocHelper(TL);
01111 })
01112 
01113 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
01114   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
01115   return TraverseArrayTypeLocHelper(TL);
01116 })
01117 
01118 // FIXME: order? why not size expr first?
01119 // FIXME: base VectorTypeLoc is unfinished
01120 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
01121   if (TL.getTypePtr()->getSizeExpr())
01122     TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
01123   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
01124 })
01125 
01126 // FIXME: VectorTypeLoc is unfinished
01127 DEF_TRAVERSE_TYPELOC(VectorType, {
01128   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
01129 })
01130 
01131 // FIXME: size and attributes
01132 // FIXME: base VectorTypeLoc is unfinished
01133 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
01134   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
01135 })
01136 
01137 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
01138                      { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
01139 
01140 // FIXME: location of exception specifications (attributes?)
01141 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
01142   TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
01143 
01144   const FunctionProtoType *T = TL.getTypePtr();
01145 
01146   for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
01147     if (TL.getParam(I)) {
01148       TRY_TO(TraverseDecl(TL.getParam(I)));
01149     } else if (I < T->getNumParams()) {
01150       TRY_TO(TraverseType(T->getParamType(I)));
01151     }
01152   }
01153 
01154   for (const auto &E : T->exceptions()) {
01155     TRY_TO(TraverseType(E));
01156   }
01157 
01158   if (Expr *NE = T->getNoexceptExpr())
01159     TRY_TO(TraverseStmt(NE));
01160 })
01161 
01162 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
01163 DEF_TRAVERSE_TYPELOC(TypedefType, {})
01164 
01165 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
01166                      { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
01167 
01168 DEF_TRAVERSE_TYPELOC(TypeOfType, {
01169   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
01170 })
01171 
01172 // FIXME: location of underlying expr
01173 DEF_TRAVERSE_TYPELOC(DecltypeType, {
01174   TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
01175 })
01176 
01177 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
01178   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
01179 })
01180 
01181 DEF_TRAVERSE_TYPELOC(AutoType, {
01182   TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
01183 })
01184 
01185 DEF_TRAVERSE_TYPELOC(RecordType, {})
01186 DEF_TRAVERSE_TYPELOC(EnumType, {})
01187 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
01188 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {})
01189 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {})
01190 
01191 // FIXME: use the loc for the template name?
01192 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
01193   TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
01194   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
01195     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
01196   }
01197 })
01198 
01199 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
01200 
01201 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
01202 
01203 DEF_TRAVERSE_TYPELOC(AttributedType,
01204                      { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
01205 
01206 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
01207   if (TL.getQualifierLoc()) {
01208     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
01209   }
01210   TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
01211 })
01212 
01213 DEF_TRAVERSE_TYPELOC(DependentNameType, {
01214   TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
01215 })
01216 
01217 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
01218   if (TL.getQualifierLoc()) {
01219     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
01220   }
01221 
01222   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
01223     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
01224   }
01225 })
01226 
01227 DEF_TRAVERSE_TYPELOC(PackExpansionType,
01228                      { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
01229 
01230 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
01231 
01232 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
01233   // We have to watch out here because an ObjCInterfaceType's base
01234   // type is itself.
01235   if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
01236     TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
01237 })
01238 
01239 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
01240                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
01241 
01242 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
01243 
01244 #undef DEF_TRAVERSE_TYPELOC
01245 
01246 // ----------------- Decl traversal -----------------
01247 //
01248 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
01249 // the children that come from the DeclContext associated with it.
01250 // Therefore each Traverse* only needs to worry about children other
01251 // than those.
01252 
01253 template <typename Derived>
01254 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
01255   if (!DC)
01256     return true;
01257 
01258   for (auto *Child : DC->decls()) {
01259     // BlockDecls and CapturedDecls are traversed through BlockExprs and
01260     // CapturedStmts respectively.
01261     if (!isa<BlockDecl>(Child) && !isa<CapturedDecl>(Child))
01262       TRY_TO(TraverseDecl(Child));
01263   }
01264 
01265   return true;
01266 }
01267 
01268 // This macro makes available a variable D, the passed-in decl.
01269 #define DEF_TRAVERSE_DECL(DECL, CODE)                                          \
01270   template <typename Derived>                                                  \
01271   bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) {                 \
01272     TRY_TO(WalkUpFrom##DECL(D));                                               \
01273     { CODE; }                                                                  \
01274     TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D)));               \
01275     return true;                                                               \
01276   }
01277 
01278 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
01279 
01280 DEF_TRAVERSE_DECL(BlockDecl, {
01281   if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
01282     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
01283   TRY_TO(TraverseStmt(D->getBody()));
01284   for (const auto &I : D->captures()) {
01285     if (I.hasCopyExpr()) {
01286       TRY_TO(TraverseStmt(I.getCopyExpr()));
01287     }
01288   }
01289   // This return statement makes sure the traversal of nodes in
01290   // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
01291   // is skipped - don't remove it.
01292   return true;
01293 })
01294 
01295 DEF_TRAVERSE_DECL(CapturedDecl, {
01296   TRY_TO(TraverseStmt(D->getBody()));
01297   // This return statement makes sure the traversal of nodes in
01298   // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
01299   // is skipped - don't remove it.
01300   return true;
01301 })
01302 
01303 DEF_TRAVERSE_DECL(EmptyDecl, {})
01304 
01305 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
01306                   { TRY_TO(TraverseStmt(D->getAsmString())); })
01307 
01308 DEF_TRAVERSE_DECL(ImportDecl, {})
01309 
01310 DEF_TRAVERSE_DECL(FriendDecl, {
01311   // Friend is either decl or a type.
01312   if (D->getFriendType())
01313     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
01314   else
01315     TRY_TO(TraverseDecl(D->getFriendDecl()));
01316 })
01317 
01318 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
01319   if (D->getFriendType())
01320     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
01321   else
01322     TRY_TO(TraverseDecl(D->getFriendDecl()));
01323   for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
01324     TemplateParameterList *TPL = D->getTemplateParameterList(I);
01325     for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
01326          ITPL != ETPL; ++ITPL) {
01327       TRY_TO(TraverseDecl(*ITPL));
01328     }
01329   }
01330 })
01331 
01332 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
01333   TRY_TO(TraverseDecl(D->getSpecialization()));
01334 
01335   if (D->hasExplicitTemplateArgs()) {
01336     const TemplateArgumentListInfo &args = D->templateArgs();
01337     TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(),
01338                                               args.size()));
01339   }
01340 })
01341 
01342 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
01343 
01344 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
01345                                         })
01346 
01347 DEF_TRAVERSE_DECL(StaticAssertDecl, {
01348   TRY_TO(TraverseStmt(D->getAssertExpr()));
01349   TRY_TO(TraverseStmt(D->getMessage()));
01350 })
01351 
01352 DEF_TRAVERSE_DECL(
01353     TranslationUnitDecl,
01354     {// Code in an unnamed namespace shows up automatically in
01355      // decls_begin()/decls_end().  Thus we don't need to recurse on
01356      // D->getAnonymousNamespace().
01357     })
01358 
01359 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
01360   // We shouldn't traverse an aliased namespace, since it will be
01361   // defined (and, therefore, traversed) somewhere else.
01362   //
01363   // This return statement makes sure the traversal of nodes in
01364   // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
01365   // is skipped - don't remove it.
01366   return true;
01367 })
01368 
01369 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
01370                              })
01371 
01372 DEF_TRAVERSE_DECL(
01373     NamespaceDecl,
01374     {// Code in an unnamed namespace shows up automatically in
01375      // decls_begin()/decls_end().  Thus we don't need to recurse on
01376      // D->getAnonymousNamespace().
01377     })
01378 
01379 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
01380                                            })
01381 
01382 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
01383                                     })
01384 
01385 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
01386                                         })
01387 
01388 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
01389                                           })
01390 
01391 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
01392                                      })
01393 
01394 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
01395                                     })
01396 
01397 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
01398   if (D->getReturnTypeSourceInfo()) {
01399     TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
01400   }
01401   for (ObjCMethodDecl::param_iterator I = D->param_begin(), E = D->param_end();
01402        I != E; ++I) {
01403     TRY_TO(TraverseDecl(*I));
01404   }
01405   if (D->isThisDeclarationADefinition()) {
01406     TRY_TO(TraverseStmt(D->getBody()));
01407   }
01408   return true;
01409 })
01410 
01411 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
01412   if (D->getTypeSourceInfo())
01413     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
01414   else
01415     TRY_TO(TraverseType(D->getType()));
01416   return true;
01417 })
01418 
01419 DEF_TRAVERSE_DECL(UsingDecl, {
01420   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
01421   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
01422 })
01423 
01424 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
01425   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
01426 })
01427 
01428 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
01429 
01430 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
01431   for (auto *I : D->varlists()) {
01432     TRY_TO(TraverseStmt(I));
01433   }
01434 })
01435 
01436 // A helper method for TemplateDecl's children.
01437 template <typename Derived>
01438 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
01439     TemplateParameterList *TPL) {
01440   if (TPL) {
01441     for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
01442          I != E; ++I) {
01443       TRY_TO(TraverseDecl(*I));
01444     }
01445   }
01446   return true;
01447 }
01448 
01449 template <typename Derived>
01450 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
01451     ClassTemplateDecl *D) {
01452   for (auto *SD : D->specializations()) {
01453     for (auto *RD : SD->redecls()) {
01454       // We don't want to visit injected-class-names in this traversal.
01455       if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
01456         continue;
01457 
01458       switch (
01459           cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
01460       // Visit the implicit instantiations with the requested pattern.
01461       case TSK_Undeclared:
01462       case TSK_ImplicitInstantiation:
01463         TRY_TO(TraverseDecl(RD));
01464         break;
01465 
01466       // We don't need to do anything on an explicit instantiation
01467       // or explicit specialization because there will be an explicit
01468       // node for it elsewhere.
01469       case TSK_ExplicitInstantiationDeclaration:
01470       case TSK_ExplicitInstantiationDefinition:
01471       case TSK_ExplicitSpecialization:
01472         break;
01473       }
01474     }
01475   }
01476 
01477   return true;
01478 }
01479 
01480 template <typename Derived>
01481 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
01482     VarTemplateDecl *D) {
01483   for (auto *SD : D->specializations()) {
01484     for (auto *RD : SD->redecls()) {
01485       switch (
01486           cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
01487       case TSK_Undeclared:
01488       case TSK_ImplicitInstantiation:
01489         TRY_TO(TraverseDecl(RD));
01490         break;
01491 
01492       case TSK_ExplicitInstantiationDeclaration:
01493       case TSK_ExplicitInstantiationDefinition:
01494       case TSK_ExplicitSpecialization:
01495         break;
01496       }
01497     }
01498   }
01499 
01500   return true;
01501 }
01502 
01503 // A helper method for traversing the instantiations of a
01504 // function while skipping its specializations.
01505 template <typename Derived>
01506 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
01507     FunctionTemplateDecl *D) {
01508   for (auto *FD : D->specializations()) {
01509     for (auto *RD : FD->redecls()) {
01510       switch (RD->getTemplateSpecializationKind()) {
01511       case TSK_Undeclared:
01512       case TSK_ImplicitInstantiation:
01513         // We don't know what kind of FunctionDecl this is.
01514         TRY_TO(TraverseDecl(RD));
01515         break;
01516 
01517       // FIXME: For now traverse explicit instantiations here. Change that
01518       // once they are represented as dedicated nodes in the AST.
01519       case TSK_ExplicitInstantiationDeclaration:
01520       case TSK_ExplicitInstantiationDefinition:
01521         TRY_TO(TraverseDecl(RD));
01522         break;
01523 
01524       case TSK_ExplicitSpecialization:
01525         break;
01526       }
01527     }
01528   }
01529 
01530   return true;
01531 }
01532 
01533 // This macro unifies the traversal of class, variable and function
01534 // template declarations.
01535 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND)                                   \
01536   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, {                              \
01537     TRY_TO(TraverseDecl(D->getTemplatedDecl()));                               \
01538     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));   \
01539                                                                                \
01540     /* By default, we do not traverse the instantiations of                    \
01541        class templates since they do not appear in the user code. The          \
01542        following code optionally traverses them.                               \
01543                                                                                \
01544        We only traverse the class instantiations when we see the canonical     \
01545        declaration of the template, to ensure we only visit them once. */      \
01546     if (getDerived().shouldVisitTemplateInstantiations() &&                    \
01547         D == D->getCanonicalDecl())                                            \
01548       TRY_TO(TraverseTemplateInstantiations(D));                               \
01549                                                                                \
01550     /* Note that getInstantiatedFromMemberTemplate() is just a link            \
01551        from a template instantiation back to the template from which           \
01552        it was instantiated, and thus should not be traversed. */               \
01553   })
01554 
01555 DEF_TRAVERSE_TMPL_DECL(Class)
01556 DEF_TRAVERSE_TMPL_DECL(Var)
01557 DEF_TRAVERSE_TMPL_DECL(Function)
01558 
01559 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
01560   // D is the "T" in something like
01561   //   template <template <typename> class T> class container { };
01562   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
01563   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
01564     TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
01565   }
01566   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
01567 })
01568 
01569 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
01570   // D is the "T" in something like "template<typename T> class vector;"
01571   if (D->getTypeForDecl())
01572     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
01573   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
01574     TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
01575 })
01576 
01577 DEF_TRAVERSE_DECL(TypedefDecl, {
01578   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
01579   // We shouldn't traverse D->getTypeForDecl(); it's a result of
01580   // declaring the typedef, not something that was written in the
01581   // source.
01582 })
01583 
01584 DEF_TRAVERSE_DECL(TypeAliasDecl, {
01585   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
01586   // We shouldn't traverse D->getTypeForDecl(); it's a result of
01587   // declaring the type alias, not something that was written in the
01588   // source.
01589 })
01590 
01591 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
01592   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
01593   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
01594 })
01595 
01596 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
01597   // A dependent using declaration which was marked with 'typename'.
01598   //   template<class T> class A : public B<T> { using typename B<T>::foo; };
01599   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
01600   // We shouldn't traverse D->getTypeForDecl(); it's a result of
01601   // declaring the type, not something that was written in the
01602   // source.
01603 })
01604 
01605 DEF_TRAVERSE_DECL(EnumDecl, {
01606   if (D->getTypeForDecl())
01607     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
01608 
01609   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
01610   // The enumerators are already traversed by
01611   // decls_begin()/decls_end().
01612 })
01613 
01614 // Helper methods for RecordDecl and its children.
01615 template <typename Derived>
01616 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
01617   // We shouldn't traverse D->getTypeForDecl(); it's a result of
01618   // declaring the type, not something that was written in the source.
01619 
01620   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
01621   return true;
01622 }
01623 
01624 template <typename Derived>
01625 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
01626   if (!TraverseRecordHelper(D))
01627     return false;
01628   if (D->isCompleteDefinition()) {
01629     for (const auto &I : D->bases()) {
01630       TRY_TO(TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc()));
01631     }
01632     // We don't traverse the friends or the conversions, as they are
01633     // already in decls_begin()/decls_end().
01634   }
01635   return true;
01636 }
01637 
01638 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
01639 
01640 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
01641 
01642 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND)                              \
01643   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, {                \
01644     /* For implicit instantiations ("set<int> x;"), we don't want to           \
01645        recurse at all, since the instatiated template isn't written in         \
01646        the source code anywhere.  (Note the instatiated *type* --              \
01647        set<int> -- is written, and will still get a callback of                \
01648        TemplateSpecializationType).  For explicit instantiations               \
01649        ("template set<int>;"), we do need a callback, since this               \
01650        is the only callback that's made for this instantiation.                \
01651        We use getTypeAsWritten() to distinguish. */                            \
01652     if (TypeSourceInfo *TSI = D->getTypeAsWritten())                           \
01653       TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));                              \
01654                                                                                \
01655     if (!getDerived().shouldVisitTemplateInstantiations() &&                   \
01656         D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)      \
01657       /* Returning from here skips traversing the                              \
01658          declaration context of the *TemplateSpecializationDecl                \
01659          (embedded in the DEF_TRAVERSE_DECL() macro)                           \
01660          which contains the instantiated members of the template. */           \
01661       return true;                                                             \
01662   })
01663 
01664 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)
01665 DEF_TRAVERSE_TMPL_SPEC_DECL(Var)
01666 
01667 template <typename Derived>
01668 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
01669     const TemplateArgumentLoc *TAL, unsigned Count) {
01670   for (unsigned I = 0; I < Count; ++I) {
01671     TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
01672   }
01673   return true;
01674 }
01675 
01676 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND)               \
01677   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, {         \
01678     /* The partial specialization. */                                          \
01679     if (TemplateParameterList *TPL = D->getTemplateParameters()) {             \
01680       for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();   \
01681            I != E; ++I) {                                                      \
01682         TRY_TO(TraverseDecl(*I));                                              \
01683       }                                                                        \
01684     }                                                                          \
01685     /* The args that remains unspecialized. */                                 \
01686     TRY_TO(TraverseTemplateArgumentLocsHelper(                                 \
01687         D->getTemplateArgsAsWritten()->getTemplateArgs(),                      \
01688         D->getTemplateArgsAsWritten()->NumTemplateArgs));                      \
01689                                                                                \
01690     /* Don't need the *TemplatePartialSpecializationHelper, even               \
01691        though that's our parent class -- we already visit all the              \
01692        template args here. */                                                  \
01693     TRY_TO(Traverse##DECLKIND##Helper(D));                                     \
01694                                                                                \
01695     /* Instantiations will have been visited with the primary template. */     \
01696   })
01697 
01698 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
01699 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
01700 
01701 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
01702 
01703 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
01704   // Like UnresolvedUsingTypenameDecl, but without the 'typename':
01705   //    template <class T> Class A : public Base<T> { using Base<T>::foo; };
01706   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
01707   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
01708 })
01709 
01710 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
01711 
01712 template <typename Derived>
01713 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
01714   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
01715   if (D->getTypeSourceInfo())
01716     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
01717   else
01718     TRY_TO(TraverseType(D->getType()));
01719   return true;
01720 }
01721 
01722 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
01723 
01724 DEF_TRAVERSE_DECL(FieldDecl, {
01725   TRY_TO(TraverseDeclaratorHelper(D));
01726   if (D->isBitField())
01727     TRY_TO(TraverseStmt(D->getBitWidth()));
01728   else if (D->hasInClassInitializer())
01729     TRY_TO(TraverseStmt(D->getInClassInitializer()));
01730 })
01731 
01732 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
01733   TRY_TO(TraverseDeclaratorHelper(D));
01734   if (D->isBitField())
01735     TRY_TO(TraverseStmt(D->getBitWidth()));
01736   // FIXME: implement the rest.
01737 })
01738 
01739 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
01740   TRY_TO(TraverseDeclaratorHelper(D));
01741   if (D->isBitField())
01742     TRY_TO(TraverseStmt(D->getBitWidth()));
01743   // FIXME: implement the rest.
01744 })
01745 
01746 template <typename Derived>
01747 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
01748   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
01749   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
01750 
01751   // If we're an explicit template specialization, iterate over the
01752   // template args that were explicitly specified.  If we were doing
01753   // this in typing order, we'd do it between the return type and
01754   // the function args, but both are handled by the FunctionTypeLoc
01755   // above, so we have to choose one side.  I've decided to do before.
01756   if (const FunctionTemplateSpecializationInfo *FTSI =
01757           D->getTemplateSpecializationInfo()) {
01758     if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
01759         FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
01760       // A specialization might not have explicit template arguments if it has
01761       // a templated return type and concrete arguments.
01762       if (const ASTTemplateArgumentListInfo *TALI =
01763               FTSI->TemplateArgumentsAsWritten) {
01764         TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
01765                                                   TALI->NumTemplateArgs));
01766       }
01767     }
01768   }
01769 
01770   // Visit the function type itself, which can be either
01771   // FunctionNoProtoType or FunctionProtoType, or a typedef.  This
01772   // also covers the return type and the function parameters,
01773   // including exception specifications.
01774   if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
01775     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
01776   } else if (getDerived().shouldVisitImplicitCode()) {
01777     // Visit parameter variable declarations of the implicit function
01778     // if the traverser is visiting implicit code. Parameter variable
01779     // declarations do not have valid TypeSourceInfo, so to visit them
01780     // we need to traverse the declarations explicitly.
01781     for (FunctionDecl::param_const_iterator I = D->param_begin(),
01782                                             E = D->param_end();
01783          I != E; ++I)
01784       TRY_TO(TraverseDecl(*I));
01785   }
01786 
01787   if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
01788     // Constructor initializers.
01789     for (auto *I : Ctor->inits()) {
01790       TRY_TO(TraverseConstructorInitializer(I));
01791     }
01792   }
01793 
01794   if (D->isThisDeclarationADefinition()) {
01795     TRY_TO(TraverseStmt(D->getBody())); // Function body.
01796   }
01797   return true;
01798 }
01799 
01800 DEF_TRAVERSE_DECL(FunctionDecl, {
01801   // We skip decls_begin/decls_end, which are already covered by
01802   // TraverseFunctionHelper().
01803   return TraverseFunctionHelper(D);
01804 })
01805 
01806 DEF_TRAVERSE_DECL(CXXMethodDecl, {
01807   // We skip decls_begin/decls_end, which are already covered by
01808   // TraverseFunctionHelper().
01809   return TraverseFunctionHelper(D);
01810 })
01811 
01812 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
01813   // We skip decls_begin/decls_end, which are already covered by
01814   // TraverseFunctionHelper().
01815   return TraverseFunctionHelper(D);
01816 })
01817 
01818 // CXXConversionDecl is the declaration of a type conversion operator.
01819 // It's not a cast expression.
01820 DEF_TRAVERSE_DECL(CXXConversionDecl, {
01821   // We skip decls_begin/decls_end, which are already covered by
01822   // TraverseFunctionHelper().
01823   return TraverseFunctionHelper(D);
01824 })
01825 
01826 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
01827   // We skip decls_begin/decls_end, which are already covered by
01828   // TraverseFunctionHelper().
01829   return TraverseFunctionHelper(D);
01830 })
01831 
01832 template <typename Derived>
01833 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
01834   TRY_TO(TraverseDeclaratorHelper(D));
01835   // Default params are taken care of when we traverse the ParmVarDecl.
01836   if (!isa<ParmVarDecl>(D) &&
01837       (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
01838     TRY_TO(TraverseStmt(D->getInit()));
01839   return true;
01840 }
01841 
01842 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
01843 
01844 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
01845 
01846 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
01847   // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
01848   TRY_TO(TraverseDeclaratorHelper(D));
01849   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
01850     TRY_TO(TraverseStmt(D->getDefaultArgument()));
01851 })
01852 
01853 DEF_TRAVERSE_DECL(ParmVarDecl, {
01854   TRY_TO(TraverseVarHelper(D));
01855 
01856   if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
01857       !D->hasUnparsedDefaultArg())
01858     TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
01859 
01860   if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
01861       !D->hasUnparsedDefaultArg())
01862     TRY_TO(TraverseStmt(D->getDefaultArg()));
01863 })
01864 
01865 #undef DEF_TRAVERSE_DECL
01866 
01867 // ----------------- Stmt traversal -----------------
01868 //
01869 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
01870 // over the children defined in children() (every stmt defines these,
01871 // though sometimes the range is empty).  Each individual Traverse*
01872 // method only needs to worry about children other than those.  To see
01873 // what children() does for a given class, see, e.g.,
01874 //   http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
01875 
01876 // This macro makes available a variable S, the passed-in stmt.
01877 #define DEF_TRAVERSE_STMT(STMT, CODE)                                          \
01878   template <typename Derived>                                                  \
01879   bool RecursiveASTVisitor<Derived>::Traverse##STMT(STMT *S) {                 \
01880     TRY_TO(WalkUpFrom##STMT(S));                                               \
01881     { CODE; }                                                                  \
01882     for (Stmt::child_range range = S->children(); range; ++range) {            \
01883       TRY_TO(TraverseStmt(*range));                                            \
01884     }                                                                          \
01885     return true;                                                               \
01886   }
01887 
01888 DEF_TRAVERSE_STMT(GCCAsmStmt, {
01889   TRY_TO(TraverseStmt(S->getAsmString()));
01890   for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
01891     TRY_TO(TraverseStmt(S->getInputConstraintLiteral(I)));
01892   }
01893   for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
01894     TRY_TO(TraverseStmt(S->getOutputConstraintLiteral(I)));
01895   }
01896   for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
01897     TRY_TO(TraverseStmt(S->getClobberStringLiteral(I)));
01898   }
01899   // children() iterates over inputExpr and outputExpr.
01900 })
01901 
01902 DEF_TRAVERSE_STMT(
01903     MSAsmStmt,
01904     {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc.  Once
01905      // added this needs to be implemented.
01906     })
01907 
01908 DEF_TRAVERSE_STMT(CXXCatchStmt, {
01909   TRY_TO(TraverseDecl(S->getExceptionDecl()));
01910   // children() iterates over the handler block.
01911 })
01912 
01913 DEF_TRAVERSE_STMT(DeclStmt, {
01914   for (auto *I : S->decls()) {
01915     TRY_TO(TraverseDecl(I));
01916   }
01917   // Suppress the default iteration over children() by
01918   // returning.  Here's why: A DeclStmt looks like 'type var [=
01919   // initializer]'.  The decls above already traverse over the
01920   // initializers, so we don't have to do it again (which
01921   // children() would do).
01922   return true;
01923 })
01924 
01925 // These non-expr stmts (most of them), do not need any action except
01926 // iterating over the children.
01927 DEF_TRAVERSE_STMT(BreakStmt, {})
01928 DEF_TRAVERSE_STMT(CXXTryStmt, {})
01929 DEF_TRAVERSE_STMT(CaseStmt, {})
01930 DEF_TRAVERSE_STMT(CompoundStmt, {})
01931 DEF_TRAVERSE_STMT(ContinueStmt, {})
01932 DEF_TRAVERSE_STMT(DefaultStmt, {})
01933 DEF_TRAVERSE_STMT(DoStmt, {})
01934 DEF_TRAVERSE_STMT(ForStmt, {})
01935 DEF_TRAVERSE_STMT(GotoStmt, {})
01936 DEF_TRAVERSE_STMT(IfStmt, {})
01937 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
01938 DEF_TRAVERSE_STMT(LabelStmt, {})
01939 DEF_TRAVERSE_STMT(AttributedStmt, {})
01940 DEF_TRAVERSE_STMT(NullStmt, {})
01941 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
01942 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
01943 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
01944 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
01945 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
01946 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
01947 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
01948 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
01949   if (!getDerived().shouldVisitImplicitCode()) {
01950     TRY_TO(TraverseStmt(S->getLoopVarStmt()));
01951     TRY_TO(TraverseStmt(S->getRangeInit()));
01952     TRY_TO(TraverseStmt(S->getBody()));
01953     // Visit everything else only if shouldVisitImplicitCode().
01954     return true;
01955   }
01956 })
01957 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
01958   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
01959   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
01960 })
01961 DEF_TRAVERSE_STMT(ReturnStmt, {})
01962 DEF_TRAVERSE_STMT(SwitchStmt, {})
01963 DEF_TRAVERSE_STMT(WhileStmt, {})
01964 
01965 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
01966   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
01967   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
01968   if (S->hasExplicitTemplateArgs()) {
01969     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
01970                                               S->getNumTemplateArgs()));
01971   }
01972 })
01973 
01974 DEF_TRAVERSE_STMT(DeclRefExpr, {
01975   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
01976   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
01977   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
01978                                             S->getNumTemplateArgs()));
01979 })
01980 
01981 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
01982   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
01983   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
01984   if (S->hasExplicitTemplateArgs()) {
01985     TRY_TO(TraverseTemplateArgumentLocsHelper(
01986         S->getExplicitTemplateArgs().getTemplateArgs(),
01987         S->getNumTemplateArgs()));
01988   }
01989 })
01990 
01991 DEF_TRAVERSE_STMT(MemberExpr, {
01992   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
01993   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
01994   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
01995                                             S->getNumTemplateArgs()));
01996 })
01997 
01998 DEF_TRAVERSE_STMT(
01999     ImplicitCastExpr,
02000     {// We don't traverse the cast type, as it's not written in the
02001      // source code.
02002     })
02003 
02004 DEF_TRAVERSE_STMT(CStyleCastExpr, {
02005   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
02006 })
02007 
02008 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
02009   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
02010 })
02011 
02012 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
02013   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
02014 })
02015 
02016 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
02017   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
02018 })
02019 
02020 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
02021   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
02022 })
02023 
02024 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
02025   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
02026 })
02027 
02028 // InitListExpr is a tricky one, because we want to do all our work on
02029 // the syntactic form of the listexpr, but this method takes the
02030 // semantic form by default.  We can't use the macro helper because it
02031 // calls WalkUp*() on the semantic form, before our code can convert
02032 // to the syntactic form.
02033 template <typename Derived>
02034 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) {
02035   if (InitListExpr *Syn = S->getSyntacticForm())
02036     S = Syn;
02037   TRY_TO(WalkUpFromInitListExpr(S));
02038   // All we need are the default actions.  FIXME: use a helper function.
02039   for (Stmt::child_range range = S->children(); range; ++range) {
02040     TRY_TO(TraverseStmt(*range));
02041   }
02042   return true;
02043 }
02044 
02045 // GenericSelectionExpr is a special case because the types and expressions
02046 // are interleaved.  We also need to watch out for null types (default
02047 // generic associations).
02048 template <typename Derived>
02049 bool RecursiveASTVisitor<Derived>::TraverseGenericSelectionExpr(
02050     GenericSelectionExpr *S) {
02051   TRY_TO(WalkUpFromGenericSelectionExpr(S));
02052   TRY_TO(TraverseStmt(S->getControllingExpr()));
02053   for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
02054     if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
02055       TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
02056     TRY_TO(TraverseStmt(S->getAssocExpr(i)));
02057   }
02058   return true;
02059 }
02060 
02061 // PseudoObjectExpr is a special case because of the wierdness with
02062 // syntactic expressions and opaque values.
02063 template <typename Derived>
02064 bool
02065 RecursiveASTVisitor<Derived>::TraversePseudoObjectExpr(PseudoObjectExpr *S) {
02066   TRY_TO(WalkUpFromPseudoObjectExpr(S));
02067   TRY_TO(TraverseStmt(S->getSyntacticForm()));
02068   for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
02069                                             e = S->semantics_end();
02070        i != e; ++i) {
02071     Expr *sub = *i;
02072     if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
02073       sub = OVE->getSourceExpr();
02074     TRY_TO(TraverseStmt(sub));
02075   }
02076   return true;
02077 }
02078 
02079 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
02080   // This is called for code like 'return T()' where T is a built-in
02081   // (i.e. non-class) type.
02082   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
02083 })
02084 
02085 DEF_TRAVERSE_STMT(CXXNewExpr, {
02086   // The child-iterator will pick up the other arguments.
02087   TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
02088 })
02089 
02090 DEF_TRAVERSE_STMT(OffsetOfExpr, {
02091   // The child-iterator will pick up the expression representing
02092   // the field.
02093   // FIMXE: for code like offsetof(Foo, a.b.c), should we get
02094   // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
02095   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
02096 })
02097 
02098 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
02099   // The child-iterator will pick up the arg if it's an expression,
02100   // but not if it's a type.
02101   if (S->isArgumentType())
02102     TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
02103 })
02104 
02105 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
02106   // The child-iterator will pick up the arg if it's an expression,
02107   // but not if it's a type.
02108   if (S->isTypeOperand())
02109     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
02110 })
02111 
02112 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
02113   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
02114 })
02115 
02116 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
02117   // The child-iterator will pick up the arg if it's an expression,
02118   // but not if it's a type.
02119   if (S->isTypeOperand())
02120     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
02121 })
02122 
02123 DEF_TRAVERSE_STMT(TypeTraitExpr, {
02124   for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
02125     TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
02126 })
02127 
02128 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
02129   TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
02130 })
02131 
02132 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
02133                   { TRY_TO(TraverseStmt(S->getQueriedExpression())); })
02134 
02135 DEF_TRAVERSE_STMT(VAArgExpr, {
02136   // The child-iterator will pick up the expression argument.
02137   TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
02138 })
02139 
02140 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
02141   // This is called for code like 'return T()' where T is a class type.
02142   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
02143 })
02144 
02145 // Walk only the visible parts of lambda expressions.
02146 template <typename Derived>
02147 bool RecursiveASTVisitor<Derived>::TraverseLambdaExpr(LambdaExpr *S) {
02148   TRY_TO(WalkUpFromLambdaExpr(S));
02149 
02150   for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
02151                                     CEnd = S->explicit_capture_end();
02152        C != CEnd; ++C) {
02153     TRY_TO(TraverseLambdaCapture(S, C));
02154   }
02155 
02156   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
02157   FunctionProtoTypeLoc Proto = TL.castAs<FunctionProtoTypeLoc>();
02158 
02159   if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
02160     // Visit the whole type.
02161     TRY_TO(TraverseTypeLoc(TL));
02162   } else {
02163     if (S->hasExplicitParameters()) {
02164       // Visit parameters.
02165       for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
02166         TRY_TO(TraverseDecl(Proto.getParam(I)));
02167       }
02168     } else if (S->hasExplicitResultType()) {
02169       TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
02170     }
02171 
02172     auto *T = Proto.getTypePtr();
02173     for (const auto &E : T->exceptions()) {
02174       TRY_TO(TraverseType(E));
02175     }
02176 
02177     if (Expr *NE = T->getNoexceptExpr())
02178       TRY_TO(TraverseStmt(NE));
02179   }
02180 
02181   TRY_TO(TraverseLambdaBody(S));
02182   return true;
02183 }
02184 
02185 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
02186   // This is called for code like 'T()', where T is a template argument.
02187   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
02188 })
02189 
02190 // These expressions all might take explicit template arguments.
02191 // We traverse those if so.  FIXME: implement these.
02192 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
02193 DEF_TRAVERSE_STMT(CallExpr, {})
02194 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
02195 
02196 // These exprs (most of them), do not need any action except iterating
02197 // over the children.
02198 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
02199 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
02200 DEF_TRAVERSE_STMT(BlockExpr, {
02201   TRY_TO(TraverseDecl(S->getBlockDecl()));
02202   return true; // no child statements to loop through.
02203 })
02204 DEF_TRAVERSE_STMT(ChooseExpr, {})
02205 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
02206   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
02207 })
02208 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
02209 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
02210 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
02211 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
02212 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
02213 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
02214 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
02215 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
02216 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
02217   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
02218   if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
02219     TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
02220   if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
02221     TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
02222 })
02223 DEF_TRAVERSE_STMT(CXXThisExpr, {})
02224 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
02225 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
02226 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
02227 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
02228 DEF_TRAVERSE_STMT(GNUNullExpr, {})
02229 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
02230 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
02231 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
02232   if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
02233     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
02234 })
02235 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
02236 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
02237 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
02238   if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
02239     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
02240 })
02241 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
02242 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
02243 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
02244 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
02245 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
02246 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
02247   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
02248 })
02249 DEF_TRAVERSE_STMT(ParenExpr, {})
02250 DEF_TRAVERSE_STMT(ParenListExpr, {})
02251 DEF_TRAVERSE_STMT(PredefinedExpr, {})
02252 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
02253 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
02254 DEF_TRAVERSE_STMT(StmtExpr, {})
02255 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
02256   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
02257   if (S->hasExplicitTemplateArgs()) {
02258     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
02259                                               S->getNumTemplateArgs()));
02260   }
02261 })
02262 
02263 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
02264   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
02265   if (S->hasExplicitTemplateArgs()) {
02266     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
02267                                               S->getNumTemplateArgs()));
02268   }
02269 })
02270 
02271 DEF_TRAVERSE_STMT(SEHTryStmt, {})
02272 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
02273 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
02274 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
02275 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
02276 
02277 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
02278 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
02279 DEF_TRAVERSE_STMT(TypoExpr, {})
02280 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
02281 
02282 // These operators (all of them) do not need any action except
02283 // iterating over the children.
02284 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
02285 DEF_TRAVERSE_STMT(ConditionalOperator, {})
02286 DEF_TRAVERSE_STMT(UnaryOperator, {})
02287 DEF_TRAVERSE_STMT(BinaryOperator, {})
02288 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
02289 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
02290 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
02291 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
02292 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
02293 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
02294 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
02295 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
02296 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
02297 DEF_TRAVERSE_STMT(AtomicExpr, {})
02298 
02299 // These literals (all of them) do not need any action.
02300 DEF_TRAVERSE_STMT(IntegerLiteral, {})
02301 DEF_TRAVERSE_STMT(CharacterLiteral, {})
02302 DEF_TRAVERSE_STMT(FloatingLiteral, {})
02303 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
02304 DEF_TRAVERSE_STMT(StringLiteral, {})
02305 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
02306 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
02307 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
02308 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
02309 
02310 // Traverse OpenCL: AsType, Convert.
02311 DEF_TRAVERSE_STMT(AsTypeExpr, {})
02312 
02313 // OpenMP directives.
02314 template <typename Derived>
02315 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
02316     OMPExecutableDirective *S) {
02317   for (auto *C : S->clauses()) {
02318     TRY_TO(TraverseOMPClause(C));
02319   }
02320   return true;
02321 }
02322 
02323 template <typename Derived>
02324 bool
02325 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
02326   return TraverseOMPExecutableDirective(S);
02327 }
02328 
02329 DEF_TRAVERSE_STMT(OMPParallelDirective,
02330                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02331 
02332 DEF_TRAVERSE_STMT(OMPSimdDirective,
02333                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02334 
02335 DEF_TRAVERSE_STMT(OMPForDirective,
02336                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02337 
02338 DEF_TRAVERSE_STMT(OMPForSimdDirective,
02339                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02340 
02341 DEF_TRAVERSE_STMT(OMPSectionsDirective,
02342                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02343 
02344 DEF_TRAVERSE_STMT(OMPSectionDirective,
02345                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02346 
02347 DEF_TRAVERSE_STMT(OMPSingleDirective,
02348                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02349 
02350 DEF_TRAVERSE_STMT(OMPMasterDirective,
02351                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02352 
02353 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
02354   TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
02355   TRY_TO(TraverseOMPExecutableDirective(S));
02356 })
02357 
02358 DEF_TRAVERSE_STMT(OMPParallelForDirective,
02359                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02360 
02361 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
02362                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02363 
02364 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
02365                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02366 
02367 DEF_TRAVERSE_STMT(OMPTaskDirective,
02368                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02369 
02370 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
02371                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02372 
02373 DEF_TRAVERSE_STMT(OMPBarrierDirective,
02374                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02375 
02376 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
02377                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02378 
02379 DEF_TRAVERSE_STMT(OMPFlushDirective,
02380                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02381 
02382 DEF_TRAVERSE_STMT(OMPOrderedDirective,
02383                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02384 
02385 DEF_TRAVERSE_STMT(OMPAtomicDirective,
02386                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02387 
02388 DEF_TRAVERSE_STMT(OMPTargetDirective,
02389                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02390 
02391 DEF_TRAVERSE_STMT(OMPTeamsDirective,
02392                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
02393 
02394 // OpenMP clauses.
02395 template <typename Derived>
02396 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
02397   if (!C)
02398     return true;
02399   switch (C->getClauseKind()) {
02400 #define OPENMP_CLAUSE(Name, Class)                                             \
02401   case OMPC_##Name:                                                            \
02402     TRY_TO(Visit##Class(static_cast<Class *>(C)));                             \
02403     break;
02404 #include "clang/Basic/OpenMPKinds.def"
02405   case OMPC_threadprivate:
02406   case OMPC_unknown:
02407     break;
02408   }
02409   return true;
02410 }
02411 
02412 template <typename Derived>
02413 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
02414   TRY_TO(TraverseStmt(C->getCondition()));
02415   return true;
02416 }
02417 
02418 template <typename Derived>
02419 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
02420   TRY_TO(TraverseStmt(C->getCondition()));
02421   return true;
02422 }
02423 
02424 template <typename Derived>
02425 bool
02426 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
02427   TRY_TO(TraverseStmt(C->getNumThreads()));
02428   return true;
02429 }
02430 
02431 template <typename Derived>
02432 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
02433   TRY_TO(TraverseStmt(C->getSafelen()));
02434   return true;
02435 }
02436 
02437 template <typename Derived>
02438 bool
02439 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
02440   TRY_TO(TraverseStmt(C->getNumForLoops()));
02441   return true;
02442 }
02443 
02444 template <typename Derived>
02445 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
02446   return true;
02447 }
02448 
02449 template <typename Derived>
02450 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
02451   return true;
02452 }
02453 
02454 template <typename Derived>
02455 bool
02456 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
02457   TRY_TO(TraverseStmt(C->getChunkSize()));
02458   return true;
02459 }
02460 
02461 template <typename Derived>
02462 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
02463   return true;
02464 }
02465 
02466 template <typename Derived>
02467 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
02468   return true;
02469 }
02470 
02471 template <typename Derived>
02472 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
02473   return true;
02474 }
02475 
02476 template <typename Derived>
02477 bool
02478 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
02479   return true;
02480 }
02481 
02482 template <typename Derived>
02483 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
02484   return true;
02485 }
02486 
02487 template <typename Derived>
02488 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
02489   return true;
02490 }
02491 
02492 template <typename Derived>
02493 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
02494   return true;
02495 }
02496 
02497 template <typename Derived>
02498 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
02499   return true;
02500 }
02501 
02502 template <typename Derived>
02503 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
02504   return true;
02505 }
02506 
02507 template <typename Derived>
02508 template <typename T>
02509 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
02510   for (auto *E : Node->varlists()) {
02511     TRY_TO(TraverseStmt(E));
02512   }
02513   return true;
02514 }
02515 
02516 template <typename Derived>
02517 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
02518   TRY_TO(VisitOMPClauseList(C));
02519   for (auto *E : C->private_copies()) {
02520     TRY_TO(TraverseStmt(E));
02521   }
02522   return true;
02523 }
02524 
02525 template <typename Derived>
02526 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
02527     OMPFirstprivateClause *C) {
02528   TRY_TO(VisitOMPClauseList(C));
02529   for (auto *E : C->private_copies()) {
02530     TRY_TO(TraverseStmt(E));
02531   }
02532   for (auto *E : C->inits()) {
02533     TRY_TO(TraverseStmt(E));
02534   }
02535   return true;
02536 }
02537 
02538 template <typename Derived>
02539 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
02540     OMPLastprivateClause *C) {
02541   TRY_TO(VisitOMPClauseList(C));
02542   return true;
02543 }
02544 
02545 template <typename Derived>
02546 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
02547   TRY_TO(VisitOMPClauseList(C));
02548   return true;
02549 }
02550 
02551 template <typename Derived>
02552 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
02553   TRY_TO(TraverseStmt(C->getStep()));
02554   TRY_TO(VisitOMPClauseList(C));
02555   return true;
02556 }
02557 
02558 template <typename Derived>
02559 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
02560   TRY_TO(TraverseStmt(C->getAlignment()));
02561   TRY_TO(VisitOMPClauseList(C));
02562   return true;
02563 }
02564 
02565 template <typename Derived>
02566 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
02567   TRY_TO(VisitOMPClauseList(C));
02568   return true;
02569 }
02570 
02571 template <typename Derived>
02572 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
02573     OMPCopyprivateClause *C) {
02574   TRY_TO(VisitOMPClauseList(C));
02575   return true;
02576 }
02577 
02578 template <typename Derived>
02579 bool
02580 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
02581   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
02582   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
02583   TRY_TO(VisitOMPClauseList(C));
02584   return true;
02585 }
02586 
02587 template <typename Derived>
02588 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
02589   TRY_TO(VisitOMPClauseList(C));
02590   return true;
02591 }
02592 
02593 // FIXME: look at the following tricky-seeming exprs to see if we
02594 // need to recurse on anything.  These are ones that have methods
02595 // returning decls or qualtypes or nestednamespecifier -- though I'm
02596 // not sure if they own them -- or just seemed very complicated, or
02597 // had lots of sub-types to explore.
02598 //
02599 // VisitOverloadExpr and its children: recurse on template args? etc?
02600 
02601 // FIXME: go through all the stmts and exprs again, and see which of them
02602 // create new types, and recurse on the types (TypeLocs?) of those.
02603 // Candidates:
02604 //
02605 //    http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
02606 //    http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
02607 //    http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
02608 //    Every class that has getQualifier.
02609 
02610 #undef DEF_TRAVERSE_STMT
02611 
02612 #undef TRY_TO
02613 
02614 } // end namespace clang
02615 
02616 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H