xref: /llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h (revision abc8812df02599fc413d9ed77b992f8236ed2af9)
1 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //  This file defines the RecursiveASTVisitor interface, which recursively
10 //  traverses the entire AST.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
14 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
15 
16 #include "clang/AST/ASTConcept.h"
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclBase.h"
20 #include "clang/AST/DeclCXX.h"
21 #include "clang/AST/DeclFriend.h"
22 #include "clang/AST/DeclObjC.h"
23 #include "clang/AST/DeclOpenMP.h"
24 #include "clang/AST/DeclTemplate.h"
25 #include "clang/AST/DeclarationName.h"
26 #include "clang/AST/Expr.h"
27 #include "clang/AST/ExprCXX.h"
28 #include "clang/AST/ExprConcepts.h"
29 #include "clang/AST/ExprObjC.h"
30 #include "clang/AST/ExprOpenMP.h"
31 #include "clang/AST/LambdaCapture.h"
32 #include "clang/AST/NestedNameSpecifier.h"
33 #include "clang/AST/OpenACCClause.h"
34 #include "clang/AST/OpenMPClause.h"
35 #include "clang/AST/Stmt.h"
36 #include "clang/AST/StmtCXX.h"
37 #include "clang/AST/StmtObjC.h"
38 #include "clang/AST/StmtOpenACC.h"
39 #include "clang/AST/StmtOpenMP.h"
40 #include "clang/AST/StmtSYCL.h"
41 #include "clang/AST/TemplateBase.h"
42 #include "clang/AST/TemplateName.h"
43 #include "clang/AST/Type.h"
44 #include "clang/AST/TypeLoc.h"
45 #include "clang/Basic/LLVM.h"
46 #include "clang/Basic/OpenMPKinds.h"
47 #include "clang/Basic/Specifiers.h"
48 #include "llvm/ADT/PointerIntPair.h"
49 #include "llvm/ADT/SmallVector.h"
50 #include "llvm/Support/Casting.h"
51 #include <algorithm>
52 #include <cstddef>
53 #include <type_traits>
54 
55 namespace clang {
56 
57 // A helper macro to implement short-circuiting when recursing.  It
58 // invokes CALL_EXPR, which must be a method call, on the derived
59 // object (s.t. a user of RecursiveASTVisitor can override the method
60 // in CALL_EXPR).
61 #define TRY_TO(CALL_EXPR)                                                      \
62   do {                                                                         \
63     if (!getDerived().CALL_EXPR)                                               \
64       return false;                                                            \
65   } while (false)
66 
67 namespace detail {
68 
69 template <typename T, typename U>
70 struct has_same_member_pointer_type : std::false_type {};
71 template <typename T, typename U, typename R, typename... P>
72 struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
73     : std::true_type {};
74 
75 /// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr
76 /// are pointers to the same non-static member function.
77 template <typename FirstMethodPtrTy, typename SecondMethodPtrTy>
78 LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG auto
79 isSameMethod([[maybe_unused]] FirstMethodPtrTy FirstMethodPtr,
80              [[maybe_unused]] SecondMethodPtrTy SecondMethodPtr)
81     -> bool {
82   if constexpr (has_same_member_pointer_type<FirstMethodPtrTy,
83                                              SecondMethodPtrTy>::value)
84     return FirstMethodPtr == SecondMethodPtr;
85   return false;
86 }
87 
88 } // end namespace detail
89 
90 /// A class that does preorder or postorder
91 /// depth-first traversal on the entire Clang AST and visits each node.
92 ///
93 /// This class performs three distinct tasks:
94 ///   1. traverse the AST (i.e. go to each node);
95 ///   2. at a given node, walk up the class hierarchy, starting from
96 ///      the node's dynamic type, until the top-most class (e.g. Stmt,
97 ///      Decl, or Type) is reached.
98 ///   3. given a (node, class) combination, where 'class' is some base
99 ///      class of the dynamic type of 'node', call a user-overridable
100 ///      function to actually visit the node.
101 ///
102 /// These tasks are done by three groups of methods, respectively:
103 ///   1. TraverseDecl(Decl *x) does task #1.  It is the entry point
104 ///      for traversing an AST rooted at x.  This method simply
105 ///      dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
106 ///      is the dynamic type of *x, which calls WalkUpFromFoo(x) and
107 ///      then recursively visits the child nodes of x.
108 ///      TraverseStmt(Stmt *x) and TraverseType(QualType x) work
109 ///      similarly.
110 ///   2. WalkUpFromFoo(Foo *x) does task #2.  It does not try to visit
111 ///      any child node of x.  Instead, it first calls WalkUpFromBar(x)
112 ///      where Bar is the direct parent class of Foo (unless Foo has
113 ///      no parent), and then calls VisitFoo(x) (see the next list item).
114 ///   3. VisitFoo(Foo *x) does task #3.
115 ///
116 /// These three method groups are tiered (Traverse* > WalkUpFrom* >
117 /// Visit*).  A method (e.g. Traverse*) may call methods from the same
118 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
119 /// It may not call methods from a higher tier.
120 ///
121 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
122 /// is Foo's super class) before calling VisitFoo(), the result is
123 /// that the Visit*() methods for a given node are called in the
124 /// top-down order (e.g. for a node of type NamespaceDecl, the order will
125 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
126 ///
127 /// This scheme guarantees that all Visit*() calls for the same AST
128 /// node are grouped together.  In other words, Visit*() methods for
129 /// different nodes are never interleaved.
130 ///
131 /// Clients of this visitor should subclass the visitor (providing
132 /// themselves as the template argument, using the curiously recurring
133 /// template pattern) and override any of the Traverse*, WalkUpFrom*,
134 /// and Visit* methods for declarations, types, statements,
135 /// expressions, or other AST nodes where the visitor should customize
136 /// behavior.  Most users only need to override Visit*.  Advanced
137 /// users may override Traverse* and WalkUpFrom* to implement custom
138 /// traversal strategies.  Returning false from one of these overridden
139 /// functions will abort the entire traversal.
140 ///
141 /// By default, this visitor tries to visit every part of the explicit
142 /// source code exactly once.  The default policy towards templates
143 /// is to descend into the 'pattern' class or function body, not any
144 /// explicit or implicit instantiations.  Explicit specializations
145 /// are still visited, and the patterns of partial specializations
146 /// are visited separately.  This behavior can be changed by
147 /// overriding shouldVisitTemplateInstantiations() in the derived class
148 /// to return true, in which case all known implicit and explicit
149 /// instantiations will be visited at the same time as the pattern
150 /// from which they were produced.
151 ///
152 /// By default, this visitor preorder traverses the AST. If postorder traversal
153 /// is needed, the \c shouldTraversePostOrder method needs to be overridden
154 /// to return \c true.
155 template <typename Derived> class RecursiveASTVisitor {
156 public:
157   /// A queue used for performing data recursion over statements.
158   /// Parameters involving this type are used to implement data
159   /// recursion over Stmts and Exprs within this class, and should
160   /// typically not be explicitly specified by derived classes.
161   /// The bool bit indicates whether the statement has been traversed or not.
162   typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>>
163     DataRecursionQueue;
164 
165   /// Return a reference to the derived class.
166   Derived &getDerived() { return *static_cast<Derived *>(this); }
167 
168   /// Return whether this visitor should recurse into
169   /// template instantiations.
170   bool shouldVisitTemplateInstantiations() const { return false; }
171 
172   /// Return whether this visitor should recurse into the types of
173   /// TypeLocs.
174   bool shouldWalkTypesOfTypeLocs() const { return true; }
175 
176   /// Return whether this visitor should recurse into implicit
177   /// code, e.g., implicit constructors and destructors.
178   bool shouldVisitImplicitCode() const { return false; }
179 
180   /// Return whether this visitor should recurse into lambda body
181   bool shouldVisitLambdaBody() const { return true; }
182 
183   /// Return whether this visitor should traverse post-order.
184   bool shouldTraversePostOrder() const { return false; }
185 
186   /// Recursively visits an entire AST, starting from the TranslationUnitDecl.
187   /// \returns false if visitation was terminated early.
188   bool TraverseAST(ASTContext &AST) {
189     // Currently just an alias for TraverseDecl(TUDecl), but kept in case
190     // we change the implementation again.
191     return getDerived().TraverseDecl(AST.getTranslationUnitDecl());
192   }
193 
194   /// Recursively visit a statement or expression, by
195   /// dispatching to Traverse*() based on the argument's dynamic type.
196   ///
197   /// \returns false if the visitation was terminated early, true
198   /// otherwise (including when the argument is nullptr).
199   bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr);
200 
201   /// Invoked before visiting a statement or expression via data recursion.
202   ///
203   /// \returns false to skip visiting the node, true otherwise.
204   bool dataTraverseStmtPre(Stmt *S) { return true; }
205 
206   /// Invoked after visiting a statement or expression via data recursion.
207   /// This is not invoked if the previously invoked \c dataTraverseStmtPre
208   /// returned false.
209   ///
210   /// \returns false if the visitation was terminated early, true otherwise.
211   bool dataTraverseStmtPost(Stmt *S) { return true; }
212 
213   /// Recursively visit a type, by dispatching to
214   /// Traverse*Type() based on the argument's getTypeClass() property.
215   ///
216   /// \returns false if the visitation was terminated early, true
217   /// otherwise (including when the argument is a Null type).
218   bool TraverseType(QualType T);
219 
220   /// Recursively visit a type with location, by dispatching to
221   /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
222   ///
223   /// \returns false if the visitation was terminated early, true
224   /// otherwise (including when the argument is a Null type location).
225   bool TraverseTypeLoc(TypeLoc TL);
226 
227   /// Recursively visit an attribute, by dispatching to
228   /// Traverse*Attr() based on the argument's dynamic type.
229   ///
230   /// \returns false if the visitation was terminated early, true
231   /// otherwise (including when the argument is a Null type location).
232   bool TraverseAttr(Attr *At);
233 
234   /// Recursively visit a declaration, by dispatching to
235   /// Traverse*Decl() based on the argument's dynamic type.
236   ///
237   /// \returns false if the visitation was terminated early, true
238   /// otherwise (including when the argument is NULL).
239   bool TraverseDecl(Decl *D);
240 
241   /// Recursively visit a C++ nested-name-specifier.
242   ///
243   /// \returns false if the visitation was terminated early, true otherwise.
244   bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
245 
246   /// Recursively visit a C++ nested-name-specifier with location
247   /// information.
248   ///
249   /// \returns false if the visitation was terminated early, true otherwise.
250   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
251 
252   /// Recursively visit a name with its location information.
253   ///
254   /// \returns false if the visitation was terminated early, true otherwise.
255   bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
256 
257   /// Recursively visit a template name and dispatch to the
258   /// appropriate method.
259   ///
260   /// \returns false if the visitation was terminated early, true otherwise.
261   bool TraverseTemplateName(TemplateName Template);
262 
263   /// Recursively visit a template argument and dispatch to the
264   /// appropriate method for the argument type.
265   ///
266   /// \returns false if the visitation was terminated early, true otherwise.
267   // FIXME: migrate callers to TemplateArgumentLoc instead.
268   bool TraverseTemplateArgument(const TemplateArgument &Arg);
269 
270   /// Recursively visit a template argument location and dispatch to the
271   /// appropriate method for the argument type.
272   ///
273   /// \returns false if the visitation was terminated early, true otherwise.
274   bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
275 
276   /// Recursively visit a set of template arguments.
277   /// This can be overridden by a subclass, but it's not expected that
278   /// will be needed -- this visitor always dispatches to another.
279   ///
280   /// \returns false if the visitation was terminated early, true otherwise.
281   // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
282   bool TraverseTemplateArguments(ArrayRef<TemplateArgument> Args);
283 
284   /// Recursively visit a base specifier. This can be overridden by a
285   /// subclass.
286   ///
287   /// \returns false if the visitation was terminated early, true otherwise.
288   bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base);
289 
290   /// Recursively visit a constructor initializer.  This
291   /// automatically dispatches to another visitor for the initializer
292   /// expression, but not for the name of the initializer, so may
293   /// be overridden for clients that need access to the name.
294   ///
295   /// \returns false if the visitation was terminated early, true otherwise.
296   bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
297 
298   /// Recursively visit a lambda capture. \c Init is the expression that
299   /// will be used to initialize the capture.
300   ///
301   /// \returns false if the visitation was terminated early, true otherwise.
302   bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
303                              Expr *Init);
304 
305   /// Recursively visit the syntactic or semantic form of an
306   /// initialization list.
307   ///
308   /// \returns false if the visitation was terminated early, true otherwise.
309   bool TraverseSynOrSemInitListExpr(InitListExpr *S,
310                                     DataRecursionQueue *Queue = nullptr);
311 
312   /// Recursively visit an Objective-C protocol reference with location
313   /// information.
314   ///
315   /// \returns false if the visitation was terminated early, true otherwise.
316   bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc);
317 
318   /// Recursively visit concept reference with location information.
319   ///
320   /// \returns false if the visitation was terminated early, true otherwise.
321   bool TraverseConceptReference(ConceptReference *CR);
322 
323   // Visit concept reference.
324   bool VisitConceptReference(ConceptReference *CR) { return true; }
325   // ---- Methods on Attrs ----
326 
327   // Visit an attribute.
328   bool VisitAttr(Attr *A) { return true; }
329 
330 // Declare Traverse* and empty Visit* for all Attr classes.
331 #define ATTR_VISITOR_DECLS_ONLY
332 #include "clang/AST/AttrVisitor.inc"
333 #undef ATTR_VISITOR_DECLS_ONLY
334 
335 // ---- Methods on Stmts ----
336 
337   Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); }
338 
339 private:
340   // Traverse the given statement. If the most-derived traverse function takes a
341   // data recursion queue, pass it on; otherwise, discard it. Note that the
342   // first branch of this conditional must compile whether or not the derived
343   // class can take a queue, so if we're taking the second arm, make the first
344   // arm call our function rather than the derived class version.
345 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE)                            \
346   (::clang::detail::has_same_member_pointer_type<                              \
347        decltype(&RecursiveASTVisitor::Traverse##NAME),                         \
348        decltype(&Derived::Traverse##NAME)>::value                              \
349        ? static_cast<std::conditional_t<                                       \
350              ::clang::detail::has_same_member_pointer_type<                    \
351                  decltype(&RecursiveASTVisitor::Traverse##NAME),               \
352                  decltype(&Derived::Traverse##NAME)>::value,                   \
353              Derived &, RecursiveASTVisitor &>>(*this)                         \
354              .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE)                 \
355        : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
356 
357 // Try to traverse the given statement, or enqueue it if we're performing data
358 // recursion in the middle of traversing another statement. Can only be called
359 // from within a DEF_TRAVERSE_STMT body or similar context.
360 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S)                                     \
361   do {                                                                         \
362     if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue))                             \
363       return false;                                                            \
364   } while (false)
365 
366 public:
367 // Declare Traverse*() for all concrete Stmt classes.
368 #define ABSTRACT_STMT(STMT)
369 #define STMT(CLASS, PARENT) \
370   bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
371 #include "clang/AST/StmtNodes.inc"
372   // The above header #undefs ABSTRACT_STMT and STMT upon exit.
373 
374   // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
375   bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
376   bool VisitStmt(Stmt *S) { return true; }
377 #define STMT(CLASS, PARENT)                                                    \
378   bool WalkUpFrom##CLASS(CLASS *S) {                                           \
379     TRY_TO(WalkUpFrom##PARENT(S));                                             \
380     TRY_TO(Visit##CLASS(S));                                                   \
381     return true;                                                               \
382   }                                                                            \
383   bool Visit##CLASS(CLASS *S) { return true; }
384 #include "clang/AST/StmtNodes.inc"
385 
386 // ---- Methods on Types ----
387 // FIXME: revamp to take TypeLoc's rather than Types.
388 
389 // Declare Traverse*() for all concrete Type classes.
390 #define ABSTRACT_TYPE(CLASS, BASE)
391 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
392 #include "clang/AST/TypeNodes.inc"
393   // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
394 
395   // Define WalkUpFrom*() and empty Visit*() for all Type classes.
396   bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
397   bool VisitType(Type *T) { return true; }
398 #define TYPE(CLASS, BASE)                                                      \
399   bool WalkUpFrom##CLASS##Type(CLASS##Type *T) {                               \
400     TRY_TO(WalkUpFrom##BASE(T));                                               \
401     TRY_TO(Visit##CLASS##Type(T));                                             \
402     return true;                                                               \
403   }                                                                            \
404   bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
405 #include "clang/AST/TypeNodes.inc"
406 
407 // ---- Methods on TypeLocs ----
408 // FIXME: this currently just calls the matching Type methods
409 
410 // Declare Traverse*() for all concrete TypeLoc classes.
411 #define ABSTRACT_TYPELOC(CLASS, BASE)
412 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
413 #include "clang/AST/TypeLocNodes.def"
414   // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
415 
416   // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
417   bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
418   bool VisitTypeLoc(TypeLoc TL) { return true; }
419 
420   // QualifiedTypeLoc and UnqualTypeLoc are not declared in
421   // TypeNodes.inc and thus need to be handled specially.
422   bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
423     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
424   }
425   bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
426   bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
427     return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
428   }
429   bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
430 
431 // Note that BASE includes trailing 'Type' which CLASS doesn't.
432 #define TYPE(CLASS, BASE)                                                      \
433   bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) {                         \
434     TRY_TO(WalkUpFrom##BASE##Loc(TL));                                         \
435     TRY_TO(Visit##CLASS##TypeLoc(TL));                                         \
436     return true;                                                               \
437   }                                                                            \
438   bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
439 #include "clang/AST/TypeNodes.inc"
440 
441 // ---- Methods on Decls ----
442 
443 // Declare Traverse*() for all concrete Decl classes.
444 #define ABSTRACT_DECL(DECL)
445 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
446 #include "clang/AST/DeclNodes.inc"
447   // The above header #undefs ABSTRACT_DECL and DECL upon exit.
448 
449   // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
450   bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
451   bool VisitDecl(Decl *D) { return true; }
452 #define DECL(CLASS, BASE)                                                      \
453   bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) {                               \
454     TRY_TO(WalkUpFrom##BASE(D));                                               \
455     TRY_TO(Visit##CLASS##Decl(D));                                             \
456     return true;                                                               \
457   }                                                                            \
458   bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
459 #include "clang/AST/DeclNodes.inc"
460 
461   bool canIgnoreChildDeclWhileTraversingDeclContext(const Decl *Child);
462 
463 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND)                                   \
464   bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
465   DEF_TRAVERSE_TMPL_INST(Class)
466   DEF_TRAVERSE_TMPL_INST(Var)
467   DEF_TRAVERSE_TMPL_INST(Function)
468 #undef DEF_TRAVERSE_TMPL_INST
469 
470   bool TraverseTypeConstraint(const TypeConstraint *C);
471 
472   bool TraverseConceptRequirement(concepts::Requirement *R);
473   bool TraverseConceptTypeRequirement(concepts::TypeRequirement *R);
474   bool TraverseConceptExprRequirement(concepts::ExprRequirement *R);
475   bool TraverseConceptNestedRequirement(concepts::NestedRequirement *R);
476 
477   bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
478 
479 private:
480   // These are helper methods used by more than one Traverse* method.
481   bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
482 
483   // Traverses template parameter lists of either a DeclaratorDecl or TagDecl.
484   template <typename T>
485   bool TraverseDeclTemplateParameterLists(T *D);
486 
487   bool TraverseTemplateTypeParamDeclConstraints(const TemplateTypeParmDecl *D);
488 
489   bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
490                                           unsigned Count);
491   bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
492   bool TraverseRecordHelper(RecordDecl *D);
493   bool TraverseCXXRecordHelper(CXXRecordDecl *D);
494   bool TraverseDeclaratorHelper(DeclaratorDecl *D);
495   bool TraverseDeclContextHelper(DeclContext *DC);
496   bool TraverseFunctionHelper(FunctionDecl *D);
497   bool TraverseVarHelper(VarDecl *D);
498   bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
499   bool TraverseOMPLoopDirective(OMPLoopDirective *S);
500   bool TraverseOMPClause(OMPClause *C);
501 #define GEN_CLANG_CLAUSE_CLASS
502 #define CLAUSE_CLASS(Enum, Str, Class) bool Visit##Class(Class *C);
503 #include "llvm/Frontend/OpenMP/OMP.inc"
504   /// Process clauses with list of variables.
505   template <typename T> bool VisitOMPClauseList(T *Node);
506   /// Process clauses with pre-initis.
507   bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
508   bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
509 
510   bool PostVisitStmt(Stmt *S);
511   bool TraverseOpenACCConstructStmt(OpenACCConstructStmt *S);
512   bool
513   TraverseOpenACCAssociatedStmtConstruct(OpenACCAssociatedStmtConstruct *S);
514   bool VisitOpenACCClauseList(ArrayRef<const OpenACCClause *>);
515   bool VisitOpenACCClause(const OpenACCClause *);
516 };
517 
518 template <typename Derived>
519 bool RecursiveASTVisitor<Derived>::TraverseTypeConstraint(
520     const TypeConstraint *C) {
521   if (!getDerived().shouldVisitImplicitCode()) {
522     TRY_TO(TraverseConceptReference(C->getConceptReference()));
523     return true;
524   }
525   if (Expr *IDC = C->getImmediatelyDeclaredConstraint()) {
526     TRY_TO(TraverseStmt(IDC));
527   } else {
528     // Avoid traversing the ConceptReference in the TypeConstraint
529     // if we have an immediately-declared-constraint, otherwise
530     // we'll end up visiting the concept and the arguments in
531     // the TC twice.
532     TRY_TO(TraverseConceptReference(C->getConceptReference()));
533   }
534   return true;
535 }
536 
537 template <typename Derived>
538 bool RecursiveASTVisitor<Derived>::TraverseConceptRequirement(
539     concepts::Requirement *R) {
540   switch (R->getKind()) {
541   case concepts::Requirement::RK_Type:
542     return getDerived().TraverseConceptTypeRequirement(
543         cast<concepts::TypeRequirement>(R));
544   case concepts::Requirement::RK_Simple:
545   case concepts::Requirement::RK_Compound:
546     return getDerived().TraverseConceptExprRequirement(
547         cast<concepts::ExprRequirement>(R));
548   case concepts::Requirement::RK_Nested:
549     return getDerived().TraverseConceptNestedRequirement(
550         cast<concepts::NestedRequirement>(R));
551   }
552   llvm_unreachable("unexpected case");
553 }
554 
555 template <typename Derived>
556 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
557                                                     DataRecursionQueue *Queue) {
558   // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
559   switch (S->getStmtClass()) {
560   case Stmt::NoStmtClass:
561     break;
562 #define ABSTRACT_STMT(STMT)
563 #define STMT(CLASS, PARENT)                                                    \
564   case Stmt::CLASS##Class:                                                     \
565     return TRAVERSE_STMT_BASE(CLASS, CLASS, S, Queue);
566 #include "clang/AST/StmtNodes.inc"
567   }
568 
569   return true;
570 }
571 
572 #undef DISPATCH_STMT
573 
574 template <typename Derived>
575 bool RecursiveASTVisitor<Derived>::TraverseConceptTypeRequirement(
576     concepts::TypeRequirement *R) {
577   if (R->isSubstitutionFailure())
578     return true;
579   return getDerived().TraverseTypeLoc(R->getType()->getTypeLoc());
580 }
581 
582 template <typename Derived>
583 bool RecursiveASTVisitor<Derived>::TraverseConceptExprRequirement(
584     concepts::ExprRequirement *R) {
585   if (!R->isExprSubstitutionFailure())
586     TRY_TO(TraverseStmt(R->getExpr()));
587   auto &RetReq = R->getReturnTypeRequirement();
588   if (RetReq.isTypeConstraint()) {
589     if (getDerived().shouldVisitImplicitCode()) {
590       TRY_TO(TraverseTemplateParameterListHelper(
591           RetReq.getTypeConstraintTemplateParameterList()));
592     } else {
593       // Template parameter list is implicit, visit constraint directly.
594       TRY_TO(TraverseTypeConstraint(RetReq.getTypeConstraint()));
595     }
596   }
597   return true;
598 }
599 
600 template <typename Derived>
601 bool RecursiveASTVisitor<Derived>::TraverseConceptNestedRequirement(
602     concepts::NestedRequirement *R) {
603   if (!R->hasInvalidConstraint())
604     return getDerived().TraverseStmt(R->getConstraintExpr());
605   return true;
606 }
607 
608 template <typename Derived>
609 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
610   // In pre-order traversal mode, each Traverse##STMT method is responsible for
611   // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and
612   // does not call the default implementation, the WalkUpFrom callback is not
613   // called. Post-order traversal mode should provide the same behavior
614   // regarding method overrides.
615   //
616   // In post-order traversal mode the Traverse##STMT method, when it receives a
617   // DataRecursionQueue, can't call WalkUpFrom after traversing children because
618   // it only enqueues the children and does not traverse them. TraverseStmt
619   // traverses the enqueued children, and we call WalkUpFrom here.
620   //
621   // However, to make pre-order and post-order modes identical with regards to
622   // whether they call WalkUpFrom at all, we call WalkUpFrom if and only if the
623   // user did not override the Traverse##STMT method. We implement the override
624   // check with isSameMethod calls below.
625 
626   switch (S->getStmtClass()) {
627   case Stmt::NoStmtClass:
628     break;
629 #define ABSTRACT_STMT(STMT)
630 #define STMT(CLASS, PARENT)                                                    \
631   case Stmt::CLASS##Class:                                                     \
632     if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS,   \
633                                       &Derived::Traverse##CLASS)) {            \
634       TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S)));                      \
635     }                                                                          \
636     break;
637 #define INITLISTEXPR(CLASS, PARENT)                                            \
638   case Stmt::CLASS##Class:                                                     \
639     if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS,   \
640                                       &Derived::Traverse##CLASS)) {            \
641       auto ILE = static_cast<CLASS *>(S);                                      \
642       if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE)    \
643         TRY_TO(WalkUpFrom##CLASS(Syn));                                        \
644       if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm())     \
645         TRY_TO(WalkUpFrom##CLASS(Sem));                                        \
646     }                                                                          \
647     break;
648 #include "clang/AST/StmtNodes.inc"
649   }
650 
651   return true;
652 }
653 
654 #undef DISPATCH_STMT
655 
656 // Inlining this method can lead to large code size and compile-time increases
657 // without any benefit to runtime performance.
658 template <typename Derived>
659 LLVM_ATTRIBUTE_NOINLINE bool
660 RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S, DataRecursionQueue *Queue) {
661   if (!S)
662     return true;
663 
664   if (Queue) {
665     Queue->push_back({S, false});
666     return true;
667   }
668 
669   SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
670   LocalQueue.push_back({S, false});
671 
672   while (!LocalQueue.empty()) {
673     auto &CurrSAndVisited = LocalQueue.back();
674     Stmt *CurrS = CurrSAndVisited.getPointer();
675     bool Visited = CurrSAndVisited.getInt();
676     if (Visited) {
677       LocalQueue.pop_back();
678       TRY_TO(dataTraverseStmtPost(CurrS));
679       if (getDerived().shouldTraversePostOrder()) {
680         TRY_TO(PostVisitStmt(CurrS));
681       }
682       continue;
683     }
684 
685     if (getDerived().dataTraverseStmtPre(CurrS)) {
686       CurrSAndVisited.setInt(true);
687       size_t N = LocalQueue.size();
688       TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
689       // Process new children in the order they were added.
690       std::reverse(LocalQueue.begin() + N, LocalQueue.end());
691     } else {
692       LocalQueue.pop_back();
693     }
694   }
695 
696   return true;
697 }
698 
699 template <typename Derived>
700 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
701   if (T.isNull())
702     return true;
703 
704   switch (T->getTypeClass()) {
705 #define ABSTRACT_TYPE(CLASS, BASE)
706 #define TYPE(CLASS, BASE)                                                      \
707   case Type::CLASS:                                                            \
708     return getDerived().Traverse##CLASS##Type(                                 \
709         static_cast<CLASS##Type *>(const_cast<Type *>(T.getTypePtr())));
710 #include "clang/AST/TypeNodes.inc"
711   }
712 
713   return true;
714 }
715 
716 template <typename Derived>
717 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
718   if (TL.isNull())
719     return true;
720 
721   switch (TL.getTypeLocClass()) {
722 #define ABSTRACT_TYPELOC(CLASS, BASE)
723 #define TYPELOC(CLASS, BASE)                                                   \
724   case TypeLoc::CLASS:                                                         \
725     return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
726 #include "clang/AST/TypeLocNodes.def"
727   }
728 
729   return true;
730 }
731 
732 // Define the Traverse*Attr(Attr* A) methods
733 #define VISITORCLASS RecursiveASTVisitor
734 #include "clang/AST/AttrVisitor.inc"
735 #undef VISITORCLASS
736 
737 template <typename Derived>
738 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
739   if (!D)
740     return true;
741 
742   // As a syntax visitor, by default we want to ignore declarations for
743   // implicit declarations (ones not typed explicitly by the user).
744   if (!getDerived().shouldVisitImplicitCode()) {
745     if (D->isImplicit()) {
746       // For an implicit template type parameter, its type constraints are not
747       // implicit and are not represented anywhere else. We still need to visit
748       // them.
749       if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(D))
750         return TraverseTemplateTypeParamDeclConstraints(TTPD);
751       return true;
752     }
753 
754     // Deduction guides for alias templates are always synthesized, so they
755     // should not be traversed unless shouldVisitImplicitCode() returns true.
756     //
757     // It's important to note that checking the implicit bit is not efficient
758     // for the alias case. For deduction guides synthesized from explicit
759     // user-defined deduction guides, we must maintain the explicit bit to
760     // ensure correct overload resolution.
761     if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
762       if (llvm::isa_and_present<TypeAliasTemplateDecl>(
763               FTD->getDeclName().getCXXDeductionGuideTemplate()))
764         return true;
765   }
766 
767   switch (D->getKind()) {
768 #define ABSTRACT_DECL(DECL)
769 #define DECL(CLASS, BASE)                                                      \
770   case Decl::CLASS:                                                            \
771     if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D)))    \
772       return false;                                                            \
773     break;
774 #include "clang/AST/DeclNodes.inc"
775   }
776   return true;
777 }
778 
779 template <typename Derived>
780 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
781     NestedNameSpecifier *NNS) {
782   if (!NNS)
783     return true;
784 
785   if (NNS->getPrefix())
786     TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
787 
788   switch (NNS->getKind()) {
789   case NestedNameSpecifier::Identifier:
790   case NestedNameSpecifier::Namespace:
791   case NestedNameSpecifier::NamespaceAlias:
792   case NestedNameSpecifier::Global:
793   case NestedNameSpecifier::Super:
794     return true;
795 
796   case NestedNameSpecifier::TypeSpec:
797   case NestedNameSpecifier::TypeSpecWithTemplate:
798     TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
799   }
800 
801   return true;
802 }
803 
804 template <typename Derived>
805 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
806     NestedNameSpecifierLoc NNS) {
807   if (!NNS)
808     return true;
809 
810   if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
811     TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
812 
813   switch (NNS.getNestedNameSpecifier()->getKind()) {
814   case NestedNameSpecifier::Identifier:
815   case NestedNameSpecifier::Namespace:
816   case NestedNameSpecifier::NamespaceAlias:
817   case NestedNameSpecifier::Global:
818   case NestedNameSpecifier::Super:
819     return true;
820 
821   case NestedNameSpecifier::TypeSpec:
822   case NestedNameSpecifier::TypeSpecWithTemplate:
823     TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
824     break;
825   }
826 
827   return true;
828 }
829 
830 template <typename Derived>
831 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
832     DeclarationNameInfo NameInfo) {
833   switch (NameInfo.getName().getNameKind()) {
834   case DeclarationName::CXXConstructorName:
835   case DeclarationName::CXXDestructorName:
836   case DeclarationName::CXXConversionFunctionName:
837     if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
838       TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
839     break;
840 
841   case DeclarationName::CXXDeductionGuideName:
842     TRY_TO(TraverseTemplateName(
843         TemplateName(NameInfo.getName().getCXXDeductionGuideTemplate())));
844     break;
845 
846   case DeclarationName::Identifier:
847   case DeclarationName::ObjCZeroArgSelector:
848   case DeclarationName::ObjCOneArgSelector:
849   case DeclarationName::ObjCMultiArgSelector:
850   case DeclarationName::CXXOperatorName:
851   case DeclarationName::CXXLiteralOperatorName:
852   case DeclarationName::CXXUsingDirective:
853     break;
854   }
855 
856   return true;
857 }
858 
859 template <typename Derived>
860 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
861   if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
862     TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
863   } else if (QualifiedTemplateName *QTN =
864                  Template.getAsQualifiedTemplateName()) {
865     if (QTN->getQualifier()) {
866       TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
867     }
868   }
869 
870   return true;
871 }
872 
873 template <typename Derived>
874 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
875     const TemplateArgument &Arg) {
876   switch (Arg.getKind()) {
877   case TemplateArgument::Null:
878   case TemplateArgument::Declaration:
879   case TemplateArgument::Integral:
880   case TemplateArgument::NullPtr:
881   case TemplateArgument::StructuralValue:
882     return true;
883 
884   case TemplateArgument::Type:
885     return getDerived().TraverseType(Arg.getAsType());
886 
887   case TemplateArgument::Template:
888   case TemplateArgument::TemplateExpansion:
889     return getDerived().TraverseTemplateName(
890         Arg.getAsTemplateOrTemplatePattern());
891 
892   case TemplateArgument::Expression:
893     return getDerived().TraverseStmt(Arg.getAsExpr());
894 
895   case TemplateArgument::Pack:
896     return getDerived().TraverseTemplateArguments(Arg.pack_elements());
897   }
898 
899   return true;
900 }
901 
902 // FIXME: no template name location?
903 // FIXME: no source locations for a template argument pack?
904 template <typename Derived>
905 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
906     const TemplateArgumentLoc &ArgLoc) {
907   const TemplateArgument &Arg = ArgLoc.getArgument();
908 
909   switch (Arg.getKind()) {
910   case TemplateArgument::Null:
911   case TemplateArgument::Declaration:
912   case TemplateArgument::Integral:
913   case TemplateArgument::NullPtr:
914   case TemplateArgument::StructuralValue:
915     return true;
916 
917   case TemplateArgument::Type: {
918     // FIXME: how can TSI ever be NULL?
919     if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
920       return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
921     else
922       return getDerived().TraverseType(Arg.getAsType());
923   }
924 
925   case TemplateArgument::Template:
926   case TemplateArgument::TemplateExpansion:
927     if (ArgLoc.getTemplateQualifierLoc())
928       TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
929           ArgLoc.getTemplateQualifierLoc()));
930     return getDerived().TraverseTemplateName(
931         Arg.getAsTemplateOrTemplatePattern());
932 
933   case TemplateArgument::Expression:
934     return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
935 
936   case TemplateArgument::Pack:
937     return getDerived().TraverseTemplateArguments(Arg.pack_elements());
938   }
939 
940   return true;
941 }
942 
943 template <typename Derived>
944 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
945     ArrayRef<TemplateArgument> Args) {
946   for (const TemplateArgument &Arg : Args)
947     TRY_TO(TraverseTemplateArgument(Arg));
948 
949   return true;
950 }
951 
952 template <typename Derived>
953 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
954     CXXCtorInitializer *Init) {
955   if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
956     TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
957 
958   if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
959     TRY_TO(TraverseStmt(Init->getInit()));
960 
961   return true;
962 }
963 
964 template <typename Derived>
965 bool
966 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
967                                                     const LambdaCapture *C,
968                                                     Expr *Init) {
969   if (LE->isInitCapture(C))
970     TRY_TO(TraverseDecl(C->getCapturedVar()));
971   else
972     TRY_TO(TraverseStmt(Init));
973   return true;
974 }
975 
976 // ----------------- Type traversal -----------------
977 
978 // This macro makes available a variable T, the passed-in type.
979 #define DEF_TRAVERSE_TYPE(TYPE, CODE)                                          \
980   template <typename Derived>                                                  \
981   bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) {                 \
982     if (!getDerived().shouldTraversePostOrder())                               \
983       TRY_TO(WalkUpFrom##TYPE(T));                                             \
984     { CODE; }                                                                  \
985     if (getDerived().shouldTraversePostOrder())                                \
986       TRY_TO(WalkUpFrom##TYPE(T));                                             \
987     return true;                                                               \
988   }
989 
990 DEF_TRAVERSE_TYPE(BuiltinType, {})
991 
992 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
993 
994 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
995 
996 DEF_TRAVERSE_TYPE(BlockPointerType,
997                   { TRY_TO(TraverseType(T->getPointeeType())); })
998 
999 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 DEF_TRAVERSE_STMT(ResolvedUnexpandedPackExpr, {})
2954 
2955 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {
2956   if (S->getLifetimeExtendedTemporaryDecl()) {
2957     TRY_TO(TraverseLifetimeExtendedTemporaryDecl(
2958         S->getLifetimeExtendedTemporaryDecl()));
2959     ShouldVisitChildren = false;
2960   }
2961 })
2962 // For coroutines expressions, traverse either the operand
2963 // as written or the implied calls, depending on what the
2964 // derived class requests.
2965 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
2966   if (!getDerived().shouldVisitImplicitCode()) {
2967     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2968     ShouldVisitChildren = false;
2969   }
2970 })
2971 DEF_TRAVERSE_STMT(CoreturnStmt, {
2972   if (!getDerived().shouldVisitImplicitCode()) {
2973     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2974     ShouldVisitChildren = false;
2975   }
2976 })
2977 DEF_TRAVERSE_STMT(CoawaitExpr, {
2978   if (!getDerived().shouldVisitImplicitCode()) {
2979     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2980     ShouldVisitChildren = false;
2981   }
2982 })
2983 DEF_TRAVERSE_STMT(DependentCoawaitExpr, {
2984   if (!getDerived().shouldVisitImplicitCode()) {
2985     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2986     ShouldVisitChildren = false;
2987   }
2988 })
2989 DEF_TRAVERSE_STMT(CoyieldExpr, {
2990   if (!getDerived().shouldVisitImplicitCode()) {
2991     TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2992     ShouldVisitChildren = false;
2993   }
2994 })
2995 
2996 DEF_TRAVERSE_STMT(ConceptSpecializationExpr, {
2997   TRY_TO(TraverseConceptReference(S->getConceptReference()));
2998 })
2999 
3000 DEF_TRAVERSE_STMT(RequiresExpr, {
3001   TRY_TO(TraverseDecl(S->getBody()));
3002   for (ParmVarDecl *Parm : S->getLocalParameters())
3003     TRY_TO(TraverseDecl(Parm));
3004   for (concepts::Requirement *Req : S->getRequirements())
3005     TRY_TO(TraverseConceptRequirement(Req));
3006 })
3007 
3008 // These literals (all of them) do not need any action.
3009 DEF_TRAVERSE_STMT(IntegerLiteral, {})
3010 DEF_TRAVERSE_STMT(FixedPointLiteral, {})
3011 DEF_TRAVERSE_STMT(CharacterLiteral, {})
3012 DEF_TRAVERSE_STMT(FloatingLiteral, {})
3013 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
3014 DEF_TRAVERSE_STMT(StringLiteral, {})
3015 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
3016 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
3017 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
3018 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
3019 
3020 // Traverse OpenCL: AsType, Convert.
3021 DEF_TRAVERSE_STMT(AsTypeExpr, {})
3022 
3023 // OpenMP directives.
3024 template <typename Derived>
3025 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
3026     OMPExecutableDirective *S) {
3027   for (auto *C : S->clauses()) {
3028     TRY_TO(TraverseOMPClause(C));
3029   }
3030   return true;
3031 }
3032 
3033 DEF_TRAVERSE_STMT(OMPCanonicalLoop, {
3034   if (!getDerived().shouldVisitImplicitCode()) {
3035     // Visit only the syntactical loop.
3036     TRY_TO(TraverseStmt(S->getLoopStmt()));
3037     ShouldVisitChildren = false;
3038   }
3039 })
3040 
3041 template <typename Derived>
3042 bool
3043 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
3044   return TraverseOMPExecutableDirective(S);
3045 }
3046 
3047 DEF_TRAVERSE_STMT(OMPMetaDirective,
3048                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3049 
3050 DEF_TRAVERSE_STMT(OMPParallelDirective,
3051                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3052 
3053 DEF_TRAVERSE_STMT(OMPSimdDirective,
3054                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3055 
3056 DEF_TRAVERSE_STMT(OMPTileDirective,
3057                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3058 
3059 DEF_TRAVERSE_STMT(OMPUnrollDirective,
3060                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3061 
3062 DEF_TRAVERSE_STMT(OMPReverseDirective,
3063                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3064 
3065 DEF_TRAVERSE_STMT(OMPInterchangeDirective,
3066                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3067 
3068 DEF_TRAVERSE_STMT(OMPForDirective,
3069                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3070 
3071 DEF_TRAVERSE_STMT(OMPForSimdDirective,
3072                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3073 
3074 DEF_TRAVERSE_STMT(OMPSectionsDirective,
3075                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3076 
3077 DEF_TRAVERSE_STMT(OMPSectionDirective,
3078                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3079 
3080 DEF_TRAVERSE_STMT(OMPScopeDirective,
3081                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3082 
3083 DEF_TRAVERSE_STMT(OMPSingleDirective,
3084                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3085 
3086 DEF_TRAVERSE_STMT(OMPMasterDirective,
3087                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3088 
3089 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
3090   TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
3091   TRY_TO(TraverseOMPExecutableDirective(S));
3092 })
3093 
3094 DEF_TRAVERSE_STMT(OMPParallelForDirective,
3095                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3096 
3097 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
3098                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3099 
3100 DEF_TRAVERSE_STMT(OMPParallelMasterDirective,
3101                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3102 
3103 DEF_TRAVERSE_STMT(OMPParallelMaskedDirective,
3104                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3105 
3106 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
3107                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3108 
3109 DEF_TRAVERSE_STMT(OMPTaskDirective,
3110                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3111 
3112 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
3113                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3114 
3115 DEF_TRAVERSE_STMT(OMPBarrierDirective,
3116                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3117 
3118 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
3119                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3120 
3121 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
3122                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3123 
3124 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
3125                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3126 
3127 DEF_TRAVERSE_STMT(OMPCancelDirective,
3128                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3129 
3130 DEF_TRAVERSE_STMT(OMPFlushDirective,
3131                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3132 
3133 DEF_TRAVERSE_STMT(OMPDepobjDirective,
3134                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3135 
3136 DEF_TRAVERSE_STMT(OMPScanDirective,
3137                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3138 
3139 DEF_TRAVERSE_STMT(OMPOrderedDirective,
3140                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3141 
3142 DEF_TRAVERSE_STMT(OMPAtomicDirective,
3143                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3144 
3145 DEF_TRAVERSE_STMT(OMPTargetDirective,
3146                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3147 
3148 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
3149                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3150 
3151 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
3152                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3153 
3154 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
3155                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3156 
3157 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
3158                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3159 
3160 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
3161                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3162 
3163 DEF_TRAVERSE_STMT(OMPTeamsDirective,
3164                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3165 
3166 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
3167                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3168 
3169 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
3170                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3171 
3172 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
3173                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3174 
3175 DEF_TRAVERSE_STMT(OMPMasterTaskLoopDirective,
3176                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3177 
3178 DEF_TRAVERSE_STMT(OMPMasterTaskLoopSimdDirective,
3179                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3180 
3181 DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopDirective,
3182                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3183 
3184 DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopSimdDirective,
3185                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3186 
3187 DEF_TRAVERSE_STMT(OMPMaskedTaskLoopDirective,
3188                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3189 
3190 DEF_TRAVERSE_STMT(OMPMaskedTaskLoopSimdDirective,
3191                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3192 
3193 DEF_TRAVERSE_STMT(OMPParallelMaskedTaskLoopDirective,
3194                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3195 
3196 DEF_TRAVERSE_STMT(OMPParallelMaskedTaskLoopSimdDirective,
3197                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3198 
3199 DEF_TRAVERSE_STMT(OMPDistributeDirective,
3200                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3201 
3202 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
3203                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3204 
3205 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
3206                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3207 
3208 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
3209                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3210 
3211 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
3212                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3213 
3214 DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
3215                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3216 
3217 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
3218                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3219 
3220 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
3221                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3222 
3223 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
3224                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3225 
3226 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
3227                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3228 
3229 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
3230                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3231 
3232 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
3233                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3234 
3235 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
3236                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3237 
3238 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective,
3239                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3240 
3241 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective,
3242                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3243 
3244 DEF_TRAVERSE_STMT(OMPInteropDirective,
3245                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3246 
3247 DEF_TRAVERSE_STMT(OMPDispatchDirective,
3248                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3249 
3250 DEF_TRAVERSE_STMT(OMPMaskedDirective,
3251                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3252 
3253 DEF_TRAVERSE_STMT(OMPGenericLoopDirective,
3254                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3255 
3256 DEF_TRAVERSE_STMT(OMPTeamsGenericLoopDirective,
3257                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3258 
3259 DEF_TRAVERSE_STMT(OMPTargetTeamsGenericLoopDirective,
3260                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3261 
3262 DEF_TRAVERSE_STMT(OMPParallelGenericLoopDirective,
3263                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3264 
3265 DEF_TRAVERSE_STMT(OMPTargetParallelGenericLoopDirective,
3266                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3267 
3268 DEF_TRAVERSE_STMT(OMPAssumeDirective,
3269                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3270 
3271 DEF_TRAVERSE_STMT(OMPErrorDirective,
3272                   { TRY_TO(TraverseOMPExecutableDirective(S)); })
3273 
3274 // OpenMP clauses.
3275 template <typename Derived>
3276 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
3277   if (!C)
3278     return true;
3279   switch (C->getClauseKind()) {
3280 #define GEN_CLANG_CLAUSE_CLASS
3281 #define CLAUSE_CLASS(Enum, Str, Class)                                         \
3282   case llvm::omp::Clause::Enum:                                                \
3283     TRY_TO(Visit##Class(static_cast<Class *>(C)));                             \
3284     break;
3285 #define CLAUSE_NO_CLASS(Enum, Str)                                             \
3286   case llvm::omp::Clause::Enum:                                                \
3287     break;
3288 #include "llvm/Frontend/OpenMP/OMP.inc"
3289   }
3290   return true;
3291 }
3292 
3293 template <typename Derived>
3294 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
3295     OMPClauseWithPreInit *Node) {
3296   TRY_TO(TraverseStmt(Node->getPreInitStmt()));
3297   return true;
3298 }
3299 
3300 template <typename Derived>
3301 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
3302     OMPClauseWithPostUpdate *Node) {
3303   TRY_TO(VisitOMPClauseWithPreInit(Node));
3304   TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
3305   return true;
3306 }
3307 
3308 template <typename Derived>
3309 bool RecursiveASTVisitor<Derived>::VisitOMPAllocatorClause(
3310     OMPAllocatorClause *C) {
3311   TRY_TO(TraverseStmt(C->getAllocator()));
3312   return true;
3313 }
3314 
3315 template <typename Derived>
3316 bool RecursiveASTVisitor<Derived>::VisitOMPAllocateClause(OMPAllocateClause *C) {
3317   TRY_TO(TraverseStmt(C->getAllocator()));
3318   TRY_TO(VisitOMPClauseList(C));
3319   return true;
3320 }
3321 
3322 template <typename Derived>
3323 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
3324   TRY_TO(VisitOMPClauseWithPreInit(C));
3325   TRY_TO(TraverseStmt(C->getCondition()));
3326   return true;
3327 }
3328 
3329 template <typename Derived>
3330 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
3331   TRY_TO(VisitOMPClauseWithPreInit(C));
3332   TRY_TO(TraverseStmt(C->getCondition()));
3333   return true;
3334 }
3335 
3336 template <typename Derived>
3337 bool
3338 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
3339   TRY_TO(VisitOMPClauseWithPreInit(C));
3340   TRY_TO(TraverseStmt(C->getNumThreads()));
3341   return true;
3342 }
3343 
3344 template <typename Derived>
3345 bool RecursiveASTVisitor<Derived>::VisitOMPAlignClause(OMPAlignClause *C) {
3346   TRY_TO(TraverseStmt(C->getAlignment()));
3347   return true;
3348 }
3349 
3350 template <typename Derived>
3351 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
3352   TRY_TO(TraverseStmt(C->getSafelen()));
3353   return true;
3354 }
3355 
3356 template <typename Derived>
3357 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
3358   TRY_TO(TraverseStmt(C->getSimdlen()));
3359   return true;
3360 }
3361 
3362 template <typename Derived>
3363 bool RecursiveASTVisitor<Derived>::VisitOMPSizesClause(OMPSizesClause *C) {
3364   for (Expr *E : C->getSizesRefs())
3365     TRY_TO(TraverseStmt(E));
3366   return true;
3367 }
3368 
3369 template <typename Derived>
3370 bool RecursiveASTVisitor<Derived>::VisitOMPPermutationClause(
3371     OMPPermutationClause *C) {
3372   for (Expr *E : C->getArgsRefs())
3373     TRY_TO(TraverseStmt(E));
3374   return true;
3375 }
3376 
3377 template <typename Derived>
3378 bool RecursiveASTVisitor<Derived>::VisitOMPFullClause(OMPFullClause *C) {
3379   return true;
3380 }
3381 
3382 template <typename Derived>
3383 bool RecursiveASTVisitor<Derived>::VisitOMPPartialClause(OMPPartialClause *C) {
3384   TRY_TO(TraverseStmt(C->getFactor()));
3385   return true;
3386 }
3387 
3388 template <typename Derived>
3389 bool
3390 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
3391   TRY_TO(TraverseStmt(C->getNumForLoops()));
3392   return true;
3393 }
3394 
3395 template <typename Derived>
3396 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
3397   return true;
3398 }
3399 
3400 template <typename Derived>
3401 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
3402   return true;
3403 }
3404 
3405 template <typename Derived>
3406 bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedAddressClause(
3407     OMPUnifiedAddressClause *) {
3408   return true;
3409 }
3410 
3411 template <typename Derived>
3412 bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedSharedMemoryClause(
3413     OMPUnifiedSharedMemoryClause *) {
3414   return true;
3415 }
3416 
3417 template <typename Derived>
3418 bool RecursiveASTVisitor<Derived>::VisitOMPReverseOffloadClause(
3419     OMPReverseOffloadClause *) {
3420   return true;
3421 }
3422 
3423 template <typename Derived>
3424 bool RecursiveASTVisitor<Derived>::VisitOMPDynamicAllocatorsClause(
3425     OMPDynamicAllocatorsClause *) {
3426   return true;
3427 }
3428 
3429 template <typename Derived>
3430 bool RecursiveASTVisitor<Derived>::VisitOMPAtomicDefaultMemOrderClause(
3431     OMPAtomicDefaultMemOrderClause *) {
3432   return true;
3433 }
3434 
3435 template <typename Derived>
3436 bool RecursiveASTVisitor<Derived>::VisitOMPAtClause(OMPAtClause *) {
3437   return true;
3438 }
3439 
3440 template <typename Derived>
3441 bool RecursiveASTVisitor<Derived>::VisitOMPSeverityClause(OMPSeverityClause *) {
3442   return true;
3443 }
3444 
3445 template <typename Derived>
3446 bool RecursiveASTVisitor<Derived>::VisitOMPMessageClause(OMPMessageClause *C) {
3447   TRY_TO(TraverseStmt(C->getMessageString()));
3448   return true;
3449 }
3450 
3451 template <typename Derived>
3452 bool
3453 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
3454   TRY_TO(VisitOMPClauseWithPreInit(C));
3455   TRY_TO(TraverseStmt(C->getChunkSize()));
3456   return true;
3457 }
3458 
3459 template <typename Derived>
3460 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
3461   TRY_TO(TraverseStmt(C->getNumForLoops()));
3462   return true;
3463 }
3464 
3465 template <typename Derived>
3466 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
3467   return true;
3468 }
3469 
3470 template <typename Derived>
3471 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
3472   return true;
3473 }
3474 
3475 template <typename Derived>
3476 bool
3477 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
3478   return true;
3479 }
3480 
3481 template <typename Derived>
3482 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
3483   return true;
3484 }
3485 
3486 template <typename Derived>
3487 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
3488   return true;
3489 }
3490 
3491 template <typename Derived>
3492 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
3493   return true;
3494 }
3495 
3496 template <typename Derived>
3497 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
3498   return true;
3499 }
3500 
3501 template <typename Derived>
3502 bool RecursiveASTVisitor<Derived>::VisitOMPCompareClause(OMPCompareClause *) {
3503   return true;
3504 }
3505 
3506 template <typename Derived>
3507 bool RecursiveASTVisitor<Derived>::VisitOMPFailClause(OMPFailClause *) {
3508   return true;
3509 }
3510 
3511 template <typename Derived>
3512 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
3513   return true;
3514 }
3515 
3516 template <typename Derived>
3517 bool RecursiveASTVisitor<Derived>::VisitOMPAcqRelClause(OMPAcqRelClause *) {
3518   return true;
3519 }
3520 
3521 template <typename Derived>
3522 bool RecursiveASTVisitor<Derived>::VisitOMPAbsentClause(OMPAbsentClause *) {
3523   return true;
3524 }
3525 
3526 template <typename Derived>
3527 bool RecursiveASTVisitor<Derived>::VisitOMPHoldsClause(OMPHoldsClause *) {
3528   return true;
3529 }
3530 
3531 template <typename Derived>
3532 bool RecursiveASTVisitor<Derived>::VisitOMPContainsClause(OMPContainsClause *) {
3533   return true;
3534 }
3535 
3536 template <typename Derived>
3537 bool RecursiveASTVisitor<Derived>::VisitOMPNoOpenMPClause(OMPNoOpenMPClause *) {
3538   return true;
3539 }
3540 
3541 template <typename Derived>
3542 bool RecursiveASTVisitor<Derived>::VisitOMPNoOpenMPRoutinesClause(
3543     OMPNoOpenMPRoutinesClause *) {
3544   return true;
3545 }
3546 
3547 template <typename Derived>
3548 bool RecursiveASTVisitor<Derived>::VisitOMPNoParallelismClause(
3549     OMPNoParallelismClause *) {
3550   return true;
3551 }
3552 
3553 template <typename Derived>
3554 bool RecursiveASTVisitor<Derived>::VisitOMPAcquireClause(OMPAcquireClause *) {
3555   return true;
3556 }
3557 
3558 template <typename Derived>
3559 bool RecursiveASTVisitor<Derived>::VisitOMPReleaseClause(OMPReleaseClause *) {
3560   return true;
3561 }
3562 
3563 template <typename Derived>
3564 bool RecursiveASTVisitor<Derived>::VisitOMPRelaxedClause(OMPRelaxedClause *) {
3565   return true;
3566 }
3567 
3568 template <typename Derived>
3569 bool RecursiveASTVisitor<Derived>::VisitOMPWeakClause(OMPWeakClause *) {
3570   return true;
3571 }
3572 
3573 template <typename Derived>
3574 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
3575   return true;
3576 }
3577 
3578 template <typename Derived>
3579 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
3580   return true;
3581 }
3582 
3583 template <typename Derived>
3584 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
3585   return true;
3586 }
3587 
3588 template <typename Derived>
3589 bool RecursiveASTVisitor<Derived>::VisitOMPInitClause(OMPInitClause *C) {
3590   TRY_TO(VisitOMPClauseList(C));
3591   return true;
3592 }
3593 
3594 template <typename Derived>
3595 bool RecursiveASTVisitor<Derived>::VisitOMPUseClause(OMPUseClause *C) {
3596   TRY_TO(TraverseStmt(C->getInteropVar()));
3597   return true;
3598 }
3599 
3600 template <typename Derived>
3601 bool RecursiveASTVisitor<Derived>::VisitOMPDestroyClause(OMPDestroyClause *C) {
3602   TRY_TO(TraverseStmt(C->getInteropVar()));
3603   return true;
3604 }
3605 
3606 template <typename Derived>
3607 bool RecursiveASTVisitor<Derived>::VisitOMPNovariantsClause(
3608     OMPNovariantsClause *C) {
3609   TRY_TO(VisitOMPClauseWithPreInit(C));
3610   TRY_TO(TraverseStmt(C->getCondition()));
3611   return true;
3612 }
3613 
3614 template <typename Derived>
3615 bool RecursiveASTVisitor<Derived>::VisitOMPNocontextClause(
3616     OMPNocontextClause *C) {
3617   TRY_TO(VisitOMPClauseWithPreInit(C));
3618   TRY_TO(TraverseStmt(C->getCondition()));
3619   return true;
3620 }
3621 
3622 template <typename Derived>
3623 template <typename T>
3624 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
3625   for (auto *E : Node->varlist()) {
3626     TRY_TO(TraverseStmt(E));
3627   }
3628   return true;
3629 }
3630 
3631 template <typename Derived>
3632 bool RecursiveASTVisitor<Derived>::VisitOMPInclusiveClause(
3633     OMPInclusiveClause *C) {
3634   TRY_TO(VisitOMPClauseList(C));
3635   return true;
3636 }
3637 
3638 template <typename Derived>
3639 bool RecursiveASTVisitor<Derived>::VisitOMPExclusiveClause(
3640     OMPExclusiveClause *C) {
3641   TRY_TO(VisitOMPClauseList(C));
3642   return true;
3643 }
3644 
3645 template <typename Derived>
3646 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
3647   TRY_TO(VisitOMPClauseList(C));
3648   for (auto *E : C->private_copies()) {
3649     TRY_TO(TraverseStmt(E));
3650   }
3651   return true;
3652 }
3653 
3654 template <typename Derived>
3655 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
3656     OMPFirstprivateClause *C) {
3657   TRY_TO(VisitOMPClauseList(C));
3658   TRY_TO(VisitOMPClauseWithPreInit(C));
3659   for (auto *E : C->private_copies()) {
3660     TRY_TO(TraverseStmt(E));
3661   }
3662   for (auto *E : C->inits()) {
3663     TRY_TO(TraverseStmt(E));
3664   }
3665   return true;
3666 }
3667 
3668 template <typename Derived>
3669 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
3670     OMPLastprivateClause *C) {
3671   TRY_TO(VisitOMPClauseList(C));
3672   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3673   for (auto *E : C->private_copies()) {
3674     TRY_TO(TraverseStmt(E));
3675   }
3676   for (auto *E : C->source_exprs()) {
3677     TRY_TO(TraverseStmt(E));
3678   }
3679   for (auto *E : C->destination_exprs()) {
3680     TRY_TO(TraverseStmt(E));
3681   }
3682   for (auto *E : C->assignment_ops()) {
3683     TRY_TO(TraverseStmt(E));
3684   }
3685   return true;
3686 }
3687 
3688 template <typename Derived>
3689 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
3690   TRY_TO(VisitOMPClauseList(C));
3691   return true;
3692 }
3693 
3694 template <typename Derived>
3695 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
3696   TRY_TO(TraverseStmt(C->getStep()));
3697   TRY_TO(TraverseStmt(C->getCalcStep()));
3698   TRY_TO(VisitOMPClauseList(C));
3699   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3700   for (auto *E : C->privates()) {
3701     TRY_TO(TraverseStmt(E));
3702   }
3703   for (auto *E : C->inits()) {
3704     TRY_TO(TraverseStmt(E));
3705   }
3706   for (auto *E : C->updates()) {
3707     TRY_TO(TraverseStmt(E));
3708   }
3709   for (auto *E : C->finals()) {
3710     TRY_TO(TraverseStmt(E));
3711   }
3712   return true;
3713 }
3714 
3715 template <typename Derived>
3716 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
3717   TRY_TO(TraverseStmt(C->getAlignment()));
3718   TRY_TO(VisitOMPClauseList(C));
3719   return true;
3720 }
3721 
3722 template <typename Derived>
3723 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
3724   TRY_TO(VisitOMPClauseList(C));
3725   for (auto *E : C->source_exprs()) {
3726     TRY_TO(TraverseStmt(E));
3727   }
3728   for (auto *E : C->destination_exprs()) {
3729     TRY_TO(TraverseStmt(E));
3730   }
3731   for (auto *E : C->assignment_ops()) {
3732     TRY_TO(TraverseStmt(E));
3733   }
3734   return true;
3735 }
3736 
3737 template <typename Derived>
3738 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
3739     OMPCopyprivateClause *C) {
3740   TRY_TO(VisitOMPClauseList(C));
3741   for (auto *E : C->source_exprs()) {
3742     TRY_TO(TraverseStmt(E));
3743   }
3744   for (auto *E : C->destination_exprs()) {
3745     TRY_TO(TraverseStmt(E));
3746   }
3747   for (auto *E : C->assignment_ops()) {
3748     TRY_TO(TraverseStmt(E));
3749   }
3750   return true;
3751 }
3752 
3753 template <typename Derived>
3754 bool
3755 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
3756   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3757   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3758   TRY_TO(VisitOMPClauseList(C));
3759   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3760   for (auto *E : C->privates()) {
3761     TRY_TO(TraverseStmt(E));
3762   }
3763   for (auto *E : C->lhs_exprs()) {
3764     TRY_TO(TraverseStmt(E));
3765   }
3766   for (auto *E : C->rhs_exprs()) {
3767     TRY_TO(TraverseStmt(E));
3768   }
3769   for (auto *E : C->reduction_ops()) {
3770     TRY_TO(TraverseStmt(E));
3771   }
3772   if (C->getModifier() == OMPC_REDUCTION_inscan) {
3773     for (auto *E : C->copy_ops()) {
3774       TRY_TO(TraverseStmt(E));
3775     }
3776     for (auto *E : C->copy_array_temps()) {
3777       TRY_TO(TraverseStmt(E));
3778     }
3779     for (auto *E : C->copy_array_elems()) {
3780       TRY_TO(TraverseStmt(E));
3781     }
3782   }
3783   return true;
3784 }
3785 
3786 template <typename Derived>
3787 bool RecursiveASTVisitor<Derived>::VisitOMPTaskReductionClause(
3788     OMPTaskReductionClause *C) {
3789   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3790   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3791   TRY_TO(VisitOMPClauseList(C));
3792   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3793   for (auto *E : C->privates()) {
3794     TRY_TO(TraverseStmt(E));
3795   }
3796   for (auto *E : C->lhs_exprs()) {
3797     TRY_TO(TraverseStmt(E));
3798   }
3799   for (auto *E : C->rhs_exprs()) {
3800     TRY_TO(TraverseStmt(E));
3801   }
3802   for (auto *E : C->reduction_ops()) {
3803     TRY_TO(TraverseStmt(E));
3804   }
3805   return true;
3806 }
3807 
3808 template <typename Derived>
3809 bool RecursiveASTVisitor<Derived>::VisitOMPInReductionClause(
3810     OMPInReductionClause *C) {
3811   TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3812   TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3813   TRY_TO(VisitOMPClauseList(C));
3814   TRY_TO(VisitOMPClauseWithPostUpdate(C));
3815   for (auto *E : C->privates()) {
3816     TRY_TO(TraverseStmt(E));
3817   }
3818   for (auto *E : C->lhs_exprs()) {
3819     TRY_TO(TraverseStmt(E));
3820   }
3821   for (auto *E : C->rhs_exprs()) {
3822     TRY_TO(TraverseStmt(E));
3823   }
3824   for (auto *E : C->reduction_ops()) {
3825     TRY_TO(TraverseStmt(E));
3826   }
3827   for (auto *E : C->taskgroup_descriptors())
3828     TRY_TO(TraverseStmt(E));
3829   return true;
3830 }
3831 
3832 template <typename Derived>
3833 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
3834   TRY_TO(VisitOMPClauseList(C));
3835   return true;
3836 }
3837 
3838 template <typename Derived>
3839 bool RecursiveASTVisitor<Derived>::VisitOMPDepobjClause(OMPDepobjClause *C) {
3840   TRY_TO(TraverseStmt(C->getDepobj()));
3841   return true;
3842 }
3843 
3844 template <typename Derived>
3845 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
3846   TRY_TO(VisitOMPClauseList(C));
3847   return true;
3848 }
3849 
3850 template <typename Derived>
3851 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
3852   TRY_TO(VisitOMPClauseWithPreInit(C));
3853   TRY_TO(TraverseStmt(C->getDevice()));
3854   return true;
3855 }
3856 
3857 template <typename Derived>
3858 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
3859   TRY_TO(VisitOMPClauseList(C));
3860   return true;
3861 }
3862 
3863 template <typename Derived>
3864 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
3865     OMPNumTeamsClause *C) {
3866   TRY_TO(VisitOMPClauseList(C));
3867   TRY_TO(VisitOMPClauseWithPreInit(C));
3868   return true;
3869 }
3870 
3871 template <typename Derived>
3872 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
3873     OMPThreadLimitClause *C) {
3874   TRY_TO(VisitOMPClauseList(C));
3875   TRY_TO(VisitOMPClauseWithPreInit(C));
3876   return true;
3877 }
3878 
3879 template <typename Derived>
3880 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
3881     OMPPriorityClause *C) {
3882   TRY_TO(VisitOMPClauseWithPreInit(C));
3883   TRY_TO(TraverseStmt(C->getPriority()));
3884   return true;
3885 }
3886 
3887 template <typename Derived>
3888 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
3889     OMPGrainsizeClause *C) {
3890   TRY_TO(VisitOMPClauseWithPreInit(C));
3891   TRY_TO(TraverseStmt(C->getGrainsize()));
3892   return true;
3893 }
3894 
3895 template <typename Derived>
3896 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
3897     OMPNumTasksClause *C) {
3898   TRY_TO(VisitOMPClauseWithPreInit(C));
3899   TRY_TO(TraverseStmt(C->getNumTasks()));
3900   return true;
3901 }
3902 
3903 template <typename Derived>
3904 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
3905   TRY_TO(TraverseStmt(C->getHint()));
3906   return true;
3907 }
3908 
3909 template <typename Derived>
3910 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
3911     OMPDistScheduleClause *C) {
3912   TRY_TO(VisitOMPClauseWithPreInit(C));
3913   TRY_TO(TraverseStmt(C->getChunkSize()));
3914   return true;
3915 }
3916 
3917 template <typename Derived>
3918 bool
3919 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
3920   return true;
3921 }
3922 
3923 template <typename Derived>
3924 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
3925   TRY_TO(VisitOMPClauseList(C));
3926   return true;
3927 }
3928 
3929 template <typename Derived>
3930 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
3931   TRY_TO(VisitOMPClauseList(C));
3932   return true;
3933 }
3934 
3935 template <typename Derived>
3936 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
3937     OMPUseDevicePtrClause *C) {
3938   TRY_TO(VisitOMPClauseList(C));
3939   return true;
3940 }
3941 
3942 template <typename Derived>
3943 bool RecursiveASTVisitor<Derived>::VisitOMPUseDeviceAddrClause(
3944     OMPUseDeviceAddrClause *C) {
3945   TRY_TO(VisitOMPClauseList(C));
3946   return true;
3947 }
3948 
3949 template <typename Derived>
3950 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
3951     OMPIsDevicePtrClause *C) {
3952   TRY_TO(VisitOMPClauseList(C));
3953   return true;
3954 }
3955 
3956 template <typename Derived>
3957 bool RecursiveASTVisitor<Derived>::VisitOMPHasDeviceAddrClause(
3958     OMPHasDeviceAddrClause *C) {
3959   TRY_TO(VisitOMPClauseList(C));
3960   return true;
3961 }
3962 
3963 template <typename Derived>
3964 bool RecursiveASTVisitor<Derived>::VisitOMPNontemporalClause(
3965     OMPNontemporalClause *C) {
3966   TRY_TO(VisitOMPClauseList(C));
3967   for (auto *E : C->private_refs()) {
3968     TRY_TO(TraverseStmt(E));
3969   }
3970   return true;
3971 }
3972 
3973 template <typename Derived>
3974 bool RecursiveASTVisitor<Derived>::VisitOMPOrderClause(OMPOrderClause *) {
3975   return true;
3976 }
3977 
3978 template <typename Derived>
3979 bool RecursiveASTVisitor<Derived>::VisitOMPDetachClause(OMPDetachClause *C) {
3980   TRY_TO(TraverseStmt(C->getEventHandler()));
3981   return true;
3982 }
3983 
3984 template <typename Derived>
3985 bool RecursiveASTVisitor<Derived>::VisitOMPUsesAllocatorsClause(
3986     OMPUsesAllocatorsClause *C) {
3987   for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
3988     const OMPUsesAllocatorsClause::Data Data = C->getAllocatorData(I);
3989     TRY_TO(TraverseStmt(Data.Allocator));
3990     TRY_TO(TraverseStmt(Data.AllocatorTraits));
3991   }
3992   return true;
3993 }
3994 
3995 template <typename Derived>
3996 bool RecursiveASTVisitor<Derived>::VisitOMPAffinityClause(
3997     OMPAffinityClause *C) {
3998   TRY_TO(TraverseStmt(C->getModifier()));
3999   for (Expr *E : C->varlist())
4000     TRY_TO(TraverseStmt(E));
4001   return true;
4002 }
4003 
4004 template <typename Derived>
4005 bool RecursiveASTVisitor<Derived>::VisitOMPFilterClause(OMPFilterClause *C) {
4006   TRY_TO(VisitOMPClauseWithPreInit(C));
4007   TRY_TO(TraverseStmt(C->getThreadID()));
4008   return true;
4009 }
4010 
4011 template <typename Derived>
4012 bool RecursiveASTVisitor<Derived>::VisitOMPBindClause(OMPBindClause *C) {
4013   return true;
4014 }
4015 
4016 template <typename Derived>
4017 bool RecursiveASTVisitor<Derived>::VisitOMPXDynCGroupMemClause(
4018     OMPXDynCGroupMemClause *C) {
4019   TRY_TO(VisitOMPClauseWithPreInit(C));
4020   TRY_TO(TraverseStmt(C->getSize()));
4021   return true;
4022 }
4023 
4024 template <typename Derived>
4025 bool RecursiveASTVisitor<Derived>::VisitOMPDoacrossClause(
4026     OMPDoacrossClause *C) {
4027   TRY_TO(VisitOMPClauseList(C));
4028   return true;
4029 }
4030 
4031 template <typename Derived>
4032 bool RecursiveASTVisitor<Derived>::VisitOMPXAttributeClause(
4033     OMPXAttributeClause *C) {
4034   return true;
4035 }
4036 
4037 template <typename Derived>
4038 bool RecursiveASTVisitor<Derived>::VisitOMPXBareClause(OMPXBareClause *C) {
4039   return true;
4040 }
4041 
4042 template <typename Derived>
4043 bool RecursiveASTVisitor<Derived>::TraverseOpenACCConstructStmt(
4044     OpenACCConstructStmt *C) {
4045   TRY_TO(VisitOpenACCClauseList(C->clauses()));
4046   return true;
4047 }
4048 
4049 template <typename Derived>
4050 bool RecursiveASTVisitor<Derived>::TraverseOpenACCAssociatedStmtConstruct(
4051     OpenACCAssociatedStmtConstruct *S) {
4052   TRY_TO(TraverseOpenACCConstructStmt(S));
4053   TRY_TO(TraverseStmt(S->getAssociatedStmt()));
4054   return true;
4055 }
4056 
4057 template <typename Derived>
4058 bool RecursiveASTVisitor<Derived>::VisitOpenACCClause(const OpenACCClause *C) {
4059   for (const Stmt *Child : C->children())
4060     TRY_TO(TraverseStmt(const_cast<Stmt *>(Child)));
4061   return true;
4062 }
4063 
4064 template <typename Derived>
4065 bool RecursiveASTVisitor<Derived>::VisitOpenACCClauseList(
4066     ArrayRef<const OpenACCClause *> Clauses) {
4067 
4068   for (const auto *C : Clauses)
4069     TRY_TO(VisitOpenACCClause(C));
4070   return true;
4071 }
4072 
4073 DEF_TRAVERSE_STMT(OpenACCComputeConstruct,
4074                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4075 DEF_TRAVERSE_STMT(OpenACCLoopConstruct,
4076                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4077 DEF_TRAVERSE_STMT(OpenACCCombinedConstruct,
4078                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4079 DEF_TRAVERSE_STMT(OpenACCDataConstruct,
4080                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4081 DEF_TRAVERSE_STMT(OpenACCEnterDataConstruct,
4082                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4083 DEF_TRAVERSE_STMT(OpenACCExitDataConstruct,
4084                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4085 DEF_TRAVERSE_STMT(OpenACCHostDataConstruct,
4086                   { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
4087 DEF_TRAVERSE_STMT(OpenACCWaitConstruct, {
4088   if (S->hasDevNumExpr())
4089     TRY_TO(TraverseStmt(S->getDevNumExpr()));
4090   for (auto *E : S->getQueueIdExprs())
4091     TRY_TO(TraverseStmt(E));
4092   TRY_TO(VisitOpenACCClauseList(S->clauses()));
4093 })
4094 DEF_TRAVERSE_STMT(OpenACCInitConstruct,
4095                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4096 DEF_TRAVERSE_STMT(OpenACCShutdownConstruct,
4097                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4098 DEF_TRAVERSE_STMT(OpenACCSetConstruct,
4099                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4100 DEF_TRAVERSE_STMT(OpenACCUpdateConstruct,
4101                   { TRY_TO(VisitOpenACCClauseList(S->clauses())); })
4102 
4103 // Traverse HLSL: Out argument expression
4104 DEF_TRAVERSE_STMT(HLSLOutArgExpr, {})
4105 
4106 // FIXME: look at the following tricky-seeming exprs to see if we
4107 // need to recurse on anything.  These are ones that have methods
4108 // returning decls or qualtypes or nestednamespecifier -- though I'm
4109 // not sure if they own them -- or just seemed very complicated, or
4110 // had lots of sub-types to explore.
4111 //
4112 // VisitOverloadExpr and its children: recurse on template args? etc?
4113 
4114 // FIXME: go through all the stmts and exprs again, and see which of them
4115 // create new types, and recurse on the types (TypeLocs?) of those.
4116 // Candidates:
4117 //
4118 //    http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
4119 //    http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
4120 //    http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
4121 //    Every class that has getQualifier.
4122 
4123 #undef DEF_TRAVERSE_STMT
4124 #undef TRAVERSE_STMT
4125 #undef TRAVERSE_STMT_BASE
4126 
4127 #undef TRY_TO
4128 
4129 } // end namespace clang
4130 
4131 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
4132