Home | History | Annotate | Download | only in libclang
      1 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 //  This file defines the RecursiveASTVisitor interface, which recursively
     11 //  traverses the entire AST.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 #ifndef LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H
     15 #define LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H
     16 
     17 #include "clang/AST/Decl.h"
     18 #include "clang/AST/DeclCXX.h"
     19 #include "clang/AST/DeclFriend.h"
     20 #include "clang/AST/DeclObjC.h"
     21 #include "clang/AST/DeclTemplate.h"
     22 #include "clang/AST/Expr.h"
     23 #include "clang/AST/ExprCXX.h"
     24 #include "clang/AST/ExprObjC.h"
     25 #include "clang/AST/NestedNameSpecifier.h"
     26 #include "clang/AST/Stmt.h"
     27 #include "clang/AST/StmtCXX.h"
     28 #include "clang/AST/StmtObjC.h"
     29 #include "clang/AST/TemplateBase.h"
     30 #include "clang/AST/TemplateName.h"
     31 #include "clang/AST/Type.h"
     32 #include "clang/AST/TypeLoc.h"
     33 
     34 // The following three macros are used for meta programming.  The code
     35 // using them is responsible for defining macro OPERATOR().
     36 
     37 // All unary operators.
     38 #define UNARYOP_LIST()                          \
     39   OPERATOR(PostInc)   OPERATOR(PostDec)         \
     40   OPERATOR(PreInc)    OPERATOR(PreDec)          \
     41   OPERATOR(AddrOf)    OPERATOR(Deref)           \
     42   OPERATOR(Plus)      OPERATOR(Minus)           \
     43   OPERATOR(Not)       OPERATOR(LNot)            \
     44   OPERATOR(Real)      OPERATOR(Imag)            \
     45   OPERATOR(Extension)
     46 
     47 // All binary operators (excluding compound assign operators).
     48 #define BINOP_LIST() \
     49   OPERATOR(PtrMemD)              OPERATOR(PtrMemI)    \
     50   OPERATOR(Mul)   OPERATOR(Div)  OPERATOR(Rem)        \
     51   OPERATOR(Add)   OPERATOR(Sub)  OPERATOR(Shl)        \
     52   OPERATOR(Shr)                                       \
     53                                                       \
     54   OPERATOR(LT)    OPERATOR(GT)   OPERATOR(LE)         \
     55   OPERATOR(GE)    OPERATOR(EQ)   OPERATOR(NE)         \
     56   OPERATOR(And)   OPERATOR(Xor)  OPERATOR(Or)         \
     57   OPERATOR(LAnd)  OPERATOR(LOr)                       \
     58                                                       \
     59   OPERATOR(Assign)                                    \
     60   OPERATOR(Comma)
     61 
     62 // All compound assign operators.
     63 #define CAO_LIST()                                                      \
     64   OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \
     65   OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or)  OPERATOR(Xor)
     66 
     67 namespace clang {
     68 namespace cxindex {
     69 
     70 // A helper macro to implement short-circuiting when recursing.  It
     71 // invokes CALL_EXPR, which must be a method call, on the derived
     72 // object (s.t. a user of RecursiveASTVisitor can override the method
     73 // in CALL_EXPR).
     74 #define TRY_TO(CALL_EXPR) \
     75   do { if (!getDerived().CALL_EXPR) return false; } while (0)
     76 
     77 /// \brief A class that does preorder depth-first traversal on the
     78 /// entire Clang AST and visits each node.
     79 ///
     80 /// This class performs three distinct tasks:
     81 ///   1. traverse the AST (i.e. go to each node);
     82 ///   2. at a given node, walk up the class hierarchy, starting from
     83 ///      the node's dynamic type, until the top-most class (e.g. Stmt,
     84 ///      Decl, or Type) is reached.
     85 ///   3. given a (node, class) combination, where 'class' is some base
     86 ///      class of the dynamic type of 'node', call a user-overridable
     87 ///      function to actually visit the node.
     88 ///
     89 /// These tasks are done by three groups of methods, respectively:
     90 ///   1. TraverseDecl(Decl *x) does task #1.  It is the entry point
     91 ///      for traversing an AST rooted at x.  This method simply
     92 ///      dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
     93 ///      is the dynamic type of *x, which calls WalkUpFromFoo(x) and
     94 ///      then recursively visits the child nodes of x.
     95 ///      TraverseStmt(Stmt *x) and TraverseType(QualType x) work
     96 ///      similarly.
     97 ///   2. WalkUpFromFoo(Foo *x) does task #2.  It does not try to visit
     98 ///      any child node of x.  Instead, it first calls WalkUpFromBar(x)
     99 ///      where Bar is the direct parent class of Foo (unless Foo has
    100 ///      no parent), and then calls VisitFoo(x) (see the next list item).
    101 ///   3. VisitFoo(Foo *x) does task #3.
    102 ///
    103 /// These three method groups are tiered (Traverse* > WalkUpFrom* >
    104 /// Visit*).  A method (e.g. Traverse*) may call methods from the same
    105 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
    106 /// It may not call methods from a higher tier.
    107 ///
    108 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
    109 /// is Foo's super class) before calling VisitFoo(), the result is
    110 /// that the Visit*() methods for a given node are called in the
    111 /// top-down order (e.g. for a node of type NamedDecl, the order will
    112 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
    113 ///
    114 /// This scheme guarantees that all Visit*() calls for the same AST
    115 /// node are grouped together.  In other words, Visit*() methods for
    116 /// different nodes are never interleaved.
    117 ///
    118 /// Stmts are traversed internally using a data queue to avoid a stack overflow
    119 /// with hugely nested ASTs.
    120 ///
    121 /// Clients of this visitor should subclass the visitor (providing
    122 /// themselves as the template argument, using the curiously recurring
    123 /// template pattern) and override any of the Traverse*, WalkUpFrom*,
    124 /// and Visit* methods for declarations, types, statements,
    125 /// expressions, or other AST nodes where the visitor should customize
    126 /// behavior.  Most users only need to override Visit*.  Advanced
    127 /// users may override Traverse* and WalkUpFrom* to implement custom
    128 /// traversal strategies.  Returning false from one of these overridden
    129 /// functions will abort the entire traversal.
    130 ///
    131 /// By default, this visitor tries to visit every part of the explicit
    132 /// source code exactly once.  The default policy towards templates
    133 /// is to descend into the 'pattern' class or function body, not any
    134 /// explicit or implicit instantiations.  Explicit specializations
    135 /// are still visited, and the patterns of partial specializations
    136 /// are visited separately.  This behavior can be changed by
    137 /// overriding shouldVisitTemplateInstantiations() in the derived class
    138 /// to return true, in which case all known implicit and explicit
    139 /// instantiations will be visited at the same time as the pattern
    140 /// from which they were produced.
    141 template<typename Derived>
    142 class RecursiveASTVisitor {
    143 public:
    144   /// \brief Return a reference to the derived class.
    145   Derived &getDerived() { return *static_cast<Derived*>(this); }
    146 
    147   /// \brief Return whether this visitor should recurse into
    148   /// template instantiations.
    149   bool shouldVisitTemplateInstantiations() const { return false; }
    150 
    151   /// \brief Return whether this visitor should recurse into the types of
    152   /// TypeLocs.
    153   bool shouldWalkTypesOfTypeLocs() const { return true; }
    154 
    155   /// \brief Recursively visit a statement or expression, by
    156   /// dispatching to Traverse*() based on the argument's dynamic type.
    157   ///
    158   /// \returns false if the visitation was terminated early, true
    159   /// otherwise (including when the argument is NULL).
    160   bool TraverseStmt(Stmt *S);
    161 
    162   /// \brief Recursively visit a type, by dispatching to
    163   /// Traverse*Type() based on the argument's getTypeClass() property.
    164   ///
    165   /// \returns false if the visitation was terminated early, true
    166   /// otherwise (including when the argument is a Null type).
    167   bool TraverseType(QualType T);
    168 
    169   /// \brief Recursively visit a type with location, by dispatching to
    170   /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
    171   ///
    172   /// \returns false if the visitation was terminated early, true
    173   /// otherwise (including when the argument is a Null type location).
    174   bool TraverseTypeLoc(TypeLoc TL);
    175 
    176   /// \brief Recursively visit a declaration, by dispatching to
    177   /// Traverse*Decl() based on the argument's dynamic type.
    178   ///
    179   /// \returns false if the visitation was terminated early, true
    180   /// otherwise (including when the argument is NULL).
    181   bool TraverseDecl(Decl *D);
    182 
    183   /// \brief Recursively visit a C++ nested-name-specifier.
    184   ///
    185   /// \returns false if the visitation was terminated early, true otherwise.
    186   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
    187 
    188   /// \brief Recursively visit a C++ nested-name-specifier with location
    189   /// information.
    190   ///
    191   /// \returns false if the visitation was terminated early, true otherwise.
    192   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
    193 
    194   /// \brief Recursively visit a name with its location information.
    195   ///
    196   /// \returns false if the visitation was terminated early, true otherwise.
    197   bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
    198 
    199   /// \brief Recursively visit a template name and dispatch to the
    200   /// appropriate method.
    201   ///
    202   /// \returns false if the visitation was terminated early, true otherwise.
    203   bool TraverseTemplateName(TemplateName Template);
    204 
    205   /// \brief Recursively visit a template argument and dispatch to the
    206   /// appropriate method for the argument type.
    207   ///
    208   /// \returns false if the visitation was terminated early, true otherwise.
    209   // FIXME: migrate callers to TemplateArgumentLoc instead.
    210   bool TraverseTemplateArgument(const TemplateArgument &Arg);
    211 
    212   /// \brief Recursively visit a template argument location and dispatch to the
    213   /// appropriate method for the argument type.
    214   ///
    215   /// \returns false if the visitation was terminated early, true otherwise.
    216   bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
    217 
    218   /// \brief Recursively visit a set of template arguments.
    219   /// This can be overridden by a subclass, but it's not expected that
    220   /// will be needed -- this visitor always dispatches to another.
    221   ///
    222   /// \returns false if the visitation was terminated early, true otherwise.
    223   // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
    224   bool TraverseTemplateArguments(const TemplateArgument *Args,
    225                                  unsigned NumArgs);
    226 
    227   /// \brief Recursively visit a constructor initializer.  This
    228   /// automatically dispatches to another visitor for the initializer
    229   /// expression, but not for the name of the initializer, so may
    230   /// be overridden for clients that need access to the name.
    231   ///
    232   /// \returns false if the visitation was terminated early, true otherwise.
    233   bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
    234 
    235   /// \brief Recursively visit a lambda capture.
    236   ///
    237   /// \returns false if the visitation was terminated early, true otherwise.
    238   bool TraverseLambdaCapture(LambdaExpr::Capture C);
    239 
    240   // ---- Methods on Stmts ----
    241 
    242   // Declare Traverse*() for all concrete Stmt classes.
    243 #define ABSTRACT_STMT(STMT)
    244 #define STMT(CLASS, PARENT)                                     \
    245   bool Traverse##CLASS(CLASS *S);
    246 #include "clang/AST/StmtNodes.inc"
    247   // The above header #undefs ABSTRACT_STMT and STMT upon exit.
    248 
    249   // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
    250   bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
    251   bool VisitStmt(Stmt *S) { return true; }
    252 #define STMT(CLASS, PARENT)                                     \
    253   bool WalkUpFrom##CLASS(CLASS *S) {                            \
    254     TRY_TO(WalkUpFrom##PARENT(S));                              \
    255     TRY_TO(Visit##CLASS(S));                                    \
    256     return true;                                                \
    257   }                                                             \
    258   bool Visit##CLASS(CLASS *S) { return true; }
    259 #include "clang/AST/StmtNodes.inc"
    260 
    261   // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
    262   // operator methods.  Unary operators are not classes in themselves
    263   // (they're all opcodes in UnaryOperator) but do have visitors.
    264 #define OPERATOR(NAME)                                           \
    265   bool TraverseUnary##NAME(UnaryOperator *S) {                  \
    266     TRY_TO(WalkUpFromUnary##NAME(S));                           \
    267     StmtQueueAction StmtQueue(*this);                           \
    268     StmtQueue.queue(S->getSubExpr());                           \
    269     return true;                                                \
    270   }                                                             \
    271   bool WalkUpFromUnary##NAME(UnaryOperator *S) {                \
    272     TRY_TO(WalkUpFromUnaryOperator(S));                         \
    273     TRY_TO(VisitUnary##NAME(S));                                \
    274     return true;                                                \
    275   }                                                             \
    276   bool VisitUnary##NAME(UnaryOperator *S) { return true; }
    277 
    278   UNARYOP_LIST()
    279 #undef OPERATOR
    280 
    281   // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
    282   // operator methods.  Binary operators are not classes in themselves
    283   // (they're all opcodes in BinaryOperator) but do have visitors.
    284 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE)                \
    285   bool TraverseBin##NAME(BINOP_TYPE *S) {                       \
    286     TRY_TO(WalkUpFromBin##NAME(S));                             \
    287     StmtQueueAction StmtQueue(*this);                           \
    288     StmtQueue.queue(S->getLHS());                               \
    289     StmtQueue.queue(S->getRHS());                               \
    290     return true;                                                \
    291   }                                                             \
    292   bool WalkUpFromBin##NAME(BINOP_TYPE *S) {                     \
    293     TRY_TO(WalkUpFrom##BINOP_TYPE(S));                          \
    294     TRY_TO(VisitBin##NAME(S));                                  \
    295     return true;                                                \
    296   }                                                             \
    297   bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
    298 
    299 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
    300   BINOP_LIST()
    301 #undef OPERATOR
    302 
    303   // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
    304   // assignment methods.  Compound assignment operators are not
    305   // classes in themselves (they're all opcodes in
    306   // CompoundAssignOperator) but do have visitors.
    307 #define OPERATOR(NAME) \
    308   GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
    309 
    310   CAO_LIST()
    311 #undef OPERATOR
    312 #undef GENERAL_BINOP_FALLBACK
    313 
    314   // ---- Methods on Types ----
    315   // FIXME: revamp to take TypeLoc's rather than Types.
    316 
    317   // Declare Traverse*() for all concrete Type classes.
    318 #define ABSTRACT_TYPE(CLASS, BASE)
    319 #define TYPE(CLASS, BASE) \
    320   bool Traverse##CLASS##Type(CLASS##Type *T);
    321 #include "clang/AST/TypeNodes.def"
    322   // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
    323 
    324   // Define WalkUpFrom*() and empty Visit*() for all Type classes.
    325   bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
    326   bool VisitType(Type *T) { return true; }
    327 #define TYPE(CLASS, BASE)                                       \
    328   bool WalkUpFrom##CLASS##Type(CLASS##Type *T) {                \
    329     TRY_TO(WalkUpFrom##BASE(T));                                \
    330     TRY_TO(Visit##CLASS##Type(T));                              \
    331     return true;                                                \
    332   }                                                             \
    333   bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
    334 #include "clang/AST/TypeNodes.def"
    335 
    336   // ---- Methods on TypeLocs ----
    337   // FIXME: this currently just calls the matching Type methods
    338 
    339   // Declare Traverse*() for all concrete Type classes.
    340 #define ABSTRACT_TYPELOC(CLASS, BASE)
    341 #define TYPELOC(CLASS, BASE) \
    342   bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
    343 #include "clang/AST/TypeLocNodes.def"
    344   // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
    345 
    346   // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
    347   bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
    348   bool VisitTypeLoc(TypeLoc TL) { return true; }
    349 
    350   // QualifiedTypeLoc and UnqualTypeLoc are not declared in
    351   // TypeNodes.def and thus need to be handled specially.
    352   bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
    353     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
    354   }
    355   bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
    356   bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
    357     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
    358   }
    359   bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
    360 
    361   // Note that BASE includes trailing 'Type' which CLASS doesn't.
    362 #define TYPE(CLASS, BASE)                                       \
    363   bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) {          \
    364     TRY_TO(WalkUpFrom##BASE##Loc(TL));                          \
    365     TRY_TO(Visit##CLASS##TypeLoc(TL));                          \
    366     return true;                                                \
    367   }                                                             \
    368   bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
    369 #include "clang/AST/TypeNodes.def"
    370 
    371   // ---- Methods on Decls ----
    372 
    373   // Declare Traverse*() for all concrete Decl classes.
    374 #define ABSTRACT_DECL(DECL)
    375 #define DECL(CLASS, BASE) \
    376   bool Traverse##CLASS##Decl(CLASS##Decl *D);
    377 #include "clang/AST/DeclNodes.inc"
    378   // The above header #undefs ABSTRACT_DECL and DECL upon exit.
    379 
    380   // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
    381   bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
    382   bool VisitDecl(Decl *D) { return true; }
    383 #define DECL(CLASS, BASE)                                       \
    384   bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) {                \
    385     TRY_TO(WalkUpFrom##BASE(D));                                \
    386     TRY_TO(Visit##CLASS##Decl(D));                              \
    387     return true;                                                \
    388   }                                                             \
    389   bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
    390 #include "clang/AST/DeclNodes.inc"
    391 
    392 private:
    393   // These are helper methods used by more than one Traverse* method.
    394   bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
    395   bool TraverseClassInstantiations(ClassTemplateDecl *D);
    396   bool TraverseFunctionInstantiations(FunctionTemplateDecl *D) ;
    397   bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
    398                                           unsigned Count);
    399   bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
    400   bool TraverseRecordHelper(RecordDecl *D);
    401   bool TraverseCXXRecordHelper(CXXRecordDecl *D);
    402   bool TraverseDeclaratorHelper(DeclaratorDecl *D);
    403   bool TraverseDeclContextHelper(DeclContext *DC);
    404   bool TraverseFunctionHelper(FunctionDecl *D);
    405   bool TraverseVarHelper(VarDecl *D);
    406 
    407   typedef SmallVector<Stmt *, 16> StmtsTy;
    408   typedef SmallVector<StmtsTy *, 4> QueuesTy;
    409 
    410   QueuesTy Queues;
    411 
    412   class NewQueueRAII {
    413     RecursiveASTVisitor &RAV;
    414   public:
    415     NewQueueRAII(StmtsTy &queue, RecursiveASTVisitor &RAV) : RAV(RAV) {
    416       RAV.Queues.push_back(&queue);
    417     }
    418     ~NewQueueRAII() {
    419       RAV.Queues.pop_back();
    420     }
    421   };
    422 
    423   StmtsTy &getCurrentQueue() {
    424     assert(!Queues.empty() && "base TraverseStmt was never called?");
    425     return *Queues.back();
    426   }
    427 
    428 public:
    429   class StmtQueueAction {
    430     StmtsTy &CurrQueue;
    431   public:
    432     explicit StmtQueueAction(RecursiveASTVisitor &RAV)
    433       : CurrQueue(RAV.getCurrentQueue()) { }
    434 
    435     void queue(Stmt *S) {
    436       CurrQueue.push_back(S);
    437     }
    438   };
    439 };
    440 
    441 #define DISPATCH(NAME, CLASS, VAR) \
    442   return getDerived().Traverse##NAME(static_cast<CLASS*>(VAR))
    443 
    444 template<typename Derived>
    445 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S) {
    446   if (!S)
    447     return true;
    448 
    449   StmtsTy Queue, StmtsToEnqueu;
    450   Queue.push_back(S);
    451   NewQueueRAII NQ(StmtsToEnqueu, *this);
    452 
    453   while (!Queue.empty()) {
    454     S = Queue.pop_back_val();
    455     if (!S)
    456       continue;
    457 
    458     StmtsToEnqueu.clear();
    459 
    460 #define DISPATCH_STMT(NAME, CLASS, VAR) \
    461     TRY_TO(Traverse##NAME(static_cast<CLASS*>(VAR))); break
    462 
    463     // If we have a binary expr, dispatch to the subcode of the binop.  A smart
    464     // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
    465     // below.
    466     if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
    467       switch (BinOp->getOpcode()) {
    468 #define OPERATOR(NAME) \
    469       case BO_##NAME: DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
    470 
    471       BINOP_LIST()
    472 #undef OPERATOR
    473 #undef BINOP_LIST
    474 
    475 #define OPERATOR(NAME)                                          \
    476       case BO_##NAME##Assign:                          \
    477         DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
    478 
    479       CAO_LIST()
    480 #undef OPERATOR
    481 #undef CAO_LIST
    482       }
    483     } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
    484       switch (UnOp->getOpcode()) {
    485 #define OPERATOR(NAME)                                                  \
    486       case UO_##NAME: DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
    487 
    488       UNARYOP_LIST()
    489 #undef OPERATOR
    490 #undef UNARYOP_LIST
    491       }
    492     } else {
    493 
    494       // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
    495       switch (S->getStmtClass()) {
    496       case Stmt::NoStmtClass: break;
    497 #define ABSTRACT_STMT(STMT)
    498 #define STMT(CLASS, PARENT) \
    499       case Stmt::CLASS##Class: DISPATCH_STMT(CLASS, CLASS, S);
    500 #include "clang/AST/StmtNodes.inc"
    501       }
    502     }
    503 
    504     for (SmallVector<Stmt *, 8>::reverse_iterator
    505            RI = StmtsToEnqueu.rbegin(),
    506            RE = StmtsToEnqueu.rend(); RI != RE; ++RI)
    507       Queue.push_back(*RI);
    508   }
    509 
    510   return true;
    511 }
    512 
    513 template<typename Derived>
    514 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
    515   if (T.isNull())
    516     return true;
    517 
    518   switch (T->getTypeClass()) {
    519 #define ABSTRACT_TYPE(CLASS, BASE)
    520 #define TYPE(CLASS, BASE) \
    521   case Type::CLASS: DISPATCH(CLASS##Type, CLASS##Type, \
    522                              const_cast<Type*>(T.getTypePtr()));
    523 #include "clang/AST/TypeNodes.def"
    524   }
    525 
    526   return true;
    527 }
    528 
    529 template<typename Derived>
    530 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
    531   if (TL.isNull())
    532     return true;
    533 
    534   switch (TL.getTypeLocClass()) {
    535 #define ABSTRACT_TYPELOC(CLASS, BASE)
    536 #define TYPELOC(CLASS, BASE) \
    537   case TypeLoc::CLASS: \
    538     return getDerived().Traverse##CLASS##TypeLoc(*cast<CLASS##TypeLoc>(&TL));
    539 #include "clang/AST/TypeLocNodes.def"
    540   }
    541 
    542   return true;
    543 }
    544 
    545 
    546 template<typename Derived>
    547 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
    548   if (!D)
    549     return true;
    550 
    551   // As a syntax visitor, we want to ignore declarations for
    552   // implicitly-defined declarations (ones not typed explicitly by the
    553   // user).
    554   if (D->isImplicit())
    555     return true;
    556 
    557   switch (D->getKind()) {
    558 #define ABSTRACT_DECL(DECL)
    559 #define DECL(CLASS, BASE) \
    560   case Decl::CLASS: DISPATCH(CLASS##Decl, CLASS##Decl, D);
    561 #include "clang/AST/DeclNodes.inc"
    562  }
    563 
    564   return true;
    565 }
    566 
    567 #undef DISPATCH
    568 
    569 template<typename Derived>
    570 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
    571                                                     NestedNameSpecifier *NNS) {
    572   if (!NNS)
    573     return true;
    574 
    575   if (NNS->getPrefix())
    576     TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
    577 
    578   switch (NNS->getKind()) {
    579   case NestedNameSpecifier::Identifier:
    580   case NestedNameSpecifier::Namespace:
    581   case NestedNameSpecifier::NamespaceAlias:
    582   case NestedNameSpecifier::Global:
    583     return true;
    584 
    585   case NestedNameSpecifier::TypeSpec:
    586   case NestedNameSpecifier::TypeSpecWithTemplate:
    587     TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
    588   }
    589 
    590   return true;
    591 }
    592 
    593 template<typename Derived>
    594 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
    595                                                   NestedNameSpecifierLoc NNS) {
    596   if (!NNS)
    597     return true;
    598 
    599    if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
    600      TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
    601 
    602   switch (NNS.getNestedNameSpecifier()->getKind()) {
    603   case NestedNameSpecifier::Identifier:
    604   case NestedNameSpecifier::Namespace:
    605   case NestedNameSpecifier::NamespaceAlias:
    606   case NestedNameSpecifier::Global:
    607     return true;
    608 
    609   case NestedNameSpecifier::TypeSpec:
    610   case NestedNameSpecifier::TypeSpecWithTemplate:
    611     TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
    612     break;
    613   }
    614 
    615   return true;
    616 }
    617 
    618 template<typename Derived>
    619 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
    620                                                  DeclarationNameInfo NameInfo) {
    621   switch (NameInfo.getName().getNameKind()) {
    622   case DeclarationName::CXXConstructorName:
    623   case DeclarationName::CXXDestructorName:
    624   case DeclarationName::CXXConversionFunctionName:
    625     if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
    626       TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
    627 
    628     break;
    629 
    630   case DeclarationName::Identifier:
    631   case DeclarationName::ObjCZeroArgSelector:
    632   case DeclarationName::ObjCOneArgSelector:
    633   case DeclarationName::ObjCMultiArgSelector:
    634   case DeclarationName::CXXOperatorName:
    635   case DeclarationName::CXXLiteralOperatorName:
    636   case DeclarationName::CXXUsingDirective:
    637     break;
    638   }
    639 
    640   return true;
    641 }
    642 
    643 template<typename Derived>
    644 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
    645   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
    646     TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
    647   else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
    648     TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
    649 
    650   return true;
    651 }
    652 
    653 template<typename Derived>
    654 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
    655                                                 const TemplateArgument &Arg) {
    656   switch (Arg.getKind()) {
    657   case TemplateArgument::Null:
    658   case TemplateArgument::Declaration:
    659   case TemplateArgument::Integral:
    660     return true;
    661 
    662   case TemplateArgument::Type:
    663     return getDerived().TraverseType(Arg.getAsType());
    664 
    665   case TemplateArgument::Template:
    666   case TemplateArgument::TemplateExpansion:
    667     return getDerived().TraverseTemplateName(
    668                                           Arg.getAsTemplateOrTemplatePattern());
    669 
    670   case TemplateArgument::Expression:
    671     return getDerived().TraverseStmt(Arg.getAsExpr());
    672 
    673   case TemplateArgument::Pack:
    674     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
    675                                                   Arg.pack_size());
    676   }
    677 
    678   return true;
    679 }
    680 
    681 // FIXME: no template name location?
    682 // FIXME: no source locations for a template argument pack?
    683 template<typename Derived>
    684 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
    685                                            const TemplateArgumentLoc &ArgLoc) {
    686   const TemplateArgument &Arg = ArgLoc.getArgument();
    687 
    688   switch (Arg.getKind()) {
    689   case TemplateArgument::Null:
    690   case TemplateArgument::Declaration:
    691   case TemplateArgument::Integral:
    692     return true;
    693 
    694   case TemplateArgument::Type: {
    695     // FIXME: how can TSI ever be NULL?
    696     if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
    697       return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
    698     else
    699       return getDerived().TraverseType(Arg.getAsType());
    700   }
    701 
    702   case TemplateArgument::Template:
    703   case TemplateArgument::TemplateExpansion:
    704     if (ArgLoc.getTemplateQualifierLoc())
    705       TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
    706                                             ArgLoc.getTemplateQualifierLoc()));
    707     return getDerived().TraverseTemplateName(
    708                                          Arg.getAsTemplateOrTemplatePattern());
    709 
    710   case TemplateArgument::Expression:
    711     return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
    712 
    713   case TemplateArgument::Pack:
    714     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
    715                                                   Arg.pack_size());
    716   }
    717 
    718   return true;
    719 }
    720 
    721 template<typename Derived>
    722 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
    723                                                   const TemplateArgument *Args,
    724                                                             unsigned NumArgs) {
    725   for (unsigned I = 0; I != NumArgs; ++I) {
    726     TRY_TO(TraverseTemplateArgument(Args[I]));
    727   }
    728 
    729   return true;
    730 }
    731 
    732 template<typename Derived>
    733 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
    734                                                      CXXCtorInitializer *Init) {
    735   if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
    736     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
    737 
    738   if (Init->isWritten())
    739     TRY_TO(TraverseStmt(Init->getInit()));
    740   return true;
    741 }
    742 
    743 template<typename Derived>
    744 bool RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr::Capture C){
    745   return true;
    746 }
    747 
    748 // ----------------- Type traversal -----------------
    749 
    750 // This macro makes available a variable T, the passed-in type.
    751 #define DEF_TRAVERSE_TYPE(TYPE, CODE)                     \
    752   template<typename Derived>                                           \
    753   bool RecursiveASTVisitor<Derived>::Traverse##TYPE (TYPE *T) {        \
    754     TRY_TO(WalkUpFrom##TYPE (T));                                      \
    755     { CODE; }                                                          \
    756     return true;                                                       \
    757   }
    758 
    759 DEF_TRAVERSE_TYPE(BuiltinType, { })
    760 
    761 DEF_TRAVERSE_TYPE(ComplexType, {
    762     TRY_TO(TraverseType(T->getElementType()));
    763   })
    764 
    765 DEF_TRAVERSE_TYPE(PointerType, {
    766     TRY_TO(TraverseType(T->getPointeeType()));
    767   })
    768 
    769 DEF_TRAVERSE_TYPE(BlockPointerType, {
    770     TRY_TO(TraverseType(T->getPointeeType()));
    771   })
    772 
    773 DEF_TRAVERSE_TYPE(LValueReferenceType, {
    774     TRY_TO(TraverseType(T->getPointeeType()));
    775   })
    776 
    777 DEF_TRAVERSE_TYPE(RValueReferenceType, {
    778     TRY_TO(TraverseType(T->getPointeeType()));
    779   })
    780 
    781 DEF_TRAVERSE_TYPE(MemberPointerType, {
    782     TRY_TO(TraverseType(QualType(T->getClass(), 0)));
    783     TRY_TO(TraverseType(T->getPointeeType()));
    784   })
    785 
    786 DEF_TRAVERSE_TYPE(ConstantArrayType, {
    787     TRY_TO(TraverseType(T->getElementType()));
    788   })
    789 
    790 DEF_TRAVERSE_TYPE(IncompleteArrayType, {
    791     TRY_TO(TraverseType(T->getElementType()));
    792   })
    793 
    794 DEF_TRAVERSE_TYPE(VariableArrayType, {
    795     TRY_TO(TraverseType(T->getElementType()));
    796     TRY_TO(TraverseStmt(T->getSizeExpr()));
    797   })
    798 
    799 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
    800     TRY_TO(TraverseType(T->getElementType()));
    801     if (T->getSizeExpr())
    802       TRY_TO(TraverseStmt(T->getSizeExpr()));
    803   })
    804 
    805 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
    806     if (T->getSizeExpr())
    807       TRY_TO(TraverseStmt(T->getSizeExpr()));
    808     TRY_TO(TraverseType(T->getElementType()));
    809   })
    810 
    811 DEF_TRAVERSE_TYPE(VectorType, {
    812     TRY_TO(TraverseType(T->getElementType()));
    813   })
    814 
    815 DEF_TRAVERSE_TYPE(ExtVectorType, {
    816     TRY_TO(TraverseType(T->getElementType()));
    817   })
    818 
    819 DEF_TRAVERSE_TYPE(FunctionNoProtoType, {
    820     TRY_TO(TraverseType(T->getResultType()));
    821   })
    822 
    823 DEF_TRAVERSE_TYPE(FunctionProtoType, {
    824     TRY_TO(TraverseType(T->getResultType()));
    825 
    826     for (FunctionProtoType::arg_type_iterator A = T->arg_type_begin(),
    827                                            AEnd = T->arg_type_end();
    828          A != AEnd; ++A) {
    829       TRY_TO(TraverseType(*A));
    830     }
    831 
    832     for (FunctionProtoType::exception_iterator E = T->exception_begin(),
    833                                             EEnd = T->exception_end();
    834          E != EEnd; ++E) {
    835       TRY_TO(TraverseType(*E));
    836     }
    837   })
    838 
    839 DEF_TRAVERSE_TYPE(UnresolvedUsingType, { })
    840 DEF_TRAVERSE_TYPE(TypedefType, { })
    841 
    842 DEF_TRAVERSE_TYPE(TypeOfExprType, {
    843     TRY_TO(TraverseStmt(T->getUnderlyingExpr()));
    844   })
    845 
    846 DEF_TRAVERSE_TYPE(TypeOfType, {
    847     TRY_TO(TraverseType(T->getUnderlyingType()));
    848   })
    849 
    850 DEF_TRAVERSE_TYPE(DecltypeType, {
    851     TRY_TO(TraverseStmt(T->getUnderlyingExpr()));
    852   })
    853 
    854 DEF_TRAVERSE_TYPE(UnaryTransformType, {
    855     TRY_TO(TraverseType(T->getBaseType()));
    856     TRY_TO(TraverseType(T->getUnderlyingType()));
    857     })
    858 
    859 DEF_TRAVERSE_TYPE(AutoType, {
    860     TRY_TO(TraverseType(T->getDeducedType()));
    861   })
    862 
    863 DEF_TRAVERSE_TYPE(RecordType, { })
    864 DEF_TRAVERSE_TYPE(EnumType, { })
    865 DEF_TRAVERSE_TYPE(TemplateTypeParmType, { })
    866 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, { })
    867 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, { })
    868 
    869 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
    870     TRY_TO(TraverseTemplateName(T->getTemplateName()));
    871     TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
    872   })
    873 
    874 DEF_TRAVERSE_TYPE(InjectedClassNameType, { })
    875 
    876 DEF_TRAVERSE_TYPE(AttributedType, {
    877     TRY_TO(TraverseType(T->getModifiedType()));
    878   })
    879 
    880 DEF_TRAVERSE_TYPE(ParenType, {
    881     TRY_TO(TraverseType(T->getInnerType()));
    882   })
    883 
    884 DEF_TRAVERSE_TYPE(ElaboratedType, {
    885     if (T->getQualifier()) {
    886       TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
    887     }
    888     TRY_TO(TraverseType(T->getNamedType()));
    889   })
    890 
    891 DEF_TRAVERSE_TYPE(DependentNameType, {
    892     TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
    893   })
    894 
    895 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
    896     TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
    897     TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
    898   })
    899 
    900 DEF_TRAVERSE_TYPE(PackExpansionType, {
    901     TRY_TO(TraverseType(T->getPattern()));
    902   })
    903 
    904 DEF_TRAVERSE_TYPE(ObjCInterfaceType, { })
    905 
    906 DEF_TRAVERSE_TYPE(ObjCObjectType, {
    907     // We have to watch out here because an ObjCInterfaceType's base
    908     // type is itself.
    909     if (T->getBaseType().getTypePtr() != T)
    910       TRY_TO(TraverseType(T->getBaseType()));
    911   })
    912 
    913 DEF_TRAVERSE_TYPE(ObjCObjectPointerType, {
    914     TRY_TO(TraverseType(T->getPointeeType()));
    915   })
    916 
    917 DEF_TRAVERSE_TYPE(AtomicType, {
    918     TRY_TO(TraverseType(T->getValueType()));
    919   })
    920 
    921 #undef DEF_TRAVERSE_TYPE
    922 
    923 // ----------------- TypeLoc traversal -----------------
    924 
    925 // This macro makes available a variable TL, the passed-in TypeLoc.
    926 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
    927 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
    928 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
    929 // continue to work.
    930 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE)                                \
    931   template<typename Derived>                                            \
    932   bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
    933     if (getDerived().shouldWalkTypesOfTypeLocs())                       \
    934       TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE*>(TL.getTypePtr())));     \
    935     TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                  \
    936     { CODE; }                                                           \
    937     return true;                                                        \
    938   }
    939 
    940 template<typename Derived>
    941 bool RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(
    942     QualifiedTypeLoc TL) {
    943   // Move this over to the 'main' typeloc tree.  Note that this is a
    944   // move -- we pretend that we were really looking at the unqualified
    945   // typeloc all along -- rather than a recursion, so we don't follow
    946   // the normal CRTP plan of going through
    947   // getDerived().TraverseTypeLoc.  If we did, we'd be traversing
    948   // twice for the same type (once as a QualifiedTypeLoc version of
    949   // the type, once as an UnqualifiedTypeLoc version of the type),
    950   // which in effect means we'd call VisitTypeLoc twice with the
    951   // 'same' type.  This solves that problem, at the cost of never
    952   // seeing the qualified version of the type (unless the client
    953   // subclasses TraverseQualifiedTypeLoc themselves).  It's not a
    954   // perfect solution.  A perfect solution probably requires making
    955   // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
    956   // wrapper around Type* -- rather than being its own class in the
    957   // type hierarchy.
    958   return TraverseTypeLoc(TL.getUnqualifiedLoc());
    959 }
    960 
    961 DEF_TRAVERSE_TYPELOC(BuiltinType, { })
    962 
    963 // FIXME: ComplexTypeLoc is unfinished
    964 DEF_TRAVERSE_TYPELOC(ComplexType, {
    965     TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
    966   })
    967 
    968 DEF_TRAVERSE_TYPELOC(PointerType, {
    969     TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
    970   })
    971 
    972 DEF_TRAVERSE_TYPELOC(BlockPointerType, {
    973     TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
    974   })
    975 
    976 DEF_TRAVERSE_TYPELOC(LValueReferenceType, {
    977     TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
    978   })
    979 
    980 DEF_TRAVERSE_TYPELOC(RValueReferenceType, {
    981     TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
    982   })
    983 
    984 // FIXME: location of base class?
    985 // We traverse this in the type case as well, but how is it not reached through
    986 // the pointee type?
    987 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
    988     TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
    989     TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
    990   })
    991 
    992 template<typename Derived>
    993 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
    994   // This isn't available for ArrayType, but is for the ArrayTypeLoc.
    995   TRY_TO(TraverseStmt(TL.getSizeExpr()));
    996   return true;
    997 }
    998 
    999 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
   1000     TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
   1001     return TraverseArrayTypeLocHelper(TL);
   1002   })
   1003 
   1004 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
   1005     TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
   1006     return TraverseArrayTypeLocHelper(TL);
   1007   })
   1008 
   1009 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
   1010     TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
   1011     return TraverseArrayTypeLocHelper(TL);
   1012   })
   1013 
   1014 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
   1015     TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
   1016     return TraverseArrayTypeLocHelper(TL);
   1017   })
   1018 
   1019 // FIXME: order? why not size expr first?
   1020 // FIXME: base VectorTypeLoc is unfinished
   1021 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
   1022     if (TL.getTypePtr()->getSizeExpr())
   1023       TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
   1024     TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1025   })
   1026 
   1027 // FIXME: VectorTypeLoc is unfinished
   1028 DEF_TRAVERSE_TYPELOC(VectorType, {
   1029     TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1030   })
   1031 
   1032 // FIXME: size and attributes
   1033 // FIXME: base VectorTypeLoc is unfinished
   1034 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
   1035     TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1036   })
   1037 
   1038 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType, {
   1039     TRY_TO(TraverseTypeLoc(TL.getResultLoc()));
   1040   })
   1041 
   1042 // FIXME: location of exception specifications (attributes?)
   1043 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
   1044     TRY_TO(TraverseTypeLoc(TL.getResultLoc()));
   1045 
   1046     const FunctionProtoType *T = TL.getTypePtr();
   1047 
   1048     for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
   1049       if (TL.getArg(I)) {
   1050         TRY_TO(TraverseDecl(TL.getArg(I)));
   1051       } else if (I < T->getNumArgs()) {
   1052         TRY_TO(TraverseType(T->getArgType(I)));
   1053       }
   1054     }
   1055 
   1056     for (FunctionProtoType::exception_iterator E = T->exception_begin(),
   1057                                             EEnd = T->exception_end();
   1058          E != EEnd; ++E) {
   1059       TRY_TO(TraverseType(*E));
   1060     }
   1061   })
   1062 
   1063 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, { })
   1064 DEF_TRAVERSE_TYPELOC(TypedefType, { })
   1065 
   1066 DEF_TRAVERSE_TYPELOC(TypeOfExprType, {
   1067     TRY_TO(TraverseStmt(TL.getUnderlyingExpr()));
   1068   })
   1069 
   1070 DEF_TRAVERSE_TYPELOC(TypeOfType, {
   1071     TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
   1072   })
   1073 
   1074 // FIXME: location of underlying expr
   1075 DEF_TRAVERSE_TYPELOC(DecltypeType, {
   1076     TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
   1077   })
   1078 
   1079 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
   1080     TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
   1081   })
   1082 
   1083 DEF_TRAVERSE_TYPELOC(AutoType, {
   1084     TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
   1085   })
   1086 
   1087 DEF_TRAVERSE_TYPELOC(RecordType, { })
   1088 DEF_TRAVERSE_TYPELOC(EnumType, { })
   1089 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, { })
   1090 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, { })
   1091 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, { })
   1092 
   1093 // FIXME: use the loc for the template name?
   1094 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
   1095     TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
   1096     for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
   1097       TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
   1098     }
   1099   })
   1100 
   1101 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, { })
   1102 
   1103 DEF_TRAVERSE_TYPELOC(ParenType, {
   1104     TRY_TO(TraverseTypeLoc(TL.getInnerLoc()));
   1105   })
   1106 
   1107 DEF_TRAVERSE_TYPELOC(AttributedType, {
   1108     TRY_TO(TraverseTypeLoc(TL.getModifiedLoc()));
   1109   })
   1110 
   1111 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
   1112     if (TL.getQualifierLoc()) {
   1113       TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
   1114     }
   1115     TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
   1116   })
   1117 
   1118 DEF_TRAVERSE_TYPELOC(DependentNameType, {
   1119     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
   1120   })
   1121 
   1122 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
   1123     if (TL.getQualifierLoc()) {
   1124       TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
   1125     }
   1126 
   1127     for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
   1128       TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
   1129     }
   1130   })
   1131 
   1132 DEF_TRAVERSE_TYPELOC(PackExpansionType, {
   1133     TRY_TO(TraverseTypeLoc(TL.getPatternLoc()));
   1134   })
   1135 
   1136 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, { })
   1137 
   1138 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
   1139     // We have to watch out here because an ObjCInterfaceType's base
   1140     // type is itself.
   1141     if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
   1142       TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
   1143   })
   1144 
   1145 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType, {
   1146     TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
   1147   })
   1148 
   1149 DEF_TRAVERSE_TYPELOC(AtomicType, {
   1150     TRY_TO(TraverseTypeLoc(TL.getValueLoc()));
   1151   })
   1152 
   1153 #undef DEF_TRAVERSE_TYPELOC
   1154 
   1155 // ----------------- Decl traversal -----------------
   1156 //
   1157 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
   1158 // the children that come from the DeclContext associated with it.
   1159 // Therefore each Traverse* only needs to worry about children other
   1160 // than those.
   1161 
   1162 template<typename Derived>
   1163 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
   1164   if (!DC)
   1165     return true;
   1166 
   1167   for (DeclContext::decl_iterator Child = DC->decls_begin(),
   1168            ChildEnd = DC->decls_end();
   1169        Child != ChildEnd; ++Child) {
   1170     // BlockDecls are traversed through BlockExprs.
   1171     if (!isa<BlockDecl>(*Child))
   1172       TRY_TO(TraverseDecl(*Child));
   1173   }
   1174 
   1175   return true;
   1176 }
   1177 
   1178 // This macro makes available a variable D, the passed-in decl.
   1179 #define DEF_TRAVERSE_DECL(DECL, CODE)                           \
   1180 template<typename Derived>                                      \
   1181 bool RecursiveASTVisitor<Derived>::Traverse##DECL (DECL *D) {   \
   1182   TRY_TO(WalkUpFrom##DECL (D));                                 \
   1183   { CODE; }                                                     \
   1184   TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D)));  \
   1185   return true;                                                  \
   1186 }
   1187 
   1188 DEF_TRAVERSE_DECL(AccessSpecDecl, { })
   1189 
   1190 DEF_TRAVERSE_DECL(BlockDecl, {
   1191     if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
   1192       TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
   1193     TRY_TO(TraverseStmt(D->getBody()));
   1194     // This return statement makes sure the traversal of nodes in
   1195     // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
   1196     // is skipped - don't remove it.
   1197     return true;
   1198   })
   1199 
   1200 DEF_TRAVERSE_DECL(FileScopeAsmDecl, {
   1201     TRY_TO(TraverseStmt(D->getAsmString()));
   1202   })
   1203 
   1204 DEF_TRAVERSE_DECL(ImportDecl, { })
   1205 
   1206 DEF_TRAVERSE_DECL(FriendDecl, {
   1207     // Friend is either decl or a type.
   1208     if (D->getFriendType())
   1209       TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
   1210     else
   1211       TRY_TO(TraverseDecl(D->getFriendDecl()));
   1212   })
   1213 
   1214 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
   1215     if (D->getFriendType())
   1216       TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
   1217     else
   1218       TRY_TO(TraverseDecl(D->getFriendDecl()));
   1219     for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
   1220       TemplateParameterList *TPL = D->getTemplateParameterList(I);
   1221       for (TemplateParameterList::iterator ITPL = TPL->begin(),
   1222                                            ETPL = TPL->end();
   1223            ITPL != ETPL; ++ITPL) {
   1224         TRY_TO(TraverseDecl(*ITPL));
   1225       }
   1226     }
   1227   })
   1228 
   1229 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
   1230   TRY_TO(TraverseDecl(D->getSpecialization()));
   1231  })
   1232 
   1233 DEF_TRAVERSE_DECL(LinkageSpecDecl, { })
   1234 
   1235 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {
   1236     // FIXME: implement this
   1237   })
   1238 
   1239 DEF_TRAVERSE_DECL(StaticAssertDecl, {
   1240     TRY_TO(TraverseStmt(D->getAssertExpr()));
   1241     TRY_TO(TraverseStmt(D->getMessage()));
   1242   })
   1243 
   1244 DEF_TRAVERSE_DECL(TranslationUnitDecl, {
   1245     // Code in an unnamed namespace shows up automatically in
   1246     // decls_begin()/decls_end().  Thus we don't need to recurse on
   1247     // D->getAnonymousNamespace().
   1248   })
   1249 
   1250 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
   1251     // We shouldn't traverse an aliased namespace, since it will be
   1252     // defined (and, therefore, traversed) somewhere else.
   1253     //
   1254     // This return statement makes sure the traversal of nodes in
   1255     // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
   1256     // is skipped - don't remove it.
   1257     return true;
   1258   })
   1259 
   1260 DEF_TRAVERSE_DECL(LabelDecl, {
   1261   // There is no code in a LabelDecl.
   1262 })
   1263 
   1264 
   1265 DEF_TRAVERSE_DECL(NamespaceDecl, {
   1266     // Code in an unnamed namespace shows up automatically in
   1267     // decls_begin()/decls_end().  Thus we don't need to recurse on
   1268     // D->getAnonymousNamespace().
   1269   })
   1270 
   1271 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {
   1272     // FIXME: implement
   1273   })
   1274 
   1275 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {
   1276     // FIXME: implement
   1277   })
   1278 
   1279 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {
   1280     // FIXME: implement
   1281   })
   1282 
   1283 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {
   1284     // FIXME: implement
   1285   })
   1286 
   1287 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {
   1288     // FIXME: implement
   1289   })
   1290 
   1291 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {
   1292     // FIXME: implement
   1293   })
   1294 
   1295 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
   1296     if (D->getResultTypeSourceInfo()) {
   1297       TRY_TO(TraverseTypeLoc(D->getResultTypeSourceInfo()->getTypeLoc()));
   1298     }
   1299     for (ObjCMethodDecl::param_iterator
   1300            I = D->param_begin(), E = D->param_end(); I != E; ++I) {
   1301       TRY_TO(TraverseDecl(*I));
   1302     }
   1303     if (D->isThisDeclarationADefinition()) {
   1304       TRY_TO(TraverseStmt(D->getBody()));
   1305     }
   1306     return true;
   1307   })
   1308 
   1309 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
   1310     // FIXME: implement
   1311   })
   1312 
   1313 DEF_TRAVERSE_DECL(UsingDecl, {
   1314     TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1315     TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
   1316   })
   1317 
   1318 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
   1319     TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1320   })
   1321 
   1322 DEF_TRAVERSE_DECL(UsingShadowDecl, { })
   1323 
   1324 // A helper method for TemplateDecl's children.
   1325 template<typename Derived>
   1326 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
   1327     TemplateParameterList *TPL) {
   1328   if (TPL) {
   1329     for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
   1330          I != E; ++I) {
   1331       TRY_TO(TraverseDecl(*I));
   1332     }
   1333   }
   1334   return true;
   1335 }
   1336 
   1337 // A helper method for traversing the implicit instantiations of a
   1338 // class template.
   1339 template<typename Derived>
   1340 bool RecursiveASTVisitor<Derived>::TraverseClassInstantiations(
   1341     ClassTemplateDecl *D) {
   1342   ClassTemplateDecl::spec_iterator end = D->spec_end();
   1343   for (ClassTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) {
   1344     ClassTemplateSpecializationDecl* SD = *it;
   1345 
   1346     switch (SD->getSpecializationKind()) {
   1347     // Visit the implicit instantiations with the requested pattern.
   1348     case TSK_Undeclared:
   1349     case TSK_ImplicitInstantiation:
   1350       TRY_TO(TraverseDecl(SD));
   1351       break;
   1352 
   1353     // We don't need to do anything on an explicit instantiation
   1354     // or explicit specialization because there will be an explicit
   1355     // node for it elsewhere.
   1356     case TSK_ExplicitInstantiationDeclaration:
   1357     case TSK_ExplicitInstantiationDefinition:
   1358     case TSK_ExplicitSpecialization:
   1359       break;
   1360     }
   1361   }
   1362 
   1363   return true;
   1364 }
   1365 
   1366 DEF_TRAVERSE_DECL(ClassTemplateDecl, {
   1367     CXXRecordDecl* TempDecl = D->getTemplatedDecl();
   1368     TRY_TO(TraverseDecl(TempDecl));
   1369     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
   1370 
   1371     // By default, we do not traverse the instantiations of
   1372     // class templates since they do not appear in the user code. The
   1373     // following code optionally traverses them.
   1374     //
   1375     // We only traverse the class instantiations when we see the canonical
   1376     // declaration of the template, to ensure we only visit them once.
   1377     if (getDerived().shouldVisitTemplateInstantiations() &&
   1378         D == D->getCanonicalDecl())
   1379       TRY_TO(TraverseClassInstantiations(D));
   1380 
   1381     // Note that getInstantiatedFromMemberTemplate() is just a link
   1382     // from a template instantiation back to the template from which
   1383     // it was instantiated, and thus should not be traversed.
   1384   })
   1385 
   1386 // A helper method for traversing the instantiations of a
   1387 // function while skipping its specializations.
   1388 template<typename Derived>
   1389 bool RecursiveASTVisitor<Derived>::TraverseFunctionInstantiations(
   1390     FunctionTemplateDecl *D) {
   1391   FunctionTemplateDecl::spec_iterator end = D->spec_end();
   1392   for (FunctionTemplateDecl::spec_iterator it = D->spec_begin(); it != end;
   1393        ++it) {
   1394     FunctionDecl* FD = *it;
   1395     switch (FD->getTemplateSpecializationKind()) {
   1396     case TSK_Undeclared:
   1397     case TSK_ImplicitInstantiation:
   1398       // We don't know what kind of FunctionDecl this is.
   1399       TRY_TO(TraverseDecl(FD));
   1400       break;
   1401 
   1402     // No need to visit explicit instantiations, we'll find the node
   1403     // eventually.
   1404     case TSK_ExplicitInstantiationDeclaration:
   1405     case TSK_ExplicitInstantiationDefinition:
   1406       break;
   1407 
   1408     case TSK_ExplicitSpecialization:
   1409       break;
   1410     }
   1411   }
   1412 
   1413   return true;
   1414 }
   1415 
   1416 DEF_TRAVERSE_DECL(FunctionTemplateDecl, {
   1417     TRY_TO(TraverseDecl(D->getTemplatedDecl()));
   1418     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
   1419 
   1420     // By default, we do not traverse the instantiations of
   1421     // function templates since they do not appear in the user code. The
   1422     // following code optionally traverses them.
   1423     //
   1424     // We only traverse the function instantiations when we see the canonical
   1425     // declaration of the template, to ensure we only visit them once.
   1426     if (getDerived().shouldVisitTemplateInstantiations() &&
   1427         D == D->getCanonicalDecl())
   1428       TRY_TO(TraverseFunctionInstantiations(D));
   1429   })
   1430 
   1431 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
   1432     // D is the "T" in something like
   1433     //   template <template <typename> class T> class container { };
   1434     TRY_TO(TraverseDecl(D->getTemplatedDecl()));
   1435     if (D->hasDefaultArgument()) {
   1436       TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
   1437     }
   1438     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
   1439   })
   1440 
   1441 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
   1442     // D is the "T" in something like "template<typename T> class vector;"
   1443     if (D->getTypeForDecl())
   1444       TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
   1445     if (D->hasDefaultArgument())
   1446       TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
   1447   })
   1448 
   1449 DEF_TRAVERSE_DECL(TypedefDecl, {
   1450     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1451     // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1452     // declaring the typedef, not something that was written in the
   1453     // source.
   1454   })
   1455 
   1456 DEF_TRAVERSE_DECL(TypeAliasDecl, {
   1457     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1458     // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1459     // declaring the type alias, not something that was written in the
   1460     // source.
   1461   })
   1462 
   1463 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
   1464     TRY_TO(TraverseDecl(D->getTemplatedDecl()));
   1465     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
   1466   })
   1467 
   1468 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
   1469     // A dependent using declaration which was marked with 'typename'.
   1470     //   template<class T> class A : public B<T> { using typename B<T>::foo; };
   1471     TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1472     // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1473     // declaring the type, not something that was written in the
   1474     // source.
   1475   })
   1476 
   1477 DEF_TRAVERSE_DECL(EnumDecl, {
   1478     if (D->getTypeForDecl())
   1479       TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
   1480 
   1481     TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1482     // The enumerators are already traversed by
   1483     // decls_begin()/decls_end().
   1484   })
   1485 
   1486 
   1487 // Helper methods for RecordDecl and its children.
   1488 template<typename Derived>
   1489 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(
   1490     RecordDecl *D) {
   1491   // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1492   // declaring the type, not something that was written in the source.
   1493 
   1494   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1495   return true;
   1496 }
   1497 
   1498 template<typename Derived>
   1499 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(
   1500     CXXRecordDecl *D) {
   1501   if (!TraverseRecordHelper(D))
   1502     return false;
   1503   if (D->isCompleteDefinition()) {
   1504     for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
   1505                                             E = D->bases_end();
   1506          I != E; ++I) {
   1507       TRY_TO(TraverseTypeLoc(I->getTypeSourceInfo()->getTypeLoc()));
   1508     }
   1509     // We don't traverse the friends or the conversions, as they are
   1510     // already in decls_begin()/decls_end().
   1511   }
   1512   return true;
   1513 }
   1514 
   1515 DEF_TRAVERSE_DECL(RecordDecl, {
   1516     TRY_TO(TraverseRecordHelper(D));
   1517   })
   1518 
   1519 DEF_TRAVERSE_DECL(CXXRecordDecl, {
   1520     TRY_TO(TraverseCXXRecordHelper(D));
   1521   })
   1522 
   1523 DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, {
   1524     // For implicit instantiations ("set<int> x;"), we don't want to
   1525     // recurse at all, since the instatiated class isn't written in
   1526     // the source code anywhere.  (Note the instatiated *type* --
   1527     // set<int> -- is written, and will still get a callback of
   1528     // TemplateSpecializationType).  For explicit instantiations
   1529     // ("template set<int>;"), we do need a callback, since this
   1530     // is the only callback that's made for this instantiation.
   1531     // We use getTypeAsWritten() to distinguish.
   1532     if (TypeSourceInfo *TSI = D->getTypeAsWritten())
   1533       TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
   1534 
   1535     if (!getDerived().shouldVisitTemplateInstantiations() &&
   1536         D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)
   1537       // Returning from here skips traversing the
   1538       // declaration context of the ClassTemplateSpecializationDecl
   1539       // (embedded in the DEF_TRAVERSE_DECL() macro)
   1540       // which contains the instantiated members of the class.
   1541       return true;
   1542   })
   1543 
   1544 template <typename Derived>
   1545 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
   1546     const TemplateArgumentLoc *TAL, unsigned Count) {
   1547   for (unsigned I = 0; I < Count; ++I) {
   1548     TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
   1549   }
   1550   return true;
   1551 }
   1552 
   1553 DEF_TRAVERSE_DECL(ClassTemplatePartialSpecializationDecl, {
   1554     // The partial specialization.
   1555     if (TemplateParameterList *TPL = D->getTemplateParameters()) {
   1556       for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
   1557            I != E; ++I) {
   1558         TRY_TO(TraverseDecl(*I));
   1559       }
   1560     }
   1561     // The args that remains unspecialized.
   1562     TRY_TO(TraverseTemplateArgumentLocsHelper(
   1563         D->getTemplateArgsAsWritten(), D->getNumTemplateArgsAsWritten()));
   1564 
   1565     // Don't need the ClassTemplatePartialSpecializationHelper, even
   1566     // though that's our parent class -- we already visit all the
   1567     // template args here.
   1568     TRY_TO(TraverseCXXRecordHelper(D));
   1569 
   1570     // Instantiations will have been visited with the primary template.
   1571   })
   1572 
   1573 DEF_TRAVERSE_DECL(EnumConstantDecl, {
   1574     TRY_TO(TraverseStmt(D->getInitExpr()));
   1575   })
   1576 
   1577 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
   1578     // Like UnresolvedUsingTypenameDecl, but without the 'typename':
   1579     //    template <class T> Class A : public Base<T> { using Base<T>::foo; };
   1580     TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1581     TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
   1582   })
   1583 
   1584 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
   1585 
   1586 template<typename Derived>
   1587 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
   1588   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1589   if (D->getTypeSourceInfo())
   1590     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1591   else
   1592     TRY_TO(TraverseType(D->getType()));
   1593   return true;
   1594 }
   1595 
   1596 DEF_TRAVERSE_DECL(FieldDecl, {
   1597     TRY_TO(TraverseDeclaratorHelper(D));
   1598     if (D->isBitField())
   1599       TRY_TO(TraverseStmt(D->getBitWidth()));
   1600     else if (D->hasInClassInitializer())
   1601       TRY_TO(TraverseStmt(D->getInClassInitializer()));
   1602   })
   1603 
   1604 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
   1605     TRY_TO(TraverseDeclaratorHelper(D));
   1606     if (D->isBitField())
   1607       TRY_TO(TraverseStmt(D->getBitWidth()));
   1608     // FIXME: implement the rest.
   1609   })
   1610 
   1611 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
   1612     TRY_TO(TraverseDeclaratorHelper(D));
   1613     if (D->isBitField())
   1614       TRY_TO(TraverseStmt(D->getBitWidth()));
   1615     // FIXME: implement the rest.
   1616   })
   1617 
   1618 template<typename Derived>
   1619 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
   1620   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1621   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
   1622 
   1623   // If we're an explicit template specialization, iterate over the
   1624   // template args that were explicitly specified.  If we were doing
   1625   // this in typing order, we'd do it between the return type and
   1626   // the function args, but both are handled by the FunctionTypeLoc
   1627   // above, so we have to choose one side.  I've decided to do before.
   1628   if (const FunctionTemplateSpecializationInfo *FTSI =
   1629       D->getTemplateSpecializationInfo()) {
   1630     if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
   1631         FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
   1632       // A specialization might not have explicit template arguments if it has
   1633       // a templated return type and concrete arguments.
   1634       if (const ASTTemplateArgumentListInfo *TALI =
   1635           FTSI->TemplateArgumentsAsWritten) {
   1636         TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
   1637                                                   TALI->NumTemplateArgs));
   1638       }
   1639     }
   1640   }
   1641 
   1642   // Visit the function type itself, which can be either
   1643   // FunctionNoProtoType or FunctionProtoType, or a typedef.  This
   1644   // also covers the return type and the function parameters,
   1645   // including exception specifications.
   1646   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1647 
   1648   if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
   1649     // Constructor initializers.
   1650     for (CXXConstructorDecl::init_iterator I = Ctor->init_begin(),
   1651                                            E = Ctor->init_end();
   1652          I != E; ++I) {
   1653       TRY_TO(TraverseConstructorInitializer(*I));
   1654     }
   1655   }
   1656 
   1657   if (D->isThisDeclarationADefinition()) {
   1658     TRY_TO(TraverseStmt(D->getBody()));  // Function body.
   1659   }
   1660   return true;
   1661 }
   1662 
   1663 DEF_TRAVERSE_DECL(FunctionDecl, {
   1664     // We skip decls_begin/decls_end, which are already covered by
   1665     // TraverseFunctionHelper().
   1666     return TraverseFunctionHelper(D);
   1667   })
   1668 
   1669 DEF_TRAVERSE_DECL(CXXMethodDecl, {
   1670     // We skip decls_begin/decls_end, which are already covered by
   1671     // TraverseFunctionHelper().
   1672     return TraverseFunctionHelper(D);
   1673   })
   1674 
   1675 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
   1676     // We skip decls_begin/decls_end, which are already covered by
   1677     // TraverseFunctionHelper().
   1678     return TraverseFunctionHelper(D);
   1679   })
   1680 
   1681 // CXXConversionDecl is the declaration of a type conversion operator.
   1682 // It's not a cast expression.
   1683 DEF_TRAVERSE_DECL(CXXConversionDecl, {
   1684     // We skip decls_begin/decls_end, which are already covered by
   1685     // TraverseFunctionHelper().
   1686     return TraverseFunctionHelper(D);
   1687   })
   1688 
   1689 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
   1690     // We skip decls_begin/decls_end, which are already covered by
   1691     // TraverseFunctionHelper().
   1692     return TraverseFunctionHelper(D);
   1693   })
   1694 
   1695 template<typename Derived>
   1696 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
   1697   TRY_TO(TraverseDeclaratorHelper(D));
   1698   // Default params are taken care of when we traverse the ParmVarDecl.
   1699   if (!isa<ParmVarDecl>(D))
   1700     TRY_TO(TraverseStmt(D->getInit()));
   1701   return true;
   1702 }
   1703 
   1704 DEF_TRAVERSE_DECL(VarDecl, {
   1705     TRY_TO(TraverseVarHelper(D));
   1706   })
   1707 
   1708 DEF_TRAVERSE_DECL(ImplicitParamDecl, {
   1709     TRY_TO(TraverseVarHelper(D));
   1710   })
   1711 
   1712 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
   1713     // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
   1714     TRY_TO(TraverseDeclaratorHelper(D));
   1715     TRY_TO(TraverseStmt(D->getDefaultArgument()));
   1716   })
   1717 
   1718 DEF_TRAVERSE_DECL(ParmVarDecl, {
   1719     TRY_TO(TraverseVarHelper(D));
   1720 
   1721     if (D->hasDefaultArg() &&
   1722         D->hasUninstantiatedDefaultArg() &&
   1723         !D->hasUnparsedDefaultArg())
   1724       TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
   1725 
   1726     if (D->hasDefaultArg() &&
   1727         !D->hasUninstantiatedDefaultArg() &&
   1728         !D->hasUnparsedDefaultArg())
   1729       TRY_TO(TraverseStmt(D->getDefaultArg()));
   1730   })
   1731 
   1732 #undef DEF_TRAVERSE_DECL
   1733 
   1734 // ----------------- Stmt traversal -----------------
   1735 //
   1736 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
   1737 // over the children defined in children() (every stmt defines these,
   1738 // though sometimes the range is empty).  Each individual Traverse*
   1739 // method only needs to worry about children other than those.  To see
   1740 // what children() does for a given class, see, e.g.,
   1741 //   http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
   1742 
   1743 // This macro makes available a variable S, the passed-in stmt.
   1744 #define DEF_TRAVERSE_STMT(STMT, CODE)                                   \
   1745 template<typename Derived>                                              \
   1746 bool RecursiveASTVisitor<Derived>::Traverse##STMT (STMT *S) {           \
   1747   TRY_TO(WalkUpFrom##STMT(S));                                          \
   1748   StmtQueueAction StmtQueue(*this);                                     \
   1749   { CODE; }                                                             \
   1750   for (Stmt::child_range range = S->children(); range; ++range) {       \
   1751     StmtQueue.queue(*range);                                            \
   1752   }                                                                     \
   1753   return true;                                                          \
   1754 }
   1755 
   1756 DEF_TRAVERSE_STMT(GCCAsmStmt, {
   1757     StmtQueue.queue(S->getAsmString());
   1758     for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
   1759       StmtQueue.queue(S->getInputConstraintLiteral(I));
   1760     }
   1761     for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
   1762       StmtQueue.queue(S->getOutputConstraintLiteral(I));
   1763     }
   1764     for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
   1765       StmtQueue.queue(S->getClobberStringLiteral(I));
   1766     }
   1767     // children() iterates over inputExpr and outputExpr.
   1768   })
   1769 
   1770 DEF_TRAVERSE_STMT(MSAsmStmt, {
   1771     // FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc.  Once
   1772     // added this needs to be implemented.
   1773   })
   1774 
   1775 DEF_TRAVERSE_STMT(CXXCatchStmt, {
   1776     TRY_TO(TraverseDecl(S->getExceptionDecl()));
   1777     // children() iterates over the handler block.
   1778   })
   1779 
   1780 DEF_TRAVERSE_STMT(DeclStmt, {
   1781     for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end();
   1782          I != E; ++I) {
   1783       TRY_TO(TraverseDecl(*I));
   1784     }
   1785     // Suppress the default iteration over children() by
   1786     // returning.  Here's why: A DeclStmt looks like 'type var [=
   1787     // initializer]'.  The decls above already traverse over the
   1788     // initializers, so we don't have to do it again (which
   1789     // children() would do).
   1790     return true;
   1791   })
   1792 
   1793 
   1794 // These non-expr stmts (most of them), do not need any action except
   1795 // iterating over the children.
   1796 DEF_TRAVERSE_STMT(BreakStmt, { })
   1797 DEF_TRAVERSE_STMT(CXXTryStmt, { })
   1798 DEF_TRAVERSE_STMT(CaseStmt, { })
   1799 DEF_TRAVERSE_STMT(CompoundStmt, { })
   1800 DEF_TRAVERSE_STMT(ContinueStmt, { })
   1801 DEF_TRAVERSE_STMT(DefaultStmt, { })
   1802 DEF_TRAVERSE_STMT(DoStmt, { })
   1803 DEF_TRAVERSE_STMT(ForStmt, { })
   1804 DEF_TRAVERSE_STMT(GotoStmt, { })
   1805 DEF_TRAVERSE_STMT(IfStmt, { })
   1806 DEF_TRAVERSE_STMT(IndirectGotoStmt, { })
   1807 DEF_TRAVERSE_STMT(LabelStmt, { })
   1808 DEF_TRAVERSE_STMT(AttributedStmt, { })
   1809 DEF_TRAVERSE_STMT(NullStmt, { })
   1810 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, { })
   1811 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, { })
   1812 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, { })
   1813 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, { })
   1814 DEF_TRAVERSE_STMT(ObjCAtTryStmt, { })
   1815 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, { })
   1816 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, { })
   1817 DEF_TRAVERSE_STMT(CXXForRangeStmt, { })
   1818 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
   1819     TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   1820     TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
   1821 })
   1822 DEF_TRAVERSE_STMT(ReturnStmt, { })
   1823 DEF_TRAVERSE_STMT(SwitchStmt, { })
   1824 DEF_TRAVERSE_STMT(WhileStmt, { })
   1825 
   1826 
   1827 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
   1828     TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   1829     TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
   1830     if (S->hasExplicitTemplateArgs()) {
   1831       TRY_TO(TraverseTemplateArgumentLocsHelper(
   1832           S->getTemplateArgs(), S->getNumTemplateArgs()));
   1833     }
   1834   })
   1835 
   1836 DEF_TRAVERSE_STMT(DeclRefExpr, {
   1837     TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   1838     TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
   1839     TRY_TO(TraverseTemplateArgumentLocsHelper(
   1840         S->getTemplateArgs(), S->getNumTemplateArgs()));
   1841   })
   1842 
   1843 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
   1844     TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   1845     TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
   1846     if (S->hasExplicitTemplateArgs()) {
   1847       TRY_TO(TraverseTemplateArgumentLocsHelper(
   1848           S->getExplicitTemplateArgs().getTemplateArgs(),
   1849           S->getNumTemplateArgs()));
   1850     }
   1851   })
   1852 
   1853 DEF_TRAVERSE_STMT(MemberExpr, {
   1854     TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   1855     TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
   1856     TRY_TO(TraverseTemplateArgumentLocsHelper(
   1857         S->getTemplateArgs(), S->getNumTemplateArgs()));
   1858   })
   1859 
   1860 DEF_TRAVERSE_STMT(ImplicitCastExpr, {
   1861     // We don't traverse the cast type, as it's not written in the
   1862     // source code.
   1863   })
   1864 
   1865 DEF_TRAVERSE_STMT(CStyleCastExpr, {
   1866     TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   1867   })
   1868 
   1869 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
   1870     TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   1871   })
   1872 
   1873 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
   1874     TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   1875   })
   1876 
   1877 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
   1878     TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   1879   })
   1880 
   1881 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
   1882     TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   1883   })
   1884 
   1885 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
   1886     TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   1887   })
   1888 
   1889 // InitListExpr is a tricky one, because we want to do all our work on
   1890 // the syntactic form of the listexpr, but this method takes the
   1891 // semantic form by default.  We can't use the macro helper because it
   1892 // calls WalkUp*() on the semantic form, before our code can convert
   1893 // to the syntactic form.
   1894 template<typename Derived>
   1895 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) {
   1896   if (InitListExpr *Syn = S->getSyntacticForm())
   1897     S = Syn;
   1898   TRY_TO(WalkUpFromInitListExpr(S));
   1899   StmtQueueAction StmtQueue(*this);
   1900   // All we need are the default actions.  FIXME: use a helper function.
   1901   for (Stmt::child_range range = S->children(); range; ++range) {
   1902     StmtQueue.queue(*range);
   1903   }
   1904   return true;
   1905 }
   1906 
   1907 // GenericSelectionExpr is a special case because the types and expressions
   1908 // are interleaved.  We also need to watch out for null types (default
   1909 // generic associations).
   1910 template<typename Derived>
   1911 bool RecursiveASTVisitor<Derived>::
   1912 TraverseGenericSelectionExpr(GenericSelectionExpr *S) {
   1913   TRY_TO(WalkUpFromGenericSelectionExpr(S));
   1914   StmtQueueAction StmtQueue(*this);
   1915   StmtQueue.queue(S->getControllingExpr());
   1916   for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
   1917     if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
   1918       TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
   1919     StmtQueue.queue(S->getAssocExpr(i));
   1920   }
   1921   return true;
   1922 }
   1923 
   1924 // PseudoObjectExpr is a special case because of the wierdness with
   1925 // syntactic expressions and opaque values.
   1926 template<typename Derived>
   1927 bool RecursiveASTVisitor<Derived>::
   1928 TraversePseudoObjectExpr(PseudoObjectExpr *S) {
   1929   TRY_TO(WalkUpFromPseudoObjectExpr(S));
   1930   StmtQueueAction StmtQueue(*this);
   1931   StmtQueue.queue(S->getSyntacticForm());
   1932   for (PseudoObjectExpr::semantics_iterator
   1933          i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) {
   1934     Expr *sub = *i;
   1935     if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
   1936       sub = OVE->getSourceExpr();
   1937     StmtQueue.queue(sub);
   1938   }
   1939   return true;
   1940 }
   1941 
   1942 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
   1943     // This is called for code like 'return T()' where T is a built-in
   1944     // (i.e. non-class) type.
   1945     TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   1946   })
   1947 
   1948 DEF_TRAVERSE_STMT(CXXNewExpr, {
   1949   // The child-iterator will pick up the other arguments.
   1950   TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
   1951   })
   1952 
   1953 DEF_TRAVERSE_STMT(OffsetOfExpr, {
   1954     // The child-iterator will pick up the expression representing
   1955     // the field.
   1956     // FIMXE: for code like offsetof(Foo, a.b.c), should we get
   1957     // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
   1958     TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   1959   })
   1960 
   1961 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
   1962     // The child-iterator will pick up the arg if it's an expression,
   1963     // but not if it's a type.
   1964     if (S->isArgumentType())
   1965       TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
   1966   })
   1967 
   1968 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
   1969     // The child-iterator will pick up the arg if it's an expression,
   1970     // but not if it's a type.
   1971     if (S->isTypeOperand())
   1972       TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
   1973   })
   1974 
   1975 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
   1976     // The child-iterator will pick up the arg if it's an expression,
   1977     // but not if it's a type.
   1978     if (S->isTypeOperand())
   1979       TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
   1980   })
   1981 
   1982 DEF_TRAVERSE_STMT(UnaryTypeTraitExpr, {
   1983     TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
   1984   })
   1985 
   1986 DEF_TRAVERSE_STMT(BinaryTypeTraitExpr, {
   1987     TRY_TO(TraverseTypeLoc(S->getLhsTypeSourceInfo()->getTypeLoc()));
   1988     TRY_TO(TraverseTypeLoc(S->getRhsTypeSourceInfo()->getTypeLoc()));
   1989   })
   1990 
   1991 DEF_TRAVERSE_STMT(TypeTraitExpr, {
   1992   for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
   1993     TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
   1994 })
   1995 
   1996 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
   1997     TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
   1998   })
   1999 
   2000 DEF_TRAVERSE_STMT(ExpressionTraitExpr, {
   2001     StmtQueue.queue(S->getQueriedExpression());
   2002   })
   2003 
   2004 DEF_TRAVERSE_STMT(VAArgExpr, {
   2005     // The child-iterator will pick up the expression argument.
   2006     TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
   2007   })
   2008 
   2009 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
   2010     // This is called for code like 'return T()' where T is a class type.
   2011     TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   2012   })
   2013 
   2014 // Walk only the visible parts of lambda expressions.
   2015 template<typename Derived>
   2016 bool RecursiveASTVisitor<Derived>::TraverseLambdaExpr(LambdaExpr *S) {
   2017   for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
   2018                                  CEnd = S->explicit_capture_end();
   2019        C != CEnd; ++C) {
   2020     TRY_TO(TraverseLambdaCapture(*C));
   2021   }
   2022 
   2023   if (S->hasExplicitParameters() || S->hasExplicitResultType()) {
   2024     TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
   2025     if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
   2026       // Visit the whole type.
   2027       TRY_TO(TraverseTypeLoc(TL));
   2028     } else if (isa<FunctionProtoTypeLoc>(TL)) {
   2029       FunctionProtoTypeLoc Proto = cast<FunctionProtoTypeLoc>(TL);
   2030       if (S->hasExplicitParameters()) {
   2031         // Visit parameters.
   2032         for (unsigned I = 0, N = Proto.getNumArgs(); I != N; ++I) {
   2033           TRY_TO(TraverseDecl(Proto.getArg(I)));
   2034         }
   2035       } else {
   2036         TRY_TO(TraverseTypeLoc(Proto.getResultLoc()));
   2037       }
   2038     }
   2039   }
   2040 
   2041   StmtQueueAction StmtQueue(*this);
   2042   StmtQueue.queue(S->getBody());
   2043   return true;
   2044 }
   2045 
   2046 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
   2047     // This is called for code like 'T()', where T is a template argument.
   2048     TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   2049   })
   2050 
   2051 // These expressions all might take explicit template arguments.
   2052 // We traverse those if so.  FIXME: implement these.
   2053 DEF_TRAVERSE_STMT(CXXConstructExpr, { })
   2054 DEF_TRAVERSE_STMT(CallExpr, { })
   2055 DEF_TRAVERSE_STMT(CXXMemberCallExpr, { })
   2056 
   2057 // These exprs (most of them), do not need any action except iterating
   2058 // over the children.
   2059 DEF_TRAVERSE_STMT(AddrLabelExpr, { })
   2060 DEF_TRAVERSE_STMT(ArraySubscriptExpr, { })
   2061 DEF_TRAVERSE_STMT(BlockExpr, {
   2062   TRY_TO(TraverseDecl(S->getBlockDecl()));
   2063   return true; // no child statements to loop through.
   2064 })
   2065 DEF_TRAVERSE_STMT(ChooseExpr, { })
   2066 DEF_TRAVERSE_STMT(CompoundLiteralExpr, { })
   2067 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, { })
   2068 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, { })
   2069 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, { })
   2070 DEF_TRAVERSE_STMT(CXXDeleteExpr, { })
   2071 DEF_TRAVERSE_STMT(ExprWithCleanups, { })
   2072 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, { })
   2073 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
   2074   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2075   if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
   2076     TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
   2077   if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
   2078     TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
   2079 })
   2080 DEF_TRAVERSE_STMT(CXXThisExpr, { })
   2081 DEF_TRAVERSE_STMT(CXXThrowExpr, { })
   2082 DEF_TRAVERSE_STMT(UserDefinedLiteral, { })
   2083 DEF_TRAVERSE_STMT(DesignatedInitExpr, { })
   2084 DEF_TRAVERSE_STMT(ExtVectorElementExpr, { })
   2085 DEF_TRAVERSE_STMT(GNUNullExpr, { })
   2086 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, { })
   2087 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, { })
   2088 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
   2089   if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
   2090     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
   2091 })
   2092 DEF_TRAVERSE_STMT(ObjCIsaExpr, { })
   2093 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, { })
   2094 DEF_TRAVERSE_STMT(ObjCMessageExpr, { })
   2095 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, { })
   2096 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, { })
   2097 DEF_TRAVERSE_STMT(ObjCProtocolExpr, { })
   2098 DEF_TRAVERSE_STMT(ObjCSelectorExpr, { })
   2099 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, { })
   2100 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
   2101   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2102 })
   2103 DEF_TRAVERSE_STMT(ParenExpr, { })
   2104 DEF_TRAVERSE_STMT(ParenListExpr, { })
   2105 DEF_TRAVERSE_STMT(PredefinedExpr, { })
   2106 DEF_TRAVERSE_STMT(ShuffleVectorExpr, { })
   2107 DEF_TRAVERSE_STMT(StmtExpr, { })
   2108 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
   2109   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2110   if (S->hasExplicitTemplateArgs()) {
   2111     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
   2112                                               S->getNumTemplateArgs()));
   2113   }
   2114 })
   2115 
   2116 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
   2117   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2118   if (S->hasExplicitTemplateArgs()) {
   2119     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
   2120                                               S->getNumTemplateArgs()));
   2121   }
   2122 })
   2123 
   2124 DEF_TRAVERSE_STMT(SEHTryStmt, {})
   2125 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
   2126 DEF_TRAVERSE_STMT(SEHFinallyStmt,{})
   2127 
   2128 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, { })
   2129 DEF_TRAVERSE_STMT(OpaqueValueExpr, { })
   2130 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, { })
   2131 
   2132 // These operators (all of them) do not need any action except
   2133 // iterating over the children.
   2134 DEF_TRAVERSE_STMT(BinaryConditionalOperator, { })
   2135 DEF_TRAVERSE_STMT(ConditionalOperator, { })
   2136 DEF_TRAVERSE_STMT(UnaryOperator, { })
   2137 DEF_TRAVERSE_STMT(BinaryOperator, { })
   2138 DEF_TRAVERSE_STMT(CompoundAssignOperator, { })
   2139 DEF_TRAVERSE_STMT(CXXNoexceptExpr, { })
   2140 DEF_TRAVERSE_STMT(PackExpansionExpr, { })
   2141 DEF_TRAVERSE_STMT(SizeOfPackExpr, { })
   2142 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, { })
   2143 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, { })
   2144 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, { })
   2145 DEF_TRAVERSE_STMT(AtomicExpr, { })
   2146 
   2147 // These literals (all of them) do not need any action.
   2148 DEF_TRAVERSE_STMT(IntegerLiteral, { })
   2149 DEF_TRAVERSE_STMT(CharacterLiteral, { })
   2150 DEF_TRAVERSE_STMT(FloatingLiteral, { })
   2151 DEF_TRAVERSE_STMT(ImaginaryLiteral, { })
   2152 DEF_TRAVERSE_STMT(StringLiteral, { })
   2153 DEF_TRAVERSE_STMT(ObjCStringLiteral, { })
   2154 DEF_TRAVERSE_STMT(ObjCBoxedExpr, { })
   2155 DEF_TRAVERSE_STMT(ObjCArrayLiteral, { })
   2156 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, { })
   2157 
   2158 // Traverse OpenCL: AsType, Convert.
   2159 DEF_TRAVERSE_STMT(AsTypeExpr, { })
   2160 
   2161 // FIXME: look at the following tricky-seeming exprs to see if we
   2162 // need to recurse on anything.  These are ones that have methods
   2163 // returning decls or qualtypes or nestednamespecifier -- though I'm
   2164 // not sure if they own them -- or just seemed very complicated, or
   2165 // had lots of sub-types to explore.
   2166 //
   2167 // VisitOverloadExpr and its children: recurse on template args? etc?
   2168 
   2169 // FIXME: go through all the stmts and exprs again, and see which of them
   2170 // create new types, and recurse on the types (TypeLocs?) of those.
   2171 // Candidates:
   2172 //
   2173 //    http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
   2174 //    http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
   2175 //    http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
   2176 //    Every class that has getQualifier.
   2177 
   2178 #undef DEF_TRAVERSE_STMT
   2179 
   2180 #undef TRY_TO
   2181 
   2182 } // end namespace cxindex
   2183 } // end namespace clang
   2184 
   2185 #endif // LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H
   2186