1 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the RecursiveASTVisitor interface, which recursively
11 // traverses the entire AST.
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
15 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclarationName.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"
30 #include "clang/AST/LambdaCapture.h"
31 #include "clang/AST/NestedNameSpecifier.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"
42 #include "clang/Basic/OpenMPKinds.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"
49 #include <type_traits>
51 // The following three macros are used for meta programming. The code
52 // using them is responsible for defining macro OPERATOR().
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)
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(Cmp) OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) \
67 OPERATOR(LAnd) OPERATOR(LOr) OPERATOR(Assign) OPERATOR(Comma)
69 // All compound assign operators.
71 OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \
72 OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor)
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
80 #define TRY_TO(CALL_EXPR) \
82 if (!getDerived().CALL_EXPR) \
86 /// \brief A class that does preorder or postorder
87 /// depth-first traversal on the entire Clang AST and visits each node.
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.
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
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.
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.
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()).
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.
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.
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.
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 {
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.
158 typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>>
161 /// \brief Return a reference to the derived class.
162 Derived &getDerived() { return *static_cast<Derived *>(this); }
164 /// \brief Return whether this visitor should recurse into
165 /// template instantiations.
166 bool shouldVisitTemplateInstantiations() const { return false; }
168 /// \brief Return whether this visitor should recurse into the types of
170 bool shouldWalkTypesOfTypeLocs() const { return true; }
172 /// \brief Return whether this visitor should recurse into implicit
173 /// code, e.g., implicit constructors and destructors.
174 bool shouldVisitImplicitCode() const { return false; }
176 /// \brief Return whether this visitor should traverse post-order.
177 bool shouldTraversePostOrder() const { return false; }
179 /// \brief Recursively visit a statement or expression, by
180 /// dispatching to Traverse*() based on the argument's dynamic type.
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);
186 /// Invoked before visiting a statement or expression via data recursion.
188 /// \returns false to skip visiting the node, true otherwise.
189 bool dataTraverseStmtPre(Stmt *S) { return true; }
191 /// Invoked after visiting a statement or expression via data recursion.
192 /// This is not invoked if the previously invoked \c dataTraverseStmtPre
195 /// \returns false if the visitation was terminated early, true otherwise.
196 bool dataTraverseStmtPost(Stmt *S) { return true; }
198 /// \brief Recursively visit a type, by dispatching to
199 /// Traverse*Type() based on the argument's getTypeClass() property.
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);
205 /// \brief Recursively visit a type with location, by dispatching to
206 /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
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);
212 /// \brief Recursively visit an attribute, by dispatching to
213 /// Traverse*Attr() based on the argument's dynamic type.
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);
219 /// \brief Recursively visit a declaration, by dispatching to
220 /// Traverse*Decl() based on the argument's dynamic type.
222 /// \returns false if the visitation was terminated early, true
223 /// otherwise (including when the argument is NULL).
224 bool TraverseDecl(Decl *D);
226 /// \brief Recursively visit a C++ nested-name-specifier.
228 /// \returns false if the visitation was terminated early, true otherwise.
229 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
231 /// \brief Recursively visit a C++ nested-name-specifier with location
234 /// \returns false if the visitation was terminated early, true otherwise.
235 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
237 /// \brief Recursively visit a name with its location information.
239 /// \returns false if the visitation was terminated early, true otherwise.
240 bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
242 /// \brief Recursively visit a template name and dispatch to the
243 /// appropriate method.
245 /// \returns false if the visitation was terminated early, true otherwise.
246 bool TraverseTemplateName(TemplateName Template);
248 /// \brief Recursively visit a template argument and dispatch to the
249 /// appropriate method for the argument type.
251 /// \returns false if the visitation was terminated early, true otherwise.
252 // FIXME: migrate callers to TemplateArgumentLoc instead.
253 bool TraverseTemplateArgument(const TemplateArgument &Arg);
255 /// \brief Recursively visit a template argument location and dispatch to the
256 /// appropriate method for the argument type.
258 /// \returns false if the visitation was terminated early, true otherwise.
259 bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
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.
265 /// \returns false if the visitation was terminated early, true otherwise.
266 // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
267 bool TraverseTemplateArguments(const TemplateArgument *Args,
270 /// \brief Recursively visit a base specifier. This can be overridden by a
273 /// \returns false if the visitation was terminated early, true otherwise.
274 bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base);
276 /// \brief Recursively visit a constructor initializer. This
277 /// automatically dispatches to another visitor for the initializer
278 /// expression, but not for the name of the initializer, so may
279 /// be overridden for clients that need access to the name.
281 /// \returns false if the visitation was terminated early, true otherwise.
282 bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
284 /// \brief Recursively visit a lambda capture. \c Init is the expression that
285 /// will be used to initialize the capture.
287 /// \returns false if the visitation was terminated early, true otherwise.
288 bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
291 /// \brief Recursively visit the body of a lambda expression.
293 /// This provides a hook for visitors that need more context when visiting
294 /// \c LE->getBody().
296 /// \returns false if the visitation was terminated early, true otherwise.
297 bool TraverseLambdaBody(LambdaExpr *LE, DataRecursionQueue *Queue = nullptr);
299 /// \brief Recursively visit the syntactic or semantic form of an
300 /// initialization list.
302 /// \returns false if the visitation was terminated early, true otherwise.
303 bool TraverseSynOrSemInitListExpr(InitListExpr *S,
304 DataRecursionQueue *Queue = nullptr);
306 // ---- Methods on Attrs ----
308 // \brief Visit an attribute.
309 bool VisitAttr(Attr *A) { return true; }
311 // Declare Traverse* and empty Visit* for all Attr classes.
312 #define ATTR_VISITOR_DECLS_ONLY
313 #include "clang/AST/AttrVisitor.inc"
314 #undef ATTR_VISITOR_DECLS_ONLY
316 // ---- Methods on Stmts ----
318 Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); }
321 template<typename T, typename U>
322 struct has_same_member_pointer_type : std::false_type {};
323 template<typename T, typename U, typename R, typename... P>
324 struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
327 // Traverse the given statement. If the most-derived traverse function takes a
328 // data recursion queue, pass it on; otherwise, discard it. Note that the
329 // first branch of this conditional must compile whether or not the derived
330 // class can take a queue, so if we're taking the second arm, make the first
331 // arm call our function rather than the derived class version.
332 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE) \
333 (has_same_member_pointer_type<decltype( \
334 &RecursiveASTVisitor::Traverse##NAME), \
335 decltype(&Derived::Traverse##NAME)>::value \
336 ? static_cast<typename std::conditional< \
337 has_same_member_pointer_type< \
338 decltype(&RecursiveASTVisitor::Traverse##NAME), \
339 decltype(&Derived::Traverse##NAME)>::value, \
340 Derived &, RecursiveASTVisitor &>::type>(*this) \
341 .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE) \
342 : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
344 // Try to traverse the given statement, or enqueue it if we're performing data
345 // recursion in the middle of traversing another statement. Can only be called
346 // from within a DEF_TRAVERSE_STMT body or similar context.
347 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S) \
349 if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue)) \
354 // Declare Traverse*() for all concrete Stmt classes.
355 #define ABSTRACT_STMT(STMT)
356 #define STMT(CLASS, PARENT) \
357 bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
358 #include "clang/AST/StmtNodes.inc"
359 // The above header #undefs ABSTRACT_STMT and STMT upon exit.
361 // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
362 bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
363 bool VisitStmt(Stmt *S) { return true; }
364 #define STMT(CLASS, PARENT) \
365 bool WalkUpFrom##CLASS(CLASS *S) { \
366 TRY_TO(WalkUpFrom##PARENT(S)); \
367 TRY_TO(Visit##CLASS(S)); \
370 bool Visit##CLASS(CLASS *S) { return true; }
371 #include "clang/AST/StmtNodes.inc"
373 // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
374 // operator methods. Unary operators are not classes in themselves
375 // (they're all opcodes in UnaryOperator) but do have visitors.
376 #define OPERATOR(NAME) \
377 bool TraverseUnary##NAME(UnaryOperator *S, \
378 DataRecursionQueue *Queue = nullptr) { \
379 if (!getDerived().shouldTraversePostOrder()) \
380 TRY_TO(WalkUpFromUnary##NAME(S)); \
381 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \
384 bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
385 TRY_TO(WalkUpFromUnaryOperator(S)); \
386 TRY_TO(VisitUnary##NAME(S)); \
389 bool VisitUnary##NAME(UnaryOperator *S) { return true; }
394 // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
395 // operator methods. Binary operators are not classes in themselves
396 // (they're all opcodes in BinaryOperator) but do have visitors.
397 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \
398 bool TraverseBin##NAME(BINOP_TYPE *S, DataRecursionQueue *Queue = nullptr) { \
399 if (!getDerived().shouldTraversePostOrder()) \
400 TRY_TO(WalkUpFromBin##NAME(S)); \
401 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS()); \
402 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS()); \
405 bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
406 TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \
407 TRY_TO(VisitBin##NAME(S)); \
410 bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
412 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
416 // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
417 // assignment methods. Compound assignment operators are not
418 // classes in themselves (they're all opcodes in
419 // CompoundAssignOperator) but do have visitors.
420 #define OPERATOR(NAME) \
421 GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
425 #undef GENERAL_BINOP_FALLBACK
427 // ---- Methods on Types ----
428 // FIXME: revamp to take TypeLoc's rather than Types.
430 // Declare Traverse*() for all concrete Type classes.
431 #define ABSTRACT_TYPE(CLASS, BASE)
432 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
433 #include "clang/AST/TypeNodes.def"
434 // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
436 // Define WalkUpFrom*() and empty Visit*() for all Type classes.
437 bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
438 bool VisitType(Type *T) { return true; }
439 #define TYPE(CLASS, BASE) \
440 bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \
441 TRY_TO(WalkUpFrom##BASE(T)); \
442 TRY_TO(Visit##CLASS##Type(T)); \
445 bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
446 #include "clang/AST/TypeNodes.def"
448 // ---- Methods on TypeLocs ----
449 // FIXME: this currently just calls the matching Type methods
451 // Declare Traverse*() for all concrete TypeLoc classes.
452 #define ABSTRACT_TYPELOC(CLASS, BASE)
453 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
454 #include "clang/AST/TypeLocNodes.def"
455 // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
457 // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
458 bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
459 bool VisitTypeLoc(TypeLoc TL) { return true; }
461 // QualifiedTypeLoc and UnqualTypeLoc are not declared in
462 // TypeNodes.def and thus need to be handled specially.
463 bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
464 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
466 bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
467 bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
468 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
470 bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
472 // Note that BASE includes trailing 'Type' which CLASS doesn't.
473 #define TYPE(CLASS, BASE) \
474 bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
475 TRY_TO(WalkUpFrom##BASE##Loc(TL)); \
476 TRY_TO(Visit##CLASS##TypeLoc(TL)); \
479 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
480 #include "clang/AST/TypeNodes.def"
482 // ---- Methods on Decls ----
484 // Declare Traverse*() for all concrete Decl classes.
485 #define ABSTRACT_DECL(DECL)
486 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
487 #include "clang/AST/DeclNodes.inc"
488 // The above header #undefs ABSTRACT_DECL and DECL upon exit.
490 // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
491 bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
492 bool VisitDecl(Decl *D) { return true; }
493 #define DECL(CLASS, BASE) \
494 bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \
495 TRY_TO(WalkUpFrom##BASE(D)); \
496 TRY_TO(Visit##CLASS##Decl(D)); \
499 bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
500 #include "clang/AST/DeclNodes.inc"
502 bool canIgnoreChildDeclWhileTraversingDeclContext(const Decl *Child);
505 // These are helper methods used by more than one Traverse* method.
506 bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
508 // Traverses template parameter lists of either a DeclaratorDecl or TagDecl.
509 template <typename T>
510 bool TraverseDeclTemplateParameterLists(T *D);
512 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND) \
513 bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
514 DEF_TRAVERSE_TMPL_INST(Class)
515 DEF_TRAVERSE_TMPL_INST(Var)
516 DEF_TRAVERSE_TMPL_INST(Function)
517 #undef DEF_TRAVERSE_TMPL_INST
518 bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
520 bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
521 bool TraverseRecordHelper(RecordDecl *D);
522 bool TraverseCXXRecordHelper(CXXRecordDecl *D);
523 bool TraverseDeclaratorHelper(DeclaratorDecl *D);
524 bool TraverseDeclContextHelper(DeclContext *DC);
525 bool TraverseFunctionHelper(FunctionDecl *D);
526 bool TraverseVarHelper(VarDecl *D);
527 bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
528 bool TraverseOMPLoopDirective(OMPLoopDirective *S);
529 bool TraverseOMPClause(OMPClause *C);
530 #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C);
531 #include "clang/Basic/OpenMPKinds.def"
532 /// \brief Process clauses with list of variables.
533 template <typename T> bool VisitOMPClauseList(T *Node);
534 /// Process clauses with pre-initis.
535 bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
536 bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
538 bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
539 bool PostVisitStmt(Stmt *S);
542 template <typename Derived>
543 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
544 DataRecursionQueue *Queue) {
545 #define DISPATCH_STMT(NAME, CLASS, VAR) \
546 return TRAVERSE_STMT_BASE(NAME, CLASS, VAR, Queue);
548 // If we have a binary expr, dispatch to the subcode of the binop. A smart
549 // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
551 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
552 switch (BinOp->getOpcode()) {
553 #define OPERATOR(NAME) \
555 DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
561 #define OPERATOR(NAME) \
562 case BO_##NAME##Assign: \
563 DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
569 } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
570 switch (UnOp->getOpcode()) {
571 #define OPERATOR(NAME) \
573 DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
581 // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
582 switch (S->getStmtClass()) {
583 case Stmt::NoStmtClass:
585 #define ABSTRACT_STMT(STMT)
586 #define STMT(CLASS, PARENT) \
587 case Stmt::CLASS##Class: \
588 DISPATCH_STMT(CLASS, CLASS, S);
589 #include "clang/AST/StmtNodes.inc"
597 template <typename Derived>
598 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
599 switch (S->getStmtClass()) {
600 case Stmt::NoStmtClass:
602 #define ABSTRACT_STMT(STMT)
603 #define STMT(CLASS, PARENT) \
604 case Stmt::CLASS##Class: \
605 TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S))); break;
606 #define INITLISTEXPR(CLASS, PARENT) \
607 case Stmt::CLASS##Class: \
609 auto ILE = static_cast<CLASS *>(S); \
610 if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE) \
611 TRY_TO(WalkUpFrom##CLASS(Syn)); \
612 if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \
613 TRY_TO(WalkUpFrom##CLASS(Sem)); \
616 #include "clang/AST/StmtNodes.inc"
624 template <typename Derived>
625 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S,
626 DataRecursionQueue *Queue) {
631 Queue->push_back({S, false});
635 SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
636 LocalQueue.push_back({S, false});
638 while (!LocalQueue.empty()) {
639 auto &CurrSAndVisited = LocalQueue.back();
640 Stmt *CurrS = CurrSAndVisited.getPointer();
641 bool Visited = CurrSAndVisited.getInt();
643 LocalQueue.pop_back();
644 TRY_TO(dataTraverseStmtPost(CurrS));
645 if (getDerived().shouldTraversePostOrder()) {
646 TRY_TO(PostVisitStmt(CurrS));
651 if (getDerived().dataTraverseStmtPre(CurrS)) {
652 CurrSAndVisited.setInt(true);
653 size_t N = LocalQueue.size();
654 TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
655 // Process new children in the order they were added.
656 std::reverse(LocalQueue.begin() + N, LocalQueue.end());
658 LocalQueue.pop_back();
665 #define DISPATCH(NAME, CLASS, VAR) \
666 return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))
668 template <typename Derived>
669 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
673 switch (T->getTypeClass()) {
674 #define ABSTRACT_TYPE(CLASS, BASE)
675 #define TYPE(CLASS, BASE) \
677 DISPATCH(CLASS##Type, CLASS##Type, const_cast<Type *>(T.getTypePtr()));
678 #include "clang/AST/TypeNodes.def"
684 template <typename Derived>
685 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
689 switch (TL.getTypeLocClass()) {
690 #define ABSTRACT_TYPELOC(CLASS, BASE)
691 #define TYPELOC(CLASS, BASE) \
692 case TypeLoc::CLASS: \
693 return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
694 #include "clang/AST/TypeLocNodes.def"
700 // Define the Traverse*Attr(Attr* A) methods
701 #define VISITORCLASS RecursiveASTVisitor
702 #include "clang/AST/AttrVisitor.inc"
705 template <typename Derived>
706 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
710 // As a syntax visitor, by default we want to ignore declarations for
711 // implicit declarations (ones not typed explicitly by the user).
712 if (!getDerived().shouldVisitImplicitCode() && D->isImplicit())
715 switch (D->getKind()) {
716 #define ABSTRACT_DECL(DECL)
717 #define DECL(CLASS, BASE) \
719 if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D))) \
722 #include "clang/AST/DeclNodes.inc"
725 // Visit any attributes attached to this declaration.
726 for (auto *I : D->attrs()) {
727 if (!getDerived().TraverseAttr(I))
735 template <typename Derived>
736 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
737 NestedNameSpecifier *NNS) {
741 if (NNS->getPrefix())
742 TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
744 switch (NNS->getKind()) {
745 case NestedNameSpecifier::Identifier:
746 case NestedNameSpecifier::Namespace:
747 case NestedNameSpecifier::NamespaceAlias:
748 case NestedNameSpecifier::Global:
749 case NestedNameSpecifier::Super:
752 case NestedNameSpecifier::TypeSpec:
753 case NestedNameSpecifier::TypeSpecWithTemplate:
754 TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
760 template <typename Derived>
761 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
762 NestedNameSpecifierLoc NNS) {
766 if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
767 TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
769 switch (NNS.getNestedNameSpecifier()->getKind()) {
770 case NestedNameSpecifier::Identifier:
771 case NestedNameSpecifier::Namespace:
772 case NestedNameSpecifier::NamespaceAlias:
773 case NestedNameSpecifier::Global:
774 case NestedNameSpecifier::Super:
777 case NestedNameSpecifier::TypeSpec:
778 case NestedNameSpecifier::TypeSpecWithTemplate:
779 TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
786 template <typename Derived>
787 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
788 DeclarationNameInfo NameInfo) {
789 switch (NameInfo.getName().getNameKind()) {
790 case DeclarationName::CXXConstructorName:
791 case DeclarationName::CXXDestructorName:
792 case DeclarationName::CXXConversionFunctionName:
793 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
794 TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
797 case DeclarationName::CXXDeductionGuideName:
798 TRY_TO(TraverseTemplateName(
799 TemplateName(NameInfo.getName().getCXXDeductionGuideTemplate())));
802 case DeclarationName::Identifier:
803 case DeclarationName::ObjCZeroArgSelector:
804 case DeclarationName::ObjCOneArgSelector:
805 case DeclarationName::ObjCMultiArgSelector:
806 case DeclarationName::CXXOperatorName:
807 case DeclarationName::CXXLiteralOperatorName:
808 case DeclarationName::CXXUsingDirective:
815 template <typename Derived>
816 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
817 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
818 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
819 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
820 TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
825 template <typename Derived>
826 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
827 const TemplateArgument &Arg) {
828 switch (Arg.getKind()) {
829 case TemplateArgument::Null:
830 case TemplateArgument::Declaration:
831 case TemplateArgument::Integral:
832 case TemplateArgument::NullPtr:
835 case TemplateArgument::Type:
836 return getDerived().TraverseType(Arg.getAsType());
838 case TemplateArgument::Template:
839 case TemplateArgument::TemplateExpansion:
840 return getDerived().TraverseTemplateName(
841 Arg.getAsTemplateOrTemplatePattern());
843 case TemplateArgument::Expression:
844 return getDerived().TraverseStmt(Arg.getAsExpr());
846 case TemplateArgument::Pack:
847 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
854 // FIXME: no template name location?
855 // FIXME: no source locations for a template argument pack?
856 template <typename Derived>
857 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
858 const TemplateArgumentLoc &ArgLoc) {
859 const TemplateArgument &Arg = ArgLoc.getArgument();
861 switch (Arg.getKind()) {
862 case TemplateArgument::Null:
863 case TemplateArgument::Declaration:
864 case TemplateArgument::Integral:
865 case TemplateArgument::NullPtr:
868 case TemplateArgument::Type: {
869 // FIXME: how can TSI ever be NULL?
870 if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
871 return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
873 return getDerived().TraverseType(Arg.getAsType());
876 case TemplateArgument::Template:
877 case TemplateArgument::TemplateExpansion:
878 if (ArgLoc.getTemplateQualifierLoc())
879 TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
880 ArgLoc.getTemplateQualifierLoc()));
881 return getDerived().TraverseTemplateName(
882 Arg.getAsTemplateOrTemplatePattern());
884 case TemplateArgument::Expression:
885 return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
887 case TemplateArgument::Pack:
888 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
895 template <typename Derived>
896 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
897 const TemplateArgument *Args, unsigned NumArgs) {
898 for (unsigned I = 0; I != NumArgs; ++I) {
899 TRY_TO(TraverseTemplateArgument(Args[I]));
905 template <typename Derived>
906 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
907 CXXCtorInitializer *Init) {
908 if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
909 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
911 if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
912 TRY_TO(TraverseStmt(Init->getInit()));
917 template <typename Derived>
919 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
920 const LambdaCapture *C,
922 if (LE->isInitCapture(C))
923 TRY_TO(TraverseDecl(C->getCapturedVar()));
925 TRY_TO(TraverseStmt(Init));
929 template <typename Derived>
930 bool RecursiveASTVisitor<Derived>::TraverseLambdaBody(
931 LambdaExpr *LE, DataRecursionQueue *Queue) {
932 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(LE->getBody());
936 // ----------------- Type traversal -----------------
938 // This macro makes available a variable T, the passed-in type.
939 #define DEF_TRAVERSE_TYPE(TYPE, CODE) \
940 template <typename Derived> \
941 bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) { \
942 if (!getDerived().shouldTraversePostOrder()) \
943 TRY_TO(WalkUpFrom##TYPE(T)); \
945 if (getDerived().shouldTraversePostOrder()) \
946 TRY_TO(WalkUpFrom##TYPE(T)); \
950 DEF_TRAVERSE_TYPE(BuiltinType, {})
952 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
954 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
956 DEF_TRAVERSE_TYPE(BlockPointerType,
957 { TRY_TO(TraverseType(T->getPointeeType())); })
959 DEF_TRAVERSE_TYPE(LValueReferenceType,
960 { TRY_TO(TraverseType(T->getPointeeType())); })
962 DEF_TRAVERSE_TYPE(RValueReferenceType,
963 { TRY_TO(TraverseType(T->getPointeeType())); })
965 DEF_TRAVERSE_TYPE(MemberPointerType, {
966 TRY_TO(TraverseType(QualType(T->getClass(), 0)));
967 TRY_TO(TraverseType(T->getPointeeType()));
970 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
972 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
974 DEF_TRAVERSE_TYPE(ConstantArrayType,
975 { TRY_TO(TraverseType(T->getElementType())); })
977 DEF_TRAVERSE_TYPE(IncompleteArrayType,
978 { TRY_TO(TraverseType(T->getElementType())); })
980 DEF_TRAVERSE_TYPE(VariableArrayType, {
981 TRY_TO(TraverseType(T->getElementType()));
982 TRY_TO(TraverseStmt(T->getSizeExpr()));
985 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
986 TRY_TO(TraverseType(T->getElementType()));
987 if (T->getSizeExpr())
988 TRY_TO(TraverseStmt(T->getSizeExpr()));
991 DEF_TRAVERSE_TYPE(DependentAddressSpaceType, {
992 TRY_TO(TraverseStmt(T->getAddrSpaceExpr()));
993 TRY_TO(TraverseType(T->getPointeeType()));
996 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
997 if (T->getSizeExpr())
998 TRY_TO(TraverseStmt(T->getSizeExpr()));
999 TRY_TO(TraverseType(T->getElementType()));
1002 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
1004 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
1006 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
1007 { TRY_TO(TraverseType(T->getReturnType())); })
1009 DEF_TRAVERSE_TYPE(FunctionProtoType, {
1010 TRY_TO(TraverseType(T->getReturnType()));
1012 for (const auto &A : T->param_types()) {
1013 TRY_TO(TraverseType(A));
1016 for (const auto &E : T->exceptions()) {
1017 TRY_TO(TraverseType(E));
1020 if (Expr *NE = T->getNoexceptExpr())
1021 TRY_TO(TraverseStmt(NE));
1024 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
1025 DEF_TRAVERSE_TYPE(TypedefType, {})
1027 DEF_TRAVERSE_TYPE(TypeOfExprType,
1028 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1030 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
1032 DEF_TRAVERSE_TYPE(DecltypeType,
1033 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1035 DEF_TRAVERSE_TYPE(UnaryTransformType, {
1036 TRY_TO(TraverseType(T->getBaseType()));
1037 TRY_TO(TraverseType(T->getUnderlyingType()));
1040 DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
1041 DEF_TRAVERSE_TYPE(DeducedTemplateSpecializationType, {
1042 TRY_TO(TraverseTemplateName(T->getTemplateName()));
1043 TRY_TO(TraverseType(T->getDeducedType()));
1046 DEF_TRAVERSE_TYPE(RecordType, {})
1047 DEF_TRAVERSE_TYPE(EnumType, {})
1048 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
1049 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {
1050 TRY_TO(TraverseType(T->getReplacementType()));
1052 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {
1053 TRY_TO(TraverseTemplateArgument(T->getArgumentPack()));
1056 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
1057 TRY_TO(TraverseTemplateName(T->getTemplateName()));
1058 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1061 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
1063 DEF_TRAVERSE_TYPE(AttributedType,
1064 { TRY_TO(TraverseType(T->getModifiedType())); })
1066 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
1068 DEF_TRAVERSE_TYPE(ElaboratedType, {
1069 if (T->getQualifier()) {
1070 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1072 TRY_TO(TraverseType(T->getNamedType()));
1075 DEF_TRAVERSE_TYPE(DependentNameType,
1076 { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
1078 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
1079 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1080 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1083 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
1085 DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
1087 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
1089 DEF_TRAVERSE_TYPE(ObjCObjectType, {
1090 // We have to watch out here because an ObjCInterfaceType's base
1092 if (T->getBaseType().getTypePtr() != T)
1093 TRY_TO(TraverseType(T->getBaseType()));
1094 for (auto typeArg : T->getTypeArgsAsWritten()) {
1095 TRY_TO(TraverseType(typeArg));
1099 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
1100 { TRY_TO(TraverseType(T->getPointeeType())); })
1102 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
1104 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
1106 #undef DEF_TRAVERSE_TYPE
1108 // ----------------- TypeLoc traversal -----------------
1110 // This macro makes available a variable TL, the passed-in TypeLoc.
1111 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
1112 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
1113 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
1114 // continue to work.
1115 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \
1116 template <typename Derived> \
1117 bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
1118 if (getDerived().shouldWalkTypesOfTypeLocs()) \
1119 TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \
1120 TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
1125 template <typename Derived>
1127 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
1128 // Move this over to the 'main' typeloc tree. Note that this is a
1129 // move -- we pretend that we were really looking at the unqualified
1130 // typeloc all along -- rather than a recursion, so we don't follow
1131 // the normal CRTP plan of going through
1132 // getDerived().TraverseTypeLoc. If we did, we'd be traversing
1133 // twice for the same type (once as a QualifiedTypeLoc version of
1134 // the type, once as an UnqualifiedTypeLoc version of the type),
1135 // which in effect means we'd call VisitTypeLoc twice with the
1136 // 'same' type. This solves that problem, at the cost of never
1137 // seeing the qualified version of the type (unless the client
1138 // subclasses TraverseQualifiedTypeLoc themselves). It's not a
1139 // perfect solution. A perfect solution probably requires making
1140 // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
1141 // wrapper around Type* -- rather than being its own class in the
1143 return TraverseTypeLoc(TL.getUnqualifiedLoc());
1146 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
1148 // FIXME: ComplexTypeLoc is unfinished
1149 DEF_TRAVERSE_TYPELOC(ComplexType, {
1150 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1153 DEF_TRAVERSE_TYPELOC(PointerType,
1154 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1156 DEF_TRAVERSE_TYPELOC(BlockPointerType,
1157 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1159 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1160 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1162 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1163 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1165 // FIXME: location of base class?
1166 // We traverse this in the type case as well, but how is it not reached through
1167 // the pointee type?
1168 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1169 TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1170 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1173 DEF_TRAVERSE_TYPELOC(AdjustedType,
1174 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1176 DEF_TRAVERSE_TYPELOC(DecayedType,
1177 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1179 template <typename Derived>
1180 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
1181 // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1182 TRY_TO(TraverseStmt(TL.getSizeExpr()));
1186 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1187 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1188 return TraverseArrayTypeLocHelper(TL);
1191 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1192 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1193 return TraverseArrayTypeLocHelper(TL);
1196 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1197 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1198 return TraverseArrayTypeLocHelper(TL);
1201 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1202 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1203 return TraverseArrayTypeLocHelper(TL);
1206 DEF_TRAVERSE_TYPELOC(DependentAddressSpaceType, {
1207 TRY_TO(TraverseStmt(TL.getTypePtr()->getAddrSpaceExpr()));
1208 TRY_TO(TraverseType(TL.getTypePtr()->getPointeeType()));
1211 // FIXME: order? why not size expr first?
1212 // FIXME: base VectorTypeLoc is unfinished
1213 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1214 if (TL.getTypePtr()->getSizeExpr())
1215 TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1216 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1219 // FIXME: VectorTypeLoc is unfinished
1220 DEF_TRAVERSE_TYPELOC(VectorType, {
1221 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1224 // FIXME: size and attributes
1225 // FIXME: base VectorTypeLoc is unfinished
1226 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1227 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1230 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1231 { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
1233 // FIXME: location of exception specifications (attributes?)
1234 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1235 TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
1237 const FunctionProtoType *T = TL.getTypePtr();
1239 for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1240 if (TL.getParam(I)) {
1241 TRY_TO(TraverseDecl(TL.getParam(I)));
1242 } else if (I < T->getNumParams()) {
1243 TRY_TO(TraverseType(T->getParamType(I)));
1247 for (const auto &E : T->exceptions()) {
1248 TRY_TO(TraverseType(E));
1251 if (Expr *NE = T->getNoexceptExpr())
1252 TRY_TO(TraverseStmt(NE));
1255 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1256 DEF_TRAVERSE_TYPELOC(TypedefType, {})
1258 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1259 { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
1261 DEF_TRAVERSE_TYPELOC(TypeOfType, {
1262 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1265 // FIXME: location of underlying expr
1266 DEF_TRAVERSE_TYPELOC(DecltypeType, {
1267 TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1270 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1271 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1274 DEF_TRAVERSE_TYPELOC(AutoType, {
1275 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1278 DEF_TRAVERSE_TYPELOC(DeducedTemplateSpecializationType, {
1279 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1280 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1283 DEF_TRAVERSE_TYPELOC(RecordType, {})
1284 DEF_TRAVERSE_TYPELOC(EnumType, {})
1285 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1286 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {
1287 TRY_TO(TraverseType(TL.getTypePtr()->getReplacementType()));
1289 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {
1290 TRY_TO(TraverseTemplateArgument(TL.getTypePtr()->getArgumentPack()));
1293 // FIXME: use the loc for the template name?
1294 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1295 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1296 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1297 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1301 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
1303 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1305 DEF_TRAVERSE_TYPELOC(AttributedType,
1306 { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
1308 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1309 if (TL.getQualifierLoc()) {
1310 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1312 TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1315 DEF_TRAVERSE_TYPELOC(DependentNameType, {
1316 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1319 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1320 if (TL.getQualifierLoc()) {
1321 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1324 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1325 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1329 DEF_TRAVERSE_TYPELOC(PackExpansionType,
1330 { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
1332 DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {})
1334 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
1336 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1337 // We have to watch out here because an ObjCInterfaceType's base
1339 if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1340 TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1341 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
1342 TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
1345 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1346 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1348 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1350 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1352 #undef DEF_TRAVERSE_TYPELOC
1354 // ----------------- Decl traversal -----------------
1356 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1357 // the children that come from the DeclContext associated with it.
1358 // Therefore each Traverse* only needs to worry about children other
1361 template <typename Derived>
1362 bool RecursiveASTVisitor<Derived>::canIgnoreChildDeclWhileTraversingDeclContext(
1363 const Decl *Child) {
1364 // BlockDecls and CapturedDecls are traversed through BlockExprs and
1365 // CapturedStmts respectively.
1366 return isa<BlockDecl>(Child) || isa<CapturedDecl>(Child);
1369 template <typename Derived>
1370 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1374 for (auto *Child : DC->decls()) {
1375 if (!canIgnoreChildDeclWhileTraversingDeclContext(Child))
1376 TRY_TO(TraverseDecl(Child));
1382 // This macro makes available a variable D, the passed-in decl.
1383 #define DEF_TRAVERSE_DECL(DECL, CODE) \
1384 template <typename Derived> \
1385 bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) { \
1386 bool ShouldVisitChildren = true; \
1387 bool ReturnValue = true; \
1388 if (!getDerived().shouldTraversePostOrder()) \
1389 TRY_TO(WalkUpFrom##DECL(D)); \
1391 if (ReturnValue && ShouldVisitChildren) \
1392 TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \
1393 if (ReturnValue && getDerived().shouldTraversePostOrder()) \
1394 TRY_TO(WalkUpFrom##DECL(D)); \
1395 return ReturnValue; \
1398 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
1400 DEF_TRAVERSE_DECL(BlockDecl, {
1401 if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1402 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1403 TRY_TO(TraverseStmt(D->getBody()));
1404 for (const auto &I : D->captures()) {
1405 if (I.hasCopyExpr()) {
1406 TRY_TO(TraverseStmt(I.getCopyExpr()));
1409 ShouldVisitChildren = false;
1412 DEF_TRAVERSE_DECL(CapturedDecl, {
1413 TRY_TO(TraverseStmt(D->getBody()));
1414 ShouldVisitChildren = false;
1417 DEF_TRAVERSE_DECL(EmptyDecl, {})
1419 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1420 { TRY_TO(TraverseStmt(D->getAsmString())); })
1422 DEF_TRAVERSE_DECL(ImportDecl, {})
1424 DEF_TRAVERSE_DECL(FriendDecl, {
1425 // Friend is either decl or a type.
1426 if (D->getFriendType())
1427 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1429 TRY_TO(TraverseDecl(D->getFriendDecl()));
1432 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1433 if (D->getFriendType())
1434 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1436 TRY_TO(TraverseDecl(D->getFriendDecl()));
1437 for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1438 TemplateParameterList *TPL = D->getTemplateParameterList(I);
1439 for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1440 ITPL != ETPL; ++ITPL) {
1441 TRY_TO(TraverseDecl(*ITPL));
1446 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
1447 TRY_TO(TraverseDecl(D->getSpecialization()));
1449 if (D->hasExplicitTemplateArgs()) {
1450 const TemplateArgumentListInfo &args = D->templateArgs();
1451 TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(),
1456 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1458 DEF_TRAVERSE_DECL(ExportDecl, {})
1460 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1463 DEF_TRAVERSE_DECL(StaticAssertDecl, {
1464 TRY_TO(TraverseStmt(D->getAssertExpr()));
1465 TRY_TO(TraverseStmt(D->getMessage()));
1469 TranslationUnitDecl,
1470 {// Code in an unnamed namespace shows up automatically in
1471 // decls_begin()/decls_end(). Thus we don't need to recurse on
1472 // D->getAnonymousNamespace().
1475 DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
1477 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
1479 DEF_TRAVERSE_DECL(ExternCContextDecl, {})
1481 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1482 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1484 // We shouldn't traverse an aliased namespace, since it will be
1485 // defined (and, therefore, traversed) somewhere else.
1486 ShouldVisitChildren = false;
1489 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1494 {// Code in an unnamed namespace shows up automatically in
1495 // decls_begin()/decls_end(). Thus we don't need to recurse on
1496 // D->getAnonymousNamespace().
1499 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1502 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
1503 if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
1504 for (auto typeParam : *typeParamList) {
1505 TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1510 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1513 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1516 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
1517 if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
1518 for (auto typeParam : *typeParamList) {
1519 TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1523 if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
1524 TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
1528 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
1531 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1532 if (D->getReturnTypeSourceInfo()) {
1533 TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1535 for (ParmVarDecl *Parameter : D->parameters()) {
1536 TRY_TO(TraverseDecl(Parameter));
1538 if (D->isThisDeclarationADefinition()) {
1539 TRY_TO(TraverseStmt(D->getBody()));
1541 ShouldVisitChildren = false;
1544 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
1545 if (D->hasExplicitBound()) {
1546 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1547 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1548 // declaring the type alias, not something that was written in the
1553 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1554 if (D->getTypeSourceInfo())
1555 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1557 TRY_TO(TraverseType(D->getType()));
1558 ShouldVisitChildren = false;
1561 DEF_TRAVERSE_DECL(UsingDecl, {
1562 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1563 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1566 DEF_TRAVERSE_DECL(UsingPackDecl, {})
1568 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1569 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1572 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
1574 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
1576 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
1577 for (auto *I : D->varlists()) {
1578 TRY_TO(TraverseStmt(I));
1582 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
1583 TRY_TO(TraverseStmt(D->getCombiner()));
1584 if (auto *Initializer = D->getInitializer())
1585 TRY_TO(TraverseStmt(Initializer));
1586 TRY_TO(TraverseType(D->getType()));
1590 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
1592 // A helper method for TemplateDecl's children.
1593 template <typename Derived>
1594 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1595 TemplateParameterList *TPL) {
1597 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1599 TRY_TO(TraverseDecl(*I));
1605 template <typename Derived>
1606 template <typename T>
1607 bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) {
1608 for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) {
1609 TemplateParameterList *TPL = D->getTemplateParameterList(i);
1610 TraverseTemplateParameterListHelper(TPL);
1615 template <typename Derived>
1616 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1617 ClassTemplateDecl *D) {
1618 for (auto *SD : D->specializations()) {
1619 for (auto *RD : SD->redecls()) {
1620 // We don't want to visit injected-class-names in this traversal.
1621 if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
1625 cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1626 // Visit the implicit instantiations with the requested pattern.
1627 case TSK_Undeclared:
1628 case TSK_ImplicitInstantiation:
1629 TRY_TO(TraverseDecl(RD));
1632 // We don't need to do anything on an explicit instantiation
1633 // or explicit specialization because there will be an explicit
1634 // node for it elsewhere.
1635 case TSK_ExplicitInstantiationDeclaration:
1636 case TSK_ExplicitInstantiationDefinition:
1637 case TSK_ExplicitSpecialization:
1646 template <typename Derived>
1647 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1648 VarTemplateDecl *D) {
1649 for (auto *SD : D->specializations()) {
1650 for (auto *RD : SD->redecls()) {
1652 cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1653 case TSK_Undeclared:
1654 case TSK_ImplicitInstantiation:
1655 TRY_TO(TraverseDecl(RD));
1658 case TSK_ExplicitInstantiationDeclaration:
1659 case TSK_ExplicitInstantiationDefinition:
1660 case TSK_ExplicitSpecialization:
1669 // A helper method for traversing the instantiations of a
1670 // function while skipping its specializations.
1671 template <typename Derived>
1672 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1673 FunctionTemplateDecl *D) {
1674 for (auto *FD : D->specializations()) {
1675 for (auto *RD : FD->redecls()) {
1676 switch (RD->getTemplateSpecializationKind()) {
1677 case TSK_Undeclared:
1678 case TSK_ImplicitInstantiation:
1679 // We don't know what kind of FunctionDecl this is.
1680 TRY_TO(TraverseDecl(RD));
1683 // FIXME: For now traverse explicit instantiations here. Change that
1684 // once they are represented as dedicated nodes in the AST.
1685 case TSK_ExplicitInstantiationDeclaration:
1686 case TSK_ExplicitInstantiationDefinition:
1687 TRY_TO(TraverseDecl(RD));
1690 case TSK_ExplicitSpecialization:
1699 // This macro unifies the traversal of class, variable and function
1700 // template declarations.
1701 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND) \
1702 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, { \
1703 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \
1704 TRY_TO(TraverseDecl(D->getTemplatedDecl())); \
1706 /* By default, we do not traverse the instantiations of \
1707 class templates since they do not appear in the user code. The \
1708 following code optionally traverses them. \
1710 We only traverse the class instantiations when we see the canonical \
1711 declaration of the template, to ensure we only visit them once. */ \
1712 if (getDerived().shouldVisitTemplateInstantiations() && \
1713 D == D->getCanonicalDecl()) \
1714 TRY_TO(TraverseTemplateInstantiations(D)); \
1716 /* Note that getInstantiatedFromMemberTemplate() is just a link \
1717 from a template instantiation back to the template from which \
1718 it was instantiated, and thus should not be traversed. */ \
1721 DEF_TRAVERSE_TMPL_DECL(Class)
1722 DEF_TRAVERSE_TMPL_DECL(Var)
1723 DEF_TRAVERSE_TMPL_DECL(Function)
1725 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1726 // D is the "T" in something like
1727 // template <template <typename> class T> class container { };
1728 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1729 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
1730 TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1732 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1735 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
1736 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1739 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1740 // D is the "T" in something like "template<typename T> class vector;"
1741 if (D->getTypeForDecl())
1742 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1743 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1744 TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1747 DEF_TRAVERSE_DECL(TypedefDecl, {
1748 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1749 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1750 // declaring the typedef, not something that was written in the
1754 DEF_TRAVERSE_DECL(TypeAliasDecl, {
1755 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1756 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1757 // declaring the type alias, not something that was written in the
1761 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
1762 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1763 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1766 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1767 // A dependent using declaration which was marked with 'typename'.
1768 // template<class T> class A : public B<T> { using typename B<T>::foo; };
1769 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1770 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1771 // declaring the type, not something that was written in the
1775 DEF_TRAVERSE_DECL(EnumDecl, {
1776 TRY_TO(TraverseDeclTemplateParameterLists(D));
1778 if (D->getTypeForDecl())
1779 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1781 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1782 // The enumerators are already traversed by
1783 // decls_begin()/decls_end().
1786 // Helper methods for RecordDecl and its children.
1787 template <typename Derived>
1788 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
1789 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1790 // declaring the type, not something that was written in the source.
1792 TRY_TO(TraverseDeclTemplateParameterLists(D));
1793 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1797 template <typename Derived>
1798 bool RecursiveASTVisitor<Derived>::TraverseCXXBaseSpecifier(
1799 const CXXBaseSpecifier &Base) {
1800 TRY_TO(TraverseTypeLoc(Base.getTypeSourceInfo()->getTypeLoc()));
1804 template <typename Derived>
1805 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
1806 if (!TraverseRecordHelper(D))
1808 if (D->isCompleteDefinition()) {
1809 for (const auto &I : D->bases()) {
1810 TRY_TO(TraverseCXXBaseSpecifier(I));
1812 // We don't traverse the friends or the conversions, as they are
1813 // already in decls_begin()/decls_end().
1818 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
1820 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
1822 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND) \
1823 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, { \
1824 /* For implicit instantiations ("set<int> x;"), we don't want to \
1825 recurse at all, since the instatiated template isn't written in \
1826 the source code anywhere. (Note the instatiated *type* -- \
1827 set<int> -- is written, and will still get a callback of \
1828 TemplateSpecializationType). For explicit instantiations \
1829 ("template set<int>;"), we do need a callback, since this \
1830 is the only callback that's made for this instantiation. \
1831 We use getTypeAsWritten() to distinguish. */ \
1832 if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \
1833 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \
1835 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \
1836 if (!getDerived().shouldVisitTemplateInstantiations() && \
1837 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) \
1838 /* Returning from here skips traversing the \
1839 declaration context of the *TemplateSpecializationDecl \
1840 (embedded in the DEF_TRAVERSE_DECL() macro) \
1841 which contains the instantiated members of the template. */ \
1845 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)
1846 DEF_TRAVERSE_TMPL_SPEC_DECL(Var)
1848 template <typename Derived>
1849 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1850 const TemplateArgumentLoc *TAL, unsigned Count) {
1851 for (unsigned I = 0; I < Count; ++I) {
1852 TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1857 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND) \
1858 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, { \
1859 /* The partial specialization. */ \
1860 if (TemplateParameterList *TPL = D->getTemplateParameters()) { \
1861 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); \
1863 TRY_TO(TraverseDecl(*I)); \
1866 /* The args that remains unspecialized. */ \
1867 TRY_TO(TraverseTemplateArgumentLocsHelper( \
1868 D->getTemplateArgsAsWritten()->getTemplateArgs(), \
1869 D->getTemplateArgsAsWritten()->NumTemplateArgs)); \
1871 /* Don't need the *TemplatePartialSpecializationHelper, even \
1872 though that's our parent class -- we already visit all the \
1873 template args here. */ \
1874 TRY_TO(Traverse##DECLKIND##Helper(D)); \
1876 /* Instantiations will have been visited with the primary template. */ \
1879 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
1880 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
1882 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
1884 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1885 // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1886 // template <class T> Class A : public Base<T> { using Base<T>::foo; };
1887 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1888 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1891 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1893 template <typename Derived>
1894 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1895 TRY_TO(TraverseDeclTemplateParameterLists(D));
1896 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1897 if (D->getTypeSourceInfo())
1898 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1900 TRY_TO(TraverseType(D->getType()));
1904 DEF_TRAVERSE_DECL(DecompositionDecl, {
1905 TRY_TO(TraverseVarHelper(D));
1906 for (auto *Binding : D->bindings()) {
1907 TRY_TO(TraverseDecl(Binding));
1911 DEF_TRAVERSE_DECL(BindingDecl, {
1912 if (getDerived().shouldVisitImplicitCode())
1913 TRY_TO(TraverseStmt(D->getBinding()));
1916 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
1918 DEF_TRAVERSE_DECL(FieldDecl, {
1919 TRY_TO(TraverseDeclaratorHelper(D));
1920 if (D->isBitField())
1921 TRY_TO(TraverseStmt(D->getBitWidth()));
1922 else if (D->hasInClassInitializer())
1923 TRY_TO(TraverseStmt(D->getInClassInitializer()));
1926 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1927 TRY_TO(TraverseDeclaratorHelper(D));
1928 if (D->isBitField())
1929 TRY_TO(TraverseStmt(D->getBitWidth()));
1930 // FIXME: implement the rest.
1933 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1934 TRY_TO(TraverseDeclaratorHelper(D));
1935 if (D->isBitField())
1936 TRY_TO(TraverseStmt(D->getBitWidth()));
1937 // FIXME: implement the rest.
1940 template <typename Derived>
1941 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1942 TRY_TO(TraverseDeclTemplateParameterLists(D));
1943 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1944 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1946 // If we're an explicit template specialization, iterate over the
1947 // template args that were explicitly specified. If we were doing
1948 // this in typing order, we'd do it between the return type and
1949 // the function args, but both are handled by the FunctionTypeLoc
1950 // above, so we have to choose one side. I've decided to do before.
1951 if (const FunctionTemplateSpecializationInfo *FTSI =
1952 D->getTemplateSpecializationInfo()) {
1953 if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1954 FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1955 // A specialization might not have explicit template arguments if it has
1956 // a templated return type and concrete arguments.
1957 if (const ASTTemplateArgumentListInfo *TALI =
1958 FTSI->TemplateArgumentsAsWritten) {
1959 TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1960 TALI->NumTemplateArgs));
1965 // Visit the function type itself, which can be either
1966 // FunctionNoProtoType or FunctionProtoType, or a typedef. This
1967 // also covers the return type and the function parameters,
1968 // including exception specifications.
1969 if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
1970 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1971 } else if (getDerived().shouldVisitImplicitCode()) {
1972 // Visit parameter variable declarations of the implicit function
1973 // if the traverser is visiting implicit code. Parameter variable
1974 // declarations do not have valid TypeSourceInfo, so to visit them
1975 // we need to traverse the declarations explicitly.
1976 for (ParmVarDecl *Parameter : D->parameters()) {
1977 TRY_TO(TraverseDecl(Parameter));
1981 if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1982 // Constructor initializers.
1983 for (auto *I : Ctor->inits()) {
1984 TRY_TO(TraverseConstructorInitializer(I));
1988 if (D->isThisDeclarationADefinition()) {
1989 TRY_TO(TraverseStmt(D->getBody())); // Function body.
1994 DEF_TRAVERSE_DECL(FunctionDecl, {
1995 // We skip decls_begin/decls_end, which are already covered by
1996 // TraverseFunctionHelper().
1997 ShouldVisitChildren = false;
1998 ReturnValue = TraverseFunctionHelper(D);
2001 DEF_TRAVERSE_DECL(CXXDeductionGuideDecl, {
2002 // We skip decls_begin/decls_end, which are already covered by
2003 // TraverseFunctionHelper().
2004 ShouldVisitChildren = false;
2005 ReturnValue = TraverseFunctionHelper(D);
2008 DEF_TRAVERSE_DECL(CXXMethodDecl, {
2009 // We skip decls_begin/decls_end, which are already covered by
2010 // TraverseFunctionHelper().
2011 ShouldVisitChildren = false;
2012 ReturnValue = TraverseFunctionHelper(D);
2015 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
2016 // We skip decls_begin/decls_end, which are already covered by
2017 // TraverseFunctionHelper().
2018 ShouldVisitChildren = false;
2019 ReturnValue = TraverseFunctionHelper(D);
2022 // CXXConversionDecl is the declaration of a type conversion operator.
2023 // It's not a cast expression.
2024 DEF_TRAVERSE_DECL(CXXConversionDecl, {
2025 // We skip decls_begin/decls_end, which are already covered by
2026 // TraverseFunctionHelper().
2027 ShouldVisitChildren = false;
2028 ReturnValue = TraverseFunctionHelper(D);
2031 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
2032 // We skip decls_begin/decls_end, which are already covered by
2033 // TraverseFunctionHelper().
2034 ShouldVisitChildren = false;
2035 ReturnValue = TraverseFunctionHelper(D);
2038 template <typename Derived>
2039 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
2040 TRY_TO(TraverseDeclaratorHelper(D));
2041 // Default params are taken care of when we traverse the ParmVarDecl.
2042 if (!isa<ParmVarDecl>(D) &&
2043 (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
2044 TRY_TO(TraverseStmt(D->getInit()));
2048 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
2050 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
2052 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
2053 // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
2054 TRY_TO(TraverseDeclaratorHelper(D));
2055 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
2056 TRY_TO(TraverseStmt(D->getDefaultArgument()));
2059 DEF_TRAVERSE_DECL(ParmVarDecl, {
2060 TRY_TO(TraverseVarHelper(D));
2062 if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
2063 !D->hasUnparsedDefaultArg())
2064 TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
2066 if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
2067 !D->hasUnparsedDefaultArg())
2068 TRY_TO(TraverseStmt(D->getDefaultArg()));
2071 #undef DEF_TRAVERSE_DECL
2073 // ----------------- Stmt traversal -----------------
2075 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
2076 // over the children defined in children() (every stmt defines these,
2077 // though sometimes the range is empty). Each individual Traverse*
2078 // method only needs to worry about children other than those. To see
2079 // what children() does for a given class, see, e.g.,
2080 // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
2082 // This macro makes available a variable S, the passed-in stmt.
2083 #define DEF_TRAVERSE_STMT(STMT, CODE) \
2084 template <typename Derived> \
2085 bool RecursiveASTVisitor<Derived>::Traverse##STMT( \
2086 STMT *S, DataRecursionQueue *Queue) { \
2087 bool ShouldVisitChildren = true; \
2088 bool ReturnValue = true; \
2089 if (!getDerived().shouldTraversePostOrder()) \
2090 TRY_TO(WalkUpFrom##STMT(S)); \
2092 if (ShouldVisitChildren) { \
2093 for (Stmt * SubStmt : getDerived().getStmtChildren(S)) { \
2094 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt); \
2097 if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder()) \
2098 TRY_TO(WalkUpFrom##STMT(S)); \
2099 return ReturnValue; \
2102 DEF_TRAVERSE_STMT(GCCAsmStmt, {
2103 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
2104 for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
2105 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
2107 for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
2108 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
2110 for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
2111 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
2113 // children() iterates over inputExpr and outputExpr.
2118 {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc. Once
2119 // added this needs to be implemented.
2122 DEF_TRAVERSE_STMT(CXXCatchStmt, {
2123 TRY_TO(TraverseDecl(S->getExceptionDecl()));
2124 // children() iterates over the handler block.
2127 DEF_TRAVERSE_STMT(DeclStmt, {
2128 for (auto *I : S->decls()) {
2129 TRY_TO(TraverseDecl(I));
2131 // Suppress the default iteration over children() by
2132 // returning. Here's why: A DeclStmt looks like 'type var [=
2133 // initializer]'. The decls above already traverse over the
2134 // initializers, so we don't have to do it again (which
2135 // children() would do).
2136 ShouldVisitChildren = false;
2139 // These non-expr stmts (most of them), do not need any action except
2140 // iterating over the children.
2141 DEF_TRAVERSE_STMT(BreakStmt, {})
2142 DEF_TRAVERSE_STMT(CXXTryStmt, {})
2143 DEF_TRAVERSE_STMT(CaseStmt, {})
2144 DEF_TRAVERSE_STMT(CompoundStmt, {})
2145 DEF_TRAVERSE_STMT(ContinueStmt, {})
2146 DEF_TRAVERSE_STMT(DefaultStmt, {})
2147 DEF_TRAVERSE_STMT(DoStmt, {})
2148 DEF_TRAVERSE_STMT(ForStmt, {})
2149 DEF_TRAVERSE_STMT(GotoStmt, {})
2150 DEF_TRAVERSE_STMT(IfStmt, {})
2151 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
2152 DEF_TRAVERSE_STMT(LabelStmt, {})
2153 DEF_TRAVERSE_STMT(AttributedStmt, {})
2154 DEF_TRAVERSE_STMT(NullStmt, {})
2155 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
2156 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
2157 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
2158 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
2159 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
2160 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
2161 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
2163 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
2164 if (!getDerived().shouldVisitImplicitCode()) {
2165 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
2166 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
2167 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2168 // Visit everything else only if shouldVisitImplicitCode().
2169 ShouldVisitChildren = false;
2173 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
2174 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2175 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2178 DEF_TRAVERSE_STMT(ReturnStmt, {})
2179 DEF_TRAVERSE_STMT(SwitchStmt, {})
2180 DEF_TRAVERSE_STMT(WhileStmt, {})
2182 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
2183 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2184 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2185 if (S->hasExplicitTemplateArgs()) {
2186 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2187 S->getNumTemplateArgs()));
2191 DEF_TRAVERSE_STMT(DeclRefExpr, {
2192 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2193 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2194 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2195 S->getNumTemplateArgs()));
2198 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
2199 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2200 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2201 if (S->hasExplicitTemplateArgs()) {
2202 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2203 S->getNumTemplateArgs()));
2207 DEF_TRAVERSE_STMT(MemberExpr, {
2208 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2209 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2210 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2211 S->getNumTemplateArgs()));
2216 {// We don't traverse the cast type, as it's not written in the
2220 DEF_TRAVERSE_STMT(CStyleCastExpr, {
2221 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2224 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
2225 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2228 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
2229 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2232 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
2233 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2236 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
2237 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2240 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
2241 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2244 template <typename Derived>
2245 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
2246 InitListExpr *S, DataRecursionQueue *Queue) {
2248 // Skip this if we traverse postorder. We will visit it later
2249 // in PostVisitStmt.
2250 if (!getDerived().shouldTraversePostOrder())
2251 TRY_TO(WalkUpFromInitListExpr(S));
2253 // All we need are the default actions. FIXME: use a helper function.
2254 for (Stmt *SubStmt : S->children()) {
2255 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
2261 // This method is called once for each pair of syntactic and semantic
2262 // InitListExpr, and it traverses the subtrees defined by the two forms. This
2263 // may cause some of the children to be visited twice, if they appear both in
2264 // the syntactic and the semantic form.
2266 // There is no guarantee about which form \p S takes when this method is called.
2267 template <typename Derived>
2268 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(
2269 InitListExpr *S, DataRecursionQueue *Queue) {
2270 TRY_TO(TraverseSynOrSemInitListExpr(
2271 S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
2272 TRY_TO(TraverseSynOrSemInitListExpr(
2273 S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
2277 // GenericSelectionExpr is a special case because the types and expressions
2278 // are interleaved. We also need to watch out for null types (default
2279 // generic associations).
2280 DEF_TRAVERSE_STMT(GenericSelectionExpr, {
2281 TRY_TO(TraverseStmt(S->getControllingExpr()));
2282 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
2283 if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
2284 TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
2285 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAssocExpr(i));
2287 ShouldVisitChildren = false;
2290 // PseudoObjectExpr is a special case because of the weirdness with
2291 // syntactic expressions and opaque values.
2292 DEF_TRAVERSE_STMT(PseudoObjectExpr, {
2293 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
2294 for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2295 e = S->semantics_end();
2298 if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2299 sub = OVE->getSourceExpr();
2300 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub);
2302 ShouldVisitChildren = false;
2305 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
2306 // This is called for code like 'return T()' where T is a built-in
2307 // (i.e. non-class) type.
2308 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2311 DEF_TRAVERSE_STMT(CXXNewExpr, {
2312 // The child-iterator will pick up the other arguments.
2313 TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
2316 DEF_TRAVERSE_STMT(OffsetOfExpr, {
2317 // The child-iterator will pick up the expression representing
2319 // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2320 // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2321 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2324 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2325 // The child-iterator will pick up the arg if it's an expression,
2326 // but not if it's a type.
2327 if (S->isArgumentType())
2328 TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2331 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2332 // The child-iterator will pick up the arg if it's an expression,
2333 // but not if it's a type.
2334 if (S->isTypeOperand())
2335 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2338 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2339 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2342 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
2344 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2345 // The child-iterator will pick up the arg if it's an expression,
2346 // but not if it's a type.
2347 if (S->isTypeOperand())
2348 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2351 DEF_TRAVERSE_STMT(TypeTraitExpr, {
2352 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2353 TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2356 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2357 TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2360 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2361 { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
2363 DEF_TRAVERSE_STMT(VAArgExpr, {
2364 // The child-iterator will pick up the expression argument.
2365 TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2368 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2369 // This is called for code like 'return T()' where T is a class type.
2370 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2373 // Walk only the visible parts of lambda expressions.
2374 DEF_TRAVERSE_STMT(LambdaExpr, {
2375 for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
2376 const LambdaCapture *C = S->capture_begin() + I;
2377 if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
2378 TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
2382 TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2383 FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>();
2385 if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2386 // Visit the whole type.
2387 TRY_TO(TraverseTypeLoc(TL));
2389 if (S->hasExplicitParameters()) {
2390 // Visit parameters.
2391 for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
2392 TRY_TO(TraverseDecl(Proto.getParam(I)));
2394 } else if (S->hasExplicitResultType()) {
2395 TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
2398 auto *T = Proto.getTypePtr();
2399 for (const auto &E : T->exceptions()) {
2400 TRY_TO(TraverseType(E));
2403 if (Expr *NE = T->getNoexceptExpr())
2404 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
2407 ReturnValue = TRAVERSE_STMT_BASE(LambdaBody, LambdaExpr, S, Queue);
2408 ShouldVisitChildren = false;
2411 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2412 // This is called for code like 'T()', where T is a template argument.
2413 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2416 // These expressions all might take explicit template arguments.
2417 // We traverse those if so. FIXME: implement these.
2418 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2419 DEF_TRAVERSE_STMT(CallExpr, {})
2420 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
2422 // These exprs (most of them), do not need any action except iterating
2423 // over the children.
2424 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2425 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
2426 DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
2428 DEF_TRAVERSE_STMT(BlockExpr, {
2429 TRY_TO(TraverseDecl(S->getBlockDecl()));
2430 return true; // no child statements to loop through.
2433 DEF_TRAVERSE_STMT(ChooseExpr, {})
2434 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2435 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2437 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2438 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2440 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
2441 if (getDerived().shouldVisitImplicitCode())
2442 TRY_TO(TraverseStmt(S->getExpr()));
2445 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
2446 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2447 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2448 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
2449 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2450 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
2452 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2453 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2454 if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2455 TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2456 if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2457 TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2460 DEF_TRAVERSE_STMT(CXXThisExpr, {})
2461 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2462 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2463 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2464 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
2465 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2466 DEF_TRAVERSE_STMT(GNUNullExpr, {})
2467 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2468 DEF_TRAVERSE_STMT(NoInitExpr, {})
2469 DEF_TRAVERSE_STMT(ArrayInitLoopExpr, {
2470 // FIXME: The source expression of the OVE should be listed as
2471 // a child of the ArrayInitLoopExpr.
2472 if (OpaqueValueExpr *OVE = S->getCommonExpr())
2473 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr());
2475 DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {})
2476 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
2478 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2479 if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2480 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2483 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2484 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
2486 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2487 if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2488 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2491 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
2492 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2493 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2494 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2495 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
2497 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2498 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2501 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
2502 DEF_TRAVERSE_STMT(ParenExpr, {})
2503 DEF_TRAVERSE_STMT(ParenListExpr, {})
2504 DEF_TRAVERSE_STMT(PredefinedExpr, {})
2505 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2506 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2507 DEF_TRAVERSE_STMT(StmtExpr, {})
2508 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2509 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2510 if (S->hasExplicitTemplateArgs()) {
2511 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2512 S->getNumTemplateArgs()));
2516 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2517 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2518 if (S->hasExplicitTemplateArgs()) {
2519 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2520 S->getNumTemplateArgs()));
2524 DEF_TRAVERSE_STMT(SEHTryStmt, {})
2525 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2526 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
2527 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
2528 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2530 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2531 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
2532 DEF_TRAVERSE_STMT(TypoExpr, {})
2533 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
2535 // These operators (all of them) do not need any action except
2536 // iterating over the children.
2537 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2538 DEF_TRAVERSE_STMT(ConditionalOperator, {})
2539 DEF_TRAVERSE_STMT(UnaryOperator, {})
2540 DEF_TRAVERSE_STMT(BinaryOperator, {})
2541 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2542 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2543 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2544 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2545 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2546 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2547 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2548 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
2549 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
2550 DEF_TRAVERSE_STMT(AtomicExpr, {})
2552 // For coroutines expressions, traverse either the operand
2553 // as written or the implied calls, depending on what the
2554 // derived class requests.
2555 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
2556 if (!getDerived().shouldVisitImplicitCode()) {
2557 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2558 ShouldVisitChildren = false;
2561 DEF_TRAVERSE_STMT(CoreturnStmt, {
2562 if (!getDerived().shouldVisitImplicitCode()) {
2563 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2564 ShouldVisitChildren = false;
2567 DEF_TRAVERSE_STMT(CoawaitExpr, {
2568 if (!getDerived().shouldVisitImplicitCode()) {
2569 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2570 ShouldVisitChildren = false;
2573 DEF_TRAVERSE_STMT(DependentCoawaitExpr, {
2574 if (!getDerived().shouldVisitImplicitCode()) {
2575 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2576 ShouldVisitChildren = false;
2579 DEF_TRAVERSE_STMT(CoyieldExpr, {
2580 if (!getDerived().shouldVisitImplicitCode()) {
2581 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2582 ShouldVisitChildren = false;
2586 // These literals (all of them) do not need any action.
2587 DEF_TRAVERSE_STMT(IntegerLiteral, {})
2588 DEF_TRAVERSE_STMT(CharacterLiteral, {})
2589 DEF_TRAVERSE_STMT(FloatingLiteral, {})
2590 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
2591 DEF_TRAVERSE_STMT(StringLiteral, {})
2592 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
2593 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
2594 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
2595 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
2597 // Traverse OpenCL: AsType, Convert.
2598 DEF_TRAVERSE_STMT(AsTypeExpr, {})
2600 // OpenMP directives.
2601 template <typename Derived>
2602 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
2603 OMPExecutableDirective *S) {
2604 for (auto *C : S->clauses()) {
2605 TRY_TO(TraverseOMPClause(C));
2610 template <typename Derived>
2612 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
2613 return TraverseOMPExecutableDirective(S);
2616 DEF_TRAVERSE_STMT(OMPParallelDirective,
2617 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2619 DEF_TRAVERSE_STMT(OMPSimdDirective,
2620 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2622 DEF_TRAVERSE_STMT(OMPForDirective,
2623 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2625 DEF_TRAVERSE_STMT(OMPForSimdDirective,
2626 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2628 DEF_TRAVERSE_STMT(OMPSectionsDirective,
2629 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2631 DEF_TRAVERSE_STMT(OMPSectionDirective,
2632 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2634 DEF_TRAVERSE_STMT(OMPSingleDirective,
2635 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2637 DEF_TRAVERSE_STMT(OMPMasterDirective,
2638 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2640 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
2641 TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
2642 TRY_TO(TraverseOMPExecutableDirective(S));
2645 DEF_TRAVERSE_STMT(OMPParallelForDirective,
2646 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2648 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
2649 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2651 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
2652 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2654 DEF_TRAVERSE_STMT(OMPTaskDirective,
2655 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2657 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
2658 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2660 DEF_TRAVERSE_STMT(OMPBarrierDirective,
2661 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2663 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
2664 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2666 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
2667 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2669 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
2670 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2672 DEF_TRAVERSE_STMT(OMPCancelDirective,
2673 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2675 DEF_TRAVERSE_STMT(OMPFlushDirective,
2676 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2678 DEF_TRAVERSE_STMT(OMPOrderedDirective,
2679 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2681 DEF_TRAVERSE_STMT(OMPAtomicDirective,
2682 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2684 DEF_TRAVERSE_STMT(OMPTargetDirective,
2685 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2687 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
2688 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2690 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
2691 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2693 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
2694 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2696 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
2697 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2699 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
2700 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2702 DEF_TRAVERSE_STMT(OMPTeamsDirective,
2703 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2705 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
2706 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2708 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
2709 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2711 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
2712 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2714 DEF_TRAVERSE_STMT(OMPDistributeDirective,
2715 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2717 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
2718 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2720 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
2721 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2723 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
2724 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2726 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
2727 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2729 DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
2730 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2732 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
2733 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2735 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
2736 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2738 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
2739 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2741 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
2742 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2744 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
2745 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2747 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
2748 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2750 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
2751 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2753 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective,
2754 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2756 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective,
2757 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2760 template <typename Derived>
2761 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
2764 switch (C->getClauseKind()) {
2765 #define OPENMP_CLAUSE(Name, Class) \
2767 TRY_TO(Visit##Class(static_cast<Class *>(C))); \
2769 #include "clang/Basic/OpenMPKinds.def"
2770 case OMPC_threadprivate:
2778 template <typename Derived>
2779 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
2780 OMPClauseWithPreInit *Node) {
2781 TRY_TO(TraverseStmt(Node->getPreInitStmt()));
2785 template <typename Derived>
2786 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
2787 OMPClauseWithPostUpdate *Node) {
2788 TRY_TO(VisitOMPClauseWithPreInit(Node));
2789 TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
2793 template <typename Derived>
2794 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
2795 TRY_TO(VisitOMPClauseWithPreInit(C));
2796 TRY_TO(TraverseStmt(C->getCondition()));
2800 template <typename Derived>
2801 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
2802 TRY_TO(TraverseStmt(C->getCondition()));
2806 template <typename Derived>
2808 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
2809 TRY_TO(VisitOMPClauseWithPreInit(C));
2810 TRY_TO(TraverseStmt(C->getNumThreads()));
2814 template <typename Derived>
2815 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
2816 TRY_TO(TraverseStmt(C->getSafelen()));
2820 template <typename Derived>
2821 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
2822 TRY_TO(TraverseStmt(C->getSimdlen()));
2826 template <typename Derived>
2828 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
2829 TRY_TO(TraverseStmt(C->getNumForLoops()));
2833 template <typename Derived>
2834 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
2838 template <typename Derived>
2839 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
2843 template <typename Derived>
2845 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
2846 TRY_TO(VisitOMPClauseWithPreInit(C));
2847 TRY_TO(TraverseStmt(C->getChunkSize()));
2851 template <typename Derived>
2852 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
2853 TRY_TO(TraverseStmt(C->getNumForLoops()));
2857 template <typename Derived>
2858 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
2862 template <typename Derived>
2863 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
2867 template <typename Derived>
2869 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
2873 template <typename Derived>
2874 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
2878 template <typename Derived>
2879 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
2883 template <typename Derived>
2884 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
2888 template <typename Derived>
2889 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2893 template <typename Derived>
2894 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2898 template <typename Derived>
2899 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
2903 template <typename Derived>
2904 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
2908 template <typename Derived>
2909 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
2913 template <typename Derived>
2914 template <typename T>
2915 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
2916 for (auto *E : Node->varlists()) {
2917 TRY_TO(TraverseStmt(E));
2922 template <typename Derived>
2923 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
2924 TRY_TO(VisitOMPClauseList(C));
2925 for (auto *E : C->private_copies()) {
2926 TRY_TO(TraverseStmt(E));
2931 template <typename Derived>
2932 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
2933 OMPFirstprivateClause *C) {
2934 TRY_TO(VisitOMPClauseList(C));
2935 TRY_TO(VisitOMPClauseWithPreInit(C));
2936 for (auto *E : C->private_copies()) {
2937 TRY_TO(TraverseStmt(E));
2939 for (auto *E : C->inits()) {
2940 TRY_TO(TraverseStmt(E));
2945 template <typename Derived>
2946 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
2947 OMPLastprivateClause *C) {
2948 TRY_TO(VisitOMPClauseList(C));
2949 TRY_TO(VisitOMPClauseWithPostUpdate(C));
2950 for (auto *E : C->private_copies()) {
2951 TRY_TO(TraverseStmt(E));
2953 for (auto *E : C->source_exprs()) {
2954 TRY_TO(TraverseStmt(E));
2956 for (auto *E : C->destination_exprs()) {
2957 TRY_TO(TraverseStmt(E));
2959 for (auto *E : C->assignment_ops()) {
2960 TRY_TO(TraverseStmt(E));
2965 template <typename Derived>
2966 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
2967 TRY_TO(VisitOMPClauseList(C));
2971 template <typename Derived>
2972 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2973 TRY_TO(TraverseStmt(C->getStep()));
2974 TRY_TO(TraverseStmt(C->getCalcStep()));
2975 TRY_TO(VisitOMPClauseList(C));
2976 TRY_TO(VisitOMPClauseWithPostUpdate(C));
2977 for (auto *E : C->privates()) {
2978 TRY_TO(TraverseStmt(E));
2980 for (auto *E : C->inits()) {
2981 TRY_TO(TraverseStmt(E));
2983 for (auto *E : C->updates()) {
2984 TRY_TO(TraverseStmt(E));
2986 for (auto *E : C->finals()) {
2987 TRY_TO(TraverseStmt(E));
2992 template <typename Derived>
2993 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
2994 TRY_TO(TraverseStmt(C->getAlignment()));
2995 TRY_TO(VisitOMPClauseList(C));
2999 template <typename Derived>
3000 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
3001 TRY_TO(VisitOMPClauseList(C));
3002 for (auto *E : C->source_exprs()) {
3003 TRY_TO(TraverseStmt(E));
3005 for (auto *E : C->destination_exprs()) {
3006 TRY_TO(TraverseStmt(E));
3008 for (auto *E : C->assignment_ops()) {
3009 TRY_TO(TraverseStmt(E));
3014 template <typename Derived>
3015 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
3016 OMPCopyprivateClause *C) {
3017 TRY_TO(VisitOMPClauseList(C));
3018 for (auto *E : C->source_exprs()) {
3019 TRY_TO(TraverseStmt(E));
3021 for (auto *E : C->destination_exprs()) {
3022 TRY_TO(TraverseStmt(E));
3024 for (auto *E : C->assignment_ops()) {
3025 TRY_TO(TraverseStmt(E));
3030 template <typename Derived>
3032 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
3033 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3034 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3035 TRY_TO(VisitOMPClauseList(C));
3036 TRY_TO(VisitOMPClauseWithPostUpdate(C));
3037 for (auto *E : C->privates()) {
3038 TRY_TO(TraverseStmt(E));
3040 for (auto *E : C->lhs_exprs()) {
3041 TRY_TO(TraverseStmt(E));
3043 for (auto *E : C->rhs_exprs()) {
3044 TRY_TO(TraverseStmt(E));
3046 for (auto *E : C->reduction_ops()) {
3047 TRY_TO(TraverseStmt(E));
3052 template <typename Derived>
3053 bool RecursiveASTVisitor<Derived>::VisitOMPTaskReductionClause(
3054 OMPTaskReductionClause *C) {
3055 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3056 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3057 TRY_TO(VisitOMPClauseList(C));
3058 TRY_TO(VisitOMPClauseWithPostUpdate(C));
3059 for (auto *E : C->privates()) {
3060 TRY_TO(TraverseStmt(E));
3062 for (auto *E : C->lhs_exprs()) {
3063 TRY_TO(TraverseStmt(E));
3065 for (auto *E : C->rhs_exprs()) {
3066 TRY_TO(TraverseStmt(E));
3068 for (auto *E : C->reduction_ops()) {
3069 TRY_TO(TraverseStmt(E));
3074 template <typename Derived>
3075 bool RecursiveASTVisitor<Derived>::VisitOMPInReductionClause(
3076 OMPInReductionClause *C) {
3077 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3078 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3079 TRY_TO(VisitOMPClauseList(C));
3080 TRY_TO(VisitOMPClauseWithPostUpdate(C));
3081 for (auto *E : C->privates()) {
3082 TRY_TO(TraverseStmt(E));
3084 for (auto *E : C->lhs_exprs()) {
3085 TRY_TO(TraverseStmt(E));
3087 for (auto *E : C->rhs_exprs()) {
3088 TRY_TO(TraverseStmt(E));
3090 for (auto *E : C->reduction_ops()) {
3091 TRY_TO(TraverseStmt(E));
3093 for (auto *E : C->taskgroup_descriptors())
3094 TRY_TO(TraverseStmt(E));
3098 template <typename Derived>
3099 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
3100 TRY_TO(VisitOMPClauseList(C));
3104 template <typename Derived>
3105 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
3106 TRY_TO(VisitOMPClauseList(C));
3110 template <typename Derived>
3111 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
3112 TRY_TO(VisitOMPClauseWithPreInit(C));
3113 TRY_TO(TraverseStmt(C->getDevice()));
3117 template <typename Derived>
3118 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
3119 TRY_TO(VisitOMPClauseList(C));
3123 template <typename Derived>
3124 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
3125 OMPNumTeamsClause *C) {
3126 TRY_TO(VisitOMPClauseWithPreInit(C));
3127 TRY_TO(TraverseStmt(C->getNumTeams()));
3131 template <typename Derived>
3132 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
3133 OMPThreadLimitClause *C) {
3134 TRY_TO(VisitOMPClauseWithPreInit(C));
3135 TRY_TO(TraverseStmt(C->getThreadLimit()));
3139 template <typename Derived>
3140 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
3141 OMPPriorityClause *C) {
3142 TRY_TO(TraverseStmt(C->getPriority()));
3146 template <typename Derived>
3147 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
3148 OMPGrainsizeClause *C) {
3149 TRY_TO(TraverseStmt(C->getGrainsize()));
3153 template <typename Derived>
3154 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
3155 OMPNumTasksClause *C) {
3156 TRY_TO(TraverseStmt(C->getNumTasks()));
3160 template <typename Derived>
3161 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
3162 TRY_TO(TraverseStmt(C->getHint()));
3166 template <typename Derived>
3167 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
3168 OMPDistScheduleClause *C) {
3169 TRY_TO(VisitOMPClauseWithPreInit(C));
3170 TRY_TO(TraverseStmt(C->getChunkSize()));
3174 template <typename Derived>
3176 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
3180 template <typename Derived>
3181 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
3182 TRY_TO(VisitOMPClauseList(C));
3186 template <typename Derived>
3187 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
3188 TRY_TO(VisitOMPClauseList(C));
3192 template <typename Derived>
3193 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
3194 OMPUseDevicePtrClause *C) {
3195 TRY_TO(VisitOMPClauseList(C));
3199 template <typename Derived>
3200 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
3201 OMPIsDevicePtrClause *C) {
3202 TRY_TO(VisitOMPClauseList(C));
3206 // FIXME: look at the following tricky-seeming exprs to see if we
3207 // need to recurse on anything. These are ones that have methods
3208 // returning decls or qualtypes or nestednamespecifier -- though I'm
3209 // not sure if they own them -- or just seemed very complicated, or
3210 // had lots of sub-types to explore.
3212 // VisitOverloadExpr and its children: recurse on template args? etc?
3214 // FIXME: go through all the stmts and exprs again, and see which of them
3215 // create new types, and recurse on the types (TypeLocs?) of those.
3218 // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
3219 // http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
3220 // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
3221 // Every class that has getQualifier.
3223 #undef DEF_TRAVERSE_STMT
3224 #undef TRAVERSE_STMT
3225 #undef TRAVERSE_STMT_BASE
3229 } // end namespace clang
3231 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H