Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:41

0001 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the RecursiveASTVisitor interface, which recursively
0010 //  traverses the entire AST.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
0014 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
0015 
0016 #include "clang/AST/ASTConcept.h"
0017 #include "clang/AST/Attr.h"
0018 #include "clang/AST/Decl.h"
0019 #include "clang/AST/DeclBase.h"
0020 #include "clang/AST/DeclCXX.h"
0021 #include "clang/AST/DeclFriend.h"
0022 #include "clang/AST/DeclObjC.h"
0023 #include "clang/AST/DeclOpenMP.h"
0024 #include "clang/AST/DeclTemplate.h"
0025 #include "clang/AST/DeclarationName.h"
0026 #include "clang/AST/Expr.h"
0027 #include "clang/AST/ExprCXX.h"
0028 #include "clang/AST/ExprConcepts.h"
0029 #include "clang/AST/ExprObjC.h"
0030 #include "clang/AST/ExprOpenMP.h"
0031 #include "clang/AST/LambdaCapture.h"
0032 #include "clang/AST/NestedNameSpecifier.h"
0033 #include "clang/AST/OpenACCClause.h"
0034 #include "clang/AST/OpenMPClause.h"
0035 #include "clang/AST/Stmt.h"
0036 #include "clang/AST/StmtCXX.h"
0037 #include "clang/AST/StmtObjC.h"
0038 #include "clang/AST/StmtOpenACC.h"
0039 #include "clang/AST/StmtOpenMP.h"
0040 #include "clang/AST/StmtSYCL.h"
0041 #include "clang/AST/TemplateBase.h"
0042 #include "clang/AST/TemplateName.h"
0043 #include "clang/AST/Type.h"
0044 #include "clang/AST/TypeLoc.h"
0045 #include "clang/Basic/LLVM.h"
0046 #include "clang/Basic/OpenMPKinds.h"
0047 #include "clang/Basic/Specifiers.h"
0048 #include "llvm/ADT/PointerIntPair.h"
0049 #include "llvm/ADT/SmallVector.h"
0050 #include "llvm/Support/Casting.h"
0051 #include <algorithm>
0052 #include <cstddef>
0053 #include <type_traits>
0054 
0055 namespace clang {
0056 
0057 // A helper macro to implement short-circuiting when recursing.  It
0058 // invokes CALL_EXPR, which must be a method call, on the derived
0059 // object (s.t. a user of RecursiveASTVisitor can override the method
0060 // in CALL_EXPR).
0061 #define TRY_TO(CALL_EXPR)                                                      \
0062   do {                                                                         \
0063     if (!getDerived().CALL_EXPR)                                               \
0064       return false;                                                            \
0065   } while (false)
0066 
0067 namespace detail {
0068 
0069 template <typename T, typename U>
0070 struct has_same_member_pointer_type : std::false_type {};
0071 template <typename T, typename U, typename R, typename... P>
0072 struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
0073     : std::true_type {};
0074 
0075 /// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
0076 /// are pointers to the same non-static member function.
0077 template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
0078 LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG auto
0079 isSameMethod([[maybe_unused]] FirstMethodPtrTy FirstMethodPtr,
0080              [[maybe_unused]] SecondMethodPtrTy SecondMethodPtr)
0081     -> bool {
0082   if constexpr (has_same_member_pointer_type<FirstMethodPtrTy,
0083                                              SecondMethodPtrTy>::value)
0084     return FirstMethodPtr == SecondMethodPtr;
0085   return false;
0086 }
0087 
0088 } // end namespace detail
0089 
0090 /// A class that does preorder or postorder
0091 /// depth-first traversal on the entire Clang AST and visits each node.
0092 ///
0093 /// This class performs three distinct tasks:
0094 ///   1. traverse the AST (i.e. go to each node);
0095 ///   2. at a given node, walk up the class hierarchy, starting from
0096 ///      the node's dynamic type, until the top-most class (e.g. Stmt,
0097 ///      Decl, or Type) is reached.
0098 ///   3. given a (node, class) combination, where 'class' is some base
0099 ///      class of the dynamic type of 'node', call a user-overridable
0100 ///      function to actually visit the node.
0101 ///
0102 /// These tasks are done by three groups of methods, respectively:
0103 ///   1. TraverseDecl(Decl *x) does task #1.  It is the entry point
0104 ///      for traversing an AST rooted at x.  This method simply
0105 ///      dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
0106 ///      is the dynamic type of *x, which calls WalkUpFromFoo(x) and
0107 ///      then recursively visits the child nodes of x.
0108 ///      TraverseStmt(Stmt *x) and TraverseType(QualType x) work
0109 ///      similarly.
0110 ///   2. WalkUpFromFoo(Foo *x) does task #2.  It does not try to visit
0111 ///      any child node of x.  Instead, it first calls WalkUpFromBar(x)
0112 ///      where Bar is the direct parent class of Foo (unless Foo has
0113 ///      no parent), and then calls VisitFoo(x) (see the next list item).
0114 ///   3. VisitFoo(Foo *x) does task #3.
0115 ///
0116 /// These three method groups are tiered (Traverse* > WalkUpFrom* >
0117 /// Visit*).  A method (e.g. Traverse*) may call methods from the same
0118 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
0119 /// It may not call methods from a higher tier.
0120 ///
0121 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
0122 /// is Foo's super class) before calling VisitFoo(), the result is
0123 /// that the Visit*() methods for a given node are called in the
0124 /// top-down order (e.g. for a node of type NamespaceDecl, the order will
0125 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
0126 ///
0127 /// This scheme guarantees that all Visit*() calls for the same AST
0128 /// node are grouped together.  In other words, Visit*() methods for
0129 /// different nodes are never interleaved.
0130 ///
0131 /// Clients of this visitor should subclass the visitor (providing
0132 /// themselves as the template argument, using the curiously recurring
0133 /// template pattern) and override any of the Traverse*, WalkUpFrom*,
0134 /// and Visit* methods for declarations, types, statements,
0135 /// expressions, or other AST nodes where the visitor should customize
0136 /// behavior.  Most users only need to override Visit*.  Advanced
0137 /// users may override Traverse* and WalkUpFrom* to implement custom
0138 /// traversal strategies.  Returning false from one of these overridden
0139 /// functions will abort the entire traversal.
0140 ///
0141 /// By default, this visitor tries to visit every part of the explicit
0142 /// source code exactly once.  The default policy towards templates
0143 /// is to descend into the 'pattern' class or function body, not any
0144 /// explicit or implicit instantiations.  Explicit specializations
0145 /// are still visited, and the patterns of partial specializations
0146 /// are visited separately.  This behavior can be changed by
0147 /// overriding shouldVisitTemplateInstantiations() in the derived class
0148 /// to return true, in which case all known implicit and explicit
0149 /// instantiations will be visited at the same time as the pattern
0150 /// from which they were produced.
0151 ///
0152 /// By default, this visitor preorder traverses the AST. If postorder traversal
0153 /// is needed, the \c shouldTraversePostOrder method needs to be overridden
0154 /// to return \c true.
0155 template <typename Derived> class RecursiveASTVisitor {
0156 public:
0157   /// A queue used for performing data recursion over statements.
0158   /// Parameters involving this type are used to implement data
0159   /// recursion over Stmts and Exprs within this class, and should
0160   /// typically not be explicitly specified by derived classes.
0161   /// The bool bit indicates whether the statement has been traversed or not.
0162   typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>>
0163     DataRecursionQueue;
0164 
0165   /// Return a reference to the derived class.
0166   Derived &getDerived() { return *static_cast<Derived *>(this); }
0167 
0168   /// Return whether this visitor should recurse into
0169   /// template instantiations.
0170   bool shouldVisitTemplateInstantiations() const { return false; }
0171 
0172   /// Return whether this visitor should recurse into the types of
0173   /// TypeLocs.
0174   bool shouldWalkTypesOfTypeLocs() const { return true; }
0175 
0176   /// Return whether this visitor should recurse into implicit
0177   /// code, e.g., implicit constructors and destructors.
0178   bool shouldVisitImplicitCode() const { return false; }
0179 
0180   /// Return whether this visitor should recurse into lambda body
0181   bool shouldVisitLambdaBody() const { return true; }
0182 
0183   /// Return whether this visitor should traverse post-order.
0184   bool shouldTraversePostOrder() const { return false; }
0185 
0186   /// Recursively visits an entire AST, starting from the TranslationUnitDecl.
0187   /// \returns false if visitation was terminated early.
0188   bool TraverseAST(ASTContext &AST) {
0189     // Currently just an alias for TraverseDecl(TUDecl), but kept in case
0190     // we change the implementation again.
0191     return getDerived().TraverseDecl(AST.getTranslationUnitDecl());
0192   }
0193 
0194   /// Recursively visit a statement or expression, by
0195   /// dispatching to Traverse*() based on the argument's dynamic type.
0196   ///
0197   /// \returns false if the visitation was terminated early, true
0198   /// otherwise (including when the argument is nullptr).
0199   bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr);
0200 
0201   /// Invoked before visiting a statement or expression via data recursion.
0202   ///
0203   /// \returns false to skip visiting the node, true otherwise.
0204   bool dataTraverseStmtPre(Stmt *S) { return true; }
0205 
0206   /// Invoked after visiting a statement or expression via data recursion.
0207   /// This is not invoked if the previously invoked \c dataTraverseStmtPre
0208   /// returned false.
0209   ///
0210   /// \returns false if the visitation was terminated early, true otherwise.
0211   bool dataTraverseStmtPost(Stmt *S) { return true; }
0212 
0213   /// Recursively visit a type, by dispatching to
0214   /// Traverse*Type() based on the argument's getTypeClass() property.
0215   ///
0216   /// \returns false if the visitation was terminated early, true
0217   /// otherwise (including when the argument is a Null type).
0218   bool TraverseType(QualType T);
0219 
0220   /// Recursively visit a type with location, by dispatching to
0221   /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
0222   ///
0223   /// \returns false if the visitation was terminated early, true
0224   /// otherwise (including when the argument is a Null type location).
0225   bool TraverseTypeLoc(TypeLoc TL);
0226 
0227   /// Recursively visit an attribute, by dispatching to
0228   /// Traverse*Attr() based on the argument's dynamic type.
0229   ///
0230   /// \returns false if the visitation was terminated early, true
0231   /// otherwise (including when the argument is a Null type location).
0232   bool TraverseAttr(Attr *At);
0233 
0234   /// Recursively visit a declaration, by dispatching to
0235   /// Traverse*Decl() based on the argument's dynamic type.
0236   ///
0237   /// \returns false if the visitation was terminated early, true
0238   /// otherwise (including when the argument is NULL).
0239   bool TraverseDecl(Decl *D);
0240 
0241   /// Recursively visit a C++ nested-name-specifier.
0242   ///
0243   /// \returns false if the visitation was terminated early, true otherwise.
0244   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
0245 
0246   /// Recursively visit a C++ nested-name-specifier with location
0247   /// information.
0248   ///
0249   /// \returns false if the visitation was terminated early, true otherwise.
0250   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
0251 
0252   /// Recursively visit a name with its location information.
0253   ///
0254   /// \returns false if the visitation was terminated early, true otherwise.
0255   bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
0256 
0257   /// Recursively visit a template name and dispatch to the
0258   /// appropriate method.
0259   ///
0260   /// \returns false if the visitation was terminated early, true otherwise.
0261   bool TraverseTemplateName(TemplateName Template);
0262 
0263   /// Recursively visit a template argument and dispatch to the
0264   /// appropriate method for the argument type.
0265   ///
0266   /// \returns false if the visitation was terminated early, true otherwise.
0267   // FIXME: migrate callers to TemplateArgumentLoc instead.
0268   bool TraverseTemplateArgument(const TemplateArgument &Arg);
0269 
0270   /// Recursively visit a template argument location and dispatch to the
0271   /// appropriate method for the argument type.
0272   ///
0273   /// \returns false if the visitation was terminated early, true otherwise.
0274   bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
0275 
0276   /// Recursively visit a set of template arguments.
0277   /// This can be overridden by a subclass, but it's not expected that
0278   /// will be needed -- this visitor always dispatches to another.
0279   ///
0280   /// \returns false if the visitation was terminated early, true otherwise.
0281   // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
0282   bool TraverseTemplateArguments(ArrayRef<TemplateArgument> Args);
0283 
0284   /// Recursively visit a base specifier. This can be overridden by a
0285   /// subclass.
0286   ///
0287   /// \returns false if the visitation was terminated early, true otherwise.
0288   bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base);
0289 
0290   /// Recursively visit a constructor initializer.  This
0291   /// automatically dispatches to another visitor for the initializer
0292   /// expression, but not for the name of the initializer, so may
0293   /// be overridden for clients that need access to the name.
0294   ///
0295   /// \returns false if the visitation was terminated early, true otherwise.
0296   bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
0297 
0298   /// Recursively visit a lambda capture. \c Init is the expression that
0299   /// will be used to initialize the capture.
0300   ///
0301   /// \returns false if the visitation was terminated early, true otherwise.
0302   bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
0303                              Expr *Init);
0304 
0305   /// Recursively visit the syntactic or semantic form of an
0306   /// initialization list.
0307   ///
0308   /// \returns false if the visitation was terminated early, true otherwise.
0309   bool TraverseSynOrSemInitListExpr(InitListExpr *S,
0310                                     DataRecursionQueue *Queue = nullptr);
0311 
0312   /// Recursively visit an Objective-C protocol reference with location
0313   /// information.
0314   ///
0315   /// \returns false if the visitation was terminated early, true otherwise.
0316   bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc);
0317 
0318   /// Recursively visit concept reference with location information.
0319   ///
0320   /// \returns false if the visitation was terminated early, true otherwise.
0321   bool TraverseConceptReference(ConceptReference *CR);
0322 
0323   // Visit concept reference.
0324   bool VisitConceptReference(ConceptReference *CR) { return true; }
0325   // ---- Methods on Attrs ----
0326 
0327   // Visit an attribute.
0328   bool VisitAttr(Attr *A) { return true; }
0329 
0330 // Declare Traverse* and empty Visit* for all Attr classes.
0331 #define ATTR_VISITOR_DECLS_ONLY
0332 #include "clang/AST/AttrVisitor.inc"
0333 #undef ATTR_VISITOR_DECLS_ONLY
0334 
0335 // ---- Methods on Stmts ----
0336 
0337   Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); }
0338 
0339 private:
0340   // Traverse the given statement. If the most-derived traverse function takes a
0341   // data recursion queue, pass it on; otherwise, discard it. Note that the
0342   // first branch of this conditional must compile whether or not the derived
0343   // class can take a queue, so if we're taking the second arm, make the first
0344   // arm call our function rather than the derived class version.
0345 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE)                            \
0346   (::clang::detail::has_same_member_pointer_type<                              \
0347        decltype(&RecursiveASTVisitor::Traverse##NAME),                         \
0348        decltype(&Derived::Traverse##NAME)>::value                              \
0349        ? static_cast<std::conditional_t<                                       \
0350              ::clang::detail::has_same_member_pointer_type<                    \
0351                  decltype(&RecursiveASTVisitor::Traverse##NAME),               \
0352                  decltype(&Derived::Traverse##NAME)>::value,                   \
0353              Derived &, RecursiveASTVisitor &>>(*this)                         \
0354              .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE)                 \
0355        : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
0356 
0357 // Try to traverse the given statement, or enqueue it if we're performing data
0358 // recursion in the middle of traversing another statement. Can only be called
0359 // from within a DEF_TRAVERSE_STMT body or similar context.
0360 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S)                                     \
0361   do {                                                                         \
0362     if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue))                             \
0363       return false;                                                            \
0364   } while (false)
0365 
0366 public:
0367 // Declare Traverse*() for all concrete Stmt classes.
0368 #define ABSTRACT_STMT(STMT)
0369 #define STMT(CLASS, PARENT) \
0370   bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
0371 #include "clang/AST/StmtNodes.inc"
0372   // The above header #undefs ABSTRACT_STMT and STMT upon exit.
0373 
0374   // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
0375   bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
0376   bool VisitStmt(Stmt *S) { return true; }
0377 #define STMT(CLASS, PARENT)                                                    \
0378   bool WalkUpFrom##CLASS(CLASS *S) {                                           \
0379     TRY_TO(WalkUpFrom##PARENT(S));                                             \
0380     TRY_TO(Visit##CLASS(S));                                                   \
0381     return true;                                                               \
0382   }                                                                            \
0383   bool Visit##CLASS(CLASS *S) { return true; }
0384 #include "clang/AST/StmtNodes.inc"
0385 
0386 // ---- Methods on Types ----
0387 // FIXME: revamp to take TypeLoc's rather than Types.
0388 
0389 // Declare Traverse*() for all concrete Type classes.
0390 #define ABSTRACT_TYPE(CLASS, BASE)
0391 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
0392 #include "clang/AST/TypeNodes.inc"
0393   // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
0394 
0395   // Define WalkUpFrom*() and empty Visit*() for all Type classes.
0396   bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
0397   bool VisitType(Type *T) { return true; }
0398 #define TYPE(CLASS, BASE)                                                      \
0399   bool WalkUpFrom##CLASS##Type(CLASS##Type *T) {                               \
0400     TRY_TO(WalkUpFrom##BASE(T));                                               \
0401     TRY_TO(Visit##CLASS##Type(T));                                             \
0402     return true;                                                               \
0403   }                                                                            \
0404   bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
0405 #include "clang/AST/TypeNodes.inc"
0406 
0407 // ---- Methods on TypeLocs ----
0408 // FIXME: this currently just calls the matching Type methods
0409 
0410 // Declare Traverse*() for all concrete TypeLoc classes.
0411 #define ABSTRACT_TYPELOC(CLASS, BASE)
0412 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
0413 #include "clang/AST/TypeLocNodes.def"
0414   // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
0415 
0416   // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
0417   bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
0418   bool VisitTypeLoc(TypeLoc TL) { return true; }
0419 
0420   // QualifiedTypeLoc and UnqualTypeLoc are not declared in
0421   // TypeNodes.inc and thus need to be handled specially.
0422   bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
0423     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
0424   }
0425   bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
0426   bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
0427     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
0428   }
0429   bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
0430 
0431 // Note that BASE includes trailing 'Type' which CLASS doesn't.
0432 #define TYPE(CLASS, BASE)                                                      \
0433   bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) {                         \
0434     TRY_TO(WalkUpFrom##BASE##Loc(TL));                                         \
0435     TRY_TO(Visit##CLASS##TypeLoc(TL));                                         \
0436     return true;                                                               \
0437   }                                                                            \
0438   bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
0439 #include "clang/AST/TypeNodes.inc"
0440 
0441 // ---- Methods on Decls ----
0442 
0443 // Declare Traverse*() for all concrete Decl classes.
0444 #define ABSTRACT_DECL(DECL)
0445 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
0446 #include "clang/AST/DeclNodes.inc"
0447   // The above header #undefs ABSTRACT_DECL and DECL upon exit.
0448 
0449   // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
0450   bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
0451   bool VisitDecl(Decl *D) { return true; }
0452 #define DECL(CLASS, BASE)                                                      \
0453   bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) {                               \
0454     TRY_TO(WalkUpFrom##BASE(D));                                               \
0455     TRY_TO(Visit##CLASS##Decl(D));                                             \
0456     return true;                                                               \
0457   }                                                                            \
0458   bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
0459 #include "clang/AST/DeclNodes.inc"
0460 
0461   bool canIgnoreChildDeclWhileTraversingDeclContext(const Decl *Child);
0462 
0463 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND)                                   \
0464   bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
0465   DEF_TRAVERSE_TMPL_INST(Class)
0466   DEF_TRAVERSE_TMPL_INST(Var)
0467   DEF_TRAVERSE_TMPL_INST(Function)
0468 #undef DEF_TRAVERSE_TMPL_INST
0469 
0470   bool TraverseTypeConstraint(const TypeConstraint *C);
0471 
0472   bool TraverseConceptRequirement(concepts::Requirement *R);
0473   bool TraverseConceptTypeRequirement(concepts::TypeRequirement *R);
0474   bool TraverseConceptExprRequirement(concepts::ExprRequirement *R);
0475   bool TraverseConceptNestedRequirement(concepts::NestedRequirement *R);
0476 
0477   bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
0478 
0479 private:
0480   // These are helper methods used by more than one Traverse* method.
0481   bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
0482 
0483   // Traverses template parameter lists of either a DeclaratorDecl or TagDecl.
0484   template <typename T>
0485   bool TraverseDeclTemplateParameterLists(T *D);
0486 
0487   bool TraverseTemplateTypeParamDeclConstraints(const TemplateTypeParmDecl *D);
0488 
0489   bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
0490                                           unsigned Count);
0491   bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
0492   bool TraverseRecordHelper(RecordDecl *D);
0493   bool TraverseCXXRecordHelper(CXXRecordDecl *D);
0494   bool TraverseDeclaratorHelper(DeclaratorDecl *D);
0495   bool TraverseDeclContextHelper(DeclContext *DC);
0496   bool TraverseFunctionHelper(FunctionDecl *D);
0497   bool TraverseVarHelper(VarDecl *D);
0498   bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
0499   bool TraverseOMPLoopDirective(OMPLoopDirective *S);
0500   bool TraverseOMPClause(OMPClause *C);
0501 #define GEN_CLANG_CLAUSE_CLASS
0502 #define CLAUSE_CLASS(Enum, Str, Class) bool Visit##Class(Class *C);
0503 #include "llvm/Frontend/OpenMP/OMP.inc"
0504   /// Process clauses with list of variables.
0505   template <typename T> bool VisitOMPClauseList(T *Node);
0506   /// Process clauses with pre-initis.
0507   bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
0508   bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
0509 
0510   bool PostVisitStmt(Stmt *S);
0511   bool TraverseOpenACCConstructStmt(OpenACCConstructStmt *S);
0512   bool
0513   TraverseOpenACCAssociatedStmtConstruct(OpenACCAssociatedStmtConstruct *S);
0514   bool VisitOpenACCClauseList(ArrayRef<const OpenACCClause *>);
0515   bool VisitOpenACCClause(const OpenACCClause *);
0516 };
0517 
0518 template <typename Derived>
0519 bool RecursiveASTVisitor<Derived>::TraverseTypeConstraint(
0520     const TypeConstraint *C) {
0521   if (!getDerived().shouldVisitImplicitCode()) {
0522     TRY_TO(TraverseConceptReference(C->getConceptReference()));
0523     return true;
0524   }
0525   if (Expr *IDC = C->getImmediatelyDeclaredConstraint()) {
0526     TRY_TO(TraverseStmt(IDC));
0527   } else {
0528     // Avoid traversing the ConceptReference in the TypeConstraint
0529     // if we have an immediately-declared-constraint, otherwise
0530     // we'll end up visiting the concept and the arguments in
0531     // the TC twice.
0532     TRY_TO(TraverseConceptReference(C->getConceptReference()));
0533   }
0534   return true;
0535 }
0536 
0537 template <typename Derived>
0538 bool RecursiveASTVisitor<Derived>::TraverseConceptRequirement(
0539     concepts::Requirement *R) {
0540   switch (R->getKind()) {
0541   case concepts::Requirement::RK_Type:
0542     return getDerived().TraverseConceptTypeRequirement(
0543         cast<concepts::TypeRequirement>(R));
0544   case concepts::Requirement::RK_Simple:
0545   case concepts::Requirement::RK_Compound:
0546     return getDerived().TraverseConceptExprRequirement(
0547         cast<concepts::ExprRequirement>(R));
0548   case concepts::Requirement::RK_Nested:
0549     return getDerived().TraverseConceptNestedRequirement(
0550         cast<concepts::NestedRequirement>(R));
0551   }
0552   llvm_unreachable("unexpected case");
0553 }
0554 
0555 template <typename Derived>
0556 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
0557                                                     DataRecursionQueue *Queue) {
0558   // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
0559   switch (S->getStmtClass()) {
0560   case Stmt::NoStmtClass:
0561     break;
0562 #define ABSTRACT_STMT(STMT)
0563 #define STMT(CLASS, PARENT)                                                    \
0564   case Stmt::CLASS##Class:                                                     \
0565     return TRAVERSE_STMT_BASE(CLASS, CLASS, S, Queue);
0566 #include "clang/AST/StmtNodes.inc"
0567   }
0568 
0569   return true;
0570 }
0571 
0572 #undef DISPATCH_STMT
0573 
0574 template <typename Derived>
0575 bool RecursiveASTVisitor<Derived>::TraverseConceptTypeRequirement(
0576     concepts::TypeRequirement *R) {
0577   if (R->isSubstitutionFailure())
0578     return true;
0579   return getDerived().TraverseTypeLoc(R->getType()->getTypeLoc());
0580 }
0581 
0582 template <typename Derived>
0583 bool RecursiveASTVisitor<Derived>::TraverseConceptExprRequirement(
0584     concepts::ExprRequirement *R) {
0585   if (!R->isExprSubstitutionFailure())
0586     TRY_TO(TraverseStmt(R->getExpr()));
0587   auto &RetReq = R->getReturnTypeRequirement();
0588   if (RetReq.isTypeConstraint()) {
0589     if (getDerived().shouldVisitImplicitCode()) {
0590       TRY_TO(TraverseTemplateParameterListHelper(
0591           RetReq.getTypeConstraintTemplateParameterList()));
0592     } else {
0593       // Template parameter list is implicit, visit constraint directly.
0594       TRY_TO(TraverseTypeConstraint(RetReq.getTypeConstraint()));
0595     }
0596   }
0597   return true;
0598 }
0599 
0600 template <typename Derived>
0601 bool RecursiveASTVisitor<Derived>::TraverseConceptNestedRequirement(
0602     concepts::NestedRequirement *R) {
0603   if (!R->hasInvalidConstraint())
0604     return getDerived().TraverseStmt(R->getConstraintExpr());
0605   return true;
0606 }
0607 
0608 template <typename Derived>
0609 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
0610   // In pre-order traversal mode, each Traverse##STMT method is responsible for
0611   // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and
0612   // does not call the default implementation, the WalkUpFrom callback is not
0613   // called. Post-order traversal mode should provide the same behavior
0614   // regarding method overrides.
0615   //
0616   // In post-order traversal mode the Traverse##STMT method, when it receives a
0617   // DataRecursionQueue, can't call WalkUpFrom after traversing children because
0618   // it only enqueues the children and does not traverse them. TraverseStmt
0619   // traverses the enqueued children, and we call WalkUpFrom here.
0620   //
0621   // However, to make pre-order and post-order modes identical with regards to
0622   // whether they call WalkUpFrom at all, we call WalkUpFrom if and only if the
0623   // user did not override the Traverse##STMT method. We implement the override
0624   // check with isSameMethod calls below.
0625 
0626   switch (S->getStmtClass()) {
0627   case Stmt::NoStmtClass:
0628     break;
0629 #define ABSTRACT_STMT(STMT)
0630 #define STMT(CLASS, PARENT)                                                    \
0631   case Stmt::CLASS##Class:                                                     \
0632     if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS,   \
0633                                       &Derived::Traverse##CLASS)) {            \
0634       TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S)));                      \
0635     }                                                                          \
0636     break;
0637 #define INITLISTEXPR(CLASS, PARENT)                                            \
0638   case Stmt::CLASS##Class:                                                     \
0639     if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS,   \
0640                                       &Derived::Traverse##CLASS)) {            \
0641       auto ILE = static_cast<CLASS *>(S);                                      \
0642       if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE)    \
0643         TRY_TO(WalkUpFrom##CLASS(Syn));                                        \
0644       if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm())     \
0645         TRY_TO(WalkUpFrom##CLASS(Sem));                                        \
0646     }                                                                          \
0647     break;
0648 #include "clang/AST/StmtNodes.inc"
0649   }
0650 
0651   return true;
0652 }
0653 
0654 #undef DISPATCH_STMT
0655 
0656 // Inlining this method can lead to large code size and compile-time increases
0657 // without any benefit to runtime performance.
0658 template <typename Derived>
0659 LLVM_ATTRIBUTE_NOINLINE bool
0660 RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S, DataRecursionQueue *Queue) {
0661   if (!S)
0662     return true;
0663 
0664   if (Queue) {
0665     Queue->push_back({S, false});
0666     return true;
0667   }
0668 
0669   SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
0670   LocalQueue.push_back({S, false});
0671 
0672   while (!LocalQueue.empty()) {
0673     auto &CurrSAndVisited = LocalQueue.back();
0674     Stmt *CurrS = CurrSAndVisited.getPointer();
0675     bool Visited = CurrSAndVisited.getInt();
0676     if (Visited) {
0677       LocalQueue.pop_back();
0678       TRY_TO(dataTraverseStmtPost(CurrS));
0679       if (getDerived().shouldTraversePostOrder()) {
0680         TRY_TO(PostVisitStmt(CurrS));
0681       }
0682       continue;
0683     }
0684 
0685     if (getDerived().dataTraverseStmtPre(CurrS)) {
0686       CurrSAndVisited.setInt(true);
0687       size_t N = LocalQueue.size();
0688       TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
0689       // Process new children in the order they were added.
0690       std::reverse(LocalQueue.begin() + N, LocalQueue.end());
0691     } else {
0692       LocalQueue.pop_back();
0693     }
0694   }
0695 
0696   return true;
0697 }
0698 
0699 template <typename Derived>
0700 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
0701   if (T.isNull())
0702     return true;
0703 
0704   switch (T->getTypeClass()) {
0705 #define ABSTRACT_TYPE(CLASS, BASE)
0706 #define TYPE(CLASS, BASE)                                                      \
0707   case Type::CLASS:                                                            \
0708     return getDerived().Traverse##CLASS##Type(                                 \
0709         static_cast<CLASS##Type *>(const_cast<Type *>(T.getTypePtr())));
0710 #include "clang/AST/TypeNodes.inc"
0711   }
0712 
0713   return true;
0714 }
0715 
0716 template <typename Derived>
0717 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
0718   if (TL.isNull())
0719     return true;
0720 
0721   switch (TL.getTypeLocClass()) {
0722 #define ABSTRACT_TYPELOC(CLASS, BASE)
0723 #define TYPELOC(CLASS, BASE)                                                   \
0724   case TypeLoc::CLASS:                                                         \
0725     return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
0726 #include "clang/AST/TypeLocNodes.def"
0727   }
0728 
0729   return true;
0730 }
0731 
0732 // Define the Traverse*Attr(Attr* A) methods
0733 #define VISITORCLASS RecursiveASTVisitor
0734 #include "clang/AST/AttrVisitor.inc"
0735 #undef VISITORCLASS
0736 
0737 template <typename Derived>
0738 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
0739   if (!D)
0740     return true;
0741 
0742   // As a syntax visitor, by default we want to ignore declarations for
0743   // implicit declarations (ones not typed explicitly by the user).
0744   if (!getDerived().shouldVisitImplicitCode()) {
0745     if (D->isImplicit()) {
0746       // For an implicit template type parameter, its type constraints are not
0747       // implicit and are not represented anywhere else. We still need to visit
0748       // them.
0749       if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(D))
0750         return TraverseTemplateTypeParamDeclConstraints(TTPD);
0751       return true;
0752     }
0753 
0754     // Deduction guides for alias templates are always synthesized, so they
0755     // should not be traversed unless shouldVisitImplicitCode() returns true.
0756     //
0757     // It's important to note that checking the implicit bit is not efficient
0758     // for the alias case. For deduction guides synthesized from explicit
0759     // user-defined deduction guides, we must maintain the explicit bit to
0760     // ensure correct overload resolution.
0761     if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
0762       if (llvm::isa_and_present<TypeAliasTemplateDecl>(
0763               FTD->getDeclName().getCXXDeductionGuideTemplate()))
0764         return true;
0765   }
0766 
0767   switch (D->getKind()) {
0768 #define ABSTRACT_DECL(DECL)
0769 #define DECL(CLASS, BASE)                                                      \
0770   case Decl::CLASS:                                                            \
0771     if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D)))    \
0772       return false;                                                            \
0773     break;
0774 #include "clang/AST/DeclNodes.inc"
0775   }
0776   return true;
0777 }
0778 
0779 template <typename Derived>
0780 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
0781     NestedNameSpecifier *NNS) {
0782   if (!NNS)
0783     return true;
0784 
0785   if (NNS->getPrefix())
0786     TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
0787 
0788   switch (NNS->getKind()) {
0789   case NestedNameSpecifier::Identifier:
0790   case NestedNameSpecifier::Namespace:
0791   case NestedNameSpecifier::NamespaceAlias:
0792   case NestedNameSpecifier::Global:
0793   case NestedNameSpecifier::Super:
0794     return true;
0795 
0796   case NestedNameSpecifier::TypeSpec:
0797   case NestedNameSpecifier::TypeSpecWithTemplate:
0798     TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
0799   }
0800 
0801   return true;
0802 }
0803 
0804 template <typename Derived>
0805 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
0806     NestedNameSpecifierLoc NNS) {
0807   if (!NNS)
0808     return true;
0809 
0810   if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
0811     TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
0812 
0813   switch (NNS.getNestedNameSpecifier()->getKind()) {
0814   case NestedNameSpecifier::Identifier:
0815   case NestedNameSpecifier::Namespace:
0816   case NestedNameSpecifier::NamespaceAlias:
0817   case NestedNameSpecifier::Global:
0818   case NestedNameSpecifier::Super:
0819     return true;
0820 
0821   case NestedNameSpecifier::TypeSpec:
0822   case NestedNameSpecifier::TypeSpecWithTemplate:
0823     TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
0824     break;
0825   }
0826 
0827   return true;
0828 }
0829 
0830 template <typename Derived>
0831 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
0832     DeclarationNameInfo NameInfo) {
0833   switch (NameInfo.getName().getNameKind()) {
0834   case DeclarationName::CXXConstructorName:
0835   case DeclarationName::CXXDestructorName:
0836   case DeclarationName::CXXConversionFunctionName:
0837     if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
0838       TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
0839     break;
0840 
0841   case DeclarationName::CXXDeductionGuideName:
0842     TRY_TO(TraverseTemplateName(
0843         TemplateName(NameInfo.getName().getCXXDeductionGuideTemplate())));
0844     break;
0845 
0846   case DeclarationName::Identifier:
0847   case DeclarationName::ObjCZeroArgSelector:
0848   case DeclarationName::ObjCOneArgSelector:
0849   case DeclarationName::ObjCMultiArgSelector:
0850   case DeclarationName::CXXOperatorName:
0851   case DeclarationName::CXXLiteralOperatorName:
0852   case DeclarationName::CXXUsingDirective:
0853     break;
0854   }
0855 
0856   return true;
0857 }
0858 
0859 template <typename Derived>
0860 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
0861   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
0862     TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
0863   } else if (QualifiedTemplateName *QTN =
0864                  Template.getAsQualifiedTemplateName()) {
0865     if (QTN->getQualifier()) {
0866       TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
0867     }
0868   }
0869 
0870   return true;
0871 }
0872 
0873 template <typename Derived>
0874 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
0875     const TemplateArgument &Arg) {
0876   switch (Arg.getKind()) {
0877   case TemplateArgument::Null:
0878   case TemplateArgument::Declaration:
0879   case TemplateArgument::Integral:
0880   case TemplateArgument::NullPtr:
0881   case TemplateArgument::StructuralValue:
0882     return true;
0883 
0884   case TemplateArgument::Type:
0885     return getDerived().TraverseType(Arg.getAsType());
0886 
0887   case TemplateArgument::Template:
0888   case TemplateArgument::TemplateExpansion:
0889     return getDerived().TraverseTemplateName(
0890         Arg.getAsTemplateOrTemplatePattern());
0891 
0892   case TemplateArgument::Expression:
0893     return getDerived().TraverseStmt(Arg.getAsExpr());
0894 
0895   case TemplateArgument::Pack:
0896     return getDerived().TraverseTemplateArguments(Arg.pack_elements());
0897   }
0898 
0899   return true;
0900 }
0901 
0902 // FIXME: no template name location?
0903 // FIXME: no source locations for a template argument pack?
0904 template <typename Derived>
0905 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
0906     const TemplateArgumentLoc &ArgLoc) {
0907   const TemplateArgument &Arg = ArgLoc.getArgument();
0908 
0909   switch (Arg.getKind()) {
0910   case TemplateArgument::Null:
0911   case TemplateArgument::Declaration:
0912   case TemplateArgument::Integral:
0913   case TemplateArgument::NullPtr:
0914   case TemplateArgument::StructuralValue:
0915     return true;
0916 
0917   case TemplateArgument::Type: {
0918     // FIXME: how can TSI ever be NULL?
0919     if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
0920       return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
0921     else
0922       return getDerived().TraverseType(Arg.getAsType());
0923   }
0924 
0925   case TemplateArgument::Template:
0926   case TemplateArgument::TemplateExpansion:
0927     if (ArgLoc.getTemplateQualifierLoc())
0928       TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
0929           ArgLoc.getTemplateQualifierLoc()));
0930     return getDerived().TraverseTemplateName(
0931         Arg.getAsTemplateOrTemplatePattern());
0932 
0933   case TemplateArgument::Expression:
0934     return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
0935 
0936   case TemplateArgument::Pack:
0937     return getDerived().TraverseTemplateArguments(Arg.pack_elements());
0938   }
0939 
0940   return true;
0941 }
0942 
0943 template <typename Derived>
0944 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
0945     ArrayRef<TemplateArgument> Args) {
0946   for (const TemplateArgument &Arg : Args)
0947     TRY_TO(TraverseTemplateArgument(Arg));
0948 
0949   return true;
0950 }
0951 
0952 template <typename Derived>
0953 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
0954     CXXCtorInitializer *Init) {
0955   if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
0956     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
0957 
0958   if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
0959     TRY_TO(TraverseStmt(Init->getInit()));
0960 
0961   return true;
0962 }
0963 
0964 template <typename Derived>
0965 bool
0966 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
0967                                                     const LambdaCapture *C,
0968                                                     Expr *Init) {
0969   if (LE->isInitCapture(C))
0970     TRY_TO(TraverseDecl(C->getCapturedVar()));
0971   else
0972     TRY_TO(TraverseStmt(Init));
0973   return true;
0974 }
0975 
0976 // ----------------- Type traversal -----------------
0977 
0978 // This macro makes available a variable T, the passed-in type.
0979 #define DEF_TRAVERSE_TYPE(TYPE, CODE)                                          \
0980   template <typename Derived>                                                  \
0981   bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) {                 \
0982     if (!getDerived().shouldTraversePostOrder())                               \
0983       TRY_TO(WalkUpFrom##TYPE(T));                                             \
0984     { CODE; }                                                                  \
0985     if (getDerived().shouldTraversePostOrder())                                \
0986       TRY_TO(WalkUpFrom##TYPE(T));                                             \
0987     return true;                                                               \
0988   }
0989 
0990 DEF_TRAVERSE_TYPE(BuiltinType, {})
0991 
0992 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
0993 
0994 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
0995 
0996 DEF_TRAVERSE_TYPE(BlockPointerType,
0997                   { TRY_TO(TraverseType(T->getPointeeType())); })
0998 
0999 DEF_TRAVERSE_TYPE(LValueReferenceType,
1000                   { TRY_TO(TraverseType(T->getPointeeType())); })
1001 
1002 DEF_TRAVERSE_TYPE(RValueReferenceType,
1003                   { TRY_TO(TraverseType(T->getPointeeType())); })
1004 
1005 DEF_TRAVERSE_TYPE(MemberPointerType, {
1006   TRY_TO(TraverseType(QualType(T->getClass(), 0)));
1007   TRY_TO(TraverseType(T->getPointeeType()));
1008 })
1009 
1010 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
1011 
1012 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
1013 
1014 DEF_TRAVERSE_TYPE(ConstantArrayType, {
1015   TRY_TO(TraverseType(T->getElementType()));
1016   if (T->getSizeExpr())
1017     TRY_TO(TraverseStmt(const_cast<Expr*>(T->getSizeExpr())));
1018 })
1019 
1020 DEF_TRAVERSE_TYPE(ArrayParameterType, {
1021   TRY_TO(TraverseType(T->getElementType()));
1022   if (T->getSizeExpr())
1023     TRY_TO(TraverseStmt(const_cast<Expr *>(T->getSizeExpr())));
1024 })
1025 
1026 DEF_TRAVERSE_TYPE(IncompleteArrayType,
1027                   { TRY_TO(TraverseType(T->getElementType())); })
1028 
1029 DEF_TRAVERSE_TYPE(VariableArrayType, {
1030   TRY_TO(TraverseType(T->getElementType()));
1031   TRY_TO(TraverseStmt(T->getSizeExpr()));
1032 })
1033 
1034 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
1035   TRY_TO(TraverseType(T->getElementType()));
1036   if (T->getSizeExpr())
1037     TRY_TO(TraverseStmt(T->getSizeExpr()));
1038 })
1039 
1040 DEF_TRAVERSE_TYPE(DependentAddressSpaceType, {
1041   TRY_TO(TraverseStmt(T->getAddrSpaceExpr()));
1042   TRY_TO(TraverseType(T->getPointeeType()));
1043 })
1044 
1045 DEF_TRAVERSE_TYPE(DependentVectorType, {
1046   if (T->getSizeExpr())
1047     TRY_TO(TraverseStmt(T->getSizeExpr()));
1048   TRY_TO(TraverseType(T->getElementType()));
1049 })
1050 
1051 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
1052   if (T->getSizeExpr())
1053     TRY_TO(TraverseStmt(T->getSizeExpr()));
1054   TRY_TO(TraverseType(T->getElementType()));
1055 })
1056 
1057 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
1058 
1059 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
1060 
1061 DEF_TRAVERSE_TYPE(ConstantMatrixType,
1062                   { TRY_TO(TraverseType(T->getElementType())); })
1063 
1064 DEF_TRAVERSE_TYPE(DependentSizedMatrixType, {
1065   if (T->getRowExpr())
1066     TRY_TO(TraverseStmt(T->getRowExpr()));
1067   if (T->getColumnExpr())
1068     TRY_TO(TraverseStmt(T->getColumnExpr()));
1069   TRY_TO(TraverseType(T->getElementType()));
1070 })
1071 
1072 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
1073                   { TRY_TO(TraverseType(T->getReturnType())); })
1074 
1075 DEF_TRAVERSE_TYPE(FunctionProtoType, {
1076   TRY_TO(TraverseType(T->getReturnType()));
1077 
1078   for (const auto &A : T->param_types()) {
1079     TRY_TO(TraverseType(A));
1080   }
1081 
1082   for (const auto &E : T->exceptions()) {
1083     TRY_TO(TraverseType(E));
1084   }
1085 
1086   if (Expr *NE = T->getNoexceptExpr())
1087     TRY_TO(TraverseStmt(NE));
1088 })
1089 
1090 DEF_TRAVERSE_TYPE(UsingType, {})
1091 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
1092 DEF_TRAVERSE_TYPE(TypedefType, {})
1093 
1094 DEF_TRAVERSE_TYPE(TypeOfExprType,
1095                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1096 
1097 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnmodifiedType())); })
1098 
1099 DEF_TRAVERSE_TYPE(DecltypeType,
1100                   { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1101 
1102 DEF_TRAVERSE_TYPE(PackIndexingType, {
1103   TRY_TO(TraverseType(T->getPattern()));
1104   TRY_TO(TraverseStmt(T->getIndexExpr()));
1105 })
1106 
1107 DEF_TRAVERSE_TYPE(UnaryTransformType, {
1108   TRY_TO(TraverseType(T->getBaseType()));
1109   TRY_TO(TraverseType(T->getUnderlyingType()));
1110 })
1111 
1112 DEF_TRAVERSE_TYPE(AutoType, {
1113   TRY_TO(TraverseType(T->getDeducedType()));
1114   if (T->isConstrained()) {
1115     TRY_TO(TraverseTemplateArguments(T->getTypeConstraintArguments()));
1116   }
1117 })
1118 DEF_TRAVERSE_TYPE(DeducedTemplateSpecializationType, {
1119   TRY_TO(TraverseTemplateName(T->getTemplateName()));
1120   TRY_TO(TraverseType(T->getDeducedType()));
1121 })
1122 
1123 DEF_TRAVERSE_TYPE(RecordType, {})
1124 DEF_TRAVERSE_TYPE(EnumType, {})
1125 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
1126 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {
1127   TRY_TO(TraverseType(T->getReplacementType()));
1128 })
1129 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {
1130   TRY_TO(TraverseTemplateArgument(T->getArgumentPack()));
1131 })
1132 
1133 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
1134   TRY_TO(TraverseTemplateName(T->getTemplateName()));
1135   TRY_TO(TraverseTemplateArguments(T->template_arguments()));
1136 })
1137 
1138 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
1139 
1140 DEF_TRAVERSE_TYPE(AttributedType,
1141                   { TRY_TO(TraverseType(T->getModifiedType())); })
1142 
1143 DEF_TRAVERSE_TYPE(CountAttributedType, {
1144   if (T->getCountExpr())
1145     TRY_TO(TraverseStmt(T->getCountExpr()));
1146   TRY_TO(TraverseType(T->desugar()));
1147 })
1148 
1149 DEF_TRAVERSE_TYPE(BTFTagAttributedType,
1150                   { TRY_TO(TraverseType(T->getWrappedType())); })
1151 
1152 DEF_TRAVERSE_TYPE(HLSLAttributedResourceType,
1153                   { TRY_TO(TraverseType(T->getWrappedType())); })
1154 
1155 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
1156 
1157 DEF_TRAVERSE_TYPE(MacroQualifiedType,
1158                   { TRY_TO(TraverseType(T->getUnderlyingType())); })
1159 
1160 DEF_TRAVERSE_TYPE(ElaboratedType, {
1161   if (T->getQualifier()) {
1162     TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1163   }
1164   TRY_TO(TraverseType(T->getNamedType()));
1165 })
1166 
1167 DEF_TRAVERSE_TYPE(DependentNameType,
1168                   { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
1169 
1170 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
1171   TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1172   TRY_TO(TraverseTemplateArguments(T->template_arguments()));
1173 })
1174 
1175 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
1176 
1177 DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
1178 
1179 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
1180 
1181 DEF_TRAVERSE_TYPE(ObjCObjectType, {
1182   // We have to watch out here because an ObjCInterfaceType's base
1183   // type is itself.
1184   if (T->getBaseType().getTypePtr() != T)
1185     TRY_TO(TraverseType(T->getBaseType()));
1186   for (auto typeArg : T->getTypeArgsAsWritten()) {
1187     TRY_TO(TraverseType(typeArg));
1188   }
1189 })
1190 
1191 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
1192                   { TRY_TO(TraverseType(T->getPointeeType())); })
1193 
1194 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
1195 
1196 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
1197 
1198 DEF_TRAVERSE_TYPE(BitIntType, {})
1199 DEF_TRAVERSE_TYPE(DependentBitIntType,
1200                   { TRY_TO(TraverseStmt(T->getNumBitsExpr())); })
1201 
1202 #undef DEF_TRAVERSE_TYPE
1203 
1204 // ----------------- TypeLoc traversal -----------------
1205 
1206 // This macro makes available a variable TL, the passed-in TypeLoc.
1207 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
1208 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
1209 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
1210 // continue to work.
1211 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE)                                       \
1212   template <typename Derived>                                                  \
1213   bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) {       \
1214     if (!getDerived().shouldTraversePostOrder()) {                             \
1215       TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                       \
1216       if (getDerived().shouldWalkTypesOfTypeLocs())                            \
1217         TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr())));         \
1218     }                                                                          \
1219     { CODE; }                                                                  \
1220     if (getDerived().shouldTraversePostOrder()) {                              \
1221       TRY_TO(WalkUpFrom##TYPE##Loc(TL));                                       \
1222       if (getDerived().shouldWalkTypesOfTypeLocs())                            \
1223         TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr())));         \
1224     }                                                                          \
1225     return true;                                                               \
1226   }
1227 
1228 template <typename Derived>
1229 bool
1230 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
1231   // Move this over to the 'main' typeloc tree.  Note that this is a
1232   // move -- we pretend that we were really looking at the unqualified
1233   // typeloc all along -- rather than a recursion, so we don't follow
1234   // the normal CRTP plan of going through
1235   // getDerived().TraverseTypeLoc.  If we did, we'd be traversing
1236   // twice for the same type (once as a QualifiedTypeLoc version of
1237   // the type, once as an UnqualifiedTypeLoc version of the type),
1238   // which in effect means we'd call VisitTypeLoc twice with the
1239   // 'same' type.  This solves that problem, at the cost of never
1240   // seeing the qualified version of the type (unless the client
1241   // subclasses TraverseQualifiedTypeLoc themselves).  It's not a
1242   // perfect solution.  A perfect solution probably requires making
1243   // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
1244   // wrapper around Type* -- rather than being its own class in the
1245   // type hierarchy.
1246   return TraverseTypeLoc(TL.getUnqualifiedLoc());
1247 }
1248 
1249 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
1250 
1251 // FIXME: ComplexTypeLoc is unfinished
1252 DEF_TRAVERSE_TYPELOC(ComplexType, {
1253   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1254 })
1255 
1256 DEF_TRAVERSE_TYPELOC(PointerType,
1257                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1258 
1259 DEF_TRAVERSE_TYPELOC(BlockPointerType,
1260                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1261 
1262 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1263                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1264 
1265 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1266                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1267 
1268 // We traverse this in the type case as well, but how is it not reached through
1269 // the pointee type?
1270 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1271   if (auto *TSI = TL.getClassTInfo())
1272     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1273   else
1274     TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1275   TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1276 })
1277 
1278 DEF_TRAVERSE_TYPELOC(AdjustedType,
1279                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1280 
1281 DEF_TRAVERSE_TYPELOC(DecayedType,
1282                      { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1283 
1284 template <typename Derived>
1285 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
1286   // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1287   TRY_TO(TraverseStmt(TL.getSizeExpr()));
1288   return true;
1289 }
1290 
1291 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1292   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1293   TRY_TO(TraverseArrayTypeLocHelper(TL));
1294 })
1295 
1296 DEF_TRAVERSE_TYPELOC(ArrayParameterType, {
1297   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1298   TRY_TO(TraverseArrayTypeLocHelper(TL));
1299 })
1300 
1301 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1302   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1303   TRY_TO(TraverseArrayTypeLocHelper(TL));
1304 })
1305 
1306 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1307   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1308   TRY_TO(TraverseArrayTypeLocHelper(TL));
1309 })
1310 
1311 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1312   TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1313   TRY_TO(TraverseArrayTypeLocHelper(TL));
1314 })
1315 
1316 DEF_TRAVERSE_TYPELOC(DependentAddressSpaceType, {
1317   TRY_TO(TraverseStmt(TL.getTypePtr()->getAddrSpaceExpr()));
1318   TRY_TO(TraverseType(TL.getTypePtr()->getPointeeType()));
1319 })
1320 
1321 // FIXME: order? why not size expr first?
1322 // FIXME: base VectorTypeLoc is unfinished
1323 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1324   if (TL.getTypePtr()->getSizeExpr())
1325     TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1326   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1327 })
1328 
1329 // FIXME: VectorTypeLoc is unfinished
1330 DEF_TRAVERSE_TYPELOC(VectorType, {
1331   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1332 })
1333 
1334 DEF_TRAVERSE_TYPELOC(DependentVectorType, {
1335   if (TL.getTypePtr()->getSizeExpr())
1336     TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1337   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1338 })
1339 
1340 // FIXME: size and attributes
1341 // FIXME: base VectorTypeLoc is unfinished
1342 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1343   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1344 })
1345 
1346 DEF_TRAVERSE_TYPELOC(ConstantMatrixType, {
1347   TRY_TO(TraverseStmt(TL.getAttrRowOperand()));
1348   TRY_TO(TraverseStmt(TL.getAttrColumnOperand()));
1349   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1350 })
1351 
1352 DEF_TRAVERSE_TYPELOC(DependentSizedMatrixType, {
1353   TRY_TO(TraverseStmt(TL.getAttrRowOperand()));
1354   TRY_TO(TraverseStmt(TL.getAttrColumnOperand()));
1355   TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1356 })
1357 
1358 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1359                      { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
1360 
1361 // FIXME: location of exception specifications (attributes?)
1362 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1363   TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
1364 
1365   const FunctionProtoType *T = TL.getTypePtr();
1366 
1367   for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1368     if (TL.getParam(I)) {
1369       TRY_TO(TraverseDecl(TL.getParam(I)));
1370     } else if (I < T->getNumParams()) {
1371       TRY_TO(TraverseType(T->getParamType(I)));
1372     }
1373   }
1374 
1375   for (const auto &E : T->exceptions()) {
1376     TRY_TO(TraverseType(E));
1377   }
1378 
1379   if (Expr *NE = T->getNoexceptExpr())
1380     TRY_TO(TraverseStmt(NE));
1381 })
1382 
1383 DEF_TRAVERSE_TYPELOC(UsingType, {})
1384 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1385 DEF_TRAVERSE_TYPELOC(TypedefType, {})
1386 
1387 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1388                      { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
1389 
1390 DEF_TRAVERSE_TYPELOC(TypeOfType, {
1391   TRY_TO(TraverseTypeLoc(TL.getUnmodifiedTInfo()->getTypeLoc()));
1392 })
1393 
1394 // FIXME: location of underlying expr
1395 DEF_TRAVERSE_TYPELOC(DecltypeType, {
1396   TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1397 })
1398 
1399 DEF_TRAVERSE_TYPELOC(PackIndexingType, {
1400   TRY_TO(TraverseType(TL.getPattern()));
1401   TRY_TO(TraverseStmt(TL.getTypePtr()->getIndexExpr()));
1402 })
1403 
1404 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1405   TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1406 })
1407 
1408 DEF_TRAVERSE_TYPELOC(AutoType, {
1409   TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1410   if (TL.isConstrained()) {
1411     TRY_TO(TraverseConceptReference(TL.getConceptReference()));
1412   }
1413 })
1414 
1415 DEF_TRAVERSE_TYPELOC(DeducedTemplateSpecializationType, {
1416   TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1417   TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1418 })
1419 
1420 DEF_TRAVERSE_TYPELOC(RecordType, {})
1421 DEF_TRAVERSE_TYPELOC(EnumType, {})
1422 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1423 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {
1424   TRY_TO(TraverseType(TL.getTypePtr()->getReplacementType()));
1425 })
1426 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {
1427   TRY_TO(TraverseTemplateArgument(TL.getTypePtr()->getArgumentPack()));
1428 })
1429 
1430 // FIXME: use the loc for the template name?
1431 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1432   TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1433   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1434     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1435   }
1436 })
1437 
1438 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
1439 
1440 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1441 
1442 DEF_TRAVERSE_TYPELOC(MacroQualifiedType,
1443                      { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1444 
1445 DEF_TRAVERSE_TYPELOC(AttributedType,
1446                      { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
1447 
1448 DEF_TRAVERSE_TYPELOC(CountAttributedType,
1449                      { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1450 
1451 DEF_TRAVERSE_TYPELOC(BTFTagAttributedType,
1452                      { TRY_TO(TraverseTypeLoc(TL.getWrappedLoc())); })
1453 
1454 DEF_TRAVERSE_TYPELOC(HLSLAttributedResourceType,
1455                      { TRY_TO(TraverseTypeLoc(TL.getWrappedLoc())); })
1456 
1457 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1458   if (TL.getQualifierLoc()) {
1459     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1460   }
1461   TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1462 })
1463 
1464 DEF_TRAVERSE_TYPELOC(DependentNameType, {
1465   TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1466 })
1467 
1468 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1469   if (TL.getQualifierLoc()) {
1470     TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1471   }
1472 
1473   for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1474     TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1475   }
1476 })
1477 
1478 DEF_TRAVERSE_TYPELOC(PackExpansionType,
1479                      { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
1480 
1481 DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {
1482   for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
1483     ObjCProtocolLoc ProtocolLoc(TL.getProtocol(I), TL.getProtocolLoc(I));
1484     TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
1485   }
1486 })
1487 
1488 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
1489 
1490 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1491   // We have to watch out here because an ObjCInterfaceType's base
1492   // type is itself.
1493   if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1494     TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1495   for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
1496     TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
1497   for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
1498     ObjCProtocolLoc ProtocolLoc(TL.getProtocol(I), TL.getProtocolLoc(I));
1499     TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
1500   }
1501 })
1502 
1503 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1504                      { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1505 
1506 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1507 
1508 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1509 
1510 DEF_TRAVERSE_TYPELOC(BitIntType, {})
1511 DEF_TRAVERSE_TYPELOC(DependentBitIntType, {
1512   TRY_TO(TraverseStmt(TL.getTypePtr()->getNumBitsExpr()));
1513 })
1514 
1515 #undef DEF_TRAVERSE_TYPELOC
1516 
1517 // ----------------- Decl traversal -----------------
1518 //
1519 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1520 // the children that come from the DeclContext associated with it.
1521 // Therefore each Traverse* only needs to worry about children other
1522 // than those.
1523 
1524 template <typename Derived>
1525 bool RecursiveASTVisitor<Derived>::canIgnoreChildDeclWhileTraversingDeclContext(
1526     const Decl *Child) {
1527   // BlockDecls are traversed through BlockExprs,
1528   // CapturedDecls are traversed through CapturedStmts.
1529   if (isa<BlockDecl>(Child) || isa<CapturedDecl>(Child))
1530     return true;
1531   // Lambda classes are traversed through LambdaExprs.
1532   if (const CXXRecordDecl* Cls = dyn_cast<CXXRecordDecl>(Child))
1533     return Cls->isLambda();
1534   return false;
1535 }
1536 
1537 template <typename Derived>
1538 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1539   if (!DC)
1540     return true;
1541 
1542   for (auto *Child : DC->decls()) {
1543     if (!canIgnoreChildDeclWhileTraversingDeclContext(Child))
1544       TRY_TO(TraverseDecl(Child));
1545   }
1546 
1547   return true;
1548 }
1549 
1550 // This macro makes available a variable D, the passed-in decl.
1551 #define DEF_TRAVERSE_DECL(DECL, CODE)                                          \
1552   template <typename Derived>                                                  \
1553   bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) {                 \
1554     bool ShouldVisitChildren = true;                                           \
1555     bool ReturnValue = true;                                                   \
1556     if (!getDerived().shouldTraversePostOrder())                               \
1557       TRY_TO(WalkUpFrom##DECL(D));                                             \
1558     { CODE; }                                                                  \
1559     if (ReturnValue && ShouldVisitChildren)                                    \
1560       TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D)));             \
1561     if (ReturnValue) {                                                         \
1562       /* Visit any attributes attached to this declaration. */                 \
1563       for (auto *I : D->attrs())                                               \
1564         TRY_TO(getDerived().TraverseAttr(I));                                  \
1565     }                                                                          \
1566     if (ReturnValue && getDerived().shouldTraversePostOrder())                 \
1567       TRY_TO(WalkUpFrom##DECL(D));                                             \
1568     return ReturnValue;                                                        \
1569   }
1570 
1571 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
1572 
1573 DEF_TRAVERSE_DECL(BlockDecl, {
1574   if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1575     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1576   TRY_TO(TraverseStmt(D->getBody()));
1577   for (const auto &I : D->captures()) {
1578     if (I.hasCopyExpr()) {
1579       TRY_TO(TraverseStmt(I.getCopyExpr()));
1580     }
1581   }
1582   ShouldVisitChildren = false;
1583 })
1584 
1585 DEF_TRAVERSE_DECL(OutlinedFunctionDecl, {
1586   TRY_TO(TraverseStmt(D->getBody()));
1587   ShouldVisitChildren = false;
1588 })
1589 
1590 DEF_TRAVERSE_DECL(CapturedDecl, {
1591   TRY_TO(TraverseStmt(D->getBody()));
1592   ShouldVisitChildren = false;
1593 })
1594 
1595 DEF_TRAVERSE_DECL(EmptyDecl, {})
1596 
1597 DEF_TRAVERSE_DECL(HLSLBufferDecl, {})
1598 
1599 DEF_TRAVERSE_DECL(LifetimeExtendedTemporaryDecl, {
1600   TRY_TO(TraverseStmt(D->getTemporaryExpr()));
1601 })
1602 
1603 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1604                   { TRY_TO(TraverseStmt(D->getAsmString())); })
1605 
1606 DEF_TRAVERSE_DECL(TopLevelStmtDecl, { TRY_TO(TraverseStmt(D->getStmt())); })
1607 
1608 DEF_TRAVERSE_DECL(ImportDecl, {})
1609 
1610 DEF_TRAVERSE_DECL(FriendDecl, {
1611   // Friend is either decl or a type.
1612   if (D->getFriendType()) {
1613     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1614     // Traverse any CXXRecordDecl owned by this type, since
1615     // it will not be in the parent context:
1616     if (auto *ET = D->getFriendType()->getType()->getAs<ElaboratedType>())
1617       TRY_TO(TraverseDecl(ET->getOwnedTagDecl()));
1618   } else {
1619     TRY_TO(TraverseDecl(D->getFriendDecl()));
1620   }
1621 })
1622 
1623 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1624   if (D->getFriendType())
1625     TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1626   else
1627     TRY_TO(TraverseDecl(D->getFriendDecl()));
1628   for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1629     TemplateParameterList *TPL = D->getTemplateParameterList(I);
1630     for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1631          ITPL != ETPL; ++ITPL) {
1632       TRY_TO(TraverseDecl(*ITPL));
1633     }
1634   }
1635 })
1636 
1637 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1638 
1639 DEF_TRAVERSE_DECL(ExportDecl, {})
1640 
1641 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1642                                         })
1643 
1644 DEF_TRAVERSE_DECL(StaticAssertDecl, {
1645   TRY_TO(TraverseStmt(D->getAssertExpr()));
1646   TRY_TO(TraverseStmt(D->getMessage()));
1647 })
1648 
1649 DEF_TRAVERSE_DECL(TranslationUnitDecl, {
1650   // Code in an unnamed namespace shows up automatically in
1651   // decls_begin()/decls_end().  Thus we don't need to recurse on
1652   // D->getAnonymousNamespace().
1653 
1654   // If the traversal scope is set, then consider them to be the children of
1655   // the TUDecl, rather than traversing (and loading?) all top-level decls.
1656   auto Scope = D->getASTContext().getTraversalScope();
1657   bool HasLimitedScope =
1658       Scope.size() != 1 || !isa<TranslationUnitDecl>(Scope.front());
1659   if (HasLimitedScope) {
1660     ShouldVisitChildren = false; // we'll do that here instead
1661     for (auto *Child : Scope) {
1662       if (!canIgnoreChildDeclWhileTraversingDeclContext(Child))
1663         TRY_TO(TraverseDecl(Child));
1664     }
1665   }
1666 })
1667 
1668 DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
1669 
1670 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
1671 
1672 DEF_TRAVERSE_DECL(ExternCContextDecl, {})
1673 
1674 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1675   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1676 
1677   // We shouldn't traverse an aliased namespace, since it will be
1678   // defined (and, therefore, traversed) somewhere else.
1679   ShouldVisitChildren = false;
1680 })
1681 
1682 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1683                              })
1684 
1685 DEF_TRAVERSE_DECL(
1686     NamespaceDecl,
1687     {// Code in an unnamed namespace shows up automatically in
1688      // decls_begin()/decls_end().  Thus we don't need to recurse on
1689      // D->getAnonymousNamespace().
1690     })
1691 
1692 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1693                                            })
1694 
1695 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {
1696   if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
1697     for (auto typeParam : *typeParamList) {
1698       TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1699     }
1700   }
1701   for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) {
1702     ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It));
1703     TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
1704   }
1705 })
1706 
1707 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1708                                         })
1709 
1710 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1711                                           })
1712 
1713 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {
1714   if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
1715     for (auto typeParam : *typeParamList) {
1716       TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1717     }
1718   }
1719 
1720   if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
1721     TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
1722   }
1723   if (D->isThisDeclarationADefinition()) {
1724     for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) {
1725       ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It));
1726       TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
1727     }
1728   }
1729 })
1730 
1731 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {
1732   if (D->isThisDeclarationADefinition()) {
1733     for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) {
1734       ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It));
1735       TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc));
1736     }
1737   }
1738 })
1739 
1740 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1741   if (D->getReturnTypeSourceInfo()) {
1742     TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1743   }
1744   for (ParmVarDecl *Parameter : D->parameters()) {
1745     TRY_TO(TraverseDecl(Parameter));
1746   }
1747   if (D->isThisDeclarationADefinition()) {
1748     TRY_TO(TraverseStmt(D->getBody()));
1749   }
1750   ShouldVisitChildren = false;
1751 })
1752 
1753 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
1754   if (D->hasExplicitBound()) {
1755     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1756     // We shouldn't traverse D->getTypeForDecl(); it's a result of
1757     // declaring the type alias, not something that was written in the
1758     // source.
1759   }
1760 })
1761 
1762 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1763   if (D->getTypeSourceInfo())
1764     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1765   else
1766     TRY_TO(TraverseType(D->getType()));
1767   ShouldVisitChildren = false;
1768 })
1769 
1770 DEF_TRAVERSE_DECL(UsingDecl, {
1771   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1772   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1773 })
1774 
1775 DEF_TRAVERSE_DECL(UsingEnumDecl,
1776                   { TRY_TO(TraverseTypeLoc(D->getEnumTypeLoc())); })
1777 
1778 DEF_TRAVERSE_DECL(UsingPackDecl, {})
1779 
1780 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1781   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1782 })
1783 
1784 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
1785 
1786 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
1787 
1788 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
1789   for (auto *I : D->varlist()) {
1790     TRY_TO(TraverseStmt(I));
1791   }
1792 })
1793 
1794 DEF_TRAVERSE_DECL(OMPRequiresDecl, {
1795   for (auto *C : D->clauselists()) {
1796     TRY_TO(TraverseOMPClause(C));
1797   }
1798 })
1799 
1800 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
1801   TRY_TO(TraverseStmt(D->getCombiner()));
1802   if (auto *Initializer = D->getInitializer())
1803     TRY_TO(TraverseStmt(Initializer));
1804   TRY_TO(TraverseType(D->getType()));
1805   return true;
1806 })
1807 
1808 DEF_TRAVERSE_DECL(OMPDeclareMapperDecl, {
1809   for (auto *C : D->clauselists())
1810     TRY_TO(TraverseOMPClause(C));
1811   TRY_TO(TraverseType(D->getType()));
1812   return true;
1813 })
1814 
1815 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
1816 
1817 DEF_TRAVERSE_DECL(OMPAllocateDecl, {
1818   for (auto *I : D->varlist())
1819     TRY_TO(TraverseStmt(I));
1820   for (auto *C : D->clauselists())
1821     TRY_TO(TraverseOMPClause(C));
1822 })
1823 
1824 // A helper method for TemplateDecl's children.
1825 template <typename Derived>
1826 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1827     TemplateParameterList *TPL) {
1828   if (TPL) {
1829     for (NamedDecl *D : *TPL) {
1830       TRY_TO(TraverseDecl(D));
1831     }
1832     if (Expr *RequiresClause = TPL->getRequiresClause()) {
1833       TRY_TO(TraverseStmt(RequiresClause));
1834     }
1835   }
1836   return true;
1837 }
1838 
1839 template <typename Derived>
1840 template <typename T>
1841 bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) {
1842   for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) {
1843     TemplateParameterList *TPL = D->getTemplateParameterList(i);
1844     TraverseTemplateParameterListHelper(TPL);
1845   }
1846   return true;
1847 }
1848 
1849 template <typename Derived>
1850 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1851     ClassTemplateDecl *D) {
1852   for (auto *SD : D->specializations()) {
1853     for (auto *RD : SD->redecls()) {
1854       assert(!cast<CXXRecordDecl>(RD)->isInjectedClassName());
1855       switch (
1856           cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1857       // Visit the implicit instantiations with the requested pattern.
1858       case TSK_Undeclared:
1859       case TSK_ImplicitInstantiation:
1860         TRY_TO(TraverseDecl(RD));
1861         break;
1862 
1863       // We don't need to do anything on an explicit instantiation
1864       // or explicit specialization because there will be an explicit
1865       // node for it elsewhere.
1866       case TSK_ExplicitInstantiationDeclaration:
1867       case TSK_ExplicitInstantiationDefinition:
1868       case TSK_ExplicitSpecialization:
1869         break;
1870       }
1871     }
1872   }
1873 
1874   return true;
1875 }
1876 
1877 template <typename Derived>
1878 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1879     VarTemplateDecl *D) {
1880   for (auto *SD : D->specializations()) {
1881     for (auto *RD : SD->redecls()) {
1882       switch (
1883           cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1884       case TSK_Undeclared:
1885       case TSK_ImplicitInstantiation:
1886         TRY_TO(TraverseDecl(RD));
1887         break;
1888 
1889       case TSK_ExplicitInstantiationDeclaration:
1890       case TSK_ExplicitInstantiationDefinition:
1891       case TSK_ExplicitSpecialization:
1892         break;
1893       }
1894     }
1895   }
1896 
1897   return true;
1898 }
1899 
1900 // A helper method for traversing the instantiations of a
1901 // function while skipping its specializations.
1902 template <typename Derived>
1903 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1904     FunctionTemplateDecl *D) {
1905   for (auto *FD : D->specializations()) {
1906     for (auto *RD : FD->redecls()) {
1907       switch (RD->getTemplateSpecializationKind()) {
1908       case TSK_Undeclared:
1909       case TSK_ImplicitInstantiation:
1910         // We don't know what kind of FunctionDecl this is.
1911         TRY_TO(TraverseDecl(RD));
1912         break;
1913 
1914       // FIXME: For now traverse explicit instantiations here. Change that
1915       // once they are represented as dedicated nodes in the AST.
1916       case TSK_ExplicitInstantiationDeclaration:
1917       case TSK_ExplicitInstantiationDefinition:
1918         TRY_TO(TraverseDecl(RD));
1919         break;
1920 
1921       case TSK_ExplicitSpecialization:
1922         break;
1923       }
1924     }
1925   }
1926 
1927   return true;
1928 }
1929 
1930 // This macro unifies the traversal of class, variable and function
1931 // template declarations.
1932 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND)                                   \
1933   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, {                              \
1934     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));   \
1935     TRY_TO(TraverseDecl(D->getTemplatedDecl()));                               \
1936                                                                                \
1937     /* By default, we do not traverse the instantiations of                    \
1938        class templates since they do not appear in the user code. The          \
1939        following code optionally traverses them.                               \
1940                                                                                \
1941        We only traverse the class instantiations when we see the canonical     \
1942        declaration of the template, to ensure we only visit them once. */      \
1943     if (getDerived().shouldVisitTemplateInstantiations() &&                    \
1944         D == D->getCanonicalDecl())                                            \
1945       TRY_TO(TraverseTemplateInstantiations(D));                               \
1946                                                                                \
1947     /* Note that getInstantiatedFromMemberTemplate() is just a link            \
1948        from a template instantiation back to the template from which           \
1949        it was instantiated, and thus should not be traversed. */               \
1950   })
1951 
1952 DEF_TRAVERSE_TMPL_DECL(Class)
1953 DEF_TRAVERSE_TMPL_DECL(Var)
1954 DEF_TRAVERSE_TMPL_DECL(Function)
1955 
1956 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1957   // D is the "T" in something like
1958   //   template <template <typename> class T> class container { };
1959   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1960   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1961     TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1962   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1963 })
1964 
1965 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
1966   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1967 })
1968 
1969 template <typename Derived>
1970 bool RecursiveASTVisitor<Derived>::TraverseTemplateTypeParamDeclConstraints(
1971     const TemplateTypeParmDecl *D) {
1972   if (const auto *TC = D->getTypeConstraint())
1973     TRY_TO(TraverseTypeConstraint(TC));
1974   return true;
1975 }
1976 
1977 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1978   // D is the "T" in something like "template<typename T> class vector;"
1979   if (D->getTypeForDecl())
1980     TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1981   TRY_TO(TraverseTemplateTypeParamDeclConstraints(D));
1982   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1983     TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1984 })
1985 
1986 DEF_TRAVERSE_DECL(TypedefDecl, {
1987   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1988   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1989   // declaring the typedef, not something that was written in the
1990   // source.
1991 })
1992 
1993 DEF_TRAVERSE_DECL(TypeAliasDecl, {
1994   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1995   // We shouldn't traverse D->getTypeForDecl(); it's a result of
1996   // declaring the type alias, not something that was written in the
1997   // source.
1998 })
1999 
2000 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
2001   TRY_TO(TraverseDecl(D->getTemplatedDecl()));
2002   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
2003 })
2004 
2005 DEF_TRAVERSE_DECL(ConceptDecl, {
2006   TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
2007   TRY_TO(TraverseStmt(D->getConstraintExpr()));
2008 })
2009 
2010 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
2011   // A dependent using declaration which was marked with 'typename'.
2012   //   template<class T> class A : public B<T> { using typename B<T>::foo; };
2013   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
2014   // We shouldn't traverse D->getTypeForDecl(); it's a result of
2015   // declaring the type, not something that was written in the
2016   // source.
2017 })
2018 
2019 DEF_TRAVERSE_DECL(UnresolvedUsingIfExistsDecl, {})
2020 
2021 DEF_TRAVERSE_DECL(EnumDecl, {
2022   TRY_TO(TraverseDeclTemplateParameterLists(D));
2023 
2024   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
2025   if (auto *TSI = D->getIntegerTypeSourceInfo())
2026     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
2027   // The enumerators are already traversed by
2028   // decls_begin()/decls_end().
2029 })
2030 
2031 // Helper methods for RecordDecl and its children.
2032 template <typename Derived>
2033 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
2034   // We shouldn't traverse D->getTypeForDecl(); it's a result of
2035   // declaring the type, not something that was written in the source.
2036 
2037   TRY_TO(TraverseDeclTemplateParameterLists(D));
2038   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
2039   return true;
2040 }
2041 
2042 template <typename Derived>
2043 bool RecursiveASTVisitor<Derived>::TraverseCXXBaseSpecifier(
2044     const CXXBaseSpecifier &Base) {
2045   TRY_TO(TraverseTypeLoc(Base.getTypeSourceInfo()->getTypeLoc()));
2046   return true;
2047 }
2048 
2049 template <typename Derived>
2050 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
2051   if (!TraverseRecordHelper(D))
2052     return false;
2053   if (D->isCompleteDefinition()) {
2054     for (const auto &I : D->bases()) {
2055       TRY_TO(TraverseCXXBaseSpecifier(I));
2056     }
2057     // We don't traverse the friends or the conversions, as they are
2058     // already in decls_begin()/decls_end().
2059   }
2060   return true;
2061 }
2062 
2063 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
2064 
2065 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
2066 
2067 template <typename Derived>
2068 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
2069     const TemplateArgumentLoc *TAL, unsigned Count) {
2070   for (unsigned I = 0; I < Count; ++I) {
2071     TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
2072   }
2073   return true;
2074 }
2075 
2076 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND, DECLKIND)                    \
2077   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, {                \
2078     /* For implicit instantiations ("set<int> x;"), we don't want to           \
2079        recurse at all, since the instatiated template isn't written in         \
2080        the source code anywhere.  (Note the instatiated *type* --              \
2081        set<int> -- is written, and will still get a callback of                \
2082        TemplateSpecializationType).  For explicit instantiations               \
2083        ("template set<int>;"), we do need a callback, since this               \
2084        is the only callback that's made for this instantiation.                \
2085        We use getTemplateArgsAsWritten() to distinguish. */                    \
2086     if (const auto *ArgsWritten = D->getTemplateArgsAsWritten()) {             \
2087       /* The args that remains unspecialized. */                               \
2088       TRY_TO(TraverseTemplateArgumentLocsHelper(                               \
2089           ArgsWritten->getTemplateArgs(), ArgsWritten->NumTemplateArgs));      \
2090     }                                                                          \
2091                                                                                \
2092     if (getDerived().shouldVisitTemplateInstantiations() ||                    \
2093         D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {    \
2094       /* Traverse base definition for explicit specializations */              \
2095       TRY_TO(Traverse##DECLKIND##Helper(D));                                   \
2096     } else {                                                                   \
2097       TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));            \
2098                                                                                \
2099       /* Returning from here skips traversing the                              \
2100          declaration context of the *TemplateSpecializationDecl                \
2101          (embedded in the DEF_TRAVERSE_DECL() macro)                           \
2102          which contains the instantiated members of the template. */           \
2103       return true;                                                             \
2104     }                                                                          \
2105   })
2106 
2107 DEF_TRAVERSE_TMPL_SPEC_DECL(Class, CXXRecord)
2108 DEF_TRAVERSE_TMPL_SPEC_DECL(Var, Var)
2109 
2110 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND)               \
2111   DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, {         \
2112     /* The partial specialization. */                                          \
2113     TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));   \
2114     /* The args that remains unspecialized. */                                 \
2115     TRY_TO(TraverseTemplateArgumentLocsHelper(                                 \
2116         D->getTemplateArgsAsWritten()->getTemplateArgs(),                      \
2117         D->getTemplateArgsAsWritten()->NumTemplateArgs));                      \
2118                                                                                \
2119     /* Don't need the *TemplatePartialSpecializationHelper, even               \
2120        though that's our parent class -- we already visit all the              \
2121        template args here. */                                                  \
2122     TRY_TO(Traverse##DECLKIND##Helper(D));                                     \
2123                                                                                \
2124     /* Instantiations will have been visited with the primary template. */     \
2125   })
2126 
2127 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
2128 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
2129 
2130 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
2131 
2132 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
2133   // Like UnresolvedUsingTypenameDecl, but without the 'typename':
2134   //    template <class T> Class A : public Base<T> { using Base<T>::foo; };
2135   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
2136   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
2137 })
2138 
2139 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
2140 
2141 template <typename Derived>
2142 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
2143   TRY_TO(TraverseDeclTemplateParameterLists(D));
2144   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
2145   if (D->getTypeSourceInfo())
2146     TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
2147   else
2148     TRY_TO(TraverseType(D->getType()));
2149   return true;
2150 }
2151 
2152 DEF_TRAVERSE_DECL(DecompositionDecl, {
2153   TRY_TO(TraverseVarHelper(D));
2154   for (auto *Binding : D->bindings()) {
2155     TRY_TO(TraverseDecl(Binding));
2156   }
2157 })
2158 
2159 DEF_TRAVERSE_DECL(BindingDecl, {
2160   if (getDerived().shouldVisitImplicitCode()) {
2161     TRY_TO(TraverseStmt(D->getBinding()));
2162     if (const auto HoldingVar = D->getHoldingVar())
2163       TRY_TO(TraverseDecl(HoldingVar));
2164   }
2165 })
2166 
2167 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
2168 
2169 DEF_TRAVERSE_DECL(MSGuidDecl, {})
2170 DEF_TRAVERSE_DECL(UnnamedGlobalConstantDecl, {})
2171 
2172 DEF_TRAVERSE_DECL(TemplateParamObjectDecl, {})
2173 
2174 DEF_TRAVERSE_DECL(FieldDecl, {
2175   TRY_TO(TraverseDeclaratorHelper(D));
2176   if (D->isBitField())
2177     TRY_TO(TraverseStmt(D->getBitWidth()));
2178   if (D->hasInClassInitializer())
2179     TRY_TO(TraverseStmt(D->getInClassInitializer()));
2180 })
2181 
2182 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
2183   TRY_TO(TraverseDeclaratorHelper(D));
2184   if (D->isBitField())
2185     TRY_TO(TraverseStmt(D->getBitWidth()));
2186   // FIXME: implement the rest.
2187 })
2188 
2189 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
2190   TRY_TO(TraverseDeclaratorHelper(D));
2191   if (D->isBitField())
2192     TRY_TO(TraverseStmt(D->getBitWidth()));
2193   // FIXME: implement the rest.
2194 })
2195 
2196 template <typename Derived>
2197 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
2198   TRY_TO(TraverseDeclTemplateParameterLists(D));
2199   TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
2200   TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
2201 
2202   // If we're an explicit template specialization, iterate over the
2203   // template args that were explicitly specified.  If we were doing
2204   // this in typing order, we'd do it between the return type and
2205   // the function args, but both are handled by the FunctionTypeLoc
2206   // above, so we have to choose one side.  I've decided to do before.
2207   if (const FunctionTemplateSpecializationInfo *FTSI =
2208           D->getTemplateSpecializationInfo()) {
2209     if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
2210         FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
2211       // A specialization might not have explicit template arguments if it has
2212       // a templated return type and concrete arguments.
2213       if (const ASTTemplateArgumentListInfo *TALI =
2214               FTSI->TemplateArgumentsAsWritten) {
2215         TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
2216                                                   TALI->NumTemplateArgs));
2217       }
2218     }
2219   } else if (const DependentFunctionTemplateSpecializationInfo *DFSI =
2220                  D->getDependentSpecializationInfo()) {
2221     if (const ASTTemplateArgumentListInfo *TALI =
2222             DFSI->TemplateArgumentsAsWritten) {
2223       TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
2224                                                 TALI->NumTemplateArgs));
2225     }
2226   }
2227 
2228   // Visit the function type itself, which can be either
2229   // FunctionNoProtoType or FunctionProtoType, or a typedef.  This
2230   // also covers the return type and the function parameters,
2231   // including exception specifications.
2232   if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
2233     TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
2234   } else if (getDerived().shouldVisitImplicitCode()) {
2235     // Visit parameter variable declarations of the implicit function
2236     // if the traverser is visiting implicit code. Parameter variable
2237     // declarations do not have valid TypeSourceInfo, so to visit them
2238     // we need to traverse the declarations explicitly.
2239     for (ParmVarDecl *Parameter : D->parameters()) {
2240       TRY_TO(TraverseDecl(Parameter));
2241     }
2242   }
2243 
2244   // Visit the trailing requires clause, if any.
2245   if (Expr *TrailingRequiresClause = D->getTrailingRequiresClause()) {
2246     TRY_TO(TraverseStmt(TrailingRequiresClause));
2247   }
2248 
2249   if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
2250     // Constructor initializers.
2251     for (auto *I : Ctor->inits()) {
2252       if (I->isWritten() || getDerived().shouldVisitImplicitCode())
2253         TRY_TO(TraverseConstructorInitializer(I));
2254     }
2255   }
2256 
2257   bool VisitBody =
2258       D->isThisDeclarationADefinition() &&
2259       // Don't visit the function body if the function definition is generated
2260       // by clang.
2261       (!D->isDefaulted() || getDerived().shouldVisitImplicitCode());
2262 
2263   if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
2264     if (const CXXRecordDecl *RD = MD->getParent()) {
2265       if (RD->isLambda() &&
2266           declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
2267         VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
2268       }
2269     }
2270   }
2271 
2272   if (VisitBody) {
2273     TRY_TO(TraverseStmt(D->getBody()));
2274     // Body may contain using declarations whose shadows are parented to the
2275     // FunctionDecl itself.
2276     for (auto *Child : D->decls()) {
2277       if (isa<UsingShadowDecl>(Child))
2278         TRY_TO(TraverseDecl(Child));
2279     }
2280   }
2281   return true;
2282 }
2283 
2284 DEF_TRAVERSE_DECL(FunctionDecl, {
2285   // We skip decls_begin/decls_end, which are already covered by
2286   // TraverseFunctionHelper().
2287   ShouldVisitChildren = false;
2288   ReturnValue = TraverseFunctionHelper(D);
2289 })
2290 
2291 DEF_TRAVERSE_DECL(CXXDeductionGuideDecl, {
2292   // We skip decls_begin/decls_end, which are already covered by
2293   // TraverseFunctionHelper().
2294   ShouldVisitChildren = false;
2295   ReturnValue = TraverseFunctionHelper(D);
2296 })
2297 
2298 DEF_TRAVERSE_DECL(CXXMethodDecl, {
2299   // We skip decls_begin/decls_end, which are already covered by
2300   // TraverseFunctionHelper().
2301   ShouldVisitChildren = false;
2302   ReturnValue = TraverseFunctionHelper(D);
2303 })
2304 
2305 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
2306   // We skip decls_begin/decls_end, which are already covered by
2307   // TraverseFunctionHelper().
2308   ShouldVisitChildren = false;
2309   ReturnValue = TraverseFunctionHelper(D);
2310 })
2311 
2312 // CXXConversionDecl is the declaration of a type conversion operator.
2313 // It's not a cast expression.
2314 DEF_TRAVERSE_DECL(CXXConversionDecl, {
2315   // We skip decls_begin/decls_end, which are already covered by
2316   // TraverseFunctionHelper().
2317   ShouldVisitChildren = false;
2318   ReturnValue = TraverseFunctionHelper(D);
2319 })
2320 
2321 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
2322   // We skip decls_begin/decls_end, which are already covered by
2323   // TraverseFunctionHelper().
2324   ShouldVisitChildren = false;
2325   ReturnValue = TraverseFunctionHelper(D);
2326 })
2327 
2328 template <typename Derived>
2329 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
2330   TRY_TO(TraverseDeclaratorHelper(D));
2331   // Default params are taken care of when we traverse the ParmVarDecl.
2332   if (!isa<ParmVarDecl>(D) &&
2333       (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
2334     TRY_TO(TraverseStmt(D->getInit()));
2335   return true;
2336 }
2337 
2338 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
2339 
2340 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
2341 
2342 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
2343   // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
2344   TRY_TO(TraverseDeclaratorHelper(D));
2345   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
2346     TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
2347 })
2348 
2349 DEF_TRAVERSE_DECL(ParmVarDecl, {
2350   TRY_TO(TraverseVarHelper(D));
2351 
2352   if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
2353       !D->hasUnparsedDefaultArg())
2354     TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
2355 
2356   if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
2357       !D->hasUnparsedDefaultArg())
2358     TRY_TO(TraverseStmt(D->getDefaultArg()));
2359 })
2360 
2361 DEF_TRAVERSE_DECL(RequiresExprBodyDecl, {})
2362 
2363 DEF_TRAVERSE_DECL(ImplicitConceptSpecializationDecl, {
2364   TRY_TO(TraverseTemplateArguments(D->getTemplateArguments()));
2365 })
2366 
2367 #undef DEF_TRAVERSE_DECL
2368 
2369 // ----------------- Stmt traversal -----------------
2370 //
2371 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
2372 // over the children defined in children() (every stmt defines these,
2373 // though sometimes the range is empty).  Each individual Traverse*
2374 // method only needs to worry about children other than those.  To see
2375 // what children() does for a given class, see, e.g.,
2376 //   http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
2377 
2378 // This macro makes available a variable S, the passed-in stmt.
2379 #define DEF_TRAVERSE_STMT(STMT, CODE)                                          \
2380   template <typename Derived>                                                  \
2381   bool RecursiveASTVisitor<Derived>::Traverse##STMT(                           \
2382       STMT *S, DataRecursionQueue *Queue) {                                    \
2383     bool ShouldVisitChildren = true;                                           \
2384     bool ReturnValue = true;                                                   \
2385     if (!getDerived().shouldTraversePostOrder())                               \
2386       TRY_TO(WalkUpFrom##STMT(S));                                             \
2387     { CODE; }                                                                  \
2388     if (ShouldVisitChildren) {                                                 \
2389       for (Stmt * SubStmt : getDerived().getStmtChildren(S)) {                 \
2390         TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);                              \
2391       }                                                                        \
2392     }                                                                          \
2393     /* Call WalkUpFrom if TRY_TO_TRAVERSE_OR_ENQUEUE_STMT has traversed the    \
2394      * children already. If TRY_TO_TRAVERSE_OR_ENQUEUE_STMT only enqueued the  \
2395      * children, PostVisitStmt will call WalkUpFrom after we are done visiting \
2396      * children. */                                                            \
2397     if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder()) {     \
2398       TRY_TO(WalkUpFrom##STMT(S));                                             \
2399     }                                                                          \
2400     return ReturnValue;                                                        \
2401   }
2402 
2403 DEF_TRAVERSE_STMT(GCCAsmStmt, {
2404   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
2405   for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
2406     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
2407   }
2408   for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
2409     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
2410   }
2411   for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
2412     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
2413   }
2414   // children() iterates over inputExpr and outputExpr.
2415 })
2416 
2417 DEF_TRAVERSE_STMT(
2418     MSAsmStmt,
2419     {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc.  Once
2420      // added this needs to be implemented.
2421     })
2422 
2423 DEF_TRAVERSE_STMT(CXXCatchStmt, {
2424   TRY_TO(TraverseDecl(S->getExceptionDecl()));
2425   // children() iterates over the handler block.
2426 })
2427 
2428 DEF_TRAVERSE_STMT(DeclStmt, {
2429   for (auto *I : S->decls()) {
2430     TRY_TO(TraverseDecl(I));
2431   }
2432   // Suppress the default iteration over children() by
2433   // returning.  Here's why: A DeclStmt looks like 'type var [=
2434   // initializer]'.  The decls above already traverse over the
2435   // initializers, so we don't have to do it again (which
2436   // children() would do).
2437   ShouldVisitChildren = false;
2438 })
2439 
2440 // These non-expr stmts (most of them), do not need any action except
2441 // iterating over the children.
2442 DEF_TRAVERSE_STMT(BreakStmt, {})
2443 DEF_TRAVERSE_STMT(CXXTryStmt, {})
2444 DEF_TRAVERSE_STMT(CaseStmt, {})
2445 DEF_TRAVERSE_STMT(CompoundStmt, {})
2446 DEF_TRAVERSE_STMT(ContinueStmt, {})
2447 DEF_TRAVERSE_STMT(DefaultStmt, {})
2448 DEF_TRAVERSE_STMT(DoStmt, {})
2449 DEF_TRAVERSE_STMT(ForStmt, {})
2450 DEF_TRAVERSE_STMT(GotoStmt, {})
2451 DEF_TRAVERSE_STMT(IfStmt, {})
2452 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
2453 DEF_TRAVERSE_STMT(LabelStmt, {})
2454 DEF_TRAVERSE_STMT(AttributedStmt, {})
2455 DEF_TRAVERSE_STMT(NullStmt, {})
2456 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
2457 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
2458 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
2459 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
2460 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
2461 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
2462 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
2463 
2464 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
2465   if (!getDerived().shouldVisitImplicitCode()) {
2466     if (S->getInit())
2467       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInit());
2468     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
2469     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
2470     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2471     // Visit everything else only if shouldVisitImplicitCode().
2472     ShouldVisitChildren = false;
2473   }
2474 })
2475 
2476 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
2477   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2478   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2479 })
2480 
2481 DEF_TRAVERSE_STMT(ReturnStmt, {})
2482 DEF_TRAVERSE_STMT(SwitchStmt, {})
2483 DEF_TRAVERSE_STMT(WhileStmt, {})
2484 
2485 DEF_TRAVERSE_STMT(ConstantExpr, {})
2486 
2487 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
2488   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2489   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2490   if (S->hasExplicitTemplateArgs()) {
2491     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2492                                               S->getNumTemplateArgs()));
2493   }
2494 })
2495 
2496 DEF_TRAVERSE_STMT(DeclRefExpr, {
2497   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2498   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2499   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2500                                             S->getNumTemplateArgs()));
2501 })
2502 
2503 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
2504   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2505   TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2506   if (S->hasExplicitTemplateArgs()) {
2507     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2508                                               S->getNumTemplateArgs()));
2509   }
2510 })
2511 
2512 DEF_TRAVERSE_STMT(MemberExpr, {
2513   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2514   TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2515   TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2516                                             S->getNumTemplateArgs()));
2517 })
2518 
2519 DEF_TRAVERSE_STMT(
2520     ImplicitCastExpr,
2521     {// We don't traverse the cast type, as it's not written in the
2522      // source code.
2523     })
2524 
2525 DEF_TRAVERSE_STMT(CStyleCastExpr, {
2526   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2527 })
2528 
2529 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
2530   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2531 })
2532 
2533 DEF_TRAVERSE_STMT(CXXAddrspaceCastExpr, {
2534   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2535 })
2536 
2537 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
2538   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2539 })
2540 
2541 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
2542   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2543 })
2544 
2545 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
2546   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2547 })
2548 
2549 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
2550   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2551 })
2552 
2553 DEF_TRAVERSE_STMT(BuiltinBitCastExpr, {
2554   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2555 })
2556 
2557 template <typename Derived>
2558 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
2559     InitListExpr *S, DataRecursionQueue *Queue) {
2560   if (S) {
2561     // Skip this if we traverse postorder. We will visit it later
2562     // in PostVisitStmt.
2563     if (!getDerived().shouldTraversePostOrder())
2564       TRY_TO(WalkUpFromInitListExpr(S));
2565 
2566     // All we need are the default actions.  FIXME: use a helper function.
2567     for (Stmt *SubStmt : S->children()) {
2568       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
2569     }
2570 
2571     if (!Queue && getDerived().shouldTraversePostOrder())
2572       TRY_TO(WalkUpFromInitListExpr(S));
2573   }
2574   return true;
2575 }
2576 
2577 template <typename Derived>
2578 bool RecursiveASTVisitor<Derived>::TraverseObjCProtocolLoc(
2579     ObjCProtocolLoc ProtocolLoc) {
2580   return true;
2581 }
2582 
2583 template <typename Derived>
2584 bool RecursiveASTVisitor<Derived>::TraverseConceptReference(
2585     ConceptReference *CR) {
2586   if (!getDerived().shouldTraversePostOrder())
2587     TRY_TO(VisitConceptReference(CR));
2588   TRY_TO(TraverseNestedNameSpecifierLoc(CR->getNestedNameSpecifierLoc()));
2589   TRY_TO(TraverseDeclarationNameInfo(CR->getConceptNameInfo()));
2590   if (CR->hasExplicitTemplateArgs())
2591     TRY_TO(TraverseTemplateArgumentLocsHelper(
2592         CR->getTemplateArgsAsWritten()->getTemplateArgs(),
2593         CR->getTemplateArgsAsWritten()->NumTemplateArgs));
2594   if (getDerived().shouldTraversePostOrder())
2595     TRY_TO(VisitConceptReference(CR));
2596   return true;
2597 }
2598 
2599 // If shouldVisitImplicitCode() returns false, this method traverses only the
2600 // syntactic form of InitListExpr.
2601 // If shouldVisitImplicitCode() return true, this method is called once for
2602 // each pair of syntactic and semantic InitListExpr, and it traverses the
2603 // subtrees defined by the two forms. This may cause some of the children to be
2604 // visited twice, if they appear both in the syntactic and the semantic form.
2605 //
2606 // There is no guarantee about which form \p S takes when this method is called.
2607 template <typename Derived>
2608 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(
2609     InitListExpr *S, DataRecursionQueue *Queue) {
2610   if (S->isSemanticForm() && S->isSyntacticForm()) {
2611     // `S` does not have alternative forms, traverse only once.
2612     TRY_TO(TraverseSynOrSemInitListExpr(S, Queue));
2613     return true;
2614   }
2615   TRY_TO(TraverseSynOrSemInitListExpr(
2616       S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
2617   if (getDerived().shouldVisitImplicitCode()) {
2618     // Only visit the semantic form if the clients are interested in implicit
2619     // compiler-generated.
2620     TRY_TO(TraverseSynOrSemInitListExpr(
2621         S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
2622   }
2623   return true;
2624 }
2625 
2626 // GenericSelectionExpr is a special case because the types and expressions
2627 // are interleaved.  We also need to watch out for null types (default
2628 // generic associations).
2629 DEF_TRAVERSE_STMT(GenericSelectionExpr, {
2630   if (S->isExprPredicate())
2631     TRY_TO(TraverseStmt(S->getControllingExpr()));
2632   else
2633     TRY_TO(TraverseTypeLoc(S->getControllingType()->getTypeLoc()));
2634 
2635   for (const GenericSelectionExpr::Association Assoc : S->associations()) {
2636     if (TypeSourceInfo *TSI = Assoc.getTypeSourceInfo())
2637       TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
2638     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Assoc.getAssociationExpr());
2639   }
2640   ShouldVisitChildren = false;
2641 })
2642 
2643 // PseudoObjectExpr is a special case because of the weirdness with
2644 // syntactic expressions and opaque values.
2645 DEF_TRAVERSE_STMT(PseudoObjectExpr, {
2646   TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
2647   for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2648                                             e = S->semantics_end();
2649        i != e; ++i) {
2650     Expr *sub = *i;
2651     if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2652       sub = OVE->getSourceExpr();
2653     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub);
2654   }
2655   ShouldVisitChildren = false;
2656 })
2657 
2658 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
2659   // This is called for code like 'return T()' where T is a built-in
2660   // (i.e. non-class) type.
2661   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2662 })
2663 
2664 DEF_TRAVERSE_STMT(CXXNewExpr, {
2665   // The child-iterator will pick up the other arguments.
2666   TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
2667 })
2668 
2669 DEF_TRAVERSE_STMT(OffsetOfExpr, {
2670   // The child-iterator will pick up the expression representing
2671   // the field.
2672   // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2673   // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2674   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2675 })
2676 
2677 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2678   // The child-iterator will pick up the arg if it's an expression,
2679   // but not if it's a type.
2680   if (S->isArgumentType())
2681     TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2682 })
2683 
2684 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2685   // The child-iterator will pick up the arg if it's an expression,
2686   // but not if it's a type.
2687   if (S->isTypeOperand())
2688     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2689 })
2690 
2691 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2692   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2693 })
2694 
2695 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
2696 
2697 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2698   // The child-iterator will pick up the arg if it's an expression,
2699   // but not if it's a type.
2700   if (S->isTypeOperand())
2701     TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2702 })
2703 
2704 DEF_TRAVERSE_STMT(TypeTraitExpr, {
2705   for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2706     TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2707 })
2708 
2709 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2710   TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2711 })
2712 
2713 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2714                   { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
2715 
2716 DEF_TRAVERSE_STMT(VAArgExpr, {
2717   // The child-iterator will pick up the expression argument.
2718   TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2719 })
2720 
2721 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2722   // This is called for code like 'return T()' where T is a class type.
2723   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2724 })
2725 
2726 // Walk only the visible parts of lambda expressions.
2727 DEF_TRAVERSE_STMT(LambdaExpr, {
2728   // Visit the capture list.
2729   for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
2730     const LambdaCapture *C = S->capture_begin() + I;
2731     if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
2732       TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
2733     }
2734   }
2735 
2736   if (getDerived().shouldVisitImplicitCode()) {
2737     // The implicit model is simple: everything else is in the lambda class.
2738     TRY_TO(TraverseDecl(S->getLambdaClass()));
2739   } else {
2740     // We need to poke around to find the bits that might be explicitly written.
2741     TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2742     FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>();
2743 
2744     TRY_TO(TraverseTemplateParameterListHelper(S->getTemplateParameterList()));
2745     if (S->hasExplicitParameters()) {
2746       // Visit parameters.
2747       for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)
2748         TRY_TO(TraverseDecl(Proto.getParam(I)));
2749     }
2750 
2751     auto *T = Proto.getTypePtr();
2752     for (const auto &E : T->exceptions())
2753       TRY_TO(TraverseType(E));
2754 
2755     if (Expr *NE = T->getNoexceptExpr())
2756       TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
2757 
2758     if (S->hasExplicitResultType())
2759       TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
2760     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getTrailingRequiresClause());
2761 
2762     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2763   }
2764   ShouldVisitChildren = false;
2765 })
2766 
2767 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2768   // This is called for code like 'T()', where T is a template argument.
2769   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2770 })
2771 
2772 // These expressions all might take explicit template arguments.
2773 // We traverse those if so.  FIXME: implement these.
2774 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2775 DEF_TRAVERSE_STMT(CallExpr, {})
2776 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
2777 
2778 // These exprs (most of them), do not need any action except iterating
2779 // over the children.
2780 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2781 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
2782 DEF_TRAVERSE_STMT(MatrixSubscriptExpr, {})
2783 DEF_TRAVERSE_STMT(ArraySectionExpr, {})
2784 DEF_TRAVERSE_STMT(OMPArrayShapingExpr, {})
2785 DEF_TRAVERSE_STMT(OMPIteratorExpr, {})
2786 
2787 DEF_TRAVERSE_STMT(BlockExpr, {
2788   TRY_TO(TraverseDecl(S->getBlockDecl()));
2789   return true; // no child statements to loop through.
2790 })
2791 
2792 DEF_TRAVERSE_STMT(ChooseExpr, {})
2793 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2794   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2795 })
2796 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2797 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2798 
2799 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
2800   if (getDerived().shouldVisitImplicitCode())
2801     TRY_TO(TraverseStmt(S->getExpr()));
2802 })
2803 
2804 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {
2805   if (getDerived().shouldVisitImplicitCode())
2806     TRY_TO(TraverseStmt(S->getExpr()));
2807 })
2808 
2809 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2810 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2811 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
2812 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2813 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
2814 
2815 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2816   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2817   if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2818     TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2819   if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2820     TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2821 })
2822 
2823 DEF_TRAVERSE_STMT(CXXThisExpr, {})
2824 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2825 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2826 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2827 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
2828 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2829 DEF_TRAVERSE_STMT(GNUNullExpr, {})
2830 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2831 DEF_TRAVERSE_STMT(NoInitExpr, {})
2832 DEF_TRAVERSE_STMT(ArrayInitLoopExpr, {
2833   // FIXME: The source expression of the OVE should be listed as
2834   // a child of the ArrayInitLoopExpr.
2835   if (OpaqueValueExpr *OVE = S->getCommonExpr())
2836     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr());
2837 })
2838 DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {})
2839 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
2840 
2841 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2842   if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2843     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2844 })
2845 
2846 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2847 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
2848 
2849 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2850   if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2851     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2852 })
2853 
2854 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {
2855   if (S->isClassReceiver()) {
2856     ObjCInterfaceDecl *IDecl = S->getClassReceiver();
2857     QualType Type = IDecl->getASTContext().getObjCInterfaceType(IDecl);
2858     ObjCInterfaceLocInfo Data;
2859     Data.NameLoc = S->getReceiverLocation();
2860     Data.NameEndLoc = Data.NameLoc;
2861     TRY_TO(TraverseTypeLoc(TypeLoc(Type, &Data)));
2862   }
2863 })
2864 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2865 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2866 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2867 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
2868 
2869 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2870   TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2871 })
2872 
2873 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
2874 DEF_TRAVERSE_STMT(ParenExpr, {})
2875 DEF_TRAVERSE_STMT(ParenListExpr, {})
2876 DEF_TRAVERSE_STMT(SYCLUniqueStableNameExpr, {
2877   TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2878 })
2879 DEF_TRAVERSE_STMT(OpenACCAsteriskSizeExpr, {})
2880 DEF_TRAVERSE_STMT(PredefinedExpr, {})
2881 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2882 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2883 DEF_TRAVERSE_STMT(StmtExpr, {})
2884 DEF_TRAVERSE_STMT(SourceLocExpr, {})
2885 DEF_TRAVERSE_STMT(EmbedExpr, {
2886   for (IntegerLiteral *IL : S->underlying_data_elements()) {
2887     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(IL);
2888   }
2889 })
2890 
2891 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2892   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2893   if (S->hasExplicitTemplateArgs()) {
2894     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2895                                               S->getNumTemplateArgs()));
2896   }
2897 })
2898 
2899 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2900   TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2901   if (S->hasExplicitTemplateArgs()) {
2902     TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2903                                               S->getNumTemplateArgs()));
2904   }
2905 })
2906 
2907 DEF_TRAVERSE_STMT(SEHTryStmt, {})
2908 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2909 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
2910 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
2911 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2912 
2913 DEF_TRAVERSE_STMT(SYCLKernelCallStmt, {
2914   if (getDerived().shouldVisitImplicitCode()) {
2915     TRY_TO(TraverseStmt(S->getOriginalStmt()));
2916     TRY_TO(TraverseDecl(S->getOutlinedFunctionDecl()));
2917     ShouldVisitChildren = false;
2918   }
2919 })
2920 
2921 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2922 DEF_TRAVERSE_STMT(CXXRewrittenBinaryOperator, {
2923   if (!getDerived().shouldVisitImplicitCode()) {
2924     CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
2925         S->getDecomposedForm();
2926     TRY_TO(TraverseStmt(const_cast<Expr*>(Decomposed.LHS)));
2927     TRY_TO(TraverseStmt(const_cast<Expr*>(Decomposed.RHS)));
2928     ShouldVisitChildren = false;
2929   }
2930 })
2931 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
2932 DEF_TRAVERSE_STMT(TypoExpr, {})
2933 DEF_TRAVERSE_STMT(RecoveryExpr, {})
2934 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
2935 
2936 // These operators (all of them) do not need any action except
2937 // iterating over the children.
2938 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2939 DEF_TRAVERSE_STMT(ConditionalOperator, {})
2940 DEF_TRAVERSE_STMT(UnaryOperator, {})
2941 DEF_TRAVERSE_STMT(BinaryOperator, {})
2942 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2943 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2944 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2945 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2946 DEF_TRAVERSE_STMT(PackIndexingExpr, {})
2947 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2948 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2949 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2950 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
2951 DEF_TRAVERSE_STMT(AtomicExpr, {})
2952 DEF_TRAVERSE_STMT(CXXParenListInitExpr, {})
2953 
2954 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {
2955   if (S->getLifetimeExtendedTemporaryDecl()) {
2956     TRY_TO(TraverseLifetimeExtendedTemporaryDecl(
2957         S->getLifetimeExtendedTemporaryDecl()));
2958     ShouldVisitChildren = false;
2959   }
2960 })
2961 // For coroutines expressions, traverse either the operand
2962 // as written or the implied calls, depending on what the
2963 // derived class requests.
2964 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
2965   if (!getDerived().shouldVisitImplicitCode()) {
2966     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2967     ShouldVisitChildren = false;
2968   }
2969 })
2970 DEF_TRAVERSE_STMT(CoreturnStmt, {
2971   if (!getDerived().shouldVisitImplicitCode()) {
2972     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2973     ShouldVisitChildren = false;
2974   }
2975 })
2976 DEF_TRAVERSE_STMT(CoawaitExpr, {
2977   if (!getDerived().shouldVisitImplicitCode()) {
2978     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2979     ShouldVisitChildren = false;
2980   }
2981 })
2982 DEF_TRAVERSE_STMT(DependentCoawaitExpr, {
2983   if (!getDerived().shouldVisitImplicitCode()) {
2984     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2985     ShouldVisitChildren = false;
2986   }
2987 })
2988 DEF_TRAVERSE_STMT(CoyieldExpr, {
2989   if (!getDerived().shouldVisitImplicitCode()) {
2990     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2991     ShouldVisitChildren = false;
2992   }
2993 })
2994 
2995 DEF_TRAVERSE_STMT(ConceptSpecializationExpr, {
2996   TRY_TO(TraverseConceptReference(S->getConceptReference()));
2997 })
2998 
2999 DEF_TRAVERSE_STMT(RequiresExpr, {
3000   TRY_TO(TraverseDecl(S->getBody()));
3001   for (ParmVarDecl *Parm : S->getLocalParameters())
3002     TRY_TO(TraverseDecl(Parm));
3003   for (concepts::Requirement *Req : S->getRequirements())
3004     TRY_TO(TraverseConceptRequirement(Req));
3005 })
3006 
3007 // These literals (all of them) do not need any action.
3008 DEF_TRAVERSE_STMT(IntegerLiteral, {})
3009 DEF_TRAVERSE_STMT(FixedPointLiteral, {})
3010 DEF_TRAVERSE_STMT(CharacterLiteral, {})
3011 DEF_TRAVERSE_STMT(FloatingLiteral, {})
3012 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
3013 DEF_TRAVERSE_STMT(StringLiteral, {})
3014 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
3015 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
3016 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
3017 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
3018 
3019 // Traverse OpenCL: AsType, Convert.
3020 DEF_TRAVERSE_STMT(AsTypeExpr, {})
3021 
3022 // OpenMP directives.
3023 template <typename Derived>
3024 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
3025     OMPExecutableDirective *S) {
3026   for (auto *C : S->clauses()) {
3027     TRY_TO(TraverseOMPClause(C));
3028   }
3029   return true;
3030 }
3031 
3032 DEF_TRAVERSE_STMT(OMPCanonicalLoop, {
3033   if (!getDerived().shouldVisitImplicitCode()) {
3034     // Visit only the syntactical loop.
3035     TRY_TO(TraverseStmt(S->getLoopStmt()));
3036     ShouldVisitChildren = false;
3037   }
3038 })
3039 
3040 template <typename Derived>
3041 bool
3042 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
3043   return TraverseOMPExecutableDirective(S);
3044 }
3045 
3046 DEF_TRAVERSE_STMT(OMPMetaDirective,
3047                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3048 
3049 DEF_TRAVERSE_STMT(OMPParallelDirective,
3050                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3051 
3052 DEF_TRAVERSE_STMT(OMPSimdDirective,
3053                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3054 
3055 DEF_TRAVERSE_STMT(OMPTileDirective,
3056                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3057 
3058 DEF_TRAVERSE_STMT(OMPUnrollDirective,
3059                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3060 
3061 DEF_TRAVERSE_STMT(OMPReverseDirective,
3062                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3063 
3064 DEF_TRAVERSE_STMT(OMPInterchangeDirective,
3065                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3066 
3067 DEF_TRAVERSE_STMT(OMPForDirective,
3068                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3069 
3070 DEF_TRAVERSE_STMT(OMPForSimdDirective,
3071                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3072 
3073 DEF_TRAVERSE_STMT(OMPSectionsDirective,
3074                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3075 
3076 DEF_TRAVERSE_STMT(OMPSectionDirective,
3077                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3078 
3079 DEF_TRAVERSE_STMT(OMPScopeDirective,
3080                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3081 
3082 DEF_TRAVERSE_STMT(OMPSingleDirective,
3083                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3084 
3085 DEF_TRAVERSE_STMT(OMPMasterDirective,
3086                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3087 
3088 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
3089   TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
3090   TRY_TO(TraverseOMPExecutableDirective(S));
3091 })
3092 
3093 DEF_TRAVERSE_STMT(OMPParallelForDirective,
3094                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3095 
3096 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
3097                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3098 
3099 DEF_TRAVERSE_STMT(OMPParallelMasterDirective,
3100                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3101 
3102 DEF_TRAVERSE_STMT(OMPParallelMaskedDirective,
3103                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3104 
3105 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
3106                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3107 
3108 DEF_TRAVERSE_STMT(OMPTaskDirective,
3109                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3110 
3111 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
3112                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3113 
3114 DEF_TRAVERSE_STMT(OMPBarrierDirective,
3115                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3116 
3117 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
3118                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3119 
3120 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
3121                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3122 
3123 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
3124                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3125 
3126 DEF_TRAVERSE_STMT(OMPCancelDirective,
3127                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3128 
3129 DEF_TRAVERSE_STMT(OMPFlushDirective,
3130                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3131 
3132 DEF_TRAVERSE_STMT(OMPDepobjDirective,
3133                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3134 
3135 DEF_TRAVERSE_STMT(OMPScanDirective,
3136                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3137 
3138 DEF_TRAVERSE_STMT(OMPOrderedDirective,
3139                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3140 
3141 DEF_TRAVERSE_STMT(OMPAtomicDirective,
3142                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3143 
3144 DEF_TRAVERSE_STMT(OMPTargetDirective,
3145                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3146 
3147 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
3148                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3149 
3150 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
3151                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3152 
3153 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
3154                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3155 
3156 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
3157                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3158 
3159 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
3160                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3161 
3162 DEF_TRAVERSE_STMT(OMPTeamsDirective,
3163                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3164 
3165 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
3166                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3167 
3168 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
3169                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3170 
3171 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
3172                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3173 
3174 DEF_TRAVERSE_STMT(OMPMasterTaskLoopDirective,
3175                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3176 
3177 DEF_TRAVERSE_STMT(OMPMasterTaskLoopSimdDirective,
3178                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3179 
3180 DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopDirective,
3181                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3182 
3183 DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopSimdDirective,
3184                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3185 
3186 DEF_TRAVERSE_STMT(OMPMaskedTaskLoopDirective,
3187                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3188 
3189 DEF_TRAVERSE_STMT(OMPMaskedTaskLoopSimdDirective,
3190                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3191 
3192 DEF_TRAVERSE_STMT(OMPParallelMaskedTaskLoopDirective,
3193                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3194 
3195 DEF_TRAVERSE_STMT(OMPParallelMaskedTaskLoopSimdDirective,
3196                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3197 
3198 DEF_TRAVERSE_STMT(OMPDistributeDirective,
3199                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3200 
3201 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
3202                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3203 
3204 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
3205                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3206 
3207 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
3208                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3209 
3210 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
3211                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3212 
3213 DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
3214                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3215 
3216 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
3217                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3218 
3219 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
3220                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3221 
3222 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
3223                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3224 
3225 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
3226                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3227 
3228 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
3229                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3230 
3231 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
3232                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3233 
3234 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
3235                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3236 
3237 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective,
3238                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3239 
3240 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective,
3241                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3242 
3243 DEF_TRAVERSE_STMT(OMPInteropDirective,
3244                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3245 
3246 DEF_TRAVERSE_STMT(OMPDispatchDirective,
3247                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3248 
3249 DEF_TRAVERSE_STMT(OMPMaskedDirective,
3250                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3251 
3252 DEF_TRAVERSE_STMT(OMPGenericLoopDirective,
3253                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3254 
3255 DEF_TRAVERSE_STMT(OMPTeamsGenericLoopDirective,
3256                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3257 
3258 DEF_TRAVERSE_STMT(OMPTargetTeamsGenericLoopDirective,
3259                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3260 
3261 DEF_TRAVERSE_STMT(OMPParallelGenericLoopDirective,
3262                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3263 
3264 DEF_TRAVERSE_STMT(OMPTargetParallelGenericLoopDirective,
3265                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3266 
3267 DEF_TRAVERSE_STMT(OMPAssumeDirective,
3268                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3269 
3270 DEF_TRAVERSE_STMT(OMPErrorDirective,
3271                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3272 
3273 // OpenMP clauses.
3274 template <typename Derived>
3275 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
3276   if (!C)
3277     return true;
3278   switch (C->getClauseKind()) {
3279 #define GEN_CLANG_CLAUSE_CLASS
3280 #define CLAUSE_CLASS(Enum, Str, Class)                                         \
3281   case llvm::omp::Clause::Enum:                                                \
3282     TRY_TO(Visit##Class(static_cast<Class *>(C)));                             \
3283     break;
3284 #define CLAUSE_NO_CLASS(Enum, Str)                                             \
3285   case llvm::omp::Clause::Enum:                                                \
3286     break;
3287 #include "llvm/Frontend/OpenMP/OMP.inc"
3288   }
3289   return true;
3290 }
3291 
3292 template <typename Derived>
3293 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
3294     OMPClauseWithPreInit *Node) {
3295   TRY_TO(TraverseStmt(Node->getPreInitStmt()));
3296   return true;
3297 }
3298 
3299 template <typename Derived>
3300 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
3301     OMPClauseWithPostUpdate *Node) {
3302   TRY_TO(VisitOMPClauseWithPreInit(Node));
3303   TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
3304   return true;
3305 }
3306 
3307 template <typename Derived>
3308 bool RecursiveASTVisitor<Derived>::VisitOMPAllocatorClause(
3309     OMPAllocatorClause *C) {
3310   TRY_TO(TraverseStmt(C->getAllocator()));
3311   return true;
3312 }
3313 
3314 template <typename Derived>
3315 bool RecursiveASTVisitor<Derived>::VisitOMPAllocateClause(OMPAllocateClause *C) {
3316   TRY_TO(TraverseStmt(C->getAllocator()));
3317   TRY_TO(VisitOMPClauseList(C));
3318   return true;
3319 }
3320 
3321 template <typename Derived>
3322 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
3323   TRY_TO(VisitOMPClauseWithPreInit(C));
3324   TRY_TO(TraverseStmt(C->getCondition()));
3325   return true;
3326 }
3327 
3328 template <typename Derived>
3329 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
3330   TRY_TO(VisitOMPClauseWithPreInit(C));
3331   TRY_TO(TraverseStmt(C->getCondition()));
3332   return true;
3333 }
3334 
3335 template <typename Derived>
3336 bool
3337 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
3338   TRY_TO(VisitOMPClauseWithPreInit(C));
3339   TRY_TO(TraverseStmt(C->getNumThreads()));
3340   return true;
3341 }
3342 
3343 template <typename Derived>
3344 bool RecursiveASTVisitor<Derived>::VisitOMPAlignClause(OMPAlignClause *C) {
3345   TRY_TO(TraverseStmt(C->getAlignment()));
3346   return true;
3347 }
3348 
3349 template <typename Derived>
3350 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
3351   TRY_TO(TraverseStmt(C->getSafelen()));
3352   return true;
3353 }
3354 
3355 template <typename Derived>
3356 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
3357   TRY_TO(TraverseStmt(C->getSimdlen()));
3358   return true;
3359 }
3360 
3361 template <typename Derived>
3362 bool RecursiveASTVisitor<Derived>::VisitOMPSizesClause(OMPSizesClause *C) {
3363   for (Expr *E : C->getSizesRefs())
3364     TRY_TO(TraverseStmt(E));
3365   return true;
3366 }
3367 
3368 template <typename Derived>
3369 bool RecursiveASTVisitor<Derived>::VisitOMPPermutationClause(
3370     OMPPermutationClause *C) {
3371   for (Expr *E : C->getArgsRefs())
3372     TRY_TO(TraverseStmt(E));
3373   return true;
3374 }
3375 
3376 template <typename Derived>
3377 bool RecursiveASTVisitor<Derived>::VisitOMPFullClause(OMPFullClause *C) {
3378   return true;
3379 }
3380 
3381 template <typename Derived>
3382 bool RecursiveASTVisitor<Derived>::VisitOMPPartialClause(OMPPartialClause *C) {
3383   TRY_TO(TraverseStmt(C->getFactor()));
3384   return true;
3385 }
3386 
3387 template <typename Derived>
3388 bool
3389 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
3390   TRY_TO(TraverseStmt(C->getNumForLoops()));
3391   return true;
3392 }
3393 
3394 template <typename Derived>
3395 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
3396   return true;
3397 }
3398 
3399 template <typename Derived>
3400 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
3401   return true;
3402 }
3403 
3404 template <typename Derived>
3405 bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedAddressClause(
3406     OMPUnifiedAddressClause *) {
3407   return true;
3408 }
3409 
3410 template <typename Derived>
3411 bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedSharedMemoryClause(
3412     OMPUnifiedSharedMemoryClause *) {
3413   return true;
3414 }
3415 
3416 template <typename Derived>
3417 bool RecursiveASTVisitor<Derived>::VisitOMPReverseOffloadClause(
3418     OMPReverseOffloadClause *) {
3419   return true;
3420 }
3421 
3422 template <typename Derived>
3423 bool RecursiveASTVisitor<Derived>::VisitOMPDynamicAllocatorsClause(
3424     OMPDynamicAllocatorsClause *) {
3425   return true;
3426 }
3427 
3428 template <typename Derived>
3429 bool RecursiveASTVisitor<Derived>::VisitOMPAtomicDefaultMemOrderClause(
3430     OMPAtomicDefaultMemOrderClause *) {
3431   return true;
3432 }
3433 
3434 template <typename Derived>
3435 bool RecursiveASTVisitor<Derived>::VisitOMPAtClause(OMPAtClause *) {
3436   return true;
3437 }
3438 
3439 template <typename Derived>
3440 bool RecursiveASTVisitor<Derived>::VisitOMPSeverityClause(OMPSeverityClause *) {
3441   return true;
3442 }
3443 
3444 template <typename Derived>
3445 bool RecursiveASTVisitor<Derived>::VisitOMPMessageClause(OMPMessageClause *C) {
3446   TRY_TO(TraverseStmt(C->getMessageString()));
3447   return true;
3448 }
3449 
3450 template <typename Derived>
3451 bool
3452 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
3453   TRY_TO(VisitOMPClauseWithPreInit(C));
3454   TRY_TO(TraverseStmt(C->getChunkSize()));
3455   return true;
3456 }
3457 
3458 template <typename Derived>
3459 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
3460   TRY_TO(TraverseStmt(C->getNumForLoops()));
3461   return true;
3462 }
3463 
3464 template <typename Derived>
3465 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
3466   return true;
3467 }
3468 
3469 template <typename Derived>
3470 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
3471   return true;
3472 }
3473 
3474 template <typename Derived>
3475 bool
3476 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
3477   return true;
3478 }
3479 
3480 template <typename Derived>
3481 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
3482   return true;
3483 }
3484 
3485 template <typename Derived>
3486 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
3487   return true;
3488 }
3489 
3490 template <typename Derived>
3491 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
3492   return true;
3493 }
3494 
3495 template <typename Derived>
3496 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
3497   return true;
3498 }
3499 
3500 template <typename Derived>
3501 bool RecursiveASTVisitor<Derived>::VisitOMPCompareClause(OMPCompareClause *) {
3502   return true;
3503 }
3504 
3505 template <typename Derived>
3506 bool RecursiveASTVisitor<Derived>::VisitOMPFailClause(OMPFailClause *) {
3507   return true;
3508 }
3509 
3510 template <typename Derived>
3511 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
3512   return true;
3513 }
3514 
3515 template <typename Derived>
3516 bool RecursiveASTVisitor<Derived>::VisitOMPAcqRelClause(OMPAcqRelClause *) {
3517   return true;
3518 }
3519 
3520 template <typename Derived>
3521 bool RecursiveASTVisitor<Derived>::VisitOMPAbsentClause(OMPAbsentClause *) {
3522   return true;
3523 }
3524 
3525 template <typename Derived>
3526 bool RecursiveASTVisitor<Derived>::VisitOMPHoldsClause(OMPHoldsClause *) {
3527   return true;
3528 }
3529 
3530 template <typename Derived>
3531 bool RecursiveASTVisitor<Derived>::VisitOMPContainsClause(OMPContainsClause *) {
3532   return true;
3533 }
3534 
3535 template <typename Derived>
3536 bool RecursiveASTVisitor<Derived>::VisitOMPNoOpenMPClause(OMPNoOpenMPClause *) {
3537   return true;
3538 }
3539 
3540 template <typename Derived>
3541 bool RecursiveASTVisitor<Derived>::VisitOMPNoOpenMPRoutinesClause(
3542     OMPNoOpenMPRoutinesClause *) {
3543   return true;
3544 }
3545 
3546 template <typename Derived>
3547 bool RecursiveASTVisitor<Derived>::VisitOMPNoParallelismClause(
3548     OMPNoParallelismClause *) {
3549   return true;
3550 }
3551 
3552 template <typename Derived>
3553 bool RecursiveASTVisitor<Derived>::VisitOMPAcquireClause(OMPAcquireClause *) {
3554   return true;
3555 }
3556 
3557 template <typename Derived>
3558 bool RecursiveASTVisitor<Derived>::VisitOMPReleaseClause(OMPReleaseClause *) {
3559   return true;
3560 }
3561 
3562 template <typename Derived>
3563 bool RecursiveASTVisitor<Derived>::VisitOMPRelaxedClause(OMPRelaxedClause *) {
3564   return true;
3565 }
3566 
3567 template <typename Derived>
3568 bool RecursiveASTVisitor<Derived>::VisitOMPWeakClause(OMPWeakClause *) {
3569   return true;
3570 }
3571 
3572 template <typename Derived>
3573 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
3574   return true;
3575 }
3576 
3577 template <typename Derived>
3578 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
3579   return true;
3580 }
3581 
3582 template <typename Derived>
3583 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
3584   return true;
3585 }
3586 
3587 template <typename Derived>
3588 bool RecursiveASTVisitor<Derived>::VisitOMPInitClause(OMPInitClause *C) {
3589   TRY_TO(VisitOMPClauseList(C));
3590   return true;
3591 }
3592 
3593 template <typename Derived>
3594 bool RecursiveASTVisitor<Derived>::VisitOMPUseClause(OMPUseClause *C) {
3595   TRY_TO(TraverseStmt(C->getInteropVar()));
3596   return true;
3597 }
3598 
3599 template <typename Derived>
3600 bool RecursiveASTVisitor<Derived>::VisitOMPDestroyClause(OMPDestroyClause *C) {
3601   TRY_TO(TraverseStmt(C->getInteropVar()));
3602   return true;
3603 }
3604 
3605 template <typename Derived>
3606 bool RecursiveASTVisitor<Derived>::VisitOMPNovariantsClause(
3607     OMPNovariantsClause *C) {
3608   TRY_TO(VisitOMPClauseWithPreInit(C));
3609   TRY_TO(TraverseStmt(C->getCondition()));
3610   return true;
3611 }
3612 
3613 template <typename Derived>
3614 bool RecursiveASTVisitor<Derived>::VisitOMPNocontextClause(
3615     OMPNocontextClause *C) {
3616   TRY_TO(VisitOMPClauseWithPreInit(C));
3617   TRY_TO(TraverseStmt(C->getCondition()));
3618   return true;
3619 }
3620 
3621 template <typename Derived>
3622 template <typename T>
3623 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
3624   for (auto *E : Node->varlist()) {
3625     TRY_TO(TraverseStmt(E));
3626   }
3627   return true;
3628 }
3629 
3630 template <typename Derived>
3631 bool RecursiveASTVisitor<Derived>::VisitOMPInclusiveClause(
3632     OMPInclusiveClause *C) {
3633   TRY_TO(VisitOMPClauseList(C));
3634   return true;
3635 }
3636 
3637 template <typename Derived>
3638 bool RecursiveASTVisitor<Derived>::VisitOMPExclusiveClause(
3639     OMPExclusiveClause *C) {
3640   TRY_TO(VisitOMPClauseList(C));
3641   return true;
3642 }
3643 
3644 template <typename Derived>
3645 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
3646   TRY_TO(VisitOMPClauseList(C));
3647   for (auto *E : C->private_copies()) {
3648     TRY_TO(TraverseStmt(E));
3649   }
3650   return true;
3651 }
3652 
3653 template <typename Derived>
3654 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
3655     OMPFirstprivateClause *C) {
3656   TRY_TO(VisitOMPClauseList(C));
3657   TRY_TO(VisitOMPClauseWithPreInit(C));
3658   for (auto *E : C->private_copies()) {
3659     TRY_TO(TraverseStmt(E));
3660   }
3661   for (auto *E : C->inits()) {
3662     TRY_TO(TraverseStmt(E));
3663   }
3664   return true;
3665 }
3666 
3667 template <typename Derived>
3668 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
3669     OMPLastprivateClause *C) {
3670   TRY_TO(VisitOMPClauseList(C));
3671   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3672   for (auto *E : C->private_copies()) {
3673     TRY_TO(TraverseStmt(E));
3674   }
3675   for (auto *E : C->source_exprs()) {
3676     TRY_TO(TraverseStmt(E));
3677   }
3678   for (auto *E : C->destination_exprs()) {
3679     TRY_TO(TraverseStmt(E));
3680   }
3681   for (auto *E : C->assignment_ops()) {
3682     TRY_TO(TraverseStmt(E));
3683   }
3684   return true;
3685 }
3686 
3687 template <typename Derived>
3688 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
3689   TRY_TO(VisitOMPClauseList(C));
3690   return true;
3691 }
3692 
3693 template <typename Derived>
3694 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
3695   TRY_TO(TraverseStmt(C->getStep()));
3696   TRY_TO(TraverseStmt(C->getCalcStep()));
3697   TRY_TO(VisitOMPClauseList(C));
3698   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3699   for (auto *E : C->privates()) {
3700     TRY_TO(TraverseStmt(E));
3701   }
3702   for (auto *E : C->inits()) {
3703     TRY_TO(TraverseStmt(E));
3704   }
3705   for (auto *E : C->updates()) {
3706     TRY_TO(TraverseStmt(E));
3707   }
3708   for (auto *E : C->finals()) {
3709     TRY_TO(TraverseStmt(E));
3710   }
3711   return true;
3712 }
3713 
3714 template <typename Derived>
3715 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
3716   TRY_TO(TraverseStmt(C->getAlignment()));
3717   TRY_TO(VisitOMPClauseList(C));
3718   return true;
3719 }
3720 
3721 template <typename Derived>
3722 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
3723   TRY_TO(VisitOMPClauseList(C));
3724   for (auto *E : C->source_exprs()) {
3725     TRY_TO(TraverseStmt(E));
3726   }
3727   for (auto *E : C->destination_exprs()) {
3728     TRY_TO(TraverseStmt(E));
3729   }
3730   for (auto *E : C->assignment_ops()) {
3731     TRY_TO(TraverseStmt(E));
3732   }
3733   return true;
3734 }
3735 
3736 template <typename Derived>
3737 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
3738     OMPCopyprivateClause *C) {
3739   TRY_TO(VisitOMPClauseList(C));
3740   for (auto *E : C->source_exprs()) {
3741     TRY_TO(TraverseStmt(E));
3742   }
3743   for (auto *E : C->destination_exprs()) {
3744     TRY_TO(TraverseStmt(E));
3745   }
3746   for (auto *E : C->assignment_ops()) {
3747     TRY_TO(TraverseStmt(E));
3748   }
3749   return true;
3750 }
3751 
3752 template <typename Derived>
3753 bool
3754 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
3755   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3756   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3757   TRY_TO(VisitOMPClauseList(C));
3758   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3759   for (auto *E : C->privates()) {
3760     TRY_TO(TraverseStmt(E));
3761   }
3762   for (auto *E : C->lhs_exprs()) {
3763     TRY_TO(TraverseStmt(E));
3764   }
3765   for (auto *E : C->rhs_exprs()) {
3766     TRY_TO(TraverseStmt(E));
3767   }
3768   for (auto *E : C->reduction_ops()) {
3769     TRY_TO(TraverseStmt(E));
3770   }
3771   if (C->getModifier() == OMPC_REDUCTION_inscan) {
3772     for (auto *E : C->copy_ops()) {
3773       TRY_TO(TraverseStmt(E));
3774     }
3775     for (auto *E : C->copy_array_temps()) {
3776       TRY_TO(TraverseStmt(E));
3777     }
3778     for (auto *E : C->copy_array_elems()) {
3779       TRY_TO(TraverseStmt(E));
3780     }
3781   }
3782   return true;
3783 }
3784 
3785 template <typename Derived>
3786 bool RecursiveASTVisitor<Derived>::VisitOMPTaskReductionClause(
3787     OMPTaskReductionClause *C) {
3788   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3789   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3790   TRY_TO(VisitOMPClauseList(C));
3791   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3792   for (auto *E : C->privates()) {
3793     TRY_TO(TraverseStmt(E));
3794   }
3795   for (auto *E : C->lhs_exprs()) {
3796     TRY_TO(TraverseStmt(E));
3797   }
3798   for (auto *E : C->rhs_exprs()) {
3799     TRY_TO(TraverseStmt(E));
3800   }
3801   for (auto *E : C->reduction_ops()) {
3802     TRY_TO(TraverseStmt(E));
3803   }
3804   return true;
3805 }
3806 
3807 template <typename Derived>
3808 bool RecursiveASTVisitor<Derived>::VisitOMPInReductionClause(
3809     OMPInReductionClause *C) {
3810   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3811   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3812   TRY_TO(VisitOMPClauseList(C));
3813   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3814   for (auto *E : C->privates()) {
3815     TRY_TO(TraverseStmt(E));
3816   }
3817   for (auto *E : C->lhs_exprs()) {
3818     TRY_TO(TraverseStmt(E));
3819   }
3820   for (auto *E : C->rhs_exprs()) {
3821     TRY_TO(TraverseStmt(E));
3822   }
3823   for (auto *E : C->reduction_ops()) {
3824     TRY_TO(TraverseStmt(E));
3825   }
3826   for (auto *E : C->taskgroup_descriptors())
3827     TRY_TO(TraverseStmt(E));
3828   return true;
3829 }
3830 
3831 template <typename Derived>
3832 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
3833   TRY_TO(VisitOMPClauseList(C));
3834   return true;
3835 }
3836 
3837 template <typename Derived>
3838 bool RecursiveASTVisitor<Derived>::VisitOMPDepobjClause(OMPDepobjClause *C) {
3839   TRY_TO(TraverseStmt(C->getDepobj()));
3840   return true;
3841 }
3842 
3843 template <typename Derived>
3844 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
3845   TRY_TO(VisitOMPClauseList(C));
3846   return true;
3847 }
3848 
3849 template <typename Derived>
3850 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
3851   TRY_TO(VisitOMPClauseWithPreInit(C));
3852   TRY_TO(TraverseStmt(C->getDevice()));
3853   return true;
3854 }
3855 
3856 template <typename Derived>
3857 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
3858   TRY_TO(VisitOMPClauseList(C));
3859   return true;
3860 }
3861 
3862 template <typename Derived>
3863 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
3864     OMPNumTeamsClause *C) {
3865   TRY_TO(VisitOMPClauseList(C));
3866   TRY_TO(VisitOMPClauseWithPreInit(C));
3867   return true;
3868 }
3869 
3870 template <typename Derived>
3871 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
3872     OMPThreadLimitClause *C) {
3873   TRY_TO(VisitOMPClauseList(C));
3874   TRY_TO(VisitOMPClauseWithPreInit(C));
3875   return true;
3876 }
3877 
3878 template <typename Derived>
3879 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
3880     OMPPriorityClause *C) {
3881   TRY_TO(VisitOMPClauseWithPreInit(C));
3882   TRY_TO(TraverseStmt(C->getPriority()));
3883   return true;
3884 }
3885 
3886 template <typename Derived>
3887 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
3888     OMPGrainsizeClause *C) {
3889   TRY_TO(VisitOMPClauseWithPreInit(C));
3890   TRY_TO(TraverseStmt(C->getGrainsize()));
3891   return true;
3892 }
3893 
3894 template <typename Derived>
3895 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
3896     OMPNumTasksClause *C) {
3897   TRY_TO(VisitOMPClauseWithPreInit(C));
3898   TRY_TO(TraverseStmt(C->getNumTasks()));
3899   return true;
3900 }
3901 
3902 template <typename Derived>
3903 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
3904   TRY_TO(TraverseStmt(C->getHint()));
3905   return true;
3906 }
3907 
3908 template <typename Derived>
3909 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
3910     OMPDistScheduleClause *C) {
3911   TRY_TO(VisitOMPClauseWithPreInit(C));
3912   TRY_TO(TraverseStmt(C->getChunkSize()));
3913   return true;
3914 }
3915 
3916 template <typename Derived>
3917 bool
3918 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
3919   return true;
3920 }
3921 
3922 template <typename Derived>
3923 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
3924   TRY_TO(VisitOMPClauseList(C));
3925   return true;
3926 }
3927 
3928 template <typename Derived>
3929 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
3930   TRY_TO(VisitOMPClauseList(C));
3931   return true;
3932 }
3933 
3934 template <typename Derived>
3935 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
3936     OMPUseDevicePtrClause *C) {
3937   TRY_TO(VisitOMPClauseList(C));
3938   return true;
3939 }
3940 
3941 template <typename Derived>
3942 bool RecursiveASTVisitor<Derived>::VisitOMPUseDeviceAddrClause(
3943     OMPUseDeviceAddrClause *C) {
3944   TRY_TO(VisitOMPClauseList(C));
3945   return true;
3946 }
3947 
3948 template <typename Derived>
3949 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
3950     OMPIsDevicePtrClause *C) {
3951   TRY_TO(VisitOMPClauseList(C));
3952   return true;
3953 }
3954 
3955 template <typename Derived>
3956 bool RecursiveASTVisitor<Derived>::VisitOMPHasDeviceAddrClause(
3957     OMPHasDeviceAddrClause *C) {
3958   TRY_TO(VisitOMPClauseList(C));
3959   return true;
3960 }
3961 
3962 template <typename Derived>
3963 bool RecursiveASTVisitor<Derived>::VisitOMPNontemporalClause(
3964     OMPNontemporalClause *C) {
3965   TRY_TO(VisitOMPClauseList(C));
3966   for (auto *E : C->private_refs()) {
3967     TRY_TO(TraverseStmt(E));
3968   }
3969   return true;
3970 }
3971 
3972 template <typename Derived>
3973 bool RecursiveASTVisitor<Derived>::VisitOMPOrderClause(OMPOrderClause *) {
3974   return true;
3975 }
3976 
3977 template <typename Derived>
3978 bool RecursiveASTVisitor<Derived>::VisitOMPDetachClause(OMPDetachClause *C) {
3979   TRY_TO(TraverseStmt(C->getEventHandler()));
3980   return true;
3981 }
3982 
3983 template <typename Derived>
3984 bool RecursiveASTVisitor<Derived>::VisitOMPUsesAllocatorsClause(
3985     OMPUsesAllocatorsClause *C) {
3986   for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
3987     const OMPUsesAllocatorsClause::Data Data = C->getAllocatorData(I);
3988     TRY_TO(TraverseStmt(Data.Allocator));
3989     TRY_TO(TraverseStmt(Data.AllocatorTraits));
3990   }
3991   return true;
3992 }
3993 
3994 template <typename Derived>
3995 bool RecursiveASTVisitor<Derived>::VisitOMPAffinityClause(
3996     OMPAffinityClause *C) {
3997   TRY_TO(TraverseStmt(C->getModifier()));
3998   for (Expr *E : C->varlist())
3999     TRY_TO(TraverseStmt(E));
4000   return true;
4001 }
4002 
4003 template <typename Derived>
4004 bool RecursiveASTVisitor<Derived>::VisitOMPFilterClause(OMPFilterClause *C) {
4005   TRY_TO(VisitOMPClauseWithPreInit(C));
4006   TRY_TO(TraverseStmt(C->getThreadID()));
4007   return true;
4008 }
4009 
4010 template <typename Derived>
4011 bool RecursiveASTVisitor<Derived>::VisitOMPBindClause(OMPBindClause *C) {
4012   return true;
4013 }
4014 
4015 template <typename Derived>
4016 bool RecursiveASTVisitor<Derived>::VisitOMPXDynCGroupMemClause(
4017     OMPXDynCGroupMemClause *C) {
4018   TRY_TO(VisitOMPClauseWithPreInit(C));
4019   TRY_TO(TraverseStmt(C->getSize()));
4020   return true;
4021 }
4022 
4023 template <typename Derived>
4024 bool RecursiveASTVisitor<Derived>::VisitOMPDoacrossClause(
4025     OMPDoacrossClause *C) {
4026   TRY_TO(VisitOMPClauseList(C));
4027   return true;
4028 }
4029 
4030 template <typename Derived>
4031 bool RecursiveASTVisitor<Derived>::VisitOMPXAttributeClause(
4032     OMPXAttributeClause *C) {
4033   return true;
4034 }
4035 
4036 template <typename Derived>
4037 bool RecursiveASTVisitor<Derived>::VisitOMPXBareClause(OMPXBareClause *C) {
4038   return true;
4039 }
4040 
4041 template <typename Derived>
4042 bool RecursiveASTVisitor<Derived>::TraverseOpenACCConstructStmt(
4043     OpenACCConstructStmt *C) {
4044   TRY_TO(VisitOpenACCClauseList(C->clauses()));
4045   return true;
4046 }
4047 
4048 template <typename Derived>
4049 bool RecursiveASTVisitor<Derived>::TraverseOpenACCAssociatedStmtConstruct(
4050     OpenACCAssociatedStmtConstruct *S) {
4051   TRY_TO(TraverseOpenACCConstructStmt(S));
4052   TRY_TO(TraverseStmt(S->getAssociatedStmt()));
4053   return true;
4054 }
4055 
4056 template <typename Derived>
4057 bool RecursiveASTVisitor<Derived>::VisitOpenACCClause(const OpenACCClause *C) {
4058   for (const Stmt *Child : C->children())
4059     TRY_TO(TraverseStmt(const_cast<Stmt *>(Child)));
4060   return true;
4061 }
4062 
4063 template <typename Derived>
4064 bool RecursiveASTVisitor<Derived>::VisitOpenACCClauseList(
4065     ArrayRef<const OpenACCClause *> Clauses) {
4066 
4067   for (const auto *C : Clauses)
4068     TRY_TO(VisitOpenACCClause(C));
4069   return true;
4070 }
4071 
4072 DEF_TRAVERSE_STMT(OpenACCComputeConstruct,
4073                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4074 DEF_TRAVERSE_STMT(OpenACCLoopConstruct,
4075                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4076 DEF_TRAVERSE_STMT(OpenACCCombinedConstruct,
4077                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4078 DEF_TRAVERSE_STMT(OpenACCDataConstruct,
4079                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4080 DEF_TRAVERSE_STMT(OpenACCEnterDataConstruct,
4081                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4082 DEF_TRAVERSE_STMT(OpenACCExitDataConstruct,
4083                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4084 DEF_TRAVERSE_STMT(OpenACCHostDataConstruct,
4085                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4086 DEF_TRAVERSE_STMT(OpenACCWaitConstruct, {
4087   if (S->hasDevNumExpr())
4088     TRY_TO(TraverseStmt(S->getDevNumExpr()));
4089   for (auto *E : S->getQueueIdExprs())
4090     TRY_TO(TraverseStmt(E));
4091   TRY_TO(VisitOpenACCClauseList(S->clauses()));
4092 })
4093 DEF_TRAVERSE_STMT(OpenACCInitConstruct,
4094                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4095 DEF_TRAVERSE_STMT(OpenACCShutdownConstruct,
4096                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4097 DEF_TRAVERSE_STMT(OpenACCSetConstruct,
4098                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4099 DEF_TRAVERSE_STMT(OpenACCUpdateConstruct,
4100                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4101 
4102 // Traverse HLSL: Out argument expression
4103 DEF_TRAVERSE_STMT(HLSLOutArgExpr, {})
4104 
4105 // FIXME: look at the following tricky-seeming exprs to see if we
4106 // need to recurse on anything.  These are ones that have methods
4107 // returning decls or qualtypes or nestednamespecifier -- though I'm
4108 // not sure if they own them -- or just seemed very complicated, or
4109 // had lots of sub-types to explore.
4110 //
4111 // VisitOverloadExpr and its children: recurse on template args? etc?
4112 
4113 // FIXME: go through all the stmts and exprs again, and see which of them
4114 // create new types, and recurse on the types (TypeLocs?) of those.
4115 // Candidates:
4116 //
4117 //    http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
4118 //    http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
4119 //    http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
4120 //    Every class that has getQualifier.
4121 
4122 #undef DEF_TRAVERSE_STMT
4123 #undef TRAVERSE_STMT
4124 #undef TRAVERSE_STMT_BASE
4125 
4126 #undef TRY_TO
4127 
4128 } // end namespace clang
4129 
4130 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H