clang API Documentation

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