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(And) OPERATOR(Xor) OPERATOR(Or) OPERATOR(LAnd) \
67 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 preordor 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 constructor initializer. This
271 /// automatically dispatches to another visitor for the initializer
272 /// expression, but not for the name of the initializer, so may
273 /// be overridden for clients that need access to the name.
275 /// \returns false if the visitation was terminated early, true otherwise.
276 bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
278 /// \brief Recursively visit a lambda capture. \c Init is the expression that
279 /// will be used to initialize the capture.
281 /// \returns false if the visitation was terminated early, true otherwise.
282 bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
285 /// \brief Recursively visit the body of a lambda expression.
287 /// This provides a hook for visitors that need more context when visiting
288 /// \c LE->getBody().
290 /// \returns false if the visitation was terminated early, true otherwise.
291 bool TraverseLambdaBody(LambdaExpr *LE, DataRecursionQueue *Queue = nullptr);
293 /// \brief Recursively visit the syntactic or semantic form of an
294 /// initialization list.
296 /// \returns false if the visitation was terminated early, true otherwise.
297 bool TraverseSynOrSemInitListExpr(InitListExpr *S,
298 DataRecursionQueue *Queue = nullptr);
300 // ---- Methods on Attrs ----
302 // \brief Visit an attribute.
303 bool VisitAttr(Attr *A) { return true; }
305 // Declare Traverse* and empty Visit* for all Attr classes.
306 #define ATTR_VISITOR_DECLS_ONLY
307 #include "clang/AST/AttrVisitor.inc"
308 #undef ATTR_VISITOR_DECLS_ONLY
310 // ---- Methods on Stmts ----
313 template<typename T, typename U>
314 struct has_same_member_pointer_type : std::false_type {};
315 template<typename T, typename U, typename R, typename... P>
316 struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
319 // Traverse the given statement. If the most-derived traverse function takes a
320 // data recursion queue, pass it on; otherwise, discard it. Note that the
321 // first branch of this conditional must compile whether or not the derived
322 // class can take a queue, so if we're taking the second arm, make the first
323 // arm call our function rather than the derived class version.
324 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE) \
325 (has_same_member_pointer_type<decltype( \
326 &RecursiveASTVisitor::Traverse##NAME), \
327 decltype(&Derived::Traverse##NAME)>::value \
328 ? static_cast<typename std::conditional< \
329 has_same_member_pointer_type< \
330 decltype(&RecursiveASTVisitor::Traverse##NAME), \
331 decltype(&Derived::Traverse##NAME)>::value, \
332 Derived &, RecursiveASTVisitor &>::type>(*this) \
333 .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE) \
334 : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
336 // Try to traverse the given statement, or enqueue it if we're performing data
337 // recursion in the middle of traversing another statement. Can only be called
338 // from within a DEF_TRAVERSE_STMT body or similar context.
339 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S) \
341 if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue)) \
346 // Declare Traverse*() for all concrete Stmt classes.
347 #define ABSTRACT_STMT(STMT)
348 #define STMT(CLASS, PARENT) \
349 bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
350 #include "clang/AST/StmtNodes.inc"
351 // The above header #undefs ABSTRACT_STMT and STMT upon exit.
353 // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
354 bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
355 bool VisitStmt(Stmt *S) { return true; }
356 #define STMT(CLASS, PARENT) \
357 bool WalkUpFrom##CLASS(CLASS *S) { \
358 TRY_TO(WalkUpFrom##PARENT(S)); \
359 TRY_TO(Visit##CLASS(S)); \
362 bool Visit##CLASS(CLASS *S) { return true; }
363 #include "clang/AST/StmtNodes.inc"
365 // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
366 // operator methods. Unary operators are not classes in themselves
367 // (they're all opcodes in UnaryOperator) but do have visitors.
368 #define OPERATOR(NAME) \
369 bool TraverseUnary##NAME(UnaryOperator *S, \
370 DataRecursionQueue *Queue = nullptr) { \
371 if (!getDerived().shouldTraversePostOrder()) \
372 TRY_TO(WalkUpFromUnary##NAME(S)); \
373 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \
376 bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
377 TRY_TO(WalkUpFromUnaryOperator(S)); \
378 TRY_TO(VisitUnary##NAME(S)); \
381 bool VisitUnary##NAME(UnaryOperator *S) { return true; }
386 // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
387 // operator methods. Binary operators are not classes in themselves
388 // (they're all opcodes in BinaryOperator) but do have visitors.
389 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \
390 bool TraverseBin##NAME(BINOP_TYPE *S, DataRecursionQueue *Queue = nullptr) { \
391 if (!getDerived().shouldTraversePostOrder()) \
392 TRY_TO(WalkUpFromBin##NAME(S)); \
393 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS()); \
394 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS()); \
397 bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
398 TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \
399 TRY_TO(VisitBin##NAME(S)); \
402 bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
404 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
408 // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
409 // assignment methods. Compound assignment operators are not
410 // classes in themselves (they're all opcodes in
411 // CompoundAssignOperator) but do have visitors.
412 #define OPERATOR(NAME) \
413 GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
417 #undef GENERAL_BINOP_FALLBACK
419 // ---- Methods on Types ----
420 // FIXME: revamp to take TypeLoc's rather than Types.
422 // Declare Traverse*() for all concrete Type classes.
423 #define ABSTRACT_TYPE(CLASS, BASE)
424 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
425 #include "clang/AST/TypeNodes.def"
426 // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
428 // Define WalkUpFrom*() and empty Visit*() for all Type classes.
429 bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
430 bool VisitType(Type *T) { return true; }
431 #define TYPE(CLASS, BASE) \
432 bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \
433 TRY_TO(WalkUpFrom##BASE(T)); \
434 TRY_TO(Visit##CLASS##Type(T)); \
437 bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
438 #include "clang/AST/TypeNodes.def"
440 // ---- Methods on TypeLocs ----
441 // FIXME: this currently just calls the matching Type methods
443 // Declare Traverse*() for all concrete TypeLoc classes.
444 #define ABSTRACT_TYPELOC(CLASS, BASE)
445 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
446 #include "clang/AST/TypeLocNodes.def"
447 // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
449 // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
450 bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
451 bool VisitTypeLoc(TypeLoc TL) { return true; }
453 // QualifiedTypeLoc and UnqualTypeLoc are not declared in
454 // TypeNodes.def and thus need to be handled specially.
455 bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
456 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
458 bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
459 bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
460 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
462 bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
464 // Note that BASE includes trailing 'Type' which CLASS doesn't.
465 #define TYPE(CLASS, BASE) \
466 bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
467 TRY_TO(WalkUpFrom##BASE##Loc(TL)); \
468 TRY_TO(Visit##CLASS##TypeLoc(TL)); \
471 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
472 #include "clang/AST/TypeNodes.def"
474 // ---- Methods on Decls ----
476 // Declare Traverse*() for all concrete Decl classes.
477 #define ABSTRACT_DECL(DECL)
478 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
479 #include "clang/AST/DeclNodes.inc"
480 // The above header #undefs ABSTRACT_DECL and DECL upon exit.
482 // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
483 bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
484 bool VisitDecl(Decl *D) { return true; }
485 #define DECL(CLASS, BASE) \
486 bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \
487 TRY_TO(WalkUpFrom##BASE(D)); \
488 TRY_TO(Visit##CLASS##Decl(D)); \
491 bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
492 #include "clang/AST/DeclNodes.inc"
495 // These are helper methods used by more than one Traverse* method.
496 bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
498 // Traverses template parameter lists of either a DeclaratorDecl or TagDecl.
499 template <typename T>
500 bool TraverseDeclTemplateParameterLists(T *D);
502 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND) \
503 bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
504 DEF_TRAVERSE_TMPL_INST(Class)
505 DEF_TRAVERSE_TMPL_INST(Var)
506 DEF_TRAVERSE_TMPL_INST(Function)
507 #undef DEF_TRAVERSE_TMPL_INST
508 bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
510 bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
511 bool TraverseRecordHelper(RecordDecl *D);
512 bool TraverseCXXRecordHelper(CXXRecordDecl *D);
513 bool TraverseDeclaratorHelper(DeclaratorDecl *D);
514 bool TraverseDeclContextHelper(DeclContext *DC);
515 bool TraverseFunctionHelper(FunctionDecl *D);
516 bool TraverseVarHelper(VarDecl *D);
517 bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
518 bool TraverseOMPLoopDirective(OMPLoopDirective *S);
519 bool TraverseOMPClause(OMPClause *C);
520 #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C);
521 #include "clang/Basic/OpenMPKinds.def"
522 /// \brief Process clauses with list of variables.
523 template <typename T> bool VisitOMPClauseList(T *Node);
524 /// Process clauses with pre-initis.
525 bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
526 bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
528 bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
529 bool PostVisitStmt(Stmt *S);
532 template <typename Derived>
533 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
534 DataRecursionQueue *Queue) {
535 #define DISPATCH_STMT(NAME, CLASS, VAR) \
536 return TRAVERSE_STMT_BASE(NAME, CLASS, VAR, Queue);
538 // If we have a binary expr, dispatch to the subcode of the binop. A smart
539 // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
541 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
542 switch (BinOp->getOpcode()) {
543 #define OPERATOR(NAME) \
545 DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
551 #define OPERATOR(NAME) \
552 case BO_##NAME##Assign: \
553 DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
559 } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
560 switch (UnOp->getOpcode()) {
561 #define OPERATOR(NAME) \
563 DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
571 // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
572 switch (S->getStmtClass()) {
573 case Stmt::NoStmtClass:
575 #define ABSTRACT_STMT(STMT)
576 #define STMT(CLASS, PARENT) \
577 case Stmt::CLASS##Class: \
578 DISPATCH_STMT(CLASS, CLASS, S);
579 #include "clang/AST/StmtNodes.inc"
587 template <typename Derived>
588 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
589 switch (S->getStmtClass()) {
590 case Stmt::NoStmtClass:
592 #define ABSTRACT_STMT(STMT)
593 #define STMT(CLASS, PARENT) \
594 case Stmt::CLASS##Class: \
595 TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S))); break;
596 #define INITLISTEXPR(CLASS, PARENT) \
597 case Stmt::CLASS##Class: \
599 auto ILE = static_cast<CLASS *>(S); \
600 if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE) \
601 TRY_TO(WalkUpFrom##CLASS(Syn)); \
602 if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \
603 TRY_TO(WalkUpFrom##CLASS(Sem)); \
606 #include "clang/AST/StmtNodes.inc"
614 template <typename Derived>
615 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S,
616 DataRecursionQueue *Queue) {
621 Queue->push_back({S, false});
625 SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
626 LocalQueue.push_back({S, false});
628 while (!LocalQueue.empty()) {
629 auto &CurrSAndVisited = LocalQueue.back();
630 Stmt *CurrS = CurrSAndVisited.getPointer();
631 bool Visited = CurrSAndVisited.getInt();
633 LocalQueue.pop_back();
634 TRY_TO(dataTraverseStmtPost(CurrS));
635 if (getDerived().shouldTraversePostOrder()) {
636 TRY_TO(PostVisitStmt(CurrS));
641 if (getDerived().dataTraverseStmtPre(CurrS)) {
642 CurrSAndVisited.setInt(true);
643 size_t N = LocalQueue.size();
644 TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
645 // Process new children in the order they were added.
646 std::reverse(LocalQueue.begin() + N, LocalQueue.end());
648 LocalQueue.pop_back();
655 #define DISPATCH(NAME, CLASS, VAR) \
656 return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))
658 template <typename Derived>
659 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
663 switch (T->getTypeClass()) {
664 #define ABSTRACT_TYPE(CLASS, BASE)
665 #define TYPE(CLASS, BASE) \
667 DISPATCH(CLASS##Type, CLASS##Type, const_cast<Type *>(T.getTypePtr()));
668 #include "clang/AST/TypeNodes.def"
674 template <typename Derived>
675 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
679 switch (TL.getTypeLocClass()) {
680 #define ABSTRACT_TYPELOC(CLASS, BASE)
681 #define TYPELOC(CLASS, BASE) \
682 case TypeLoc::CLASS: \
683 return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
684 #include "clang/AST/TypeLocNodes.def"
690 // Define the Traverse*Attr(Attr* A) methods
691 #define VISITORCLASS RecursiveASTVisitor
692 #include "clang/AST/AttrVisitor.inc"
695 template <typename Derived>
696 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
700 // As a syntax visitor, by default we want to ignore declarations for
701 // implicit declarations (ones not typed explicitly by the user).
702 if (!getDerived().shouldVisitImplicitCode() && D->isImplicit())
705 switch (D->getKind()) {
706 #define ABSTRACT_DECL(DECL)
707 #define DECL(CLASS, BASE) \
709 if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D))) \
712 #include "clang/AST/DeclNodes.inc"
715 // Visit any attributes attached to this declaration.
716 for (auto *I : D->attrs()) {
717 if (!getDerived().TraverseAttr(I))
725 template <typename Derived>
726 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
727 NestedNameSpecifier *NNS) {
731 if (NNS->getPrefix())
732 TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
734 switch (NNS->getKind()) {
735 case NestedNameSpecifier::Identifier:
736 case NestedNameSpecifier::Namespace:
737 case NestedNameSpecifier::NamespaceAlias:
738 case NestedNameSpecifier::Global:
739 case NestedNameSpecifier::Super:
742 case NestedNameSpecifier::TypeSpec:
743 case NestedNameSpecifier::TypeSpecWithTemplate:
744 TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
750 template <typename Derived>
751 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
752 NestedNameSpecifierLoc NNS) {
756 if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
757 TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
759 switch (NNS.getNestedNameSpecifier()->getKind()) {
760 case NestedNameSpecifier::Identifier:
761 case NestedNameSpecifier::Namespace:
762 case NestedNameSpecifier::NamespaceAlias:
763 case NestedNameSpecifier::Global:
764 case NestedNameSpecifier::Super:
767 case NestedNameSpecifier::TypeSpec:
768 case NestedNameSpecifier::TypeSpecWithTemplate:
769 TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
776 template <typename Derived>
777 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
778 DeclarationNameInfo NameInfo) {
779 switch (NameInfo.getName().getNameKind()) {
780 case DeclarationName::CXXConstructorName:
781 case DeclarationName::CXXDestructorName:
782 case DeclarationName::CXXConversionFunctionName:
783 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
784 TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
787 case DeclarationName::CXXDeductionGuideName:
788 TRY_TO(TraverseTemplateName(
789 TemplateName(NameInfo.getName().getCXXDeductionGuideTemplate())));
792 case DeclarationName::Identifier:
793 case DeclarationName::ObjCZeroArgSelector:
794 case DeclarationName::ObjCOneArgSelector:
795 case DeclarationName::ObjCMultiArgSelector:
796 case DeclarationName::CXXOperatorName:
797 case DeclarationName::CXXLiteralOperatorName:
798 case DeclarationName::CXXUsingDirective:
805 template <typename Derived>
806 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
807 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
808 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
809 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
810 TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
815 template <typename Derived>
816 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
817 const TemplateArgument &Arg) {
818 switch (Arg.getKind()) {
819 case TemplateArgument::Null:
820 case TemplateArgument::Declaration:
821 case TemplateArgument::Integral:
822 case TemplateArgument::NullPtr:
825 case TemplateArgument::Type:
826 return getDerived().TraverseType(Arg.getAsType());
828 case TemplateArgument::Template:
829 case TemplateArgument::TemplateExpansion:
830 return getDerived().TraverseTemplateName(
831 Arg.getAsTemplateOrTemplatePattern());
833 case TemplateArgument::Expression:
834 return getDerived().TraverseStmt(Arg.getAsExpr());
836 case TemplateArgument::Pack:
837 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
844 // FIXME: no template name location?
845 // FIXME: no source locations for a template argument pack?
846 template <typename Derived>
847 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
848 const TemplateArgumentLoc &ArgLoc) {
849 const TemplateArgument &Arg = ArgLoc.getArgument();
851 switch (Arg.getKind()) {
852 case TemplateArgument::Null:
853 case TemplateArgument::Declaration:
854 case TemplateArgument::Integral:
855 case TemplateArgument::NullPtr:
858 case TemplateArgument::Type: {
859 // FIXME: how can TSI ever be NULL?
860 if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
861 return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
863 return getDerived().TraverseType(Arg.getAsType());
866 case TemplateArgument::Template:
867 case TemplateArgument::TemplateExpansion:
868 if (ArgLoc.getTemplateQualifierLoc())
869 TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
870 ArgLoc.getTemplateQualifierLoc()));
871 return getDerived().TraverseTemplateName(
872 Arg.getAsTemplateOrTemplatePattern());
874 case TemplateArgument::Expression:
875 return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
877 case TemplateArgument::Pack:
878 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
885 template <typename Derived>
886 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
887 const TemplateArgument *Args, unsigned NumArgs) {
888 for (unsigned I = 0; I != NumArgs; ++I) {
889 TRY_TO(TraverseTemplateArgument(Args[I]));
895 template <typename Derived>
896 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
897 CXXCtorInitializer *Init) {
898 if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
899 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
901 if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
902 TRY_TO(TraverseStmt(Init->getInit()));
907 template <typename Derived>
909 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
910 const LambdaCapture *C,
912 if (LE->isInitCapture(C))
913 TRY_TO(TraverseDecl(C->getCapturedVar()));
915 TRY_TO(TraverseStmt(Init));
919 template <typename Derived>
920 bool RecursiveASTVisitor<Derived>::TraverseLambdaBody(
921 LambdaExpr *LE, DataRecursionQueue *Queue) {
922 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(LE->getBody());
926 // ----------------- Type traversal -----------------
928 // This macro makes available a variable T, the passed-in type.
929 #define DEF_TRAVERSE_TYPE(TYPE, CODE) \
930 template <typename Derived> \
931 bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) { \
932 if (!getDerived().shouldTraversePostOrder()) \
933 TRY_TO(WalkUpFrom##TYPE(T)); \
935 if (getDerived().shouldTraversePostOrder()) \
936 TRY_TO(WalkUpFrom##TYPE(T)); \
940 DEF_TRAVERSE_TYPE(BuiltinType, {})
942 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
944 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
946 DEF_TRAVERSE_TYPE(BlockPointerType,
947 { TRY_TO(TraverseType(T->getPointeeType())); })
949 DEF_TRAVERSE_TYPE(LValueReferenceType,
950 { TRY_TO(TraverseType(T->getPointeeType())); })
952 DEF_TRAVERSE_TYPE(RValueReferenceType,
953 { TRY_TO(TraverseType(T->getPointeeType())); })
955 DEF_TRAVERSE_TYPE(MemberPointerType, {
956 TRY_TO(TraverseType(QualType(T->getClass(), 0)));
957 TRY_TO(TraverseType(T->getPointeeType()));
960 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
962 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
964 DEF_TRAVERSE_TYPE(ConstantArrayType,
965 { TRY_TO(TraverseType(T->getElementType())); })
967 DEF_TRAVERSE_TYPE(IncompleteArrayType,
968 { TRY_TO(TraverseType(T->getElementType())); })
970 DEF_TRAVERSE_TYPE(VariableArrayType, {
971 TRY_TO(TraverseType(T->getElementType()));
972 TRY_TO(TraverseStmt(T->getSizeExpr()));
975 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
976 TRY_TO(TraverseType(T->getElementType()));
977 if (T->getSizeExpr())
978 TRY_TO(TraverseStmt(T->getSizeExpr()));
981 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
982 if (T->getSizeExpr())
983 TRY_TO(TraverseStmt(T->getSizeExpr()));
984 TRY_TO(TraverseType(T->getElementType()));
987 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
989 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
991 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
992 { TRY_TO(TraverseType(T->getReturnType())); })
994 DEF_TRAVERSE_TYPE(FunctionProtoType, {
995 TRY_TO(TraverseType(T->getReturnType()));
997 for (const auto &A : T->param_types()) {
998 TRY_TO(TraverseType(A));
1001 for (const auto &E : T->exceptions()) {
1002 TRY_TO(TraverseType(E));
1005 if (Expr *NE = T->getNoexceptExpr())
1006 TRY_TO(TraverseStmt(NE));
1009 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
1010 DEF_TRAVERSE_TYPE(TypedefType, {})
1012 DEF_TRAVERSE_TYPE(TypeOfExprType,
1013 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1015 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
1017 DEF_TRAVERSE_TYPE(DecltypeType,
1018 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
1020 DEF_TRAVERSE_TYPE(UnaryTransformType, {
1021 TRY_TO(TraverseType(T->getBaseType()));
1022 TRY_TO(TraverseType(T->getUnderlyingType()));
1025 DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
1026 DEF_TRAVERSE_TYPE(DeducedTemplateSpecializationType, {
1027 TRY_TO(TraverseTemplateName(T->getTemplateName()));
1028 TRY_TO(TraverseType(T->getDeducedType()));
1031 DEF_TRAVERSE_TYPE(RecordType, {})
1032 DEF_TRAVERSE_TYPE(EnumType, {})
1033 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
1034 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {
1035 TRY_TO(TraverseType(T->getReplacementType()));
1037 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {
1038 TRY_TO(TraverseTemplateArgument(T->getArgumentPack()));
1041 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
1042 TRY_TO(TraverseTemplateName(T->getTemplateName()));
1043 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1046 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
1048 DEF_TRAVERSE_TYPE(AttributedType,
1049 { TRY_TO(TraverseType(T->getModifiedType())); })
1051 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
1053 DEF_TRAVERSE_TYPE(ElaboratedType, {
1054 if (T->getQualifier()) {
1055 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1057 TRY_TO(TraverseType(T->getNamedType()));
1060 DEF_TRAVERSE_TYPE(DependentNameType,
1061 { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
1063 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
1064 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1065 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1068 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
1070 DEF_TRAVERSE_TYPE(ObjCTypeParamType, {})
1072 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
1074 DEF_TRAVERSE_TYPE(ObjCObjectType, {
1075 // We have to watch out here because an ObjCInterfaceType's base
1077 if (T->getBaseType().getTypePtr() != T)
1078 TRY_TO(TraverseType(T->getBaseType()));
1079 for (auto typeArg : T->getTypeArgsAsWritten()) {
1080 TRY_TO(TraverseType(typeArg));
1084 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
1085 { TRY_TO(TraverseType(T->getPointeeType())); })
1087 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
1089 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
1091 #undef DEF_TRAVERSE_TYPE
1093 // ----------------- TypeLoc traversal -----------------
1095 // This macro makes available a variable TL, the passed-in TypeLoc.
1096 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
1097 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
1098 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
1099 // continue to work.
1100 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \
1101 template <typename Derived> \
1102 bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
1103 if (getDerived().shouldWalkTypesOfTypeLocs()) \
1104 TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \
1105 TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
1110 template <typename Derived>
1112 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
1113 // Move this over to the 'main' typeloc tree. Note that this is a
1114 // move -- we pretend that we were really looking at the unqualified
1115 // typeloc all along -- rather than a recursion, so we don't follow
1116 // the normal CRTP plan of going through
1117 // getDerived().TraverseTypeLoc. If we did, we'd be traversing
1118 // twice for the same type (once as a QualifiedTypeLoc version of
1119 // the type, once as an UnqualifiedTypeLoc version of the type),
1120 // which in effect means we'd call VisitTypeLoc twice with the
1121 // 'same' type. This solves that problem, at the cost of never
1122 // seeing the qualified version of the type (unless the client
1123 // subclasses TraverseQualifiedTypeLoc themselves). It's not a
1124 // perfect solution. A perfect solution probably requires making
1125 // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
1126 // wrapper around Type* -- rather than being its own class in the
1128 return TraverseTypeLoc(TL.getUnqualifiedLoc());
1131 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
1133 // FIXME: ComplexTypeLoc is unfinished
1134 DEF_TRAVERSE_TYPELOC(ComplexType, {
1135 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1138 DEF_TRAVERSE_TYPELOC(PointerType,
1139 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1141 DEF_TRAVERSE_TYPELOC(BlockPointerType,
1142 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1144 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1145 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1147 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1148 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1150 // FIXME: location of base class?
1151 // We traverse this in the type case as well, but how is it not reached through
1152 // the pointee type?
1153 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1154 TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1155 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1158 DEF_TRAVERSE_TYPELOC(AdjustedType,
1159 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1161 DEF_TRAVERSE_TYPELOC(DecayedType,
1162 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1164 template <typename Derived>
1165 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
1166 // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1167 TRY_TO(TraverseStmt(TL.getSizeExpr()));
1171 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1172 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1173 return TraverseArrayTypeLocHelper(TL);
1176 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1177 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1178 return TraverseArrayTypeLocHelper(TL);
1181 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1182 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1183 return TraverseArrayTypeLocHelper(TL);
1186 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1187 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1188 return TraverseArrayTypeLocHelper(TL);
1191 // FIXME: order? why not size expr first?
1192 // FIXME: base VectorTypeLoc is unfinished
1193 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1194 if (TL.getTypePtr()->getSizeExpr())
1195 TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1196 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1199 // FIXME: VectorTypeLoc is unfinished
1200 DEF_TRAVERSE_TYPELOC(VectorType, {
1201 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1204 // FIXME: size and attributes
1205 // FIXME: base VectorTypeLoc is unfinished
1206 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1207 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1210 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1211 { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
1213 // FIXME: location of exception specifications (attributes?)
1214 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1215 TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
1217 const FunctionProtoType *T = TL.getTypePtr();
1219 for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1220 if (TL.getParam(I)) {
1221 TRY_TO(TraverseDecl(TL.getParam(I)));
1222 } else if (I < T->getNumParams()) {
1223 TRY_TO(TraverseType(T->getParamType(I)));
1227 for (const auto &E : T->exceptions()) {
1228 TRY_TO(TraverseType(E));
1231 if (Expr *NE = T->getNoexceptExpr())
1232 TRY_TO(TraverseStmt(NE));
1235 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1236 DEF_TRAVERSE_TYPELOC(TypedefType, {})
1238 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1239 { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
1241 DEF_TRAVERSE_TYPELOC(TypeOfType, {
1242 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1245 // FIXME: location of underlying expr
1246 DEF_TRAVERSE_TYPELOC(DecltypeType, {
1247 TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1250 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1251 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1254 DEF_TRAVERSE_TYPELOC(AutoType, {
1255 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1258 DEF_TRAVERSE_TYPELOC(DeducedTemplateSpecializationType, {
1259 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1260 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1263 DEF_TRAVERSE_TYPELOC(RecordType, {})
1264 DEF_TRAVERSE_TYPELOC(EnumType, {})
1265 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1266 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {
1267 TRY_TO(TraverseType(TL.getTypePtr()->getReplacementType()));
1269 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {
1270 TRY_TO(TraverseTemplateArgument(TL.getTypePtr()->getArgumentPack()));
1273 // FIXME: use the loc for the template name?
1274 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1275 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1276 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1277 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1281 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
1283 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1285 DEF_TRAVERSE_TYPELOC(AttributedType,
1286 { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
1288 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1289 if (TL.getQualifierLoc()) {
1290 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1292 TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1295 DEF_TRAVERSE_TYPELOC(DependentNameType, {
1296 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1299 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1300 if (TL.getQualifierLoc()) {
1301 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1304 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1305 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1309 DEF_TRAVERSE_TYPELOC(PackExpansionType,
1310 { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
1312 DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, {})
1314 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
1316 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1317 // We have to watch out here because an ObjCInterfaceType's base
1319 if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1320 TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1321 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
1322 TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
1325 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1326 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1328 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1330 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1332 #undef DEF_TRAVERSE_TYPELOC
1334 // ----------------- Decl traversal -----------------
1336 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1337 // the children that come from the DeclContext associated with it.
1338 // Therefore each Traverse* only needs to worry about children other
1341 template <typename Derived>
1342 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1346 for (auto *Child : DC->decls()) {
1347 // BlockDecls and CapturedDecls are traversed through BlockExprs and
1348 // CapturedStmts respectively.
1349 if (!isa<BlockDecl>(Child) && !isa<CapturedDecl>(Child))
1350 TRY_TO(TraverseDecl(Child));
1356 // This macro makes available a variable D, the passed-in decl.
1357 #define DEF_TRAVERSE_DECL(DECL, CODE) \
1358 template <typename Derived> \
1359 bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) { \
1360 bool ShouldVisitChildren = true; \
1361 bool ReturnValue = true; \
1362 if (!getDerived().shouldTraversePostOrder()) \
1363 TRY_TO(WalkUpFrom##DECL(D)); \
1365 if (ReturnValue && ShouldVisitChildren) \
1366 TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \
1367 if (ReturnValue && getDerived().shouldTraversePostOrder()) \
1368 TRY_TO(WalkUpFrom##DECL(D)); \
1369 return ReturnValue; \
1372 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
1374 DEF_TRAVERSE_DECL(BlockDecl, {
1375 if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1376 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1377 TRY_TO(TraverseStmt(D->getBody()));
1378 for (const auto &I : D->captures()) {
1379 if (I.hasCopyExpr()) {
1380 TRY_TO(TraverseStmt(I.getCopyExpr()));
1383 ShouldVisitChildren = false;
1386 DEF_TRAVERSE_DECL(CapturedDecl, {
1387 TRY_TO(TraverseStmt(D->getBody()));
1388 ShouldVisitChildren = false;
1391 DEF_TRAVERSE_DECL(EmptyDecl, {})
1393 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1394 { TRY_TO(TraverseStmt(D->getAsmString())); })
1396 DEF_TRAVERSE_DECL(ImportDecl, {})
1398 DEF_TRAVERSE_DECL(FriendDecl, {
1399 // Friend is either decl or a type.
1400 if (D->getFriendType())
1401 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1403 TRY_TO(TraverseDecl(D->getFriendDecl()));
1406 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1407 if (D->getFriendType())
1408 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1410 TRY_TO(TraverseDecl(D->getFriendDecl()));
1411 for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1412 TemplateParameterList *TPL = D->getTemplateParameterList(I);
1413 for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1414 ITPL != ETPL; ++ITPL) {
1415 TRY_TO(TraverseDecl(*ITPL));
1420 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
1421 TRY_TO(TraverseDecl(D->getSpecialization()));
1423 if (D->hasExplicitTemplateArgs()) {
1424 const TemplateArgumentListInfo &args = D->templateArgs();
1425 TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(),
1430 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1432 DEF_TRAVERSE_DECL(ExportDecl, {})
1434 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1437 DEF_TRAVERSE_DECL(StaticAssertDecl, {
1438 TRY_TO(TraverseStmt(D->getAssertExpr()));
1439 TRY_TO(TraverseStmt(D->getMessage()));
1443 TranslationUnitDecl,
1444 {// Code in an unnamed namespace shows up automatically in
1445 // decls_begin()/decls_end(). Thus we don't need to recurse on
1446 // D->getAnonymousNamespace().
1449 DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
1451 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
1453 DEF_TRAVERSE_DECL(ExternCContextDecl, {})
1455 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1456 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1458 // We shouldn't traverse an aliased namespace, since it will be
1459 // defined (and, therefore, traversed) somewhere else.
1460 ShouldVisitChildren = false;
1463 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1468 {// Code in an unnamed namespace shows up automatically in
1469 // decls_begin()/decls_end(). Thus we don't need to recurse on
1470 // D->getAnonymousNamespace().
1473 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1476 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
1477 if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
1478 for (auto typeParam : *typeParamList) {
1479 TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1484 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1487 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1490 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
1491 if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
1492 for (auto typeParam : *typeParamList) {
1493 TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1497 if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
1498 TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
1502 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
1505 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1506 if (D->getReturnTypeSourceInfo()) {
1507 TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1509 for (ParmVarDecl *Parameter : D->parameters()) {
1510 TRY_TO(TraverseDecl(Parameter));
1512 if (D->isThisDeclarationADefinition()) {
1513 TRY_TO(TraverseStmt(D->getBody()));
1515 ShouldVisitChildren = false;
1518 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
1519 if (D->hasExplicitBound()) {
1520 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1521 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1522 // declaring the type alias, not something that was written in the
1527 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1528 if (D->getTypeSourceInfo())
1529 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1531 TRY_TO(TraverseType(D->getType()));
1532 ShouldVisitChildren = false;
1535 DEF_TRAVERSE_DECL(UsingDecl, {
1536 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1537 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1540 DEF_TRAVERSE_DECL(UsingPackDecl, {})
1542 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1543 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1546 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
1548 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
1550 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
1551 for (auto *I : D->varlists()) {
1552 TRY_TO(TraverseStmt(I));
1556 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
1557 TRY_TO(TraverseStmt(D->getCombiner()));
1558 if (auto *Initializer = D->getInitializer())
1559 TRY_TO(TraverseStmt(Initializer));
1560 TRY_TO(TraverseType(D->getType()));
1564 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
1566 // A helper method for TemplateDecl's children.
1567 template <typename Derived>
1568 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1569 TemplateParameterList *TPL) {
1571 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1573 TRY_TO(TraverseDecl(*I));
1579 template <typename Derived>
1580 template <typename T>
1581 bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) {
1582 for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) {
1583 TemplateParameterList *TPL = D->getTemplateParameterList(i);
1584 TraverseTemplateParameterListHelper(TPL);
1589 template <typename Derived>
1590 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1591 ClassTemplateDecl *D) {
1592 for (auto *SD : D->specializations()) {
1593 for (auto *RD : SD->redecls()) {
1594 // We don't want to visit injected-class-names in this traversal.
1595 if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
1599 cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1600 // Visit the implicit instantiations with the requested pattern.
1601 case TSK_Undeclared:
1602 case TSK_ImplicitInstantiation:
1603 TRY_TO(TraverseDecl(RD));
1606 // We don't need to do anything on an explicit instantiation
1607 // or explicit specialization because there will be an explicit
1608 // node for it elsewhere.
1609 case TSK_ExplicitInstantiationDeclaration:
1610 case TSK_ExplicitInstantiationDefinition:
1611 case TSK_ExplicitSpecialization:
1620 template <typename Derived>
1621 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1622 VarTemplateDecl *D) {
1623 for (auto *SD : D->specializations()) {
1624 for (auto *RD : SD->redecls()) {
1626 cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1627 case TSK_Undeclared:
1628 case TSK_ImplicitInstantiation:
1629 TRY_TO(TraverseDecl(RD));
1632 case TSK_ExplicitInstantiationDeclaration:
1633 case TSK_ExplicitInstantiationDefinition:
1634 case TSK_ExplicitSpecialization:
1643 // A helper method for traversing the instantiations of a
1644 // function while skipping its specializations.
1645 template <typename Derived>
1646 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1647 FunctionTemplateDecl *D) {
1648 for (auto *FD : D->specializations()) {
1649 for (auto *RD : FD->redecls()) {
1650 switch (RD->getTemplateSpecializationKind()) {
1651 case TSK_Undeclared:
1652 case TSK_ImplicitInstantiation:
1653 // We don't know what kind of FunctionDecl this is.
1654 TRY_TO(TraverseDecl(RD));
1657 // FIXME: For now traverse explicit instantiations here. Change that
1658 // once they are represented as dedicated nodes in the AST.
1659 case TSK_ExplicitInstantiationDeclaration:
1660 case TSK_ExplicitInstantiationDefinition:
1661 TRY_TO(TraverseDecl(RD));
1664 case TSK_ExplicitSpecialization:
1673 // This macro unifies the traversal of class, variable and function
1674 // template declarations.
1675 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND) \
1676 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, { \
1677 TRY_TO(TraverseDecl(D->getTemplatedDecl())); \
1678 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \
1680 /* By default, we do not traverse the instantiations of \
1681 class templates since they do not appear in the user code. The \
1682 following code optionally traverses them. \
1684 We only traverse the class instantiations when we see the canonical \
1685 declaration of the template, to ensure we only visit them once. */ \
1686 if (getDerived().shouldVisitTemplateInstantiations() && \
1687 D == D->getCanonicalDecl()) \
1688 TRY_TO(TraverseTemplateInstantiations(D)); \
1690 /* Note that getInstantiatedFromMemberTemplate() is just a link \
1691 from a template instantiation back to the template from which \
1692 it was instantiated, and thus should not be traversed. */ \
1695 DEF_TRAVERSE_TMPL_DECL(Class)
1696 DEF_TRAVERSE_TMPL_DECL(Var)
1697 DEF_TRAVERSE_TMPL_DECL(Function)
1699 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1700 // D is the "T" in something like
1701 // template <template <typename> class T> class container { };
1702 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1703 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
1704 TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1706 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1709 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
1710 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1713 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1714 // D is the "T" in something like "template<typename T> class vector;"
1715 if (D->getTypeForDecl())
1716 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1717 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1718 TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1721 DEF_TRAVERSE_DECL(TypedefDecl, {
1722 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1723 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1724 // declaring the typedef, not something that was written in the
1728 DEF_TRAVERSE_DECL(TypeAliasDecl, {
1729 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1730 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1731 // declaring the type alias, not something that was written in the
1735 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
1736 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1737 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1740 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1741 // A dependent using declaration which was marked with 'typename'.
1742 // template<class T> class A : public B<T> { using typename B<T>::foo; };
1743 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1744 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1745 // declaring the type, not something that was written in the
1749 DEF_TRAVERSE_DECL(EnumDecl, {
1750 TRY_TO(TraverseDeclTemplateParameterLists(D));
1752 if (D->getTypeForDecl())
1753 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1755 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1756 // The enumerators are already traversed by
1757 // decls_begin()/decls_end().
1760 // Helper methods for RecordDecl and its children.
1761 template <typename Derived>
1762 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
1763 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1764 // declaring the type, not something that was written in the source.
1766 TRY_TO(TraverseDeclTemplateParameterLists(D));
1767 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1771 template <typename Derived>
1772 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
1773 if (!TraverseRecordHelper(D))
1775 if (D->isCompleteDefinition()) {
1776 for (const auto &I : D->bases()) {
1777 TRY_TO(TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc()));
1779 // We don't traverse the friends or the conversions, as they are
1780 // already in decls_begin()/decls_end().
1785 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
1787 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
1789 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND) \
1790 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, { \
1791 /* For implicit instantiations ("set<int> x;"), we don't want to \
1792 recurse at all, since the instatiated template isn't written in \
1793 the source code anywhere. (Note the instatiated *type* -- \
1794 set<int> -- is written, and will still get a callback of \
1795 TemplateSpecializationType). For explicit instantiations \
1796 ("template set<int>;"), we do need a callback, since this \
1797 is the only callback that's made for this instantiation. \
1798 We use getTypeAsWritten() to distinguish. */ \
1799 if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \
1800 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \
1802 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \
1803 if (!getDerived().shouldVisitTemplateInstantiations() && \
1804 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) \
1805 /* Returning from here skips traversing the \
1806 declaration context of the *TemplateSpecializationDecl \
1807 (embedded in the DEF_TRAVERSE_DECL() macro) \
1808 which contains the instantiated members of the template. */ \
1812 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)
1813 DEF_TRAVERSE_TMPL_SPEC_DECL(Var)
1815 template <typename Derived>
1816 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1817 const TemplateArgumentLoc *TAL, unsigned Count) {
1818 for (unsigned I = 0; I < Count; ++I) {
1819 TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1824 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND) \
1825 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, { \
1826 /* The partial specialization. */ \
1827 if (TemplateParameterList *TPL = D->getTemplateParameters()) { \
1828 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); \
1830 TRY_TO(TraverseDecl(*I)); \
1833 /* The args that remains unspecialized. */ \
1834 TRY_TO(TraverseTemplateArgumentLocsHelper( \
1835 D->getTemplateArgsAsWritten()->getTemplateArgs(), \
1836 D->getTemplateArgsAsWritten()->NumTemplateArgs)); \
1838 /* Don't need the *TemplatePartialSpecializationHelper, even \
1839 though that's our parent class -- we already visit all the \
1840 template args here. */ \
1841 TRY_TO(Traverse##DECLKIND##Helper(D)); \
1843 /* Instantiations will have been visited with the primary template. */ \
1846 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
1847 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
1849 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
1851 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1852 // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1853 // template <class T> Class A : public Base<T> { using Base<T>::foo; };
1854 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1855 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1858 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1860 template <typename Derived>
1861 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1862 TRY_TO(TraverseDeclTemplateParameterLists(D));
1863 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1864 if (D->getTypeSourceInfo())
1865 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1867 TRY_TO(TraverseType(D->getType()));
1871 DEF_TRAVERSE_DECL(DecompositionDecl, {
1872 TRY_TO(TraverseVarHelper(D));
1873 for (auto *Binding : D->bindings()) {
1874 TRY_TO(TraverseDecl(Binding));
1878 DEF_TRAVERSE_DECL(BindingDecl, {
1879 if (getDerived().shouldVisitImplicitCode())
1880 TRY_TO(TraverseStmt(D->getBinding()));
1883 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
1885 DEF_TRAVERSE_DECL(FieldDecl, {
1886 TRY_TO(TraverseDeclaratorHelper(D));
1887 if (D->isBitField())
1888 TRY_TO(TraverseStmt(D->getBitWidth()));
1889 else if (D->hasInClassInitializer())
1890 TRY_TO(TraverseStmt(D->getInClassInitializer()));
1893 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1894 TRY_TO(TraverseDeclaratorHelper(D));
1895 if (D->isBitField())
1896 TRY_TO(TraverseStmt(D->getBitWidth()));
1897 // FIXME: implement the rest.
1900 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1901 TRY_TO(TraverseDeclaratorHelper(D));
1902 if (D->isBitField())
1903 TRY_TO(TraverseStmt(D->getBitWidth()));
1904 // FIXME: implement the rest.
1907 template <typename Derived>
1908 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1909 TRY_TO(TraverseDeclTemplateParameterLists(D));
1910 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1911 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1913 // If we're an explicit template specialization, iterate over the
1914 // template args that were explicitly specified. If we were doing
1915 // this in typing order, we'd do it between the return type and
1916 // the function args, but both are handled by the FunctionTypeLoc
1917 // above, so we have to choose one side. I've decided to do before.
1918 if (const FunctionTemplateSpecializationInfo *FTSI =
1919 D->getTemplateSpecializationInfo()) {
1920 if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1921 FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1922 // A specialization might not have explicit template arguments if it has
1923 // a templated return type and concrete arguments.
1924 if (const ASTTemplateArgumentListInfo *TALI =
1925 FTSI->TemplateArgumentsAsWritten) {
1926 TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1927 TALI->NumTemplateArgs));
1932 // Visit the function type itself, which can be either
1933 // FunctionNoProtoType or FunctionProtoType, or a typedef. This
1934 // also covers the return type and the function parameters,
1935 // including exception specifications.
1936 if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
1937 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1938 } else if (getDerived().shouldVisitImplicitCode()) {
1939 // Visit parameter variable declarations of the implicit function
1940 // if the traverser is visiting implicit code. Parameter variable
1941 // declarations do not have valid TypeSourceInfo, so to visit them
1942 // we need to traverse the declarations explicitly.
1943 for (ParmVarDecl *Parameter : D->parameters()) {
1944 TRY_TO(TraverseDecl(Parameter));
1948 if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1949 // Constructor initializers.
1950 for (auto *I : Ctor->inits()) {
1951 TRY_TO(TraverseConstructorInitializer(I));
1955 if (D->isThisDeclarationADefinition()) {
1956 TRY_TO(TraverseStmt(D->getBody())); // Function body.
1961 DEF_TRAVERSE_DECL(FunctionDecl, {
1962 // We skip decls_begin/decls_end, which are already covered by
1963 // TraverseFunctionHelper().
1964 ShouldVisitChildren = false;
1965 ReturnValue = TraverseFunctionHelper(D);
1968 DEF_TRAVERSE_DECL(CXXDeductionGuideDecl, {
1969 // We skip decls_begin/decls_end, which are already covered by
1970 // TraverseFunctionHelper().
1971 ShouldVisitChildren = false;
1972 ReturnValue = TraverseFunctionHelper(D);
1975 DEF_TRAVERSE_DECL(CXXMethodDecl, {
1976 // We skip decls_begin/decls_end, which are already covered by
1977 // TraverseFunctionHelper().
1978 ShouldVisitChildren = false;
1979 ReturnValue = TraverseFunctionHelper(D);
1982 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
1983 // We skip decls_begin/decls_end, which are already covered by
1984 // TraverseFunctionHelper().
1985 ShouldVisitChildren = false;
1986 ReturnValue = TraverseFunctionHelper(D);
1989 // CXXConversionDecl is the declaration of a type conversion operator.
1990 // It's not a cast expression.
1991 DEF_TRAVERSE_DECL(CXXConversionDecl, {
1992 // We skip decls_begin/decls_end, which are already covered by
1993 // TraverseFunctionHelper().
1994 ShouldVisitChildren = false;
1995 ReturnValue = TraverseFunctionHelper(D);
1998 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
1999 // We skip decls_begin/decls_end, which are already covered by
2000 // TraverseFunctionHelper().
2001 ShouldVisitChildren = false;
2002 ReturnValue = TraverseFunctionHelper(D);
2005 template <typename Derived>
2006 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
2007 TRY_TO(TraverseDeclaratorHelper(D));
2008 // Default params are taken care of when we traverse the ParmVarDecl.
2009 if (!isa<ParmVarDecl>(D) &&
2010 (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
2011 TRY_TO(TraverseStmt(D->getInit()));
2015 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
2017 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
2019 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
2020 // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
2021 TRY_TO(TraverseDeclaratorHelper(D));
2022 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
2023 TRY_TO(TraverseStmt(D->getDefaultArgument()));
2026 DEF_TRAVERSE_DECL(ParmVarDecl, {
2027 TRY_TO(TraverseVarHelper(D));
2029 if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
2030 !D->hasUnparsedDefaultArg())
2031 TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
2033 if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
2034 !D->hasUnparsedDefaultArg())
2035 TRY_TO(TraverseStmt(D->getDefaultArg()));
2038 #undef DEF_TRAVERSE_DECL
2040 // ----------------- Stmt traversal -----------------
2042 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
2043 // over the children defined in children() (every stmt defines these,
2044 // though sometimes the range is empty). Each individual Traverse*
2045 // method only needs to worry about children other than those. To see
2046 // what children() does for a given class, see, e.g.,
2047 // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
2049 // This macro makes available a variable S, the passed-in stmt.
2050 #define DEF_TRAVERSE_STMT(STMT, CODE) \
2051 template <typename Derived> \
2052 bool RecursiveASTVisitor<Derived>::Traverse##STMT( \
2053 STMT *S, DataRecursionQueue *Queue) { \
2054 bool ShouldVisitChildren = true; \
2055 bool ReturnValue = true; \
2056 if (!getDerived().shouldTraversePostOrder()) \
2057 TRY_TO(WalkUpFrom##STMT(S)); \
2059 if (ShouldVisitChildren) { \
2060 for (Stmt *SubStmt : S->children()) { \
2061 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt); \
2064 if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder()) \
2065 TRY_TO(WalkUpFrom##STMT(S)); \
2066 return ReturnValue; \
2069 DEF_TRAVERSE_STMT(GCCAsmStmt, {
2070 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
2071 for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
2072 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
2074 for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
2075 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
2077 for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
2078 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
2080 // children() iterates over inputExpr and outputExpr.
2085 {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc. Once
2086 // added this needs to be implemented.
2089 DEF_TRAVERSE_STMT(CXXCatchStmt, {
2090 TRY_TO(TraverseDecl(S->getExceptionDecl()));
2091 // children() iterates over the handler block.
2094 DEF_TRAVERSE_STMT(DeclStmt, {
2095 for (auto *I : S->decls()) {
2096 TRY_TO(TraverseDecl(I));
2098 // Suppress the default iteration over children() by
2099 // returning. Here's why: A DeclStmt looks like 'type var [=
2100 // initializer]'. The decls above already traverse over the
2101 // initializers, so we don't have to do it again (which
2102 // children() would do).
2103 ShouldVisitChildren = false;
2106 // These non-expr stmts (most of them), do not need any action except
2107 // iterating over the children.
2108 DEF_TRAVERSE_STMT(BreakStmt, {})
2109 DEF_TRAVERSE_STMT(CXXTryStmt, {})
2110 DEF_TRAVERSE_STMT(CaseStmt, {})
2111 DEF_TRAVERSE_STMT(CompoundStmt, {})
2112 DEF_TRAVERSE_STMT(ContinueStmt, {})
2113 DEF_TRAVERSE_STMT(DefaultStmt, {})
2114 DEF_TRAVERSE_STMT(DoStmt, {})
2115 DEF_TRAVERSE_STMT(ForStmt, {})
2116 DEF_TRAVERSE_STMT(GotoStmt, {})
2117 DEF_TRAVERSE_STMT(IfStmt, {})
2118 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
2119 DEF_TRAVERSE_STMT(LabelStmt, {})
2120 DEF_TRAVERSE_STMT(AttributedStmt, {})
2121 DEF_TRAVERSE_STMT(NullStmt, {})
2122 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
2123 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
2124 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
2125 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
2126 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
2127 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
2128 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
2130 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
2131 if (!getDerived().shouldVisitImplicitCode()) {
2132 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
2133 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
2134 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2135 // Visit everything else only if shouldVisitImplicitCode().
2136 ShouldVisitChildren = false;
2140 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
2141 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2142 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2145 DEF_TRAVERSE_STMT(ReturnStmt, {})
2146 DEF_TRAVERSE_STMT(SwitchStmt, {})
2147 DEF_TRAVERSE_STMT(WhileStmt, {})
2149 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
2150 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2151 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2152 if (S->hasExplicitTemplateArgs()) {
2153 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2154 S->getNumTemplateArgs()));
2158 DEF_TRAVERSE_STMT(DeclRefExpr, {
2159 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2160 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2161 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2162 S->getNumTemplateArgs()));
2165 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
2166 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2167 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2168 if (S->hasExplicitTemplateArgs()) {
2169 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2170 S->getNumTemplateArgs()));
2174 DEF_TRAVERSE_STMT(MemberExpr, {
2175 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2176 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2177 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2178 S->getNumTemplateArgs()));
2183 {// We don't traverse the cast type, as it's not written in the
2187 DEF_TRAVERSE_STMT(CStyleCastExpr, {
2188 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2191 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
2192 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2195 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
2196 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2199 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
2200 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2203 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
2204 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2207 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
2208 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2211 template <typename Derived>
2212 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
2213 InitListExpr *S, DataRecursionQueue *Queue) {
2215 // Skip this if we traverse postorder. We will visit it later
2216 // in PostVisitStmt.
2217 if (!getDerived().shouldTraversePostOrder())
2218 TRY_TO(WalkUpFromInitListExpr(S));
2220 // All we need are the default actions. FIXME: use a helper function.
2221 for (Stmt *SubStmt : S->children()) {
2222 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
2228 // This method is called once for each pair of syntactic and semantic
2229 // InitListExpr, and it traverses the subtrees defined by the two forms. This
2230 // may cause some of the children to be visited twice, if they appear both in
2231 // the syntactic and the semantic form.
2233 // There is no guarantee about which form \p S takes when this method is called.
2234 template <typename Derived>
2235 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(
2236 InitListExpr *S, DataRecursionQueue *Queue) {
2237 TRY_TO(TraverseSynOrSemInitListExpr(
2238 S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
2239 TRY_TO(TraverseSynOrSemInitListExpr(
2240 S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
2244 // GenericSelectionExpr is a special case because the types and expressions
2245 // are interleaved. We also need to watch out for null types (default
2246 // generic associations).
2247 DEF_TRAVERSE_STMT(GenericSelectionExpr, {
2248 TRY_TO(TraverseStmt(S->getControllingExpr()));
2249 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
2250 if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
2251 TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
2252 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAssocExpr(i));
2254 ShouldVisitChildren = false;
2257 // PseudoObjectExpr is a special case because of the weirdness with
2258 // syntactic expressions and opaque values.
2259 DEF_TRAVERSE_STMT(PseudoObjectExpr, {
2260 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
2261 for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2262 e = S->semantics_end();
2265 if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2266 sub = OVE->getSourceExpr();
2267 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub);
2269 ShouldVisitChildren = false;
2272 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
2273 // This is called for code like 'return T()' where T is a built-in
2274 // (i.e. non-class) type.
2275 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2278 DEF_TRAVERSE_STMT(CXXNewExpr, {
2279 // The child-iterator will pick up the other arguments.
2280 TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
2283 DEF_TRAVERSE_STMT(OffsetOfExpr, {
2284 // The child-iterator will pick up the expression representing
2286 // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2287 // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2288 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2291 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2292 // The child-iterator will pick up the arg if it's an expression,
2293 // but not if it's a type.
2294 if (S->isArgumentType())
2295 TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2298 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2299 // The child-iterator will pick up the arg if it's an expression,
2300 // but not if it's a type.
2301 if (S->isTypeOperand())
2302 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2305 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2306 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2309 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
2311 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2312 // The child-iterator will pick up the arg if it's an expression,
2313 // but not if it's a type.
2314 if (S->isTypeOperand())
2315 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2318 DEF_TRAVERSE_STMT(TypeTraitExpr, {
2319 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2320 TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2323 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2324 TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2327 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2328 { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
2330 DEF_TRAVERSE_STMT(VAArgExpr, {
2331 // The child-iterator will pick up the expression argument.
2332 TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2335 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2336 // This is called for code like 'return T()' where T is a class type.
2337 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2340 // Walk only the visible parts of lambda expressions.
2341 DEF_TRAVERSE_STMT(LambdaExpr, {
2342 for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
2343 const LambdaCapture *C = S->capture_begin() + I;
2344 if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
2345 TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
2349 TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2350 FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>();
2352 if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2353 // Visit the whole type.
2354 TRY_TO(TraverseTypeLoc(TL));
2356 if (S->hasExplicitParameters()) {
2357 // Visit parameters.
2358 for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
2359 TRY_TO(TraverseDecl(Proto.getParam(I)));
2361 } else if (S->hasExplicitResultType()) {
2362 TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
2365 auto *T = Proto.getTypePtr();
2366 for (const auto &E : T->exceptions()) {
2367 TRY_TO(TraverseType(E));
2370 if (Expr *NE = T->getNoexceptExpr())
2371 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
2374 ReturnValue = TRAVERSE_STMT_BASE(LambdaBody, LambdaExpr, S, Queue);
2375 ShouldVisitChildren = false;
2378 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2379 // This is called for code like 'T()', where T is a template argument.
2380 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2383 // These expressions all might take explicit template arguments.
2384 // We traverse those if so. FIXME: implement these.
2385 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2386 DEF_TRAVERSE_STMT(CallExpr, {})
2387 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
2389 // These exprs (most of them), do not need any action except iterating
2390 // over the children.
2391 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2392 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
2393 DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
2395 DEF_TRAVERSE_STMT(BlockExpr, {
2396 TRY_TO(TraverseDecl(S->getBlockDecl()));
2397 return true; // no child statements to loop through.
2400 DEF_TRAVERSE_STMT(ChooseExpr, {})
2401 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2402 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2404 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2405 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2407 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
2408 if (getDerived().shouldVisitImplicitCode())
2409 TRY_TO(TraverseStmt(S->getExpr()));
2412 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
2413 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2414 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2415 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
2416 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2417 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
2419 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2420 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2421 if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2422 TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2423 if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2424 TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2427 DEF_TRAVERSE_STMT(CXXThisExpr, {})
2428 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2429 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2430 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2431 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
2432 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2433 DEF_TRAVERSE_STMT(GNUNullExpr, {})
2434 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2435 DEF_TRAVERSE_STMT(NoInitExpr, {})
2436 DEF_TRAVERSE_STMT(ArrayInitLoopExpr, {
2437 // FIXME: The source expression of the OVE should be listed as
2438 // a child of the ArrayInitLoopExpr.
2439 if (OpaqueValueExpr *OVE = S->getCommonExpr())
2440 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr());
2442 DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {})
2443 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
2445 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2446 if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2447 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2450 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2451 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
2453 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2454 if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2455 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2458 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
2459 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2460 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2461 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2462 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
2464 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2465 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2468 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
2469 DEF_TRAVERSE_STMT(ParenExpr, {})
2470 DEF_TRAVERSE_STMT(ParenListExpr, {})
2471 DEF_TRAVERSE_STMT(PredefinedExpr, {})
2472 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2473 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2474 DEF_TRAVERSE_STMT(StmtExpr, {})
2475 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2476 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2477 if (S->hasExplicitTemplateArgs()) {
2478 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2479 S->getNumTemplateArgs()));
2483 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2484 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2485 if (S->hasExplicitTemplateArgs()) {
2486 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2487 S->getNumTemplateArgs()));
2491 DEF_TRAVERSE_STMT(SEHTryStmt, {})
2492 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2493 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
2494 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
2495 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2497 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2498 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
2499 DEF_TRAVERSE_STMT(TypoExpr, {})
2500 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
2502 // These operators (all of them) do not need any action except
2503 // iterating over the children.
2504 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2505 DEF_TRAVERSE_STMT(ConditionalOperator, {})
2506 DEF_TRAVERSE_STMT(UnaryOperator, {})
2507 DEF_TRAVERSE_STMT(BinaryOperator, {})
2508 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2509 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2510 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2511 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2512 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2513 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2514 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2515 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
2516 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
2517 DEF_TRAVERSE_STMT(AtomicExpr, {})
2519 // For coroutines expressions, traverse either the operand
2520 // as written or the implied calls, depending on what the
2521 // derived class requests.
2522 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
2523 if (!getDerived().shouldVisitImplicitCode()) {
2524 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2525 ShouldVisitChildren = false;
2528 DEF_TRAVERSE_STMT(CoreturnStmt, {
2529 if (!getDerived().shouldVisitImplicitCode()) {
2530 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2531 ShouldVisitChildren = false;
2534 DEF_TRAVERSE_STMT(CoawaitExpr, {
2535 if (!getDerived().shouldVisitImplicitCode()) {
2536 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2537 ShouldVisitChildren = false;
2540 DEF_TRAVERSE_STMT(DependentCoawaitExpr, {
2541 if (!getDerived().shouldVisitImplicitCode()) {
2542 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2543 ShouldVisitChildren = false;
2546 DEF_TRAVERSE_STMT(CoyieldExpr, {
2547 if (!getDerived().shouldVisitImplicitCode()) {
2548 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2549 ShouldVisitChildren = false;
2553 // These literals (all of them) do not need any action.
2554 DEF_TRAVERSE_STMT(IntegerLiteral, {})
2555 DEF_TRAVERSE_STMT(CharacterLiteral, {})
2556 DEF_TRAVERSE_STMT(FloatingLiteral, {})
2557 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
2558 DEF_TRAVERSE_STMT(StringLiteral, {})
2559 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
2560 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
2561 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
2562 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
2564 // Traverse OpenCL: AsType, Convert.
2565 DEF_TRAVERSE_STMT(AsTypeExpr, {})
2567 // OpenMP directives.
2568 template <typename Derived>
2569 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
2570 OMPExecutableDirective *S) {
2571 for (auto *C : S->clauses()) {
2572 TRY_TO(TraverseOMPClause(C));
2577 template <typename Derived>
2579 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
2580 return TraverseOMPExecutableDirective(S);
2583 DEF_TRAVERSE_STMT(OMPParallelDirective,
2584 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2586 DEF_TRAVERSE_STMT(OMPSimdDirective,
2587 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2589 DEF_TRAVERSE_STMT(OMPForDirective,
2590 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2592 DEF_TRAVERSE_STMT(OMPForSimdDirective,
2593 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2595 DEF_TRAVERSE_STMT(OMPSectionsDirective,
2596 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2598 DEF_TRAVERSE_STMT(OMPSectionDirective,
2599 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2601 DEF_TRAVERSE_STMT(OMPSingleDirective,
2602 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2604 DEF_TRAVERSE_STMT(OMPMasterDirective,
2605 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2607 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
2608 TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
2609 TRY_TO(TraverseOMPExecutableDirective(S));
2612 DEF_TRAVERSE_STMT(OMPParallelForDirective,
2613 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2615 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
2616 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2618 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
2619 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2621 DEF_TRAVERSE_STMT(OMPTaskDirective,
2622 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2624 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
2625 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2627 DEF_TRAVERSE_STMT(OMPBarrierDirective,
2628 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2630 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
2631 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2633 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
2634 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2636 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
2637 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2639 DEF_TRAVERSE_STMT(OMPCancelDirective,
2640 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2642 DEF_TRAVERSE_STMT(OMPFlushDirective,
2643 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2645 DEF_TRAVERSE_STMT(OMPOrderedDirective,
2646 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2648 DEF_TRAVERSE_STMT(OMPAtomicDirective,
2649 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2651 DEF_TRAVERSE_STMT(OMPTargetDirective,
2652 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2654 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
2655 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2657 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
2658 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2660 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
2661 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2663 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
2664 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2666 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
2667 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2669 DEF_TRAVERSE_STMT(OMPTeamsDirective,
2670 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2672 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
2673 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2675 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
2676 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2678 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
2679 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2681 DEF_TRAVERSE_STMT(OMPDistributeDirective,
2682 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2684 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
2685 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2687 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
2688 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2690 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
2691 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2693 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
2694 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2696 DEF_TRAVERSE_STMT(OMPTargetSimdDirective,
2697 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2699 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective,
2700 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2702 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective,
2703 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2705 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective,
2706 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2708 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective,
2709 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2711 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective,
2712 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2714 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective,
2715 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2717 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective,
2718 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2720 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective,
2721 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2723 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective,
2724 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2727 template <typename Derived>
2728 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
2731 switch (C->getClauseKind()) {
2732 #define OPENMP_CLAUSE(Name, Class) \
2734 TRY_TO(Visit##Class(static_cast<Class *>(C))); \
2736 #include "clang/Basic/OpenMPKinds.def"
2737 case OMPC_threadprivate:
2745 template <typename Derived>
2746 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
2747 OMPClauseWithPreInit *Node) {
2748 TRY_TO(TraverseStmt(Node->getPreInitStmt()));
2752 template <typename Derived>
2753 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
2754 OMPClauseWithPostUpdate *Node) {
2755 TRY_TO(VisitOMPClauseWithPreInit(Node));
2756 TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
2760 template <typename Derived>
2761 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
2762 TRY_TO(VisitOMPClauseWithPreInit(C));
2763 TRY_TO(TraverseStmt(C->getCondition()));
2767 template <typename Derived>
2768 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
2769 TRY_TO(TraverseStmt(C->getCondition()));
2773 template <typename Derived>
2775 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
2776 TRY_TO(VisitOMPClauseWithPreInit(C));
2777 TRY_TO(TraverseStmt(C->getNumThreads()));
2781 template <typename Derived>
2782 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
2783 TRY_TO(TraverseStmt(C->getSafelen()));
2787 template <typename Derived>
2788 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
2789 TRY_TO(TraverseStmt(C->getSimdlen()));
2793 template <typename Derived>
2795 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
2796 TRY_TO(TraverseStmt(C->getNumForLoops()));
2800 template <typename Derived>
2801 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
2805 template <typename Derived>
2806 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
2810 template <typename Derived>
2812 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
2813 TRY_TO(VisitOMPClauseWithPreInit(C));
2814 TRY_TO(TraverseStmt(C->getChunkSize()));
2818 template <typename Derived>
2819 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
2820 TRY_TO(TraverseStmt(C->getNumForLoops()));
2824 template <typename Derived>
2825 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
2829 template <typename Derived>
2830 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
2834 template <typename Derived>
2836 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
2840 template <typename Derived>
2841 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
2845 template <typename Derived>
2846 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
2850 template <typename Derived>
2851 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
2855 template <typename Derived>
2856 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2860 template <typename Derived>
2861 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2865 template <typename Derived>
2866 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
2870 template <typename Derived>
2871 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
2875 template <typename Derived>
2876 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
2880 template <typename Derived>
2881 template <typename T>
2882 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
2883 for (auto *E : Node->varlists()) {
2884 TRY_TO(TraverseStmt(E));
2889 template <typename Derived>
2890 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
2891 TRY_TO(VisitOMPClauseList(C));
2892 for (auto *E : C->private_copies()) {
2893 TRY_TO(TraverseStmt(E));
2898 template <typename Derived>
2899 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
2900 OMPFirstprivateClause *C) {
2901 TRY_TO(VisitOMPClauseList(C));
2902 TRY_TO(VisitOMPClauseWithPreInit(C));
2903 for (auto *E : C->private_copies()) {
2904 TRY_TO(TraverseStmt(E));
2906 for (auto *E : C->inits()) {
2907 TRY_TO(TraverseStmt(E));
2912 template <typename Derived>
2913 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
2914 OMPLastprivateClause *C) {
2915 TRY_TO(VisitOMPClauseList(C));
2916 TRY_TO(VisitOMPClauseWithPostUpdate(C));
2917 for (auto *E : C->private_copies()) {
2918 TRY_TO(TraverseStmt(E));
2920 for (auto *E : C->source_exprs()) {
2921 TRY_TO(TraverseStmt(E));
2923 for (auto *E : C->destination_exprs()) {
2924 TRY_TO(TraverseStmt(E));
2926 for (auto *E : C->assignment_ops()) {
2927 TRY_TO(TraverseStmt(E));
2932 template <typename Derived>
2933 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
2934 TRY_TO(VisitOMPClauseList(C));
2938 template <typename Derived>
2939 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2940 TRY_TO(TraverseStmt(C->getStep()));
2941 TRY_TO(TraverseStmt(C->getCalcStep()));
2942 TRY_TO(VisitOMPClauseList(C));
2943 TRY_TO(VisitOMPClauseWithPostUpdate(C));
2944 for (auto *E : C->privates()) {
2945 TRY_TO(TraverseStmt(E));
2947 for (auto *E : C->inits()) {
2948 TRY_TO(TraverseStmt(E));
2950 for (auto *E : C->updates()) {
2951 TRY_TO(TraverseStmt(E));
2953 for (auto *E : C->finals()) {
2954 TRY_TO(TraverseStmt(E));
2959 template <typename Derived>
2960 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
2961 TRY_TO(TraverseStmt(C->getAlignment()));
2962 TRY_TO(VisitOMPClauseList(C));
2966 template <typename Derived>
2967 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
2968 TRY_TO(VisitOMPClauseList(C));
2969 for (auto *E : C->source_exprs()) {
2970 TRY_TO(TraverseStmt(E));
2972 for (auto *E : C->destination_exprs()) {
2973 TRY_TO(TraverseStmt(E));
2975 for (auto *E : C->assignment_ops()) {
2976 TRY_TO(TraverseStmt(E));
2981 template <typename Derived>
2982 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
2983 OMPCopyprivateClause *C) {
2984 TRY_TO(VisitOMPClauseList(C));
2985 for (auto *E : C->source_exprs()) {
2986 TRY_TO(TraverseStmt(E));
2988 for (auto *E : C->destination_exprs()) {
2989 TRY_TO(TraverseStmt(E));
2991 for (auto *E : C->assignment_ops()) {
2992 TRY_TO(TraverseStmt(E));
2997 template <typename Derived>
2999 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
3000 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3001 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3002 TRY_TO(VisitOMPClauseList(C));
3003 TRY_TO(VisitOMPClauseWithPostUpdate(C));
3004 for (auto *E : C->privates()) {
3005 TRY_TO(TraverseStmt(E));
3007 for (auto *E : C->lhs_exprs()) {
3008 TRY_TO(TraverseStmt(E));
3010 for (auto *E : C->rhs_exprs()) {
3011 TRY_TO(TraverseStmt(E));
3013 for (auto *E : C->reduction_ops()) {
3014 TRY_TO(TraverseStmt(E));
3019 template <typename Derived>
3020 bool RecursiveASTVisitor<Derived>::VisitOMPTaskReductionClause(
3021 OMPTaskReductionClause *C) {
3022 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
3023 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
3024 TRY_TO(VisitOMPClauseList(C));
3025 TRY_TO(VisitOMPClauseWithPostUpdate(C));
3026 for (auto *E : C->privates()) {
3027 TRY_TO(TraverseStmt(E));
3029 for (auto *E : C->lhs_exprs()) {
3030 TRY_TO(TraverseStmt(E));
3032 for (auto *E : C->rhs_exprs()) {
3033 TRY_TO(TraverseStmt(E));
3035 for (auto *E : C->reduction_ops()) {
3036 TRY_TO(TraverseStmt(E));
3041 template <typename Derived>
3042 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
3043 TRY_TO(VisitOMPClauseList(C));
3047 template <typename Derived>
3048 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
3049 TRY_TO(VisitOMPClauseList(C));
3053 template <typename Derived>
3054 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
3055 TRY_TO(TraverseStmt(C->getDevice()));
3059 template <typename Derived>
3060 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
3061 TRY_TO(VisitOMPClauseList(C));
3065 template <typename Derived>
3066 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
3067 OMPNumTeamsClause *C) {
3068 TRY_TO(VisitOMPClauseWithPreInit(C));
3069 TRY_TO(TraverseStmt(C->getNumTeams()));
3073 template <typename Derived>
3074 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
3075 OMPThreadLimitClause *C) {
3076 TRY_TO(VisitOMPClauseWithPreInit(C));
3077 TRY_TO(TraverseStmt(C->getThreadLimit()));
3081 template <typename Derived>
3082 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
3083 OMPPriorityClause *C) {
3084 TRY_TO(TraverseStmt(C->getPriority()));
3088 template <typename Derived>
3089 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
3090 OMPGrainsizeClause *C) {
3091 TRY_TO(TraverseStmt(C->getGrainsize()));
3095 template <typename Derived>
3096 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
3097 OMPNumTasksClause *C) {
3098 TRY_TO(TraverseStmt(C->getNumTasks()));
3102 template <typename Derived>
3103 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
3104 TRY_TO(TraverseStmt(C->getHint()));
3108 template <typename Derived>
3109 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
3110 OMPDistScheduleClause *C) {
3111 TRY_TO(VisitOMPClauseWithPreInit(C));
3112 TRY_TO(TraverseStmt(C->getChunkSize()));
3116 template <typename Derived>
3118 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
3122 template <typename Derived>
3123 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
3124 TRY_TO(VisitOMPClauseList(C));
3128 template <typename Derived>
3129 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
3130 TRY_TO(VisitOMPClauseList(C));
3134 template <typename Derived>
3135 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
3136 OMPUseDevicePtrClause *C) {
3137 TRY_TO(VisitOMPClauseList(C));
3141 template <typename Derived>
3142 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
3143 OMPIsDevicePtrClause *C) {
3144 TRY_TO(VisitOMPClauseList(C));
3148 // FIXME: look at the following tricky-seeming exprs to see if we
3149 // need to recurse on anything. These are ones that have methods
3150 // returning decls or qualtypes or nestednamespecifier -- though I'm
3151 // not sure if they own them -- or just seemed very complicated, or
3152 // had lots of sub-types to explore.
3154 // VisitOverloadExpr and its children: recurse on template args? etc?
3156 // FIXME: go through all the stmts and exprs again, and see which of them
3157 // create new types, and recurse on the types (TypeLocs?) of those.
3160 // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
3161 // http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
3162 // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
3163 // Every class that has getQualifier.
3165 #undef DEF_TRAVERSE_STMT
3166 #undef TRAVERSE_STMT
3167 #undef TRAVERSE_STMT_BASE
3171 } // end namespace clang
3173 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H