1*0a6a1f1dSLionel Sambuc //===--- DataRecursiveASTVisitor.h - Data-Recursive AST Visitor -*- C++ -*-===//
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc // The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*0a6a1f1dSLionel Sambuc // License. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc //
8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
9*0a6a1f1dSLionel Sambuc //
10*0a6a1f1dSLionel Sambuc // This file defines the DataRecursiveASTVisitor interface, which recursively
11*0a6a1f1dSLionel Sambuc // traverses the entire AST, using data recursion for Stmts/Exprs.
12*0a6a1f1dSLionel Sambuc //
13*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
14*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_AST_DATARECURSIVEASTVISITOR_H
15*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_AST_DATARECURSIVEASTVISITOR_H
16*0a6a1f1dSLionel Sambuc
17*0a6a1f1dSLionel Sambuc #include "clang/AST/Attr.h"
18*0a6a1f1dSLionel Sambuc #include "clang/AST/Decl.h"
19*0a6a1f1dSLionel Sambuc #include "clang/AST/DeclCXX.h"
20*0a6a1f1dSLionel Sambuc #include "clang/AST/DeclFriend.h"
21*0a6a1f1dSLionel Sambuc #include "clang/AST/DeclObjC.h"
22*0a6a1f1dSLionel Sambuc #include "clang/AST/DeclOpenMP.h"
23*0a6a1f1dSLionel Sambuc #include "clang/AST/DeclTemplate.h"
24*0a6a1f1dSLionel Sambuc #include "clang/AST/Expr.h"
25*0a6a1f1dSLionel Sambuc #include "clang/AST/ExprCXX.h"
26*0a6a1f1dSLionel Sambuc #include "clang/AST/ExprObjC.h"
27*0a6a1f1dSLionel Sambuc #include "clang/AST/NestedNameSpecifier.h"
28*0a6a1f1dSLionel Sambuc #include "clang/AST/Stmt.h"
29*0a6a1f1dSLionel Sambuc #include "clang/AST/StmtCXX.h"
30*0a6a1f1dSLionel Sambuc #include "clang/AST/StmtObjC.h"
31*0a6a1f1dSLionel Sambuc #include "clang/AST/StmtOpenMP.h"
32*0a6a1f1dSLionel Sambuc #include "clang/AST/TemplateBase.h"
33*0a6a1f1dSLionel Sambuc #include "clang/AST/TemplateName.h"
34*0a6a1f1dSLionel Sambuc #include "clang/AST/Type.h"
35*0a6a1f1dSLionel Sambuc #include "clang/AST/TypeLoc.h"
36*0a6a1f1dSLionel Sambuc
37*0a6a1f1dSLionel Sambuc // The following three macros are used for meta programming. The code
38*0a6a1f1dSLionel Sambuc // using them is responsible for defining macro OPERATOR().
39*0a6a1f1dSLionel Sambuc
40*0a6a1f1dSLionel Sambuc // All unary operators.
41*0a6a1f1dSLionel Sambuc #define UNARYOP_LIST() \
42*0a6a1f1dSLionel Sambuc OPERATOR(PostInc) OPERATOR(PostDec) OPERATOR(PreInc) OPERATOR(PreDec) \
43*0a6a1f1dSLionel Sambuc OPERATOR(AddrOf) OPERATOR(Deref) OPERATOR(Plus) OPERATOR(Minus) \
44*0a6a1f1dSLionel Sambuc OPERATOR(Not) OPERATOR(LNot) OPERATOR(Real) OPERATOR(Imag) \
45*0a6a1f1dSLionel Sambuc OPERATOR(Extension)
46*0a6a1f1dSLionel Sambuc
47*0a6a1f1dSLionel Sambuc // All binary operators (excluding compound assign operators).
48*0a6a1f1dSLionel Sambuc #define BINOP_LIST() \
49*0a6a1f1dSLionel Sambuc OPERATOR(PtrMemD) OPERATOR(PtrMemI) OPERATOR(Mul) OPERATOR(Div) \
50*0a6a1f1dSLionel Sambuc OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) OPERATOR(Shr) \
51*0a6a1f1dSLionel Sambuc OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) OPERATOR(GE) OPERATOR(EQ) \
52*0a6a1f1dSLionel Sambuc OPERATOR(NE) OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) OPERATOR(LAnd) \
53*0a6a1f1dSLionel Sambuc OPERATOR(LOr) OPERATOR(Assign) OPERATOR(Comma)
54*0a6a1f1dSLionel Sambuc
55*0a6a1f1dSLionel Sambuc // All compound assign operators.
56*0a6a1f1dSLionel Sambuc #define CAO_LIST() \
57*0a6a1f1dSLionel Sambuc OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \
58*0a6a1f1dSLionel Sambuc OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor)
59*0a6a1f1dSLionel Sambuc
60*0a6a1f1dSLionel Sambuc namespace clang {
61*0a6a1f1dSLionel Sambuc
62*0a6a1f1dSLionel Sambuc // Reduce the diff between RecursiveASTVisitor / DataRecursiveASTVisitor to
63*0a6a1f1dSLionel Sambuc // make it easier to track changes and keep the two in sync.
64*0a6a1f1dSLionel Sambuc #define RecursiveASTVisitor DataRecursiveASTVisitor
65*0a6a1f1dSLionel Sambuc
66*0a6a1f1dSLionel Sambuc // A helper macro to implement short-circuiting when recursing. It
67*0a6a1f1dSLionel Sambuc // invokes CALL_EXPR, which must be a method call, on the derived
68*0a6a1f1dSLionel Sambuc // object (s.t. a user of RecursiveASTVisitor can override the method
69*0a6a1f1dSLionel Sambuc // in CALL_EXPR).
70*0a6a1f1dSLionel Sambuc #define TRY_TO(CALL_EXPR) \
71*0a6a1f1dSLionel Sambuc do { \
72*0a6a1f1dSLionel Sambuc if (!getDerived().CALL_EXPR) \
73*0a6a1f1dSLionel Sambuc return false; \
74*0a6a1f1dSLionel Sambuc } while (0)
75*0a6a1f1dSLionel Sambuc
76*0a6a1f1dSLionel Sambuc /// \brief A class that does preorder depth-first traversal on the
77*0a6a1f1dSLionel Sambuc /// entire Clang AST and visits each node.
78*0a6a1f1dSLionel Sambuc ///
79*0a6a1f1dSLionel Sambuc /// This class performs three distinct tasks:
80*0a6a1f1dSLionel Sambuc /// 1. traverse the AST (i.e. go to each node);
81*0a6a1f1dSLionel Sambuc /// 2. at a given node, walk up the class hierarchy, starting from
82*0a6a1f1dSLionel Sambuc /// the node's dynamic type, until the top-most class (e.g. Stmt,
83*0a6a1f1dSLionel Sambuc /// Decl, or Type) is reached.
84*0a6a1f1dSLionel Sambuc /// 3. given a (node, class) combination, where 'class' is some base
85*0a6a1f1dSLionel Sambuc /// class of the dynamic type of 'node', call a user-overridable
86*0a6a1f1dSLionel Sambuc /// function to actually visit the node.
87*0a6a1f1dSLionel Sambuc ///
88*0a6a1f1dSLionel Sambuc /// These tasks are done by three groups of methods, respectively:
89*0a6a1f1dSLionel Sambuc /// 1. TraverseDecl(Decl *x) does task #1. It is the entry point
90*0a6a1f1dSLionel Sambuc /// for traversing an AST rooted at x. This method simply
91*0a6a1f1dSLionel Sambuc /// dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
92*0a6a1f1dSLionel Sambuc /// is the dynamic type of *x, which calls WalkUpFromFoo(x) and
93*0a6a1f1dSLionel Sambuc /// then recursively visits the child nodes of x.
94*0a6a1f1dSLionel Sambuc /// TraverseStmt(Stmt *x) and TraverseType(QualType x) work
95*0a6a1f1dSLionel Sambuc /// similarly.
96*0a6a1f1dSLionel Sambuc /// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit
97*0a6a1f1dSLionel Sambuc /// any child node of x. Instead, it first calls WalkUpFromBar(x)
98*0a6a1f1dSLionel Sambuc /// where Bar is the direct parent class of Foo (unless Foo has
99*0a6a1f1dSLionel Sambuc /// no parent), and then calls VisitFoo(x) (see the next list item).
100*0a6a1f1dSLionel Sambuc /// 3. VisitFoo(Foo *x) does task #3.
101*0a6a1f1dSLionel Sambuc ///
102*0a6a1f1dSLionel Sambuc /// These three method groups are tiered (Traverse* > WalkUpFrom* >
103*0a6a1f1dSLionel Sambuc /// Visit*). A method (e.g. Traverse*) may call methods from the same
104*0a6a1f1dSLionel Sambuc /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
105*0a6a1f1dSLionel Sambuc /// It may not call methods from a higher tier.
106*0a6a1f1dSLionel Sambuc ///
107*0a6a1f1dSLionel Sambuc /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
108*0a6a1f1dSLionel Sambuc /// is Foo's super class) before calling VisitFoo(), the result is
109*0a6a1f1dSLionel Sambuc /// that the Visit*() methods for a given node are called in the
110*0a6a1f1dSLionel Sambuc /// top-down order (e.g. for a node of type NamespaceDecl, the order will
111*0a6a1f1dSLionel Sambuc /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
112*0a6a1f1dSLionel Sambuc ///
113*0a6a1f1dSLionel Sambuc /// This scheme guarantees that all Visit*() calls for the same AST
114*0a6a1f1dSLionel Sambuc /// node are grouped together. In other words, Visit*() methods for
115*0a6a1f1dSLionel Sambuc /// different nodes are never interleaved.
116*0a6a1f1dSLionel Sambuc ///
117*0a6a1f1dSLionel Sambuc /// Stmts are traversed internally using a data queue to avoid a stack overflow
118*0a6a1f1dSLionel Sambuc /// with hugely nested ASTs.
119*0a6a1f1dSLionel Sambuc ///
120*0a6a1f1dSLionel Sambuc /// Clients of this visitor should subclass the visitor (providing
121*0a6a1f1dSLionel Sambuc /// themselves as the template argument, using the curiously recurring
122*0a6a1f1dSLionel Sambuc /// template pattern) and override any of the Traverse*, WalkUpFrom*,
123*0a6a1f1dSLionel Sambuc /// and Visit* methods for declarations, types, statements,
124*0a6a1f1dSLionel Sambuc /// expressions, or other AST nodes where the visitor should customize
125*0a6a1f1dSLionel Sambuc /// behavior. Most users only need to override Visit*. Advanced
126*0a6a1f1dSLionel Sambuc /// users may override Traverse* and WalkUpFrom* to implement custom
127*0a6a1f1dSLionel Sambuc /// traversal strategies. Returning false from one of these overridden
128*0a6a1f1dSLionel Sambuc /// functions will abort the entire traversal.
129*0a6a1f1dSLionel Sambuc ///
130*0a6a1f1dSLionel Sambuc /// By default, this visitor tries to visit every part of the explicit
131*0a6a1f1dSLionel Sambuc /// source code exactly once. The default policy towards templates
132*0a6a1f1dSLionel Sambuc /// is to descend into the 'pattern' class or function body, not any
133*0a6a1f1dSLionel Sambuc /// explicit or implicit instantiations. Explicit specializations
134*0a6a1f1dSLionel Sambuc /// are still visited, and the patterns of partial specializations
135*0a6a1f1dSLionel Sambuc /// are visited separately. This behavior can be changed by
136*0a6a1f1dSLionel Sambuc /// overriding shouldVisitTemplateInstantiations() in the derived class
137*0a6a1f1dSLionel Sambuc /// to return true, in which case all known implicit and explicit
138*0a6a1f1dSLionel Sambuc /// instantiations will be visited at the same time as the pattern
139*0a6a1f1dSLionel Sambuc /// from which they were produced.
140*0a6a1f1dSLionel Sambuc template <typename Derived> class RecursiveASTVisitor {
141*0a6a1f1dSLionel Sambuc public:
142*0a6a1f1dSLionel Sambuc /// \brief Return a reference to the derived class.
getDerived()143*0a6a1f1dSLionel Sambuc Derived &getDerived() { return *static_cast<Derived *>(this); }
144*0a6a1f1dSLionel Sambuc
145*0a6a1f1dSLionel Sambuc /// \brief Return whether this visitor should recurse into
146*0a6a1f1dSLionel Sambuc /// template instantiations.
shouldVisitTemplateInstantiations()147*0a6a1f1dSLionel Sambuc bool shouldVisitTemplateInstantiations() const { return false; }
148*0a6a1f1dSLionel Sambuc
149*0a6a1f1dSLionel Sambuc /// \brief Return whether this visitor should recurse into the types of
150*0a6a1f1dSLionel Sambuc /// TypeLocs.
shouldWalkTypesOfTypeLocs()151*0a6a1f1dSLionel Sambuc bool shouldWalkTypesOfTypeLocs() const { return true; }
152*0a6a1f1dSLionel Sambuc
153*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a statement or expression, by
154*0a6a1f1dSLionel Sambuc /// dispatching to Traverse*() based on the argument's dynamic type.
155*0a6a1f1dSLionel Sambuc ///
156*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true
157*0a6a1f1dSLionel Sambuc /// otherwise (including when the argument is NULL).
158*0a6a1f1dSLionel Sambuc bool TraverseStmt(Stmt *S);
159*0a6a1f1dSLionel Sambuc
160*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a type, by dispatching to
161*0a6a1f1dSLionel Sambuc /// Traverse*Type() based on the argument's getTypeClass() property.
162*0a6a1f1dSLionel Sambuc ///
163*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true
164*0a6a1f1dSLionel Sambuc /// otherwise (including when the argument is a Null type).
165*0a6a1f1dSLionel Sambuc bool TraverseType(QualType T);
166*0a6a1f1dSLionel Sambuc
167*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a type with location, by dispatching to
168*0a6a1f1dSLionel Sambuc /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
169*0a6a1f1dSLionel Sambuc ///
170*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true
171*0a6a1f1dSLionel Sambuc /// otherwise (including when the argument is a Null type location).
172*0a6a1f1dSLionel Sambuc bool TraverseTypeLoc(TypeLoc TL);
173*0a6a1f1dSLionel Sambuc
174*0a6a1f1dSLionel Sambuc /// \brief Recursively visit an attribute, by dispatching to
175*0a6a1f1dSLionel Sambuc /// Traverse*Attr() based on the argument's dynamic type.
176*0a6a1f1dSLionel Sambuc ///
177*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true
178*0a6a1f1dSLionel Sambuc /// otherwise (including when the argument is a Null type location).
179*0a6a1f1dSLionel Sambuc bool TraverseAttr(Attr *At);
180*0a6a1f1dSLionel Sambuc
181*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a declaration, by dispatching to
182*0a6a1f1dSLionel Sambuc /// Traverse*Decl() based on the argument's dynamic type.
183*0a6a1f1dSLionel Sambuc ///
184*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true
185*0a6a1f1dSLionel Sambuc /// otherwise (including when the argument is NULL).
186*0a6a1f1dSLionel Sambuc bool TraverseDecl(Decl *D);
187*0a6a1f1dSLionel Sambuc
188*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a C++ nested-name-specifier.
189*0a6a1f1dSLionel Sambuc ///
190*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
191*0a6a1f1dSLionel Sambuc bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
192*0a6a1f1dSLionel Sambuc
193*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a C++ nested-name-specifier with location
194*0a6a1f1dSLionel Sambuc /// information.
195*0a6a1f1dSLionel Sambuc ///
196*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
197*0a6a1f1dSLionel Sambuc bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
198*0a6a1f1dSLionel Sambuc
199*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a name with its location information.
200*0a6a1f1dSLionel Sambuc ///
201*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
202*0a6a1f1dSLionel Sambuc bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
203*0a6a1f1dSLionel Sambuc
204*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a template name and dispatch to the
205*0a6a1f1dSLionel Sambuc /// appropriate method.
206*0a6a1f1dSLionel Sambuc ///
207*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
208*0a6a1f1dSLionel Sambuc bool TraverseTemplateName(TemplateName Template);
209*0a6a1f1dSLionel Sambuc
210*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a template argument and dispatch to the
211*0a6a1f1dSLionel Sambuc /// appropriate method for the argument type.
212*0a6a1f1dSLionel Sambuc ///
213*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
214*0a6a1f1dSLionel Sambuc // FIXME: migrate callers to TemplateArgumentLoc instead.
215*0a6a1f1dSLionel Sambuc bool TraverseTemplateArgument(const TemplateArgument &Arg);
216*0a6a1f1dSLionel Sambuc
217*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a template argument location and dispatch to the
218*0a6a1f1dSLionel Sambuc /// appropriate method for the argument type.
219*0a6a1f1dSLionel Sambuc ///
220*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
221*0a6a1f1dSLionel Sambuc bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
222*0a6a1f1dSLionel Sambuc
223*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a set of template arguments.
224*0a6a1f1dSLionel Sambuc /// This can be overridden by a subclass, but it's not expected that
225*0a6a1f1dSLionel Sambuc /// will be needed -- this visitor always dispatches to another.
226*0a6a1f1dSLionel Sambuc ///
227*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
228*0a6a1f1dSLionel Sambuc // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
229*0a6a1f1dSLionel Sambuc bool TraverseTemplateArguments(const TemplateArgument *Args,
230*0a6a1f1dSLionel Sambuc unsigned NumArgs);
231*0a6a1f1dSLionel Sambuc
232*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a constructor initializer. This
233*0a6a1f1dSLionel Sambuc /// automatically dispatches to another visitor for the initializer
234*0a6a1f1dSLionel Sambuc /// expression, but not for the name of the initializer, so may
235*0a6a1f1dSLionel Sambuc /// be overridden for clients that need access to the name.
236*0a6a1f1dSLionel Sambuc ///
237*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
238*0a6a1f1dSLionel Sambuc bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
239*0a6a1f1dSLionel Sambuc
240*0a6a1f1dSLionel Sambuc /// \brief Recursively visit a lambda capture.
241*0a6a1f1dSLionel Sambuc ///
242*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
243*0a6a1f1dSLionel Sambuc bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C);
244*0a6a1f1dSLionel Sambuc
245*0a6a1f1dSLionel Sambuc /// \brief Recursively visit the body of a lambda expression.
246*0a6a1f1dSLionel Sambuc ///
247*0a6a1f1dSLionel Sambuc /// This provides a hook for visitors that need more context when visiting
248*0a6a1f1dSLionel Sambuc /// \c LE->getBody().
249*0a6a1f1dSLionel Sambuc ///
250*0a6a1f1dSLionel Sambuc /// \returns false if the visitation was terminated early, true otherwise.
251*0a6a1f1dSLionel Sambuc bool TraverseLambdaBody(LambdaExpr *LE);
252*0a6a1f1dSLionel Sambuc
253*0a6a1f1dSLionel Sambuc // ---- Methods on Attrs ----
254*0a6a1f1dSLionel Sambuc
255*0a6a1f1dSLionel Sambuc // \brief Visit an attribute.
VisitAttr(Attr * A)256*0a6a1f1dSLionel Sambuc bool VisitAttr(Attr *A) { return true; }
257*0a6a1f1dSLionel Sambuc
258*0a6a1f1dSLionel Sambuc // Declare Traverse* and empty Visit* for all Attr classes.
259*0a6a1f1dSLionel Sambuc #define ATTR_VISITOR_DECLS_ONLY
260*0a6a1f1dSLionel Sambuc #include "clang/AST/AttrVisitor.inc"
261*0a6a1f1dSLionel Sambuc #undef ATTR_VISITOR_DECLS_ONLY
262*0a6a1f1dSLionel Sambuc
263*0a6a1f1dSLionel Sambuc // ---- Methods on Stmts ----
264*0a6a1f1dSLionel Sambuc
265*0a6a1f1dSLionel Sambuc // Declare Traverse*() for all concrete Stmt classes.
266*0a6a1f1dSLionel Sambuc #define ABSTRACT_STMT(STMT)
267*0a6a1f1dSLionel Sambuc #define STMT(CLASS, PARENT) bool Traverse##CLASS(CLASS *S);
268*0a6a1f1dSLionel Sambuc #include "clang/AST/StmtNodes.inc"
269*0a6a1f1dSLionel Sambuc // The above header #undefs ABSTRACT_STMT and STMT upon exit.
270*0a6a1f1dSLionel Sambuc
271*0a6a1f1dSLionel Sambuc // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
WalkUpFromStmt(Stmt * S)272*0a6a1f1dSLionel Sambuc bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
VisitStmt(Stmt * S)273*0a6a1f1dSLionel Sambuc bool VisitStmt(Stmt *S) { return true; }
274*0a6a1f1dSLionel Sambuc #define STMT(CLASS, PARENT) \
275*0a6a1f1dSLionel Sambuc bool WalkUpFrom##CLASS(CLASS *S) { \
276*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##PARENT(S)); \
277*0a6a1f1dSLionel Sambuc TRY_TO(Visit##CLASS(S)); \
278*0a6a1f1dSLionel Sambuc return true; \
279*0a6a1f1dSLionel Sambuc } \
280*0a6a1f1dSLionel Sambuc bool Visit##CLASS(CLASS *S) { return true; }
281*0a6a1f1dSLionel Sambuc #include "clang/AST/StmtNodes.inc"
282*0a6a1f1dSLionel Sambuc
283*0a6a1f1dSLionel Sambuc // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
284*0a6a1f1dSLionel Sambuc // operator methods. Unary operators are not classes in themselves
285*0a6a1f1dSLionel Sambuc // (they're all opcodes in UnaryOperator) but do have visitors.
286*0a6a1f1dSLionel Sambuc #define OPERATOR(NAME) \
287*0a6a1f1dSLionel Sambuc bool TraverseUnary##NAME(UnaryOperator *S) { \
288*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFromUnary##NAME(S)); \
289*0a6a1f1dSLionel Sambuc StmtQueueAction StmtQueue(*this); \
290*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getSubExpr()); \
291*0a6a1f1dSLionel Sambuc return true; \
292*0a6a1f1dSLionel Sambuc } \
293*0a6a1f1dSLionel Sambuc bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
294*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFromUnaryOperator(S)); \
295*0a6a1f1dSLionel Sambuc TRY_TO(VisitUnary##NAME(S)); \
296*0a6a1f1dSLionel Sambuc return true; \
297*0a6a1f1dSLionel Sambuc } \
298*0a6a1f1dSLionel Sambuc bool VisitUnary##NAME(UnaryOperator *S) { return true; }
299*0a6a1f1dSLionel Sambuc
300*0a6a1f1dSLionel Sambuc UNARYOP_LIST()
301*0a6a1f1dSLionel Sambuc #undef OPERATOR
302*0a6a1f1dSLionel Sambuc
303*0a6a1f1dSLionel Sambuc // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
304*0a6a1f1dSLionel Sambuc // operator methods. Binary operators are not classes in themselves
305*0a6a1f1dSLionel Sambuc // (they're all opcodes in BinaryOperator) but do have visitors.
306*0a6a1f1dSLionel Sambuc #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \
307*0a6a1f1dSLionel Sambuc bool TraverseBin##NAME(BINOP_TYPE *S) { \
308*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFromBin##NAME(S)); \
309*0a6a1f1dSLionel Sambuc StmtQueueAction StmtQueue(*this); \
310*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getLHS()); \
311*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getRHS()); \
312*0a6a1f1dSLionel Sambuc return true; \
313*0a6a1f1dSLionel Sambuc } \
314*0a6a1f1dSLionel Sambuc bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
315*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \
316*0a6a1f1dSLionel Sambuc TRY_TO(VisitBin##NAME(S)); \
317*0a6a1f1dSLionel Sambuc return true; \
318*0a6a1f1dSLionel Sambuc } \
319*0a6a1f1dSLionel Sambuc bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
320*0a6a1f1dSLionel Sambuc
321*0a6a1f1dSLionel Sambuc #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
BINOP_LIST()322*0a6a1f1dSLionel Sambuc BINOP_LIST()
323*0a6a1f1dSLionel Sambuc #undef OPERATOR
324*0a6a1f1dSLionel Sambuc
325*0a6a1f1dSLionel Sambuc // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
326*0a6a1f1dSLionel Sambuc // assignment methods. Compound assignment operators are not
327*0a6a1f1dSLionel Sambuc // classes in themselves (they're all opcodes in
328*0a6a1f1dSLionel Sambuc // CompoundAssignOperator) but do have visitors.
329*0a6a1f1dSLionel Sambuc #define OPERATOR(NAME) \
330*0a6a1f1dSLionel Sambuc GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
331*0a6a1f1dSLionel Sambuc
332*0a6a1f1dSLionel Sambuc CAO_LIST()
333*0a6a1f1dSLionel Sambuc #undef OPERATOR
334*0a6a1f1dSLionel Sambuc #undef GENERAL_BINOP_FALLBACK
335*0a6a1f1dSLionel Sambuc
336*0a6a1f1dSLionel Sambuc // ---- Methods on Types ----
337*0a6a1f1dSLionel Sambuc // FIXME: revamp to take TypeLoc's rather than Types.
338*0a6a1f1dSLionel Sambuc
339*0a6a1f1dSLionel Sambuc // Declare Traverse*() for all concrete Type classes.
340*0a6a1f1dSLionel Sambuc #define ABSTRACT_TYPE(CLASS, BASE)
341*0a6a1f1dSLionel Sambuc #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
342*0a6a1f1dSLionel Sambuc #include "clang/AST/TypeNodes.def"
343*0a6a1f1dSLionel Sambuc // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
344*0a6a1f1dSLionel Sambuc
345*0a6a1f1dSLionel Sambuc // Define WalkUpFrom*() and empty Visit*() for all Type classes.
346*0a6a1f1dSLionel Sambuc bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
VisitType(Type * T)347*0a6a1f1dSLionel Sambuc bool VisitType(Type *T) { return true; }
348*0a6a1f1dSLionel Sambuc #define TYPE(CLASS, BASE) \
349*0a6a1f1dSLionel Sambuc bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \
350*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##BASE(T)); \
351*0a6a1f1dSLionel Sambuc TRY_TO(Visit##CLASS##Type(T)); \
352*0a6a1f1dSLionel Sambuc return true; \
353*0a6a1f1dSLionel Sambuc } \
354*0a6a1f1dSLionel Sambuc bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
355*0a6a1f1dSLionel Sambuc #include "clang/AST/TypeNodes.def"
356*0a6a1f1dSLionel Sambuc
357*0a6a1f1dSLionel Sambuc // ---- Methods on TypeLocs ----
358*0a6a1f1dSLionel Sambuc // FIXME: this currently just calls the matching Type methods
359*0a6a1f1dSLionel Sambuc
360*0a6a1f1dSLionel Sambuc // Declare Traverse*() for all concrete TypeLoc classes.
361*0a6a1f1dSLionel Sambuc #define ABSTRACT_TYPELOC(CLASS, BASE)
362*0a6a1f1dSLionel Sambuc #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
363*0a6a1f1dSLionel Sambuc #include "clang/AST/TypeLocNodes.def"
364*0a6a1f1dSLionel Sambuc // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
365*0a6a1f1dSLionel Sambuc
366*0a6a1f1dSLionel Sambuc // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
WalkUpFromTypeLoc(TypeLoc TL)367*0a6a1f1dSLionel Sambuc bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
VisitTypeLoc(TypeLoc TL)368*0a6a1f1dSLionel Sambuc bool VisitTypeLoc(TypeLoc TL) { return true; }
369*0a6a1f1dSLionel Sambuc
370*0a6a1f1dSLionel Sambuc // QualifiedTypeLoc and UnqualTypeLoc are not declared in
371*0a6a1f1dSLionel Sambuc // TypeNodes.def and thus need to be handled specially.
WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL)372*0a6a1f1dSLionel Sambuc bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
373*0a6a1f1dSLionel Sambuc return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
374*0a6a1f1dSLionel Sambuc }
VisitQualifiedTypeLoc(QualifiedTypeLoc TL)375*0a6a1f1dSLionel Sambuc bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL)376*0a6a1f1dSLionel Sambuc bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
377*0a6a1f1dSLionel Sambuc return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
378*0a6a1f1dSLionel Sambuc }
VisitUnqualTypeLoc(UnqualTypeLoc TL)379*0a6a1f1dSLionel Sambuc bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
380*0a6a1f1dSLionel Sambuc
381*0a6a1f1dSLionel Sambuc // Note that BASE includes trailing 'Type' which CLASS doesn't.
382*0a6a1f1dSLionel Sambuc #define TYPE(CLASS, BASE) \
383*0a6a1f1dSLionel Sambuc bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
384*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##BASE##Loc(TL)); \
385*0a6a1f1dSLionel Sambuc TRY_TO(Visit##CLASS##TypeLoc(TL)); \
386*0a6a1f1dSLionel Sambuc return true; \
387*0a6a1f1dSLionel Sambuc } \
388*0a6a1f1dSLionel Sambuc bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
389*0a6a1f1dSLionel Sambuc #include "clang/AST/TypeNodes.def"
390*0a6a1f1dSLionel Sambuc
391*0a6a1f1dSLionel Sambuc // ---- Methods on Decls ----
392*0a6a1f1dSLionel Sambuc
393*0a6a1f1dSLionel Sambuc // Declare Traverse*() for all concrete Decl classes.
394*0a6a1f1dSLionel Sambuc #define ABSTRACT_DECL(DECL)
395*0a6a1f1dSLionel Sambuc #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
396*0a6a1f1dSLionel Sambuc #include "clang/AST/DeclNodes.inc"
397*0a6a1f1dSLionel Sambuc // The above header #undefs ABSTRACT_DECL and DECL upon exit.
398*0a6a1f1dSLionel Sambuc
399*0a6a1f1dSLionel Sambuc // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
WalkUpFromDecl(Decl * D)400*0a6a1f1dSLionel Sambuc bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
VisitDecl(Decl * D)401*0a6a1f1dSLionel Sambuc bool VisitDecl(Decl *D) { return true; }
402*0a6a1f1dSLionel Sambuc #define DECL(CLASS, BASE) \
403*0a6a1f1dSLionel Sambuc bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \
404*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##BASE(D)); \
405*0a6a1f1dSLionel Sambuc TRY_TO(Visit##CLASS##Decl(D)); \
406*0a6a1f1dSLionel Sambuc return true; \
407*0a6a1f1dSLionel Sambuc } \
408*0a6a1f1dSLionel Sambuc bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
409*0a6a1f1dSLionel Sambuc #include "clang/AST/DeclNodes.inc"
410*0a6a1f1dSLionel Sambuc
411*0a6a1f1dSLionel Sambuc private:
412*0a6a1f1dSLionel Sambuc // These are helper methods used by more than one Traverse* method.
413*0a6a1f1dSLionel Sambuc bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
414*0a6a1f1dSLionel Sambuc bool TraverseClassInstantiations(ClassTemplateDecl *D);
415*0a6a1f1dSLionel Sambuc bool TraverseVariableInstantiations(VarTemplateDecl *D);
416*0a6a1f1dSLionel Sambuc bool TraverseFunctionInstantiations(FunctionTemplateDecl *D);
417*0a6a1f1dSLionel Sambuc bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
418*0a6a1f1dSLionel Sambuc unsigned Count);
419*0a6a1f1dSLionel Sambuc bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
420*0a6a1f1dSLionel Sambuc bool TraverseRecordHelper(RecordDecl *D);
421*0a6a1f1dSLionel Sambuc bool TraverseCXXRecordHelper(CXXRecordDecl *D);
422*0a6a1f1dSLionel Sambuc bool TraverseDeclaratorHelper(DeclaratorDecl *D);
423*0a6a1f1dSLionel Sambuc bool TraverseDeclContextHelper(DeclContext *DC);
424*0a6a1f1dSLionel Sambuc bool TraverseFunctionHelper(FunctionDecl *D);
425*0a6a1f1dSLionel Sambuc bool TraverseVarHelper(VarDecl *D);
426*0a6a1f1dSLionel Sambuc bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
427*0a6a1f1dSLionel Sambuc bool TraverseOMPLoopDirective(OMPLoopDirective *S);
428*0a6a1f1dSLionel Sambuc bool TraverseOMPClause(OMPClause *C);
429*0a6a1f1dSLionel Sambuc #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C);
430*0a6a1f1dSLionel Sambuc #include "clang/Basic/OpenMPKinds.def"
431*0a6a1f1dSLionel Sambuc /// \brief Process clauses with list of variables.
432*0a6a1f1dSLionel Sambuc template <typename T> bool VisitOMPClauseList(T *Node);
433*0a6a1f1dSLionel Sambuc
434*0a6a1f1dSLionel Sambuc typedef SmallVector<Stmt *, 16> StmtsTy;
435*0a6a1f1dSLionel Sambuc typedef SmallVector<StmtsTy *, 4> QueuesTy;
436*0a6a1f1dSLionel Sambuc
437*0a6a1f1dSLionel Sambuc QueuesTy Queues;
438*0a6a1f1dSLionel Sambuc
439*0a6a1f1dSLionel Sambuc class NewQueueRAII {
440*0a6a1f1dSLionel Sambuc RecursiveASTVisitor &RAV;
441*0a6a1f1dSLionel Sambuc
442*0a6a1f1dSLionel Sambuc public:
NewQueueRAII(StmtsTy & queue,RecursiveASTVisitor & RAV)443*0a6a1f1dSLionel Sambuc NewQueueRAII(StmtsTy &queue, RecursiveASTVisitor &RAV) : RAV(RAV) {
444*0a6a1f1dSLionel Sambuc RAV.Queues.push_back(&queue);
445*0a6a1f1dSLionel Sambuc }
~NewQueueRAII()446*0a6a1f1dSLionel Sambuc ~NewQueueRAII() { RAV.Queues.pop_back(); }
447*0a6a1f1dSLionel Sambuc };
448*0a6a1f1dSLionel Sambuc
getCurrentQueue()449*0a6a1f1dSLionel Sambuc StmtsTy &getCurrentQueue() {
450*0a6a1f1dSLionel Sambuc assert(!Queues.empty() && "base TraverseStmt was never called?");
451*0a6a1f1dSLionel Sambuc return *Queues.back();
452*0a6a1f1dSLionel Sambuc }
453*0a6a1f1dSLionel Sambuc
454*0a6a1f1dSLionel Sambuc public:
455*0a6a1f1dSLionel Sambuc class StmtQueueAction {
456*0a6a1f1dSLionel Sambuc StmtsTy &CurrQueue;
457*0a6a1f1dSLionel Sambuc
458*0a6a1f1dSLionel Sambuc public:
StmtQueueAction(RecursiveASTVisitor & RAV)459*0a6a1f1dSLionel Sambuc explicit StmtQueueAction(RecursiveASTVisitor &RAV)
460*0a6a1f1dSLionel Sambuc : CurrQueue(RAV.getCurrentQueue()) {}
461*0a6a1f1dSLionel Sambuc
queue(Stmt * S)462*0a6a1f1dSLionel Sambuc void queue(Stmt *S) { CurrQueue.push_back(S); }
463*0a6a1f1dSLionel Sambuc };
464*0a6a1f1dSLionel Sambuc };
465*0a6a1f1dSLionel Sambuc
466*0a6a1f1dSLionel Sambuc #define DISPATCH(NAME, CLASS, VAR) \
467*0a6a1f1dSLionel Sambuc return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))
468*0a6a1f1dSLionel Sambuc
469*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseStmt(Stmt * S)470*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S) {
471*0a6a1f1dSLionel Sambuc if (!S)
472*0a6a1f1dSLionel Sambuc return true;
473*0a6a1f1dSLionel Sambuc
474*0a6a1f1dSLionel Sambuc StmtsTy Queue, StmtsToEnqueue;
475*0a6a1f1dSLionel Sambuc Queue.push_back(S);
476*0a6a1f1dSLionel Sambuc NewQueueRAII NQ(StmtsToEnqueue, *this);
477*0a6a1f1dSLionel Sambuc
478*0a6a1f1dSLionel Sambuc while (!Queue.empty()) {
479*0a6a1f1dSLionel Sambuc S = Queue.pop_back_val();
480*0a6a1f1dSLionel Sambuc if (!S)
481*0a6a1f1dSLionel Sambuc continue;
482*0a6a1f1dSLionel Sambuc
483*0a6a1f1dSLionel Sambuc StmtsToEnqueue.clear();
484*0a6a1f1dSLionel Sambuc
485*0a6a1f1dSLionel Sambuc #define DISPATCH_STMT(NAME, CLASS, VAR) \
486*0a6a1f1dSLionel Sambuc TRY_TO(Traverse##NAME(static_cast<CLASS *>(VAR))); \
487*0a6a1f1dSLionel Sambuc break
488*0a6a1f1dSLionel Sambuc
489*0a6a1f1dSLionel Sambuc // If we have a binary expr, dispatch to the subcode of the binop. A smart
490*0a6a1f1dSLionel Sambuc // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
491*0a6a1f1dSLionel Sambuc // below.
492*0a6a1f1dSLionel Sambuc if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
493*0a6a1f1dSLionel Sambuc switch (BinOp->getOpcode()) {
494*0a6a1f1dSLionel Sambuc #define OPERATOR(NAME) \
495*0a6a1f1dSLionel Sambuc case BO_##NAME: \
496*0a6a1f1dSLionel Sambuc DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
497*0a6a1f1dSLionel Sambuc
498*0a6a1f1dSLionel Sambuc BINOP_LIST()
499*0a6a1f1dSLionel Sambuc #undef OPERATOR
500*0a6a1f1dSLionel Sambuc #undef BINOP_LIST
501*0a6a1f1dSLionel Sambuc
502*0a6a1f1dSLionel Sambuc #define OPERATOR(NAME) \
503*0a6a1f1dSLionel Sambuc case BO_##NAME##Assign: \
504*0a6a1f1dSLionel Sambuc DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
505*0a6a1f1dSLionel Sambuc
506*0a6a1f1dSLionel Sambuc CAO_LIST()
507*0a6a1f1dSLionel Sambuc #undef OPERATOR
508*0a6a1f1dSLionel Sambuc #undef CAO_LIST
509*0a6a1f1dSLionel Sambuc }
510*0a6a1f1dSLionel Sambuc } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
511*0a6a1f1dSLionel Sambuc switch (UnOp->getOpcode()) {
512*0a6a1f1dSLionel Sambuc #define OPERATOR(NAME) \
513*0a6a1f1dSLionel Sambuc case UO_##NAME: \
514*0a6a1f1dSLionel Sambuc DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
515*0a6a1f1dSLionel Sambuc
516*0a6a1f1dSLionel Sambuc UNARYOP_LIST()
517*0a6a1f1dSLionel Sambuc #undef OPERATOR
518*0a6a1f1dSLionel Sambuc #undef UNARYOP_LIST
519*0a6a1f1dSLionel Sambuc }
520*0a6a1f1dSLionel Sambuc } else {
521*0a6a1f1dSLionel Sambuc
522*0a6a1f1dSLionel Sambuc // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
523*0a6a1f1dSLionel Sambuc switch (S->getStmtClass()) {
524*0a6a1f1dSLionel Sambuc case Stmt::NoStmtClass:
525*0a6a1f1dSLionel Sambuc break;
526*0a6a1f1dSLionel Sambuc #define ABSTRACT_STMT(STMT)
527*0a6a1f1dSLionel Sambuc #define STMT(CLASS, PARENT) \
528*0a6a1f1dSLionel Sambuc case Stmt::CLASS##Class: \
529*0a6a1f1dSLionel Sambuc DISPATCH_STMT(CLASS, CLASS, S);
530*0a6a1f1dSLionel Sambuc #include "clang/AST/StmtNodes.inc"
531*0a6a1f1dSLionel Sambuc }
532*0a6a1f1dSLionel Sambuc }
533*0a6a1f1dSLionel Sambuc
534*0a6a1f1dSLionel Sambuc for (SmallVectorImpl<Stmt *>::reverse_iterator RI = StmtsToEnqueue.rbegin(),
535*0a6a1f1dSLionel Sambuc RE = StmtsToEnqueue.rend();
536*0a6a1f1dSLionel Sambuc RI != RE; ++RI)
537*0a6a1f1dSLionel Sambuc Queue.push_back(*RI);
538*0a6a1f1dSLionel Sambuc }
539*0a6a1f1dSLionel Sambuc
540*0a6a1f1dSLionel Sambuc return true;
541*0a6a1f1dSLionel Sambuc }
542*0a6a1f1dSLionel Sambuc
543*0a6a1f1dSLionel Sambuc #undef DISPATCH_STMT
544*0a6a1f1dSLionel Sambuc
545*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseType(QualType T)546*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
547*0a6a1f1dSLionel Sambuc if (T.isNull())
548*0a6a1f1dSLionel Sambuc return true;
549*0a6a1f1dSLionel Sambuc
550*0a6a1f1dSLionel Sambuc switch (T->getTypeClass()) {
551*0a6a1f1dSLionel Sambuc #define ABSTRACT_TYPE(CLASS, BASE)
552*0a6a1f1dSLionel Sambuc #define TYPE(CLASS, BASE) \
553*0a6a1f1dSLionel Sambuc case Type::CLASS: \
554*0a6a1f1dSLionel Sambuc DISPATCH(CLASS##Type, CLASS##Type, const_cast<Type *>(T.getTypePtr()));
555*0a6a1f1dSLionel Sambuc #include "clang/AST/TypeNodes.def"
556*0a6a1f1dSLionel Sambuc }
557*0a6a1f1dSLionel Sambuc
558*0a6a1f1dSLionel Sambuc return true;
559*0a6a1f1dSLionel Sambuc }
560*0a6a1f1dSLionel Sambuc
561*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseTypeLoc(TypeLoc TL)562*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
563*0a6a1f1dSLionel Sambuc if (TL.isNull())
564*0a6a1f1dSLionel Sambuc return true;
565*0a6a1f1dSLionel Sambuc
566*0a6a1f1dSLionel Sambuc switch (TL.getTypeLocClass()) {
567*0a6a1f1dSLionel Sambuc #define ABSTRACT_TYPELOC(CLASS, BASE)
568*0a6a1f1dSLionel Sambuc #define TYPELOC(CLASS, BASE) \
569*0a6a1f1dSLionel Sambuc case TypeLoc::CLASS: \
570*0a6a1f1dSLionel Sambuc return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
571*0a6a1f1dSLionel Sambuc #include "clang/AST/TypeLocNodes.def"
572*0a6a1f1dSLionel Sambuc }
573*0a6a1f1dSLionel Sambuc
574*0a6a1f1dSLionel Sambuc return true;
575*0a6a1f1dSLionel Sambuc }
576*0a6a1f1dSLionel Sambuc
577*0a6a1f1dSLionel Sambuc // Define the Traverse*Attr(Attr* A) methods
578*0a6a1f1dSLionel Sambuc #define VISITORCLASS RecursiveASTVisitor
579*0a6a1f1dSLionel Sambuc #include "clang/AST/AttrVisitor.inc"
580*0a6a1f1dSLionel Sambuc #undef VISITORCLASS
581*0a6a1f1dSLionel Sambuc
582*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseDecl(Decl * D)583*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
584*0a6a1f1dSLionel Sambuc if (!D)
585*0a6a1f1dSLionel Sambuc return true;
586*0a6a1f1dSLionel Sambuc
587*0a6a1f1dSLionel Sambuc // As a syntax visitor, we want to ignore declarations for
588*0a6a1f1dSLionel Sambuc // implicitly-defined declarations (ones not typed explicitly by the
589*0a6a1f1dSLionel Sambuc // user).
590*0a6a1f1dSLionel Sambuc if (D->isImplicit())
591*0a6a1f1dSLionel Sambuc return true;
592*0a6a1f1dSLionel Sambuc
593*0a6a1f1dSLionel Sambuc switch (D->getKind()) {
594*0a6a1f1dSLionel Sambuc #define ABSTRACT_DECL(DECL)
595*0a6a1f1dSLionel Sambuc #define DECL(CLASS, BASE) \
596*0a6a1f1dSLionel Sambuc case Decl::CLASS: \
597*0a6a1f1dSLionel Sambuc if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D))) \
598*0a6a1f1dSLionel Sambuc return false; \
599*0a6a1f1dSLionel Sambuc break;
600*0a6a1f1dSLionel Sambuc #include "clang/AST/DeclNodes.inc"
601*0a6a1f1dSLionel Sambuc }
602*0a6a1f1dSLionel Sambuc
603*0a6a1f1dSLionel Sambuc // Visit any attributes attached to this declaration.
604*0a6a1f1dSLionel Sambuc for (auto *I : D->attrs()) {
605*0a6a1f1dSLionel Sambuc if (!getDerived().TraverseAttr(I))
606*0a6a1f1dSLionel Sambuc return false;
607*0a6a1f1dSLionel Sambuc }
608*0a6a1f1dSLionel Sambuc return true;
609*0a6a1f1dSLionel Sambuc }
610*0a6a1f1dSLionel Sambuc
611*0a6a1f1dSLionel Sambuc #undef DISPATCH
612*0a6a1f1dSLionel Sambuc
613*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseNestedNameSpecifier(NestedNameSpecifier * NNS)614*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
615*0a6a1f1dSLionel Sambuc NestedNameSpecifier *NNS) {
616*0a6a1f1dSLionel Sambuc if (!NNS)
617*0a6a1f1dSLionel Sambuc return true;
618*0a6a1f1dSLionel Sambuc
619*0a6a1f1dSLionel Sambuc if (NNS->getPrefix())
620*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
621*0a6a1f1dSLionel Sambuc
622*0a6a1f1dSLionel Sambuc switch (NNS->getKind()) {
623*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::Identifier:
624*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::Namespace:
625*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::NamespaceAlias:
626*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::Global:
627*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::Super:
628*0a6a1f1dSLionel Sambuc return true;
629*0a6a1f1dSLionel Sambuc
630*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::TypeSpec:
631*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::TypeSpecWithTemplate:
632*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
633*0a6a1f1dSLionel Sambuc }
634*0a6a1f1dSLionel Sambuc
635*0a6a1f1dSLionel Sambuc return true;
636*0a6a1f1dSLionel Sambuc }
637*0a6a1f1dSLionel Sambuc
638*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)639*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
640*0a6a1f1dSLionel Sambuc NestedNameSpecifierLoc NNS) {
641*0a6a1f1dSLionel Sambuc if (!NNS)
642*0a6a1f1dSLionel Sambuc return true;
643*0a6a1f1dSLionel Sambuc
644*0a6a1f1dSLionel Sambuc if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
645*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
646*0a6a1f1dSLionel Sambuc
647*0a6a1f1dSLionel Sambuc switch (NNS.getNestedNameSpecifier()->getKind()) {
648*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::Identifier:
649*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::Namespace:
650*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::NamespaceAlias:
651*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::Global:
652*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::Super:
653*0a6a1f1dSLionel Sambuc return true;
654*0a6a1f1dSLionel Sambuc
655*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::TypeSpec:
656*0a6a1f1dSLionel Sambuc case NestedNameSpecifier::TypeSpecWithTemplate:
657*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
658*0a6a1f1dSLionel Sambuc break;
659*0a6a1f1dSLionel Sambuc }
660*0a6a1f1dSLionel Sambuc
661*0a6a1f1dSLionel Sambuc return true;
662*0a6a1f1dSLionel Sambuc }
663*0a6a1f1dSLionel Sambuc
664*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo)665*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
666*0a6a1f1dSLionel Sambuc DeclarationNameInfo NameInfo) {
667*0a6a1f1dSLionel Sambuc switch (NameInfo.getName().getNameKind()) {
668*0a6a1f1dSLionel Sambuc case DeclarationName::CXXConstructorName:
669*0a6a1f1dSLionel Sambuc case DeclarationName::CXXDestructorName:
670*0a6a1f1dSLionel Sambuc case DeclarationName::CXXConversionFunctionName:
671*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
672*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
673*0a6a1f1dSLionel Sambuc
674*0a6a1f1dSLionel Sambuc break;
675*0a6a1f1dSLionel Sambuc
676*0a6a1f1dSLionel Sambuc case DeclarationName::Identifier:
677*0a6a1f1dSLionel Sambuc case DeclarationName::ObjCZeroArgSelector:
678*0a6a1f1dSLionel Sambuc case DeclarationName::ObjCOneArgSelector:
679*0a6a1f1dSLionel Sambuc case DeclarationName::ObjCMultiArgSelector:
680*0a6a1f1dSLionel Sambuc case DeclarationName::CXXOperatorName:
681*0a6a1f1dSLionel Sambuc case DeclarationName::CXXLiteralOperatorName:
682*0a6a1f1dSLionel Sambuc case DeclarationName::CXXUsingDirective:
683*0a6a1f1dSLionel Sambuc break;
684*0a6a1f1dSLionel Sambuc }
685*0a6a1f1dSLionel Sambuc
686*0a6a1f1dSLionel Sambuc return true;
687*0a6a1f1dSLionel Sambuc }
688*0a6a1f1dSLionel Sambuc
689*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseTemplateName(TemplateName Template)690*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
691*0a6a1f1dSLionel Sambuc if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
692*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
693*0a6a1f1dSLionel Sambuc else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
694*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
695*0a6a1f1dSLionel Sambuc
696*0a6a1f1dSLionel Sambuc return true;
697*0a6a1f1dSLionel Sambuc }
698*0a6a1f1dSLionel Sambuc
699*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseTemplateArgument(const TemplateArgument & Arg)700*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
701*0a6a1f1dSLionel Sambuc const TemplateArgument &Arg) {
702*0a6a1f1dSLionel Sambuc switch (Arg.getKind()) {
703*0a6a1f1dSLionel Sambuc case TemplateArgument::Null:
704*0a6a1f1dSLionel Sambuc case TemplateArgument::Declaration:
705*0a6a1f1dSLionel Sambuc case TemplateArgument::Integral:
706*0a6a1f1dSLionel Sambuc case TemplateArgument::NullPtr:
707*0a6a1f1dSLionel Sambuc return true;
708*0a6a1f1dSLionel Sambuc
709*0a6a1f1dSLionel Sambuc case TemplateArgument::Type:
710*0a6a1f1dSLionel Sambuc return getDerived().TraverseType(Arg.getAsType());
711*0a6a1f1dSLionel Sambuc
712*0a6a1f1dSLionel Sambuc case TemplateArgument::Template:
713*0a6a1f1dSLionel Sambuc case TemplateArgument::TemplateExpansion:
714*0a6a1f1dSLionel Sambuc return getDerived().TraverseTemplateName(
715*0a6a1f1dSLionel Sambuc Arg.getAsTemplateOrTemplatePattern());
716*0a6a1f1dSLionel Sambuc
717*0a6a1f1dSLionel Sambuc case TemplateArgument::Expression:
718*0a6a1f1dSLionel Sambuc return getDerived().TraverseStmt(Arg.getAsExpr());
719*0a6a1f1dSLionel Sambuc
720*0a6a1f1dSLionel Sambuc case TemplateArgument::Pack:
721*0a6a1f1dSLionel Sambuc return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
722*0a6a1f1dSLionel Sambuc Arg.pack_size());
723*0a6a1f1dSLionel Sambuc }
724*0a6a1f1dSLionel Sambuc
725*0a6a1f1dSLionel Sambuc return true;
726*0a6a1f1dSLionel Sambuc }
727*0a6a1f1dSLionel Sambuc
728*0a6a1f1dSLionel Sambuc // FIXME: no template name location?
729*0a6a1f1dSLionel Sambuc // FIXME: no source locations for a template argument pack?
730*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseTemplateArgumentLoc(const TemplateArgumentLoc & ArgLoc)731*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
732*0a6a1f1dSLionel Sambuc const TemplateArgumentLoc &ArgLoc) {
733*0a6a1f1dSLionel Sambuc const TemplateArgument &Arg = ArgLoc.getArgument();
734*0a6a1f1dSLionel Sambuc
735*0a6a1f1dSLionel Sambuc switch (Arg.getKind()) {
736*0a6a1f1dSLionel Sambuc case TemplateArgument::Null:
737*0a6a1f1dSLionel Sambuc case TemplateArgument::Declaration:
738*0a6a1f1dSLionel Sambuc case TemplateArgument::Integral:
739*0a6a1f1dSLionel Sambuc case TemplateArgument::NullPtr:
740*0a6a1f1dSLionel Sambuc return true;
741*0a6a1f1dSLionel Sambuc
742*0a6a1f1dSLionel Sambuc case TemplateArgument::Type: {
743*0a6a1f1dSLionel Sambuc // FIXME: how can TSI ever be NULL?
744*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
745*0a6a1f1dSLionel Sambuc return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
746*0a6a1f1dSLionel Sambuc else
747*0a6a1f1dSLionel Sambuc return getDerived().TraverseType(Arg.getAsType());
748*0a6a1f1dSLionel Sambuc }
749*0a6a1f1dSLionel Sambuc
750*0a6a1f1dSLionel Sambuc case TemplateArgument::Template:
751*0a6a1f1dSLionel Sambuc case TemplateArgument::TemplateExpansion:
752*0a6a1f1dSLionel Sambuc if (ArgLoc.getTemplateQualifierLoc())
753*0a6a1f1dSLionel Sambuc TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
754*0a6a1f1dSLionel Sambuc ArgLoc.getTemplateQualifierLoc()));
755*0a6a1f1dSLionel Sambuc return getDerived().TraverseTemplateName(
756*0a6a1f1dSLionel Sambuc Arg.getAsTemplateOrTemplatePattern());
757*0a6a1f1dSLionel Sambuc
758*0a6a1f1dSLionel Sambuc case TemplateArgument::Expression:
759*0a6a1f1dSLionel Sambuc return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
760*0a6a1f1dSLionel Sambuc
761*0a6a1f1dSLionel Sambuc case TemplateArgument::Pack:
762*0a6a1f1dSLionel Sambuc return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
763*0a6a1f1dSLionel Sambuc Arg.pack_size());
764*0a6a1f1dSLionel Sambuc }
765*0a6a1f1dSLionel Sambuc
766*0a6a1f1dSLionel Sambuc return true;
767*0a6a1f1dSLionel Sambuc }
768*0a6a1f1dSLionel Sambuc
769*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseTemplateArguments(const TemplateArgument * Args,unsigned NumArgs)770*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
771*0a6a1f1dSLionel Sambuc const TemplateArgument *Args, unsigned NumArgs) {
772*0a6a1f1dSLionel Sambuc for (unsigned I = 0; I != NumArgs; ++I) {
773*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgument(Args[I]));
774*0a6a1f1dSLionel Sambuc }
775*0a6a1f1dSLionel Sambuc
776*0a6a1f1dSLionel Sambuc return true;
777*0a6a1f1dSLionel Sambuc }
778*0a6a1f1dSLionel Sambuc
779*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseConstructorInitializer(CXXCtorInitializer * Init)780*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
781*0a6a1f1dSLionel Sambuc CXXCtorInitializer *Init) {
782*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
783*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
784*0a6a1f1dSLionel Sambuc
785*0a6a1f1dSLionel Sambuc if (Init->isWritten())
786*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(Init->getInit()));
787*0a6a1f1dSLionel Sambuc return true;
788*0a6a1f1dSLionel Sambuc }
789*0a6a1f1dSLionel Sambuc
790*0a6a1f1dSLionel Sambuc template <typename Derived>
791*0a6a1f1dSLionel Sambuc bool
TraverseLambdaCapture(LambdaExpr * LE,const LambdaCapture * C)792*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
793*0a6a1f1dSLionel Sambuc const LambdaCapture *C) {
794*0a6a1f1dSLionel Sambuc if (C->isInitCapture())
795*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(C->getCapturedVar()));
796*0a6a1f1dSLionel Sambuc return true;
797*0a6a1f1dSLionel Sambuc }
798*0a6a1f1dSLionel Sambuc
799*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseLambdaBody(LambdaExpr * LE)800*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseLambdaBody(LambdaExpr *LE) {
801*0a6a1f1dSLionel Sambuc StmtQueueAction StmtQueue(*this);
802*0a6a1f1dSLionel Sambuc StmtQueue.queue(LE->getBody());
803*0a6a1f1dSLionel Sambuc return true;
804*0a6a1f1dSLionel Sambuc }
805*0a6a1f1dSLionel Sambuc
806*0a6a1f1dSLionel Sambuc // ----------------- Type traversal -----------------
807*0a6a1f1dSLionel Sambuc
808*0a6a1f1dSLionel Sambuc // This macro makes available a variable T, the passed-in type.
809*0a6a1f1dSLionel Sambuc #define DEF_TRAVERSE_TYPE(TYPE, CODE) \
810*0a6a1f1dSLionel Sambuc template <typename Derived> \
811*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) { \
812*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##TYPE(T)); \
813*0a6a1f1dSLionel Sambuc { CODE; } \
814*0a6a1f1dSLionel Sambuc return true; \
815*0a6a1f1dSLionel Sambuc }
816*0a6a1f1dSLionel Sambuc
817*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(BuiltinType, {})
818*0a6a1f1dSLionel Sambuc
819*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
820*0a6a1f1dSLionel Sambuc
821*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
822*0a6a1f1dSLionel Sambuc
823*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(BlockPointerType,
824*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseType(T->getPointeeType())); })
825*0a6a1f1dSLionel Sambuc
826*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(LValueReferenceType,
827*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseType(T->getPointeeType())); })
828*0a6a1f1dSLionel Sambuc
829*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(RValueReferenceType,
830*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseType(T->getPointeeType())); })
831*0a6a1f1dSLionel Sambuc
832*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(MemberPointerType, {
833*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(QualType(T->getClass(), 0)));
834*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getPointeeType()));
835*0a6a1f1dSLionel Sambuc })
836*0a6a1f1dSLionel Sambuc
837*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
838*0a6a1f1dSLionel Sambuc
839*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
840*0a6a1f1dSLionel Sambuc
841*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(ConstantArrayType,
842*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseType(T->getElementType())); })
843*0a6a1f1dSLionel Sambuc
844*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(IncompleteArrayType,
845*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseType(T->getElementType())); })
846*0a6a1f1dSLionel Sambuc
847*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(VariableArrayType, {
848*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getElementType()));
849*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(T->getSizeExpr()));
850*0a6a1f1dSLionel Sambuc })
851*0a6a1f1dSLionel Sambuc
852*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
853*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getElementType()));
854*0a6a1f1dSLionel Sambuc if (T->getSizeExpr())
855*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(T->getSizeExpr()));
856*0a6a1f1dSLionel Sambuc })
857*0a6a1f1dSLionel Sambuc
858*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
859*0a6a1f1dSLionel Sambuc if (T->getSizeExpr())
860*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(T->getSizeExpr()));
861*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getElementType()));
862*0a6a1f1dSLionel Sambuc })
863*0a6a1f1dSLionel Sambuc
864*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
865*0a6a1f1dSLionel Sambuc
866*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
867*0a6a1f1dSLionel Sambuc
868*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(FunctionNoProtoType,
869*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseType(T->getReturnType())); })
870*0a6a1f1dSLionel Sambuc
871*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(FunctionProtoType, {
872*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getReturnType()));
873*0a6a1f1dSLionel Sambuc
874*0a6a1f1dSLionel Sambuc for (const auto &A : T->param_types()) {
875*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(A));
876*0a6a1f1dSLionel Sambuc }
877*0a6a1f1dSLionel Sambuc
878*0a6a1f1dSLionel Sambuc for (const auto &E : T->exceptions()) {
879*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(E));
880*0a6a1f1dSLionel Sambuc }
881*0a6a1f1dSLionel Sambuc
882*0a6a1f1dSLionel Sambuc if (Expr *NE = T->getNoexceptExpr())
883*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(NE));
884*0a6a1f1dSLionel Sambuc })
885*0a6a1f1dSLionel Sambuc
886*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
887*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(TypedefType, {})
888*0a6a1f1dSLionel Sambuc
889*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(TypeOfExprType,
890*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
891*0a6a1f1dSLionel Sambuc
892*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
893*0a6a1f1dSLionel Sambuc
894*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(DecltypeType,
895*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
896*0a6a1f1dSLionel Sambuc
897*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(UnaryTransformType, {
898*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getBaseType()));
899*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getUnderlyingType()));
900*0a6a1f1dSLionel Sambuc })
901*0a6a1f1dSLionel Sambuc
902*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
903*0a6a1f1dSLionel Sambuc
904*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(RecordType, {})
905*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(EnumType, {})
906*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
907*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {})
908*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {})
909*0a6a1f1dSLionel Sambuc
910*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
911*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateName(T->getTemplateName()));
912*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
913*0a6a1f1dSLionel Sambuc })
914*0a6a1f1dSLionel Sambuc
915*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
916*0a6a1f1dSLionel Sambuc
917*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(AttributedType,
918*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseType(T->getModifiedType())); })
919*0a6a1f1dSLionel Sambuc
920*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
921*0a6a1f1dSLionel Sambuc
922*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(ElaboratedType, {
923*0a6a1f1dSLionel Sambuc if (T->getQualifier()) {
924*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
925*0a6a1f1dSLionel Sambuc }
926*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getNamedType()));
927*0a6a1f1dSLionel Sambuc })
928*0a6a1f1dSLionel Sambuc
929*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(DependentNameType,
930*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
931*0a6a1f1dSLionel Sambuc
932*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
933*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
934*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
935*0a6a1f1dSLionel Sambuc })
936*0a6a1f1dSLionel Sambuc
937*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
938*0a6a1f1dSLionel Sambuc
939*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
940*0a6a1f1dSLionel Sambuc
941*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(ObjCObjectType, {
942*0a6a1f1dSLionel Sambuc // We have to watch out here because an ObjCInterfaceType's base
943*0a6a1f1dSLionel Sambuc // type is itself.
944*0a6a1f1dSLionel Sambuc if (T->getBaseType().getTypePtr() != T)
945*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getBaseType()));
946*0a6a1f1dSLionel Sambuc })
947*0a6a1f1dSLionel Sambuc
948*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
949*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseType(T->getPointeeType())); })
950*0a6a1f1dSLionel Sambuc
951*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
952*0a6a1f1dSLionel Sambuc
953*0a6a1f1dSLionel Sambuc #undef DEF_TRAVERSE_TYPE
954*0a6a1f1dSLionel Sambuc
955*0a6a1f1dSLionel Sambuc // ----------------- TypeLoc traversal -----------------
956*0a6a1f1dSLionel Sambuc
957*0a6a1f1dSLionel Sambuc // This macro makes available a variable TL, the passed-in TypeLoc.
958*0a6a1f1dSLionel Sambuc // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
959*0a6a1f1dSLionel Sambuc // in addition to WalkUpFrom* for the TypeLoc itself, such that existing
960*0a6a1f1dSLionel Sambuc // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
961*0a6a1f1dSLionel Sambuc // continue to work.
962*0a6a1f1dSLionel Sambuc #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \
963*0a6a1f1dSLionel Sambuc template <typename Derived> \
964*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
965*0a6a1f1dSLionel Sambuc if (getDerived().shouldWalkTypesOfTypeLocs()) \
966*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \
967*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
968*0a6a1f1dSLionel Sambuc { CODE; } \
969*0a6a1f1dSLionel Sambuc return true; \
970*0a6a1f1dSLionel Sambuc }
971*0a6a1f1dSLionel Sambuc
972*0a6a1f1dSLionel Sambuc template <typename Derived>
973*0a6a1f1dSLionel Sambuc bool
TraverseQualifiedTypeLoc(QualifiedTypeLoc TL)974*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
975*0a6a1f1dSLionel Sambuc // Move this over to the 'main' typeloc tree. Note that this is a
976*0a6a1f1dSLionel Sambuc // move -- we pretend that we were really looking at the unqualified
977*0a6a1f1dSLionel Sambuc // typeloc all along -- rather than a recursion, so we don't follow
978*0a6a1f1dSLionel Sambuc // the normal CRTP plan of going through
979*0a6a1f1dSLionel Sambuc // getDerived().TraverseTypeLoc. If we did, we'd be traversing
980*0a6a1f1dSLionel Sambuc // twice for the same type (once as a QualifiedTypeLoc version of
981*0a6a1f1dSLionel Sambuc // the type, once as an UnqualifiedTypeLoc version of the type),
982*0a6a1f1dSLionel Sambuc // which in effect means we'd call VisitTypeLoc twice with the
983*0a6a1f1dSLionel Sambuc // 'same' type. This solves that problem, at the cost of never
984*0a6a1f1dSLionel Sambuc // seeing the qualified version of the type (unless the client
985*0a6a1f1dSLionel Sambuc // subclasses TraverseQualifiedTypeLoc themselves). It's not a
986*0a6a1f1dSLionel Sambuc // perfect solution. A perfect solution probably requires making
987*0a6a1f1dSLionel Sambuc // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
988*0a6a1f1dSLionel Sambuc // wrapper around Type* -- rather than being its own class in the
989*0a6a1f1dSLionel Sambuc // type hierarchy.
990*0a6a1f1dSLionel Sambuc return TraverseTypeLoc(TL.getUnqualifiedLoc());
991*0a6a1f1dSLionel Sambuc }
992*0a6a1f1dSLionel Sambuc
993*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(BuiltinType, {})
994*0a6a1f1dSLionel Sambuc
995*0a6a1f1dSLionel Sambuc // FIXME: ComplexTypeLoc is unfinished
996*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(ComplexType, {
997*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
998*0a6a1f1dSLionel Sambuc })
999*0a6a1f1dSLionel Sambuc
1000*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(PointerType,
1001*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1002*0a6a1f1dSLionel Sambuc
1003*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(BlockPointerType,
1004*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1005*0a6a1f1dSLionel Sambuc
1006*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1007*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1008*0a6a1f1dSLionel Sambuc
1009*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1010*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1011*0a6a1f1dSLionel Sambuc
1012*0a6a1f1dSLionel Sambuc // FIXME: location of base class?
1013*0a6a1f1dSLionel Sambuc // We traverse this in the type case as well, but how is it not reached through
1014*0a6a1f1dSLionel Sambuc // the pointee type?
1015*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(MemberPointerType, {
1016*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1017*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1018*0a6a1f1dSLionel Sambuc })
1019*0a6a1f1dSLionel Sambuc
1020*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(AdjustedType,
1021*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1022*0a6a1f1dSLionel Sambuc
1023*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(DecayedType,
1024*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
1025*0a6a1f1dSLionel Sambuc
1026*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseArrayTypeLocHelper(ArrayTypeLoc TL)1027*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
1028*0a6a1f1dSLionel Sambuc // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1029*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(TL.getSizeExpr()));
1030*0a6a1f1dSLionel Sambuc return true;
1031*0a6a1f1dSLionel Sambuc }
1032*0a6a1f1dSLionel Sambuc
1033*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
1034*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1035*0a6a1f1dSLionel Sambuc return TraverseArrayTypeLocHelper(TL);
1036*0a6a1f1dSLionel Sambuc })
1037*0a6a1f1dSLionel Sambuc
1038*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
1039*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1040*0a6a1f1dSLionel Sambuc return TraverseArrayTypeLocHelper(TL);
1041*0a6a1f1dSLionel Sambuc })
1042*0a6a1f1dSLionel Sambuc
1043*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(VariableArrayType, {
1044*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1045*0a6a1f1dSLionel Sambuc return TraverseArrayTypeLocHelper(TL);
1046*0a6a1f1dSLionel Sambuc })
1047*0a6a1f1dSLionel Sambuc
1048*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
1049*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1050*0a6a1f1dSLionel Sambuc return TraverseArrayTypeLocHelper(TL);
1051*0a6a1f1dSLionel Sambuc })
1052*0a6a1f1dSLionel Sambuc
1053*0a6a1f1dSLionel Sambuc // FIXME: order? why not size expr first?
1054*0a6a1f1dSLionel Sambuc // FIXME: base VectorTypeLoc is unfinished
1055*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
1056*0a6a1f1dSLionel Sambuc if (TL.getTypePtr()->getSizeExpr())
1057*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1058*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1059*0a6a1f1dSLionel Sambuc })
1060*0a6a1f1dSLionel Sambuc
1061*0a6a1f1dSLionel Sambuc // FIXME: VectorTypeLoc is unfinished
1062*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(VectorType, {
1063*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1064*0a6a1f1dSLionel Sambuc })
1065*0a6a1f1dSLionel Sambuc
1066*0a6a1f1dSLionel Sambuc // FIXME: size and attributes
1067*0a6a1f1dSLionel Sambuc // FIXME: base VectorTypeLoc is unfinished
1068*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(ExtVectorType, {
1069*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1070*0a6a1f1dSLionel Sambuc })
1071*0a6a1f1dSLionel Sambuc
1072*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1073*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
1074*0a6a1f1dSLionel Sambuc
1075*0a6a1f1dSLionel Sambuc // FIXME: location of exception specifications (attributes?)
1076*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
1077*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
1078*0a6a1f1dSLionel Sambuc
1079*0a6a1f1dSLionel Sambuc const FunctionProtoType *T = TL.getTypePtr();
1080*0a6a1f1dSLionel Sambuc
1081*0a6a1f1dSLionel Sambuc for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1082*0a6a1f1dSLionel Sambuc if (TL.getParam(I)) {
1083*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(TL.getParam(I)));
1084*0a6a1f1dSLionel Sambuc } else if (I < T->getNumParams()) {
1085*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(T->getParamType(I)));
1086*0a6a1f1dSLionel Sambuc }
1087*0a6a1f1dSLionel Sambuc }
1088*0a6a1f1dSLionel Sambuc
1089*0a6a1f1dSLionel Sambuc for (const auto &E : T->exceptions()) {
1090*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(E));
1091*0a6a1f1dSLionel Sambuc }
1092*0a6a1f1dSLionel Sambuc
1093*0a6a1f1dSLionel Sambuc if (Expr *NE = T->getNoexceptExpr())
1094*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(NE));
1095*0a6a1f1dSLionel Sambuc })
1096*0a6a1f1dSLionel Sambuc
1097*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1098*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(TypedefType, {})
1099*0a6a1f1dSLionel Sambuc
1100*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1101*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
1102*0a6a1f1dSLionel Sambuc
1103*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(TypeOfType, {
1104*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1105*0a6a1f1dSLionel Sambuc })
1106*0a6a1f1dSLionel Sambuc
1107*0a6a1f1dSLionel Sambuc // FIXME: location of underlying expr
1108*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(DecltypeType, {
1109*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1110*0a6a1f1dSLionel Sambuc })
1111*0a6a1f1dSLionel Sambuc
1112*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
1113*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1114*0a6a1f1dSLionel Sambuc })
1115*0a6a1f1dSLionel Sambuc
1116*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(AutoType, {
1117*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1118*0a6a1f1dSLionel Sambuc })
1119*0a6a1f1dSLionel Sambuc
1120*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(RecordType, {})
1121*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(EnumType, {})
1122*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1123*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {})
1124*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {})
1125*0a6a1f1dSLionel Sambuc
1126*0a6a1f1dSLionel Sambuc // FIXME: use the loc for the template name?
1127*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
1128*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1129*0a6a1f1dSLionel Sambuc for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1130*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1131*0a6a1f1dSLionel Sambuc }
1132*0a6a1f1dSLionel Sambuc })
1133*0a6a1f1dSLionel Sambuc
1134*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
1135*0a6a1f1dSLionel Sambuc
1136*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
1137*0a6a1f1dSLionel Sambuc
1138*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(AttributedType,
1139*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
1140*0a6a1f1dSLionel Sambuc
1141*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(ElaboratedType, {
1142*0a6a1f1dSLionel Sambuc if (TL.getQualifierLoc()) {
1143*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1144*0a6a1f1dSLionel Sambuc }
1145*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1146*0a6a1f1dSLionel Sambuc })
1147*0a6a1f1dSLionel Sambuc
1148*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(DependentNameType, {
1149*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1150*0a6a1f1dSLionel Sambuc })
1151*0a6a1f1dSLionel Sambuc
1152*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
1153*0a6a1f1dSLionel Sambuc if (TL.getQualifierLoc()) {
1154*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1155*0a6a1f1dSLionel Sambuc }
1156*0a6a1f1dSLionel Sambuc
1157*0a6a1f1dSLionel Sambuc for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1158*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1159*0a6a1f1dSLionel Sambuc }
1160*0a6a1f1dSLionel Sambuc })
1161*0a6a1f1dSLionel Sambuc
1162*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(PackExpansionType,
1163*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
1164*0a6a1f1dSLionel Sambuc
1165*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
1166*0a6a1f1dSLionel Sambuc
1167*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
1168*0a6a1f1dSLionel Sambuc // We have to watch out here because an ObjCInterfaceType's base
1169*0a6a1f1dSLionel Sambuc // type is itself.
1170*0a6a1f1dSLionel Sambuc if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1171*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1172*0a6a1f1dSLionel Sambuc })
1173*0a6a1f1dSLionel Sambuc
1174*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1175*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
1176*0a6a1f1dSLionel Sambuc
1177*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
1178*0a6a1f1dSLionel Sambuc
1179*0a6a1f1dSLionel Sambuc #undef DEF_TRAVERSE_TYPELOC
1180*0a6a1f1dSLionel Sambuc
1181*0a6a1f1dSLionel Sambuc // ----------------- Decl traversal -----------------
1182*0a6a1f1dSLionel Sambuc //
1183*0a6a1f1dSLionel Sambuc // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1184*0a6a1f1dSLionel Sambuc // the children that come from the DeclContext associated with it.
1185*0a6a1f1dSLionel Sambuc // Therefore each Traverse* only needs to worry about children other
1186*0a6a1f1dSLionel Sambuc // than those.
1187*0a6a1f1dSLionel Sambuc
1188*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseDeclContextHelper(DeclContext * DC)1189*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
1190*0a6a1f1dSLionel Sambuc if (!DC)
1191*0a6a1f1dSLionel Sambuc return true;
1192*0a6a1f1dSLionel Sambuc
1193*0a6a1f1dSLionel Sambuc for (auto *Child : DC->decls()) {
1194*0a6a1f1dSLionel Sambuc // BlockDecls and CapturedDecls are traversed through BlockExprs and
1195*0a6a1f1dSLionel Sambuc // CapturedStmts respectively.
1196*0a6a1f1dSLionel Sambuc if (!isa<BlockDecl>(Child) && !isa<CapturedDecl>(Child))
1197*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(Child));
1198*0a6a1f1dSLionel Sambuc }
1199*0a6a1f1dSLionel Sambuc
1200*0a6a1f1dSLionel Sambuc return true;
1201*0a6a1f1dSLionel Sambuc }
1202*0a6a1f1dSLionel Sambuc
1203*0a6a1f1dSLionel Sambuc // This macro makes available a variable D, the passed-in decl.
1204*0a6a1f1dSLionel Sambuc #define DEF_TRAVERSE_DECL(DECL, CODE) \
1205*0a6a1f1dSLionel Sambuc template <typename Derived> \
1206*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) { \
1207*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##DECL(D)); \
1208*0a6a1f1dSLionel Sambuc { CODE; } \
1209*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \
1210*0a6a1f1dSLionel Sambuc return true; \
1211*0a6a1f1dSLionel Sambuc }
1212*0a6a1f1dSLionel Sambuc
1213*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(AccessSpecDecl, {})
1214*0a6a1f1dSLionel Sambuc
1215*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(BlockDecl, {
1216*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1217*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1218*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getBody()));
1219*0a6a1f1dSLionel Sambuc for (const auto &I : D->captures()) {
1220*0a6a1f1dSLionel Sambuc if (I.hasCopyExpr()) {
1221*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(I.getCopyExpr()));
1222*0a6a1f1dSLionel Sambuc }
1223*0a6a1f1dSLionel Sambuc }
1224*0a6a1f1dSLionel Sambuc // This return statement makes sure the traversal of nodes in
1225*0a6a1f1dSLionel Sambuc // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1226*0a6a1f1dSLionel Sambuc // is skipped - don't remove it.
1227*0a6a1f1dSLionel Sambuc return true;
1228*0a6a1f1dSLionel Sambuc })
1229*0a6a1f1dSLionel Sambuc
1230*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(CapturedDecl, {
1231*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getBody()));
1232*0a6a1f1dSLionel Sambuc // This return statement makes sure the traversal of nodes in
1233*0a6a1f1dSLionel Sambuc // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1234*0a6a1f1dSLionel Sambuc // is skipped - don't remove it.
1235*0a6a1f1dSLionel Sambuc return true;
1236*0a6a1f1dSLionel Sambuc })
1237*0a6a1f1dSLionel Sambuc
1238*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(EmptyDecl, {})
1239*0a6a1f1dSLionel Sambuc
1240*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1241*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseStmt(D->getAsmString())); })
1242*0a6a1f1dSLionel Sambuc
1243*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ImportDecl, {})
1244*0a6a1f1dSLionel Sambuc
1245*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(FriendDecl, {
1246*0a6a1f1dSLionel Sambuc // Friend is either decl or a type.
1247*0a6a1f1dSLionel Sambuc if (D->getFriendType())
1248*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1249*0a6a1f1dSLionel Sambuc else
1250*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(D->getFriendDecl()));
1251*0a6a1f1dSLionel Sambuc })
1252*0a6a1f1dSLionel Sambuc
1253*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1254*0a6a1f1dSLionel Sambuc if (D->getFriendType())
1255*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1256*0a6a1f1dSLionel Sambuc else
1257*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(D->getFriendDecl()));
1258*0a6a1f1dSLionel Sambuc for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1259*0a6a1f1dSLionel Sambuc TemplateParameterList *TPL = D->getTemplateParameterList(I);
1260*0a6a1f1dSLionel Sambuc for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1261*0a6a1f1dSLionel Sambuc ITPL != ETPL; ++ITPL) {
1262*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(*ITPL));
1263*0a6a1f1dSLionel Sambuc }
1264*0a6a1f1dSLionel Sambuc }
1265*0a6a1f1dSLionel Sambuc })
1266*0a6a1f1dSLionel Sambuc
1267*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl,
1268*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseDecl(D->getSpecialization())); })
1269*0a6a1f1dSLionel Sambuc
1270*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1271*0a6a1f1dSLionel Sambuc
1272*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1273*0a6a1f1dSLionel Sambuc })
1274*0a6a1f1dSLionel Sambuc
1275*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(StaticAssertDecl, {
1276*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getAssertExpr()));
1277*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getMessage()));
1278*0a6a1f1dSLionel Sambuc })
1279*0a6a1f1dSLionel Sambuc
1280*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(
1281*0a6a1f1dSLionel Sambuc TranslationUnitDecl,
1282*0a6a1f1dSLionel Sambuc {// Code in an unnamed namespace shows up automatically in
1283*0a6a1f1dSLionel Sambuc // decls_begin()/decls_end(). Thus we don't need to recurse on
1284*0a6a1f1dSLionel Sambuc // D->getAnonymousNamespace().
1285*0a6a1f1dSLionel Sambuc })
1286*0a6a1f1dSLionel Sambuc
1287*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1288*0a6a1f1dSLionel Sambuc // We shouldn't traverse an aliased namespace, since it will be
1289*0a6a1f1dSLionel Sambuc // defined (and, therefore, traversed) somewhere else.
1290*0a6a1f1dSLionel Sambuc //
1291*0a6a1f1dSLionel Sambuc // This return statement makes sure the traversal of nodes in
1292*0a6a1f1dSLionel Sambuc // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1293*0a6a1f1dSLionel Sambuc // is skipped - don't remove it.
1294*0a6a1f1dSLionel Sambuc return true;
1295*0a6a1f1dSLionel Sambuc })
1296*0a6a1f1dSLionel Sambuc
1297*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1298*0a6a1f1dSLionel Sambuc })
1299*0a6a1f1dSLionel Sambuc
1300*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(
1301*0a6a1f1dSLionel Sambuc NamespaceDecl,
1302*0a6a1f1dSLionel Sambuc {// Code in an unnamed namespace shows up automatically in
1303*0a6a1f1dSLionel Sambuc // decls_begin()/decls_end(). Thus we don't need to recurse on
1304*0a6a1f1dSLionel Sambuc // D->getAnonymousNamespace().
1305*0a6a1f1dSLionel Sambuc })
1306*0a6a1f1dSLionel Sambuc
1307*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1308*0a6a1f1dSLionel Sambuc })
1309*0a6a1f1dSLionel Sambuc
1310*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
1311*0a6a1f1dSLionel Sambuc })
1312*0a6a1f1dSLionel Sambuc
1313*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1314*0a6a1f1dSLionel Sambuc })
1315*0a6a1f1dSLionel Sambuc
1316*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1317*0a6a1f1dSLionel Sambuc })
1318*0a6a1f1dSLionel Sambuc
1319*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
1320*0a6a1f1dSLionel Sambuc })
1321*0a6a1f1dSLionel Sambuc
1322*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
1323*0a6a1f1dSLionel Sambuc })
1324*0a6a1f1dSLionel Sambuc
1325*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1326*0a6a1f1dSLionel Sambuc if (D->getReturnTypeSourceInfo()) {
1327*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1328*0a6a1f1dSLionel Sambuc }
1329*0a6a1f1dSLionel Sambuc for (ObjCMethodDecl::param_iterator I = D->param_begin(), E = D->param_end();
1330*0a6a1f1dSLionel Sambuc I != E; ++I) {
1331*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(*I));
1332*0a6a1f1dSLionel Sambuc }
1333*0a6a1f1dSLionel Sambuc if (D->isThisDeclarationADefinition()) {
1334*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getBody()));
1335*0a6a1f1dSLionel Sambuc }
1336*0a6a1f1dSLionel Sambuc return true;
1337*0a6a1f1dSLionel Sambuc })
1338*0a6a1f1dSLionel Sambuc
1339*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1340*0a6a1f1dSLionel Sambuc if (D->getTypeSourceInfo())
1341*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1342*0a6a1f1dSLionel Sambuc else
1343*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(D->getType()));
1344*0a6a1f1dSLionel Sambuc return true;
1345*0a6a1f1dSLionel Sambuc })
1346*0a6a1f1dSLionel Sambuc
1347*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(UsingDecl, {
1348*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1349*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1350*0a6a1f1dSLionel Sambuc })
1351*0a6a1f1dSLionel Sambuc
1352*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1353*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1354*0a6a1f1dSLionel Sambuc })
1355*0a6a1f1dSLionel Sambuc
1356*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(UsingShadowDecl, {})
1357*0a6a1f1dSLionel Sambuc
1358*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
1359*0a6a1f1dSLionel Sambuc for (auto *I : D->varlists()) {
1360*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(I));
1361*0a6a1f1dSLionel Sambuc }
1362*0a6a1f1dSLionel Sambuc })
1363*0a6a1f1dSLionel Sambuc
1364*0a6a1f1dSLionel Sambuc // A helper method for TemplateDecl's children.
1365*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseTemplateParameterListHelper(TemplateParameterList * TPL)1366*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1367*0a6a1f1dSLionel Sambuc TemplateParameterList *TPL) {
1368*0a6a1f1dSLionel Sambuc if (TPL) {
1369*0a6a1f1dSLionel Sambuc for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1370*0a6a1f1dSLionel Sambuc I != E; ++I) {
1371*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(*I));
1372*0a6a1f1dSLionel Sambuc }
1373*0a6a1f1dSLionel Sambuc }
1374*0a6a1f1dSLionel Sambuc return true;
1375*0a6a1f1dSLionel Sambuc }
1376*0a6a1f1dSLionel Sambuc
1377*0a6a1f1dSLionel Sambuc // A helper method for traversing the implicit instantiations of a
1378*0a6a1f1dSLionel Sambuc // class template.
1379*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseClassInstantiations(ClassTemplateDecl * D)1380*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseClassInstantiations(
1381*0a6a1f1dSLionel Sambuc ClassTemplateDecl *D) {
1382*0a6a1f1dSLionel Sambuc for (auto *SD : D->specializations()) {
1383*0a6a1f1dSLionel Sambuc for (auto *RD : SD->redecls()) {
1384*0a6a1f1dSLionel Sambuc // We don't want to visit injected-class-names in this traversal.
1385*0a6a1f1dSLionel Sambuc if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
1386*0a6a1f1dSLionel Sambuc continue;
1387*0a6a1f1dSLionel Sambuc
1388*0a6a1f1dSLionel Sambuc switch (
1389*0a6a1f1dSLionel Sambuc cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1390*0a6a1f1dSLionel Sambuc // Visit the implicit instantiations with the requested pattern.
1391*0a6a1f1dSLionel Sambuc case TSK_Undeclared:
1392*0a6a1f1dSLionel Sambuc case TSK_ImplicitInstantiation:
1393*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(RD));
1394*0a6a1f1dSLionel Sambuc break;
1395*0a6a1f1dSLionel Sambuc
1396*0a6a1f1dSLionel Sambuc // We don't need to do anything on an explicit instantiation
1397*0a6a1f1dSLionel Sambuc // or explicit specialization because there will be an explicit
1398*0a6a1f1dSLionel Sambuc // node for it elsewhere.
1399*0a6a1f1dSLionel Sambuc case TSK_ExplicitInstantiationDeclaration:
1400*0a6a1f1dSLionel Sambuc case TSK_ExplicitInstantiationDefinition:
1401*0a6a1f1dSLionel Sambuc case TSK_ExplicitSpecialization:
1402*0a6a1f1dSLionel Sambuc break;
1403*0a6a1f1dSLionel Sambuc }
1404*0a6a1f1dSLionel Sambuc }
1405*0a6a1f1dSLionel Sambuc }
1406*0a6a1f1dSLionel Sambuc
1407*0a6a1f1dSLionel Sambuc return true;
1408*0a6a1f1dSLionel Sambuc }
1409*0a6a1f1dSLionel Sambuc
1410*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ClassTemplateDecl, {
1411*0a6a1f1dSLionel Sambuc CXXRecordDecl *TempDecl = D->getTemplatedDecl();
1412*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(TempDecl));
1413*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1414*0a6a1f1dSLionel Sambuc
1415*0a6a1f1dSLionel Sambuc // By default, we do not traverse the instantiations of
1416*0a6a1f1dSLionel Sambuc // class templates since they do not appear in the user code. The
1417*0a6a1f1dSLionel Sambuc // following code optionally traverses them.
1418*0a6a1f1dSLionel Sambuc //
1419*0a6a1f1dSLionel Sambuc // We only traverse the class instantiations when we see the canonical
1420*0a6a1f1dSLionel Sambuc // declaration of the template, to ensure we only visit them once.
1421*0a6a1f1dSLionel Sambuc if (getDerived().shouldVisitTemplateInstantiations() &&
1422*0a6a1f1dSLionel Sambuc D == D->getCanonicalDecl())
1423*0a6a1f1dSLionel Sambuc TRY_TO(TraverseClassInstantiations(D));
1424*0a6a1f1dSLionel Sambuc
1425*0a6a1f1dSLionel Sambuc // Note that getInstantiatedFromMemberTemplate() is just a link
1426*0a6a1f1dSLionel Sambuc // from a template instantiation back to the template from which
1427*0a6a1f1dSLionel Sambuc // it was instantiated, and thus should not be traversed.
1428*0a6a1f1dSLionel Sambuc })
1429*0a6a1f1dSLionel Sambuc
1430*0a6a1f1dSLionel Sambuc // A helper method for traversing the implicit instantiations of a
1431*0a6a1f1dSLionel Sambuc // class template.
1432*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseVariableInstantiations(VarTemplateDecl * D)1433*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseVariableInstantiations(
1434*0a6a1f1dSLionel Sambuc VarTemplateDecl *D) {
1435*0a6a1f1dSLionel Sambuc for (auto *SD : D->specializations()) {
1436*0a6a1f1dSLionel Sambuc for (auto *RD : SD->redecls()) {
1437*0a6a1f1dSLionel Sambuc switch (
1438*0a6a1f1dSLionel Sambuc cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
1439*0a6a1f1dSLionel Sambuc // Visit the implicit instantiations with the requested pattern.
1440*0a6a1f1dSLionel Sambuc case TSK_Undeclared:
1441*0a6a1f1dSLionel Sambuc case TSK_ImplicitInstantiation:
1442*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(RD));
1443*0a6a1f1dSLionel Sambuc break;
1444*0a6a1f1dSLionel Sambuc
1445*0a6a1f1dSLionel Sambuc // We don't need to do anything on an explicit instantiation
1446*0a6a1f1dSLionel Sambuc // or explicit specialization because there will be an explicit
1447*0a6a1f1dSLionel Sambuc // node for it elsewhere.
1448*0a6a1f1dSLionel Sambuc case TSK_ExplicitInstantiationDeclaration:
1449*0a6a1f1dSLionel Sambuc case TSK_ExplicitInstantiationDefinition:
1450*0a6a1f1dSLionel Sambuc case TSK_ExplicitSpecialization:
1451*0a6a1f1dSLionel Sambuc break;
1452*0a6a1f1dSLionel Sambuc }
1453*0a6a1f1dSLionel Sambuc }
1454*0a6a1f1dSLionel Sambuc }
1455*0a6a1f1dSLionel Sambuc
1456*0a6a1f1dSLionel Sambuc return true;
1457*0a6a1f1dSLionel Sambuc }
1458*0a6a1f1dSLionel Sambuc
1459*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(VarTemplateDecl, {
1460*0a6a1f1dSLionel Sambuc VarDecl *TempDecl = D->getTemplatedDecl();
1461*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(TempDecl));
1462*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1463*0a6a1f1dSLionel Sambuc
1464*0a6a1f1dSLionel Sambuc // By default, we do not traverse the instantiations of
1465*0a6a1f1dSLionel Sambuc // variable templates since they do not appear in the user code. The
1466*0a6a1f1dSLionel Sambuc // following code optionally traverses them.
1467*0a6a1f1dSLionel Sambuc //
1468*0a6a1f1dSLionel Sambuc // We only traverse the variable instantiations when we see the canonical
1469*0a6a1f1dSLionel Sambuc // declaration of the template, to ensure we only visit them once.
1470*0a6a1f1dSLionel Sambuc if (getDerived().shouldVisitTemplateInstantiations() &&
1471*0a6a1f1dSLionel Sambuc D == D->getCanonicalDecl())
1472*0a6a1f1dSLionel Sambuc TRY_TO(TraverseVariableInstantiations(D));
1473*0a6a1f1dSLionel Sambuc
1474*0a6a1f1dSLionel Sambuc // Note that getInstantiatedFromMemberTemplate() is just a link
1475*0a6a1f1dSLionel Sambuc // from a template instantiation back to the template from which
1476*0a6a1f1dSLionel Sambuc // it was instantiated, and thus should not be traversed.
1477*0a6a1f1dSLionel Sambuc })
1478*0a6a1f1dSLionel Sambuc
1479*0a6a1f1dSLionel Sambuc // A helper method for traversing the instantiations of a
1480*0a6a1f1dSLionel Sambuc // function while skipping its specializations.
1481*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseFunctionInstantiations(FunctionTemplateDecl * D)1482*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseFunctionInstantiations(
1483*0a6a1f1dSLionel Sambuc FunctionTemplateDecl *D) {
1484*0a6a1f1dSLionel Sambuc for (auto *FD : D->specializations()) {
1485*0a6a1f1dSLionel Sambuc for (auto *RD : FD->redecls()) {
1486*0a6a1f1dSLionel Sambuc switch (RD->getTemplateSpecializationKind()) {
1487*0a6a1f1dSLionel Sambuc case TSK_Undeclared:
1488*0a6a1f1dSLionel Sambuc case TSK_ImplicitInstantiation:
1489*0a6a1f1dSLionel Sambuc // We don't know what kind of FunctionDecl this is.
1490*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(RD));
1491*0a6a1f1dSLionel Sambuc break;
1492*0a6a1f1dSLionel Sambuc
1493*0a6a1f1dSLionel Sambuc // No need to visit explicit instantiations, we'll find the node
1494*0a6a1f1dSLionel Sambuc // eventually.
1495*0a6a1f1dSLionel Sambuc // FIXME: This is incorrect; there is no other node for an explicit
1496*0a6a1f1dSLionel Sambuc // instantiation of a function template specialization.
1497*0a6a1f1dSLionel Sambuc case TSK_ExplicitInstantiationDeclaration:
1498*0a6a1f1dSLionel Sambuc case TSK_ExplicitInstantiationDefinition:
1499*0a6a1f1dSLionel Sambuc break;
1500*0a6a1f1dSLionel Sambuc
1501*0a6a1f1dSLionel Sambuc case TSK_ExplicitSpecialization:
1502*0a6a1f1dSLionel Sambuc break;
1503*0a6a1f1dSLionel Sambuc }
1504*0a6a1f1dSLionel Sambuc }
1505*0a6a1f1dSLionel Sambuc }
1506*0a6a1f1dSLionel Sambuc
1507*0a6a1f1dSLionel Sambuc return true;
1508*0a6a1f1dSLionel Sambuc }
1509*0a6a1f1dSLionel Sambuc
1510*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(FunctionTemplateDecl, {
1511*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1512*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1513*0a6a1f1dSLionel Sambuc
1514*0a6a1f1dSLionel Sambuc // By default, we do not traverse the instantiations of
1515*0a6a1f1dSLionel Sambuc // function templates since they do not appear in the user code. The
1516*0a6a1f1dSLionel Sambuc // following code optionally traverses them.
1517*0a6a1f1dSLionel Sambuc //
1518*0a6a1f1dSLionel Sambuc // We only traverse the function instantiations when we see the canonical
1519*0a6a1f1dSLionel Sambuc // declaration of the template, to ensure we only visit them once.
1520*0a6a1f1dSLionel Sambuc if (getDerived().shouldVisitTemplateInstantiations() &&
1521*0a6a1f1dSLionel Sambuc D == D->getCanonicalDecl())
1522*0a6a1f1dSLionel Sambuc TRY_TO(TraverseFunctionInstantiations(D));
1523*0a6a1f1dSLionel Sambuc })
1524*0a6a1f1dSLionel Sambuc
1525*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1526*0a6a1f1dSLionel Sambuc // D is the "T" in something like
1527*0a6a1f1dSLionel Sambuc // template <template <typename> class T> class container { };
1528*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1529*0a6a1f1dSLionel Sambuc if (D->hasDefaultArgument()) {
1530*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1531*0a6a1f1dSLionel Sambuc }
1532*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1533*0a6a1f1dSLionel Sambuc })
1534*0a6a1f1dSLionel Sambuc
1535*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1536*0a6a1f1dSLionel Sambuc // D is the "T" in something like "template<typename T> class vector;"
1537*0a6a1f1dSLionel Sambuc if (D->getTypeForDecl())
1538*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1539*0a6a1f1dSLionel Sambuc if (D->hasDefaultArgument())
1540*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1541*0a6a1f1dSLionel Sambuc })
1542*0a6a1f1dSLionel Sambuc
1543*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(TypedefDecl, {
1544*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1545*0a6a1f1dSLionel Sambuc // We shouldn't traverse D->getTypeForDecl(); it's a result of
1546*0a6a1f1dSLionel Sambuc // declaring the typedef, not something that was written in the
1547*0a6a1f1dSLionel Sambuc // source.
1548*0a6a1f1dSLionel Sambuc })
1549*0a6a1f1dSLionel Sambuc
1550*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(TypeAliasDecl, {
1551*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1552*0a6a1f1dSLionel Sambuc // We shouldn't traverse D->getTypeForDecl(); it's a result of
1553*0a6a1f1dSLionel Sambuc // declaring the type alias, not something that was written in the
1554*0a6a1f1dSLionel Sambuc // source.
1555*0a6a1f1dSLionel Sambuc })
1556*0a6a1f1dSLionel Sambuc
1557*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
1558*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1559*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1560*0a6a1f1dSLionel Sambuc })
1561*0a6a1f1dSLionel Sambuc
1562*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1563*0a6a1f1dSLionel Sambuc // A dependent using declaration which was marked with 'typename'.
1564*0a6a1f1dSLionel Sambuc // template<class T> class A : public B<T> { using typename B<T>::foo; };
1565*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1566*0a6a1f1dSLionel Sambuc // We shouldn't traverse D->getTypeForDecl(); it's a result of
1567*0a6a1f1dSLionel Sambuc // declaring the type, not something that was written in the
1568*0a6a1f1dSLionel Sambuc // source.
1569*0a6a1f1dSLionel Sambuc })
1570*0a6a1f1dSLionel Sambuc
1571*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(EnumDecl, {
1572*0a6a1f1dSLionel Sambuc if (D->getTypeForDecl())
1573*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1574*0a6a1f1dSLionel Sambuc
1575*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1576*0a6a1f1dSLionel Sambuc // The enumerators are already traversed by
1577*0a6a1f1dSLionel Sambuc // decls_begin()/decls_end().
1578*0a6a1f1dSLionel Sambuc })
1579*0a6a1f1dSLionel Sambuc
1580*0a6a1f1dSLionel Sambuc // Helper methods for RecordDecl and its children.
1581*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseRecordHelper(RecordDecl * D)1582*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
1583*0a6a1f1dSLionel Sambuc // We shouldn't traverse D->getTypeForDecl(); it's a result of
1584*0a6a1f1dSLionel Sambuc // declaring the type, not something that was written in the source.
1585*0a6a1f1dSLionel Sambuc
1586*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1587*0a6a1f1dSLionel Sambuc return true;
1588*0a6a1f1dSLionel Sambuc }
1589*0a6a1f1dSLionel Sambuc
1590*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseCXXRecordHelper(CXXRecordDecl * D)1591*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
1592*0a6a1f1dSLionel Sambuc if (!TraverseRecordHelper(D))
1593*0a6a1f1dSLionel Sambuc return false;
1594*0a6a1f1dSLionel Sambuc if (D->isCompleteDefinition()) {
1595*0a6a1f1dSLionel Sambuc for (const auto &I : D->bases()) {
1596*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc()));
1597*0a6a1f1dSLionel Sambuc }
1598*0a6a1f1dSLionel Sambuc // We don't traverse the friends or the conversions, as they are
1599*0a6a1f1dSLionel Sambuc // already in decls_begin()/decls_end().
1600*0a6a1f1dSLionel Sambuc }
1601*0a6a1f1dSLionel Sambuc return true;
1602*0a6a1f1dSLionel Sambuc }
1603*0a6a1f1dSLionel Sambuc
1604*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
1605*0a6a1f1dSLionel Sambuc
1606*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
1607*0a6a1f1dSLionel Sambuc
1608*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, {
1609*0a6a1f1dSLionel Sambuc // For implicit instantiations ("set<int> x;"), we don't want to
1610*0a6a1f1dSLionel Sambuc // recurse at all, since the instatiated class isn't written in
1611*0a6a1f1dSLionel Sambuc // the source code anywhere. (Note the instatiated *type* --
1612*0a6a1f1dSLionel Sambuc // set<int> -- is written, and will still get a callback of
1613*0a6a1f1dSLionel Sambuc // TemplateSpecializationType). For explicit instantiations
1614*0a6a1f1dSLionel Sambuc // ("template set<int>;"), we do need a callback, since this
1615*0a6a1f1dSLionel Sambuc // is the only callback that's made for this instantiation.
1616*0a6a1f1dSLionel Sambuc // We use getTypeAsWritten() to distinguish.
1617*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TSI = D->getTypeAsWritten())
1618*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1619*0a6a1f1dSLionel Sambuc
1620*0a6a1f1dSLionel Sambuc if (!getDerived().shouldVisitTemplateInstantiations() &&
1621*0a6a1f1dSLionel Sambuc D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)
1622*0a6a1f1dSLionel Sambuc // Returning from here skips traversing the
1623*0a6a1f1dSLionel Sambuc // declaration context of the ClassTemplateSpecializationDecl
1624*0a6a1f1dSLionel Sambuc // (embedded in the DEF_TRAVERSE_DECL() macro)
1625*0a6a1f1dSLionel Sambuc // which contains the instantiated members of the class.
1626*0a6a1f1dSLionel Sambuc return true;
1627*0a6a1f1dSLionel Sambuc })
1628*0a6a1f1dSLionel Sambuc
1629*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc * TAL,unsigned Count)1630*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1631*0a6a1f1dSLionel Sambuc const TemplateArgumentLoc *TAL, unsigned Count) {
1632*0a6a1f1dSLionel Sambuc for (unsigned I = 0; I < Count; ++I) {
1633*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1634*0a6a1f1dSLionel Sambuc }
1635*0a6a1f1dSLionel Sambuc return true;
1636*0a6a1f1dSLionel Sambuc }
1637*0a6a1f1dSLionel Sambuc
1638*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ClassTemplatePartialSpecializationDecl, {
1639*0a6a1f1dSLionel Sambuc // The partial specialization.
1640*0a6a1f1dSLionel Sambuc if (TemplateParameterList *TPL = D->getTemplateParameters()) {
1641*0a6a1f1dSLionel Sambuc for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1642*0a6a1f1dSLionel Sambuc I != E; ++I) {
1643*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(*I));
1644*0a6a1f1dSLionel Sambuc }
1645*0a6a1f1dSLionel Sambuc }
1646*0a6a1f1dSLionel Sambuc // The args that remains unspecialized.
1647*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(
1648*0a6a1f1dSLionel Sambuc D->getTemplateArgsAsWritten()->getTemplateArgs(),
1649*0a6a1f1dSLionel Sambuc D->getTemplateArgsAsWritten()->NumTemplateArgs));
1650*0a6a1f1dSLionel Sambuc
1651*0a6a1f1dSLionel Sambuc // Don't need the ClassTemplatePartialSpecializationHelper, even
1652*0a6a1f1dSLionel Sambuc // though that's our parent class -- we already visit all the
1653*0a6a1f1dSLionel Sambuc // template args here.
1654*0a6a1f1dSLionel Sambuc TRY_TO(TraverseCXXRecordHelper(D));
1655*0a6a1f1dSLionel Sambuc
1656*0a6a1f1dSLionel Sambuc // Instantiations will have been visited with the primary template.
1657*0a6a1f1dSLionel Sambuc })
1658*0a6a1f1dSLionel Sambuc
1659*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
1660*0a6a1f1dSLionel Sambuc
1661*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1662*0a6a1f1dSLionel Sambuc // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1663*0a6a1f1dSLionel Sambuc // template <class T> Class A : public Base<T> { using Base<T>::foo; };
1664*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1665*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1666*0a6a1f1dSLionel Sambuc })
1667*0a6a1f1dSLionel Sambuc
1668*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1669*0a6a1f1dSLionel Sambuc
1670*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseDeclaratorHelper(DeclaratorDecl * D)1671*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1672*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1673*0a6a1f1dSLionel Sambuc if (D->getTypeSourceInfo())
1674*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1675*0a6a1f1dSLionel Sambuc else
1676*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(D->getType()));
1677*0a6a1f1dSLionel Sambuc return true;
1678*0a6a1f1dSLionel Sambuc }
1679*0a6a1f1dSLionel Sambuc
1680*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
1681*0a6a1f1dSLionel Sambuc
1682*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(FieldDecl, {
1683*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclaratorHelper(D));
1684*0a6a1f1dSLionel Sambuc if (D->isBitField())
1685*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getBitWidth()));
1686*0a6a1f1dSLionel Sambuc else if (D->hasInClassInitializer())
1687*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getInClassInitializer()));
1688*0a6a1f1dSLionel Sambuc })
1689*0a6a1f1dSLionel Sambuc
1690*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1691*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclaratorHelper(D));
1692*0a6a1f1dSLionel Sambuc if (D->isBitField())
1693*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getBitWidth()));
1694*0a6a1f1dSLionel Sambuc // FIXME: implement the rest.
1695*0a6a1f1dSLionel Sambuc })
1696*0a6a1f1dSLionel Sambuc
1697*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1698*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclaratorHelper(D));
1699*0a6a1f1dSLionel Sambuc if (D->isBitField())
1700*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getBitWidth()));
1701*0a6a1f1dSLionel Sambuc // FIXME: implement the rest.
1702*0a6a1f1dSLionel Sambuc })
1703*0a6a1f1dSLionel Sambuc
1704*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseFunctionHelper(FunctionDecl * D)1705*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1706*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1707*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1708*0a6a1f1dSLionel Sambuc
1709*0a6a1f1dSLionel Sambuc // If we're an explicit template specialization, iterate over the
1710*0a6a1f1dSLionel Sambuc // template args that were explicitly specified. If we were doing
1711*0a6a1f1dSLionel Sambuc // this in typing order, we'd do it between the return type and
1712*0a6a1f1dSLionel Sambuc // the function args, but both are handled by the FunctionTypeLoc
1713*0a6a1f1dSLionel Sambuc // above, so we have to choose one side. I've decided to do before.
1714*0a6a1f1dSLionel Sambuc if (const FunctionTemplateSpecializationInfo *FTSI =
1715*0a6a1f1dSLionel Sambuc D->getTemplateSpecializationInfo()) {
1716*0a6a1f1dSLionel Sambuc if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1717*0a6a1f1dSLionel Sambuc FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1718*0a6a1f1dSLionel Sambuc // A specialization might not have explicit template arguments if it has
1719*0a6a1f1dSLionel Sambuc // a templated return type and concrete arguments.
1720*0a6a1f1dSLionel Sambuc if (const ASTTemplateArgumentListInfo *TALI =
1721*0a6a1f1dSLionel Sambuc FTSI->TemplateArgumentsAsWritten) {
1722*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1723*0a6a1f1dSLionel Sambuc TALI->NumTemplateArgs));
1724*0a6a1f1dSLionel Sambuc }
1725*0a6a1f1dSLionel Sambuc }
1726*0a6a1f1dSLionel Sambuc }
1727*0a6a1f1dSLionel Sambuc
1728*0a6a1f1dSLionel Sambuc // Visit the function type itself, which can be either
1729*0a6a1f1dSLionel Sambuc // FunctionNoProtoType or FunctionProtoType, or a typedef. This
1730*0a6a1f1dSLionel Sambuc // also covers the return type and the function parameters,
1731*0a6a1f1dSLionel Sambuc // including exception specifications.
1732*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1733*0a6a1f1dSLionel Sambuc
1734*0a6a1f1dSLionel Sambuc if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1735*0a6a1f1dSLionel Sambuc // Constructor initializers.
1736*0a6a1f1dSLionel Sambuc for (auto *I : Ctor->inits()) {
1737*0a6a1f1dSLionel Sambuc TRY_TO(TraverseConstructorInitializer(I));
1738*0a6a1f1dSLionel Sambuc }
1739*0a6a1f1dSLionel Sambuc }
1740*0a6a1f1dSLionel Sambuc
1741*0a6a1f1dSLionel Sambuc if (D->isThisDeclarationADefinition()) {
1742*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getBody())); // Function body.
1743*0a6a1f1dSLionel Sambuc }
1744*0a6a1f1dSLionel Sambuc return true;
1745*0a6a1f1dSLionel Sambuc }
1746*0a6a1f1dSLionel Sambuc
1747*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(FunctionDecl, {
1748*0a6a1f1dSLionel Sambuc // We skip decls_begin/decls_end, which are already covered by
1749*0a6a1f1dSLionel Sambuc // TraverseFunctionHelper().
1750*0a6a1f1dSLionel Sambuc return TraverseFunctionHelper(D);
1751*0a6a1f1dSLionel Sambuc })
1752*0a6a1f1dSLionel Sambuc
1753*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(CXXMethodDecl, {
1754*0a6a1f1dSLionel Sambuc // We skip decls_begin/decls_end, which are already covered by
1755*0a6a1f1dSLionel Sambuc // TraverseFunctionHelper().
1756*0a6a1f1dSLionel Sambuc return TraverseFunctionHelper(D);
1757*0a6a1f1dSLionel Sambuc })
1758*0a6a1f1dSLionel Sambuc
1759*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(CXXConstructorDecl, {
1760*0a6a1f1dSLionel Sambuc // We skip decls_begin/decls_end, which are already covered by
1761*0a6a1f1dSLionel Sambuc // TraverseFunctionHelper().
1762*0a6a1f1dSLionel Sambuc return TraverseFunctionHelper(D);
1763*0a6a1f1dSLionel Sambuc })
1764*0a6a1f1dSLionel Sambuc
1765*0a6a1f1dSLionel Sambuc // CXXConversionDecl is the declaration of a type conversion operator.
1766*0a6a1f1dSLionel Sambuc // It's not a cast expression.
1767*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(CXXConversionDecl, {
1768*0a6a1f1dSLionel Sambuc // We skip decls_begin/decls_end, which are already covered by
1769*0a6a1f1dSLionel Sambuc // TraverseFunctionHelper().
1770*0a6a1f1dSLionel Sambuc return TraverseFunctionHelper(D);
1771*0a6a1f1dSLionel Sambuc })
1772*0a6a1f1dSLionel Sambuc
1773*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(CXXDestructorDecl, {
1774*0a6a1f1dSLionel Sambuc // We skip decls_begin/decls_end, which are already covered by
1775*0a6a1f1dSLionel Sambuc // TraverseFunctionHelper().
1776*0a6a1f1dSLionel Sambuc return TraverseFunctionHelper(D);
1777*0a6a1f1dSLionel Sambuc })
1778*0a6a1f1dSLionel Sambuc
1779*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseVarHelper(VarDecl * D)1780*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
1781*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclaratorHelper(D));
1782*0a6a1f1dSLionel Sambuc // Default params are taken care of when we traverse the ParmVarDecl.
1783*0a6a1f1dSLionel Sambuc if (!isa<ParmVarDecl>(D))
1784*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getInit()));
1785*0a6a1f1dSLionel Sambuc return true;
1786*0a6a1f1dSLionel Sambuc }
1787*0a6a1f1dSLionel Sambuc
1788*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
1789*0a6a1f1dSLionel Sambuc
1790*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(VarTemplateSpecializationDecl, {
1791*0a6a1f1dSLionel Sambuc // For implicit instantiations, we don't want to
1792*0a6a1f1dSLionel Sambuc // recurse at all, since the instatiated class isn't written in
1793*0a6a1f1dSLionel Sambuc // the source code anywhere.
1794*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TSI = D->getTypeAsWritten())
1795*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1796*0a6a1f1dSLionel Sambuc
1797*0a6a1f1dSLionel Sambuc if (!getDerived().shouldVisitTemplateInstantiations() &&
1798*0a6a1f1dSLionel Sambuc D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)
1799*0a6a1f1dSLionel Sambuc // Returning from here skips traversing the
1800*0a6a1f1dSLionel Sambuc // declaration context of the VarTemplateSpecializationDecl
1801*0a6a1f1dSLionel Sambuc // (embedded in the DEF_TRAVERSE_DECL() macro).
1802*0a6a1f1dSLionel Sambuc return true;
1803*0a6a1f1dSLionel Sambuc })
1804*0a6a1f1dSLionel Sambuc
1805*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(VarTemplatePartialSpecializationDecl, {
1806*0a6a1f1dSLionel Sambuc // The partial specialization.
1807*0a6a1f1dSLionel Sambuc if (TemplateParameterList *TPL = D->getTemplateParameters()) {
1808*0a6a1f1dSLionel Sambuc for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1809*0a6a1f1dSLionel Sambuc I != E; ++I) {
1810*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(*I));
1811*0a6a1f1dSLionel Sambuc }
1812*0a6a1f1dSLionel Sambuc }
1813*0a6a1f1dSLionel Sambuc // The args that remains unspecialized.
1814*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(
1815*0a6a1f1dSLionel Sambuc D->getTemplateArgsAsWritten()->getTemplateArgs(),
1816*0a6a1f1dSLionel Sambuc D->getTemplateArgsAsWritten()->NumTemplateArgs));
1817*0a6a1f1dSLionel Sambuc
1818*0a6a1f1dSLionel Sambuc // Don't need the VarTemplatePartialSpecializationHelper, even
1819*0a6a1f1dSLionel Sambuc // though that's our parent class -- we already visit all the
1820*0a6a1f1dSLionel Sambuc // template args here.
1821*0a6a1f1dSLionel Sambuc TRY_TO(TraverseVarHelper(D));
1822*0a6a1f1dSLionel Sambuc
1823*0a6a1f1dSLionel Sambuc // Instantiations will have been visited with the primary
1824*0a6a1f1dSLionel Sambuc // template.
1825*0a6a1f1dSLionel Sambuc })
1826*0a6a1f1dSLionel Sambuc
1827*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
1828*0a6a1f1dSLionel Sambuc
1829*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
1830*0a6a1f1dSLionel Sambuc // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
1831*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclaratorHelper(D));
1832*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getDefaultArgument()));
1833*0a6a1f1dSLionel Sambuc })
1834*0a6a1f1dSLionel Sambuc
1835*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_DECL(ParmVarDecl, {
1836*0a6a1f1dSLionel Sambuc TRY_TO(TraverseVarHelper(D));
1837*0a6a1f1dSLionel Sambuc
1838*0a6a1f1dSLionel Sambuc if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
1839*0a6a1f1dSLionel Sambuc !D->hasUnparsedDefaultArg())
1840*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
1841*0a6a1f1dSLionel Sambuc
1842*0a6a1f1dSLionel Sambuc if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
1843*0a6a1f1dSLionel Sambuc !D->hasUnparsedDefaultArg())
1844*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(D->getDefaultArg()));
1845*0a6a1f1dSLionel Sambuc })
1846*0a6a1f1dSLionel Sambuc
1847*0a6a1f1dSLionel Sambuc #undef DEF_TRAVERSE_DECL
1848*0a6a1f1dSLionel Sambuc
1849*0a6a1f1dSLionel Sambuc // ----------------- Stmt traversal -----------------
1850*0a6a1f1dSLionel Sambuc //
1851*0a6a1f1dSLionel Sambuc // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
1852*0a6a1f1dSLionel Sambuc // over the children defined in children() (every stmt defines these,
1853*0a6a1f1dSLionel Sambuc // though sometimes the range is empty). Each individual Traverse*
1854*0a6a1f1dSLionel Sambuc // method only needs to worry about children other than those. To see
1855*0a6a1f1dSLionel Sambuc // what children() does for a given class, see, e.g.,
1856*0a6a1f1dSLionel Sambuc // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
1857*0a6a1f1dSLionel Sambuc
1858*0a6a1f1dSLionel Sambuc // This macro makes available a variable S, the passed-in stmt.
1859*0a6a1f1dSLionel Sambuc #define DEF_TRAVERSE_STMT(STMT, CODE) \
1860*0a6a1f1dSLionel Sambuc template <typename Derived> \
1861*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::Traverse##STMT(STMT *S) { \
1862*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFrom##STMT(S)); \
1863*0a6a1f1dSLionel Sambuc StmtQueueAction StmtQueue(*this); \
1864*0a6a1f1dSLionel Sambuc { CODE; } \
1865*0a6a1f1dSLionel Sambuc for (Stmt::child_range range = S->children(); range; ++range) { \
1866*0a6a1f1dSLionel Sambuc StmtQueue.queue(*range); \
1867*0a6a1f1dSLionel Sambuc } \
1868*0a6a1f1dSLionel Sambuc return true; \
1869*0a6a1f1dSLionel Sambuc }
1870*0a6a1f1dSLionel Sambuc
1871*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(GCCAsmStmt, {
1872*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getAsmString());
1873*0a6a1f1dSLionel Sambuc for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
1874*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getInputConstraintLiteral(I));
1875*0a6a1f1dSLionel Sambuc }
1876*0a6a1f1dSLionel Sambuc for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
1877*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getOutputConstraintLiteral(I));
1878*0a6a1f1dSLionel Sambuc }
1879*0a6a1f1dSLionel Sambuc for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
1880*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getClobberStringLiteral(I));
1881*0a6a1f1dSLionel Sambuc }
1882*0a6a1f1dSLionel Sambuc // children() iterates over inputExpr and outputExpr.
1883*0a6a1f1dSLionel Sambuc })
1884*0a6a1f1dSLionel Sambuc
1885*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(
1886*0a6a1f1dSLionel Sambuc MSAsmStmt,
1887*0a6a1f1dSLionel Sambuc {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc. Once
1888*0a6a1f1dSLionel Sambuc // added this needs to be implemented.
1889*0a6a1f1dSLionel Sambuc })
1890*0a6a1f1dSLionel Sambuc
1891*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXCatchStmt, {
1892*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(S->getExceptionDecl()));
1893*0a6a1f1dSLionel Sambuc // children() iterates over the handler block.
1894*0a6a1f1dSLionel Sambuc })
1895*0a6a1f1dSLionel Sambuc
1896*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(DeclStmt, {
1897*0a6a1f1dSLionel Sambuc for (auto *I : S->decls()) {
1898*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(I));
1899*0a6a1f1dSLionel Sambuc }
1900*0a6a1f1dSLionel Sambuc // Suppress the default iteration over children() by
1901*0a6a1f1dSLionel Sambuc // returning. Here's why: A DeclStmt looks like 'type var [=
1902*0a6a1f1dSLionel Sambuc // initializer]'. The decls above already traverse over the
1903*0a6a1f1dSLionel Sambuc // initializers, so we don't have to do it again (which
1904*0a6a1f1dSLionel Sambuc // children() would do).
1905*0a6a1f1dSLionel Sambuc return true;
1906*0a6a1f1dSLionel Sambuc })
1907*0a6a1f1dSLionel Sambuc
1908*0a6a1f1dSLionel Sambuc // These non-expr stmts (most of them), do not need any action except
1909*0a6a1f1dSLionel Sambuc // iterating over the children.
1910*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(BreakStmt, {})
1911*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXTryStmt, {})
1912*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CaseStmt, {})
1913*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CompoundStmt, {})
1914*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ContinueStmt, {})
1915*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(DefaultStmt, {})
1916*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(DoStmt, {})
1917*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ForStmt, {})
1918*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(GotoStmt, {})
1919*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(IfStmt, {})
1920*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
1921*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(LabelStmt, {})
1922*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(AttributedStmt, {})
1923*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(NullStmt, {})
1924*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
1925*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
1926*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
1927*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
1928*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
1929*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
1930*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
1931*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXForRangeStmt, {})
1932*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
1933*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1934*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
1935*0a6a1f1dSLionel Sambuc })
1936*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ReturnStmt, {})
1937*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(SwitchStmt, {})
1938*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(WhileStmt, {})
1939*0a6a1f1dSLionel Sambuc
1940*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
1941*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1942*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
1943*0a6a1f1dSLionel Sambuc if (S->hasExplicitTemplateArgs()) {
1944*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
1945*0a6a1f1dSLionel Sambuc S->getNumTemplateArgs()));
1946*0a6a1f1dSLionel Sambuc }
1947*0a6a1f1dSLionel Sambuc })
1948*0a6a1f1dSLionel Sambuc
1949*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(DeclRefExpr, {
1950*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1951*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
1952*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
1953*0a6a1f1dSLionel Sambuc S->getNumTemplateArgs()));
1954*0a6a1f1dSLionel Sambuc })
1955*0a6a1f1dSLionel Sambuc
1956*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
1957*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1958*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
1959*0a6a1f1dSLionel Sambuc if (S->hasExplicitTemplateArgs()) {
1960*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(
1961*0a6a1f1dSLionel Sambuc S->getExplicitTemplateArgs().getTemplateArgs(),
1962*0a6a1f1dSLionel Sambuc S->getNumTemplateArgs()));
1963*0a6a1f1dSLionel Sambuc }
1964*0a6a1f1dSLionel Sambuc })
1965*0a6a1f1dSLionel Sambuc
1966*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(MemberExpr, {
1967*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1968*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
1969*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
1970*0a6a1f1dSLionel Sambuc S->getNumTemplateArgs()));
1971*0a6a1f1dSLionel Sambuc })
1972*0a6a1f1dSLionel Sambuc
1973*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(
1974*0a6a1f1dSLionel Sambuc ImplicitCastExpr,
1975*0a6a1f1dSLionel Sambuc {// We don't traverse the cast type, as it's not written in the
1976*0a6a1f1dSLionel Sambuc // source code.
1977*0a6a1f1dSLionel Sambuc })
1978*0a6a1f1dSLionel Sambuc
1979*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CStyleCastExpr, {
1980*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1981*0a6a1f1dSLionel Sambuc })
1982*0a6a1f1dSLionel Sambuc
1983*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
1984*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1985*0a6a1f1dSLionel Sambuc })
1986*0a6a1f1dSLionel Sambuc
1987*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXConstCastExpr, {
1988*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1989*0a6a1f1dSLionel Sambuc })
1990*0a6a1f1dSLionel Sambuc
1991*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
1992*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1993*0a6a1f1dSLionel Sambuc })
1994*0a6a1f1dSLionel Sambuc
1995*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
1996*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1997*0a6a1f1dSLionel Sambuc })
1998*0a6a1f1dSLionel Sambuc
1999*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
2000*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2001*0a6a1f1dSLionel Sambuc })
2002*0a6a1f1dSLionel Sambuc
2003*0a6a1f1dSLionel Sambuc // InitListExpr is a tricky one, because we want to do all our work on
2004*0a6a1f1dSLionel Sambuc // the syntactic form of the listexpr, but this method takes the
2005*0a6a1f1dSLionel Sambuc // semantic form by default. We can't use the macro helper because it
2006*0a6a1f1dSLionel Sambuc // calls WalkUp*() on the semantic form, before our code can convert
2007*0a6a1f1dSLionel Sambuc // to the syntactic form.
2008*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseInitListExpr(InitListExpr * S)2009*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) {
2010*0a6a1f1dSLionel Sambuc if (InitListExpr *Syn = S->getSyntacticForm())
2011*0a6a1f1dSLionel Sambuc S = Syn;
2012*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFromInitListExpr(S));
2013*0a6a1f1dSLionel Sambuc StmtQueueAction StmtQueue(*this);
2014*0a6a1f1dSLionel Sambuc // All we need are the default actions. FIXME: use a helper function.
2015*0a6a1f1dSLionel Sambuc for (Stmt::child_range range = S->children(); range; ++range) {
2016*0a6a1f1dSLionel Sambuc StmtQueue.queue(*range);
2017*0a6a1f1dSLionel Sambuc }
2018*0a6a1f1dSLionel Sambuc return true;
2019*0a6a1f1dSLionel Sambuc }
2020*0a6a1f1dSLionel Sambuc
2021*0a6a1f1dSLionel Sambuc // GenericSelectionExpr is a special case because the types and expressions
2022*0a6a1f1dSLionel Sambuc // are interleaved. We also need to watch out for null types (default
2023*0a6a1f1dSLionel Sambuc // generic associations).
2024*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseGenericSelectionExpr(GenericSelectionExpr * S)2025*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseGenericSelectionExpr(
2026*0a6a1f1dSLionel Sambuc GenericSelectionExpr *S) {
2027*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFromGenericSelectionExpr(S));
2028*0a6a1f1dSLionel Sambuc StmtQueueAction StmtQueue(*this);
2029*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getControllingExpr());
2030*0a6a1f1dSLionel Sambuc for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
2031*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
2032*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
2033*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getAssocExpr(i));
2034*0a6a1f1dSLionel Sambuc }
2035*0a6a1f1dSLionel Sambuc return true;
2036*0a6a1f1dSLionel Sambuc }
2037*0a6a1f1dSLionel Sambuc
2038*0a6a1f1dSLionel Sambuc // PseudoObjectExpr is a special case because of the wierdness with
2039*0a6a1f1dSLionel Sambuc // syntactic expressions and opaque values.
2040*0a6a1f1dSLionel Sambuc template <typename Derived>
2041*0a6a1f1dSLionel Sambuc bool
TraversePseudoObjectExpr(PseudoObjectExpr * S)2042*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::TraversePseudoObjectExpr(PseudoObjectExpr *S) {
2043*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFromPseudoObjectExpr(S));
2044*0a6a1f1dSLionel Sambuc StmtQueueAction StmtQueue(*this);
2045*0a6a1f1dSLionel Sambuc StmtQueue.queue(S->getSyntacticForm());
2046*0a6a1f1dSLionel Sambuc for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2047*0a6a1f1dSLionel Sambuc e = S->semantics_end();
2048*0a6a1f1dSLionel Sambuc i != e; ++i) {
2049*0a6a1f1dSLionel Sambuc Expr *sub = *i;
2050*0a6a1f1dSLionel Sambuc if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2051*0a6a1f1dSLionel Sambuc sub = OVE->getSourceExpr();
2052*0a6a1f1dSLionel Sambuc StmtQueue.queue(sub);
2053*0a6a1f1dSLionel Sambuc }
2054*0a6a1f1dSLionel Sambuc return true;
2055*0a6a1f1dSLionel Sambuc }
2056*0a6a1f1dSLionel Sambuc
2057*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
2058*0a6a1f1dSLionel Sambuc // This is called for code like 'return T()' where T is a built-in
2059*0a6a1f1dSLionel Sambuc // (i.e. non-class) type.
2060*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2061*0a6a1f1dSLionel Sambuc })
2062*0a6a1f1dSLionel Sambuc
2063*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXNewExpr, {
2064*0a6a1f1dSLionel Sambuc // The child-iterator will pick up the other arguments.
2065*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
2066*0a6a1f1dSLionel Sambuc })
2067*0a6a1f1dSLionel Sambuc
2068*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OffsetOfExpr, {
2069*0a6a1f1dSLionel Sambuc // The child-iterator will pick up the expression representing
2070*0a6a1f1dSLionel Sambuc // the field.
2071*0a6a1f1dSLionel Sambuc // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2072*0a6a1f1dSLionel Sambuc // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2073*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2074*0a6a1f1dSLionel Sambuc })
2075*0a6a1f1dSLionel Sambuc
2076*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
2077*0a6a1f1dSLionel Sambuc // The child-iterator will pick up the arg if it's an expression,
2078*0a6a1f1dSLionel Sambuc // but not if it's a type.
2079*0a6a1f1dSLionel Sambuc if (S->isArgumentType())
2080*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2081*0a6a1f1dSLionel Sambuc })
2082*0a6a1f1dSLionel Sambuc
2083*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXTypeidExpr, {
2084*0a6a1f1dSLionel Sambuc // The child-iterator will pick up the arg if it's an expression,
2085*0a6a1f1dSLionel Sambuc // but not if it's a type.
2086*0a6a1f1dSLionel Sambuc if (S->isTypeOperand())
2087*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2088*0a6a1f1dSLionel Sambuc })
2089*0a6a1f1dSLionel Sambuc
2090*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2091*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2092*0a6a1f1dSLionel Sambuc })
2093*0a6a1f1dSLionel Sambuc
2094*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXUuidofExpr, {
2095*0a6a1f1dSLionel Sambuc // The child-iterator will pick up the arg if it's an expression,
2096*0a6a1f1dSLionel Sambuc // but not if it's a type.
2097*0a6a1f1dSLionel Sambuc if (S->isTypeOperand())
2098*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2099*0a6a1f1dSLionel Sambuc })
2100*0a6a1f1dSLionel Sambuc
2101*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(TypeTraitExpr, {
2102*0a6a1f1dSLionel Sambuc for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2103*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2104*0a6a1f1dSLionel Sambuc })
2105*0a6a1f1dSLionel Sambuc
2106*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
2107*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2108*0a6a1f1dSLionel Sambuc })
2109*0a6a1f1dSLionel Sambuc
2110*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2111*0a6a1f1dSLionel Sambuc { StmtQueue.queue(S->getQueriedExpression()); })
2112*0a6a1f1dSLionel Sambuc
2113*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(VAArgExpr, {
2114*0a6a1f1dSLionel Sambuc // The child-iterator will pick up the expression argument.
2115*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2116*0a6a1f1dSLionel Sambuc })
2117*0a6a1f1dSLionel Sambuc
2118*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
2119*0a6a1f1dSLionel Sambuc // This is called for code like 'return T()' where T is a class type.
2120*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2121*0a6a1f1dSLionel Sambuc })
2122*0a6a1f1dSLionel Sambuc
2123*0a6a1f1dSLionel Sambuc // Walk only the visible parts of lambda expressions.
2124*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseLambdaExpr(LambdaExpr * S)2125*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseLambdaExpr(LambdaExpr *S) {
2126*0a6a1f1dSLionel Sambuc TRY_TO(WalkUpFromLambdaExpr(S));
2127*0a6a1f1dSLionel Sambuc
2128*0a6a1f1dSLionel Sambuc for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
2129*0a6a1f1dSLionel Sambuc CEnd = S->explicit_capture_end();
2130*0a6a1f1dSLionel Sambuc C != CEnd; ++C) {
2131*0a6a1f1dSLionel Sambuc TRY_TO(TraverseLambdaCapture(S, C));
2132*0a6a1f1dSLionel Sambuc }
2133*0a6a1f1dSLionel Sambuc
2134*0a6a1f1dSLionel Sambuc TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2135*0a6a1f1dSLionel Sambuc FunctionProtoTypeLoc Proto = TL.castAs<FunctionProtoTypeLoc>();
2136*0a6a1f1dSLionel Sambuc
2137*0a6a1f1dSLionel Sambuc if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2138*0a6a1f1dSLionel Sambuc // Visit the whole type.
2139*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TL));
2140*0a6a1f1dSLionel Sambuc } else {
2141*0a6a1f1dSLionel Sambuc if (S->hasExplicitParameters()) {
2142*0a6a1f1dSLionel Sambuc // Visit parameters.
2143*0a6a1f1dSLionel Sambuc for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
2144*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(Proto.getParam(I)));
2145*0a6a1f1dSLionel Sambuc }
2146*0a6a1f1dSLionel Sambuc } else if (S->hasExplicitResultType()) {
2147*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
2148*0a6a1f1dSLionel Sambuc }
2149*0a6a1f1dSLionel Sambuc
2150*0a6a1f1dSLionel Sambuc auto *T = Proto.getTypePtr();
2151*0a6a1f1dSLionel Sambuc for (const auto &E : T->exceptions()) {
2152*0a6a1f1dSLionel Sambuc TRY_TO(TraverseType(E));
2153*0a6a1f1dSLionel Sambuc }
2154*0a6a1f1dSLionel Sambuc
2155*0a6a1f1dSLionel Sambuc if (Expr *NE = T->getNoexceptExpr())
2156*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(NE));
2157*0a6a1f1dSLionel Sambuc }
2158*0a6a1f1dSLionel Sambuc
2159*0a6a1f1dSLionel Sambuc TRY_TO(TraverseLambdaBody(S));
2160*0a6a1f1dSLionel Sambuc return true;
2161*0a6a1f1dSLionel Sambuc }
2162*0a6a1f1dSLionel Sambuc
2163*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
2164*0a6a1f1dSLionel Sambuc // This is called for code like 'T()', where T is a template argument.
2165*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2166*0a6a1f1dSLionel Sambuc })
2167*0a6a1f1dSLionel Sambuc
2168*0a6a1f1dSLionel Sambuc // These expressions all might take explicit template arguments.
2169*0a6a1f1dSLionel Sambuc // We traverse those if so. FIXME: implement these.
2170*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2171*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CallExpr, {})
2172*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
2173*0a6a1f1dSLionel Sambuc
2174*0a6a1f1dSLionel Sambuc // These exprs (most of them), do not need any action except iterating
2175*0a6a1f1dSLionel Sambuc // over the children.
2176*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2177*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
2178*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(BlockExpr, {
2179*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDecl(S->getBlockDecl()));
2180*0a6a1f1dSLionel Sambuc return true; // no child statements to loop through.
2181*0a6a1f1dSLionel Sambuc })
2182*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ChooseExpr, {})
2183*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2184*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2185*0a6a1f1dSLionel Sambuc })
2186*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2187*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2188*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
2189*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
2190*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2191*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2192*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2193*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
2194*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2195*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2196*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2197*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2198*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2199*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2200*0a6a1f1dSLionel Sambuc })
2201*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXThisExpr, {})
2202*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2203*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2204*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2205*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2206*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(GNUNullExpr, {})
2207*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2208*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
2209*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2210*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2211*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2212*0a6a1f1dSLionel Sambuc })
2213*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2214*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
2215*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2216*0a6a1f1dSLionel Sambuc if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2217*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2218*0a6a1f1dSLionel Sambuc })
2219*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
2220*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2221*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2222*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2223*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
2224*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2225*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2226*0a6a1f1dSLionel Sambuc })
2227*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ParenExpr, {})
2228*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ParenListExpr, {})
2229*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(PredefinedExpr, {})
2230*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2231*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2232*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(StmtExpr, {})
2233*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2234*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2235*0a6a1f1dSLionel Sambuc if (S->hasExplicitTemplateArgs()) {
2236*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2237*0a6a1f1dSLionel Sambuc S->getNumTemplateArgs()));
2238*0a6a1f1dSLionel Sambuc }
2239*0a6a1f1dSLionel Sambuc })
2240*0a6a1f1dSLionel Sambuc
2241*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2242*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2243*0a6a1f1dSLionel Sambuc if (S->hasExplicitTemplateArgs()) {
2244*0a6a1f1dSLionel Sambuc TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2245*0a6a1f1dSLionel Sambuc S->getNumTemplateArgs()));
2246*0a6a1f1dSLionel Sambuc }
2247*0a6a1f1dSLionel Sambuc })
2248*0a6a1f1dSLionel Sambuc
2249*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(SEHTryStmt, {})
2250*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(SEHExceptStmt, {})
2251*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
2252*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
2253*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
2254*0a6a1f1dSLionel Sambuc
2255*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2256*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
2257*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(TypoExpr, {})
2258*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
2259*0a6a1f1dSLionel Sambuc
2260*0a6a1f1dSLionel Sambuc // These operators (all of them) do not need any action except
2261*0a6a1f1dSLionel Sambuc // iterating over the children.
2262*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2263*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ConditionalOperator, {})
2264*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(UnaryOperator, {})
2265*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(BinaryOperator, {})
2266*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2267*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2268*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2269*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2270*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2271*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2272*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2273*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
2274*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CXXFoldExpr, {})
2275*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(AtomicExpr, {})
2276*0a6a1f1dSLionel Sambuc
2277*0a6a1f1dSLionel Sambuc // These literals (all of them) do not need any action.
2278*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(IntegerLiteral, {})
2279*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(CharacterLiteral, {})
2280*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(FloatingLiteral, {})
2281*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
2282*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(StringLiteral, {})
2283*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
2284*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
2285*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
2286*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
2287*0a6a1f1dSLionel Sambuc
2288*0a6a1f1dSLionel Sambuc // Traverse OpenCL: AsType, Convert.
2289*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(AsTypeExpr, {})
2290*0a6a1f1dSLionel Sambuc
2291*0a6a1f1dSLionel Sambuc // OpenMP directives.
2292*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseOMPExecutableDirective(OMPExecutableDirective * S)2293*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
2294*0a6a1f1dSLionel Sambuc OMPExecutableDirective *S) {
2295*0a6a1f1dSLionel Sambuc for (auto *C : S->clauses()) {
2296*0a6a1f1dSLionel Sambuc TRY_TO(TraverseOMPClause(C));
2297*0a6a1f1dSLionel Sambuc }
2298*0a6a1f1dSLionel Sambuc return true;
2299*0a6a1f1dSLionel Sambuc }
2300*0a6a1f1dSLionel Sambuc
2301*0a6a1f1dSLionel Sambuc template <typename Derived>
2302*0a6a1f1dSLionel Sambuc bool
TraverseOMPLoopDirective(OMPLoopDirective * S)2303*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
2304*0a6a1f1dSLionel Sambuc return TraverseOMPExecutableDirective(S);
2305*0a6a1f1dSLionel Sambuc }
2306*0a6a1f1dSLionel Sambuc
2307*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPParallelDirective,
2308*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2309*0a6a1f1dSLionel Sambuc
2310*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPSimdDirective,
2311*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2312*0a6a1f1dSLionel Sambuc
2313*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPForDirective,
2314*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2315*0a6a1f1dSLionel Sambuc
2316*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPForSimdDirective,
2317*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2318*0a6a1f1dSLionel Sambuc
2319*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPSectionsDirective,
2320*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2321*0a6a1f1dSLionel Sambuc
2322*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPSectionDirective,
2323*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2324*0a6a1f1dSLionel Sambuc
2325*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPSingleDirective,
2326*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2327*0a6a1f1dSLionel Sambuc
2328*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPMasterDirective,
2329*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2330*0a6a1f1dSLionel Sambuc
2331*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPCriticalDirective, {
2332*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
2333*0a6a1f1dSLionel Sambuc TRY_TO(TraverseOMPExecutableDirective(S));
2334*0a6a1f1dSLionel Sambuc })
2335*0a6a1f1dSLionel Sambuc
2336*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPParallelForDirective,
2337*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2338*0a6a1f1dSLionel Sambuc
2339*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
2340*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2341*0a6a1f1dSLionel Sambuc
2342*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
2343*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2344*0a6a1f1dSLionel Sambuc
2345*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPTaskDirective,
2346*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2347*0a6a1f1dSLionel Sambuc
2348*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
2349*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2350*0a6a1f1dSLionel Sambuc
2351*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPBarrierDirective,
2352*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2353*0a6a1f1dSLionel Sambuc
2354*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
2355*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2356*0a6a1f1dSLionel Sambuc
2357*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPFlushDirective,
2358*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2359*0a6a1f1dSLionel Sambuc
2360*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPOrderedDirective,
2361*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2362*0a6a1f1dSLionel Sambuc
2363*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPAtomicDirective,
2364*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2365*0a6a1f1dSLionel Sambuc
2366*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPTargetDirective,
2367*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2368*0a6a1f1dSLionel Sambuc
2369*0a6a1f1dSLionel Sambuc DEF_TRAVERSE_STMT(OMPTeamsDirective,
2370*0a6a1f1dSLionel Sambuc { TRY_TO(TraverseOMPExecutableDirective(S)); })
2371*0a6a1f1dSLionel Sambuc
2372*0a6a1f1dSLionel Sambuc // OpenMP clauses.
2373*0a6a1f1dSLionel Sambuc template <typename Derived>
TraverseOMPClause(OMPClause * C)2374*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
2375*0a6a1f1dSLionel Sambuc if (!C)
2376*0a6a1f1dSLionel Sambuc return true;
2377*0a6a1f1dSLionel Sambuc switch (C->getClauseKind()) {
2378*0a6a1f1dSLionel Sambuc #define OPENMP_CLAUSE(Name, Class) \
2379*0a6a1f1dSLionel Sambuc case OMPC_##Name: \
2380*0a6a1f1dSLionel Sambuc TRY_TO(Visit##Class(static_cast<Class *>(C))); \
2381*0a6a1f1dSLionel Sambuc break;
2382*0a6a1f1dSLionel Sambuc #include "clang/Basic/OpenMPKinds.def"
2383*0a6a1f1dSLionel Sambuc case OMPC_threadprivate:
2384*0a6a1f1dSLionel Sambuc case OMPC_unknown:
2385*0a6a1f1dSLionel Sambuc break;
2386*0a6a1f1dSLionel Sambuc }
2387*0a6a1f1dSLionel Sambuc return true;
2388*0a6a1f1dSLionel Sambuc }
2389*0a6a1f1dSLionel Sambuc
2390*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPIfClause(OMPIfClause * C)2391*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
2392*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(C->getCondition()));
2393*0a6a1f1dSLionel Sambuc return true;
2394*0a6a1f1dSLionel Sambuc }
2395*0a6a1f1dSLionel Sambuc
2396*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPFinalClause(OMPFinalClause * C)2397*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
2398*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(C->getCondition()));
2399*0a6a1f1dSLionel Sambuc return true;
2400*0a6a1f1dSLionel Sambuc }
2401*0a6a1f1dSLionel Sambuc
2402*0a6a1f1dSLionel Sambuc template <typename Derived>
2403*0a6a1f1dSLionel Sambuc bool
VisitOMPNumThreadsClause(OMPNumThreadsClause * C)2404*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
2405*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(C->getNumThreads()));
2406*0a6a1f1dSLionel Sambuc return true;
2407*0a6a1f1dSLionel Sambuc }
2408*0a6a1f1dSLionel Sambuc
2409*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPSafelenClause(OMPSafelenClause * C)2410*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
2411*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(C->getSafelen()));
2412*0a6a1f1dSLionel Sambuc return true;
2413*0a6a1f1dSLionel Sambuc }
2414*0a6a1f1dSLionel Sambuc
2415*0a6a1f1dSLionel Sambuc template <typename Derived>
2416*0a6a1f1dSLionel Sambuc bool
VisitOMPCollapseClause(OMPCollapseClause * C)2417*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
2418*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(C->getNumForLoops()));
2419*0a6a1f1dSLionel Sambuc return true;
2420*0a6a1f1dSLionel Sambuc }
2421*0a6a1f1dSLionel Sambuc
2422*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPDefaultClause(OMPDefaultClause *)2423*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
2424*0a6a1f1dSLionel Sambuc return true;
2425*0a6a1f1dSLionel Sambuc }
2426*0a6a1f1dSLionel Sambuc
2427*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPProcBindClause(OMPProcBindClause *)2428*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
2429*0a6a1f1dSLionel Sambuc return true;
2430*0a6a1f1dSLionel Sambuc }
2431*0a6a1f1dSLionel Sambuc
2432*0a6a1f1dSLionel Sambuc template <typename Derived>
2433*0a6a1f1dSLionel Sambuc bool
VisitOMPScheduleClause(OMPScheduleClause * C)2434*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
2435*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(C->getChunkSize()));
2436*0a6a1f1dSLionel Sambuc return true;
2437*0a6a1f1dSLionel Sambuc }
2438*0a6a1f1dSLionel Sambuc
2439*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPOrderedClause(OMPOrderedClause *)2440*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
2441*0a6a1f1dSLionel Sambuc return true;
2442*0a6a1f1dSLionel Sambuc }
2443*0a6a1f1dSLionel Sambuc
2444*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPNowaitClause(OMPNowaitClause *)2445*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
2446*0a6a1f1dSLionel Sambuc return true;
2447*0a6a1f1dSLionel Sambuc }
2448*0a6a1f1dSLionel Sambuc
2449*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPUntiedClause(OMPUntiedClause *)2450*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
2451*0a6a1f1dSLionel Sambuc return true;
2452*0a6a1f1dSLionel Sambuc }
2453*0a6a1f1dSLionel Sambuc
2454*0a6a1f1dSLionel Sambuc template <typename Derived>
2455*0a6a1f1dSLionel Sambuc bool
VisitOMPMergeableClause(OMPMergeableClause *)2456*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
2457*0a6a1f1dSLionel Sambuc return true;
2458*0a6a1f1dSLionel Sambuc }
2459*0a6a1f1dSLionel Sambuc
2460*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPReadClause(OMPReadClause *)2461*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
2462*0a6a1f1dSLionel Sambuc return true;
2463*0a6a1f1dSLionel Sambuc }
2464*0a6a1f1dSLionel Sambuc
2465*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPWriteClause(OMPWriteClause *)2466*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
2467*0a6a1f1dSLionel Sambuc return true;
2468*0a6a1f1dSLionel Sambuc }
2469*0a6a1f1dSLionel Sambuc
2470*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPUpdateClause(OMPUpdateClause *)2471*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
2472*0a6a1f1dSLionel Sambuc return true;
2473*0a6a1f1dSLionel Sambuc }
2474*0a6a1f1dSLionel Sambuc
2475*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPCaptureClause(OMPCaptureClause *)2476*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2477*0a6a1f1dSLionel Sambuc return true;
2478*0a6a1f1dSLionel Sambuc }
2479*0a6a1f1dSLionel Sambuc
2480*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPSeqCstClause(OMPSeqCstClause *)2481*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2482*0a6a1f1dSLionel Sambuc return true;
2483*0a6a1f1dSLionel Sambuc }
2484*0a6a1f1dSLionel Sambuc
2485*0a6a1f1dSLionel Sambuc template <typename Derived>
2486*0a6a1f1dSLionel Sambuc template <typename T>
VisitOMPClauseList(T * Node)2487*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
2488*0a6a1f1dSLionel Sambuc for (auto *E : Node->varlists()) {
2489*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(E));
2490*0a6a1f1dSLionel Sambuc }
2491*0a6a1f1dSLionel Sambuc return true;
2492*0a6a1f1dSLionel Sambuc }
2493*0a6a1f1dSLionel Sambuc
2494*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPPrivateClause(OMPPrivateClause * C)2495*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
2496*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2497*0a6a1f1dSLionel Sambuc for (auto *E : C->private_copies()) {
2498*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(E));
2499*0a6a1f1dSLionel Sambuc }
2500*0a6a1f1dSLionel Sambuc return true;
2501*0a6a1f1dSLionel Sambuc }
2502*0a6a1f1dSLionel Sambuc
2503*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPFirstprivateClause(OMPFirstprivateClause * C)2504*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
2505*0a6a1f1dSLionel Sambuc OMPFirstprivateClause *C) {
2506*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2507*0a6a1f1dSLionel Sambuc for (auto *E : C->private_copies()) {
2508*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(E));
2509*0a6a1f1dSLionel Sambuc }
2510*0a6a1f1dSLionel Sambuc for (auto *E : C->inits()) {
2511*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(E));
2512*0a6a1f1dSLionel Sambuc }
2513*0a6a1f1dSLionel Sambuc return true;
2514*0a6a1f1dSLionel Sambuc }
2515*0a6a1f1dSLionel Sambuc
2516*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPLastprivateClause(OMPLastprivateClause * C)2517*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
2518*0a6a1f1dSLionel Sambuc OMPLastprivateClause *C) {
2519*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2520*0a6a1f1dSLionel Sambuc return true;
2521*0a6a1f1dSLionel Sambuc }
2522*0a6a1f1dSLionel Sambuc
2523*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPSharedClause(OMPSharedClause * C)2524*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
2525*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2526*0a6a1f1dSLionel Sambuc return true;
2527*0a6a1f1dSLionel Sambuc }
2528*0a6a1f1dSLionel Sambuc
2529*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPLinearClause(OMPLinearClause * C)2530*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
2531*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(C->getStep()));
2532*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2533*0a6a1f1dSLionel Sambuc return true;
2534*0a6a1f1dSLionel Sambuc }
2535*0a6a1f1dSLionel Sambuc
2536*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPAlignedClause(OMPAlignedClause * C)2537*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
2538*0a6a1f1dSLionel Sambuc TRY_TO(TraverseStmt(C->getAlignment()));
2539*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2540*0a6a1f1dSLionel Sambuc return true;
2541*0a6a1f1dSLionel Sambuc }
2542*0a6a1f1dSLionel Sambuc
2543*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPCopyinClause(OMPCopyinClause * C)2544*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
2545*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2546*0a6a1f1dSLionel Sambuc return true;
2547*0a6a1f1dSLionel Sambuc }
2548*0a6a1f1dSLionel Sambuc
2549*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPCopyprivateClause(OMPCopyprivateClause * C)2550*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
2551*0a6a1f1dSLionel Sambuc OMPCopyprivateClause *C) {
2552*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2553*0a6a1f1dSLionel Sambuc return true;
2554*0a6a1f1dSLionel Sambuc }
2555*0a6a1f1dSLionel Sambuc
2556*0a6a1f1dSLionel Sambuc template <typename Derived>
2557*0a6a1f1dSLionel Sambuc bool
VisitOMPReductionClause(OMPReductionClause * C)2558*0a6a1f1dSLionel Sambuc RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
2559*0a6a1f1dSLionel Sambuc TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
2560*0a6a1f1dSLionel Sambuc TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
2561*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2562*0a6a1f1dSLionel Sambuc return true;
2563*0a6a1f1dSLionel Sambuc }
2564*0a6a1f1dSLionel Sambuc
2565*0a6a1f1dSLionel Sambuc template <typename Derived>
VisitOMPFlushClause(OMPFlushClause * C)2566*0a6a1f1dSLionel Sambuc bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
2567*0a6a1f1dSLionel Sambuc TRY_TO(VisitOMPClauseList(C));
2568*0a6a1f1dSLionel Sambuc return true;
2569*0a6a1f1dSLionel Sambuc }
2570*0a6a1f1dSLionel Sambuc
2571*0a6a1f1dSLionel Sambuc // FIXME: look at the following tricky-seeming exprs to see if we
2572*0a6a1f1dSLionel Sambuc // need to recurse on anything. These are ones that have methods
2573*0a6a1f1dSLionel Sambuc // returning decls or qualtypes or nestednamespecifier -- though I'm
2574*0a6a1f1dSLionel Sambuc // not sure if they own them -- or just seemed very complicated, or
2575*0a6a1f1dSLionel Sambuc // had lots of sub-types to explore.
2576*0a6a1f1dSLionel Sambuc //
2577*0a6a1f1dSLionel Sambuc // VisitOverloadExpr and its children: recurse on template args? etc?
2578*0a6a1f1dSLionel Sambuc
2579*0a6a1f1dSLionel Sambuc // FIXME: go through all the stmts and exprs again, and see which of them
2580*0a6a1f1dSLionel Sambuc // create new types, and recurse on the types (TypeLocs?) of those.
2581*0a6a1f1dSLionel Sambuc // Candidates:
2582*0a6a1f1dSLionel Sambuc //
2583*0a6a1f1dSLionel Sambuc // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
2584*0a6a1f1dSLionel Sambuc // http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
2585*0a6a1f1dSLionel Sambuc // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
2586*0a6a1f1dSLionel Sambuc // Every class that has getQualifier.
2587*0a6a1f1dSLionel Sambuc
2588*0a6a1f1dSLionel Sambuc #undef DEF_TRAVERSE_STMT
2589*0a6a1f1dSLionel Sambuc
2590*0a6a1f1dSLionel Sambuc #undef TRY_TO
2591*0a6a1f1dSLionel Sambuc
2592*0a6a1f1dSLionel Sambuc #undef RecursiveASTVisitor
2593*0a6a1f1dSLionel Sambuc
2594*0a6a1f1dSLionel Sambuc } // end namespace clang
2595*0a6a1f1dSLionel Sambuc
2596*0a6a1f1dSLionel Sambuc #endif // LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H
2597