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