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