Home | History | Annotate | Line # | Download | only in AST
      1 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
      2 //
      3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4 // See https://llvm.org/LICENSE.txt for license information.
      5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6 //
      7 //===----------------------------------------------------------------------===//
      8 //
      9 //  This file defines the RecursiveASTVisitor interface, which recursively
     10 //  traverses the entire AST.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
     14 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
     15 
     16 #include "clang/AST/Attr.h"
     17 #include "clang/AST/Decl.h"
     18 #include "clang/AST/DeclarationName.h"
     19 #include "clang/AST/DeclBase.h"
     20 #include "clang/AST/DeclCXX.h"
     21 #include "clang/AST/DeclFriend.h"
     22 #include "clang/AST/DeclObjC.h"
     23 #include "clang/AST/DeclOpenMP.h"
     24 #include "clang/AST/DeclTemplate.h"
     25 #include "clang/AST/Expr.h"
     26 #include "clang/AST/ExprConcepts.h"
     27 #include "clang/AST/ExprCXX.h"
     28 #include "clang/AST/ExprObjC.h"
     29 #include "clang/AST/ExprOpenMP.h"
     30 #include "clang/AST/LambdaCapture.h"
     31 #include "clang/AST/NestedNameSpecifier.h"
     32 #include "clang/AST/OpenMPClause.h"
     33 #include "clang/AST/Stmt.h"
     34 #include "clang/AST/StmtCXX.h"
     35 #include "clang/AST/StmtObjC.h"
     36 #include "clang/AST/StmtOpenMP.h"
     37 #include "clang/AST/TemplateBase.h"
     38 #include "clang/AST/TemplateName.h"
     39 #include "clang/AST/Type.h"
     40 #include "clang/AST/TypeLoc.h"
     41 #include "clang/Basic/LLVM.h"
     42 #include "clang/Basic/OpenMPKinds.h"
     43 #include "clang/Basic/Specifiers.h"
     44 #include "llvm/ADT/PointerIntPair.h"
     45 #include "llvm/ADT/SmallVector.h"
     46 #include "llvm/Support/Casting.h"
     47 #include <algorithm>
     48 #include <cstddef>
     49 #include <type_traits>
     50 
     51 namespace clang {
     52 
     53 // A helper macro to implement short-circuiting when recursing.  It
     54 // invokes CALL_EXPR, which must be a method call, on the derived
     55 // object (s.t. a user of RecursiveASTVisitor can override the method
     56 // in CALL_EXPR).
     57 #define TRY_TO(CALL_EXPR)                                                      \
     58   do {                                                                         \
     59     if (!getDerived().CALL_EXPR)                                               \
     60       return false;                                                            \
     61   } while (false)
     62 
     63 namespace detail {
     64 
     65 template <typename T, typename U>
     66 struct has_same_member_pointer_type : std::false_type {};
     67 template <typename T, typename U, typename R, typename... P>
     68 struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
     69     : std::true_type {};
     70 
     71 template <bool has_same_type> struct is_same_method_impl {
     72   template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
     73   static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
     74                            SecondMethodPtrTy SecondMethodPtr) {
     75     return false;
     76   }
     77 };
     78 
     79 template <> struct is_same_method_impl<true> {
     80   template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
     81   static bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
     82                            SecondMethodPtrTy SecondMethodPtr) {
     83     return FirstMethodPtr == SecondMethodPtr;
     84   }
     85 };
     86 
     87 /// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
     88 /// are pointers to the same non-static member function.
     89 template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
     90 bool isSameMethod(FirstMethodPtrTy FirstMethodPtr,
     91                   SecondMethodPtrTy SecondMethodPtr) {
     92   return is_same_method_impl<has_same_member_pointer_type<
     93       FirstMethodPtrTy,
     94       SecondMethodPtrTy>::value>::isSameMethod(FirstMethodPtr, SecondMethodPtr);
     95 }
     96 
     97 } // end namespace detail
     98 
     99 /// A class that does preorder or postorder
    100 /// depth-first traversal on the entire Clang AST and visits each node.
    101 ///
    102 /// This class performs three distinct tasks:
    103 ///   1. traverse the AST (i.e. go to each node);
    104 ///   2. at a given node, walk up the class hierarchy, starting from
    105 ///      the node's dynamic type, until the top-most class (e.g. Stmt,
    106 ///      Decl, or Type) is reached.
    107 ///   3. given a (node, class) combination, where 'class' is some base
    108 ///      class of the dynamic type of 'node', call a user-overridable
    109 ///      function to actually visit the node.
    110 ///
    111 /// These tasks are done by three groups of methods, respectively:
    112 ///   1. TraverseDecl(Decl *x) does task #1.  It is the entry point
    113 ///      for traversing an AST rooted at x.  This method simply
    114 ///      dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
    115 ///      is the dynamic type of *x, which calls WalkUpFromFoo(x) and
    116 ///      then recursively visits the child nodes of x.
    117 ///      TraverseStmt(Stmt *x) and TraverseType(QualType x) work
    118 ///      similarly.
    119 ///   2. WalkUpFromFoo(Foo *x) does task #2.  It does not try to visit
    120 ///      any child node of x.  Instead, it first calls WalkUpFromBar(x)
    121 ///      where Bar is the direct parent class of Foo (unless Foo has
    122 ///      no parent), and then calls VisitFoo(x) (see the next list item).
    123 ///   3. VisitFoo(Foo *x) does task #3.
    124 ///
    125 /// These three method groups are tiered (Traverse* > WalkUpFrom* >
    126 /// Visit*).  A method (e.g. Traverse*) may call methods from the same
    127 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
    128 /// It may not call methods from a higher tier.
    129 ///
    130 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
    131 /// is Foo's super class) before calling VisitFoo(), the result is
    132 /// that the Visit*() methods for a given node are called in the
    133 /// top-down order (e.g. for a node of type NamespaceDecl, the order will
    134 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
    135 ///
    136 /// This scheme guarantees that all Visit*() calls for the same AST
    137 /// node are grouped together.  In other words, Visit*() methods for
    138 /// different nodes are never interleaved.
    139 ///
    140 /// Clients of this visitor should subclass the visitor (providing
    141 /// themselves as the template argument, using the curiously recurring
    142 /// template pattern) and override any of the Traverse*, WalkUpFrom*,
    143 /// and Visit* methods for declarations, types, statements,
    144 /// expressions, or other AST nodes where the visitor should customize
    145 /// behavior.  Most users only need to override Visit*.  Advanced
    146 /// users may override Traverse* and WalkUpFrom* to implement custom
    147 /// traversal strategies.  Returning false from one of these overridden
    148 /// functions will abort the entire traversal.
    149 ///
    150 /// By default, this visitor tries to visit every part of the explicit
    151 /// source code exactly once.  The default policy towards templates
    152 /// is to descend into the 'pattern' class or function body, not any
    153 /// explicit or implicit instantiations.  Explicit specializations
    154 /// are still visited, and the patterns of partial specializations
    155 /// are visited separately.  This behavior can be changed by
    156 /// overriding shouldVisitTemplateInstantiations() in the derived class
    157 /// to return true, in which case all known implicit and explicit
    158 /// instantiations will be visited at the same time as the pattern
    159 /// from which they were produced.
    160 ///
    161 /// By default, this visitor preorder traverses the AST. If postorder traversal
    162 /// is needed, the \c shouldTraversePostOrder method needs to be overridden
    163 /// to return \c true.
    164 template <typename Derived> class RecursiveASTVisitor {
    165 public:
    166   /// A queue used for performing data recursion over statements.
    167   /// Parameters involving this type are used to implement data
    168   /// recursion over Stmts and Exprs within this class, and should
    169   /// typically not be explicitly specified by derived classes.
    170   /// The bool bit indicates whether the statement has been traversed or not.
    171   typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>>
    172     DataRecursionQueue;
    173 
    174   /// Return a reference to the derived class.
    175   Derived &getDerived() { return *static_cast<Derived *>(this); }
    176 
    177   /// Return whether this visitor should recurse into
    178   /// template instantiations.
    179   bool shouldVisitTemplateInstantiations() const { return false; }
    180 
    181   /// Return whether this visitor should recurse into the types of
    182   /// TypeLocs.
    183   bool shouldWalkTypesOfTypeLocs() const { return true; }
    184 
    185   /// Return whether this visitor should recurse into implicit
    186   /// code, e.g., implicit constructors and destructors.
    187   bool shouldVisitImplicitCode() const { return false; }
    188 
    189   /// Return whether this visitor should recurse into lambda body
    190   bool shouldVisitLambdaBody() const { return true; }
    191 
    192   /// Return whether this visitor should traverse post-order.
    193   bool shouldTraversePostOrder() const { return false; }
    194 
    195   /// Recursively visits an entire AST, starting from the top-level Decls
    196   /// in the AST traversal scope (by default, the TranslationUnitDecl).
    197   /// \returns false if visitation was terminated early.
    198   bool TraverseAST(ASTContext &AST) {
    199     for (Decl *D : AST.getTraversalScope())
    200       if (!getDerived().TraverseDecl(D))
    201         return false;
    202     return true;
    203   }
    204 
    205   /// Recursively visit a statement or expression, by
    206   /// dispatching to Traverse*() based on the argument's dynamic type.
    207   ///
    208   /// \returns false if the visitation was terminated early, true
    209   /// otherwise (including when the argument is nullptr).
    210   bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr);
    211 
    212   /// Invoked before visiting a statement or expression via data recursion.
    213   ///
    214   /// \returns false to skip visiting the node, true otherwise.
    215   bool dataTraverseStmtPre(Stmt *S) { return true; }
    216 
    217   /// Invoked after visiting a statement or expression via data recursion.
    218   /// This is not invoked if the previously invoked \c dataTraverseStmtPre
    219   /// returned false.
    220   ///
    221   /// \returns false if the visitation was terminated early, true otherwise.
    222   bool dataTraverseStmtPost(Stmt *S) { return true; }
    223 
    224   /// Recursively visit a type, by dispatching to
    225   /// Traverse*Type() based on the argument's getTypeClass() property.
    226   ///
    227   /// \returns false if the visitation was terminated early, true
    228   /// otherwise (including when the argument is a Null type).
    229   bool TraverseType(QualType T);
    230 
    231   /// Recursively visit a type with location, by dispatching to
    232   /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
    233   ///
    234   /// \returns false if the visitation was terminated early, true
    235   /// otherwise (including when the argument is a Null type location).
    236   bool TraverseTypeLoc(TypeLoc TL);
    237 
    238   /// Recursively visit an attribute, by dispatching to
    239   /// Traverse*Attr() based on the argument's dynamic type.
    240   ///
    241   /// \returns false if the visitation was terminated early, true
    242   /// otherwise (including when the argument is a Null type location).
    243   bool TraverseAttr(Attr *At);
    244 
    245   /// Recursively visit a declaration, by dispatching to
    246   /// Traverse*Decl() based on the argument's dynamic type.
    247   ///
    248   /// \returns false if the visitation was terminated early, true
    249   /// otherwise (including when the argument is NULL).
    250   bool TraverseDecl(Decl *D);
    251 
    252   /// Recursively visit a C++ nested-name-specifier.
    253   ///
    254   /// \returns false if the visitation was terminated early, true otherwise.
    255   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
    256 
    257   /// Recursively visit a C++ nested-name-specifier with location
    258   /// information.
    259   ///
    260   /// \returns false if the visitation was terminated early, true otherwise.
    261   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
    262 
    263   /// Recursively visit a name with its location information.
    264   ///
    265   /// \returns false if the visitation was terminated early, true otherwise.
    266   bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
    267 
    268   /// Recursively visit a template name and dispatch to the
    269   /// appropriate method.
    270   ///
    271   /// \returns false if the visitation was terminated early, true otherwise.
    272   bool TraverseTemplateName(TemplateName Template);
    273 
    274   /// Recursively visit a template argument and dispatch to the
    275   /// appropriate method for the argument type.
    276   ///
    277   /// \returns false if the visitation was terminated early, true otherwise.
    278   // FIXME: migrate callers to TemplateArgumentLoc instead.
    279   bool TraverseTemplateArgument(const TemplateArgument &Arg);
    280 
    281   /// Recursively visit a template argument location and dispatch to the
    282   /// appropriate method for the argument type.
    283   ///
    284   /// \returns false if the visitation was terminated early, true otherwise.
    285   bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
    286 
    287   /// Recursively visit a set of template arguments.
    288   /// This can be overridden by a subclass, but it's not expected that
    289   /// will be needed -- this visitor always dispatches to another.
    290   ///
    291   /// \returns false if the visitation was terminated early, true otherwise.
    292   // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
    293   bool TraverseTemplateArguments(const TemplateArgument *Args,
    294                                  unsigned NumArgs);
    295 
    296   /// Recursively visit a base specifier. This can be overridden by a
    297   /// subclass.
    298   ///
    299   /// \returns false if the visitation was terminated early, true otherwise.
    300   bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base);
    301 
    302   /// Recursively visit a constructor initializer.  This
    303   /// automatically dispatches to another visitor for the initializer
    304   /// expression, but not for the name of the initializer, so may
    305   /// be overridden for clients that need access to the name.
    306   ///
    307   /// \returns false if the visitation was terminated early, true otherwise.
    308   bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
    309 
    310   /// Recursively visit a lambda capture. \c Init is the expression that
    311   /// will be used to initialize the capture.
    312   ///
    313   /// \returns false if the visitation was terminated early, true otherwise.
    314   bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
    315                              Expr *Init);
    316 
    317   /// Recursively visit the syntactic or semantic form of an
    318   /// initialization list.
    319   ///
    320   /// \returns false if the visitation was terminated early, true otherwise.
    321   bool TraverseSynOrSemInitListExpr(InitListExpr *S,
    322                                     DataRecursionQueue *Queue = nullptr);
    323 
    324   /// Recursively visit a reference to a concept with potential arguments.
    325   ///
    326   /// \returns false if the visitation was terminated early, true otherwise.
    327   bool TraverseConceptReference(const ConceptReference &C);
    328 
    329   // ---- Methods on Attrs ----
    330 
    331   // Visit an attribute.
    332   bool VisitAttr(Attr *A) { return true; }
    333 
    334 // Declare Traverse* and empty Visit* for all Attr classes.
    335 #define ATTR_VISITOR_DECLS_ONLY
    336 #include "clang/AST/AttrVisitor.inc"
    337 #undef ATTR_VISITOR_DECLS_ONLY
    338 
    339 // ---- Methods on Stmts ----
    340 
    341   Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); }
    342 
    343 private:
    344   // Traverse the given statement. If the most-derived traverse function takes a
    345   // data recursion queue, pass it on; otherwise, discard it. Note that the
    346   // first branch of this conditional must compile whether or not the derived
    347   // class can take a queue, so if we're taking the second arm, make the first
    348   // arm call our function rather than the derived class version.
    349 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE)                            \
    350   (::clang::detail::has_same_member_pointer_type<                              \
    351        decltype(&RecursiveASTVisitor::Traverse##NAME),                         \
    352        decltype(&Derived::Traverse##NAME)>::value                              \
    353        ? static_cast<std::conditional_t<                                       \
    354              ::clang::detail::has_same_member_pointer_type<                    \
    355                  decltype(&RecursiveASTVisitor::Traverse##NAME),               \
    356                  decltype(&Derived::Traverse##NAME)>::value,                   \
    357              Derived &, RecursiveASTVisitor &>>(*this)                         \
    358              .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE)                 \
    359        : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
    360 
    361 // Try to traverse the given statement, or enqueue it if we're performing data
    362 // recursion in the middle of traversing another statement. Can only be called
    363 // from within a DEF_TRAVERSE_STMT body or similar context.
    364 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S)                                     \
    365   do {                                                                         \
    366     if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue))                             \
    367       return false;                                                            \
    368   } while (false)
    369 
    370 public:
    371 // Declare Traverse*() for all concrete Stmt classes.
    372 #define ABSTRACT_STMT(STMT)
    373 #define STMT(CLASS, PARENT) \
    374   bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
    375 #include "clang/AST/StmtNodes.inc"
    376   // The above header #undefs ABSTRACT_STMT and STMT upon exit.
    377 
    378   // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
    379   bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
    380   bool VisitStmt(Stmt *S) { return true; }
    381 #define STMT(CLASS, PARENT)                                                    \
    382   bool WalkUpFrom##CLASS(CLASS *S) {                                           \
    383     TRY_TO(WalkUpFrom##PARENT(S));                                             \
    384     TRY_TO(Visit##CLASS(S));                                                   \
    385     return true;                                                               \
    386   }                                                                            \
    387   bool Visit##CLASS(CLASS *S) { return true; }
    388 #include "clang/AST/StmtNodes.inc"
    389 
    390 // ---- Methods on Types ----
    391 // FIXME: revamp to take TypeLoc's rather than Types.
    392 
    393 // Declare Traverse*() for all concrete Type classes.
    394 #define ABSTRACT_TYPE(CLASS, BASE)
    395 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
    396 #include "clang/AST/TypeNodes.inc"
    397   // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
    398 
    399   // Define WalkUpFrom*() and empty Visit*() for all Type classes.
    400   bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
    401   bool VisitType(Type *T) { return true; }
    402 #define TYPE(CLASS, BASE)                                                      \
    403   bool WalkUpFrom##CLASS##Type(CLASS##Type *T) {                               \
    404     TRY_TO(WalkUpFrom##BASE(T));                                               \
    405     TRY_TO(Visit##CLASS##Type(T));                                             \
    406     return true;                                                               \
    407   }                                                                            \
    408   bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
    409 #include "clang/AST/TypeNodes.inc"
    410 
    411 // ---- Methods on TypeLocs ----
    412 // FIXME: this currently just calls the matching Type methods
    413 
    414 // Declare Traverse*() for all concrete TypeLoc classes.
    415 #define ABSTRACT_TYPELOC(CLASS, BASE)
    416 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
    417 #include "clang/AST/TypeLocNodes.def"
    418   // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
    419 
    420   // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
    421   bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
    422   bool VisitTypeLoc(TypeLoc TL) { return true; }
    423 
    424   // QualifiedTypeLoc and UnqualTypeLoc are not declared in
    425   // TypeNodes.inc and thus need to be handled specially.
    426   bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
    427     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
    428   }
    429   bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
    430   bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
    431     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
    432   }
    433   bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
    434 
    435 // Note that BASE includes trailing 'Type' which CLASS doesn't.
    436 #define TYPE(CLASS, BASE)                                                      \
    437   bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) {                         \
    438     TRY_TO(WalkUpFrom##BASE##Loc(TL));                                         \
    439     TRY_TO(Visit##CLASS##TypeLoc(TL));                                         \
    440     return true;                                                               \
    441   }                                                                            \
    442   bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
    443 #include "clang/AST/TypeNodes.inc"
    444 
    445 // ---- Methods on Decls ----
    446 
    447 // Declare Traverse*() for all concrete Decl classes.
    448 #define ABSTRACT_DECL(DECL)
    449 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
    450 #include "clang/AST/DeclNodes.inc"
    451   // The above header #undefs ABSTRACT_DECL and DECL upon exit.
    452 
    453   // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
    454   bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
    455   bool VisitDecl(Decl *D) { return true; }
    456 #define DECL(CLASS, BASE)                                                      \
    457   bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) {                               \
    458     TRY_TO(WalkUpFrom##BASE(D));                                               \
    459     TRY_TO(Visit##CLASS##Decl(D));                                             \
    460     return true;                                                               \
    461   }                                                                            \
    462   bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
    463 #include "clang/AST/DeclNodes.inc"
    464 
    465   bool canIgnoreChildDeclWhileTraversingDeclContext(const Decl *Child);
    466 
    467 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND)                                   \
    468   bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
    469   DEF_TRAVERSE_TMPL_INST(Class)
    470   DEF_TRAVERSE_TMPL_INST(Var)
    471   DEF_TRAVERSE_TMPL_INST(Function)
    472 #undef DEF_TRAVERSE_TMPL_INST
    473 
    474   bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
    475 
    476 private:
    477   // These are helper methods used by more than one Traverse* method.
    478   bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
    479 
    480   // Traverses template parameter lists of either a DeclaratorDecl or TagDecl.
    481   template <typename T>
    482   bool TraverseDeclTemplateParameterLists(T *D);
    483 
    484   bool TraverseTemplateTypeParamDeclConstraints(const TemplateTypeParmDecl *D);
    485 
    486   bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
    487                                           unsigned Count);
    488   bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
    489   bool TraverseRecordHelper(RecordDecl *D);
    490   bool TraverseCXXRecordHelper(CXXRecordDecl *D);
    491   bool TraverseDeclaratorHelper(DeclaratorDecl *D);
    492   bool TraverseDeclContextHelper(DeclContext *DC);
    493   bool TraverseFunctionHelper(FunctionDecl *D);
    494   bool TraverseVarHelper(VarDecl *D);
    495   bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
    496   bool TraverseOMPLoopDirective(OMPLoopDirective *S);
    497   bool TraverseOMPClause(OMPClause *C);
    498 #define GEN_CLANG_CLAUSE_CLASS
    499 #define CLAUSE_CLASS(Enum, Str, Class) bool Visit##Class(Class *C);
    500 #include "llvm/Frontend/OpenMP/OMP.inc"
    501   /// Process clauses with list of variables.
    502   template <typename T> bool VisitOMPClauseList(T *Node);
    503   /// Process clauses with pre-initis.
    504   bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
    505   bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
    506 
    507   bool PostVisitStmt(Stmt *S);
    508 };
    509 
    510 template <typename Derived>
    511 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
    512                                                     DataRecursionQueue *Queue) {
    513   // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
    514   switch (S->getStmtClass()) {
    515   case Stmt::NoStmtClass:
    516     break;
    517 #define ABSTRACT_STMT(STMT)
    518 #define STMT(CLASS, PARENT)                                                    \
    519   case Stmt::CLASS##Class:                                                     \
    520     return TRAVERSE_STMT_BASE(CLASS, CLASS, S, Queue);
    521 #include "clang/AST/StmtNodes.inc"
    522   }
    523 
    524   return true;
    525 }
    526 
    527 #undef DISPATCH_STMT
    528 
    529 template <typename Derived>
    530 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
    531   // In pre-order traversal mode, each Traverse##STMT method is responsible for
    532   // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and
    533   // does not call the default implementation, the WalkUpFrom callback is not
    534   // called. Post-order traversal mode should provide the same behavior
    535   // regarding method overrides.
    536   //
    537   // In post-order traversal mode the Traverse##STMT method, when it receives a
    538   // DataRecursionQueue, can't call WalkUpFrom after traversing children because
    539   // it only enqueues the children and does not traverse them. TraverseStmt
    540   // traverses the enqueued children, and we call WalkUpFrom here.
    541   //
    542   // However, to make pre-order and post-order modes identical with regards to
    543   // whether they call WalkUpFrom at all, we call WalkUpFrom if and only if the
    544   // user did not override the Traverse##STMT method. We implement the override
    545   // check with isSameMethod calls below.
    546 
    547   switch (S->getStmtClass()) {
    548   case Stmt::NoStmtClass:
    549     break;
    550 #define ABSTRACT_STMT(STMT)
    551 #define STMT(CLASS, PARENT)                                                    \
    552   case Stmt::CLASS##Class:                                                     \
    553     if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS,   \
    554                                       &Derived::Traverse##CLASS)) {            \
    555       TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S)));                      \
    556     }                                                                          \
    557     break;
    558 #define INITLISTEXPR(CLASS, PARENT)                                            \
    559   case Stmt::CLASS##Class:                                                     \
    560     if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS,   \
    561                                       &Derived::Traverse##CLASS)) {            \
    562       auto ILE = static_cast<CLASS *>(S);                                      \
    563       if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE)    \
    564         TRY_TO(WalkUpFrom##CLASS(Syn));                                        \
    565       if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm())     \
    566         TRY_TO(WalkUpFrom##CLASS(Sem));                                        \
    567     }                                                                          \
    568     break;
    569 #include "clang/AST/StmtNodes.inc"
    570   }
    571 
    572   return true;
    573 }
    574 
    575 #undef DISPATCH_STMT
    576 
    577 template <typename Derived>
    578 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S,
    579                                                 DataRecursionQueue *Queue) {
    580   if (!S)
    581     return true;
    582 
    583   if (Queue) {
    584     Queue->push_back({S, false});
    585     return true;
    586   }
    587 
    588   SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
    589   LocalQueue.push_back({S, false});
    590 
    591   while (!LocalQueue.empty()) {
    592     auto &CurrSAndVisited = LocalQueue.back();
    593     Stmt *CurrS = CurrSAndVisited.getPointer();
    594     bool Visited = CurrSAndVisited.getInt();
    595     if (Visited) {
    596       LocalQueue.pop_back();
    597       TRY_TO(dataTraverseStmtPost(CurrS));
    598       if (getDerived().shouldTraversePostOrder()) {
    599         TRY_TO(PostVisitStmt(CurrS));
    600       }
    601       continue;
    602     }
    603 
    604     if (getDerived().dataTraverseStmtPre(CurrS)) {
    605       CurrSAndVisited.setInt(true);
    606       size_t N = LocalQueue.size();
    607       TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
    608       // Process new children in the order they were added.
    609       std::reverse(LocalQueue.begin() + N, LocalQueue.end());
    610     } else {
    611       LocalQueue.pop_back();
    612     }
    613   }
    614 
    615   return true;
    616 }
    617 
    618 template <typename Derived>
    619 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
    620   if (T.isNull())
    621     return true;
    622 
    623   switch (T->getTypeClass()) {
    624 #define ABSTRACT_TYPE(CLASS, BASE)
    625 #define TYPE(CLASS, BASE)                                                      \
    626   case Type::CLASS:                                                            \
    627     return getDerived().Traverse##CLASS##Type(                                 \
    628         static_cast<CLASS##Type *>(const_cast<Type *>(T.getTypePtr())));
    629 #include "clang/AST/TypeNodes.inc"
    630   }
    631 
    632   return true;
    633 }
    634 
    635 template <typename Derived>
    636 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
    637   if (TL.isNull())
    638     return true;
    639 
    640   switch (TL.getTypeLocClass()) {
    641 #define ABSTRACT_TYPELOC(CLASS, BASE)
    642 #define TYPELOC(CLASS, BASE)                                                   \
    643   case TypeLoc::CLASS:                                                         \
    644     return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
    645 #include "clang/AST/TypeLocNodes.def"
    646   }
    647 
    648   return true;
    649 }
    650 
    651 // Define the Traverse*Attr(Attr* A) methods
    652 #define VISITORCLASS RecursiveASTVisitor
    653 #include "clang/AST/AttrVisitor.inc"
    654 #undef VISITORCLASS
    655 
    656 template <typename Derived>
    657 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
    658   if (!D)
    659     return true;
    660 
    661   // As a syntax visitor, by default we want to ignore declarations for
    662   // implicit declarations (ones not typed explicitly by the user).
    663   if (!getDerived().shouldVisitImplicitCode() && D->isImplicit()) {
    664     // For an implicit template type parameter, its type constraints are not
    665     // implicit and are not represented anywhere else. We still need to visit
    666     // them.
    667     if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(D))
    668       return TraverseTemplateTypeParamDeclConstraints(TTPD);
    669     return true;
    670   }
    671 
    672   switch (D->getKind()) {
    673 #define ABSTRACT_DECL(DECL)
    674 #define DECL(CLASS, BASE)                                                      \
    675   case Decl::CLASS:                                                            \
    676     if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D)))    \
    677       return false;                                                            \
    678     break;
    679 #include "clang/AST/DeclNodes.inc"
    680   }
    681   return true;
    682 }
    683 
    684 template <typename Derived>
    685 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
    686     NestedNameSpecifier *NNS) {
    687   if (!NNS)
    688     return true;
    689 
    690   if (NNS->getPrefix())
    691     TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
    692 
    693   switch (NNS->getKind()) {
    694   case NestedNameSpecifier::Identifier:
    695   case NestedNameSpecifier::Namespace:
    696   case NestedNameSpecifier::NamespaceAlias:
    697   case NestedNameSpecifier::Global:
    698   case NestedNameSpecifier::Super:
    699     return true;
    700 
    701   case NestedNameSpecifier::TypeSpec:
    702   case NestedNameSpecifier::TypeSpecWithTemplate:
    703     TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
    704   }
    705 
    706   return true;
    707 }
    708 
    709 template <typename Derived>
    710 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
    711     NestedNameSpecifierLoc NNS) {
    712   if (!NNS)
    713     return true;
    714 
    715   if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
    716     TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
    717 
    718   switch (NNS.getNestedNameSpecifier()->getKind()) {
    719   case NestedNameSpecifier::Identifier:
    720   case NestedNameSpecifier::Namespace:
    721   case NestedNameSpecifier::NamespaceAlias:
    722   case NestedNameSpecifier::Global:
    723   case NestedNameSpecifier::Super:
    724     return true;
    725 
    726   case NestedNameSpecifier::TypeSpec:
    727   case NestedNameSpecifier::TypeSpecWithTemplate:
    728     TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
    729     break;
    730   }
    731 
    732   return true;
    733 }
    734 
    735 template <typename Derived>
    736 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
    737     DeclarationNameInfo NameInfo) {
    738   switch (NameInfo.getName().getNameKind()) {
    739   case DeclarationName::CXXConstructorName:
    740   case DeclarationName::CXXDestructorName:
    741   case DeclarationName::CXXConversionFunctionName:
    742     if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
    743       TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
    744     break;
    745 
    746   case DeclarationName::CXXDeductionGuideName:
    747     TRY_TO(TraverseTemplateName(
    748         TemplateName(NameInfo.getName().getCXXDeductionGuideTemplate())));
    749     break;
    750 
    751   case DeclarationName::Identifier:
    752   case DeclarationName::ObjCZeroArgSelector:
    753   case DeclarationName::ObjCOneArgSelector:
    754   case DeclarationName::ObjCMultiArgSelector:
    755   case DeclarationName::CXXOperatorName:
    756   case DeclarationName::CXXLiteralOperatorName:
    757   case DeclarationName::CXXUsingDirective:
    758     break;
    759   }
    760 
    761   return true;
    762 }
    763 
    764 template <typename Derived>
    765 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
    766   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
    767     TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
    768   else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
    769     TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
    770 
    771   return true;
    772 }
    773 
    774 template <typename Derived>
    775 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
    776     const TemplateArgument &Arg) {
    777   switch (Arg.getKind()) {
    778   case TemplateArgument::Null:
    779   case TemplateArgument::Declaration:
    780   case TemplateArgument::Integral:
    781   case TemplateArgument::NullPtr:
    782     return true;
    783 
    784   case TemplateArgument::Type:
    785     return getDerived().TraverseType(Arg.getAsType());
    786 
    787   case TemplateArgument::Template:
    788   case TemplateArgument::TemplateExpansion:
    789     return getDerived().TraverseTemplateName(
    790         Arg.getAsTemplateOrTemplatePattern());
    791 
    792   case TemplateArgument::Expression:
    793     return getDerived().TraverseStmt(Arg.getAsExpr());
    794 
    795   case TemplateArgument::Pack:
    796     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
    797                                                   Arg.pack_size());
    798   }
    799 
    800   return true;
    801 }
    802 
    803 // FIXME: no template name location?
    804 // FIXME: no source locations for a template argument pack?
    805 template <typename Derived>
    806 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
    807     const TemplateArgumentLoc &ArgLoc) {
    808   const TemplateArgument &Arg = ArgLoc.getArgument();
    809 
    810   switch (Arg.getKind()) {
    811   case TemplateArgument::Null:
    812   case TemplateArgument::Declaration:
    813   case TemplateArgument::Integral:
    814   case TemplateArgument::NullPtr:
    815     return true;
    816 
    817   case TemplateArgument::Type: {
    818     // FIXME: how can TSI ever be NULL?
    819     if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
    820       return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
    821     else
    822       return getDerived().TraverseType(Arg.getAsType());
    823   }
    824 
    825   case TemplateArgument::Template:
    826   case TemplateArgument::TemplateExpansion:
    827     if (ArgLoc.getTemplateQualifierLoc())
    828       TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
    829           ArgLoc.getTemplateQualifierLoc()));
    830     return getDerived().TraverseTemplateName(
    831         Arg.getAsTemplateOrTemplatePattern());
    832 
    833   case TemplateArgument::Expression:
    834     return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
    835 
    836   case TemplateArgument::Pack:
    837     return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
    838                                                   Arg.pack_size());
    839   }
    840 
    841   return true;
    842 }
    843 
    844 template <typename Derived>
    845 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
    846     const TemplateArgument *Args, unsigned NumArgs) {
    847   for (unsigned I = 0; I != NumArgs; ++I) {
    848     TRY_TO(TraverseTemplateArgument(Args[I]));
    849   }
    850 
    851   return true;
    852 }
    853 
    854 template <typename Derived>
    855 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
    856     CXXCtorInitializer *Init) {
    857   if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
    858     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
    859 
    860   if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
    861     TRY_TO(TraverseStmt(Init->getInit()));
    862 
    863   return true;
    864 }
    865 
    866 template <typename Derived>
    867 bool
    868 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
    869                                                     const LambdaCapture *C,
    870                                                     Expr *Init) {
    871   if (LE->isInitCapture(C))
    872     TRY_TO(TraverseDecl(C->getCapturedVar()));
    873   else
    874     TRY_TO(TraverseStmt(Init));
    875   return true;
    876 }
    877 
    878 // ----------------- Type traversal -----------------
    879 
    880 // This macro makes available a variable T, the passed-in type.
    881 #define DEF_TRAVERSE_TYPE(TYPE, CODE)                                          \
    882   template <typename Derived>                                                  \
    883   bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) {                 \
    884     if (!getDerived().shouldTraversePostOrder())                               \
    885       TRY_TO(WalkUpFrom##TYPE(T));                                             \
    886     { CODE; }                                                                  \
    887     if (getDerived().shouldTraversePostOrder())                                \
    888       TRY_TO(WalkUpFrom##TYPE(T));                                             \
    889     return true;                                                               \
    890   }
    891 
    892 DEF_TRAVERSE_TYPE(BuiltinType, {})
    893 
    894 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
    895 
    896 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
    897 
    898 DEF_TRAVERSE_TYPE(BlockPointerType,
    899                   { TRY_TO(TraverseType(T->getPointeeType())); })
    900 
    901 DEF_TRAVERSE_TYPE(LValueReferenceType,
    902                   { TRY_TO(TraverseType(T->getPointeeType())); })
    903 
    904 DEF_TRAVERSE_TYPE(RValueReferenceType,
    905                   { TRY_TO(TraverseType(T->getPointeeType())); })
    906 
    907 DEF_TRAVERSE_TYPE(MemberPointerType, {
    908   TRY_TO(TraverseType(QualType(T->getClass(), 0)));
    909   TRY_TO(TraverseType(T->getPointeeType()));
    910 })
    911 
    912 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
    913 
    914 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
    915 
    916 DEF_TRAVERSE_TYPE(ConstantArrayType, {
    917   TRY_TO(TraverseType(T->getElementType()));
    918   if (T->getSizeExpr())
    919     TRY_TO(TraverseStmt(const_cast<Expr*>(T->getSizeExpr())));
    920 })
    921 
    922 DEF_TRAVERSE_TYPE(IncompleteArrayType,
    923                   { TRY_TO(TraverseType(T->getElementType())); })
    924 
    925 DEF_TRAVERSE_TYPE(VariableArrayType, {
    926   TRY_TO(TraverseType(T->getElementType()));
    927   TRY_TO(TraverseStmt(T->getSizeExpr()));
    928 })
    929 
    930 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
    931   TRY_TO(TraverseType(T->getElementType()));
    932   if (T->getSizeExpr())
    933     TRY_TO(TraverseStmt(T->getSizeExpr()));
    934 })
    935 
    936 DEF_TRAVERSE_TYPE(DependentAddressSpaceType, {
    937   TRY_TO(TraverseStmt(T->getAddrSpaceExpr()));
    938   TRY_TO(TraverseType(T->getPointeeType()));
    939 })
    940 
    941 DEF_TRAVERSE_TYPE(DependentVectorType, {
    942   if (T->getSizeExpr())
    943     TRY_TO(TraverseStmt(T->getSizeExpr()));
    944   TRY_TO(TraverseType(T->getElementType()));
    945 })
    946 
    947 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
    948   if (T->getSizeExpr())
    949     TRY_TO(TraverseStmt(T->getSizeExpr()));
    950   TRY_TO(TraverseType(T->getElementType()));
    951 })
    952 
    953 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
    954 
    955 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
    956 
    957 DEF_TRAVERSE_TYPE(ConstantMatrixType,
    958                   { TRY_TO(TraverseType(T->getElementType())); })
    959 
    960 DEF_TRAVERSE_TYPE(DependentSizedMatrixType, {
    961   if (T->getRowExpr())
    962     TRY_TO(TraverseStmt(T->getRowExpr()));
    963   if (T->getColumnExpr())
    964     TRY_TO(TraverseStmt(T->getColumnExpr()));
    965   TRY_TO(TraverseType(T->getElementType()));
    966 })
    967 
    968 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
    969                   { TRY_TO(TraverseType(T->getReturnType())); })
    970 
    971 DEF_TRAVERSE_TYPE(FunctionProtoType, {
    972   TRY_TO(TraverseType(T->getReturnType()));
    973 
    974   for (const auto &A : T->param_types()) {
    975     TRY_TO(TraverseType(A));
    976   }
    977 
    978   for (const auto &E : T->exceptions()) {
    979     TRY_TO(TraverseType(E));
    980   }
    981 
    982   if (Expr *NE = T->getNoexceptExpr())
    983     TRY_TO(TraverseStmt(NE));
    984 })
    985 
    986 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
    987 DEF_TRAVERSE_TYPE(TypedefType, {})
    988 
    989 DEF_TRAVERSE_TYPE(TypeOfExprType,
    990                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
    991 
    992 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
    993 
    994 DEF_TRAVERSE_TYPE(DecltypeType,
    995                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
    996 
    997 DEF_TRAVERSE_TYPE(UnaryTransformType, {
    998   TRY_TO(TraverseType(T->getBaseType()));
    999   TRY_TO(TraverseType(T->getUnderlyingType()));
   1000 })
   1001 
   1002 DEF_TRAVERSE_TYPE(AutoType, {
   1003   TRY_TO(TraverseType(T->getDeducedType()));
   1004   if (T->isConstrained()) {
   1005     TRY_TO(TraverseDecl(T->getTypeConstraintConcept()));
   1006     TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
   1007   }
   1008 })
   1009 DEF_TRAVERSE_TYPE(DeducedTemplateSpecializationType, {
   1010   TRY_TO(TraverseTemplateName(T->getTemplateName()));
   1011   TRY_TO(TraverseType(T->getDeducedType()));
   1012 })
   1013 
   1014 DEF_TRAVERSE_TYPE(RecordType, {})
   1015 DEF_TRAVERSE_TYPE(EnumType, {})
   1016 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
   1017 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {
   1018   TRY_TO(TraverseType(T->getReplacementType()));
   1019 })
   1020 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {
   1021   TRY_TO(TraverseTemplateArgument(T->getArgumentPack()));
   1022 })
   1023 
   1024 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
   1025   TRY_TO(TraverseTemplateName(T->getTemplateName()));
   1026   TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
   1027 })
   1028 
   1029 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
   1030 
   1031 DEF_TRAVERSE_TYPE(AttributedType,
   1032                   { TRY_TO(TraverseType(T->getModifiedType())); })
   1033 
   1034 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
   1035 
   1036 DEF_TRAVERSE_TYPE(MacroQualifiedType,
   1037                   { TRY_TO(TraverseType(T->getUnderlyingType())); })
   1038 
   1039 DEF_TRAVERSE_TYPE(ElaboratedType, {
   1040   if (T->getQualifier()) {
   1041     TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
   1042   }
   1043   TRY_TO(TraverseType(T->getNamedType()));
   1044 })
   1045 
   1046 DEF_TRAVERSE_TYPE(DependentNameType,
   1047                   { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
   1048 
   1049 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
   1050   TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
   1051   TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
   1052 })
   1053 
   1054 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
   1055 
   1056 DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
   1057 
   1058 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
   1059 
   1060 DEF_TRAVERSE_TYPE(ObjCObjectType, {
   1061   // We have to watch out here because an ObjCInterfaceType's base
   1062   // type is itself.
   1063   if (T->getBaseType().getTypePtr() != T)
   1064     TRY_TO(TraverseType(T->getBaseType()));
   1065   for (auto typeArg : T->getTypeArgsAsWritten()) {
   1066     TRY_TO(TraverseType(typeArg));
   1067   }
   1068 })
   1069 
   1070 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
   1071                   { TRY_TO(TraverseType(T->getPointeeType())); })
   1072 
   1073 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
   1074 
   1075 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
   1076 
   1077 DEF_TRAVERSE_TYPE(ExtIntType, {})
   1078 DEF_TRAVERSE_TYPE(DependentExtIntType,
   1079                   { TRY_TO(TraverseStmt(T->getNumBitsExpr())); })
   1080 
   1081 #undef DEF_TRAVERSE_TYPE
   1082 
   1083 // ----------------- TypeLoc traversal -----------------
   1084 
   1085 // This macro makes available a variable TL, the passed-in TypeLoc.
   1086 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
   1087 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
   1088 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
   1089 // continue to work.
   1090 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE)                                       \
   1091   template <typename Derived>                                                  \
   1092   bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) {       \
   1093     if (!getDerived().shouldTraversePostOrder()) {                             \
   1094       TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                       \
   1095       if (getDerived().shouldWalkTypesOfTypeLocs())                            \
   1096         TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr())));         \
   1097     }                                                                          \
   1098     { CODE; }                                                                  \
   1099     if (getDerived().shouldTraversePostOrder()) {                              \
   1100       TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                       \
   1101       if (getDerived().shouldWalkTypesOfTypeLocs())                            \
   1102         TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr())));         \
   1103     }                                                                          \
   1104     return true;                                                               \
   1105   }
   1106 
   1107 template <typename Derived>
   1108 bool
   1109 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
   1110   // Move this over to the 'main' typeloc tree.  Note that this is a
   1111   // move -- we pretend that we were really looking at the unqualified
   1112   // typeloc all along -- rather than a recursion, so we don't follow
   1113   // the normal CRTP plan of going through
   1114   // getDerived().TraverseTypeLoc.  If we did, we'd be traversing
   1115   // twice for the same type (once as a QualifiedTypeLoc version of
   1116   // the type, once as an UnqualifiedTypeLoc version of the type),
   1117   // which in effect means we'd call VisitTypeLoc twice with the
   1118   // 'same' type.  This solves that problem, at the cost of never
   1119   // seeing the qualified version of the type (unless the client
   1120   // subclasses TraverseQualifiedTypeLoc themselves).  It's not a
   1121   // perfect solution.  A perfect solution probably requires making
   1122   // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
   1123   // wrapper around Type* -- rather than being its own class in the
   1124   // type hierarchy.
   1125   return TraverseTypeLoc(TL.getUnqualifiedLoc());
   1126 }
   1127 
   1128 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
   1129 
   1130 // FIXME: ComplexTypeLoc is unfinished
   1131 DEF_TRAVERSE_TYPELOC(ComplexType, {
   1132   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1133 })
   1134 
   1135 DEF_TRAVERSE_TYPELOC(PointerType,
   1136                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
   1137 
   1138 DEF_TRAVERSE_TYPELOC(BlockPointerType,
   1139                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
   1140 
   1141 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
   1142                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
   1143 
   1144 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
   1145                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
   1146 
   1147 // We traverse this in the type case as well, but how is it not reached through
   1148 // the pointee type?
   1149 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
   1150   if (auto *TSI = TL.getClassTInfo())
   1151     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
   1152   else
   1153     TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
   1154   TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
   1155 })
   1156 
   1157 DEF_TRAVERSE_TYPELOC(AdjustedType,
   1158                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
   1159 
   1160 DEF_TRAVERSE_TYPELOC(DecayedType,
   1161                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
   1162 
   1163 template <typename Derived>
   1164 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
   1165   // This isn't available for ArrayType, but is for the ArrayTypeLoc.
   1166   TRY_TO(TraverseStmt(TL.getSizeExpr()));
   1167   return true;
   1168 }
   1169 
   1170 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
   1171   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
   1172   TRY_TO(TraverseArrayTypeLocHelper(TL));
   1173 })
   1174 
   1175 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
   1176   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
   1177   TRY_TO(TraverseArrayTypeLocHelper(TL));
   1178 })
   1179 
   1180 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
   1181   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
   1182   TRY_TO(TraverseArrayTypeLocHelper(TL));
   1183 })
   1184 
   1185 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
   1186   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
   1187   TRY_TO(TraverseArrayTypeLocHelper(TL));
   1188 })
   1189 
   1190 DEF_TRAVERSE_TYPELOC(DependentAddressSpaceType, {
   1191   TRY_TO(TraverseStmt(TL.getTypePtr()->getAddrSpaceExpr()));
   1192   TRY_TO(TraverseType(TL.getTypePtr()->getPointeeType()));
   1193 })
   1194 
   1195 // FIXME: order? why not size expr first?
   1196 // FIXME: base VectorTypeLoc is unfinished
   1197 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
   1198   if (TL.getTypePtr()->getSizeExpr())
   1199     TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
   1200   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1201 })
   1202 
   1203 // FIXME: VectorTypeLoc is unfinished
   1204 DEF_TRAVERSE_TYPELOC(VectorType, {
   1205   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1206 })
   1207 
   1208 DEF_TRAVERSE_TYPELOC(DependentVectorType, {
   1209   if (TL.getTypePtr()->getSizeExpr())
   1210     TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
   1211   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1212 })
   1213 
   1214 // FIXME: size and attributes
   1215 // FIXME: base VectorTypeLoc is unfinished
   1216 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
   1217   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1218 })
   1219 
   1220 DEF_TRAVERSE_TYPELOC(ConstantMatrixType, {
   1221   TRY_TO(TraverseStmt(TL.getAttrRowOperand()));
   1222   TRY_TO(TraverseStmt(TL.getAttrColumnOperand()));
   1223   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1224 })
   1225 
   1226 DEF_TRAVERSE_TYPELOC(DependentSizedMatrixType, {
   1227   TRY_TO(TraverseStmt(TL.getAttrRowOperand()));
   1228   TRY_TO(TraverseStmt(TL.getAttrColumnOperand()));
   1229   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
   1230 })
   1231 
   1232 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
   1233                      { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
   1234 
   1235 // FIXME: location of exception specifications (attributes?)
   1236 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
   1237   TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
   1238 
   1239   const FunctionProtoType *T = TL.getTypePtr();
   1240 
   1241   for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
   1242     if (TL.getParam(I)) {
   1243       TRY_TO(TraverseDecl(TL.getParam(I)));
   1244     } else if (I < T->getNumParams()) {
   1245       TRY_TO(TraverseType(T->getParamType(I)));
   1246     }
   1247   }
   1248 
   1249   for (const auto &E : T->exceptions()) {
   1250     TRY_TO(TraverseType(E));
   1251   }
   1252 
   1253   if (Expr *NE = T->getNoexceptExpr())
   1254     TRY_TO(TraverseStmt(NE));
   1255 })
   1256 
   1257 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
   1258 DEF_TRAVERSE_TYPELOC(TypedefType, {})
   1259 
   1260 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
   1261                      { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
   1262 
   1263 DEF_TRAVERSE_TYPELOC(TypeOfType, {
   1264   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
   1265 })
   1266 
   1267 // FIXME: location of underlying expr
   1268 DEF_TRAVERSE_TYPELOC(DecltypeType, {
   1269   TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
   1270 })
   1271 
   1272 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
   1273   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
   1274 })
   1275 
   1276 DEF_TRAVERSE_TYPELOC(AutoType, {
   1277   TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
   1278   if (TL.isConstrained()) {
   1279     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getNestedNameSpecifierLoc()));
   1280     TRY_TO(TraverseDeclarationNameInfo(TL.getConceptNameInfo()));
   1281     for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
   1282       TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
   1283   }
   1284 })
   1285 
   1286 DEF_TRAVERSE_TYPELOC(DeducedTemplateSpecializationType, {
   1287   TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
   1288   TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
   1289 })
   1290 
   1291 DEF_TRAVERSE_TYPELOC(RecordType, {})
   1292 DEF_TRAVERSE_TYPELOC(EnumType, {})
   1293 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
   1294 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {
   1295   TRY_TO(TraverseType(TL.getTypePtr()->getReplacementType()));
   1296 })
   1297 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {
   1298   TRY_TO(TraverseTemplateArgument(TL.getTypePtr()->getArgumentPack()));
   1299 })
   1300 
   1301 // FIXME: use the loc for the template name?
   1302 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
   1303   TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
   1304   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
   1305     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
   1306   }
   1307 })
   1308 
   1309 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
   1310 
   1311 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
   1312 
   1313 DEF_TRAVERSE_TYPELOC(MacroQualifiedType,
   1314                      { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
   1315 
   1316 DEF_TRAVERSE_TYPELOC(AttributedType,
   1317                      { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
   1318 
   1319 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
   1320   if (TL.getQualifierLoc()) {
   1321     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
   1322   }
   1323   TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
   1324 })
   1325 
   1326 DEF_TRAVERSE_TYPELOC(DependentNameType, {
   1327   TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
   1328 })
   1329 
   1330 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
   1331   if (TL.getQualifierLoc()) {
   1332     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
   1333   }
   1334 
   1335   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
   1336     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
   1337   }
   1338 })
   1339 
   1340 DEF_TRAVERSE_TYPELOC(PackExpansionType,
   1341                      { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
   1342 
   1343 DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {})
   1344 
   1345 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
   1346 
   1347 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
   1348   // We have to watch out here because an ObjCInterfaceType's base
   1349   // type is itself.
   1350   if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
   1351     TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
   1352   for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
   1353     TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
   1354 })
   1355 
   1356 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
   1357                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
   1358 
   1359 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
   1360 
   1361 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
   1362 
   1363 DEF_TRAVERSE_TYPELOC(ExtIntType, {})
   1364 DEF_TRAVERSE_TYPELOC(DependentExtIntType, {
   1365   TRY_TO(TraverseStmt(TL.getTypePtr()->getNumBitsExpr()));
   1366 })
   1367 
   1368 #undef DEF_TRAVERSE_TYPELOC
   1369 
   1370 // ----------------- Decl traversal -----------------
   1371 //
   1372 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
   1373 // the children that come from the DeclContext associated with it.
   1374 // Therefore each Traverse* only needs to worry about children other
   1375 // than those.
   1376 
   1377 template <typename Derived>
   1378 bool RecursiveASTVisitor<Derived>::canIgnoreChildDeclWhileTraversingDeclContext(
   1379     const Decl *Child) {
   1380   // BlockDecls are traversed through BlockExprs,
   1381   // CapturedDecls are traversed through CapturedStmts.
   1382   if (isa<BlockDecl>(Child) || isa<CapturedDecl>(Child))
   1383     return true;
   1384   // Lambda classes are traversed through LambdaExprs.
   1385   if (const CXXRecordDecl* Cls = dyn_cast<CXXRecordDecl>(Child))
   1386     return Cls->isLambda();
   1387   return false;
   1388 }
   1389 
   1390 template <typename Derived>
   1391 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
   1392   if (!DC)
   1393     return true;
   1394 
   1395   for (auto *Child : DC->decls()) {
   1396     if (!canIgnoreChildDeclWhileTraversingDeclContext(Child))
   1397       TRY_TO(TraverseDecl(Child));
   1398   }
   1399 
   1400   return true;
   1401 }
   1402 
   1403 // This macro makes available a variable D, the passed-in decl.
   1404 #define DEF_TRAVERSE_DECL(DECL, CODE)                                          \
   1405   template <typename Derived>                                                  \
   1406   bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) {                 \
   1407     bool ShouldVisitChildren = true;                                           \
   1408     bool ReturnValue = true;                                                   \
   1409     if (!getDerived().shouldTraversePostOrder())                               \
   1410       TRY_TO(WalkUpFrom##DECL(D));                                             \
   1411     { CODE; }                                                                  \
   1412     if (ReturnValue && ShouldVisitChildren)                                    \
   1413       TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D)));             \
   1414     if (ReturnValue) {                                                         \
   1415       /* Visit any attributes attached to this declaration. */                 \
   1416       for (auto *I : D->attrs())                                               \
   1417         TRY_TO(getDerived().TraverseAttr(I));                                  \
   1418     }                                                                          \
   1419     if (ReturnValue && getDerived().shouldTraversePostOrder())                 \
   1420       TRY_TO(WalkUpFrom##DECL(D));                                             \
   1421     return ReturnValue;                                                        \
   1422   }
   1423 
   1424 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
   1425 
   1426 DEF_TRAVERSE_DECL(BlockDecl, {
   1427   if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
   1428     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
   1429   TRY_TO(TraverseStmt(D->getBody()));
   1430   for (const auto &I : D->captures()) {
   1431     if (I.hasCopyExpr()) {
   1432       TRY_TO(TraverseStmt(I.getCopyExpr()));
   1433     }
   1434   }
   1435   ShouldVisitChildren = false;
   1436 })
   1437 
   1438 DEF_TRAVERSE_DECL(CapturedDecl, {
   1439   TRY_TO(TraverseStmt(D->getBody()));
   1440   ShouldVisitChildren = false;
   1441 })
   1442 
   1443 DEF_TRAVERSE_DECL(EmptyDecl, {})
   1444 
   1445 DEF_TRAVERSE_DECL(LifetimeExtendedTemporaryDecl, {
   1446   TRY_TO(TraverseStmt(D->getTemporaryExpr()));
   1447 })
   1448 
   1449 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
   1450                   { TRY_TO(TraverseStmt(D->getAsmString())); })
   1451 
   1452 DEF_TRAVERSE_DECL(ImportDecl, {})
   1453 
   1454 DEF_TRAVERSE_DECL(FriendDecl, {
   1455   // Friend is either decl or a type.
   1456   if (D->getFriendType())
   1457     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
   1458   else
   1459     TRY_TO(TraverseDecl(D->getFriendDecl()));
   1460 })
   1461 
   1462 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
   1463   if (D->getFriendType())
   1464     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
   1465   else
   1466     TRY_TO(TraverseDecl(D->getFriendDecl()));
   1467   for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
   1468     TemplateParameterList *TPL = D->getTemplateParameterList(I);
   1469     for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
   1470          ITPL != ETPL; ++ITPL) {
   1471       TRY_TO(TraverseDecl(*ITPL));
   1472     }
   1473   }
   1474 })
   1475 
   1476 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
   1477   TRY_TO(TraverseDecl(D->getSpecialization()));
   1478 
   1479   if (D->hasExplicitTemplateArgs()) {
   1480     TRY_TO(TraverseTemplateArgumentLocsHelper(
   1481         D->getTemplateArgsAsWritten()->getTemplateArgs(),
   1482         D->getTemplateArgsAsWritten()->NumTemplateArgs));
   1483   }
   1484 })
   1485 
   1486 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
   1487 
   1488 DEF_TRAVERSE_DECL(ExportDecl, {})
   1489 
   1490 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
   1491                                         })
   1492 
   1493 DEF_TRAVERSE_DECL(StaticAssertDecl, {
   1494   TRY_TO(TraverseStmt(D->getAssertExpr()));
   1495   TRY_TO(TraverseStmt(D->getMessage()));
   1496 })
   1497 
   1498 DEF_TRAVERSE_DECL(
   1499     TranslationUnitDecl,
   1500     {// Code in an unnamed namespace shows up automatically in
   1501      // decls_begin()/decls_end().  Thus we don't need to recurse on
   1502      // D->getAnonymousNamespace().
   1503     })
   1504 
   1505 DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
   1506 
   1507 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
   1508 
   1509 DEF_TRAVERSE_DECL(ExternCContextDecl, {})
   1510 
   1511 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
   1512   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1513 
   1514   // We shouldn't traverse an aliased namespace, since it will be
   1515   // defined (and, therefore, traversed) somewhere else.
   1516   ShouldVisitChildren = false;
   1517 })
   1518 
   1519 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
   1520                              })
   1521 
   1522 DEF_TRAVERSE_DECL(
   1523     NamespaceDecl,
   1524     {// Code in an unnamed namespace shows up automatically in
   1525      // decls_begin()/decls_end().  Thus we don't need to recurse on
   1526      // D->getAnonymousNamespace().
   1527     })
   1528 
   1529 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
   1530                                            })
   1531 
   1532 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
   1533   if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
   1534     for (auto typeParam : *typeParamList) {
   1535       TRY_TO(TraverseObjCTypeParamDecl(typeParam));
   1536     }
   1537   }
   1538 })
   1539 
   1540 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
   1541                                         })
   1542 
   1543 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
   1544                                           })
   1545 
   1546 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
   1547   if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
   1548     for (auto typeParam : *typeParamList) {
   1549       TRY_TO(TraverseObjCTypeParamDecl(typeParam));
   1550     }
   1551   }
   1552 
   1553   if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
   1554     TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
   1555   }
   1556 })
   1557 
   1558 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
   1559                                     })
   1560 
   1561 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
   1562   if (D->getReturnTypeSourceInfo()) {
   1563     TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
   1564   }
   1565   for (ParmVarDecl *Parameter : D->parameters()) {
   1566     TRY_TO(TraverseDecl(Parameter));
   1567   }
   1568   if (D->isThisDeclarationADefinition()) {
   1569     TRY_TO(TraverseStmt(D->getBody()));
   1570   }
   1571   ShouldVisitChildren = false;
   1572 })
   1573 
   1574 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
   1575   if (D->hasExplicitBound()) {
   1576     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1577     // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1578     // declaring the type alias, not something that was written in the
   1579     // source.
   1580   }
   1581 })
   1582 
   1583 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
   1584   if (D->getTypeSourceInfo())
   1585     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1586   else
   1587     TRY_TO(TraverseType(D->getType()));
   1588   ShouldVisitChildren = false;
   1589 })
   1590 
   1591 DEF_TRAVERSE_DECL(UsingDecl, {
   1592   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1593   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
   1594 })
   1595 
   1596 DEF_TRAVERSE_DECL(UsingPackDecl, {})
   1597 
   1598 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
   1599   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1600 })
   1601 
   1602 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
   1603 
   1604 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
   1605 
   1606 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
   1607   for (auto *I : D->varlists()) {
   1608     TRY_TO(TraverseStmt(I));
   1609   }
   1610  })
   1611 
   1612 DEF_TRAVERSE_DECL(OMPRequiresDecl, {
   1613   for (auto *C : D->clauselists()) {
   1614     TRY_TO(TraverseOMPClause(C));
   1615   }
   1616 })
   1617 
   1618 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
   1619   TRY_TO(TraverseStmt(D->getCombiner()));
   1620   if (auto *Initializer = D->getInitializer())
   1621     TRY_TO(TraverseStmt(Initializer));
   1622   TRY_TO(TraverseType(D->getType()));
   1623   return true;
   1624 })
   1625 
   1626 DEF_TRAVERSE_DECL(OMPDeclareMapperDecl, {
   1627   for (auto *C : D->clauselists())
   1628     TRY_TO(TraverseOMPClause(C));
   1629   TRY_TO(TraverseType(D->getType()));
   1630   return true;
   1631 })
   1632 
   1633 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
   1634 
   1635 DEF_TRAVERSE_DECL(OMPAllocateDecl, {
   1636   for (auto *I : D->varlists())
   1637     TRY_TO(TraverseStmt(I));
   1638   for (auto *C : D->clauselists())
   1639     TRY_TO(TraverseOMPClause(C));
   1640 })
   1641 
   1642 // A helper method for TemplateDecl's children.
   1643 template <typename Derived>
   1644 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
   1645     TemplateParameterList *TPL) {
   1646   if (TPL) {
   1647     for (NamedDecl *D : *TPL) {
   1648       TRY_TO(TraverseDecl(D));
   1649     }
   1650     if (Expr *RequiresClause = TPL->getRequiresClause()) {
   1651       TRY_TO(TraverseStmt(RequiresClause));
   1652     }
   1653   }
   1654   return true;
   1655 }
   1656 
   1657 template <typename Derived>
   1658 template <typename T>
   1659 bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) {
   1660   for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) {
   1661     TemplateParameterList *TPL = D->getTemplateParameterList(i);
   1662     TraverseTemplateParameterListHelper(TPL);
   1663   }
   1664   return true;
   1665 }
   1666 
   1667 template <typename Derived>
   1668 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
   1669     ClassTemplateDecl *D) {
   1670   for (auto *SD : D->specializations()) {
   1671     for (auto *RD : SD->redecls()) {
   1672       // We don't want to visit injected-class-names in this traversal.
   1673       if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
   1674         continue;
   1675 
   1676       switch (
   1677           cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
   1678       // Visit the implicit instantiations with the requested pattern.
   1679       case TSK_Undeclared:
   1680       case TSK_ImplicitInstantiation:
   1681         TRY_TO(TraverseDecl(RD));
   1682         break;
   1683 
   1684       // We don't need to do anything on an explicit instantiation
   1685       // or explicit specialization because there will be an explicit
   1686       // node for it elsewhere.
   1687       case TSK_ExplicitInstantiationDeclaration:
   1688       case TSK_ExplicitInstantiationDefinition:
   1689       case TSK_ExplicitSpecialization:
   1690         break;
   1691       }
   1692     }
   1693   }
   1694 
   1695   return true;
   1696 }
   1697 
   1698 template <typename Derived>
   1699 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
   1700     VarTemplateDecl *D) {
   1701   for (auto *SD : D->specializations()) {
   1702     for (auto *RD : SD->redecls()) {
   1703       switch (
   1704           cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
   1705       case TSK_Undeclared:
   1706       case TSK_ImplicitInstantiation:
   1707         TRY_TO(TraverseDecl(RD));
   1708         break;
   1709 
   1710       case TSK_ExplicitInstantiationDeclaration:
   1711       case TSK_ExplicitInstantiationDefinition:
   1712       case TSK_ExplicitSpecialization:
   1713         break;
   1714       }
   1715     }
   1716   }
   1717 
   1718   return true;
   1719 }
   1720 
   1721 // A helper method for traversing the instantiations of a
   1722 // function while skipping its specializations.
   1723 template <typename Derived>
   1724 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
   1725     FunctionTemplateDecl *D) {
   1726   for (auto *FD : D->specializations()) {
   1727     for (auto *RD : FD->redecls()) {
   1728       switch (RD->getTemplateSpecializationKind()) {
   1729       case TSK_Undeclared:
   1730       case TSK_ImplicitInstantiation:
   1731         // We don't know what kind of FunctionDecl this is.
   1732         TRY_TO(TraverseDecl(RD));
   1733         break;
   1734 
   1735       // FIXME: For now traverse explicit instantiations here. Change that
   1736       // once they are represented as dedicated nodes in the AST.
   1737       case TSK_ExplicitInstantiationDeclaration:
   1738       case TSK_ExplicitInstantiationDefinition:
   1739         TRY_TO(TraverseDecl(RD));
   1740         break;
   1741 
   1742       case TSK_ExplicitSpecialization:
   1743         break;
   1744       }
   1745     }
   1746   }
   1747 
   1748   return true;
   1749 }
   1750 
   1751 // This macro unifies the traversal of class, variable and function
   1752 // template declarations.
   1753 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND)                                   \
   1754   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, {                              \
   1755     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));   \
   1756     TRY_TO(TraverseDecl(D->getTemplatedDecl()));                               \
   1757                                                                                \
   1758     /* By default, we do not traverse the instantiations of                    \
   1759        class templates since they do not appear in the user code. The          \
   1760        following code optionally traverses them.                               \
   1761                                                                                \
   1762        We only traverse the class instantiations when we see the canonical     \
   1763        declaration of the template, to ensure we only visit them once. */      \
   1764     if (getDerived().shouldVisitTemplateInstantiations() &&                    \
   1765         D == D->getCanonicalDecl())                                            \
   1766       TRY_TO(TraverseTemplateInstantiations(D));                               \
   1767                                                                                \
   1768     /* Note that getInstantiatedFromMemberTemplate() is just a link            \
   1769        from a template instantiation back to the template from which           \
   1770        it was instantiated, and thus should not be traversed. */               \
   1771   })
   1772 
   1773 DEF_TRAVERSE_TMPL_DECL(Class)
   1774 DEF_TRAVERSE_TMPL_DECL(Var)
   1775 DEF_TRAVERSE_TMPL_DECL(Function)
   1776 
   1777 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
   1778   // D is the "T" in something like
   1779   //   template <template <typename> class T> class container { };
   1780   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
   1781   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
   1782     TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
   1783   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
   1784 })
   1785 
   1786 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
   1787   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
   1788 })
   1789 
   1790 template <typename Derived>
   1791 bool RecursiveASTVisitor<Derived>::TraverseTemplateTypeParamDeclConstraints(
   1792     const TemplateTypeParmDecl *D) {
   1793   if (const auto *TC = D->getTypeConstraint()) {
   1794     if (Expr *IDC = TC->getImmediatelyDeclaredConstraint()) {
   1795       TRY_TO(TraverseStmt(IDC));
   1796     } else {
   1797       // Avoid traversing the ConceptReference in the TypeCosntraint
   1798       // if we have an immediately-declared-constraint, otherwise
   1799       // we'll end up visiting the concept and the arguments in
   1800       // the TC twice.
   1801       TRY_TO(TraverseConceptReference(*TC));
   1802     }
   1803   }
   1804   return true;
   1805 }
   1806 
   1807 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
   1808   // D is the "T" in something like "template<typename T> class vector;"
   1809   if (D->getTypeForDecl())
   1810     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
   1811   TRY_TO(TraverseTemplateTypeParamDeclConstraints(D));
   1812   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
   1813     TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
   1814 })
   1815 
   1816 DEF_TRAVERSE_DECL(TypedefDecl, {
   1817   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1818   // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1819   // declaring the typedef, not something that was written in the
   1820   // source.
   1821 })
   1822 
   1823 DEF_TRAVERSE_DECL(TypeAliasDecl, {
   1824   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1825   // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1826   // declaring the type alias, not something that was written in the
   1827   // source.
   1828 })
   1829 
   1830 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
   1831   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
   1832   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
   1833 })
   1834 
   1835 DEF_TRAVERSE_DECL(ConceptDecl, {
   1836   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
   1837   TRY_TO(TraverseStmt(D->getConstraintExpr()));
   1838 })
   1839 
   1840 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
   1841   // A dependent using declaration which was marked with 'typename'.
   1842   //   template<class T> class A : public B<T> { using typename B<T>::foo; };
   1843   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1844   // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1845   // declaring the type, not something that was written in the
   1846   // source.
   1847 })
   1848 
   1849 DEF_TRAVERSE_DECL(EnumDecl, {
   1850   TRY_TO(TraverseDeclTemplateParameterLists(D));
   1851 
   1852   if (D->getTypeForDecl())
   1853     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
   1854 
   1855   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1856   // The enumerators are already traversed by
   1857   // decls_begin()/decls_end().
   1858 })
   1859 
   1860 // Helper methods for RecordDecl and its children.
   1861 template <typename Derived>
   1862 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
   1863   // We shouldn't traverse D->getTypeForDecl(); it's a result of
   1864   // declaring the type, not something that was written in the source.
   1865 
   1866   TRY_TO(TraverseDeclTemplateParameterLists(D));
   1867   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1868   return true;
   1869 }
   1870 
   1871 template <typename Derived>
   1872 bool RecursiveASTVisitor<Derived>::TraverseCXXBaseSpecifier(
   1873     const CXXBaseSpecifier &Base) {
   1874   TRY_TO(TraverseTypeLoc(Base.getTypeSourceInfo()->getTypeLoc()));
   1875   return true;
   1876 }
   1877 
   1878 template <typename Derived>
   1879 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
   1880   if (!TraverseRecordHelper(D))
   1881     return false;
   1882   if (D->isCompleteDefinition()) {
   1883     for (const auto &I : D->bases()) {
   1884       TRY_TO(TraverseCXXBaseSpecifier(I));
   1885     }
   1886     // We don't traverse the friends or the conversions, as they are
   1887     // already in decls_begin()/decls_end().
   1888   }
   1889   return true;
   1890 }
   1891 
   1892 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
   1893 
   1894 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
   1895 
   1896 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND)                              \
   1897   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, {                \
   1898     /* For implicit instantiations ("set<int> x;"), we don't want to           \
   1899        recurse at all, since the instatiated template isn't written in         \
   1900        the source code anywhere.  (Note the instatiated *type* --              \
   1901        set<int> -- is written, and will still get a callback of                \
   1902        TemplateSpecializationType).  For explicit instantiations               \
   1903        ("template set<int>;"), we do need a callback, since this               \
   1904        is the only callback that's made for this instantiation.                \
   1905        We use getTypeAsWritten() to distinguish. */                            \
   1906     if (TypeSourceInfo *TSI = D->getTypeAsWritten())                           \
   1907       TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));                              \
   1908                                                                                \
   1909     TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));              \
   1910     if (!getDerived().shouldVisitTemplateInstantiations() &&                   \
   1911         D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)      \
   1912       /* Returning from here skips traversing the                              \
   1913          declaration context of the *TemplateSpecializationDecl                \
   1914          (embedded in the DEF_TRAVERSE_DECL() macro)                           \
   1915          which contains the instantiated members of the template. */           \
   1916       return true;                                                             \
   1917   })
   1918 
   1919 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)
   1920 DEF_TRAVERSE_TMPL_SPEC_DECL(Var)
   1921 
   1922 template <typename Derived>
   1923 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
   1924     const TemplateArgumentLoc *TAL, unsigned Count) {
   1925   for (unsigned I = 0; I < Count; ++I) {
   1926     TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
   1927   }
   1928   return true;
   1929 }
   1930 
   1931 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND)               \
   1932   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, {         \
   1933     /* The partial specialization. */                                          \
   1934     if (TemplateParameterList *TPL = D->getTemplateParameters()) {             \
   1935       for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();   \
   1936            I != E; ++I) {                                                      \
   1937         TRY_TO(TraverseDecl(*I));                                              \
   1938       }                                                                        \
   1939     }                                                                          \
   1940     /* The args that remains unspecialized. */                                 \
   1941     TRY_TO(TraverseTemplateArgumentLocsHelper(                                 \
   1942         D->getTemplateArgsAsWritten()->getTemplateArgs(),                      \
   1943         D->getTemplateArgsAsWritten()->NumTemplateArgs));                      \
   1944                                                                                \
   1945     /* Don't need the *TemplatePartialSpecializationHelper, even               \
   1946        though that's our parent class -- we already visit all the              \
   1947        template args here. */                                                  \
   1948     TRY_TO(Traverse##DECLKIND##Helper(D));                                     \
   1949                                                                                \
   1950     /* Instantiations will have been visited with the primary template. */     \
   1951   })
   1952 
   1953 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
   1954 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
   1955 
   1956 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
   1957 
   1958 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
   1959   // Like UnresolvedUsingTypenameDecl, but without the 'typename':
   1960   //    template <class T> Class A : public Base<T> { using Base<T>::foo; };
   1961   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1962   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
   1963 })
   1964 
   1965 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
   1966 
   1967 template <typename Derived>
   1968 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
   1969   TRY_TO(TraverseDeclTemplateParameterLists(D));
   1970   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   1971   if (D->getTypeSourceInfo())
   1972     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
   1973   else
   1974     TRY_TO(TraverseType(D->getType()));
   1975   return true;
   1976 }
   1977 
   1978 DEF_TRAVERSE_DECL(DecompositionDecl, {
   1979   TRY_TO(TraverseVarHelper(D));
   1980   for (auto *Binding : D->bindings()) {
   1981     TRY_TO(TraverseDecl(Binding));
   1982   }
   1983 })
   1984 
   1985 DEF_TRAVERSE_DECL(BindingDecl, {
   1986   if (getDerived().shouldVisitImplicitCode())
   1987     TRY_TO(TraverseStmt(D->getBinding()));
   1988 })
   1989 
   1990 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
   1991 
   1992 DEF_TRAVERSE_DECL(MSGuidDecl, {})
   1993 
   1994 DEF_TRAVERSE_DECL(TemplateParamObjectDecl, {})
   1995 
   1996 DEF_TRAVERSE_DECL(FieldDecl, {
   1997   TRY_TO(TraverseDeclaratorHelper(D));
   1998   if (D->isBitField())
   1999     TRY_TO(TraverseStmt(D->getBitWidth()));
   2000   else if (D->hasInClassInitializer())
   2001     TRY_TO(TraverseStmt(D->getInClassInitializer()));
   2002 })
   2003 
   2004 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
   2005   TRY_TO(TraverseDeclaratorHelper(D));
   2006   if (D->isBitField())
   2007     TRY_TO(TraverseStmt(D->getBitWidth()));
   2008   // FIXME: implement the rest.
   2009 })
   2010 
   2011 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
   2012   TRY_TO(TraverseDeclaratorHelper(D));
   2013   if (D->isBitField())
   2014     TRY_TO(TraverseStmt(D->getBitWidth()));
   2015   // FIXME: implement the rest.
   2016 })
   2017 
   2018 template <typename Derived>
   2019 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
   2020   TRY_TO(TraverseDeclTemplateParameterLists(D));
   2021   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
   2022   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
   2023 
   2024   // If we're an explicit template specialization, iterate over the
   2025   // template args that were explicitly specified.  If we were doing
   2026   // this in typing order, we'd do it between the return type and
   2027   // the function args, but both are handled by the FunctionTypeLoc
   2028   // above, so we have to choose one side.  I've decided to do before.
   2029   if (const FunctionTemplateSpecializationInfo *FTSI =
   2030           D->getTemplateSpecializationInfo()) {
   2031     if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
   2032         FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
   2033       // A specialization might not have explicit template arguments if it has
   2034       // a templated return type and concrete arguments.
   2035       if (const ASTTemplateArgumentListInfo *TALI =
   2036               FTSI->TemplateArgumentsAsWritten) {
   2037         TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
   2038                                                   TALI->NumTemplateArgs));
   2039       }
   2040     }
   2041   }
   2042 
   2043   // Visit the function type itself, which can be either
   2044   // FunctionNoProtoType or FunctionProtoType, or a typedef.  This
   2045   // also covers the return type and the function parameters,
   2046   // including exception specifications.
   2047   if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
   2048     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
   2049   } else if (getDerived().shouldVisitImplicitCode()) {
   2050     // Visit parameter variable declarations of the implicit function
   2051     // if the traverser is visiting implicit code. Parameter variable
   2052     // declarations do not have valid TypeSourceInfo, so to visit them
   2053     // we need to traverse the declarations explicitly.
   2054     for (ParmVarDecl *Parameter : D->parameters()) {
   2055       TRY_TO(TraverseDecl(Parameter));
   2056     }
   2057   }
   2058 
   2059   // Visit the trailing requires clause, if any.
   2060   if (Expr *TrailingRequiresClause = D->getTrailingRequiresClause()) {
   2061     TRY_TO(TraverseStmt(TrailingRequiresClause));
   2062   }
   2063 
   2064   if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
   2065     // Constructor initializers.
   2066     for (auto *I : Ctor->inits()) {
   2067       if (I->isWritten() || getDerived().shouldVisitImplicitCode())
   2068         TRY_TO(TraverseConstructorInitializer(I));
   2069     }
   2070   }
   2071 
   2072   bool VisitBody =
   2073       D->isThisDeclarationADefinition() &&
   2074       // Don't visit the function body if the function definition is generated
   2075       // by clang.
   2076       (!D->isDefaulted() || getDerived().shouldVisitImplicitCode());
   2077 
   2078   if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
   2079     if (const CXXRecordDecl *RD = MD->getParent()) {
   2080       if (RD->isLambda() &&
   2081           declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
   2082         VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
   2083       }
   2084     }
   2085   }
   2086 
   2087   if (VisitBody) {
   2088     TRY_TO(TraverseStmt(D->getBody())); // Function body.
   2089   }
   2090   return true;
   2091 }
   2092 
   2093 DEF_TRAVERSE_DECL(FunctionDecl, {
   2094   // We skip decls_begin/decls_end, which are already covered by
   2095   // TraverseFunctionHelper().
   2096   ShouldVisitChildren = false;
   2097   ReturnValue = TraverseFunctionHelper(D);
   2098 })
   2099 
   2100 DEF_TRAVERSE_DECL(CXXDeductionGuideDecl, {
   2101   // We skip decls_begin/decls_end, which are already covered by
   2102   // TraverseFunctionHelper().
   2103   ShouldVisitChildren = false;
   2104   ReturnValue = TraverseFunctionHelper(D);
   2105 })
   2106 
   2107 DEF_TRAVERSE_DECL(CXXMethodDecl, {
   2108   // We skip decls_begin/decls_end, which are already covered by
   2109   // TraverseFunctionHelper().
   2110   ShouldVisitChildren = false;
   2111   ReturnValue = TraverseFunctionHelper(D);
   2112 })
   2113 
   2114 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
   2115   // We skip decls_begin/decls_end, which are already covered by
   2116   // TraverseFunctionHelper().
   2117   ShouldVisitChildren = false;
   2118   ReturnValue = TraverseFunctionHelper(D);
   2119 })
   2120 
   2121 // CXXConversionDecl is the declaration of a type conversion operator.
   2122 // It's not a cast expression.
   2123 DEF_TRAVERSE_DECL(CXXConversionDecl, {
   2124   // We skip decls_begin/decls_end, which are already covered by
   2125   // TraverseFunctionHelper().
   2126   ShouldVisitChildren = false;
   2127   ReturnValue = TraverseFunctionHelper(D);
   2128 })
   2129 
   2130 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
   2131   // We skip decls_begin/decls_end, which are already covered by
   2132   // TraverseFunctionHelper().
   2133   ShouldVisitChildren = false;
   2134   ReturnValue = TraverseFunctionHelper(D);
   2135 })
   2136 
   2137 template <typename Derived>
   2138 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
   2139   TRY_TO(TraverseDeclaratorHelper(D));
   2140   // Default params are taken care of when we traverse the ParmVarDecl.
   2141   if (!isa<ParmVarDecl>(D) &&
   2142       (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
   2143     TRY_TO(TraverseStmt(D->getInit()));
   2144   return true;
   2145 }
   2146 
   2147 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
   2148 
   2149 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
   2150 
   2151 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
   2152   // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
   2153   TRY_TO(TraverseDeclaratorHelper(D));
   2154   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
   2155     TRY_TO(TraverseStmt(D->getDefaultArgument()));
   2156 })
   2157 
   2158 DEF_TRAVERSE_DECL(ParmVarDecl, {
   2159   TRY_TO(TraverseVarHelper(D));
   2160 
   2161   if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
   2162       !D->hasUnparsedDefaultArg())
   2163     TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
   2164 
   2165   if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
   2166       !D->hasUnparsedDefaultArg())
   2167     TRY_TO(TraverseStmt(D->getDefaultArg()));
   2168 })
   2169 
   2170 DEF_TRAVERSE_DECL(RequiresExprBodyDecl, {})
   2171 
   2172 #undef DEF_TRAVERSE_DECL
   2173 
   2174 // ----------------- Stmt traversal -----------------
   2175 //
   2176 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
   2177 // over the children defined in children() (every stmt defines these,
   2178 // though sometimes the range is empty).  Each individual Traverse*
   2179 // method only needs to worry about children other than those.  To see
   2180 // what children() does for a given class, see, e.g.,
   2181 //   http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
   2182 
   2183 // This macro makes available a variable S, the passed-in stmt.
   2184 #define DEF_TRAVERSE_STMT(STMT, CODE)                                          \
   2185   template <typename Derived>                                                  \
   2186   bool RecursiveASTVisitor<Derived>::Traverse##STMT(                           \
   2187       STMT *S, DataRecursionQueue *Queue) {                                    \
   2188     bool ShouldVisitChildren = true;                                           \
   2189     bool ReturnValue = true;                                                   \
   2190     if (!getDerived().shouldTraversePostOrder())                               \
   2191       TRY_TO(WalkUpFrom##STMT(S));                                             \
   2192     { CODE; }                                                                  \
   2193     if (ShouldVisitChildren) {                                                 \
   2194       for (Stmt * SubStmt : getDerived().getStmtChildren(S)) {                 \
   2195         TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);                              \
   2196       }                                                                        \
   2197     }                                                                          \
   2198     /* Call WalkUpFrom if TRY_TO_TRAVERSE_OR_ENQUEUE_STMT has traversed the    \
   2199      * children already. If TRY_TO_TRAVERSE_OR_ENQUEUE_STMT only enqueued the  \
   2200      * children, PostVisitStmt will call WalkUpFrom after we are done visiting \
   2201      * children. */                                                            \
   2202     if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder()) {     \
   2203       TRY_TO(WalkUpFrom##STMT(S));                                             \
   2204     }                                                                          \
   2205     return ReturnValue;                                                        \
   2206   }
   2207 
   2208 DEF_TRAVERSE_STMT(GCCAsmStmt, {
   2209   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
   2210   for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
   2211     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
   2212   }
   2213   for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
   2214     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
   2215   }
   2216   for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
   2217     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
   2218   }
   2219   // children() iterates over inputExpr and outputExpr.
   2220 })
   2221 
   2222 DEF_TRAVERSE_STMT(
   2223     MSAsmStmt,
   2224     {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc.  Once
   2225      // added this needs to be implemented.
   2226     })
   2227 
   2228 DEF_TRAVERSE_STMT(CXXCatchStmt, {
   2229   TRY_TO(TraverseDecl(S->getExceptionDecl()));
   2230   // children() iterates over the handler block.
   2231 })
   2232 
   2233 DEF_TRAVERSE_STMT(DeclStmt, {
   2234   for (auto *I : S->decls()) {
   2235     TRY_TO(TraverseDecl(I));
   2236   }
   2237   // Suppress the default iteration over children() by
   2238   // returning.  Here's why: A DeclStmt looks like 'type var [=
   2239   // initializer]'.  The decls above already traverse over the
   2240   // initializers, so we don't have to do it again (which
   2241   // children() would do).
   2242   ShouldVisitChildren = false;
   2243 })
   2244 
   2245 // These non-expr stmts (most of them), do not need any action except
   2246 // iterating over the children.
   2247 DEF_TRAVERSE_STMT(BreakStmt, {})
   2248 DEF_TRAVERSE_STMT(CXXTryStmt, {})
   2249 DEF_TRAVERSE_STMT(CaseStmt, {})
   2250 DEF_TRAVERSE_STMT(CompoundStmt, {})
   2251 DEF_TRAVERSE_STMT(ContinueStmt, {})
   2252 DEF_TRAVERSE_STMT(DefaultStmt, {})
   2253 DEF_TRAVERSE_STMT(DoStmt, {})
   2254 DEF_TRAVERSE_STMT(ForStmt, {})
   2255 DEF_TRAVERSE_STMT(GotoStmt, {})
   2256 DEF_TRAVERSE_STMT(IfStmt, {})
   2257 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
   2258 DEF_TRAVERSE_STMT(LabelStmt, {})
   2259 DEF_TRAVERSE_STMT(AttributedStmt, {})
   2260 DEF_TRAVERSE_STMT(NullStmt, {})
   2261 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
   2262 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
   2263 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
   2264 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
   2265 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
   2266 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
   2267 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
   2268 
   2269 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
   2270   if (!getDerived().shouldVisitImplicitCode()) {
   2271     if (S->getInit())
   2272       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInit());
   2273     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
   2274     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
   2275     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
   2276     // Visit everything else only if shouldVisitImplicitCode().
   2277     ShouldVisitChildren = false;
   2278   }
   2279 })
   2280 
   2281 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
   2282   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2283   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
   2284 })
   2285 
   2286 DEF_TRAVERSE_STMT(ReturnStmt, {})
   2287 DEF_TRAVERSE_STMT(SwitchStmt, {})
   2288 DEF_TRAVERSE_STMT(WhileStmt, {})
   2289 
   2290 DEF_TRAVERSE_STMT(ConstantExpr, {})
   2291 
   2292 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
   2293   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2294   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
   2295   if (S->hasExplicitTemplateArgs()) {
   2296     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
   2297                                               S->getNumTemplateArgs()));
   2298   }
   2299 })
   2300 
   2301 DEF_TRAVERSE_STMT(DeclRefExpr, {
   2302   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2303   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
   2304   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
   2305                                             S->getNumTemplateArgs()));
   2306 })
   2307 
   2308 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
   2309   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2310   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
   2311   if (S->hasExplicitTemplateArgs()) {
   2312     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
   2313                                               S->getNumTemplateArgs()));
   2314   }
   2315 })
   2316 
   2317 DEF_TRAVERSE_STMT(MemberExpr, {
   2318   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2319   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
   2320   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
   2321                                             S->getNumTemplateArgs()));
   2322 })
   2323 
   2324 DEF_TRAVERSE_STMT(
   2325     ImplicitCastExpr,
   2326     {// We don't traverse the cast type, as it's not written in the
   2327      // source code.
   2328     })
   2329 
   2330 DEF_TRAVERSE_STMT(CStyleCastExpr, {
   2331   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2332 })
   2333 
   2334 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
   2335   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2336 })
   2337 
   2338 DEF_TRAVERSE_STMT(CXXAddrspaceCastExpr, {
   2339   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2340 })
   2341 
   2342 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
   2343   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2344 })
   2345 
   2346 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
   2347   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2348 })
   2349 
   2350 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
   2351   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2352 })
   2353 
   2354 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
   2355   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2356 })
   2357 
   2358 DEF_TRAVERSE_STMT(BuiltinBitCastExpr, {
   2359   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2360 })
   2361 
   2362 template <typename Derived>
   2363 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
   2364     InitListExpr *S, DataRecursionQueue *Queue) {
   2365   if (S) {
   2366     // Skip this if we traverse postorder. We will visit it later
   2367     // in PostVisitStmt.
   2368     if (!getDerived().shouldTraversePostOrder())
   2369       TRY_TO(WalkUpFromInitListExpr(S));
   2370 
   2371     // All we need are the default actions.  FIXME: use a helper function.
   2372     for (Stmt *SubStmt : S->children()) {
   2373       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
   2374     }
   2375 
   2376     if (!Queue && getDerived().shouldTraversePostOrder())
   2377       TRY_TO(WalkUpFromInitListExpr(S));
   2378   }
   2379   return true;
   2380 }
   2381 
   2382 template<typename Derived>
   2383 bool RecursiveASTVisitor<Derived>::TraverseConceptReference(
   2384     const ConceptReference &C) {
   2385   TRY_TO(TraverseNestedNameSpecifierLoc(C.getNestedNameSpecifierLoc()));
   2386   TRY_TO(TraverseDeclarationNameInfo(C.getConceptNameInfo()));
   2387   if (C.hasExplicitTemplateArgs())
   2388     TRY_TO(TraverseTemplateArgumentLocsHelper(
   2389         C.getTemplateArgsAsWritten()->getTemplateArgs(),
   2390         C.getTemplateArgsAsWritten()->NumTemplateArgs));
   2391   return true;
   2392 }
   2393 
   2394 // If shouldVisitImplicitCode() returns false, this method traverses only the
   2395 // syntactic form of InitListExpr.
   2396 // If shouldVisitImplicitCode() return true, this method is called once for
   2397 // each pair of syntactic and semantic InitListExpr, and it traverses the
   2398 // subtrees defined by the two forms. This may cause some of the children to be
   2399 // visited twice, if they appear both in the syntactic and the semantic form.
   2400 //
   2401 // There is no guarantee about which form \p S takes when this method is called.
   2402 template <typename Derived>
   2403 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(
   2404     InitListExpr *S, DataRecursionQueue *Queue) {
   2405   if (S->isSemanticForm() && S->isSyntacticForm()) {
   2406     // `S` does not have alternative forms, traverse only once.
   2407     TRY_TO(TraverseSynOrSemInitListExpr(S, Queue));
   2408     return true;
   2409   }
   2410   TRY_TO(TraverseSynOrSemInitListExpr(
   2411       S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
   2412   if (getDerived().shouldVisitImplicitCode()) {
   2413     // Only visit the semantic form if the clients are interested in implicit
   2414     // compiler-generated.
   2415     TRY_TO(TraverseSynOrSemInitListExpr(
   2416         S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
   2417   }
   2418   return true;
   2419 }
   2420 
   2421 // GenericSelectionExpr is a special case because the types and expressions
   2422 // are interleaved.  We also need to watch out for null types (default
   2423 // generic associations).
   2424 DEF_TRAVERSE_STMT(GenericSelectionExpr, {
   2425   TRY_TO(TraverseStmt(S->getControllingExpr()));
   2426   for (const GenericSelectionExpr::Association Assoc : S->associations()) {
   2427     if (TypeSourceInfo *TSI = Assoc.getTypeSourceInfo())
   2428       TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
   2429     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Assoc.getAssociationExpr());
   2430   }
   2431   ShouldVisitChildren = false;
   2432 })
   2433 
   2434 // PseudoObjectExpr is a special case because of the weirdness with
   2435 // syntactic expressions and opaque values.
   2436 DEF_TRAVERSE_STMT(PseudoObjectExpr, {
   2437   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
   2438   for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
   2439                                             e = S->semantics_end();
   2440        i != e; ++i) {
   2441     Expr *sub = *i;
   2442     if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
   2443       sub = OVE->getSourceExpr();
   2444     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub);
   2445   }
   2446   ShouldVisitChildren = false;
   2447 })
   2448 
   2449 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
   2450   // This is called for code like 'return T()' where T is a built-in
   2451   // (i.e. non-class) type.
   2452   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   2453 })
   2454 
   2455 DEF_TRAVERSE_STMT(CXXNewExpr, {
   2456   // The child-iterator will pick up the other arguments.
   2457   TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
   2458 })
   2459 
   2460 DEF_TRAVERSE_STMT(OffsetOfExpr, {
   2461   // The child-iterator will pick up the expression representing
   2462   // the field.
   2463   // FIMXE: for code like offsetof(Foo, a.b.c), should we get
   2464   // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
   2465   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   2466 })
   2467 
   2468 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
   2469   // The child-iterator will pick up the arg if it's an expression,
   2470   // but not if it's a type.
   2471   if (S->isArgumentType())
   2472     TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
   2473 })
   2474 
   2475 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
   2476   // The child-iterator will pick up the arg if it's an expression,
   2477   // but not if it's a type.
   2478   if (S->isTypeOperand())
   2479     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
   2480 })
   2481 
   2482 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
   2483   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2484 })
   2485 
   2486 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
   2487 
   2488 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
   2489   // The child-iterator will pick up the arg if it's an expression,
   2490   // but not if it's a type.
   2491   if (S->isTypeOperand())
   2492     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
   2493 })
   2494 
   2495 DEF_TRAVERSE_STMT(TypeTraitExpr, {
   2496   for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
   2497     TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
   2498 })
   2499 
   2500 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
   2501   TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
   2502 })
   2503 
   2504 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
   2505                   { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
   2506 
   2507 DEF_TRAVERSE_STMT(VAArgExpr, {
   2508   // The child-iterator will pick up the expression argument.
   2509   TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
   2510 })
   2511 
   2512 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
   2513   // This is called for code like 'return T()' where T is a class type.
   2514   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   2515 })
   2516 
   2517 // Walk only the visible parts of lambda expressions.
   2518 DEF_TRAVERSE_STMT(LambdaExpr, {
   2519   // Visit the capture list.
   2520   for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
   2521     const LambdaCapture *C = S->capture_begin() + I;
   2522     if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
   2523       TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
   2524     }
   2525   }
   2526 
   2527   if (getDerived().shouldVisitImplicitCode()) {
   2528     // The implicit model is simple: everything else is in the lambda class.
   2529     TRY_TO(TraverseDecl(S->getLambdaClass()));
   2530   } else {
   2531     // We need to poke around to find the bits that might be explicitly written.
   2532     TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
   2533     FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>();
   2534 
   2535     TRY_TO(TraverseTemplateParameterListHelper(S->getTemplateParameterList()));
   2536     if (S->hasExplicitParameters()) {
   2537       // Visit parameters.
   2538       for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)
   2539         TRY_TO(TraverseDecl(Proto.getParam(I)));
   2540     }
   2541 
   2542     auto *T = Proto.getTypePtr();
   2543     for (const auto &E : T->exceptions())
   2544       TRY_TO(TraverseType(E));
   2545 
   2546     if (Expr *NE = T->getNoexceptExpr())
   2547       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
   2548 
   2549     if (S->hasExplicitResultType())
   2550       TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
   2551     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getTrailingRequiresClause());
   2552 
   2553     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
   2554   }
   2555   ShouldVisitChildren = false;
   2556 })
   2557 
   2558 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
   2559   // This is called for code like 'T()', where T is a template argument.
   2560   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   2561 })
   2562 
   2563 // These expressions all might take explicit template arguments.
   2564 // We traverse those if so.  FIXME: implement these.
   2565 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
   2566 DEF_TRAVERSE_STMT(CallExpr, {})
   2567 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
   2568 
   2569 // These exprs (most of them), do not need any action except iterating
   2570 // over the children.
   2571 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
   2572 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
   2573 DEF_TRAVERSE_STMT(MatrixSubscriptExpr, {})
   2574 DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
   2575 DEF_TRAVERSE_STMT(OMPArrayShapingExpr, {})
   2576 DEF_TRAVERSE_STMT(OMPIteratorExpr, {})
   2577 
   2578 DEF_TRAVERSE_STMT(BlockExpr, {
   2579   TRY_TO(TraverseDecl(S->getBlockDecl()));
   2580   return true; // no child statements to loop through.
   2581 })
   2582 
   2583 DEF_TRAVERSE_STMT(ChooseExpr, {})
   2584 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
   2585   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
   2586 })
   2587 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
   2588 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
   2589 
   2590 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
   2591   if (getDerived().shouldVisitImplicitCode())
   2592     TRY_TO(TraverseStmt(S->getExpr()));
   2593 })
   2594 
   2595 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
   2596 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
   2597 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
   2598 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
   2599 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
   2600 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
   2601 
   2602 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
   2603   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2604   if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
   2605     TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
   2606   if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
   2607     TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
   2608 })
   2609 
   2610 DEF_TRAVERSE_STMT(CXXThisExpr, {})
   2611 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
   2612 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
   2613 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
   2614 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
   2615 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
   2616 DEF_TRAVERSE_STMT(GNUNullExpr, {})
   2617 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
   2618 DEF_TRAVERSE_STMT(NoInitExpr, {})
   2619 DEF_TRAVERSE_STMT(ArrayInitLoopExpr, {
   2620   // FIXME: The source expression of the OVE should be listed as
   2621   // a child of the ArrayInitLoopExpr.
   2622   if (OpaqueValueExpr *OVE = S->getCommonExpr())
   2623     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr());
   2624 })
   2625 DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {})
   2626 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
   2627 
   2628 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
   2629   if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
   2630     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
   2631 })
   2632 
   2633 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
   2634 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
   2635 
   2636 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
   2637   if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
   2638     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
   2639 })
   2640 
   2641 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
   2642 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
   2643 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
   2644 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
   2645 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
   2646 
   2647 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
   2648   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
   2649 })
   2650 
   2651 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
   2652 DEF_TRAVERSE_STMT(ParenExpr, {})
   2653 DEF_TRAVERSE_STMT(ParenListExpr, {})
   2654 DEF_TRAVERSE_STMT(PredefinedExpr, {})
   2655 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
   2656 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
   2657 DEF_TRAVERSE_STMT(StmtExpr, {})
   2658 DEF_TRAVERSE_STMT(SourceLocExpr, {})
   2659 
   2660 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
   2661   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2662   if (S->hasExplicitTemplateArgs()) {
   2663     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
   2664                                               S->getNumTemplateArgs()));
   2665   }
   2666 })
   2667 
   2668 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
   2669   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
   2670   if (S->hasExplicitTemplateArgs()) {
   2671     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
   2672                                               S->getNumTemplateArgs()));
   2673   }
   2674 })
   2675 
   2676 DEF_TRAVERSE_STMT(SEHTryStmt, {})
   2677 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
   2678 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
   2679 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
   2680 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
   2681 
   2682 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
   2683 DEF_TRAVERSE_STMT(CXXRewrittenBinaryOperator, {
   2684   if (!getDerived().shouldVisitImplicitCode()) {
   2685     CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
   2686         S->getDecomposedForm();
   2687     TRY_TO(TraverseStmt(const_cast<Expr*>(Decomposed.LHS)));
   2688     TRY_TO(TraverseStmt(const_cast<Expr*>(Decomposed.RHS)));
   2689     ShouldVisitChildren = false;
   2690   }
   2691 })
   2692 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
   2693 DEF_TRAVERSE_STMT(TypoExpr, {})
   2694 DEF_TRAVERSE_STMT(RecoveryExpr, {})
   2695 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
   2696 
   2697 // These operators (all of them) do not need any action except
   2698 // iterating over the children.
   2699 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
   2700 DEF_TRAVERSE_STMT(ConditionalOperator, {})
   2701 DEF_TRAVERSE_STMT(UnaryOperator, {})
   2702 DEF_TRAVERSE_STMT(BinaryOperator, {})
   2703 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
   2704 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
   2705 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
   2706 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
   2707 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
   2708 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
   2709 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
   2710 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
   2711 DEF_TRAVERSE_STMT(AtomicExpr, {})
   2712 
   2713 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {
   2714   if (S->getLifetimeExtendedTemporaryDecl()) {
   2715     TRY_TO(TraverseLifetimeExtendedTemporaryDecl(
   2716         S->getLifetimeExtendedTemporaryDecl()));
   2717     ShouldVisitChildren = false;
   2718   }
   2719 })
   2720 // For coroutines expressions, traverse either the operand
   2721 // as written or the implied calls, depending on what the
   2722 // derived class requests.
   2723 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
   2724   if (!getDerived().shouldVisitImplicitCode()) {
   2725     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
   2726     ShouldVisitChildren = false;
   2727   }
   2728 })
   2729 DEF_TRAVERSE_STMT(CoreturnStmt, {
   2730   if (!getDerived().shouldVisitImplicitCode()) {
   2731     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
   2732     ShouldVisitChildren = false;
   2733   }
   2734 })
   2735 DEF_TRAVERSE_STMT(CoawaitExpr, {
   2736   if (!getDerived().shouldVisitImplicitCode()) {
   2737     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
   2738     ShouldVisitChildren = false;
   2739   }
   2740 })
   2741 DEF_TRAVERSE_STMT(DependentCoawaitExpr, {
   2742   if (!getDerived().shouldVisitImplicitCode()) {
   2743     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
   2744     ShouldVisitChildren = false;
   2745   }
   2746 })
   2747 DEF_TRAVERSE_STMT(CoyieldExpr, {
   2748   if (!getDerived().shouldVisitImplicitCode()) {
   2749     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
   2750     ShouldVisitChildren = false;
   2751   }
   2752 })
   2753 
   2754 DEF_TRAVERSE_STMT(ConceptSpecializationExpr, {
   2755   TRY_TO(TraverseConceptReference(*S));
   2756 })
   2757 
   2758 DEF_TRAVERSE_STMT(RequiresExpr, {
   2759   TRY_TO(TraverseDecl(S->getBody()));
   2760   for (ParmVarDecl *Parm : S->getLocalParameters())
   2761     TRY_TO(TraverseDecl(Parm));
   2762   for (concepts::Requirement *Req : S->getRequirements())
   2763     if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
   2764       if (!TypeReq->isSubstitutionFailure())
   2765         TRY_TO(TraverseTypeLoc(TypeReq->getType()->getTypeLoc()));
   2766     } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
   2767       if (!ExprReq->isExprSubstitutionFailure())
   2768         TRY_TO(TraverseStmt(ExprReq->getExpr()));
   2769       auto &RetReq = ExprReq->getReturnTypeRequirement();
   2770       if (RetReq.isTypeConstraint())
   2771         TRY_TO(TraverseTemplateParameterListHelper(
   2772                    RetReq.getTypeConstraintTemplateParameterList()));
   2773     } else {
   2774       auto *NestedReq = cast<concepts::NestedRequirement>(Req);
   2775       if (!NestedReq->isSubstitutionFailure())
   2776         TRY_TO(TraverseStmt(NestedReq->getConstraintExpr()));
   2777     }
   2778 })
   2779 
   2780 // These literals (all of them) do not need any action.
   2781 DEF_TRAVERSE_STMT(IntegerLiteral, {})
   2782 DEF_TRAVERSE_STMT(FixedPointLiteral, {})
   2783 DEF_TRAVERSE_STMT(CharacterLiteral, {})
   2784 DEF_TRAVERSE_STMT(FloatingLiteral, {})
   2785 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
   2786 DEF_TRAVERSE_STMT(StringLiteral, {})
   2787 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
   2788 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
   2789 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
   2790 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
   2791 
   2792 // Traverse OpenCL: AsType, Convert.
   2793 DEF_TRAVERSE_STMT(AsTypeExpr, {})
   2794 
   2795 // OpenMP directives.
   2796 template <typename Derived>
   2797 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
   2798     OMPExecutableDirective *S) {
   2799   for (auto *C : S->clauses()) {
   2800     TRY_TO(TraverseOMPClause(C));
   2801   }
   2802   return true;
   2803 }
   2804 
   2805 DEF_TRAVERSE_STMT(OMPCanonicalLoop, {
   2806   if (!getDerived().shouldVisitImplicitCode()) {
   2807     // Visit only the syntactical loop.
   2808     TRY_TO(TraverseStmt(S->getLoopStmt()));
   2809     ShouldVisitChildren = false;
   2810   }
   2811 })
   2812 
   2813 template <typename Derived>
   2814 bool
   2815 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
   2816   return TraverseOMPExecutableDirective(S);
   2817 }
   2818 
   2819 DEF_TRAVERSE_STMT(OMPParallelDirective,
   2820                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2821 
   2822 DEF_TRAVERSE_STMT(OMPSimdDirective,
   2823                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2824 
   2825 DEF_TRAVERSE_STMT(OMPTileDirective,
   2826                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2827 
   2828 DEF_TRAVERSE_STMT(OMPForDirective,
   2829                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2830 
   2831 DEF_TRAVERSE_STMT(OMPForSimdDirective,
   2832                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2833 
   2834 DEF_TRAVERSE_STMT(OMPSectionsDirective,
   2835                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2836 
   2837 DEF_TRAVERSE_STMT(OMPSectionDirective,
   2838                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2839 
   2840 DEF_TRAVERSE_STMT(OMPSingleDirective,
   2841                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2842 
   2843 DEF_TRAVERSE_STMT(OMPMasterDirective,
   2844                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2845 
   2846 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
   2847   TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
   2848   TRY_TO(TraverseOMPExecutableDirective(S));
   2849 })
   2850 
   2851 DEF_TRAVERSE_STMT(OMPParallelForDirective,
   2852                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2853 
   2854 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
   2855                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2856 
   2857 DEF_TRAVERSE_STMT(OMPParallelMasterDirective,
   2858                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2859 
   2860 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
   2861                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2862 
   2863 DEF_TRAVERSE_STMT(OMPTaskDirective,
   2864                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2865 
   2866 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
   2867                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2868 
   2869 DEF_TRAVERSE_STMT(OMPBarrierDirective,
   2870                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2871 
   2872 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
   2873                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2874 
   2875 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
   2876                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2877 
   2878 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
   2879                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2880 
   2881 DEF_TRAVERSE_STMT(OMPCancelDirective,
   2882                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2883 
   2884 DEF_TRAVERSE_STMT(OMPFlushDirective,
   2885                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2886 
   2887 DEF_TRAVERSE_STMT(OMPDepobjDirective,
   2888                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2889 
   2890 DEF_TRAVERSE_STMT(OMPScanDirective,
   2891                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2892 
   2893 DEF_TRAVERSE_STMT(OMPOrderedDirective,
   2894                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2895 
   2896 DEF_TRAVERSE_STMT(OMPAtomicDirective,
   2897                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2898 
   2899 DEF_TRAVERSE_STMT(OMPTargetDirective,
   2900                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2901 
   2902 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
   2903                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2904 
   2905 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
   2906                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2907 
   2908 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
   2909                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2910 
   2911 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
   2912                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2913 
   2914 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
   2915                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2916 
   2917 DEF_TRAVERSE_STMT(OMPTeamsDirective,
   2918                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2919 
   2920 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
   2921                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2922 
   2923 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
   2924                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2925 
   2926 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
   2927                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2928 
   2929 DEF_TRAVERSE_STMT(OMPMasterTaskLoopDirective,
   2930                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2931 
   2932 DEF_TRAVERSE_STMT(OMPMasterTaskLoopSimdDirective,
   2933                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2934 
   2935 DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopDirective,
   2936                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2937 
   2938 DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopSimdDirective,
   2939                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2940 
   2941 DEF_TRAVERSE_STMT(OMPDistributeDirective,
   2942                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2943 
   2944 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
   2945                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2946 
   2947 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
   2948                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2949 
   2950 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
   2951                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2952 
   2953 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
   2954                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2955 
   2956 DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
   2957                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2958 
   2959 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
   2960                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2961 
   2962 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
   2963                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2964 
   2965 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
   2966                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2967 
   2968 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
   2969                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2970 
   2971 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
   2972                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2973 
   2974 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
   2975                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2976 
   2977 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
   2978                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2979 
   2980 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective,
   2981                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2982 
   2983 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective,
   2984                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2985 
   2986 DEF_TRAVERSE_STMT(OMPInteropDirective,
   2987                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2988 
   2989 DEF_TRAVERSE_STMT(OMPDispatchDirective,
   2990                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2991 
   2992 DEF_TRAVERSE_STMT(OMPMaskedDirective,
   2993                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
   2994 
   2995 // OpenMP clauses.
   2996 template <typename Derived>
   2997 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
   2998   if (!C)
   2999     return true;
   3000   switch (C->getClauseKind()) {
   3001 #define GEN_CLANG_CLAUSE_CLASS
   3002 #define CLAUSE_CLASS(Enum, Str, Class)                                         \
   3003   case llvm::omp::Clause::Enum:                                                \
   3004     TRY_TO(Visit##Class(static_cast<Class *>(C)));                             \
   3005     break;
   3006 #define CLAUSE_NO_CLASS(Enum, Str)                                             \
   3007   case llvm::omp::Clause::Enum:                                                \
   3008     break;
   3009 #include "llvm/Frontend/OpenMP/OMP.inc"
   3010   }
   3011   return true;
   3012 }
   3013 
   3014 template <typename Derived>
   3015 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
   3016     OMPClauseWithPreInit *Node) {
   3017   TRY_TO(TraverseStmt(Node->getPreInitStmt()));
   3018   return true;
   3019 }
   3020 
   3021 template <typename Derived>
   3022 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
   3023     OMPClauseWithPostUpdate *Node) {
   3024   TRY_TO(VisitOMPClauseWithPreInit(Node));
   3025   TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
   3026   return true;
   3027 }
   3028 
   3029 template <typename Derived>
   3030 bool RecursiveASTVisitor<Derived>::VisitOMPAllocatorClause(
   3031     OMPAllocatorClause *C) {
   3032   TRY_TO(TraverseStmt(C->getAllocator()));
   3033   return true;
   3034 }
   3035 
   3036 template <typename Derived>
   3037 bool RecursiveASTVisitor<Derived>::VisitOMPAllocateClause(OMPAllocateClause *C) {
   3038   TRY_TO(TraverseStmt(C->getAllocator()));
   3039   TRY_TO(VisitOMPClauseList(C));
   3040   return true;
   3041 }
   3042 
   3043 template <typename Derived>
   3044 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
   3045   TRY_TO(VisitOMPClauseWithPreInit(C));
   3046   TRY_TO(TraverseStmt(C->getCondition()));
   3047   return true;
   3048 }
   3049 
   3050 template <typename Derived>
   3051 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
   3052   TRY_TO(VisitOMPClauseWithPreInit(C));
   3053   TRY_TO(TraverseStmt(C->getCondition()));
   3054   return true;
   3055 }
   3056 
   3057 template <typename Derived>
   3058 bool
   3059 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
   3060   TRY_TO(VisitOMPClauseWithPreInit(C));
   3061   TRY_TO(TraverseStmt(C->getNumThreads()));
   3062   return true;
   3063 }
   3064 
   3065 template <typename Derived>
   3066 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
   3067   TRY_TO(TraverseStmt(C->getSafelen()));
   3068   return true;
   3069 }
   3070 
   3071 template <typename Derived>
   3072 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
   3073   TRY_TO(TraverseStmt(C->getSimdlen()));
   3074   return true;
   3075 }
   3076 
   3077 template <typename Derived>
   3078 bool RecursiveASTVisitor<Derived>::VisitOMPSizesClause(OMPSizesClause *C) {
   3079   for (Expr *E : C->getSizesRefs())
   3080     TRY_TO(TraverseStmt(E));
   3081   return true;
   3082 }
   3083 
   3084 template <typename Derived>
   3085 bool
   3086 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
   3087   TRY_TO(TraverseStmt(C->getNumForLoops()));
   3088   return true;
   3089 }
   3090 
   3091 template <typename Derived>
   3092 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
   3093   return true;
   3094 }
   3095 
   3096 template <typename Derived>
   3097 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
   3098   return true;
   3099 }
   3100 
   3101 template <typename Derived>
   3102 bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedAddressClause(
   3103     OMPUnifiedAddressClause *) {
   3104   return true;
   3105 }
   3106 
   3107 template <typename Derived>
   3108 bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedSharedMemoryClause(
   3109     OMPUnifiedSharedMemoryClause *) {
   3110   return true;
   3111 }
   3112 
   3113 template <typename Derived>
   3114 bool RecursiveASTVisitor<Derived>::VisitOMPReverseOffloadClause(
   3115     OMPReverseOffloadClause *) {
   3116   return true;
   3117 }
   3118 
   3119 template <typename Derived>
   3120 bool RecursiveASTVisitor<Derived>::VisitOMPDynamicAllocatorsClause(
   3121     OMPDynamicAllocatorsClause *) {
   3122   return true;
   3123 }
   3124 
   3125 template <typename Derived>
   3126 bool RecursiveASTVisitor<Derived>::VisitOMPAtomicDefaultMemOrderClause(
   3127     OMPAtomicDefaultMemOrderClause *) {
   3128   return true;
   3129 }
   3130 
   3131 template <typename Derived>
   3132 bool
   3133 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
   3134   TRY_TO(VisitOMPClauseWithPreInit(C));
   3135   TRY_TO(TraverseStmt(C->getChunkSize()));
   3136   return true;
   3137 }
   3138 
   3139 template <typename Derived>
   3140 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
   3141   TRY_TO(TraverseStmt(C->getNumForLoops()));
   3142   return true;
   3143 }
   3144 
   3145 template <typename Derived>
   3146 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
   3147   return true;
   3148 }
   3149 
   3150 template <typename Derived>
   3151 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
   3152   return true;
   3153 }
   3154 
   3155 template <typename Derived>
   3156 bool
   3157 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
   3158   return true;
   3159 }
   3160 
   3161 template <typename Derived>
   3162 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
   3163   return true;
   3164 }
   3165 
   3166 template <typename Derived>
   3167 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
   3168   return true;
   3169 }
   3170 
   3171 template <typename Derived>
   3172 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
   3173   return true;
   3174 }
   3175 
   3176 template <typename Derived>
   3177 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
   3178   return true;
   3179 }
   3180 
   3181 template <typename Derived>
   3182 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
   3183   return true;
   3184 }
   3185 
   3186 template <typename Derived>
   3187 bool RecursiveASTVisitor<Derived>::VisitOMPAcqRelClause(OMPAcqRelClause *) {
   3188   return true;
   3189 }
   3190 
   3191 template <typename Derived>
   3192 bool RecursiveASTVisitor<Derived>::VisitOMPAcquireClause(OMPAcquireClause *) {
   3193   return true;
   3194 }
   3195 
   3196 template <typename Derived>
   3197 bool RecursiveASTVisitor<Derived>::VisitOMPReleaseClause(OMPReleaseClause *) {
   3198   return true;
   3199 }
   3200 
   3201 template <typename Derived>
   3202 bool RecursiveASTVisitor<Derived>::VisitOMPRelaxedClause(OMPRelaxedClause *) {
   3203   return true;
   3204 }
   3205 
   3206 template <typename Derived>
   3207 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
   3208   return true;
   3209 }
   3210 
   3211 template <typename Derived>
   3212 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
   3213   return true;
   3214 }
   3215 
   3216 template <typename Derived>
   3217 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
   3218   return true;
   3219 }
   3220 
   3221 template <typename Derived>
   3222 bool RecursiveASTVisitor<Derived>::VisitOMPInitClause(OMPInitClause *C) {
   3223   TRY_TO(VisitOMPClauseList(C));
   3224   return true;
   3225 }
   3226 
   3227 template <typename Derived>
   3228 bool RecursiveASTVisitor<Derived>::VisitOMPUseClause(OMPUseClause *C) {
   3229   TRY_TO(TraverseStmt(C->getInteropVar()));
   3230   return true;
   3231 }
   3232 
   3233 template <typename Derived>
   3234 bool RecursiveASTVisitor<Derived>::VisitOMPDestroyClause(OMPDestroyClause *C) {
   3235   TRY_TO(TraverseStmt(C->getInteropVar()));
   3236   return true;
   3237 }
   3238 
   3239 template <typename Derived>
   3240 bool RecursiveASTVisitor<Derived>::VisitOMPNovariantsClause(
   3241     OMPNovariantsClause *C) {
   3242   TRY_TO(VisitOMPClauseWithPreInit(C));
   3243   TRY_TO(TraverseStmt(C->getCondition()));
   3244   return true;
   3245 }
   3246 
   3247 template <typename Derived>
   3248 bool RecursiveASTVisitor<Derived>::VisitOMPNocontextClause(
   3249     OMPNocontextClause *C) {
   3250   TRY_TO(VisitOMPClauseWithPreInit(C));
   3251   TRY_TO(TraverseStmt(C->getCondition()));
   3252   return true;
   3253 }
   3254 
   3255 template <typename Derived>
   3256 template <typename T>
   3257 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
   3258   for (auto *E : Node->varlists()) {
   3259     TRY_TO(TraverseStmt(E));
   3260   }
   3261   return true;
   3262 }
   3263 
   3264 template <typename Derived>
   3265 bool RecursiveASTVisitor<Derived>::VisitOMPInclusiveClause(
   3266     OMPInclusiveClause *C) {
   3267   TRY_TO(VisitOMPClauseList(C));
   3268   return true;
   3269 }
   3270 
   3271 template <typename Derived>
   3272 bool RecursiveASTVisitor<Derived>::VisitOMPExclusiveClause(
   3273     OMPExclusiveClause *C) {
   3274   TRY_TO(VisitOMPClauseList(C));
   3275   return true;
   3276 }
   3277 
   3278 template <typename Derived>
   3279 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
   3280   TRY_TO(VisitOMPClauseList(C));
   3281   for (auto *E : C->private_copies()) {
   3282     TRY_TO(TraverseStmt(E));
   3283   }
   3284   return true;
   3285 }
   3286 
   3287 template <typename Derived>
   3288 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
   3289     OMPFirstprivateClause *C) {
   3290   TRY_TO(VisitOMPClauseList(C));
   3291   TRY_TO(VisitOMPClauseWithPreInit(C));
   3292   for (auto *E : C->private_copies()) {
   3293     TRY_TO(TraverseStmt(E));
   3294   }
   3295   for (auto *E : C->inits()) {
   3296     TRY_TO(TraverseStmt(E));
   3297   }
   3298   return true;
   3299 }
   3300 
   3301 template <typename Derived>
   3302 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
   3303     OMPLastprivateClause *C) {
   3304   TRY_TO(VisitOMPClauseList(C));
   3305   TRY_TO(VisitOMPClauseWithPostUpdate(C));
   3306   for (auto *E : C->private_copies()) {
   3307     TRY_TO(TraverseStmt(E));
   3308   }
   3309   for (auto *E : C->source_exprs()) {
   3310     TRY_TO(TraverseStmt(E));
   3311   }
   3312   for (auto *E : C->destination_exprs()) {
   3313     TRY_TO(TraverseStmt(E));
   3314   }
   3315   for (auto *E : C->assignment_ops()) {
   3316     TRY_TO(TraverseStmt(E));
   3317   }
   3318   return true;
   3319 }
   3320 
   3321 template <typename Derived>
   3322 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
   3323   TRY_TO(VisitOMPClauseList(C));
   3324   return true;
   3325 }
   3326 
   3327 template <typename Derived>
   3328 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
   3329   TRY_TO(TraverseStmt(C->getStep()));
   3330   TRY_TO(TraverseStmt(C->getCalcStep()));
   3331   TRY_TO(VisitOMPClauseList(C));
   3332   TRY_TO(VisitOMPClauseWithPostUpdate(C));
   3333   for (auto *E : C->privates()) {
   3334     TRY_TO(TraverseStmt(E));
   3335   }
   3336   for (auto *E : C->inits()) {
   3337     TRY_TO(TraverseStmt(E));
   3338   }
   3339   for (auto *E : C->updates()) {
   3340     TRY_TO(TraverseStmt(E));
   3341   }
   3342   for (auto *E : C->finals()) {
   3343     TRY_TO(TraverseStmt(E));
   3344   }
   3345   return true;
   3346 }
   3347 
   3348 template <typename Derived>
   3349 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
   3350   TRY_TO(TraverseStmt(C->getAlignment()));
   3351   TRY_TO(VisitOMPClauseList(C));
   3352   return true;
   3353 }
   3354 
   3355 template <typename Derived>
   3356 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
   3357   TRY_TO(VisitOMPClauseList(C));
   3358   for (auto *E : C->source_exprs()) {
   3359     TRY_TO(TraverseStmt(E));
   3360   }
   3361   for (auto *E : C->destination_exprs()) {
   3362     TRY_TO(TraverseStmt(E));
   3363   }
   3364   for (auto *E : C->assignment_ops()) {
   3365     TRY_TO(TraverseStmt(E));
   3366   }
   3367   return true;
   3368 }
   3369 
   3370 template <typename Derived>
   3371 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
   3372     OMPCopyprivateClause *C) {
   3373   TRY_TO(VisitOMPClauseList(C));
   3374   for (auto *E : C->source_exprs()) {
   3375     TRY_TO(TraverseStmt(E));
   3376   }
   3377   for (auto *E : C->destination_exprs()) {
   3378     TRY_TO(TraverseStmt(E));
   3379   }
   3380   for (auto *E : C->assignment_ops()) {
   3381     TRY_TO(TraverseStmt(E));
   3382   }
   3383   return true;
   3384 }
   3385 
   3386 template <typename Derived>
   3387 bool
   3388 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
   3389   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
   3390   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
   3391   TRY_TO(VisitOMPClauseList(C));
   3392   TRY_TO(VisitOMPClauseWithPostUpdate(C));
   3393   for (auto *E : C->privates()) {
   3394     TRY_TO(TraverseStmt(E));
   3395   }
   3396   for (auto *E : C->lhs_exprs()) {
   3397     TRY_TO(TraverseStmt(E));
   3398   }
   3399   for (auto *E : C->rhs_exprs()) {
   3400     TRY_TO(TraverseStmt(E));
   3401   }
   3402   for (auto *E : C->reduction_ops()) {
   3403     TRY_TO(TraverseStmt(E));
   3404   }
   3405   if (C->getModifier() == OMPC_REDUCTION_inscan) {
   3406     for (auto *E : C->copy_ops()) {
   3407       TRY_TO(TraverseStmt(E));
   3408     }
   3409     for (auto *E : C->copy_array_temps()) {
   3410       TRY_TO(TraverseStmt(E));
   3411     }
   3412     for (auto *E : C->copy_array_elems()) {
   3413       TRY_TO(TraverseStmt(E));
   3414     }
   3415   }
   3416   return true;
   3417 }
   3418 
   3419 template <typename Derived>
   3420 bool RecursiveASTVisitor<Derived>::VisitOMPTaskReductionClause(
   3421     OMPTaskReductionClause *C) {
   3422   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
   3423   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
   3424   TRY_TO(VisitOMPClauseList(C));
   3425   TRY_TO(VisitOMPClauseWithPostUpdate(C));
   3426   for (auto *E : C->privates()) {
   3427     TRY_TO(TraverseStmt(E));
   3428   }
   3429   for (auto *E : C->lhs_exprs()) {
   3430     TRY_TO(TraverseStmt(E));
   3431   }
   3432   for (auto *E : C->rhs_exprs()) {
   3433     TRY_TO(TraverseStmt(E));
   3434   }
   3435   for (auto *E : C->reduction_ops()) {
   3436     TRY_TO(TraverseStmt(E));
   3437   }
   3438   return true;
   3439 }
   3440 
   3441 template <typename Derived>
   3442 bool RecursiveASTVisitor<Derived>::VisitOMPInReductionClause(
   3443     OMPInReductionClause *C) {
   3444   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
   3445   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
   3446   TRY_TO(VisitOMPClauseList(C));
   3447   TRY_TO(VisitOMPClauseWithPostUpdate(C));
   3448   for (auto *E : C->privates()) {
   3449     TRY_TO(TraverseStmt(E));
   3450   }
   3451   for (auto *E : C->lhs_exprs()) {
   3452     TRY_TO(TraverseStmt(E));
   3453   }
   3454   for (auto *E : C->rhs_exprs()) {
   3455     TRY_TO(TraverseStmt(E));
   3456   }
   3457   for (auto *E : C->reduction_ops()) {
   3458     TRY_TO(TraverseStmt(E));
   3459   }
   3460   for (auto *E : C->taskgroup_descriptors())
   3461     TRY_TO(TraverseStmt(E));
   3462   return true;
   3463 }
   3464 
   3465 template <typename Derived>
   3466 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
   3467   TRY_TO(VisitOMPClauseList(C));
   3468   return true;
   3469 }
   3470 
   3471 template <typename Derived>
   3472 bool RecursiveASTVisitor<Derived>::VisitOMPDepobjClause(OMPDepobjClause *C) {
   3473   TRY_TO(TraverseStmt(C->getDepobj()));
   3474   return true;
   3475 }
   3476 
   3477 template <typename Derived>
   3478 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
   3479   TRY_TO(VisitOMPClauseList(C));
   3480   return true;
   3481 }
   3482 
   3483 template <typename Derived>
   3484 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
   3485   TRY_TO(VisitOMPClauseWithPreInit(C));
   3486   TRY_TO(TraverseStmt(C->getDevice()));
   3487   return true;
   3488 }
   3489 
   3490 template <typename Derived>
   3491 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
   3492   TRY_TO(VisitOMPClauseList(C));
   3493   return true;
   3494 }
   3495 
   3496 template <typename Derived>
   3497 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
   3498     OMPNumTeamsClause *C) {
   3499   TRY_TO(VisitOMPClauseWithPreInit(C));
   3500   TRY_TO(TraverseStmt(C->getNumTeams()));
   3501   return true;
   3502 }
   3503 
   3504 template <typename Derived>
   3505 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
   3506     OMPThreadLimitClause *C) {
   3507   TRY_TO(VisitOMPClauseWithPreInit(C));
   3508   TRY_TO(TraverseStmt(C->getThreadLimit()));
   3509   return true;
   3510 }
   3511 
   3512 template <typename Derived>
   3513 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
   3514     OMPPriorityClause *C) {
   3515   TRY_TO(VisitOMPClauseWithPreInit(C));
   3516   TRY_TO(TraverseStmt(C->getPriority()));
   3517   return true;
   3518 }
   3519 
   3520 template <typename Derived>
   3521 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
   3522     OMPGrainsizeClause *C) {
   3523   TRY_TO(VisitOMPClauseWithPreInit(C));
   3524   TRY_TO(TraverseStmt(C->getGrainsize()));
   3525   return true;
   3526 }
   3527 
   3528 template <typename Derived>
   3529 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
   3530     OMPNumTasksClause *C) {
   3531   TRY_TO(VisitOMPClauseWithPreInit(C));
   3532   TRY_TO(TraverseStmt(C->getNumTasks()));
   3533   return true;
   3534 }
   3535 
   3536 template <typename Derived>
   3537 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
   3538   TRY_TO(TraverseStmt(C->getHint()));
   3539   return true;
   3540 }
   3541 
   3542 template <typename Derived>
   3543 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
   3544     OMPDistScheduleClause *C) {
   3545   TRY_TO(VisitOMPClauseWithPreInit(C));
   3546   TRY_TO(TraverseStmt(C->getChunkSize()));
   3547   return true;
   3548 }
   3549 
   3550 template <typename Derived>
   3551 bool
   3552 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
   3553   return true;
   3554 }
   3555 
   3556 template <typename Derived>
   3557 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
   3558   TRY_TO(VisitOMPClauseList(C));
   3559   return true;
   3560 }
   3561 
   3562 template <typename Derived>
   3563 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
   3564   TRY_TO(VisitOMPClauseList(C));
   3565   return true;
   3566 }
   3567 
   3568 template <typename Derived>
   3569 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
   3570     OMPUseDevicePtrClause *C) {
   3571   TRY_TO(VisitOMPClauseList(C));
   3572   return true;
   3573 }
   3574 
   3575 template <typename Derived>
   3576 bool RecursiveASTVisitor<Derived>::VisitOMPUseDeviceAddrClause(
   3577     OMPUseDeviceAddrClause *C) {
   3578   TRY_TO(VisitOMPClauseList(C));
   3579   return true;
   3580 }
   3581 
   3582 template <typename Derived>
   3583 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
   3584     OMPIsDevicePtrClause *C) {
   3585   TRY_TO(VisitOMPClauseList(C));
   3586   return true;
   3587 }
   3588 
   3589 template <typename Derived>
   3590 bool RecursiveASTVisitor<Derived>::VisitOMPNontemporalClause(
   3591     OMPNontemporalClause *C) {
   3592   TRY_TO(VisitOMPClauseList(C));
   3593   for (auto *E : C->private_refs()) {
   3594     TRY_TO(TraverseStmt(E));
   3595   }
   3596   return true;
   3597 }
   3598 
   3599 template <typename Derived>
   3600 bool RecursiveASTVisitor<Derived>::VisitOMPOrderClause(OMPOrderClause *) {
   3601   return true;
   3602 }
   3603 
   3604 template <typename Derived>
   3605 bool RecursiveASTVisitor<Derived>::VisitOMPDetachClause(OMPDetachClause *C) {
   3606   TRY_TO(TraverseStmt(C->getEventHandler()));
   3607   return true;
   3608 }
   3609 
   3610 template <typename Derived>
   3611 bool RecursiveASTVisitor<Derived>::VisitOMPUsesAllocatorsClause(
   3612     OMPUsesAllocatorsClause *C) {
   3613   for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
   3614     const OMPUsesAllocatorsClause::Data Data = C->getAllocatorData(I);
   3615     TRY_TO(TraverseStmt(Data.Allocator));
   3616     TRY_TO(TraverseStmt(Data.AllocatorTraits));
   3617   }
   3618   return true;
   3619 }
   3620 
   3621 template <typename Derived>
   3622 bool RecursiveASTVisitor<Derived>::VisitOMPAffinityClause(
   3623     OMPAffinityClause *C) {
   3624   TRY_TO(TraverseStmt(C->getModifier()));
   3625   for (Expr *E : C->varlists())
   3626     TRY_TO(TraverseStmt(E));
   3627   return true;
   3628 }
   3629 
   3630 template <typename Derived>
   3631 bool RecursiveASTVisitor<Derived>::VisitOMPFilterClause(OMPFilterClause *C) {
   3632   TRY_TO(VisitOMPClauseWithPreInit(C));
   3633   TRY_TO(TraverseStmt(C->getThreadID()));
   3634   return true;
   3635 }
   3636 
   3637 // FIXME: look at the following tricky-seeming exprs to see if we
   3638 // need to recurse on anything.  These are ones that have methods
   3639 // returning decls or qualtypes or nestednamespecifier -- though I'm
   3640 // not sure if they own them -- or just seemed very complicated, or
   3641 // had lots of sub-types to explore.
   3642 //
   3643 // VisitOverloadExpr and its children: recurse on template args? etc?
   3644 
   3645 // FIXME: go through all the stmts and exprs again, and see which of them
   3646 // create new types, and recurse on the types (TypeLocs?) of those.
   3647 // Candidates:
   3648 //
   3649 //    http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
   3650 //    http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
   3651 //    http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
   3652 //    Every class that has getQualifier.
   3653 
   3654 #undef DEF_TRAVERSE_STMT
   3655 #undef TRAVERSE_STMT
   3656 #undef TRAVERSE_STMT_BASE
   3657 
   3658 #undef TRY_TO
   3659 
   3660 } // end namespace clang
   3661 
   3662 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
   3663