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 <type_traits>
19 #include "clang/AST/Attr.h"
20 #include "clang/AST/Decl.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/NestedNameSpecifier.h"
31 #include "clang/AST/Stmt.h"
32 #include "clang/AST/StmtCXX.h"
33 #include "clang/AST/StmtObjC.h"
34 #include "clang/AST/StmtOpenMP.h"
35 #include "clang/AST/TemplateBase.h"
36 #include "clang/AST/TemplateName.h"
37 #include "clang/AST/Type.h"
38 #include "clang/AST/TypeLoc.h"
40 // The following three macros are used for meta programming. The code
41 // using them is responsible for defining macro OPERATOR().
43 // All unary operators.
44 #define UNARYOP_LIST() \
45 OPERATOR(PostInc) OPERATOR(PostDec) OPERATOR(PreInc) OPERATOR(PreDec) \
46 OPERATOR(AddrOf) OPERATOR(Deref) OPERATOR(Plus) OPERATOR(Minus) \
47 OPERATOR(Not) OPERATOR(LNot) OPERATOR(Real) OPERATOR(Imag) \
48 OPERATOR(Extension) OPERATOR(Coawait)
50 // All binary operators (excluding compound assign operators).
51 #define BINOP_LIST() \
52 OPERATOR(PtrMemD) OPERATOR(PtrMemI) OPERATOR(Mul) OPERATOR(Div) \
53 OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) OPERATOR(Shr) \
54 OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) OPERATOR(GE) OPERATOR(EQ) \
55 OPERATOR(NE) OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) OPERATOR(LAnd) \
56 OPERATOR(LOr) OPERATOR(Assign) OPERATOR(Comma)
58 // All compound assign operators.
60 OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \
61 OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor)
65 // A helper macro to implement short-circuiting when recursing. It
66 // invokes CALL_EXPR, which must be a method call, on the derived
67 // object (s.t. a user of RecursiveASTVisitor can override the method
69 #define TRY_TO(CALL_EXPR) \
71 if (!getDerived().CALL_EXPR) \
75 /// \brief A class that does preordor or postorder
76 /// depth-first traversal on the entire Clang AST and visits each node.
78 /// This class performs three distinct tasks:
79 /// 1. traverse the AST (i.e. go to each node);
80 /// 2. at a given node, walk up the class hierarchy, starting from
81 /// the node's dynamic type, until the top-most class (e.g. Stmt,
82 /// Decl, or Type) is reached.
83 /// 3. given a (node, class) combination, where 'class' is some base
84 /// class of the dynamic type of 'node', call a user-overridable
85 /// function to actually visit the node.
87 /// These tasks are done by three groups of methods, respectively:
88 /// 1. TraverseDecl(Decl *x) does task #1. It is the entry point
89 /// for traversing an AST rooted at x. This method simply
90 /// dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
91 /// is the dynamic type of *x, which calls WalkUpFromFoo(x) and
92 /// then recursively visits the child nodes of x.
93 /// TraverseStmt(Stmt *x) and TraverseType(QualType x) work
95 /// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit
96 /// any child node of x. Instead, it first calls WalkUpFromBar(x)
97 /// where Bar is the direct parent class of Foo (unless Foo has
98 /// no parent), and then calls VisitFoo(x) (see the next list item).
99 /// 3. VisitFoo(Foo *x) does task #3.
101 /// These three method groups are tiered (Traverse* > WalkUpFrom* >
102 /// Visit*). A method (e.g. Traverse*) may call methods from the same
103 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
104 /// It may not call methods from a higher tier.
106 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
107 /// is Foo's super class) before calling VisitFoo(), the result is
108 /// that the Visit*() methods for a given node are called in the
109 /// top-down order (e.g. for a node of type NamespaceDecl, the order will
110 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
112 /// This scheme guarantees that all Visit*() calls for the same AST
113 /// node are grouped together. In other words, Visit*() methods for
114 /// different nodes are never interleaved.
116 /// Clients of this visitor should subclass the visitor (providing
117 /// themselves as the template argument, using the curiously recurring
118 /// template pattern) and override any of the Traverse*, WalkUpFrom*,
119 /// and Visit* methods for declarations, types, statements,
120 /// expressions, or other AST nodes where the visitor should customize
121 /// behavior. Most users only need to override Visit*. Advanced
122 /// users may override Traverse* and WalkUpFrom* to implement custom
123 /// traversal strategies. Returning false from one of these overridden
124 /// functions will abort the entire traversal.
126 /// By default, this visitor tries to visit every part of the explicit
127 /// source code exactly once. The default policy towards templates
128 /// is to descend into the 'pattern' class or function body, not any
129 /// explicit or implicit instantiations. Explicit specializations
130 /// are still visited, and the patterns of partial specializations
131 /// are visited separately. This behavior can be changed by
132 /// overriding shouldVisitTemplateInstantiations() in the derived class
133 /// to return true, in which case all known implicit and explicit
134 /// instantiations will be visited at the same time as the pattern
135 /// from which they were produced.
137 /// By default, this visitor preorder traverses the AST. If postorder traversal
138 /// is needed, the \c shouldTraversePostOrder method needs to be overriden
139 /// to return \c true.
140 template <typename Derived> class RecursiveASTVisitor {
142 /// A queue used for performing data recursion over statements.
143 /// Parameters involving this type are used to implement data
144 /// recursion over Stmts and Exprs within this class, and should
145 /// typically not be explicitly specified by derived classes.
146 /// The bool bit indicates whether the statement has been traversed or not.
147 typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>>
150 /// \brief Return a reference to the derived class.
151 Derived &getDerived() { return *static_cast<Derived *>(this); }
153 /// \brief Return whether this visitor should recurse into
154 /// template instantiations.
155 bool shouldVisitTemplateInstantiations() const { return false; }
157 /// \brief Return whether this visitor should recurse into the types of
159 bool shouldWalkTypesOfTypeLocs() const { return true; }
161 /// \brief Return whether this visitor should recurse into implicit
162 /// code, e.g., implicit constructors and destructors.
163 bool shouldVisitImplicitCode() const { return false; }
165 /// \brief Return whether this visitor should traverse post-order.
166 bool shouldTraversePostOrder() const { return false; }
168 /// \brief Recursively visit a statement or expression, by
169 /// dispatching to Traverse*() based on the argument's dynamic type.
171 /// \returns false if the visitation was terminated early, true
172 /// otherwise (including when the argument is nullptr).
173 bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr);
175 /// Invoked before visiting a statement or expression via data recursion.
177 /// \returns false to skip visiting the node, true otherwise.
178 bool dataTraverseStmtPre(Stmt *S) { return true; }
180 /// Invoked after visiting a statement or expression via data recursion.
181 /// This is not invoked if the previously invoked \c dataTraverseStmtPre
184 /// \returns false if the visitation was terminated early, true otherwise.
185 bool dataTraverseStmtPost(Stmt *S) { return true; }
187 /// \brief Recursively visit a type, by dispatching to
188 /// Traverse*Type() based on the argument's getTypeClass() property.
190 /// \returns false if the visitation was terminated early, true
191 /// otherwise (including when the argument is a Null type).
192 bool TraverseType(QualType T);
194 /// \brief Recursively visit a type with location, by dispatching to
195 /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
197 /// \returns false if the visitation was terminated early, true
198 /// otherwise (including when the argument is a Null type location).
199 bool TraverseTypeLoc(TypeLoc TL);
201 /// \brief Recursively visit an attribute, by dispatching to
202 /// Traverse*Attr() based on the argument's dynamic type.
204 /// \returns false if the visitation was terminated early, true
205 /// otherwise (including when the argument is a Null type location).
206 bool TraverseAttr(Attr *At);
208 /// \brief Recursively visit a declaration, by dispatching to
209 /// Traverse*Decl() based on the argument's dynamic type.
211 /// \returns false if the visitation was terminated early, true
212 /// otherwise (including when the argument is NULL).
213 bool TraverseDecl(Decl *D);
215 /// \brief Recursively visit a C++ nested-name-specifier.
217 /// \returns false if the visitation was terminated early, true otherwise.
218 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
220 /// \brief Recursively visit a C++ nested-name-specifier with location
223 /// \returns false if the visitation was terminated early, true otherwise.
224 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
226 /// \brief Recursively visit a name with its location information.
228 /// \returns false if the visitation was terminated early, true otherwise.
229 bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
231 /// \brief Recursively visit a template name and dispatch to the
232 /// appropriate method.
234 /// \returns false if the visitation was terminated early, true otherwise.
235 bool TraverseTemplateName(TemplateName Template);
237 /// \brief Recursively visit a template argument and dispatch to the
238 /// appropriate method for the argument type.
240 /// \returns false if the visitation was terminated early, true otherwise.
241 // FIXME: migrate callers to TemplateArgumentLoc instead.
242 bool TraverseTemplateArgument(const TemplateArgument &Arg);
244 /// \brief Recursively visit a template argument location and dispatch to the
245 /// appropriate method for the argument type.
247 /// \returns false if the visitation was terminated early, true otherwise.
248 bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
250 /// \brief Recursively visit a set of template arguments.
251 /// This can be overridden by a subclass, but it's not expected that
252 /// will be needed -- this visitor always dispatches to another.
254 /// \returns false if the visitation was terminated early, true otherwise.
255 // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
256 bool TraverseTemplateArguments(const TemplateArgument *Args,
259 /// \brief Recursively visit a constructor initializer. This
260 /// automatically dispatches to another visitor for the initializer
261 /// expression, but not for the name of the initializer, so may
262 /// be overridden for clients that need access to the name.
264 /// \returns false if the visitation was terminated early, true otherwise.
265 bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
267 /// \brief Recursively visit a lambda capture.
269 /// \returns false if the visitation was terminated early, true otherwise.
270 bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C);
272 /// \brief Recursively visit the body of a lambda expression.
274 /// This provides a hook for visitors that need more context when visiting
275 /// \c LE->getBody().
277 /// \returns false if the visitation was terminated early, true otherwise.
278 bool TraverseLambdaBody(LambdaExpr *LE, DataRecursionQueue *Queue = nullptr);
280 /// \brief Recursively visit the syntactic or semantic form of an
281 /// initialization list.
283 /// \returns false if the visitation was terminated early, true otherwise.
284 bool TraverseSynOrSemInitListExpr(InitListExpr *S,
285 DataRecursionQueue *Queue = nullptr);
287 // ---- Methods on Attrs ----
289 // \brief Visit an attribute.
290 bool VisitAttr(Attr *A) { return true; }
292 // Declare Traverse* and empty Visit* for all Attr classes.
293 #define ATTR_VISITOR_DECLS_ONLY
294 #include "clang/AST/AttrVisitor.inc"
295 #undef ATTR_VISITOR_DECLS_ONLY
297 // ---- Methods on Stmts ----
300 template<typename T, typename U>
301 struct has_same_member_pointer_type : std::false_type {};
302 template<typename T, typename U, typename R, typename... P>
303 struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)>
306 // Traverse the given statement. If the most-derived traverse function takes a
307 // data recursion queue, pass it on; otherwise, discard it. Note that the
308 // first branch of this conditional must compile whether or not the derived
309 // class can take a queue, so if we're taking the second arm, make the first
310 // arm call our function rather than the derived class version.
311 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE) \
312 (has_same_member_pointer_type<decltype( \
313 &RecursiveASTVisitor::Traverse##NAME), \
314 decltype(&Derived::Traverse##NAME)>::value \
315 ? static_cast<typename std::conditional< \
316 has_same_member_pointer_type< \
317 decltype(&RecursiveASTVisitor::Traverse##NAME), \
318 decltype(&Derived::Traverse##NAME)>::value, \
319 Derived &, RecursiveASTVisitor &>::type>(*this) \
320 .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE) \
321 : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR)))
323 // Try to traverse the given statement, or enqueue it if we're performing data
324 // recursion in the middle of traversing another statement. Can only be called
325 // from within a DEF_TRAVERSE_STMT body or similar context.
326 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S) \
328 if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue)) \
333 // Declare Traverse*() for all concrete Stmt classes.
334 #define ABSTRACT_STMT(STMT)
335 #define STMT(CLASS, PARENT) \
336 bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr);
337 #include "clang/AST/StmtNodes.inc"
338 // The above header #undefs ABSTRACT_STMT and STMT upon exit.
340 // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
341 bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
342 bool VisitStmt(Stmt *S) { return true; }
343 #define STMT(CLASS, PARENT) \
344 bool WalkUpFrom##CLASS(CLASS *S) { \
345 TRY_TO(WalkUpFrom##PARENT(S)); \
346 TRY_TO(Visit##CLASS(S)); \
349 bool Visit##CLASS(CLASS *S) { return true; }
350 #include "clang/AST/StmtNodes.inc"
352 // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
353 // operator methods. Unary operators are not classes in themselves
354 // (they're all opcodes in UnaryOperator) but do have visitors.
355 #define OPERATOR(NAME) \
356 bool TraverseUnary##NAME(UnaryOperator *S, \
357 DataRecursionQueue *Queue = nullptr) { \
358 TRY_TO(WalkUpFromUnary##NAME(S)); \
359 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr()); \
362 bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
363 TRY_TO(WalkUpFromUnaryOperator(S)); \
364 TRY_TO(VisitUnary##NAME(S)); \
367 bool VisitUnary##NAME(UnaryOperator *S) { return true; }
372 // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
373 // operator methods. Binary operators are not classes in themselves
374 // (they're all opcodes in BinaryOperator) but do have visitors.
375 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \
376 bool TraverseBin##NAME(BINOP_TYPE *S, DataRecursionQueue *Queue = nullptr) { \
377 if (!getDerived().shouldTraversePostOrder()) \
378 TRY_TO(WalkUpFromBin##NAME(S)); \
379 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLHS()); \
380 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRHS()); \
383 bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
384 TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \
385 TRY_TO(VisitBin##NAME(S)); \
388 bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
390 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
394 // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
395 // assignment methods. Compound assignment operators are not
396 // classes in themselves (they're all opcodes in
397 // CompoundAssignOperator) but do have visitors.
398 #define OPERATOR(NAME) \
399 GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
403 #undef GENERAL_BINOP_FALLBACK
405 // ---- Methods on Types ----
406 // FIXME: revamp to take TypeLoc's rather than Types.
408 // Declare Traverse*() for all concrete Type classes.
409 #define ABSTRACT_TYPE(CLASS, BASE)
410 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
411 #include "clang/AST/TypeNodes.def"
412 // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
414 // Define WalkUpFrom*() and empty Visit*() for all Type classes.
415 bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
416 bool VisitType(Type *T) { return true; }
417 #define TYPE(CLASS, BASE) \
418 bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \
419 TRY_TO(WalkUpFrom##BASE(T)); \
420 TRY_TO(Visit##CLASS##Type(T)); \
423 bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
424 #include "clang/AST/TypeNodes.def"
426 // ---- Methods on TypeLocs ----
427 // FIXME: this currently just calls the matching Type methods
429 // Declare Traverse*() for all concrete TypeLoc classes.
430 #define ABSTRACT_TYPELOC(CLASS, BASE)
431 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
432 #include "clang/AST/TypeLocNodes.def"
433 // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
435 // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
436 bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
437 bool VisitTypeLoc(TypeLoc TL) { return true; }
439 // QualifiedTypeLoc and UnqualTypeLoc are not declared in
440 // TypeNodes.def and thus need to be handled specially.
441 bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
442 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
444 bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
445 bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
446 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
448 bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
450 // Note that BASE includes trailing 'Type' which CLASS doesn't.
451 #define TYPE(CLASS, BASE) \
452 bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
453 TRY_TO(WalkUpFrom##BASE##Loc(TL)); \
454 TRY_TO(Visit##CLASS##TypeLoc(TL)); \
457 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
458 #include "clang/AST/TypeNodes.def"
460 // ---- Methods on Decls ----
462 // Declare Traverse*() for all concrete Decl classes.
463 #define ABSTRACT_DECL(DECL)
464 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
465 #include "clang/AST/DeclNodes.inc"
466 // The above header #undefs ABSTRACT_DECL and DECL upon exit.
468 // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
469 bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
470 bool VisitDecl(Decl *D) { return true; }
471 #define DECL(CLASS, BASE) \
472 bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \
473 TRY_TO(WalkUpFrom##BASE(D)); \
474 TRY_TO(Visit##CLASS##Decl(D)); \
477 bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
478 #include "clang/AST/DeclNodes.inc"
481 // These are helper methods used by more than one Traverse* method.
482 bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
483 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND) \
484 bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D);
485 DEF_TRAVERSE_TMPL_INST(Class)
486 DEF_TRAVERSE_TMPL_INST(Var)
487 DEF_TRAVERSE_TMPL_INST(Function)
488 #undef DEF_TRAVERSE_TMPL_INST
489 bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
491 bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
492 bool TraverseRecordHelper(RecordDecl *D);
493 bool TraverseCXXRecordHelper(CXXRecordDecl *D);
494 bool TraverseDeclaratorHelper(DeclaratorDecl *D);
495 bool TraverseDeclContextHelper(DeclContext *DC);
496 bool TraverseFunctionHelper(FunctionDecl *D);
497 bool TraverseVarHelper(VarDecl *D);
498 bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
499 bool TraverseOMPLoopDirective(OMPLoopDirective *S);
500 bool TraverseOMPClause(OMPClause *C);
501 #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C);
502 #include "clang/Basic/OpenMPKinds.def"
503 /// \brief Process clauses with list of variables.
504 template <typename T> bool VisitOMPClauseList(T *Node);
505 /// Process clauses with pre-initis.
506 bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
507 bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
509 bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
510 bool PostVisitStmt(Stmt *S);
513 template <typename Derived>
514 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S,
515 DataRecursionQueue *Queue) {
516 #define DISPATCH_STMT(NAME, CLASS, VAR) \
517 return TRAVERSE_STMT_BASE(NAME, CLASS, VAR, Queue);
519 // If we have a binary expr, dispatch to the subcode of the binop. A smart
520 // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
522 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
523 switch (BinOp->getOpcode()) {
524 #define OPERATOR(NAME) \
526 DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
532 #define OPERATOR(NAME) \
533 case BO_##NAME##Assign: \
534 DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
540 } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
541 switch (UnOp->getOpcode()) {
542 #define OPERATOR(NAME) \
544 DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
552 // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
553 switch (S->getStmtClass()) {
554 case Stmt::NoStmtClass:
556 #define ABSTRACT_STMT(STMT)
557 #define STMT(CLASS, PARENT) \
558 case Stmt::CLASS##Class: \
559 DISPATCH_STMT(CLASS, CLASS, S);
560 #include "clang/AST/StmtNodes.inc"
569 template <typename Derived>
570 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) {
571 switch (S->getStmtClass()) {
572 case Stmt::NoStmtClass:
574 #define ABSTRACT_STMT(STMT)
575 #define STMT(CLASS, PARENT) \
576 case Stmt::CLASS##Class: \
577 TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S))); break;
578 #include "clang/AST/StmtNodes.inc"
586 template <typename Derived>
587 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S,
588 DataRecursionQueue *Queue) {
593 Queue->push_back({S, false});
597 SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue;
598 LocalQueue.push_back({S, false});
600 while (!LocalQueue.empty()) {
601 auto &CurrSAndVisited = LocalQueue.back();
602 Stmt *CurrS = CurrSAndVisited.getPointer();
603 bool Visited = CurrSAndVisited.getInt();
605 LocalQueue.pop_back();
606 TRY_TO(dataTraverseStmtPost(CurrS));
607 if (getDerived().shouldTraversePostOrder()) {
608 TRY_TO(PostVisitStmt(CurrS));
613 if (getDerived().dataTraverseStmtPre(CurrS)) {
614 CurrSAndVisited.setInt(true);
615 size_t N = LocalQueue.size();
616 TRY_TO(dataTraverseNode(CurrS, &LocalQueue));
617 // Process new children in the order they were added.
618 std::reverse(LocalQueue.begin() + N, LocalQueue.end());
620 LocalQueue.pop_back();
627 #define DISPATCH(NAME, CLASS, VAR) \
628 return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))
630 template <typename Derived>
631 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
635 switch (T->getTypeClass()) {
636 #define ABSTRACT_TYPE(CLASS, BASE)
637 #define TYPE(CLASS, BASE) \
639 DISPATCH(CLASS##Type, CLASS##Type, const_cast<Type *>(T.getTypePtr()));
640 #include "clang/AST/TypeNodes.def"
646 template <typename Derived>
647 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
651 switch (TL.getTypeLocClass()) {
652 #define ABSTRACT_TYPELOC(CLASS, BASE)
653 #define TYPELOC(CLASS, BASE) \
654 case TypeLoc::CLASS: \
655 return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
656 #include "clang/AST/TypeLocNodes.def"
662 // Define the Traverse*Attr(Attr* A) methods
663 #define VISITORCLASS RecursiveASTVisitor
664 #include "clang/AST/AttrVisitor.inc"
667 template <typename Derived>
668 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
672 // As a syntax visitor, by default we want to ignore declarations for
673 // implicit declarations (ones not typed explicitly by the user).
674 if (!getDerived().shouldVisitImplicitCode() && D->isImplicit())
677 switch (D->getKind()) {
678 #define ABSTRACT_DECL(DECL)
679 #define DECL(CLASS, BASE) \
681 if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D))) \
684 #include "clang/AST/DeclNodes.inc"
687 // Visit any attributes attached to this declaration.
688 for (auto *I : D->attrs()) {
689 if (!getDerived().TraverseAttr(I))
697 template <typename Derived>
698 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
699 NestedNameSpecifier *NNS) {
703 if (NNS->getPrefix())
704 TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
706 switch (NNS->getKind()) {
707 case NestedNameSpecifier::Identifier:
708 case NestedNameSpecifier::Namespace:
709 case NestedNameSpecifier::NamespaceAlias:
710 case NestedNameSpecifier::Global:
711 case NestedNameSpecifier::Super:
714 case NestedNameSpecifier::TypeSpec:
715 case NestedNameSpecifier::TypeSpecWithTemplate:
716 TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
722 template <typename Derived>
723 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
724 NestedNameSpecifierLoc NNS) {
728 if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
729 TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
731 switch (NNS.getNestedNameSpecifier()->getKind()) {
732 case NestedNameSpecifier::Identifier:
733 case NestedNameSpecifier::Namespace:
734 case NestedNameSpecifier::NamespaceAlias:
735 case NestedNameSpecifier::Global:
736 case NestedNameSpecifier::Super:
739 case NestedNameSpecifier::TypeSpec:
740 case NestedNameSpecifier::TypeSpecWithTemplate:
741 TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
748 template <typename Derived>
749 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
750 DeclarationNameInfo NameInfo) {
751 switch (NameInfo.getName().getNameKind()) {
752 case DeclarationName::CXXConstructorName:
753 case DeclarationName::CXXDestructorName:
754 case DeclarationName::CXXConversionFunctionName:
755 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
756 TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
760 case DeclarationName::Identifier:
761 case DeclarationName::ObjCZeroArgSelector:
762 case DeclarationName::ObjCOneArgSelector:
763 case DeclarationName::ObjCMultiArgSelector:
764 case DeclarationName::CXXOperatorName:
765 case DeclarationName::CXXLiteralOperatorName:
766 case DeclarationName::CXXUsingDirective:
773 template <typename Derived>
774 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
775 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
776 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
777 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
778 TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
783 template <typename Derived>
784 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
785 const TemplateArgument &Arg) {
786 switch (Arg.getKind()) {
787 case TemplateArgument::Null:
788 case TemplateArgument::Declaration:
789 case TemplateArgument::Integral:
790 case TemplateArgument::NullPtr:
793 case TemplateArgument::Type:
794 return getDerived().TraverseType(Arg.getAsType());
796 case TemplateArgument::Template:
797 case TemplateArgument::TemplateExpansion:
798 return getDerived().TraverseTemplateName(
799 Arg.getAsTemplateOrTemplatePattern());
801 case TemplateArgument::Expression:
802 return getDerived().TraverseStmt(Arg.getAsExpr());
804 case TemplateArgument::Pack:
805 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
812 // FIXME: no template name location?
813 // FIXME: no source locations for a template argument pack?
814 template <typename Derived>
815 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
816 const TemplateArgumentLoc &ArgLoc) {
817 const TemplateArgument &Arg = ArgLoc.getArgument();
819 switch (Arg.getKind()) {
820 case TemplateArgument::Null:
821 case TemplateArgument::Declaration:
822 case TemplateArgument::Integral:
823 case TemplateArgument::NullPtr:
826 case TemplateArgument::Type: {
827 // FIXME: how can TSI ever be NULL?
828 if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
829 return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
831 return getDerived().TraverseType(Arg.getAsType());
834 case TemplateArgument::Template:
835 case TemplateArgument::TemplateExpansion:
836 if (ArgLoc.getTemplateQualifierLoc())
837 TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
838 ArgLoc.getTemplateQualifierLoc()));
839 return getDerived().TraverseTemplateName(
840 Arg.getAsTemplateOrTemplatePattern());
842 case TemplateArgument::Expression:
843 return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
845 case TemplateArgument::Pack:
846 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
853 template <typename Derived>
854 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
855 const TemplateArgument *Args, unsigned NumArgs) {
856 for (unsigned I = 0; I != NumArgs; ++I) {
857 TRY_TO(TraverseTemplateArgument(Args[I]));
863 template <typename Derived>
864 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
865 CXXCtorInitializer *Init) {
866 if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
867 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
869 if (Init->isWritten() || getDerived().shouldVisitImplicitCode())
870 TRY_TO(TraverseStmt(Init->getInit()));
872 if (getDerived().shouldVisitImplicitCode())
873 // The braces for this one-line loop are required for MSVC2013. It
874 // refuses to compile
875 // for (int i : int_vec)
876 // do {} while(false);
877 // without braces on the for loop.
878 for (VarDecl *VD : Init->getArrayIndices()) {
879 TRY_TO(TraverseDecl(VD));
885 template <typename Derived>
887 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
888 const LambdaCapture *C) {
889 if (LE->isInitCapture(C))
890 TRY_TO(TraverseDecl(C->getCapturedVar()));
894 template <typename Derived>
895 bool RecursiveASTVisitor<Derived>::TraverseLambdaBody(
896 LambdaExpr *LE, DataRecursionQueue *Queue) {
897 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(LE->getBody());
901 // ----------------- Type traversal -----------------
903 // This macro makes available a variable T, the passed-in type.
904 #define DEF_TRAVERSE_TYPE(TYPE, CODE) \
905 template <typename Derived> \
906 bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) { \
907 if (!getDerived().shouldTraversePostOrder()) \
908 TRY_TO(WalkUpFrom##TYPE(T)); \
910 if (getDerived().shouldTraversePostOrder()) \
911 TRY_TO(WalkUpFrom##TYPE(T)); \
915 DEF_TRAVERSE_TYPE(BuiltinType, {})
917 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
919 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
921 DEF_TRAVERSE_TYPE(BlockPointerType,
922 { TRY_TO(TraverseType(T->getPointeeType())); })
924 DEF_TRAVERSE_TYPE(LValueReferenceType,
925 { TRY_TO(TraverseType(T->getPointeeType())); })
927 DEF_TRAVERSE_TYPE(RValueReferenceType,
928 { TRY_TO(TraverseType(T->getPointeeType())); })
930 DEF_TRAVERSE_TYPE(MemberPointerType, {
931 TRY_TO(TraverseType(QualType(T->getClass(), 0)));
932 TRY_TO(TraverseType(T->getPointeeType()));
935 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
937 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
939 DEF_TRAVERSE_TYPE(ConstantArrayType,
940 { TRY_TO(TraverseType(T->getElementType())); })
942 DEF_TRAVERSE_TYPE(IncompleteArrayType,
943 { TRY_TO(TraverseType(T->getElementType())); })
945 DEF_TRAVERSE_TYPE(VariableArrayType, {
946 TRY_TO(TraverseType(T->getElementType()));
947 TRY_TO(TraverseStmt(T->getSizeExpr()));
950 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
951 TRY_TO(TraverseType(T->getElementType()));
952 if (T->getSizeExpr())
953 TRY_TO(TraverseStmt(T->getSizeExpr()));
956 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
957 if (T->getSizeExpr())
958 TRY_TO(TraverseStmt(T->getSizeExpr()));
959 TRY_TO(TraverseType(T->getElementType()));
962 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
964 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
966 DEF_TRAVERSE_TYPE(FunctionNoProtoType,
967 { TRY_TO(TraverseType(T->getReturnType())); })
969 DEF_TRAVERSE_TYPE(FunctionProtoType, {
970 TRY_TO(TraverseType(T->getReturnType()));
972 for (const auto &A : T->param_types()) {
973 TRY_TO(TraverseType(A));
976 for (const auto &E : T->exceptions()) {
977 TRY_TO(TraverseType(E));
980 if (Expr *NE = T->getNoexceptExpr())
981 TRY_TO(TraverseStmt(NE));
984 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
985 DEF_TRAVERSE_TYPE(TypedefType, {})
987 DEF_TRAVERSE_TYPE(TypeOfExprType,
988 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
990 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
992 DEF_TRAVERSE_TYPE(DecltypeType,
993 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
995 DEF_TRAVERSE_TYPE(UnaryTransformType, {
996 TRY_TO(TraverseType(T->getBaseType()));
997 TRY_TO(TraverseType(T->getUnderlyingType()));
1000 DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
1002 DEF_TRAVERSE_TYPE(RecordType, {})
1003 DEF_TRAVERSE_TYPE(EnumType, {})
1004 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
1005 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {})
1006 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {})
1008 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
1009 TRY_TO(TraverseTemplateName(T->getTemplateName()));
1010 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1013 DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
1015 DEF_TRAVERSE_TYPE(AttributedType,
1016 { TRY_TO(TraverseType(T->getModifiedType())); })
1018 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
1020 DEF_TRAVERSE_TYPE(ElaboratedType, {
1021 if (T->getQualifier()) {
1022 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1024 TRY_TO(TraverseType(T->getNamedType()));
1027 DEF_TRAVERSE_TYPE(DependentNameType,
1028 { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
1030 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
1031 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
1032 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
1035 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
1037 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
1039 DEF_TRAVERSE_TYPE(ObjCObjectType, {
1040 // We have to watch out here because an ObjCInterfaceType's base
1042 if (T->getBaseType().getTypePtr() != T)
1043 TRY_TO(TraverseType(T->getBaseType()));
1044 for (auto typeArg : T->getTypeArgsAsWritten()) {
1045 TRY_TO(TraverseType(typeArg));
1049 DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
1050 { TRY_TO(TraverseType(T->getPointeeType())); })
1052 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
1054 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); })
1056 #undef DEF_TRAVERSE_TYPE
1058 // ----------------- TypeLoc traversal -----------------
1060 // This macro makes available a variable TL, the passed-in TypeLoc.
1061 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
1062 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
1063 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
1064 // continue to work.
1065 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \
1066 template <typename Derived> \
1067 bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
1068 if (getDerived().shouldWalkTypesOfTypeLocs()) \
1069 TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \
1070 TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
1075 template <typename Derived>
1077 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
1078 // Move this over to the 'main' typeloc tree. Note that this is a
1079 // move -- we pretend that we were really looking at the unqualified
1080 // typeloc all along -- rather than a recursion, so we don't follow
1081 // the normal CRTP plan of going through
1082 // getDerived().TraverseTypeLoc. If we did, we'd be traversing
1083 // twice for the same type (once as a QualifiedTypeLoc version of
1084 // the type, once as an UnqualifiedTypeLoc version of the type),
1085 // which in effect means we'd call VisitTypeLoc twice with the
1086 // 'same' type. This solves that problem, at the cost of never
1087 // seeing the qualified version of the type (unless the client
1088 // subclasses TraverseQualifiedTypeLoc themselves). It's not a
1089 // perfect solution. A perfect solution probably requires making
1090 // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
1091 // wrapper around Type* -- rather than being its own class in the
1093 return TraverseTypeLoc(TL.getUnqualifiedLoc());
1096 DEF_TRAVERSE_TYPELOC(BuiltinType, {})
1098 // FIXME: ComplexTypeLoc is unfinished
1099 DEF_TRAVERSE_TYPELOC(ComplexType, {
1100 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1103 DEF_TRAVERSE_TYPELOC(PointerType,
1104 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1106 DEF_TRAVERSE_TYPELOC(BlockPointerType,
1107 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1109 DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1110 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1112 DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1113 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1115 // FIXME: location of base class?
1116 // We traverse this in the type case as well, but how is it not reached through
1117 // the pointee type?
1118 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1119 TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1120 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1123 DEF_TRAVERSE_TYPELOC(AdjustedType,
1124 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1126 DEF_TRAVERSE_TYPELOC(DecayedType,
1127 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1129 template <typename Derived>
1130 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
1131 // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1132 TRY_TO(TraverseStmt(TL.getSizeExpr()));
1136 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1137 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1138 return TraverseArrayTypeLocHelper(TL);
1141 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1142 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1143 return TraverseArrayTypeLocHelper(TL);
1146 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1147 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1148 return TraverseArrayTypeLocHelper(TL);
1151 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1152 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1153 return TraverseArrayTypeLocHelper(TL);
1156 // FIXME: order? why not size expr first?
1157 // FIXME: base VectorTypeLoc is unfinished
1158 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1159 if (TL.getTypePtr()->getSizeExpr())
1160 TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1161 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1164 // FIXME: VectorTypeLoc is unfinished
1165 DEF_TRAVERSE_TYPELOC(VectorType, {
1166 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1169 // FIXME: size and attributes
1170 // FIXME: base VectorTypeLoc is unfinished
1171 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1172 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1175 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1176 { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
1178 // FIXME: location of exception specifications (attributes?)
1179 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1180 TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
1182 const FunctionProtoType *T = TL.getTypePtr();
1184 for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1185 if (TL.getParam(I)) {
1186 TRY_TO(TraverseDecl(TL.getParam(I)));
1187 } else if (I < T->getNumParams()) {
1188 TRY_TO(TraverseType(T->getParamType(I)));
1192 for (const auto &E : T->exceptions()) {
1193 TRY_TO(TraverseType(E));
1196 if (Expr *NE = T->getNoexceptExpr())
1197 TRY_TO(TraverseStmt(NE));
1200 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1201 DEF_TRAVERSE_TYPELOC(TypedefType, {})
1203 DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1204 { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
1206 DEF_TRAVERSE_TYPELOC(TypeOfType, {
1207 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1210 // FIXME: location of underlying expr
1211 DEF_TRAVERSE_TYPELOC(DecltypeType, {
1212 TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1215 DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1216 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1219 DEF_TRAVERSE_TYPELOC(AutoType, {
1220 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1223 DEF_TRAVERSE_TYPELOC(RecordType, {})
1224 DEF_TRAVERSE_TYPELOC(EnumType, {})
1225 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1226 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {})
1227 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {})
1229 // FIXME: use the loc for the template name?
1230 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1231 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1232 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1233 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1237 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
1239 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1241 DEF_TRAVERSE_TYPELOC(AttributedType,
1242 { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
1244 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1245 if (TL.getQualifierLoc()) {
1246 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1248 TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1251 DEF_TRAVERSE_TYPELOC(DependentNameType, {
1252 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1255 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1256 if (TL.getQualifierLoc()) {
1257 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1260 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1261 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1265 DEF_TRAVERSE_TYPELOC(PackExpansionType,
1266 { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
1268 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
1270 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1271 // We have to watch out here because an ObjCInterfaceType's base
1273 if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1274 TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1275 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
1276 TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc()));
1279 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1280 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1282 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1284 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1286 #undef DEF_TRAVERSE_TYPELOC
1288 // ----------------- Decl traversal -----------------
1290 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1291 // the children that come from the DeclContext associated with it.
1292 // Therefore each Traverse* only needs to worry about children other
1295 template <typename Derived>
1296 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1300 for (auto *Child : DC->decls()) {
1301 // BlockDecls and CapturedDecls are traversed through BlockExprs and
1302 // CapturedStmts respectively.
1303 if (!isa<BlockDecl>(Child) && !isa<CapturedDecl>(Child))
1304 TRY_TO(TraverseDecl(Child));
1310 // This macro makes available a variable D, the passed-in decl.
1311 #define DEF_TRAVERSE_DECL(DECL, CODE) \
1312 template <typename Derived> \
1313 bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) { \
1314 bool ShouldVisitChildren = true; \
1315 bool ReturnValue = true; \
1316 if (!getDerived().shouldTraversePostOrder()) \
1317 TRY_TO(WalkUpFrom##DECL(D)); \
1319 if (ReturnValue && ShouldVisitChildren) \
1320 TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \
1321 if (ReturnValue && getDerived().shouldTraversePostOrder()) \
1322 TRY_TO(WalkUpFrom##DECL(D)); \
1323 return ReturnValue; \
1326 DEF_TRAVERSE_DECL(AccessSpecDecl, {})
1328 DEF_TRAVERSE_DECL(BlockDecl, {
1329 if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1330 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1331 TRY_TO(TraverseStmt(D->getBody()));
1332 for (const auto &I : D->captures()) {
1333 if (I.hasCopyExpr()) {
1334 TRY_TO(TraverseStmt(I.getCopyExpr()));
1337 ShouldVisitChildren = false;
1340 DEF_TRAVERSE_DECL(CapturedDecl, {
1341 TRY_TO(TraverseStmt(D->getBody()));
1342 ShouldVisitChildren = false;
1345 DEF_TRAVERSE_DECL(EmptyDecl, {})
1347 DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1348 { TRY_TO(TraverseStmt(D->getAsmString())); })
1350 DEF_TRAVERSE_DECL(ImportDecl, {})
1352 DEF_TRAVERSE_DECL(FriendDecl, {
1353 // Friend is either decl or a type.
1354 if (D->getFriendType())
1355 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1357 TRY_TO(TraverseDecl(D->getFriendDecl()));
1360 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1361 if (D->getFriendType())
1362 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1364 TRY_TO(TraverseDecl(D->getFriendDecl()));
1365 for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1366 TemplateParameterList *TPL = D->getTemplateParameterList(I);
1367 for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1368 ITPL != ETPL; ++ITPL) {
1369 TRY_TO(TraverseDecl(*ITPL));
1374 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, {
1375 TRY_TO(TraverseDecl(D->getSpecialization()));
1377 if (D->hasExplicitTemplateArgs()) {
1378 const TemplateArgumentListInfo &args = D->templateArgs();
1379 TRY_TO(TraverseTemplateArgumentLocsHelper(args.getArgumentArray(),
1384 DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1386 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1389 DEF_TRAVERSE_DECL(StaticAssertDecl, {
1390 TRY_TO(TraverseStmt(D->getAssertExpr()));
1391 TRY_TO(TraverseStmt(D->getMessage()));
1395 TranslationUnitDecl,
1396 {// Code in an unnamed namespace shows up automatically in
1397 // decls_begin()/decls_end(). Thus we don't need to recurse on
1398 // D->getAnonymousNamespace().
1401 DEF_TRAVERSE_DECL(PragmaCommentDecl, {})
1403 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {})
1405 DEF_TRAVERSE_DECL(ExternCContextDecl, {})
1407 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1408 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1410 // We shouldn't traverse an aliased namespace, since it will be
1411 // defined (and, therefore, traversed) somewhere else.
1412 ShouldVisitChildren = false;
1415 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1420 {// Code in an unnamed namespace shows up automatically in
1421 // decls_begin()/decls_end(). Thus we don't need to recurse on
1422 // D->getAnonymousNamespace().
1425 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1428 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
1429 if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) {
1430 for (auto typeParam : *typeParamList) {
1431 TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1436 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1439 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1442 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
1443 if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {
1444 for (auto typeParam : *typeParamList) {
1445 TRY_TO(TraverseObjCTypeParamDecl(typeParam));
1449 if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) {
1450 TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc()));
1454 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
1457 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1458 if (D->getReturnTypeSourceInfo()) {
1459 TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1461 for (ParmVarDecl *Parameter : D->parameters()) {
1462 TRY_TO(TraverseDecl(Parameter));
1464 if (D->isThisDeclarationADefinition()) {
1465 TRY_TO(TraverseStmt(D->getBody()));
1467 ShouldVisitChildren = false;
1470 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, {
1471 if (D->hasExplicitBound()) {
1472 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1473 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1474 // declaring the type alias, not something that was written in the
1479 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1480 if (D->getTypeSourceInfo())
1481 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1483 TRY_TO(TraverseType(D->getType()));
1484 ShouldVisitChildren = false;
1487 DEF_TRAVERSE_DECL(UsingDecl, {
1488 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1489 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1492 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1493 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1496 DEF_TRAVERSE_DECL(UsingShadowDecl, {})
1498 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {})
1500 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
1501 for (auto *I : D->varlists()) {
1502 TRY_TO(TraverseStmt(I));
1506 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, {
1507 TRY_TO(TraverseStmt(D->getCombiner()));
1508 if (auto *Initializer = D->getInitializer())
1509 TRY_TO(TraverseStmt(Initializer));
1510 TRY_TO(TraverseType(D->getType()));
1514 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
1516 // A helper method for TemplateDecl's children.
1517 template <typename Derived>
1518 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1519 TemplateParameterList *TPL) {
1521 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1523 TRY_TO(TraverseDecl(*I));
1529 template <typename Derived>
1530 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1531 ClassTemplateDecl *D) {
1532 for (auto *SD : D->specializations()) {
1533 for (auto *RD : SD->redecls()) {
1534 // We don't want to visit injected-class-names in this traversal.
1535 if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
1539 cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1540 // Visit the implicit instantiations with the requested pattern.
1541 case TSK_Undeclared:
1542 case TSK_ImplicitInstantiation:
1543 TRY_TO(TraverseDecl(RD));
1546 // We don't need to do anything on an explicit instantiation
1547 // or explicit specialization because there will be an explicit
1548 // node for it elsewhere.
1549 case TSK_ExplicitInstantiationDeclaration:
1550 case TSK_ExplicitInstantiationDefinition:
1551 case TSK_ExplicitSpecialization:
1560 template <typename Derived>
1561 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1562 VarTemplateDecl *D) {
1563 for (auto *SD : D->specializations()) {
1564 for (auto *RD : SD->redecls()) {
1566 cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1567 case TSK_Undeclared:
1568 case TSK_ImplicitInstantiation:
1569 TRY_TO(TraverseDecl(RD));
1572 case TSK_ExplicitInstantiationDeclaration:
1573 case TSK_ExplicitInstantiationDefinition:
1574 case TSK_ExplicitSpecialization:
1583 // A helper method for traversing the instantiations of a
1584 // function while skipping its specializations.
1585 template <typename Derived>
1586 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations(
1587 FunctionTemplateDecl *D) {
1588 for (auto *FD : D->specializations()) {
1589 for (auto *RD : FD->redecls()) {
1590 switch (RD->getTemplateSpecializationKind()) {
1591 case TSK_Undeclared:
1592 case TSK_ImplicitInstantiation:
1593 // We don't know what kind of FunctionDecl this is.
1594 TRY_TO(TraverseDecl(RD));
1597 // FIXME: For now traverse explicit instantiations here. Change that
1598 // once they are represented as dedicated nodes in the AST.
1599 case TSK_ExplicitInstantiationDeclaration:
1600 case TSK_ExplicitInstantiationDefinition:
1601 TRY_TO(TraverseDecl(RD));
1604 case TSK_ExplicitSpecialization:
1613 // This macro unifies the traversal of class, variable and function
1614 // template declarations.
1615 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND) \
1616 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, { \
1617 TRY_TO(TraverseDecl(D->getTemplatedDecl())); \
1618 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \
1620 /* By default, we do not traverse the instantiations of \
1621 class templates since they do not appear in the user code. The \
1622 following code optionally traverses them. \
1624 We only traverse the class instantiations when we see the canonical \
1625 declaration of the template, to ensure we only visit them once. */ \
1626 if (getDerived().shouldVisitTemplateInstantiations() && \
1627 D == D->getCanonicalDecl()) \
1628 TRY_TO(TraverseTemplateInstantiations(D)); \
1630 /* Note that getInstantiatedFromMemberTemplate() is just a link \
1631 from a template instantiation back to the template from which \
1632 it was instantiated, and thus should not be traversed. */ \
1635 DEF_TRAVERSE_TMPL_DECL(Class)
1636 DEF_TRAVERSE_TMPL_DECL(Var)
1637 DEF_TRAVERSE_TMPL_DECL(Function)
1639 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1640 // D is the "T" in something like
1641 // template <template <typename> class T> class container { };
1642 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1643 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
1644 TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1646 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1649 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
1650 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1653 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1654 // D is the "T" in something like "template<typename T> class vector;"
1655 if (D->getTypeForDecl())
1656 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1657 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1658 TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1661 DEF_TRAVERSE_DECL(TypedefDecl, {
1662 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1663 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1664 // declaring the typedef, not something that was written in the
1668 DEF_TRAVERSE_DECL(TypeAliasDecl, {
1669 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1670 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1671 // declaring the type alias, not something that was written in the
1675 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
1676 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1677 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1680 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1681 // A dependent using declaration which was marked with 'typename'.
1682 // template<class T> class A : public B<T> { using typename B<T>::foo; };
1683 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1684 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1685 // declaring the type, not something that was written in the
1689 DEF_TRAVERSE_DECL(EnumDecl, {
1690 if (D->getTypeForDecl())
1691 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1693 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1694 // The enumerators are already traversed by
1695 // decls_begin()/decls_end().
1698 // Helper methods for RecordDecl and its children.
1699 template <typename Derived>
1700 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
1701 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1702 // declaring the type, not something that was written in the source.
1704 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1708 template <typename Derived>
1709 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
1710 if (!TraverseRecordHelper(D))
1712 if (D->isCompleteDefinition()) {
1713 for (const auto &I : D->bases()) {
1714 TRY_TO(TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc()));
1716 // We don't traverse the friends or the conversions, as they are
1717 // already in decls_begin()/decls_end().
1722 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
1724 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
1726 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND) \
1727 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, { \
1728 /* For implicit instantiations ("set<int> x;"), we don't want to \
1729 recurse at all, since the instatiated template isn't written in \
1730 the source code anywhere. (Note the instatiated *type* -- \
1731 set<int> -- is written, and will still get a callback of \
1732 TemplateSpecializationType). For explicit instantiations \
1733 ("template set<int>;"), we do need a callback, since this \
1734 is the only callback that's made for this instantiation. \
1735 We use getTypeAsWritten() to distinguish. */ \
1736 if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \
1737 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \
1739 if (!getDerived().shouldVisitTemplateInstantiations() && \
1740 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) \
1741 /* Returning from here skips traversing the \
1742 declaration context of the *TemplateSpecializationDecl \
1743 (embedded in the DEF_TRAVERSE_DECL() macro) \
1744 which contains the instantiated members of the template. */ \
1748 DEF_TRAVERSE_TMPL_SPEC_DECL(Class)
1749 DEF_TRAVERSE_TMPL_SPEC_DECL(Var)
1751 template <typename Derived>
1752 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1753 const TemplateArgumentLoc *TAL, unsigned Count) {
1754 for (unsigned I = 0; I < Count; ++I) {
1755 TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1760 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND) \
1761 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, { \
1762 /* The partial specialization. */ \
1763 if (TemplateParameterList *TPL = D->getTemplateParameters()) { \
1764 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); \
1766 TRY_TO(TraverseDecl(*I)); \
1769 /* The args that remains unspecialized. */ \
1770 TRY_TO(TraverseTemplateArgumentLocsHelper( \
1771 D->getTemplateArgsAsWritten()->getTemplateArgs(), \
1772 D->getTemplateArgsAsWritten()->NumTemplateArgs)); \
1774 /* Don't need the *TemplatePartialSpecializationHelper, even \
1775 though that's our parent class -- we already visit all the \
1776 template args here. */ \
1777 TRY_TO(Traverse##DECLKIND##Helper(D)); \
1779 /* Instantiations will have been visited with the primary template. */ \
1782 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord)
1783 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var)
1785 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
1787 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1788 // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1789 // template <class T> Class A : public Base<T> { using Base<T>::foo; };
1790 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1791 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1794 DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1796 template <typename Derived>
1797 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1798 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1799 if (D->getTypeSourceInfo())
1800 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1802 TRY_TO(TraverseType(D->getType()));
1806 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
1808 DEF_TRAVERSE_DECL(FieldDecl, {
1809 TRY_TO(TraverseDeclaratorHelper(D));
1810 if (D->isBitField())
1811 TRY_TO(TraverseStmt(D->getBitWidth()));
1812 else if (D->hasInClassInitializer())
1813 TRY_TO(TraverseStmt(D->getInClassInitializer()));
1816 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1817 TRY_TO(TraverseDeclaratorHelper(D));
1818 if (D->isBitField())
1819 TRY_TO(TraverseStmt(D->getBitWidth()));
1820 // FIXME: implement the rest.
1823 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1824 TRY_TO(TraverseDeclaratorHelper(D));
1825 if (D->isBitField())
1826 TRY_TO(TraverseStmt(D->getBitWidth()));
1827 // FIXME: implement the rest.
1830 template <typename Derived>
1831 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1832 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1833 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1835 // If we're an explicit template specialization, iterate over the
1836 // template args that were explicitly specified. If we were doing
1837 // this in typing order, we'd do it between the return type and
1838 // the function args, but both are handled by the FunctionTypeLoc
1839 // above, so we have to choose one side. I've decided to do before.
1840 if (const FunctionTemplateSpecializationInfo *FTSI =
1841 D->getTemplateSpecializationInfo()) {
1842 if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1843 FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1844 // A specialization might not have explicit template arguments if it has
1845 // a templated return type and concrete arguments.
1846 if (const ASTTemplateArgumentListInfo *TALI =
1847 FTSI->TemplateArgumentsAsWritten) {
1848 TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1849 TALI->NumTemplateArgs));
1854 // Visit the function type itself, which can be either
1855 // FunctionNoProtoType or FunctionProtoType, or a typedef. This
1856 // also covers the return type and the function parameters,
1857 // including exception specifications.
1858 if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) {
1859 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1860 } else if (getDerived().shouldVisitImplicitCode()) {
1861 // Visit parameter variable declarations of the implicit function
1862 // if the traverser is visiting implicit code. Parameter variable
1863 // declarations do not have valid TypeSourceInfo, so to visit them
1864 // we need to traverse the declarations explicitly.
1865 for (ParmVarDecl *Parameter : D->parameters()) {
1866 TRY_TO(TraverseDecl(Parameter));
1870 if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1871 // Constructor initializers.
1872 for (auto *I : Ctor->inits()) {
1873 TRY_TO(TraverseConstructorInitializer(I));
1877 if (D->isThisDeclarationADefinition()) {
1878 TRY_TO(TraverseStmt(D->getBody())); // Function body.
1883 DEF_TRAVERSE_DECL(FunctionDecl, {
1884 // We skip decls_begin/decls_end, which are already covered by
1885 // TraverseFunctionHelper().
1886 ShouldVisitChildren = false;
1887 ReturnValue = TraverseFunctionHelper(D);
1890 DEF_TRAVERSE_DECL(CXXMethodDecl, {
1891 // We skip decls_begin/decls_end, which are already covered by
1892 // TraverseFunctionHelper().
1893 ShouldVisitChildren = false;
1894 ReturnValue = TraverseFunctionHelper(D);
1897 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
1898 // We skip decls_begin/decls_end, which are already covered by
1899 // TraverseFunctionHelper().
1900 ShouldVisitChildren = false;
1901 ReturnValue = TraverseFunctionHelper(D);
1904 // CXXConversionDecl is the declaration of a type conversion operator.
1905 // It's not a cast expression.
1906 DEF_TRAVERSE_DECL(CXXConversionDecl, {
1907 // We skip decls_begin/decls_end, which are already covered by
1908 // TraverseFunctionHelper().
1909 ShouldVisitChildren = false;
1910 ReturnValue = TraverseFunctionHelper(D);
1913 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
1914 // We skip decls_begin/decls_end, which are already covered by
1915 // TraverseFunctionHelper().
1916 ShouldVisitChildren = false;
1917 ReturnValue = TraverseFunctionHelper(D);
1920 template <typename Derived>
1921 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
1922 TRY_TO(TraverseDeclaratorHelper(D));
1923 // Default params are taken care of when we traverse the ParmVarDecl.
1924 if (!isa<ParmVarDecl>(D) &&
1925 (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode()))
1926 TRY_TO(TraverseStmt(D->getInit()));
1930 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
1932 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
1934 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
1935 // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
1936 TRY_TO(TraverseDeclaratorHelper(D));
1937 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
1938 TRY_TO(TraverseStmt(D->getDefaultArgument()));
1941 DEF_TRAVERSE_DECL(ParmVarDecl, {
1942 TRY_TO(TraverseVarHelper(D));
1944 if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
1945 !D->hasUnparsedDefaultArg())
1946 TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
1948 if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
1949 !D->hasUnparsedDefaultArg())
1950 TRY_TO(TraverseStmt(D->getDefaultArg()));
1953 #undef DEF_TRAVERSE_DECL
1955 // ----------------- Stmt traversal -----------------
1957 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
1958 // over the children defined in children() (every stmt defines these,
1959 // though sometimes the range is empty). Each individual Traverse*
1960 // method only needs to worry about children other than those. To see
1961 // what children() does for a given class, see, e.g.,
1962 // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
1964 // This macro makes available a variable S, the passed-in stmt.
1965 #define DEF_TRAVERSE_STMT(STMT, CODE) \
1966 template <typename Derived> \
1967 bool RecursiveASTVisitor<Derived>::Traverse##STMT( \
1968 STMT *S, DataRecursionQueue *Queue) { \
1969 bool ShouldVisitChildren = true; \
1970 bool ReturnValue = true; \
1971 if (!getDerived().shouldTraversePostOrder()) \
1972 TRY_TO(WalkUpFrom##STMT(S)); \
1974 if (ShouldVisitChildren) { \
1975 for (Stmt *SubStmt : S->children()) { \
1976 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt); \
1979 if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder()) \
1980 TRY_TO(WalkUpFrom##STMT(S)); \
1981 return ReturnValue; \
1984 DEF_TRAVERSE_STMT(GCCAsmStmt, {
1985 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
1986 for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
1987 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
1989 for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
1990 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
1992 for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
1993 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
1995 // children() iterates over inputExpr and outputExpr.
2000 {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc. Once
2001 // added this needs to be implemented.
2004 DEF_TRAVERSE_STMT(CXXCatchStmt, {
2005 TRY_TO(TraverseDecl(S->getExceptionDecl()));
2006 // children() iterates over the handler block.
2009 DEF_TRAVERSE_STMT(DeclStmt, {
2010 for (auto *I : S->decls()) {
2011 TRY_TO(TraverseDecl(I));
2013 // Suppress the default iteration over children() by
2014 // returning. Here's why: A DeclStmt looks like 'type var [=
2015 // initializer]'. The decls above already traverse over the
2016 // initializers, so we don't have to do it again (which
2017 // children() would do).
2018 ShouldVisitChildren = false;
2021 // These non-expr stmts (most of them), do not need any action except
2022 // iterating over the children.
2023 DEF_TRAVERSE_STMT(BreakStmt, {})
2024 DEF_TRAVERSE_STMT(CXXTryStmt, {})
2025 DEF_TRAVERSE_STMT(CaseStmt, {})
2026 DEF_TRAVERSE_STMT(CompoundStmt, {})
2027 DEF_TRAVERSE_STMT(ContinueStmt, {})
2028 DEF_TRAVERSE_STMT(DefaultStmt, {})
2029 DEF_TRAVERSE_STMT(DoStmt, {})
2030 DEF_TRAVERSE_STMT(ForStmt, {})
2031 DEF_TRAVERSE_STMT(GotoStmt, {})
2032 DEF_TRAVERSE_STMT(IfStmt, {})
2033 DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
2034 DEF_TRAVERSE_STMT(LabelStmt, {})
2035 DEF_TRAVERSE_STMT(AttributedStmt, {})
2036 DEF_TRAVERSE_STMT(NullStmt, {})
2037 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
2038 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
2039 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
2040 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
2041 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
2042 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
2043 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
2044 DEF_TRAVERSE_STMT(CXXForRangeStmt, {
2045 if (!getDerived().shouldVisitImplicitCode()) {
2046 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt());
2047 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit());
2048 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2049 // Visit everything else only if shouldVisitImplicitCode().
2050 ShouldVisitChildren = false;
2053 DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
2054 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2055 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2057 DEF_TRAVERSE_STMT(ReturnStmt, {})
2058 DEF_TRAVERSE_STMT(SwitchStmt, {})
2059 DEF_TRAVERSE_STMT(WhileStmt, {})
2061 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
2062 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2063 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2064 if (S->hasExplicitTemplateArgs()) {
2065 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2066 S->getNumTemplateArgs()));
2070 DEF_TRAVERSE_STMT(DeclRefExpr, {
2071 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2072 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2073 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2074 S->getNumTemplateArgs()));
2077 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
2078 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2079 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
2080 if (S->hasExplicitTemplateArgs()) {
2081 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2082 S->getNumTemplateArgs()));
2086 DEF_TRAVERSE_STMT(MemberExpr, {
2087 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2088 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
2089 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2090 S->getNumTemplateArgs()));
2095 {// We don't traverse the cast type, as it's not written in the
2099 DEF_TRAVERSE_STMT(CStyleCastExpr, {
2100 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2103 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
2104 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2107 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
2108 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2111 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
2112 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2115 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
2116 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2119 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
2120 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2123 template <typename Derived>
2124 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr(
2125 InitListExpr *S, DataRecursionQueue *Queue) {
2127 // Skip this if we traverse postorder. We will visit it later
2128 // in PostVisitStmt.
2129 if (!getDerived().shouldTraversePostOrder())
2130 TRY_TO(WalkUpFromInitListExpr(S));
2132 // All we need are the default actions. FIXME: use a helper function.
2133 for (Stmt *SubStmt : S->children()) {
2134 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt);
2140 // This method is called once for each pair of syntactic and semantic
2141 // InitListExpr, and it traverses the subtrees defined by the two forms. This
2142 // may cause some of the children to be visited twice, if they appear both in
2143 // the syntactic and the semantic form.
2145 // There is no guarantee about which form \p S takes when this method is called.
2146 DEF_TRAVERSE_STMT(InitListExpr, {
2147 TRY_TO(TraverseSynOrSemInitListExpr(
2148 S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
2149 TRY_TO(TraverseSynOrSemInitListExpr(
2150 S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
2151 ShouldVisitChildren = false;
2154 // GenericSelectionExpr is a special case because the types and expressions
2155 // are interleaved. We also need to watch out for null types (default
2156 // generic associations).
2157 DEF_TRAVERSE_STMT(GenericSelectionExpr, {
2158 TRY_TO(TraverseStmt(S->getControllingExpr()));
2159 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
2160 if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
2161 TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
2162 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAssocExpr(i));
2164 ShouldVisitChildren = false;
2167 // PseudoObjectExpr is a special case because of the weirdness with
2168 // syntactic expressions and opaque values.
2169 DEF_TRAVERSE_STMT(PseudoObjectExpr, {
2170 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm());
2171 for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2172 e = S->semantics_end();
2175 if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2176 sub = OVE->getSourceExpr();
2177 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub);
2179 ShouldVisitChildren = false;
2182 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
2183 // This is called for code like 'return T()' where T is a built-in
2184 // (i.e. non-class) type.
2185 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2188 DEF_TRAVERSE_STMT(CXXNewExpr, {
2189 // The child-iterator will pick up the other arguments.
2190 TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
2193 DEF_TRAVERSE_STMT(OffsetOfExpr, {
2194 // The child-iterator will pick up the expression representing
2196 // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2197 // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2198 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2201 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2202 // The child-iterator will pick up the arg if it's an expression,
2203 // but not if it's a type.
2204 if (S->isArgumentType())
2205 TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2208 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2209 // The child-iterator will pick up the arg if it's an expression,
2210 // but not if it's a type.
2211 if (S->isTypeOperand())
2212 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2215 DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2216 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2219 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {})
2221 DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2222 // The child-iterator will pick up the arg if it's an expression,
2223 // but not if it's a type.
2224 if (S->isTypeOperand())
2225 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2228 DEF_TRAVERSE_STMT(TypeTraitExpr, {
2229 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2230 TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2233 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2234 TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2237 DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2238 { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); })
2240 DEF_TRAVERSE_STMT(VAArgExpr, {
2241 // The child-iterator will pick up the expression argument.
2242 TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2245 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2246 // This is called for code like 'return T()' where T is a class type.
2247 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2250 // Walk only the visible parts of lambda expressions.
2251 DEF_TRAVERSE_STMT(LambdaExpr, {
2252 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
2253 CEnd = S->explicit_capture_end();
2255 TRY_TO(TraverseLambdaCapture(S, C));
2258 TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2259 FunctionProtoTypeLoc Proto = TL.castAs<FunctionProtoTypeLoc>();
2261 if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2262 // Visit the whole type.
2263 TRY_TO(TraverseTypeLoc(TL));
2265 if (S->hasExplicitParameters()) {
2266 // Visit parameters.
2267 for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
2268 TRY_TO(TraverseDecl(Proto.getParam(I)));
2270 } else if (S->hasExplicitResultType()) {
2271 TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
2274 auto *T = Proto.getTypePtr();
2275 for (const auto &E : T->exceptions()) {
2276 TRY_TO(TraverseType(E));
2279 if (Expr *NE = T->getNoexceptExpr())
2280 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE);
2283 ReturnValue = TRAVERSE_STMT_BASE(LambdaBody, LambdaExpr, S, Queue);
2284 ShouldVisitChildren = false;
2287 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2288 // This is called for code like 'T()', where T is a template argument.
2289 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2292 // These expressions all might take explicit template arguments.
2293 // We traverse those if so. FIXME: implement these.
2294 DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2295 DEF_TRAVERSE_STMT(CallExpr, {})
2296 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
2298 // These exprs (most of them), do not need any action except iterating
2299 // over the children.
2300 DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2301 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
2302 DEF_TRAVERSE_STMT(OMPArraySectionExpr, {})
2303 DEF_TRAVERSE_STMT(BlockExpr, {
2304 TRY_TO(TraverseDecl(S->getBlockDecl()));
2305 return true; // no child statements to loop through.
2307 DEF_TRAVERSE_STMT(ChooseExpr, {})
2308 DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2309 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2311 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2312 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2313 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
2314 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
2315 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2316 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2317 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})
2318 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2319 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
2320 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2321 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2322 if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2323 TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2324 if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2325 TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2327 DEF_TRAVERSE_STMT(CXXThisExpr, {})
2328 DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2329 DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2330 DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2331 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {})
2332 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2333 DEF_TRAVERSE_STMT(GNUNullExpr, {})
2334 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2335 DEF_TRAVERSE_STMT(NoInitExpr, {})
2336 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
2337 DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2338 if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2339 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2341 DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2342 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
2343 DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2344 if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2345 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2347 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
2348 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2349 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2350 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2351 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
2352 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2353 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2355 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {})
2356 DEF_TRAVERSE_STMT(ParenExpr, {})
2357 DEF_TRAVERSE_STMT(ParenListExpr, {})
2358 DEF_TRAVERSE_STMT(PredefinedExpr, {})
2359 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2360 DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2361 DEF_TRAVERSE_STMT(StmtExpr, {})
2362 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2363 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2364 if (S->hasExplicitTemplateArgs()) {
2365 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2366 S->getNumTemplateArgs()));
2370 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2371 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2372 if (S->hasExplicitTemplateArgs()) {
2373 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2374 S->getNumTemplateArgs()));
2378 DEF_TRAVERSE_STMT(SEHTryStmt, {})
2379 DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2380 DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
2381 DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
2382 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2384 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2385 DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
2386 DEF_TRAVERSE_STMT(TypoExpr, {})
2387 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
2389 // These operators (all of them) do not need any action except
2390 // iterating over the children.
2391 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2392 DEF_TRAVERSE_STMT(ConditionalOperator, {})
2393 DEF_TRAVERSE_STMT(UnaryOperator, {})
2394 DEF_TRAVERSE_STMT(BinaryOperator, {})
2395 DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2396 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2397 DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2398 DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2399 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2400 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2401 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2402 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
2403 DEF_TRAVERSE_STMT(CXXFoldExpr, {})
2404 DEF_TRAVERSE_STMT(AtomicExpr, {})
2406 // For coroutines expressions, traverse either the operand
2407 // as written or the implied calls, depending on what the
2408 // derived class requests.
2409 DEF_TRAVERSE_STMT(CoroutineBodyStmt, {
2410 if (!getDerived().shouldVisitImplicitCode()) {
2411 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody());
2412 ShouldVisitChildren = false;
2415 DEF_TRAVERSE_STMT(CoreturnStmt, {
2416 if (!getDerived().shouldVisitImplicitCode()) {
2417 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2418 ShouldVisitChildren = false;
2421 DEF_TRAVERSE_STMT(CoawaitExpr, {
2422 if (!getDerived().shouldVisitImplicitCode()) {
2423 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2424 ShouldVisitChildren = false;
2427 DEF_TRAVERSE_STMT(CoyieldExpr, {
2428 if (!getDerived().shouldVisitImplicitCode()) {
2429 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand());
2430 ShouldVisitChildren = false;
2434 // These literals (all of them) do not need any action.
2435 DEF_TRAVERSE_STMT(IntegerLiteral, {})
2436 DEF_TRAVERSE_STMT(CharacterLiteral, {})
2437 DEF_TRAVERSE_STMT(FloatingLiteral, {})
2438 DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
2439 DEF_TRAVERSE_STMT(StringLiteral, {})
2440 DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
2441 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
2442 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
2443 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
2445 // Traverse OpenCL: AsType, Convert.
2446 DEF_TRAVERSE_STMT(AsTypeExpr, {})
2448 // OpenMP directives.
2449 template <typename Derived>
2450 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
2451 OMPExecutableDirective *S) {
2452 for (auto *C : S->clauses()) {
2453 TRY_TO(TraverseOMPClause(C));
2458 template <typename Derived>
2460 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
2461 return TraverseOMPExecutableDirective(S);
2464 DEF_TRAVERSE_STMT(OMPParallelDirective,
2465 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2467 DEF_TRAVERSE_STMT(OMPSimdDirective,
2468 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2470 DEF_TRAVERSE_STMT(OMPForDirective,
2471 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2473 DEF_TRAVERSE_STMT(OMPForSimdDirective,
2474 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2476 DEF_TRAVERSE_STMT(OMPSectionsDirective,
2477 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2479 DEF_TRAVERSE_STMT(OMPSectionDirective,
2480 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2482 DEF_TRAVERSE_STMT(OMPSingleDirective,
2483 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2485 DEF_TRAVERSE_STMT(OMPMasterDirective,
2486 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2488 DEF_TRAVERSE_STMT(OMPCriticalDirective, {
2489 TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
2490 TRY_TO(TraverseOMPExecutableDirective(S));
2493 DEF_TRAVERSE_STMT(OMPParallelForDirective,
2494 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2496 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
2497 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2499 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
2500 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2502 DEF_TRAVERSE_STMT(OMPTaskDirective,
2503 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2505 DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
2506 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2508 DEF_TRAVERSE_STMT(OMPBarrierDirective,
2509 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2511 DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
2512 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2514 DEF_TRAVERSE_STMT(OMPTaskgroupDirective,
2515 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2517 DEF_TRAVERSE_STMT(OMPCancellationPointDirective,
2518 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2520 DEF_TRAVERSE_STMT(OMPCancelDirective,
2521 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2523 DEF_TRAVERSE_STMT(OMPFlushDirective,
2524 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2526 DEF_TRAVERSE_STMT(OMPOrderedDirective,
2527 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2529 DEF_TRAVERSE_STMT(OMPAtomicDirective,
2530 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2532 DEF_TRAVERSE_STMT(OMPTargetDirective,
2533 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2535 DEF_TRAVERSE_STMT(OMPTargetDataDirective,
2536 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2538 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective,
2539 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2541 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective,
2542 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2544 DEF_TRAVERSE_STMT(OMPTargetParallelDirective,
2545 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2547 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective,
2548 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2550 DEF_TRAVERSE_STMT(OMPTeamsDirective,
2551 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2553 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective,
2554 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2556 DEF_TRAVERSE_STMT(OMPTaskLoopDirective,
2557 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2559 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective,
2560 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2562 DEF_TRAVERSE_STMT(OMPDistributeDirective,
2563 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2565 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective,
2566 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2568 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective,
2569 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2571 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective,
2572 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2574 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective,
2575 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2578 template <typename Derived>
2579 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
2582 switch (C->getClauseKind()) {
2583 #define OPENMP_CLAUSE(Name, Class) \
2585 TRY_TO(Visit##Class(static_cast<Class *>(C))); \
2587 #include "clang/Basic/OpenMPKinds.def"
2588 case OMPC_threadprivate:
2596 template <typename Derived>
2597 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit(
2598 OMPClauseWithPreInit *Node) {
2599 TRY_TO(TraverseStmt(Node->getPreInitStmt()));
2603 template <typename Derived>
2604 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate(
2605 OMPClauseWithPostUpdate *Node) {
2606 TRY_TO(VisitOMPClauseWithPreInit(Node));
2607 TRY_TO(TraverseStmt(Node->getPostUpdateExpr()));
2611 template <typename Derived>
2612 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
2613 TRY_TO(TraverseStmt(C->getCondition()));
2617 template <typename Derived>
2618 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
2619 TRY_TO(TraverseStmt(C->getCondition()));
2623 template <typename Derived>
2625 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
2626 TRY_TO(TraverseStmt(C->getNumThreads()));
2630 template <typename Derived>
2631 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
2632 TRY_TO(TraverseStmt(C->getSafelen()));
2636 template <typename Derived>
2637 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) {
2638 TRY_TO(TraverseStmt(C->getSimdlen()));
2642 template <typename Derived>
2644 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
2645 TRY_TO(TraverseStmt(C->getNumForLoops()));
2649 template <typename Derived>
2650 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
2654 template <typename Derived>
2655 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
2659 template <typename Derived>
2661 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
2662 TRY_TO(VisitOMPClauseWithPreInit(C));
2663 TRY_TO(TraverseStmt(C->getChunkSize()));
2667 template <typename Derived>
2668 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) {
2669 TRY_TO(TraverseStmt(C->getNumForLoops()));
2673 template <typename Derived>
2674 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
2678 template <typename Derived>
2679 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
2683 template <typename Derived>
2685 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
2689 template <typename Derived>
2690 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
2694 template <typename Derived>
2695 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
2699 template <typename Derived>
2700 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
2704 template <typename Derived>
2705 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2709 template <typename Derived>
2710 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2714 template <typename Derived>
2715 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) {
2719 template <typename Derived>
2720 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) {
2724 template <typename Derived>
2725 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) {
2729 template <typename Derived>
2730 template <typename T>
2731 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
2732 for (auto *E : Node->varlists()) {
2733 TRY_TO(TraverseStmt(E));
2738 template <typename Derived>
2739 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
2740 TRY_TO(VisitOMPClauseList(C));
2741 for (auto *E : C->private_copies()) {
2742 TRY_TO(TraverseStmt(E));
2747 template <typename Derived>
2748 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
2749 OMPFirstprivateClause *C) {
2750 TRY_TO(VisitOMPClauseList(C));
2751 TRY_TO(VisitOMPClauseWithPreInit(C));
2752 for (auto *E : C->private_copies()) {
2753 TRY_TO(TraverseStmt(E));
2755 for (auto *E : C->inits()) {
2756 TRY_TO(TraverseStmt(E));
2761 template <typename Derived>
2762 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
2763 OMPLastprivateClause *C) {
2764 TRY_TO(VisitOMPClauseList(C));
2765 TRY_TO(VisitOMPClauseWithPostUpdate(C));
2766 for (auto *E : C->private_copies()) {
2767 TRY_TO(TraverseStmt(E));
2769 for (auto *E : C->source_exprs()) {
2770 TRY_TO(TraverseStmt(E));
2772 for (auto *E : C->destination_exprs()) {
2773 TRY_TO(TraverseStmt(E));
2775 for (auto *E : C->assignment_ops()) {
2776 TRY_TO(TraverseStmt(E));
2781 template <typename Derived>
2782 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
2783 TRY_TO(VisitOMPClauseList(C));
2787 template <typename Derived>
2788 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2789 TRY_TO(TraverseStmt(C->getStep()));
2790 TRY_TO(TraverseStmt(C->getCalcStep()));
2791 TRY_TO(VisitOMPClauseList(C));
2792 TRY_TO(VisitOMPClauseWithPostUpdate(C));
2793 for (auto *E : C->privates()) {
2794 TRY_TO(TraverseStmt(E));
2796 for (auto *E : C->inits()) {
2797 TRY_TO(TraverseStmt(E));
2799 for (auto *E : C->updates()) {
2800 TRY_TO(TraverseStmt(E));
2802 for (auto *E : C->finals()) {
2803 TRY_TO(TraverseStmt(E));
2808 template <typename Derived>
2809 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
2810 TRY_TO(TraverseStmt(C->getAlignment()));
2811 TRY_TO(VisitOMPClauseList(C));
2815 template <typename Derived>
2816 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
2817 TRY_TO(VisitOMPClauseList(C));
2818 for (auto *E : C->source_exprs()) {
2819 TRY_TO(TraverseStmt(E));
2821 for (auto *E : C->destination_exprs()) {
2822 TRY_TO(TraverseStmt(E));
2824 for (auto *E : C->assignment_ops()) {
2825 TRY_TO(TraverseStmt(E));
2830 template <typename Derived>
2831 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
2832 OMPCopyprivateClause *C) {
2833 TRY_TO(VisitOMPClauseList(C));
2834 for (auto *E : C->source_exprs()) {
2835 TRY_TO(TraverseStmt(E));
2837 for (auto *E : C->destination_exprs()) {
2838 TRY_TO(TraverseStmt(E));
2840 for (auto *E : C->assignment_ops()) {
2841 TRY_TO(TraverseStmt(E));
2846 template <typename Derived>
2848 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
2849 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
2850 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
2851 TRY_TO(VisitOMPClauseList(C));
2852 TRY_TO(VisitOMPClauseWithPostUpdate(C));
2853 for (auto *E : C->privates()) {
2854 TRY_TO(TraverseStmt(E));
2856 for (auto *E : C->lhs_exprs()) {
2857 TRY_TO(TraverseStmt(E));
2859 for (auto *E : C->rhs_exprs()) {
2860 TRY_TO(TraverseStmt(E));
2862 for (auto *E : C->reduction_ops()) {
2863 TRY_TO(TraverseStmt(E));
2868 template <typename Derived>
2869 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
2870 TRY_TO(VisitOMPClauseList(C));
2874 template <typename Derived>
2875 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) {
2876 TRY_TO(VisitOMPClauseList(C));
2880 template <typename Derived>
2881 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) {
2882 TRY_TO(TraverseStmt(C->getDevice()));
2886 template <typename Derived>
2887 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) {
2888 TRY_TO(VisitOMPClauseList(C));
2892 template <typename Derived>
2893 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause(
2894 OMPNumTeamsClause *C) {
2895 TRY_TO(TraverseStmt(C->getNumTeams()));
2899 template <typename Derived>
2900 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause(
2901 OMPThreadLimitClause *C) {
2902 TRY_TO(TraverseStmt(C->getThreadLimit()));
2906 template <typename Derived>
2907 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause(
2908 OMPPriorityClause *C) {
2909 TRY_TO(TraverseStmt(C->getPriority()));
2913 template <typename Derived>
2914 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
2915 OMPGrainsizeClause *C) {
2916 TRY_TO(TraverseStmt(C->getGrainsize()));
2920 template <typename Derived>
2921 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
2922 OMPNumTasksClause *C) {
2923 TRY_TO(TraverseStmt(C->getNumTasks()));
2927 template <typename Derived>
2928 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) {
2929 TRY_TO(TraverseStmt(C->getHint()));
2933 template <typename Derived>
2934 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause(
2935 OMPDistScheduleClause *C) {
2936 TRY_TO(VisitOMPClauseWithPreInit(C));
2937 TRY_TO(TraverseStmt(C->getChunkSize()));
2941 template <typename Derived>
2943 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) {
2947 template <typename Derived>
2948 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) {
2949 TRY_TO(VisitOMPClauseList(C));
2953 template <typename Derived>
2954 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) {
2955 TRY_TO(VisitOMPClauseList(C));
2959 template <typename Derived>
2960 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause(
2961 OMPUseDevicePtrClause *C) {
2962 TRY_TO(VisitOMPClauseList(C));
2966 template <typename Derived>
2967 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
2968 OMPIsDevicePtrClause *C) {
2969 TRY_TO(VisitOMPClauseList(C));
2973 // FIXME: look at the following tricky-seeming exprs to see if we
2974 // need to recurse on anything. These are ones that have methods
2975 // returning decls or qualtypes or nestednamespecifier -- though I'm
2976 // not sure if they own them -- or just seemed very complicated, or
2977 // had lots of sub-types to explore.
2979 // VisitOverloadExpr and its children: recurse on template args? etc?
2981 // FIXME: go through all the stmts and exprs again, and see which of them
2982 // create new types, and recurse on the types (TypeLocs?) of those.
2985 // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
2986 // http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
2987 // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
2988 // Every class that has getQualifier.
2990 #undef DEF_TRAVERSE_STMT
2991 #undef TRAVERSE_STMT
2992 #undef TRAVERSE_STMT_BASE
2996 } // end namespace clang
2998 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H