clang  5.0.0
RecursiveASTVisitor.h
Go to the documentation of this file.
1 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the RecursiveASTVisitor interface, which recursively
11 // traverses the entire AST.
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
15 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
16 
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Decl.h"
20 #include "clang/AST/DeclBase.h"
21 #include "clang/AST/DeclCXX.h"
22 #include "clang/AST/DeclFriend.h"
23 #include "clang/AST/DeclObjC.h"
24 #include "clang/AST/DeclOpenMP.h"
25 #include "clang/AST/DeclTemplate.h"
26 #include "clang/AST/Expr.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 // The following three macros are used for meta programming. The code
52 // using them is responsible for defining macro OPERATOR().
53 
54 // All unary operators.
55 #define UNARYOP_LIST() \
56  OPERATOR(PostInc) OPERATOR(PostDec) OPERATOR(PreInc) OPERATOR(PreDec) \
57  OPERATOR(AddrOf) OPERATOR(Deref) OPERATOR(Plus) OPERATOR(Minus) \
58  OPERATOR(Not) OPERATOR(LNot) OPERATOR(Real) OPERATOR(Imag) \
59  OPERATOR(Extension) OPERATOR(Coawait)
60 
61 // All binary operators (excluding compound assign operators).
62 #define BINOP_LIST() \
63  OPERATOR(PtrMemD) OPERATOR(PtrMemI) OPERATOR(Mul) OPERATOR(Div) \
64  OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) OPERATOR(Shr) \
65  OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) OPERATOR(GE) OPERATOR(EQ) \
66  OPERATOR(NE) OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) OPERATOR(LAnd) \
67  OPERATOR(LOr) OPERATOR(Assign) OPERATOR(Comma)
68 
69 // All compound assign operators.
70 #define CAO_LIST() \
71  OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \
72  OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor)
73 
74 namespace clang {
75 
76 // A helper macro to implement short-circuiting when recursing. It
77 // invokes CALL_EXPR, which must be a method call, on the derived
78 // object (s.t. a user of RecursiveASTVisitor can override the method
79 // in CALL_EXPR).
80 #define TRY_TO(CALL_EXPR) \
81  do { \
82  if (!getDerived().CALL_EXPR) \
83  return false; \
84  } while (false)
85 
86 /// \brief A class that does preordor or postorder
87 /// depth-first traversal on the entire Clang AST and visits each node.
88 ///
89 /// This class performs three distinct tasks:
90 /// 1. traverse the AST (i.e. go to each node);
91 /// 2. at a given node, walk up the class hierarchy, starting from
92 /// the node's dynamic type, until the top-most class (e.g. Stmt,
93 /// Decl, or Type) is reached.
94 /// 3. given a (node, class) combination, where 'class' is some base
95 /// class of the dynamic type of 'node', call a user-overridable
96 /// function to actually visit the node.
97 ///
98 /// These tasks are done by three groups of methods, respectively:
99 /// 1. TraverseDecl(Decl *x) does task #1. It is the entry point
100 /// for traversing an AST rooted at x. This method simply
101 /// dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
102 /// is the dynamic type of *x, which calls WalkUpFromFoo(x) and
103 /// then recursively visits the child nodes of x.
104 /// TraverseStmt(Stmt *x) and TraverseType(QualType x) work
105 /// similarly.
106 /// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit
107 /// any child node of x. Instead, it first calls WalkUpFromBar(x)
108 /// where Bar is the direct parent class of Foo (unless Foo has
109 /// no parent), and then calls VisitFoo(x) (see the next list item).
110 /// 3. VisitFoo(Foo *x) does task #3.
111 ///
112 /// These three method groups are tiered (Traverse* > WalkUpFrom* >
113 /// Visit*). A method (e.g. Traverse*) may call methods from the same
114 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
115 /// It may not call methods from a higher tier.
116 ///
117 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
118 /// is Foo's super class) before calling VisitFoo(), the result is
119 /// that the Visit*() methods for a given node are called in the
120 /// top-down order (e.g. for a node of type NamespaceDecl, the order will
121 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
122 ///
123 /// This scheme guarantees that all Visit*() calls for the same AST
124 /// node are grouped together. In other words, Visit*() methods for
125 /// different nodes are never interleaved.
126 ///
127 /// Clients of this visitor should subclass the visitor (providing
128 /// themselves as the template argument, using the curiously recurring
129 /// template pattern) and override any of the Traverse*, WalkUpFrom*,
130 /// and Visit* methods for declarations, types, statements,
131 /// expressions, or other AST nodes where the visitor should customize
132 /// behavior. Most users only need to override Visit*. Advanced
133 /// users may override Traverse* and WalkUpFrom* to implement custom
134 /// traversal strategies. Returning false from one of these overridden
135 /// functions will abort the entire traversal.
136 ///
137 /// By default, this visitor tries to visit every part of the explicit
138 /// source code exactly once. The default policy towards templates
139 /// is to descend into the 'pattern' class or function body, not any
140 /// explicit or implicit instantiations. Explicit specializations
141 /// are still visited, and the patterns of partial specializations
142 /// are visited separately. This behavior can be changed by
143 /// overriding shouldVisitTemplateInstantiations() in the derived class
144 /// to return true, in which case all known implicit and explicit
145 /// instantiations will be visited at the same time as the pattern
146 /// from which they were produced.
147 ///
148 /// By default, this visitor preorder traverses the AST. If postorder traversal
149 /// is needed, the \c shouldTraversePostOrder method needs to be overriden
150 /// to return \c true.
151 template <typename Derived> class RecursiveASTVisitor {
152 public:
153  /// A queue used for performing data recursion over statements.
154  /// Parameters involving this type are used to implement data
155  /// recursion over Stmts and Exprs within this class, and should
156  /// typically not be explicitly specified by derived classes.
157  /// The bool bit indicates whether the statement has been traversed or not.
160 
161  /// \brief Return a reference to the derived class.
162  Derived &getDerived() { return *static_cast<Derived *>(this); }
163 
164  /// \brief Return whether this visitor should recurse into
165  /// template instantiations.
166  bool shouldVisitTemplateInstantiations() const { return false; }
167 
168  /// \brief Return whether this visitor should recurse into the types of
169  /// TypeLocs.
170  bool shouldWalkTypesOfTypeLocs() const { return true; }
171 
172  /// \brief Return whether this visitor should recurse into implicit
173  /// code, e.g., implicit constructors and destructors.
174  bool shouldVisitImplicitCode() const { return false; }
175 
176  /// \brief Return whether this visitor should traverse post-order.
177  bool shouldTraversePostOrder() const { return false; }
178 
179  /// \brief Recursively visit a statement or expression, by
180  /// dispatching to Traverse*() based on the argument's dynamic type.
181  ///
182  /// \returns false if the visitation was terminated early, true
183  /// otherwise (including when the argument is nullptr).
184  bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr);
185 
186  /// Invoked before visiting a statement or expression via data recursion.
187  ///
188  /// \returns false to skip visiting the node, true otherwise.
189  bool dataTraverseStmtPre(Stmt *S) { return true; }
190 
191  /// Invoked after visiting a statement or expression via data recursion.
192  /// This is not invoked if the previously invoked \c dataTraverseStmtPre
193  /// returned false.
194  ///
195  /// \returns false if the visitation was terminated early, true otherwise.
196  bool dataTraverseStmtPost(Stmt *S) { return true; }
197 
198  /// \brief Recursively visit a type, by dispatching to
199  /// Traverse*Type() based on the argument's getTypeClass() property.
200  ///
201  /// \returns false if the visitation was terminated early, true
202  /// otherwise (including when the argument is a Null type).
203  bool TraverseType(QualType T);
204 
205  /// \brief Recursively visit a type with location, by dispatching to
206  /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
207  ///
208  /// \returns false if the visitation was terminated early, true
209  /// otherwise (including when the argument is a Null type location).
210  bool TraverseTypeLoc(TypeLoc TL);
211 
212  /// \brief Recursively visit an attribute, by dispatching to
213  /// Traverse*Attr() based on the argument's dynamic type.
214  ///
215  /// \returns false if the visitation was terminated early, true
216  /// otherwise (including when the argument is a Null type location).
217  bool TraverseAttr(Attr *At);
218 
219  /// \brief Recursively visit a declaration, by dispatching to
220  /// Traverse*Decl() based on the argument's dynamic type.
221  ///
222  /// \returns false if the visitation was terminated early, true
223  /// otherwise (including when the argument is NULL).
224  bool TraverseDecl(Decl *D);
225 
226  /// \brief Recursively visit a C++ nested-name-specifier.
227  ///
228  /// \returns false if the visitation was terminated early, true otherwise.
230 
231  /// \brief Recursively visit a C++ nested-name-specifier with location
232  /// information.
233  ///
234  /// \returns false if the visitation was terminated early, true otherwise.
236 
237  /// \brief Recursively visit a name with its location information.
238  ///
239  /// \returns false if the visitation was terminated early, true otherwise.
241 
242  /// \brief Recursively visit a template name and dispatch to the
243  /// appropriate method.
244  ///
245  /// \returns false if the visitation was terminated early, true otherwise.
246  bool TraverseTemplateName(TemplateName Template);
247 
248  /// \brief Recursively visit a template argument and dispatch to the
249  /// appropriate method for the argument type.
250  ///
251  /// \returns false if the visitation was terminated early, true otherwise.
252  // FIXME: migrate callers to TemplateArgumentLoc instead.
254 
255  /// \brief Recursively visit a template argument location and dispatch to the
256  /// appropriate method for the argument type.
257  ///
258  /// \returns false if the visitation was terminated early, true otherwise.
260 
261  /// \brief Recursively visit a set of template arguments.
262  /// This can be overridden by a subclass, but it's not expected that
263  /// will be needed -- this visitor always dispatches to another.
264  ///
265  /// \returns false if the visitation was terminated early, true otherwise.
266  // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
268  unsigned NumArgs);
269 
270  /// \brief Recursively visit a constructor initializer. This
271  /// automatically dispatches to another visitor for the initializer
272  /// expression, but not for the name of the initializer, so may
273  /// be overridden for clients that need access to the name.
274  ///
275  /// \returns false if the visitation was terminated early, true otherwise.
277 
278  /// \brief Recursively visit a lambda capture. \c Init is the expression that
279  /// will be used to initialize the capture.
280  ///
281  /// \returns false if the visitation was terminated early, true otherwise.
283  Expr *Init);
284 
285  /// \brief Recursively visit the body of a lambda expression.
286  ///
287  /// This provides a hook for visitors that need more context when visiting
288  /// \c LE->getBody().
289  ///
290  /// \returns false if the visitation was terminated early, true otherwise.
291  bool TraverseLambdaBody(LambdaExpr *LE, DataRecursionQueue *Queue = nullptr);
292 
293  /// \brief Recursively visit the syntactic or semantic form of an
294  /// initialization list.
295  ///
296  /// \returns false if the visitation was terminated early, true otherwise.
298  DataRecursionQueue *Queue = nullptr);
299 
300  // ---- Methods on Attrs ----
301 
302  // \brief Visit an attribute.
303  bool VisitAttr(Attr *A) { return true; }
304 
305 // Declare Traverse* and empty Visit* for all Attr classes.
306 #define ATTR_VISITOR_DECLS_ONLY
307 #include "clang/AST/AttrVisitor.inc"
308 #undef ATTR_VISITOR_DECLS_ONLY
309 
310 // ---- Methods on Stmts ----
311 
312 private:
313  template<typename T, typename U>
314  struct has_same_member_pointer_type : std::false_type {};
315  template<typename T, typename U, typename R, typename... P>
316  struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
317  : std::true_type {};
318 
319  // Traverse the given statement. If the most-derived traverse function takes a
320  // data recursion queue, pass it on; otherwise, discard it. Note that the
321  // first branch of this conditional must compile whether or not the derived
322  // class can take a queue, so if we're taking the second arm, make the first
323  // arm call our function rather than the derived class version.
324 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE) \
325  (has_same_member_pointer_type<decltype( \
326  &RecursiveASTVisitor::Traverse##NAME), \
327  decltype(&Derived::Traverse##NAME)>::value \
328  ? static_cast<typename std::conditional< \
329  has_same_member_pointer_type< \
330  decltype(&RecursiveASTVisitor::Traverse##NAME), \
331  decltype(&Derived::Traverse##NAME)>::value, \
332  Derived &, RecursiveASTVisitor &>::type>(*this) \
333  .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE) \
334  : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
335 
336 // Try to traverse the given statement, or enqueue it if we're performing data
337 // recursion in the middle of traversing another statement. Can only be called
338 // from within a DEF_TRAVERSE_STMT body or similar context.
339 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S) \
340  do { \
341  if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue)) \
342  return false; \
343  } while (false)
344 
345 public:
346 // Declare Traverse*() for all concrete Stmt classes.
347 #define ABSTRACT_STMT(STMT)
348 #define STMT(CLASS, PARENT) \
349  bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
350 #include "clang/AST/StmtNodes.inc"
351  // The above header #undefs ABSTRACT_STMT and STMT upon exit.
352 
353  // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
354  bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
355  bool VisitStmt(Stmt *S) { return true; }
356 #define STMT(CLASS, PARENT) \
357  bool WalkUpFrom##CLASS(CLASS *S) { \
358  TRY_TO(WalkUpFrom##PARENT(S)); \
359  TRY_TO(Visit##CLASS(S)); \
360  return true; \
361  } \
362  bool Visit##CLASS(CLASS *S) { return true; }
363 #include "clang/AST/StmtNodes.inc"
364 
365 // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
366 // operator methods. Unary operators are not classes in themselves
367 // (they're all opcodes in UnaryOperator) but do have visitors.
368 #define OPERATOR(NAME) \
369  bool TraverseUnary##NAME(UnaryOperator *S, \
370  DataRecursionQueue *Queue = nullptr) { \
371  if (!getDerived().shouldTraversePostOrder()) \
372  TRY_TO(WalkUpFromUnary##NAME(S)); \
373  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \
374  return true; \
375  } \
376  bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
377  TRY_TO(WalkUpFromUnaryOperator(S)); \
378  TRY_TO(VisitUnary##NAME(S)); \
379  return true; \
380  } \
381  bool VisitUnary##NAME(UnaryOperator *S) { return true; }
382 
383  UNARYOP_LIST()
384 #undef OPERATOR
385 
386 // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
387 // operator methods. Binary operators are not classes in themselves
388 // (they're all opcodes in BinaryOperator) but do have visitors.
389 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \
390  bool TraverseBin##NAME(BINOP_TYPE *S, DataRecursionQueue *Queue = nullptr) { \
391  if (!getDerived().shouldTraversePostOrder()) \
392  TRY_TO(WalkUpFromBin##NAME(S)); \
393  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS()); \
394  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS()); \
395  return true; \
396  } \
397  bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
398  TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \
399  TRY_TO(VisitBin##NAME(S)); \
400  return true; \
401  } \
402  bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
403 
404 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
405  BINOP_LIST()
406 #undef OPERATOR
407 
408 // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
409 // assignment methods. Compound assignment operators are not
410 // classes in themselves (they're all opcodes in
411 // CompoundAssignOperator) but do have visitors.
412 #define OPERATOR(NAME) \
413  GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
414 
415  CAO_LIST()
416 #undef OPERATOR
417 #undef GENERAL_BINOP_FALLBACK
418 
419 // ---- Methods on Types ----
420 // FIXME: revamp to take TypeLoc's rather than Types.
421 
422 // Declare Traverse*() for all concrete Type classes.
423 #define ABSTRACT_TYPE(CLASS, BASE)
424 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
425 #include "clang/AST/TypeNodes.def"
426  // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
427 
428  // Define WalkUpFrom*() and empty Visit*() for all Type classes.
429  bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
430  bool VisitType(Type *T) { return true; }
431 #define TYPE(CLASS, BASE) \
432  bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \
433  TRY_TO(WalkUpFrom##BASE(T)); \
434  TRY_TO(Visit##CLASS##Type(T)); \
435  return true; \
436  } \
437  bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
438 #include "clang/AST/TypeNodes.def"
439 
440 // ---- Methods on TypeLocs ----
441 // FIXME: this currently just calls the matching Type methods
442 
443 // Declare Traverse*() for all concrete TypeLoc classes.
444 #define ABSTRACT_TYPELOC(CLASS, BASE)
445 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
446 #include "clang/AST/TypeLocNodes.def"
447  // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
448 
449  // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
450  bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
451  bool VisitTypeLoc(TypeLoc TL) { return true; }
452 
453  // QualifiedTypeLoc and UnqualTypeLoc are not declared in
454  // TypeNodes.def and thus need to be handled specially.
456  return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
457  }
458  bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
460  return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
461  }
462  bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
463 
464 // Note that BASE includes trailing 'Type' which CLASS doesn't.
465 #define TYPE(CLASS, BASE) \
466  bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
467  TRY_TO(WalkUpFrom##BASE##Loc(TL)); \
468  TRY_TO(Visit##CLASS##TypeLoc(TL)); \
469  return true; \
470  } \
471  bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
472 #include "clang/AST/TypeNodes.def"
473 
474 // ---- Methods on Decls ----
475 
476 // Declare Traverse*() for all concrete Decl classes.
477 #define ABSTRACT_DECL(DECL)
478 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
479 #include "clang/AST/DeclNodes.inc"
480  // The above header #undefs ABSTRACT_DECL and DECL upon exit.
481 
482  // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
483  bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
484  bool VisitDecl(Decl *D) { return true; }
485 #define DECL(CLASS, BASE) \
486  bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \
487  TRY_TO(WalkUpFrom##BASE(D)); \
488  TRY_TO(Visit##CLASS##Decl(D)); \
489  return true; \
490  } \
491  bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
492 #include "clang/AST/DeclNodes.inc"
493 
494 private:
495  // These are helper methods used by more than one Traverse* method.
496  bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
497 
498  // Traverses template parameter lists of either a DeclaratorDecl or TagDecl.
499  template <typename T>
500  bool TraverseDeclTemplateParameterLists(T *D);
501 
502 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND) \
503  bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
506  DEF_TRAVERSE_TMPL_INST(Function)
507 #undef DEF_TRAVERSE_TMPL_INST
508  bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
509  unsigned Count);
510  bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
511  bool TraverseRecordHelper(RecordDecl *D);
512  bool TraverseCXXRecordHelper(CXXRecordDecl *D);
513  bool TraverseDeclaratorHelper(DeclaratorDecl *D);
514  bool TraverseDeclContextHelper(DeclContext *DC);
515  bool TraverseFunctionHelper(FunctionDecl *D);
516  bool TraverseVarHelper(VarDecl *D);
517  bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
518  bool TraverseOMPLoopDirective(OMPLoopDirective *S);
519  bool TraverseOMPClause(OMPClause *C);
520 #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C);
521 #include "clang/Basic/OpenMPKinds.def"
522  /// \brief Process clauses with list of variables.
523  template <typename T> bool VisitOMPClauseList(T *Node);
524  /// Process clauses with pre-initis.
525  bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
526  bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
527 
528  bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
529  bool PostVisitStmt(Stmt *S);
530 };
531 
532 template <typename Derived>
533 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
534  DataRecursionQueue *Queue) {
535 #define DISPATCH_STMT(NAME, CLASS, VAR) \
536  return TRAVERSE_STMT_BASE(NAME, CLASS, VAR, Queue);
537 
538  // If we have a binary expr, dispatch to the subcode of the binop. A smart
539  // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
540  // below.
541  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
542  switch (BinOp->getOpcode()) {
543 #define OPERATOR(NAME) \
544  case BO_##NAME: \
545  DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
546 
547  BINOP_LIST()
548 #undef OPERATOR
549 #undef BINOP_LIST
550 
551 #define OPERATOR(NAME) \
552  case BO_##NAME##Assign: \
553  DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
554 
555  CAO_LIST()
556 #undef OPERATOR
557 #undef CAO_LIST
558  }
559  } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
560  switch (UnOp->getOpcode()) {
561 #define OPERATOR(NAME) \
562  case UO_##NAME: \
563  DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
564 
565  UNARYOP_LIST()
566 #undef OPERATOR
567 #undef UNARYOP_LIST
568  }
569  }
570 
571  // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
572  switch (S->getStmtClass()) {
573  case Stmt::NoStmtClass:
574  break;
575 #define ABSTRACT_STMT(STMT)
576 #define STMT(CLASS, PARENT) \
577  case Stmt::CLASS##Class: \
578  DISPATCH_STMT(CLASS, CLASS, S);
579 #include "clang/AST/StmtNodes.inc"
580  }
581 
582  return true;
583 }
584 
585 #undef DISPATCH_STMT
586 
587 template <typename Derived>
588 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
589  switch (S->getStmtClass()) {
590  case Stmt::NoStmtClass:
591  break;
592 #define ABSTRACT_STMT(STMT)
593 #define STMT(CLASS, PARENT) \
594  case Stmt::CLASS##Class: \
595  TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S))); break;
596 #define INITLISTEXPR(CLASS, PARENT) \
597  case Stmt::CLASS##Class: \
598  { \
599  auto ILE = static_cast<CLASS *>(S); \
600  if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE) \
601  TRY_TO(WalkUpFrom##CLASS(Syn)); \
602  if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \
603  TRY_TO(WalkUpFrom##CLASS(Sem)); \
604  break; \
605  }
606 #include "clang/AST/StmtNodes.inc"
607  }
608 
609  return true;
610 }
611 
612 #undef DISPATCH_STMT
613 
614 template <typename Derived>
616  DataRecursionQueue *Queue) {
617  if (!S)
618  return true;
619 
620  if (Queue) {
621  Queue->push_back({S, false});
622  return true;
623  }
624 
626  LocalQueue.push_back({S, false});
627 
628  while (!LocalQueue.empty()) {
629  auto &CurrSAndVisited = LocalQueue.back();
630  Stmt *CurrS = CurrSAndVisited.getPointer();
631  bool Visited = CurrSAndVisited.getInt();
632  if (Visited) {
633  LocalQueue.pop_back();
634  TRY_TO(dataTraverseStmtPost(CurrS));
635  if (getDerived().shouldTraversePostOrder()) {
636  TRY_TO(PostVisitStmt(CurrS));
637  }
638  continue;
639  }
640 
641  if (getDerived().dataTraverseStmtPre(CurrS)) {
642  CurrSAndVisited.setInt(true);
643  size_t N = LocalQueue.size();
644  TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
645  // Process new children in the order they were added.
646  std::reverse(LocalQueue.begin() + N, LocalQueue.end());
647  } else {
648  LocalQueue.pop_back();
649  }
650  }
651 
652  return true;
653 }
654 
655 #define DISPATCH(NAME, CLASS, VAR) \
656  return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))
657 
658 template <typename Derived>
660  if (T.isNull())
661  return true;
662 
663  switch (T->getTypeClass()) {
664 #define ABSTRACT_TYPE(CLASS, BASE)
665 #define TYPE(CLASS, BASE) \
666  case Type::CLASS: \
667  DISPATCH(CLASS##Type, CLASS##Type, const_cast<Type *>(T.getTypePtr()));
668 #include "clang/AST/TypeNodes.def"
669  }
670 
671  return true;
672 }
673 
674 template <typename Derived>
676  if (TL.isNull())
677  return true;
678 
679  switch (TL.getTypeLocClass()) {
680 #define ABSTRACT_TYPELOC(CLASS, BASE)
681 #define TYPELOC(CLASS, BASE) \
682  case TypeLoc::CLASS: \
683  return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
684 #include "clang/AST/TypeLocNodes.def"
685  }
686 
687  return true;
688 }
689 
690 // Define the Traverse*Attr(Attr* A) methods
691 #define VISITORCLASS RecursiveASTVisitor
692 #include "clang/AST/AttrVisitor.inc"
693 #undef VISITORCLASS
694 
695 template <typename Derived>
697  if (!D)
698  return true;
699 
700  // As a syntax visitor, by default we want to ignore declarations for
701  // implicit declarations (ones not typed explicitly by the user).
702  if (!getDerived().shouldVisitImplicitCode() && D->isImplicit())
703  return true;
704 
705  switch (D->getKind()) {
706 #define ABSTRACT_DECL(DECL)
707 #define DECL(CLASS, BASE) \
708  case Decl::CLASS: \
709  if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D))) \
710  return false; \
711  break;
712 #include "clang/AST/DeclNodes.inc"
713  }
714 
715  // Visit any attributes attached to this declaration.
716  for (auto *I : D->attrs()) {
717  if (!getDerived().TraverseAttr(I))
718  return false;
719  }
720  return true;
721 }
722 
723 #undef DISPATCH
724 
725 template <typename Derived>
727  NestedNameSpecifier *NNS) {
728  if (!NNS)
729  return true;
730 
731  if (NNS->getPrefix())
732  TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
733 
734  switch (NNS->getKind()) {
740  return true;
741 
744  TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
745  }
746 
747  return true;
748 }
749 
750 template <typename Derived>
753  if (!NNS)
754  return true;
755 
756  if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
757  TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
758 
759  switch (NNS.getNestedNameSpecifier()->getKind()) {
765  return true;
766 
769  TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
770  break;
771  }
772 
773  return true;
774 }
775 
776 template <typename Derived>
778  DeclarationNameInfo NameInfo) {
779  switch (NameInfo.getName().getNameKind()) {
783  if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
784  TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
785  break;
786 
788  TRY_TO(TraverseTemplateName(
790  break;
791 
799  break;
800  }
801 
802  return true;
803 }
804 
805 template <typename Derived>
808  TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
809  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
810  TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
811 
812  return true;
813 }
814 
815 template <typename Derived>
817  const TemplateArgument &Arg) {
818  switch (Arg.getKind()) {
823  return true;
824 
826  return getDerived().TraverseType(Arg.getAsType());
827 
830  return getDerived().TraverseTemplateName(
832 
834  return getDerived().TraverseStmt(Arg.getAsExpr());
835 
837  return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
838  Arg.pack_size());
839  }
840 
841  return true;
842 }
843 
844 // FIXME: no template name location?
845 // FIXME: no source locations for a template argument pack?
846 template <typename Derived>
848  const TemplateArgumentLoc &ArgLoc) {
849  const TemplateArgument &Arg = ArgLoc.getArgument();
850 
851  switch (Arg.getKind()) {
856  return true;
857 
858  case TemplateArgument::Type: {
859  // FIXME: how can TSI ever be NULL?
860  if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
861  return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
862  else
863  return getDerived().TraverseType(Arg.getAsType());
864  }
865 
868  if (ArgLoc.getTemplateQualifierLoc())
869  TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
870  ArgLoc.getTemplateQualifierLoc()));
871  return getDerived().TraverseTemplateName(
873 
875  return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
876 
878  return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
879  Arg.pack_size());
880  }
881 
882  return true;
883 }
884 
885 template <typename Derived>
887  const TemplateArgument *Args, unsigned NumArgs) {
888  for (unsigned I = 0; I != NumArgs; ++I) {
889  TRY_TO(TraverseTemplateArgument(Args[I]));
890  }
891 
892  return true;
893 }
894 
895 template <typename Derived>
897  CXXCtorInitializer *Init) {
898  if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
899  TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
900 
901  if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
902  TRY_TO(TraverseStmt(Init->getInit()));
903 
904  return true;
905 }
906 
907 template <typename Derived>
908 bool
910  const LambdaCapture *C,
911  Expr *Init) {
912  if (LE->isInitCapture(C))
913  TRY_TO(TraverseDecl(C->getCapturedVar()));
914  else
915  TRY_TO(TraverseStmt(Init));
916  return true;
917 }
918 
919 template <typename Derived>
921  LambdaExpr *LE, DataRecursionQueue *Queue) {
923  return true;
924 }
925 
926 // ----------------- Type traversal -----------------
927 
928 // This macro makes available a variable T, the passed-in type.
929 #define DEF_TRAVERSE_TYPE(TYPE, CODE) \
930  template <typename Derived> \
931  bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) { \
932  if (!getDerived().shouldTraversePostOrder()) \
933  TRY_TO(WalkUpFrom##TYPE(T)); \
934  { CODE; } \
935  if (getDerived().shouldTraversePostOrder()) \
936  TRY_TO(WalkUpFrom##TYPE(T)); \
937  return true; \
938  }
939 
940 DEF_TRAVERSE_TYPE(BuiltinType, {})
941 
942 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
943 
944 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
945 
946 DEF_TRAVERSE_TYPE(BlockPointerType,
947  { TRY_TO(TraverseType(T->getPointeeType())); })
948 
949 DEF_TRAVERSE_TYPE(LValueReferenceType,
950  { TRY_TO(TraverseType(T->getPointeeType())); })
951 
952 DEF_TRAVERSE_TYPE(RValueReferenceType,
953  { TRY_TO(TraverseType(T->getPointeeType())); })
954 
955 DEF_TRAVERSE_TYPE(MemberPointerType, {
956  TRY_TO(TraverseType(QualType(T->getClass(), 0)));
957  TRY_TO(TraverseType(T->getPointeeType()));
958 })
959 
960 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
961 
962 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
963 
964 DEF_TRAVERSE_TYPE(ConstantArrayType,
965  { TRY_TO(TraverseType(T->getElementType())); })
966 
967 DEF_TRAVERSE_TYPE(IncompleteArrayType,
968  { TRY_TO(TraverseType(T->getElementType())); })
969 
970 DEF_TRAVERSE_TYPE(VariableArrayType, {
971  TRY_TO(TraverseType(T->getElementType()));
972  TRY_TO(TraverseStmt(T->getSizeExpr()));
973 })
974 
975 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
976  TRY_TO(TraverseType(T->getElementType()));
977  if (T->getSizeExpr())
978  TRY_TO(TraverseStmt(T->getSizeExpr()));
979 })
980 
981 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
982  if (T->getSizeExpr())
983  TRY_TO(TraverseStmt(T->getSizeExpr()));
984  TRY_TO(TraverseType(T->getElementType()));
985 })
986 
987 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
988 
989 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
990 
991 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
992  { TRY_TO(TraverseType(T->getReturnType())); })
993 
994 DEF_TRAVERSE_TYPE(FunctionProtoType, {
995  TRY_TO(TraverseType(T->getReturnType()));
996 
997  for (const auto &A : T->param_types()) {
998  TRY_TO(TraverseType(A));
999  }
1000 
1001  for (const auto &E : T->exceptions()) {
1002  TRY_TO(TraverseType(E));
1003  }
1004 
1005  if (Expr *NE = T->getNoexceptExpr())
1006  TRY_TO(TraverseStmt(NE));
1007 })
1008 
1009 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
1010 DEF_TRAVERSE_TYPE(TypedefType, {})
1011 
1012 DEF_TRAVERSE_TYPE(TypeOfExprType,
1013  { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1014 
1015 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
1016 
1017 DEF_TRAVERSE_TYPE(DecltypeType,
1018  { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1019 
1020 DEF_TRAVERSE_TYPE(UnaryTransformType, {
1021  TRY_TO(TraverseType(T->getBaseType()));
1022  TRY_TO(TraverseType(T->getUnderlyingType()));
1023 })
1024 
1025 DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
1026 DEF_TRAVERSE_TYPE(DeducedTemplateSpecializationType, {
1027  TRY_TO(TraverseTemplateName(T->getTemplateName()));
1028  TRY_TO(TraverseType(T->getDeducedType()));
1029 })
1030 
1031 DEF_TRAVERSE_TYPE(RecordType, {})
1032 DEF_TRAVERSE_TYPE(EnumType, {})
1033 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
1034 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {
1035  TRY_TO(TraverseType(T->getReplacementType()));
1036 })
1037 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {
1038  TRY_TO(TraverseTemplateArgument(T->getArgumentPack()));
1039 })
1040 
1041 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
1042  TRY_TO(TraverseTemplateName(T->getTemplateName()));
1043  TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1044 })
1045 
1046 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
1047 
1048 DEF_TRAVERSE_TYPE(AttributedType,
1049  { TRY_TO(TraverseType(T->getModifiedType())); })
1050 
1051 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
1052 
1053 DEF_TRAVERSE_TYPE(ElaboratedType, {
1054  if (T->getQualifier()) {
1055  TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1056  }
1057  TRY_TO(TraverseType(T->getNamedType()));
1058 })
1059 
1060 DEF_TRAVERSE_TYPE(DependentNameType,
1061  { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
1062 
1063 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
1064  TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1065  TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1066 })
1067 
1068 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
1069 
1070 DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
1071 
1072 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
1073 
1074 DEF_TRAVERSE_TYPE(ObjCObjectType, {
1075  // We have to watch out here because an ObjCInterfaceType's base
1076  // type is itself.
1077  if (T->getBaseType().getTypePtr() != T)
1078  TRY_TO(TraverseType(T->getBaseType()));
1079  for (auto typeArg : T->getTypeArgsAsWritten()) {
1080  TRY_TO(TraverseType(typeArg));
1081  }
1082 })
1083 
1084 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
1085  { TRY_TO(TraverseType(T->getPointeeType())); })
1086 
1087 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
1088 
1089 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
1090 
1091 #undef DEF_TRAVERSE_TYPE
1092 
1093 // ----------------- TypeLoc traversal -----------------
1094 
1095 // This macro makes available a variable TL, the passed-in TypeLoc.
1096 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
1097 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
1098 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
1099 // continue to work.
1100 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \
1101  template <typename Derived> \
1102  bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
1103  if (getDerived().shouldWalkTypesOfTypeLocs()) \
1104  TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \
1105  TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
1106  { CODE; } \
1107  return true; \
1108  }
1109 
1110 template <typename Derived>
1111 bool
1112 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
1113  // Move this over to the 'main' typeloc tree. Note that this is a
1114  // move -- we pretend that we were really looking at the unqualified
1115  // typeloc all along -- rather than a recursion, so we don't follow
1116  // the normal CRTP plan of going through
1117  // getDerived().TraverseTypeLoc. If we did, we'd be traversing
1118  // twice for the same type (once as a QualifiedTypeLoc version of
1119  // the type, once as an UnqualifiedTypeLoc version of the type),
1120  // which in effect means we'd call VisitTypeLoc twice with the
1121  // 'same' type. This solves that problem, at the cost of never
1122  // seeing the qualified version of the type (unless the client
1123  // subclasses TraverseQualifiedTypeLoc themselves). It's not a
1124  // perfect solution. A perfect solution probably requires making
1125  // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
1126  // wrapper around Type* -- rather than being its own class in the
1127  // type hierarchy.
1128  return TraverseTypeLoc(TL.getUnqualifiedLoc());
1129 }
1130 
1131 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
1132 
1133 // FIXME: ComplexTypeLoc is unfinished
1134 DEF_TRAVERSE_TYPELOC(ComplexType, {
1135  TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1136 })
1137 
1138 DEF_TRAVERSE_TYPELOC(PointerType,
1139  { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1140 
1141 DEF_TRAVERSE_TYPELOC(BlockPointerType,
1142  { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1143 
1144 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1145  { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1146 
1147 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1148  { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1149 
1150 // FIXME: location of base class?
1151 // We traverse this in the type case as well, but how is it not reached through
1152 // the pointee type?
1153 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1154  TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1155  TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1156 })
1157 
1158 DEF_TRAVERSE_TYPELOC(AdjustedType,
1159  { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1160 
1161 DEF_TRAVERSE_TYPELOC(DecayedType,
1162  { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1163 
1164 template <typename Derived>
1166  // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1167  TRY_TO(TraverseStmt(TL.getSizeExpr()));
1168  return true;
1169 }
1170 
1171 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1172  TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1173  return TraverseArrayTypeLocHelper(TL);
1174 })
1175 
1176 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1177  TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1178  return TraverseArrayTypeLocHelper(TL);
1179 })
1180 
1181 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1182  TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1183  return TraverseArrayTypeLocHelper(TL);
1184 })
1185 
1186 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1187  TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1188  return TraverseArrayTypeLocHelper(TL);
1189 })
1190 
1191 // FIXME: order? why not size expr first?
1192 // FIXME: base VectorTypeLoc is unfinished
1193 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1194  if (TL.getTypePtr()->getSizeExpr())
1195  TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1196  TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1197 })
1198 
1199 // FIXME: VectorTypeLoc is unfinished
1200 DEF_TRAVERSE_TYPELOC(VectorType, {
1201  TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1202 })
1203 
1204 // FIXME: size and attributes
1205 // FIXME: base VectorTypeLoc is unfinished
1206 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1207  TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1208 })
1209 
1210 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1211  { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
1212 
1213 // FIXME: location of exception specifications (attributes?)
1214 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1215  TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
1216 
1217  const FunctionProtoType *T = TL.getTypePtr();
1218 
1219  for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1220  if (TL.getParam(I)) {
1221  TRY_TO(TraverseDecl(TL.getParam(I)));
1222  } else if (I < T->getNumParams()) {
1223  TRY_TO(TraverseType(T->getParamType(I)));
1224  }
1225  }
1226 
1227  for (const auto &E : T->exceptions()) {
1228  TRY_TO(TraverseType(E));
1229  }
1230 
1231  if (Expr *NE = T->getNoexceptExpr())
1232  TRY_TO(TraverseStmt(NE));
1233 })
1234 
1235 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1236 DEF_TRAVERSE_TYPELOC(TypedefType, {})
1237 
1238 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1239  { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
1240 
1241 DEF_TRAVERSE_TYPELOC(TypeOfType, {
1242  TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1243 })
1244 
1245 // FIXME: location of underlying expr
1246 DEF_TRAVERSE_TYPELOC(DecltypeType, {
1247  TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1248 })
1249 
1250 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1251  TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1252 })
1253 
1254 DEF_TRAVERSE_TYPELOC(AutoType, {
1255  TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1256 })
1257 
1258 DEF_TRAVERSE_TYPELOC(DeducedTemplateSpecializationType, {
1259  TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1260  TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1261 })
1262 
1263 DEF_TRAVERSE_TYPELOC(RecordType, {})
1264 DEF_TRAVERSE_TYPELOC(EnumType, {})
1265 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1266 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {
1267  TRY_TO(TraverseType(TL.getTypePtr()->getReplacementType()));
1268 })
1269 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {
1270  TRY_TO(TraverseTemplateArgument(TL.getTypePtr()->getArgumentPack()));
1271 })
1272 
1273 // FIXME: use the loc for the template name?
1274 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1275  TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1276  for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1277  TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1278  }
1279 })
1280 
1281 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
1282 
1283 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1284 
1285 DEF_TRAVERSE_TYPELOC(AttributedType,
1286  { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
1287 
1288 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1289  if (TL.getQualifierLoc()) {
1290  TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1291  }
1292  TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1293 })
1294 
1295 DEF_TRAVERSE_TYPELOC(DependentNameType, {
1296  TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1297 })
1298 
1299 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1300  if (TL.getQualifierLoc()) {
1301  TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1302  }
1303 
1304  for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1305  TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1306  }
1307 })
1308 
1309 DEF_TRAVERSE_TYPELOC(PackExpansionType,
1310  { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
1311 
1312 DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {})
1313 
1314 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
1315 
1316 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1317  // We have to watch out here because an ObjCInterfaceType's base
1318  // type is itself.
1319  if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1320  TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1321  for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
1322  TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
1323 })
1324 
1325 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1326  { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1327 
1328 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1329 
1330 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1331 
1332 #undef DEF_TRAVERSE_TYPELOC
1333 
1334 // ----------------- Decl traversal -----------------
1335 //
1336 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1337 // the children that come from the DeclContext associated with it.
1338 // Therefore each Traverse* only needs to worry about children other
1339 // than those.
1340 
1341 template <typename Derived>
1342 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1343  if (!DC)
1344  return true;
1345 
1346  for (auto *Child : DC->decls()) {
1347  // BlockDecls and CapturedDecls are traversed through BlockExprs and
1348  // CapturedStmts respectively.
1349  if (!isa<BlockDecl>(Child) && !isa<CapturedDecl>(Child))
1350  TRY_TO(TraverseDecl(Child));
1351  }
1352 
1353  return true;
1354 }
1355 
1356 // This macro makes available a variable D, the passed-in decl.
1357 #define DEF_TRAVERSE_DECL(DECL, CODE) \
1358  template <typename Derived> \
1359  bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) { \
1360  bool ShouldVisitChildren = true; \
1361  bool ReturnValue = true; \
1362  if (!getDerived().shouldTraversePostOrder()) \
1363  TRY_TO(WalkUpFrom##DECL(D)); \
1364  { CODE; } \
1365  if (ReturnValue && ShouldVisitChildren) \
1366  TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \
1367  if (ReturnValue && getDerived().shouldTraversePostOrder()) \
1368  TRY_TO(WalkUpFrom##DECL(D)); \
1369  return ReturnValue; \
1370  }
1371 
1372 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
1373 
1374 DEF_TRAVERSE_DECL(BlockDecl, {
1375  if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1376  TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1377  TRY_TO(TraverseStmt(D->getBody()));
1378  for (const auto &I : D->captures()) {
1379  if (I.hasCopyExpr()) {
1380  TRY_TO(TraverseStmt(I.getCopyExpr()));
1381  }
1382  }
1383  ShouldVisitChildren = false;
1384 })
1385 
1386 DEF_TRAVERSE_DECL(CapturedDecl, {
1387  TRY_TO(TraverseStmt(D->getBody()));
1389 })
1390 
1391 DEF_TRAVERSE_DECL(EmptyDecl, {})
1392 
1393 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1394  { TRY_TO(TraverseStmt(D->getAsmString())); })
1395 
1396 DEF_TRAVERSE_DECL(ImportDecl, {})
1397 
1398 DEF_TRAVERSE_DECL(FriendDecl, {
1399  // Friend is either decl or a type.
1400  if (D->getFriendType())
1401  TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1402  else
1403  TRY_TO(TraverseDecl(D->getFriendDecl()));
1404 })
1405 
1406 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1407  if (D->getFriendType())
1408  TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1409  else
1410  TRY_TO(TraverseDecl(D->getFriendDecl()));
1411  for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1412  TemplateParameterList *TPL = D->getTemplateParameterList(I);
1413  for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1414  ITPL != ETPL; ++ITPL) {
1415  TRY_TO(TraverseDecl(*ITPL));
1416  }
1417  }
1418 })
1419 
1420 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
1421  TRY_TO(TraverseDecl(D->getSpecialization()));
1422 
1423  if (D->hasExplicitTemplateArgs()) {
1424  const TemplateArgumentListInfo &args = D->templateArgs();
1425  TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(),
1426  args.size()));
1427  }
1428 })
1429 
1430 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1431 
1432 DEF_TRAVERSE_DECL(ExportDecl, {})
1433 
1434 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1435  })
1436 
1437 DEF_TRAVERSE_DECL(StaticAssertDecl, {
1438  TRY_TO(TraverseStmt(D->getAssertExpr()));
1439  TRY_TO(TraverseStmt(D->getMessage()));
1440 })
1441 
1443  TranslationUnitDecl,
1444  {// Code in an unnamed namespace shows up automatically in
1445  // decls_begin()/decls_end(). Thus we don't need to recurse on
1446  // D->getAnonymousNamespace().
1447  })
1448 
1449 DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
1450 
1451 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
1452 
1453 DEF_TRAVERSE_DECL(ExternCContextDecl, {})
1454 
1455 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1456  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1457 
1458  // We shouldn't traverse an aliased namespace, since it will be
1459  // defined (and, therefore, traversed) somewhere else.
1460  ShouldVisitChildren = false;
1461 })
1462 
1463 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1464  })
1465 
1467  NamespaceDecl,
1468  {// Code in an unnamed namespace shows up automatically in
1469  // decls_begin()/decls_end(). Thus we don't need to recurse on
1470  // D->getAnonymousNamespace().
1471  })
1472 
1473 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1474  })
1475 
1476 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
1477  if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
1478  for (auto typeParam : *typeParamList) {
1479  TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1480  }
1481  }
1482 })
1483 
1484 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1485  })
1486 
1487 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1488  })
1489 
1490 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
1491  if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
1492  for (auto typeParam : *typeParamList) {
1493  TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1494  }
1495  }
1496 
1497  if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
1498  TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
1499  }
1500 })
1501 
1502 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
1503  })
1504 
1505 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1506  if (D->getReturnTypeSourceInfo()) {
1507  TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1508  }
1509  for (ParmVarDecl *Parameter : D->parameters()) {
1510  TRY_TO(TraverseDecl(Parameter));
1511  }
1512  if (D->isThisDeclarationADefinition()) {
1513  TRY_TO(TraverseStmt(D->getBody()));
1514  }
1515  ShouldVisitChildren = false;
1516 })
1517 
1518 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
1519  if (D->hasExplicitBound()) {
1520  TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1521  // We shouldn't traverse D->getTypeForDecl(); it's a result of
1522  // declaring the type alias, not something that was written in the
1523  // source.
1524  }
1525 })
1526 
1527 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1528  if (D->getTypeSourceInfo())
1529  TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1530  else
1531  TRY_TO(TraverseType(D->getType()));
1532  ShouldVisitChildren = false;
1533 })
1534 
1535 DEF_TRAVERSE_DECL(UsingDecl, {
1536  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1537  TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1538 })
1539 
1540 DEF_TRAVERSE_DECL(UsingPackDecl, {})
1541 
1542 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1543  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1544 })
1545 
1546 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
1547 
1548 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
1549 
1550 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
1551  for (auto *I : D->varlists()) {
1552  TRY_TO(TraverseStmt(I));
1553  }
1554 })
1555 
1556 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
1557  TRY_TO(TraverseStmt(D->getCombiner()));
1558  if (auto *Initializer = D->getInitializer())
1559  TRY_TO(TraverseStmt(Initializer));
1560  TRY_TO(TraverseType(D->getType()));
1561  return true;
1562 })
1563 
1564 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
1565 
1566 // A helper method for TemplateDecl's children.
1567 template <typename Derived>
1568 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1569  TemplateParameterList *TPL) {
1570  if (TPL) {
1571  for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1572  I != E; ++I) {
1573  TRY_TO(TraverseDecl(*I));
1574  }
1575  }
1576  return true;
1577 }
1578 
1579 template <typename Derived>
1580 template <typename T>
1581 bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) {
1582  for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) {
1583  TemplateParameterList *TPL = D->getTemplateParameterList(i);
1584  TraverseTemplateParameterListHelper(TPL);
1585  }
1586  return true;
1587 }
1588 
1589 template <typename Derived>
1590 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1591  ClassTemplateDecl *D) {
1592  for (auto *SD : D->specializations()) {
1593  for (auto *RD : SD->redecls()) {
1594  // We don't want to visit injected-class-names in this traversal.
1595  if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
1596  continue;
1597 
1598  switch (
1599  cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1600  // Visit the implicit instantiations with the requested pattern.
1601  case TSK_Undeclared:
1603  TRY_TO(TraverseDecl(RD));
1604  break;
1605 
1606  // We don't need to do anything on an explicit instantiation
1607  // or explicit specialization because there will be an explicit
1608  // node for it elsewhere.
1612  break;
1613  }
1614  }
1615  }
1616 
1617  return true;
1618 }
1619 
1620 template <typename Derived>
1621 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1622  VarTemplateDecl *D) {
1623  for (auto *SD : D->specializations()) {
1624  for (auto *RD : SD->redecls()) {
1625  switch (
1626  cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1627  case TSK_Undeclared:
1629  TRY_TO(TraverseDecl(RD));
1630  break;
1631 
1635  break;
1636  }
1637  }
1638  }
1639 
1640  return true;
1641 }
1642 
1643 // A helper method for traversing the instantiations of a
1644 // function while skipping its specializations.
1645 template <typename Derived>
1646 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1647  FunctionTemplateDecl *D) {
1648  for (auto *FD : D->specializations()) {
1649  for (auto *RD : FD->redecls()) {
1650  switch (RD->getTemplateSpecializationKind()) {
1651  case TSK_Undeclared:
1653  // We don't know what kind of FunctionDecl this is.
1654  TRY_TO(TraverseDecl(RD));
1655  break;
1656 
1657  // FIXME: For now traverse explicit instantiations here. Change that
1658  // once they are represented as dedicated nodes in the AST.
1661  TRY_TO(TraverseDecl(RD));
1662  break;
1663 
1665  break;
1666  }
1667  }
1668  }
1669 
1670  return true;
1671 }
1672 
1673 // This macro unifies the traversal of class, variable and function
1674 // template declarations.
1675 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND) \
1676  DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, { \
1677  TRY_TO(TraverseDecl(D->getTemplatedDecl())); \
1678  TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \
1679  \
1680  /* By default, we do not traverse the instantiations of \
1681  class templates since they do not appear in the user code. The \
1682  following code optionally traverses them. \
1683  \
1684  We only traverse the class instantiations when we see the canonical \
1685  declaration of the template, to ensure we only visit them once. */ \
1686  if (getDerived().shouldVisitTemplateInstantiations() && \
1687  D == D->getCanonicalDecl()) \
1688  TRY_TO(TraverseTemplateInstantiations(D)); \
1689  \
1690  /* Note that getInstantiatedFromMemberTemplate() is just a link \
1691  from a template instantiation back to the template from which \
1692  it was instantiated, and thus should not be traversed. */ \
1693  })
1694 
1697 DEF_TRAVERSE_TMPL_DECL(Function)
1698 
1699 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1700  // D is the "T" in something like
1701  // template <template <typename> class T> class container { };
1702  TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1703  if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
1704  TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1705  }
1706  TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1707 })
1708 
1709 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
1710  TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1711 })
1712 
1713 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1714  // D is the "T" in something like "template<typename T> class vector;"
1715  if (D->getTypeForDecl())
1716  TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1717  if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1718  TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1719 })
1720 
1721 DEF_TRAVERSE_DECL(TypedefDecl, {
1722  TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1723  // We shouldn't traverse D->getTypeForDecl(); it's a result of
1724  // declaring the typedef, not something that was written in the
1725  // source.
1726 })
1727 
1728 DEF_TRAVERSE_DECL(TypeAliasDecl, {
1729  TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1730  // We shouldn't traverse D->getTypeForDecl(); it's a result of
1731  // declaring the type alias, not something that was written in the
1732  // source.
1733 })
1734 
1735 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
1736  TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1737  TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1738 })
1739 
1740 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1741  // A dependent using declaration which was marked with 'typename'.
1742  // template<class T> class A : public B<T> { using typename B<T>::foo; };
1743  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1744  // We shouldn't traverse D->getTypeForDecl(); it's a result of
1745  // declaring the type, not something that was written in the
1746  // source.
1747 })
1748 
1749 DEF_TRAVERSE_DECL(EnumDecl, {
1750  TRY_TO(TraverseDeclTemplateParameterLists(D));
1751 
1752  if (D->getTypeForDecl())
1753  TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1754 
1755  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1756  // The enumerators are already traversed by
1757  // decls_begin()/decls_end().
1758 })
1759 
1760 // Helper methods for RecordDecl and its children.
1761 template <typename Derived>
1762 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
1763  // We shouldn't traverse D->getTypeForDecl(); it's a result of
1764  // declaring the type, not something that was written in the source.
1765 
1766  TRY_TO(TraverseDeclTemplateParameterLists(D));
1767  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1768  return true;
1769 }
1770 
1771 template <typename Derived>
1772 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
1773  if (!TraverseRecordHelper(D))
1774  return false;
1775  if (D->isCompleteDefinition()) {
1776  for (const auto &I : D->bases()) {
1777  TRY_TO(TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc()));
1778  }
1779  // We don't traverse the friends or the conversions, as they are
1780  // already in decls_begin()/decls_end().
1781  }
1782  return true;
1783 }
1784 
1785 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
1786 
1787 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
1788 
1789 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND) \
1790  DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, { \
1791  /* For implicit instantiations ("set<int> x;"), we don't want to \
1792  recurse at all, since the instatiated template isn't written in \
1793  the source code anywhere. (Note the instatiated *type* -- \
1794  set<int> -- is written, and will still get a callback of \
1795  TemplateSpecializationType). For explicit instantiations \
1796  ("template set<int>;"), we do need a callback, since this \
1797  is the only callback that's made for this instantiation. \
1798  We use getTypeAsWritten() to distinguish. */ \
1799  if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \
1800  TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \
1801  \
1802  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \
1803  if (!getDerived().shouldVisitTemplateInstantiations() && \
1804  D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) \
1805  /* Returning from here skips traversing the \
1806  declaration context of the *TemplateSpecializationDecl \
1807  (embedded in the DEF_TRAVERSE_DECL() macro) \
1808  which contains the instantiated members of the template. */ \
1809  return true; \
1810  })
1811 
1814 
1815 template <typename Derived>
1816 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1817  const TemplateArgumentLoc *TAL, unsigned Count) {
1818  for (unsigned I = 0; I < Count; ++I) {
1819  TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1820  }
1821  return true;
1822 }
1823 
1824 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND) \
1825  DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, { \
1826  /* The partial specialization. */ \
1827  if (TemplateParameterList *TPL = D->getTemplateParameters()) { \
1828  for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); \
1829  I != E; ++I) { \
1830  TRY_TO(TraverseDecl(*I)); \
1831  } \
1832  } \
1833  /* The args that remains unspecialized. */ \
1834  TRY_TO(TraverseTemplateArgumentLocsHelper( \
1835  D->getTemplateArgsAsWritten()->getTemplateArgs(), \
1836  D->getTemplateArgsAsWritten()->NumTemplateArgs)); \
1837  \
1838  /* Don't need the *TemplatePartialSpecializationHelper, even \
1839  though that's our parent class -- we already visit all the \
1840  template args here. */ \
1841  TRY_TO(Traverse##DECLKIND##Helper(D)); \
1842  \
1843  /* Instantiations will have been visited with the primary template. */ \
1844  })
1845 
1846 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
1848 
1849 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
1850 
1851 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1852  // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1853  // template <class T> Class A : public Base<T> { using Base<T>::foo; };
1854  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1855  TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1856 })
1857 
1858 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1859 
1860 template <typename Derived>
1861 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1862  TRY_TO(TraverseDeclTemplateParameterLists(D));
1863  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1864  if (D->getTypeSourceInfo())
1865  TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1866  else
1867  TRY_TO(TraverseType(D->getType()));
1868  return true;
1869 }
1870 
1871 DEF_TRAVERSE_DECL(DecompositionDecl, {
1872  TRY_TO(TraverseVarHelper(D));
1873  for (auto *Binding : D->bindings()) {
1874  TRY_TO(TraverseDecl(Binding));
1875  }
1876 })
1877 
1878 DEF_TRAVERSE_DECL(BindingDecl, {
1879  if (getDerived().shouldVisitImplicitCode())
1880  TRY_TO(TraverseStmt(D->getBinding()));
1881 })
1882 
1883 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
1884 
1885 DEF_TRAVERSE_DECL(FieldDecl, {
1886  TRY_TO(TraverseDeclaratorHelper(D));
1887  if (D->isBitField())
1888  TRY_TO(TraverseStmt(D->getBitWidth()));
1889  else if (D->hasInClassInitializer())
1890  TRY_TO(TraverseStmt(D->getInClassInitializer()));
1891 })
1892 
1893 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1894  TRY_TO(TraverseDeclaratorHelper(D));
1895  if (D->isBitField())
1896  TRY_TO(TraverseStmt(D->getBitWidth()));
1897  // FIXME: implement the rest.
1898 })
1899 
1900 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1901  TRY_TO(TraverseDeclaratorHelper(D));
1902  if (D->isBitField())
1903  TRY_TO(TraverseStmt(D->getBitWidth()));
1904  // FIXME: implement the rest.
1905 })
1906 
1907 template <typename Derived>
1908 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1909  TRY_TO(TraverseDeclTemplateParameterLists(D));
1910  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1911  TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1912 
1913  // If we're an explicit template specialization, iterate over the
1914  // template args that were explicitly specified. If we were doing
1915  // this in typing order, we'd do it between the return type and
1916  // the function args, but both are handled by the FunctionTypeLoc
1917  // above, so we have to choose one side. I've decided to do before.
1918  if (const FunctionTemplateSpecializationInfo *FTSI =
1919  D->getTemplateSpecializationInfo()) {
1920  if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1921  FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1922  // A specialization might not have explicit template arguments if it has
1923  // a templated return type and concrete arguments.
1924  if (const ASTTemplateArgumentListInfo *TALI =
1925  FTSI->TemplateArgumentsAsWritten) {
1926  TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1927  TALI->NumTemplateArgs));
1928  }
1929  }
1930  }
1931 
1932  // Visit the function type itself, which can be either
1933  // FunctionNoProtoType or FunctionProtoType, or a typedef. This
1934  // also covers the return type and the function parameters,
1935  // including exception specifications.
1936  if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
1937  TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1938  } else if (getDerived().shouldVisitImplicitCode()) {
1939  // Visit parameter variable declarations of the implicit function
1940  // if the traverser is visiting implicit code. Parameter variable
1941  // declarations do not have valid TypeSourceInfo, so to visit them
1942  // we need to traverse the declarations explicitly.
1943  for (ParmVarDecl *Parameter : D->parameters()) {
1944  TRY_TO(TraverseDecl(Parameter));
1945  }
1946  }
1947 
1948  if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1949  // Constructor initializers.
1950  for (auto *I : Ctor->inits()) {
1951  TRY_TO(TraverseConstructorInitializer(I));
1952  }
1953  }
1954 
1955  if (D->isThisDeclarationADefinition()) {
1956  TRY_TO(TraverseStmt(D->getBody())); // Function body.
1957  }
1958  return true;
1959 }
1960 
1961 DEF_TRAVERSE_DECL(FunctionDecl, {
1962  // We skip decls_begin/decls_end, which are already covered by
1963  // TraverseFunctionHelper().
1964  ShouldVisitChildren = false;
1965  ReturnValue = TraverseFunctionHelper(D);
1966 })
1967 
1968 DEF_TRAVERSE_DECL(CXXDeductionGuideDecl, {
1969  // We skip decls_begin/decls_end, which are already covered by
1970  // TraverseFunctionHelper().
1971  ShouldVisitChildren = false;
1972  ReturnValue = TraverseFunctionHelper(D);
1973 })
1974 
1975 DEF_TRAVERSE_DECL(CXXMethodDecl, {
1976  // We skip decls_begin/decls_end, which are already covered by
1977  // TraverseFunctionHelper().
1978  ShouldVisitChildren = false;
1979  ReturnValue = TraverseFunctionHelper(D);
1980 })
1981 
1982 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
1983  // We skip decls_begin/decls_end, which are already covered by
1984  // TraverseFunctionHelper().
1985  ShouldVisitChildren = false;
1986  ReturnValue = TraverseFunctionHelper(D);
1987 })
1988 
1989 // CXXConversionDecl is the declaration of a type conversion operator.
1990 // It's not a cast expression.
1991 DEF_TRAVERSE_DECL(CXXConversionDecl, {
1992  // We skip decls_begin/decls_end, which are already covered by
1993  // TraverseFunctionHelper().
1994  ShouldVisitChildren = false;
1995  ReturnValue = TraverseFunctionHelper(D);
1996 })
1997 
1998 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
1999  // We skip decls_begin/decls_end, which are already covered by
2000  // TraverseFunctionHelper().
2001  ShouldVisitChildren = false;
2002  ReturnValue = TraverseFunctionHelper(D);
2003 })
2004 
2005 template <typename Derived>
2006 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
2007  TRY_TO(TraverseDeclaratorHelper(D));
2008  // Default params are taken care of when we traverse the ParmVarDecl.
2009  if (!isa<ParmVarDecl>(D) &&
2010  (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
2011  TRY_TO(TraverseStmt(D->getInit()));
2012  return true;
2013 }
2014 
2015 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
2016 
2017 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
2018 
2019 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
2020  // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
2021  TRY_TO(TraverseDeclaratorHelper(D));
2022  if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
2023  TRY_TO(TraverseStmt(D->getDefaultArgument()));
2024 })
2025 
2026 DEF_TRAVERSE_DECL(ParmVarDecl, {
2027  TRY_TO(TraverseVarHelper(D));
2028 
2029  if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
2030  !D->hasUnparsedDefaultArg())
2031  TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
2032 
2033  if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
2034  !D->hasUnparsedDefaultArg())
2035  TRY_TO(TraverseStmt(D->getDefaultArg()));
2036 })
2037 
2038 #undef DEF_TRAVERSE_DECL
2039 
2040 // ----------------- Stmt traversal -----------------
2041 //
2042 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
2043 // over the children defined in children() (every stmt defines these,
2044 // though sometimes the range is empty). Each individual Traverse*
2045 // method only needs to worry about children other than those. To see
2046 // what children() does for a given class, see, e.g.,
2047 // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
2048 
2049 // This macro makes available a variable S, the passed-in stmt.
2050 #define DEF_TRAVERSE_STMT(STMT, CODE) \
2051  template <typename Derived> \
2052  bool RecursiveASTVisitor<Derived>::Traverse##STMT( \
2053  STMT *S, DataRecursionQueue *Queue) { \
2054  bool ShouldVisitChildren = true; \
2055  bool ReturnValue = true; \
2056  if (!getDerived().shouldTraversePostOrder()) \
2057  TRY_TO(WalkUpFrom##STMT(S)); \
2058  { CODE; } \
2059  if (ShouldVisitChildren) { \
2060  for (Stmt *SubStmt : S->children()) { \
2062  } \
2063  } \
2064  if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder()) \
2065  TRY_TO(WalkUpFrom##STMT(S)); \
2066  return ReturnValue; \
2067  }
2068 
2069 DEF_TRAVERSE_STMT(GCCAsmStmt, {
2070  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
2071  for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
2072  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
2073  }
2074  for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
2075  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
2076  }
2077  for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
2078  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
2079  }
2080  // children() iterates over inputExpr and outputExpr.
2081 })
2082 
2084  MSAsmStmt,
2085  {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc. Once
2086  // added this needs to be implemented.
2087  })
2088 
2089 DEF_TRAVERSE_STMT(CXXCatchStmt, {
2090  TRY_TO(TraverseDecl(S->getExceptionDecl()));
2091  // children() iterates over the handler block.
2092 })
2093 
2094 DEF_TRAVERSE_STMT(DeclStmt, {
2095  for (auto *I : S->decls()) {
2096  TRY_TO(TraverseDecl(I));
2097  }
2098  // Suppress the default iteration over children() by
2099  // returning. Here's why: A DeclStmt looks like 'type var [=
2100  // initializer]'. The decls above already traverse over the
2101  // initializers, so we don't have to do it again (which
2102  // children() would do).
2103  ShouldVisitChildren = false;
2104 })
2105 
2106 // These non-expr stmts (most of them), do not need any action except
2107 // iterating over the children.
2108 DEF_TRAVERSE_STMT(BreakStmt, {})
2109 DEF_TRAVERSE_STMT(CXXTryStmt, {})
2110 DEF_TRAVERSE_STMT(CaseStmt, {})
2111 DEF_TRAVERSE_STMT(CompoundStmt, {})
2112 DEF_TRAVERSE_STMT(ContinueStmt, {})
2113 DEF_TRAVERSE_STMT(DefaultStmt, {})
2114 DEF_TRAVERSE_STMT(DoStmt, {})
2115 DEF_TRAVERSE_STMT(ForStmt, {})
2116 DEF_TRAVERSE_STMT(GotoStmt, {})
2117 DEF_TRAVERSE_STMT(IfStmt, {})
2118 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
2119 DEF_TRAVERSE_STMT(LabelStmt, {})
2120 DEF_TRAVERSE_STMT(AttributedStmt, {})
2121 DEF_TRAVERSE_STMT(NullStmt, {})
2122 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
2123 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
2124 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
2125 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
2126 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
2127 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
2128 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
2129 
2130 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
2131  if (!getDerived().shouldVisitImplicitCode()) {
2132  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
2133  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
2134  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2135  // Visit everything else only if shouldVisitImplicitCode().
2136  ShouldVisitChildren = false;
2137  }
2138 })
2139 
2140 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
2141  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2142  TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2143 })
2144 
2145 DEF_TRAVERSE_STMT(ReturnStmt, {})
2146 DEF_TRAVERSE_STMT(SwitchStmt, {})
2147 DEF_TRAVERSE_STMT(WhileStmt, {})
2148 
2149 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
2150  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2151  TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2152  if (S->hasExplicitTemplateArgs()) {
2153  TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2154  S->getNumTemplateArgs()));
2155  }
2156 })
2157 
2158 DEF_TRAVERSE_STMT(DeclRefExpr, {
2159  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2160  TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2161  TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2162  S->getNumTemplateArgs()));
2163 })
2164 
2165 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
2166  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2167  TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2168  if (S->hasExplicitTemplateArgs()) {
2169  TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2170  S->getNumTemplateArgs()));
2171  }
2172 })
2173 
2174 DEF_TRAVERSE_STMT(MemberExpr, {
2175  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2176  TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2177  TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2178  S->getNumTemplateArgs()));
2179 })
2180 
2182  ImplicitCastExpr,
2183  {// We don't traverse the cast type, as it's not written in the
2184  // source code.
2185  })
2186 
2187 DEF_TRAVERSE_STMT(CStyleCastExpr, {
2188  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2189 })
2190 
2191 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
2192  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2193 })
2194 
2195 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
2196  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2197 })
2198 
2199 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
2200  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2201 })
2202 
2203 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
2204  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2205 })
2206 
2207 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
2208  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2209 })
2210 
2211 template <typename Derived>
2212 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
2213  InitListExpr *S, DataRecursionQueue *Queue) {
2214  if (S) {
2215  // Skip this if we traverse postorder. We will visit it later
2216  // in PostVisitStmt.
2217  if (!getDerived().shouldTraversePostOrder())
2218  TRY_TO(WalkUpFromInitListExpr(S));
2219 
2220  // All we need are the default actions. FIXME: use a helper function.
2221  for (Stmt *SubStmt : S->children()) {
2223  }
2224  }
2225  return true;
2226 }
2227 
2228 // This method is called once for each pair of syntactic and semantic
2229 // InitListExpr, and it traverses the subtrees defined by the two forms. This
2230 // may cause some of the children to be visited twice, if they appear both in
2231 // the syntactic and the semantic form.
2232 //
2233 // There is no guarantee about which form \p S takes when this method is called.
2234 template <typename Derived>
2235 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(
2236  InitListExpr *S, DataRecursionQueue *Queue) {
2237  TRY_TO(TraverseSynOrSemInitListExpr(
2238  S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
2239  TRY_TO(TraverseSynOrSemInitListExpr(
2240  S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
2241  return true;
2242 }
2243 
2244 // GenericSelectionExpr is a special case because the types and expressions
2245 // are interleaved. We also need to watch out for null types (default
2246 // generic associations).
2247 DEF_TRAVERSE_STMT(GenericSelectionExpr, {
2248  TRY_TO(TraverseStmt(S->getControllingExpr()));
2249  for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
2250  if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
2251  TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
2252  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAssocExpr(i));
2253  }
2254  ShouldVisitChildren = false;
2255 })
2256 
2257 // PseudoObjectExpr is a special case because of the weirdness with
2258 // syntactic expressions and opaque values.
2259 DEF_TRAVERSE_STMT(PseudoObjectExpr, {
2260  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
2261  for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2262  e = S->semantics_end();
2263  i != e; ++i) {
2264  Expr *sub = *i;
2265  if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2266  sub = OVE->getSourceExpr();
2268  }
2269  ShouldVisitChildren = false;
2270 })
2271 
2272 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
2273  // This is called for code like 'return T()' where T is a built-in
2274  // (i.e. non-class) type.
2275  TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2276 })
2277 
2278 DEF_TRAVERSE_STMT(CXXNewExpr, {
2279  // The child-iterator will pick up the other arguments.
2280  TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
2281 })
2282 
2283 DEF_TRAVERSE_STMT(OffsetOfExpr, {
2284  // The child-iterator will pick up the expression representing
2285  // the field.
2286  // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2287  // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2288  TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2289 })
2290 
2291 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2292  // The child-iterator will pick up the arg if it's an expression,
2293  // but not if it's a type.
2294  if (S->isArgumentType())
2295  TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2296 })
2297 
2298 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2299  // The child-iterator will pick up the arg if it's an expression,
2300  // but not if it's a type.
2301  if (S->isTypeOperand())
2302  TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2303 })
2304 
2305 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2306  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2307 })
2308 
2309 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
2310 
2311 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2312  // The child-iterator will pick up the arg if it's an expression,
2313  // but not if it's a type.
2314  if (S->isTypeOperand())
2315  TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2316 })
2317 
2318 DEF_TRAVERSE_STMT(TypeTraitExpr, {
2319  for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2320  TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2321 })
2322 
2323 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2324  TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2325 })
2326 
2327 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2328  { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
2329 
2330 DEF_TRAVERSE_STMT(VAArgExpr, {
2331  // The child-iterator will pick up the expression argument.
2332  TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2333 })
2334 
2335 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2336  // This is called for code like 'return T()' where T is a class type.
2337  TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2338 })
2339 
2340 // Walk only the visible parts of lambda expressions.
2341 DEF_TRAVERSE_STMT(LambdaExpr, {
2342  for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
2343  const LambdaCapture *C = S->capture_begin() + I;
2344  if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
2345  TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
2346  }
2347  }
2348 
2349  TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2350  FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>();
2351 
2352  if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2353  // Visit the whole type.
2354  TRY_TO(TraverseTypeLoc(TL));
2355  } else {
2356  if (S->hasExplicitParameters()) {
2357  // Visit parameters.
2358  for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
2359  TRY_TO(TraverseDecl(Proto.getParam(I)));
2360  }
2361  } else if (S->hasExplicitResultType()) {
2362  TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
2363  }
2364 
2365  auto *T = Proto.getTypePtr();
2366  for (const auto &E : T->exceptions()) {
2367  TRY_TO(TraverseType(E));
2368  }
2369 
2370  if (Expr *NE = T->getNoexceptExpr())
2372  }
2373 
2374  ReturnValue = TRAVERSE_STMT_BASE(LambdaBody, LambdaExpr, S, Queue);
2375  ShouldVisitChildren = false;
2376 })
2377 
2378 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2379  // This is called for code like 'T()', where T is a template argument.
2380  TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2381 })
2382 
2383 // These expressions all might take explicit template arguments.
2384 // We traverse those if so. FIXME: implement these.
2385 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2386 DEF_TRAVERSE_STMT(CallExpr, {})
2387 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
2388 
2389 // These exprs (most of them), do not need any action except iterating
2390 // over the children.
2391 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2392 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
2393 DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
2394 
2395 DEF_TRAVERSE_STMT(BlockExpr, {
2396  TRY_TO(TraverseDecl(S->getBlockDecl()));
2397  return true; // no child statements to loop through.
2398 })
2399 
2400 DEF_TRAVERSE_STMT(ChooseExpr, {})
2401 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2402  TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2403 })
2404 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2405 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2406 
2407 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
2408  if (getDerived().shouldVisitImplicitCode())
2409  TRY_TO(TraverseStmt(S->getExpr()));
2410 })
2411 
2412 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
2413 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2414 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2415 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
2416 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2417 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
2418 
2419 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2420  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2421  if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2422  TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2423  if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2424  TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2425 })
2426 
2427 DEF_TRAVERSE_STMT(CXXThisExpr, {})
2428 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2429 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2430 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2431 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
2432 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2433 DEF_TRAVERSE_STMT(GNUNullExpr, {})
2434 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2435 DEF_TRAVERSE_STMT(NoInitExpr, {})
2436 DEF_TRAVERSE_STMT(ArrayInitLoopExpr, {
2437  // FIXME: The source expression of the OVE should be listed as
2438  // a child of the ArrayInitLoopExpr.
2439  if (OpaqueValueExpr *OVE = S->getCommonExpr())
2440  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr());
2441 })
2442 DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {})
2443 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
2444 
2445 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2446  if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2447  TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2448 })
2449 
2450 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2451 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
2452 
2453 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2454  if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2455  TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2456 })
2457 
2458 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
2459 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2460 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2461 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2462 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
2463 
2464 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2465  TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2466 })
2467 
2468 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
2469 DEF_TRAVERSE_STMT(ParenExpr, {})
2470 DEF_TRAVERSE_STMT(ParenListExpr, {})
2471 DEF_TRAVERSE_STMT(PredefinedExpr, {})
2472 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2473 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2474 DEF_TRAVERSE_STMT(StmtExpr, {})
2475 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2476  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2477  if (S->hasExplicitTemplateArgs()) {
2478  TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2479  S->getNumTemplateArgs()));
2480  }
2481 })
2482 
2483 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2484  TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2485  if (S->hasExplicitTemplateArgs()) {
2486  TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2487  S->getNumTemplateArgs()));
2488  }
2489 })
2490 
2491 DEF_TRAVERSE_STMT(SEHTryStmt, {})
2492 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2493 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
2494 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
2495 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2496 
2497 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2498 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
2499 DEF_TRAVERSE_STMT(TypoExpr, {})
2500 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
2501 
2502 // These operators (all of them) do not need any action except
2503 // iterating over the children.
2504 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2505 DEF_TRAVERSE_STMT(ConditionalOperator, {})
2506 DEF_TRAVERSE_STMT(UnaryOperator, {})
2507 DEF_TRAVERSE_STMT(BinaryOperator, {})
2508 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2509 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2510 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2511 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2512 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2513 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2514 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2515 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
2516 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
2517 DEF_TRAVERSE_STMT(AtomicExpr, {})
2518 
2519 // For coroutines expressions, traverse either the operand
2520 // as written or the implied calls, depending on what the
2521 // derived class requests.
2522 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
2523  if (!getDerived().shouldVisitImplicitCode()) {
2524  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2525  ShouldVisitChildren = false;
2526  }
2527 })
2528 DEF_TRAVERSE_STMT(CoreturnStmt, {
2529  if (!getDerived().shouldVisitImplicitCode()) {
2530  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2531  ShouldVisitChildren = false;
2532  }
2533 })
2534 DEF_TRAVERSE_STMT(CoawaitExpr, {
2535  if (!getDerived().shouldVisitImplicitCode()) {
2536  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2537  ShouldVisitChildren = false;
2538  }
2539 })
2540 DEF_TRAVERSE_STMT(DependentCoawaitExpr, {
2541  if (!getDerived().shouldVisitImplicitCode()) {
2542  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2543  ShouldVisitChildren = false;
2544  }
2545 })
2546 DEF_TRAVERSE_STMT(CoyieldExpr, {
2547  if (!getDerived().shouldVisitImplicitCode()) {
2548  TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2549  ShouldVisitChildren = false;
2550  }
2551 })
2552 
2553 // These literals (all of them) do not need any action.
2554 DEF_TRAVERSE_STMT(IntegerLiteral, {})
2555 DEF_TRAVERSE_STMT(CharacterLiteral, {})
2556 DEF_TRAVERSE_STMT(FloatingLiteral, {})
2557 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
2558 DEF_TRAVERSE_STMT(StringLiteral, {})
2559 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
2560 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
2561 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
2562 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
2563 
2564 // Traverse OpenCL: AsType, Convert.
2565 DEF_TRAVERSE_STMT(AsTypeExpr, {})
2566 
2567 // OpenMP directives.
2568 template <typename Derived>
2569 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
2570  OMPExecutableDirective *S) {
2571  for (auto *C : S->clauses()) {
2572  TRY_TO(TraverseOMPClause(C));
2573  }
2574  return true;
2575 }
2576 
2577 template <typename Derived>
2578 bool
2579 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
2580  return TraverseOMPExecutableDirective(S);
2581 }
2582 
2583 DEF_TRAVERSE_STMT(OMPParallelDirective,
2584  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2585 
2586 DEF_TRAVERSE_STMT(OMPSimdDirective,
2587  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2588 
2589 DEF_TRAVERSE_STMT(OMPForDirective,
2590  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2591 
2592 DEF_TRAVERSE_STMT(OMPForSimdDirective,
2593  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2594 
2595 DEF_TRAVERSE_STMT(OMPSectionsDirective,
2596  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2597 
2598 DEF_TRAVERSE_STMT(OMPSectionDirective,
2599  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2600 
2601 DEF_TRAVERSE_STMT(OMPSingleDirective,
2602  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2603 
2604 DEF_TRAVERSE_STMT(OMPMasterDirective,
2605  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2606 
2607 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
2608  TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
2609  TRY_TO(TraverseOMPExecutableDirective(S));
2610 })
2611 
2612 DEF_TRAVERSE_STMT(OMPParallelForDirective,
2613  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2614 
2615 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
2616  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2617 
2618 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
2619  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2620 
2621 DEF_TRAVERSE_STMT(OMPTaskDirective,
2622  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2623 
2624 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
2625  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2626 
2627 DEF_TRAVERSE_STMT(OMPBarrierDirective,
2628  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2629 
2630 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
2631  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2632 
2633 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
2634  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2635 
2636 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
2637  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2638 
2639 DEF_TRAVERSE_STMT(OMPCancelDirective,
2640  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2641 
2642 DEF_TRAVERSE_STMT(OMPFlushDirective,
2643  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2644 
2645 DEF_TRAVERSE_STMT(OMPOrderedDirective,
2646  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2647 
2648 DEF_TRAVERSE_STMT(OMPAtomicDirective,
2649  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2650 
2651 DEF_TRAVERSE_STMT(OMPTargetDirective,
2652  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2653 
2654 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
2655  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2656 
2657 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
2658  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2659 
2660 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
2661  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2662 
2663 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
2664  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2665 
2666 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
2667  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2668 
2669 DEF_TRAVERSE_STMT(OMPTeamsDirective,
2670  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2671 
2672 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
2673  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2674 
2675 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
2676  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2677 
2678 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
2679  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2680 
2681 DEF_TRAVERSE_STMT(OMPDistributeDirective,
2682  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2683 
2684 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
2685  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2686 
2687 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
2688  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2689 
2690 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
2691  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2692 
2693 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
2694  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2695 
2696 DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
2697  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2698 
2699 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
2700  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2701 
2702 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
2703  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2704 
2705 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
2706  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2707 
2708 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
2709  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2710 
2711 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
2712  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2713 
2714 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
2715  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2716 
2717 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
2718  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2719 
2720 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective,
2721  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2722 
2723 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective,
2724  { TRY_TO(TraverseOMPExecutableDirective(S)); })
2725 
2726 // OpenMP clauses.
2727 template <typename Derived>
2728 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
2729  if (!C)
2730  return true;
2731  switch (C->getClauseKind()) {
2732 #define OPENMP_CLAUSE(Name, Class) \
2733  case OMPC_##Name: \
2734  TRY_TO(Visit##Class(static_cast<Class *>(C))); \
2735  break;
2736 #include "clang/Basic/OpenMPKinds.def"
2737  case OMPC_threadprivate:
2738  case OMPC_uniform:
2739  case OMPC_unknown:
2740  break;
2741  }
2742  return true;
2743 }
2744 
2745 template <typename Derived>
2746 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
2748  TRY_TO(TraverseStmt(Node->getPreInitStmt()));
2749  return true;
2750 }
2751 
2752 template <typename Derived>
2753 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
2754  OMPClauseWithPostUpdate *Node) {
2755  TRY_TO(VisitOMPClauseWithPreInit(Node));
2756  TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
2757  return true;
2758 }
2759 
2760 template <typename Derived>
2761 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
2762  TRY_TO(VisitOMPClauseWithPreInit(C));
2763  TRY_TO(TraverseStmt(C->getCondition()));
2764  return true;
2765 }
2766 
2767 template <typename Derived>
2768 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
2769  TRY_TO(TraverseStmt(C->getCondition()));
2770  return true;
2771 }
2772 
2773 template <typename Derived>
2774 bool
2775 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
2776  TRY_TO(VisitOMPClauseWithPreInit(C));
2777  TRY_TO(TraverseStmt(C->getNumThreads()));
2778  return true;
2779 }
2780 
2781 template <typename Derived>
2782 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
2783  TRY_TO(TraverseStmt(C->getSafelen()));
2784  return true;
2785 }
2786 
2787 template <typename Derived>
2788 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
2789  TRY_TO(TraverseStmt(C->getSimdlen()));
2790  return true;
2791 }
2792 
2793 template <typename Derived>
2794 bool
2795 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
2796  TRY_TO(TraverseStmt(C->getNumForLoops()));
2797  return true;
2798 }
2799 
2800 template <typename Derived>
2801 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
2802  return true;
2803 }
2804 
2805 template <typename Derived>
2806 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
2807  return true;
2808 }
2809 
2810 template <typename Derived>
2811 bool
2812 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
2813  TRY_TO(VisitOMPClauseWithPreInit(C));
2814  TRY_TO(TraverseStmt(C->getChunkSize()));
2815  return true;
2816 }
2817 
2818 template <typename Derived>
2819 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
2820  TRY_TO(TraverseStmt(C->getNumForLoops()));
2821  return true;
2822 }
2823 
2824 template <typename Derived>
2825 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
2826  return true;
2827 }
2828 
2829 template <typename Derived>
2830 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
2831  return true;
2832 }
2833 
2834 template <typename Derived>
2835 bool
2836 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
2837  return true;
2838 }
2839 
2840 template <typename Derived>
2841 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
2842  return true;
2843 }
2844 
2845 template <typename Derived>
2846 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
2847  return true;
2848 }
2849 
2850 template <typename Derived>
2851 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
2852  return true;
2853 }
2854 
2855 template <typename Derived>
2856 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2857  return true;
2858 }
2859 
2860 template <typename Derived>
2861 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2862  return true;
2863 }
2864 
2865 template <typename Derived>
2866 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
2867  return true;
2868 }
2869 
2870 template <typename Derived>
2871 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
2872  return true;
2873 }
2874 
2875 template <typename Derived>
2876 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
2877  return true;
2878 }
2879 
2880 template <typename Derived>
2881 template <typename T>
2882 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
2883  for (auto *E : Node->varlists()) {
2884  TRY_TO(TraverseStmt(E));
2885  }
2886  return true;
2887 }
2888 
2889 template <typename Derived>
2890 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
2891  TRY_TO(VisitOMPClauseList(C));
2892  for (auto *E : C->private_copies()) {
2893  TRY_TO(TraverseStmt(E));
2894  }
2895  return true;
2896 }
2897 
2898 template <typename Derived>
2899 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
2900  OMPFirstprivateClause *C) {
2901  TRY_TO(VisitOMPClauseList(C));
2902  TRY_TO(VisitOMPClauseWithPreInit(C));
2903  for (auto *E : C->private_copies()) {
2904  TRY_TO(TraverseStmt(E));
2905  }
2906  for (auto *E : C->inits()) {
2907  TRY_TO(TraverseStmt(E));
2908  }
2909  return true;
2910 }
2911 
2912 template <typename Derived>
2913 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
2914  OMPLastprivateClause *C) {
2915  TRY_TO(VisitOMPClauseList(C));
2916  TRY_TO(VisitOMPClauseWithPostUpdate(C));
2917  for (auto *E : C->private_copies()) {
2918  TRY_TO(TraverseStmt(E));
2919  }
2920  for (auto *E : C->source_exprs()) {
2921  TRY_TO(TraverseStmt(E));
2922  }
2923  for (auto *E : C->destination_exprs()) {
2924  TRY_TO(TraverseStmt(E));
2925  }
2926  for (auto *E : C->assignment_ops()) {
2927  TRY_TO(TraverseStmt(E));
2928  }
2929  return true;
2930 }
2931 
2932 template <typename Derived>
2933 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
2934  TRY_TO(VisitOMPClauseList(C));
2935  return true;
2936 }
2937 
2938 template <typename Derived>
2939 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2940  TRY_TO(TraverseStmt(C->getStep()));
2941  TRY_TO(TraverseStmt(C->getCalcStep()));
2942  TRY_TO(VisitOMPClauseList(C));
2943  TRY_TO(VisitOMPClauseWithPostUpdate(C));
2944  for (auto *E : C->privates()) {
2945  TRY_TO(TraverseStmt(E));
2946  }
2947  for (auto *E : C->inits()) {
2948  TRY_TO(TraverseStmt(E));
2949  }
2950  for (auto *E : C->updates()) {
2951  TRY_TO(TraverseStmt(E));
2952  }
2953  for (auto *E : C->finals()) {
2954  TRY_TO(TraverseStmt(E));
2955  }
2956  return true;
2957 }
2958 
2959 template <typename Derived>
2960 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
2961  TRY_TO(TraverseStmt(C->getAlignment()));
2962  TRY_TO(VisitOMPClauseList(C));
2963  return true;
2964 }
2965 
2966 template <typename Derived>
2967 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
2968  TRY_TO(VisitOMPClauseList(C));
2969  for (auto *E : C->source_exprs()) {
2970  TRY_TO(TraverseStmt(E));
2971  }
2972  for (auto *E : C->destination_exprs()) {
2973  TRY_TO(TraverseStmt(E));
2974  }
2975  for (auto *E : C->assignment_ops()) {
2976  TRY_TO(TraverseStmt(E));
2977  }
2978  return true;
2979 }
2980 
2981 template <typename Derived>
2982 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
2983  OMPCopyprivateClause *C) {
2984  TRY_TO(VisitOMPClauseList(C));
2985  for (auto *E : C->source_exprs()) {
2986  TRY_TO(TraverseStmt(E));
2987  }
2988  for (auto *E : C->destination_exprs()) {
2989  TRY_TO(TraverseStmt(E));
2990  }
2991  for (auto *E : C->assignment_ops()) {
2992  TRY_TO(TraverseStmt(E));
2993  }
2994  return true;
2995 }
2996 
2997 template <typename Derived>
2998 bool
2999 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
3000  TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3001  TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3002  TRY_TO(VisitOMPClauseList(C));
3003  TRY_TO(VisitOMPClauseWithPostUpdate(C));
3004  for (auto *E : C->privates()) {
3005  TRY_TO(TraverseStmt(E));
3006  }
3007  for (auto *E : C->lhs_exprs()) {
3008  TRY_TO(TraverseStmt(E));
3009  }
3010  for (auto *E : C->rhs_exprs()) {
3011  TRY_TO(TraverseStmt(E));
3012  }
3013  for (auto *E : C->reduction_ops()) {
3014  TRY_TO(TraverseStmt(E));
3015  }
3016  return true;
3017 }
3018 
3019 template <typename Derived>
3020 bool RecursiveASTVisitor<Derived>::VisitOMPTaskReductionClause(
3021  OMPTaskReductionClause *C) {
3022  TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3023  TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3024  TRY_TO(VisitOMPClauseList(C));
3025  TRY_TO(VisitOMPClauseWithPostUpdate(C));
3026  for (auto *E : C->privates()) {
3027  TRY_TO(TraverseStmt(E));
3028  }
3029  for (auto *E : C->lhs_exprs()) {
3030  TRY_TO(TraverseStmt(E));
3031  }
3032  for (auto *E : C->rhs_exprs()) {
3033  TRY_TO(TraverseStmt(E));
3034  }
3035  for (auto *E : C->reduction_ops()) {
3036  TRY_TO(TraverseStmt(E));
3037  }
3038  return true;
3039 }
3040 
3041 template <typename Derived>
3042 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
3043  TRY_TO(VisitOMPClauseList(C));
3044  return true;
3045 }
3046 
3047 template <typename Derived>
3048 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
3049  TRY_TO(VisitOMPClauseList(C));
3050  return true;
3051 }
3052 
3053 template <typename Derived>
3054 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
3055  TRY_TO(TraverseStmt(C->getDevice()));
3056  return true;
3057 }
3058 
3059 template <typename Derived>
3060 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
3061  TRY_TO(VisitOMPClauseList(C));
3062  return true;
3063 }
3064 
3065 template <typename Derived>
3066 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
3067  OMPNumTeamsClause *C) {
3068  TRY_TO(VisitOMPClauseWithPreInit(C));
3069  TRY_TO(TraverseStmt(C->getNumTeams()));
3070  return true;
3071 }
3072 
3073 template <typename Derived>
3074 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
3075  OMPThreadLimitClause *C) {
3076  TRY_TO(VisitOMPClauseWithPreInit(C));
3077  TRY_TO(TraverseStmt(C->getThreadLimit()));
3078  return true;
3079 }
3080 
3081 template <typename Derived>
3082 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
3083  OMPPriorityClause *C) {
3084  TRY_TO(TraverseStmt(C->getPriority()));
3085  return true;
3086 }
3087 
3088 template <typename Derived>
3089 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
3090  OMPGrainsizeClause *C) {
3091  TRY_TO(TraverseStmt(C->getGrainsize()));
3092  return true;
3093 }
3094 
3095 template <typename Derived>
3096 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
3097  OMPNumTasksClause *C) {
3098  TRY_TO(TraverseStmt(C->getNumTasks()));
3099  return true;
3100 }
3101 
3102 template <typename Derived>
3103 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
3104  TRY_TO(TraverseStmt(C->getHint()));
3105  return true;
3106 }
3107 
3108 template <typename Derived>
3109 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
3110  OMPDistScheduleClause *C) {
3111  TRY_TO(VisitOMPClauseWithPreInit(C));
3112  TRY_TO(TraverseStmt(C->getChunkSize()));
3113  return true;
3114 }
3115 
3116 template <typename Derived>
3117 bool
3118 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
3119  return true;
3120 }
3121 
3122 template <typename Derived>
3123 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
3124  TRY_TO(VisitOMPClauseList(C));
3125  return true;
3126 }
3127 
3128 template <typename Derived>
3129 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
3130  TRY_TO(VisitOMPClauseList(C));
3131  return true;
3132 }
3133 
3134 template <typename Derived>
3135 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
3136  OMPUseDevicePtrClause *C) {
3137  TRY_TO(VisitOMPClauseList(C));
3138  return true;
3139 }
3140 
3141 template <typename Derived>
3142 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
3143  OMPIsDevicePtrClause *C) {
3144  TRY_TO(VisitOMPClauseList(C));
3145  return true;
3146 }
3147 
3148 // FIXME: look at the following tricky-seeming exprs to see if we
3149 // need to recurse on anything. These are ones that have methods
3150 // returning decls or qualtypes or nestednamespecifier -- though I'm
3151 // not sure if they own them -- or just seemed very complicated, or
3152 // had lots of sub-types to explore.
3153 //
3154 // VisitOverloadExpr and its children: recurse on template args? etc?
3155 
3156 // FIXME: go through all the stmts and exprs again, and see which of them
3157 // create new types, and recurse on the types (TypeLocs?) of those.
3158 // Candidates:
3159 //
3160 // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
3161 // http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
3162 // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
3163 // Every class that has getQualifier.
3164 
3165 #undef DEF_TRAVERSE_STMT
3166 #undef TRAVERSE_STMT
3167 #undef TRAVERSE_STMT_BASE
3168 
3169 #undef TRY_TO
3170 
3171 } // end namespace clang
3172 
3173 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
This represents 'thread_limit' clause in the '#pragma omp ...' directive.
bool TraverseLambdaBody(LambdaExpr *LE, DataRecursionQueue *Queue=nullptr)
Recursively visit the body of a lambda expression.
Expr * getSourceExpression() const
Definition: TemplateBase.h:484
This represents clause 'copyin' in the '#pragma omp ...' directives.
A (possibly-)qualified type.
Definition: Type.h:616
helper_expr_const_range source_exprs() const
#define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND)
Expr *const * semantics_iterator
Definition: Expr.h:5004
Stmt - This represents one statement.
Definition: Stmt.h:60
#define UNARYOP_LIST()
C Language Family Type Representation.
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Definition: TemplateBase.h:69
#define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S)
for(unsigned I=0, E=TL.getNumArgs();I!=E;++I)
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
This represents 'grainsize' clause in the '#pragma omp ...' directive.
Defines the C++ template declaration subclasses.
StringRef P
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:316
This represents 'priority' clause in the '#pragma omp ...' directive.
The base class of the type hierarchy.
Definition: Type.h:1303
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:51
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
A container of type source information.
Definition: Decl.h:62
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:306
bool TraverseTemplateName(TemplateName Template)
Recursively visit a template name and dispatch to the appropriate method.
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
Expr * getAlignment()
Returns alignment.
const TemplateArgumentLoc * getArgumentArray() const
Definition: TemplateBase.h:548
An identifier, stored as an IdentifierInfo*.
TRY_TO(TraverseType(T->getPointeeType()))
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2299
Wrapper of type source information for a type with non-trivial direct qualifiers. ...
Definition: TypeLoc.h:254
Derived & getDerived()
Return a reference to the derived class.
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:46
This represents 'defaultmap' clause in the '#pragma omp ...' directive.
bool dataTraverseStmtPre(Stmt *S)
Invoked before visiting a statement or expression via data recursion.
A namespace, stored as a NamespaceDecl*.
#define BINOP_LIST()
This represents implicit clause 'flush' for the '#pragma omp flush' directive.
Defines the Objective-C statement AST node classes.
Defines the clang::Expr interface and subclasses for C++ expressions.
SmallVectorImpl< llvm::PointerIntPair< Stmt *, 1, bool > > DataRecursionQueue
A queue used for performing data recursion over statements.
This represents 'nogroup' clause in the '#pragma omp ...' directive.
bool TraverseDecl(Decl *D)
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:40
DeclarationName getName() const
getName - Returns the embedded declaration name.
return(__x >> __y)|(__x<< (32-__y))
bool isNull() const
Definition: TypeLoc.h:102
A C++ nested-name-specifier augmented with source location information.
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:412
This represents 'simd' clause in the '#pragma omp ...' directive.
bool shouldTraversePostOrder() const
Return whether this visitor should traverse post-order.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:57
#define TYPE(CLASS, BASE)
bool shouldVisitTemplateInstantiations() const
Return whether this visitor should recurse into template instantiations.
Expr * getChunkSize()
Get chunk size.
This represents clause 'map' in the '#pragma omp ...' directives.
This represents clause 'to' in the '#pragma omp ...' directives.
Defines some OpenMP-specific enums and functions.
bool TraverseSynOrSemInitListExpr(InitListExpr *S, DataRecursionQueue *Queue=nullptr)
Recursively visit the syntactic or semantic form of an initialization list.
Wrapper of type source information for a type with no direct qualifiers.
Definition: TypeLoc.h:229
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:479
Expr * getNumTeams()
Return NumTeams number.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
#define TRY_TO(CALL_EXPR)
#define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND)
This represents clause 'copyprivate' in the '#pragma omp ...' directives.
Describes an C or C++ initializer list.
Definition: Expr.h:3848
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:537
A convenient class for passing around template argument information.
Definition: TemplateBase.h:524
NamedDecl ** iterator
Iterates through the template parameters in this list.
Definition: DeclTemplate.h:93
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo)
Recursively visit a name with its location information.
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:504
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
TypeClass getTypeClass() const
Definition: Type.h:1555
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
CompoundStmt * getBody() const
Retrieve the body of the lambda.
Definition: ExprCXX.cpp:993
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1519
This represents clause 'is_device_ptr' in the '#pragma omp ...' directives.
A class that does preordor or postorder depth-first traversal on the entire Clang AST and visits each...
#define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND)
Expr * getHint() const
Returns number of threads.
bool isWritten() const
Determine whether this initializer is explicitly written in the source code.
Definition: DeclCXX.h:2269
detail::InMemoryDirectory::const_iterator I
This represents clause 'from' in the '#pragma omp ...' directives.
#define CAO_LIST()
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, unsigned NumVars)
Build 'linear' clause with given number of variables NumVars.
Definition: OpenMPClause.h:106
This represents 'threads' clause in the '#pragma omp ...' directive.
This represents clause 'aligned' in the '#pragma omp ...' directives.
DEF_TRAVERSE_DECL(BlockDecl,{if(TypeSourceInfo *TInfo=D->getSignatureAsWritten()) TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));TRY_TO(TraverseStmt(D->getBody()));for(const auto &I:D->captures()){if(I.hasCopyExpr()){TRY_TO(TraverseStmt(I.getCopyExpr()));}}ShouldVisitChildren=false;}) DEF_TRAVERSE_DECL(CapturedDecl
DEF_TRAVERSE_TYPE(ComplexType,{TRY_TO(TraverseType(T->getElementType()));}) DEF_TRAVERSE_TYPE(PointerType
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
This represents implicit clause 'depend' for the '#pragma omp task' directive.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
Expr - This represents one expression.
Definition: Expr.h:105
bool TraverseConstructorInitializer(CXXCtorInitializer *Init)
Recursively visit a constructor initializer.
helper_expr_const_range assignment_ops() const
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:54
bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL)
bool shouldVisitImplicitCode() const
Return whether this visitor should recurse into implicit code, e.g., implicit constructors and destru...
Kind getKind() const
Definition: DeclBase.h:410
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:213
#define bool
Definition: stdbool.h:31
bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL)
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
Defines the clang::TypeLoc interface and its subclasses.
A namespace alias, stored as a NamespaceAliasDecl*.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
Definition: TemplateBase.h:266
Expr * getDevice()
Return device number.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:148
DEF_TRAVERSE_TYPELOC(ComplexType,{TRY_TO(TraverseType(TL.getTypePtr() ->getElementType()));}) DEF_TRAVERSE_TYPELOC(PointerType
return TraverseArrayTypeLocHelper(TL)
This file defines OpenMP AST classes for clauses.
helper_expr_const_range destination_exprs() const
bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL)
This represents 'num_teams' clause in the '#pragma omp ...' directive.
This represents 'hint' clause in the '#pragma omp ...' directive.
bool TraverseTypeLoc(TypeLoc TL)
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument ty...
attr_range attrs() const
Definition: DeclBase.h:482
#define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE)
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Recursively visit a C++ nested-name-specifier with location information.
Expr * getPriority()
Return Priority number.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
This file defines OpenMP nodes for declarative directives.
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition: ExprCXX.cpp:935
bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue=nullptr)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
TypeLocClass getTypeLocClass() const
Definition: TypeLoc.h:97
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:160
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:145
Expr * getGrainsize() const
Return safe iteration space distance.
bool TraverseType(QualType T)
Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() pr...
bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C, Expr *Init)
Recursively visit a lambda capture.
Defines various enumerations that describe declaration and type specifiers.
ast_type_traits::DynTypedNode Node
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T-> getSizeExpr()))
Represents a template argument.
Definition: TemplateBase.h:40
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:235
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:355
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2232
This represents 'device' clause in the '#pragma omp ...' directive.
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:63
#define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND)
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:156
Expr * getNumTasks() const
Return safe iteration space distance.
detail::InMemoryDirectory::const_iterator E
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
A type that was preceded by the 'template' keyword, stored as a Type*.
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:428
This file defines OpenMP AST classes for executable directives and clauses.
bool TraverseTemplateArgument(const TemplateArgument &Arg)
Recursively visit a template argument and dispatch to the appropriate method for the argument type...
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2105
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:152
UnqualTypeLoc getUnqualifiedLoc() const
Definition: TypeLoc.h:260
The template argument is a type.
Definition: TemplateBase.h:48
bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS)
Recursively visit a C++ nested-name-specifier.
The template argument is actually a parameter pack.
Definition: TemplateBase.h:72
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
helper_expr_const_range destination_exprs() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:336
This represents 'num_tasks' clause in the '#pragma omp ...' directive.
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:60
bool dataTraverseStmtPost(Stmt *S)
Invoked after visiting a statement or expression via data recursion.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Expr * getThreadLimit()
Return ThreadLimit number.
bool TraverseTemplateArguments(const TemplateArgument *Args, unsigned NumArgs)
Recursively visit a set of template arguments.
#define DEF_TRAVERSE_STMT(STMT, CODE)
This represents 'dist_schedule' clause in the '#pragma omp ...' directive.
bool TraverseAttr(Attr *At)
Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic typ...
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition: TypeLoc.h:304
bool VisitUnqualTypeLoc(UnqualTypeLoc TL)
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:683
The global specifier '::'. There is no stored value.
bool shouldWalkTypesOfTypeLocs() const
Return whether this visitor should recurse into the types of TypeLocs.
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:471
bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc)
Recursively visit a template argument location and dispatch to the appropriate method for the argumen...
Attr - This represents one attribute.
Definition: Attr.h:43
This represents clause 'use_device_ptr' in the '#pragma omp ...' directives.
helper_expr_const_range assignment_ops() const
Defines the LambdaCapture class.
#define STMT(CLASS, PARENT)
helper_expr_const_range source_exprs() const