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