blob: 46d2f8604137fe0df2608f398911351e7665c8c0 [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001//===--- DataRecursiveASTVisitor.h - Data-Recursive AST Visitor -*- C++ -*-===//
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Stephen Hines651f13c2014-04-23 16:59:28 -070010// This file defines the DataRecursiveASTVisitor interface, which recursively
11// traverses the entire AST, using data recursion for Stmts/Exprs.
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000012//
13//===----------------------------------------------------------------------===//
Stephen Hines651f13c2014-04-23 16:59:28 -070014#ifndef LLVM_CLANG_AST_DATARECURSIVEASTVISITOR_H
15#define LLVM_CLANG_AST_DATARECURSIVEASTVISITOR_H
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000016
Stephen Hines651f13c2014-04-23 16:59:28 -070017#include "clang/AST/Attr.h"
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000018#include "clang/AST/Decl.h"
19#include "clang/AST/DeclCXX.h"
20#include "clang/AST/DeclFriend.h"
21#include "clang/AST/DeclObjC.h"
Alexey Bataevc6400582013-03-22 06:34:35 +000022#include "clang/AST/DeclOpenMP.h"
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000023#include "clang/AST/DeclTemplate.h"
24#include "clang/AST/Expr.h"
25#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
27#include "clang/AST/NestedNameSpecifier.h"
28#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
Alexey Bataev4fa7eab2013-07-19 03:13:43 +000031#include "clang/AST/StmtOpenMP.h"
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000032#include "clang/AST/TemplateBase.h"
33#include "clang/AST/TemplateName.h"
34#include "clang/AST/Type.h"
35#include "clang/AST/TypeLoc.h"
36
37// The following three macros are used for meta programming. The code
38// using them is responsible for defining macro OPERATOR().
39
40// All unary operators.
Stephen Hines6bcf27b2014-05-29 04:14:42 -070041#define UNARYOP_LIST() \
42 OPERATOR(PostInc) OPERATOR(PostDec) OPERATOR(PreInc) OPERATOR(PreDec) \
43 OPERATOR(AddrOf) OPERATOR(Deref) OPERATOR(Plus) OPERATOR(Minus) \
44 OPERATOR(Not) OPERATOR(LNot) OPERATOR(Real) OPERATOR(Imag) \
45 OPERATOR(Extension)
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000046
47// All binary operators (excluding compound assign operators).
Stephen Hines6bcf27b2014-05-29 04:14:42 -070048#define BINOP_LIST() \
49 OPERATOR(PtrMemD) OPERATOR(PtrMemI) OPERATOR(Mul) OPERATOR(Div) \
50 OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) OPERATOR(Shr) \
51 OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) OPERATOR(GE) OPERATOR(EQ) \
52 OPERATOR(NE) OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) OPERATOR(LAnd) \
53 OPERATOR(LOr) OPERATOR(Assign) OPERATOR(Comma)
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000054
55// All compound assign operators.
Stephen Hines6bcf27b2014-05-29 04:14:42 -070056#define CAO_LIST() \
57 OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \
58 OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor)
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000059
60namespace clang {
61
Stephen Hines6bcf27b2014-05-29 04:14:42 -070062// Reduce the diff between RecursiveASTVisitor / DataRecursiveASTVisitor to
63// make it easier to track changes and keep the two in sync.
64#define RecursiveASTVisitor DataRecursiveASTVisitor
65
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000066// A helper macro to implement short-circuiting when recursing. It
67// invokes CALL_EXPR, which must be a method call, on the derived
Stephen Hines6bcf27b2014-05-29 04:14:42 -070068// object (s.t. a user of RecursiveASTVisitor can override the method
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000069// in CALL_EXPR).
Stephen Hines6bcf27b2014-05-29 04:14:42 -070070#define TRY_TO(CALL_EXPR) \
71 do { \
72 if (!getDerived().CALL_EXPR) \
73 return false; \
74 } while (0)
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +000075
76/// \brief A class that does preorder depth-first traversal on the
77/// entire Clang AST and visits each node.
78///
79/// This class performs three distinct tasks:
80/// 1. traverse the AST (i.e. go to each node);
81/// 2. at a given node, walk up the class hierarchy, starting from
82/// the node's dynamic type, until the top-most class (e.g. Stmt,
83/// Decl, or Type) is reached.
84/// 3. given a (node, class) combination, where 'class' is some base
85/// class of the dynamic type of 'node', call a user-overridable
86/// function to actually visit the node.
87///
88/// These tasks are done by three groups of methods, respectively:
89/// 1. TraverseDecl(Decl *x) does task #1. It is the entry point
90/// for traversing an AST rooted at x. This method simply
91/// dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo
92/// is the dynamic type of *x, which calls WalkUpFromFoo(x) and
93/// then recursively visits the child nodes of x.
94/// TraverseStmt(Stmt *x) and TraverseType(QualType x) work
95/// similarly.
96/// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit
97/// any child node of x. Instead, it first calls WalkUpFromBar(x)
98/// where Bar is the direct parent class of Foo (unless Foo has
99/// no parent), and then calls VisitFoo(x) (see the next list item).
100/// 3. VisitFoo(Foo *x) does task #3.
101///
102/// These three method groups are tiered (Traverse* > WalkUpFrom* >
103/// Visit*). A method (e.g. Traverse*) may call methods from the same
104/// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*).
105/// It may not call methods from a higher tier.
106///
107/// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar
108/// is Foo's super class) before calling VisitFoo(), the result is
109/// that the Visit*() methods for a given node are called in the
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700110/// top-down order (e.g. for a node of type NamespaceDecl, the order will
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000111/// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()).
112///
113/// This scheme guarantees that all Visit*() calls for the same AST
114/// node are grouped together. In other words, Visit*() methods for
115/// different nodes are never interleaved.
116///
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000117/// Stmts are traversed internally using a data queue to avoid a stack overflow
118/// with hugely nested ASTs.
119///
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000120/// Clients of this visitor should subclass the visitor (providing
121/// themselves as the template argument, using the curiously recurring
122/// template pattern) and override any of the Traverse*, WalkUpFrom*,
123/// and Visit* methods for declarations, types, statements,
124/// expressions, or other AST nodes where the visitor should customize
125/// behavior. Most users only need to override Visit*. Advanced
126/// users may override Traverse* and WalkUpFrom* to implement custom
127/// traversal strategies. Returning false from one of these overridden
128/// functions will abort the entire traversal.
129///
130/// By default, this visitor tries to visit every part of the explicit
131/// source code exactly once. The default policy towards templates
132/// is to descend into the 'pattern' class or function body, not any
133/// explicit or implicit instantiations. Explicit specializations
134/// are still visited, and the patterns of partial specializations
135/// are visited separately. This behavior can be changed by
136/// overriding shouldVisitTemplateInstantiations() in the derived class
137/// to return true, in which case all known implicit and explicit
138/// instantiations will be visited at the same time as the pattern
139/// from which they were produced.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700140template <typename Derived> class RecursiveASTVisitor {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000141public:
142 /// \brief Return a reference to the derived class.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700143 Derived &getDerived() { return *static_cast<Derived *>(this); }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000144
145 /// \brief Return whether this visitor should recurse into
146 /// template instantiations.
147 bool shouldVisitTemplateInstantiations() const { return false; }
148
149 /// \brief Return whether this visitor should recurse into the types of
150 /// TypeLocs.
151 bool shouldWalkTypesOfTypeLocs() const { return true; }
152
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000153 /// \brief Recursively visit a statement or expression, by
154 /// dispatching to Traverse*() based on the argument's dynamic type.
155 ///
156 /// \returns false if the visitation was terminated early, true
157 /// otherwise (including when the argument is NULL).
158 bool TraverseStmt(Stmt *S);
159
160 /// \brief Recursively visit a type, by dispatching to
161 /// Traverse*Type() based on the argument's getTypeClass() property.
162 ///
163 /// \returns false if the visitation was terminated early, true
164 /// otherwise (including when the argument is a Null type).
165 bool TraverseType(QualType T);
166
167 /// \brief Recursively visit a type with location, by dispatching to
168 /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
169 ///
170 /// \returns false if the visitation was terminated early, true
171 /// otherwise (including when the argument is a Null type location).
172 bool TraverseTypeLoc(TypeLoc TL);
173
Stephen Hines651f13c2014-04-23 16:59:28 -0700174 /// \brief Recursively visit an attribute, by dispatching to
175 /// Traverse*Attr() based on the argument's dynamic type.
176 ///
177 /// \returns false if the visitation was terminated early, true
178 /// otherwise (including when the argument is a Null type location).
179 bool TraverseAttr(Attr *At);
180
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000181 /// \brief Recursively visit a declaration, by dispatching to
182 /// Traverse*Decl() based on the argument's dynamic type.
183 ///
184 /// \returns false if the visitation was terminated early, true
185 /// otherwise (including when the argument is NULL).
186 bool TraverseDecl(Decl *D);
187
188 /// \brief Recursively visit a C++ nested-name-specifier.
189 ///
190 /// \returns false if the visitation was terminated early, true otherwise.
191 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
192
193 /// \brief Recursively visit a C++ nested-name-specifier with location
194 /// information.
195 ///
196 /// \returns false if the visitation was terminated early, true otherwise.
197 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
198
199 /// \brief Recursively visit a name with its location information.
200 ///
201 /// \returns false if the visitation was terminated early, true otherwise.
202 bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo);
203
204 /// \brief Recursively visit a template name and dispatch to the
205 /// appropriate method.
206 ///
207 /// \returns false if the visitation was terminated early, true otherwise.
208 bool TraverseTemplateName(TemplateName Template);
209
210 /// \brief Recursively visit a template argument and dispatch to the
211 /// appropriate method for the argument type.
212 ///
213 /// \returns false if the visitation was terminated early, true otherwise.
214 // FIXME: migrate callers to TemplateArgumentLoc instead.
215 bool TraverseTemplateArgument(const TemplateArgument &Arg);
216
217 /// \brief Recursively visit a template argument location and dispatch to the
218 /// appropriate method for the argument type.
219 ///
220 /// \returns false if the visitation was terminated early, true otherwise.
221 bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
222
223 /// \brief Recursively visit a set of template arguments.
224 /// This can be overridden by a subclass, but it's not expected that
225 /// will be needed -- this visitor always dispatches to another.
226 ///
227 /// \returns false if the visitation was terminated early, true otherwise.
228 // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
229 bool TraverseTemplateArguments(const TemplateArgument *Args,
230 unsigned NumArgs);
231
232 /// \brief Recursively visit a constructor initializer. This
233 /// automatically dispatches to another visitor for the initializer
234 /// expression, but not for the name of the initializer, so may
235 /// be overridden for clients that need access to the name.
236 ///
237 /// \returns false if the visitation was terminated early, true otherwise.
238 bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
239
240 /// \brief Recursively visit a lambda capture.
241 ///
242 /// \returns false if the visitation was terminated early, true otherwise.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700243 bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C);
244
245 /// \brief Recursively visit the body of a lambda expression.
246 ///
247 /// This provides a hook for visitors that need more context when visiting
248 /// \c LE->getBody().
249 ///
250 /// \returns false if the visitation was terminated early, true otherwise.
251 bool TraverseLambdaBody(LambdaExpr *LE);
Stephen Hines651f13c2014-04-23 16:59:28 -0700252
253 // ---- Methods on Attrs ----
254
255 // \brief Visit an attribute.
256 bool VisitAttr(Attr *A) { return true; }
257
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700258// Declare Traverse* and empty Visit* for all Attr classes.
Stephen Hines651f13c2014-04-23 16:59:28 -0700259#define ATTR_VISITOR_DECLS_ONLY
260#include "clang/AST/AttrVisitor.inc"
261#undef ATTR_VISITOR_DECLS_ONLY
262
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700263// ---- Methods on Stmts ----
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000264
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700265// Declare Traverse*() for all concrete Stmt classes.
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000266#define ABSTRACT_STMT(STMT)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700267#define STMT(CLASS, PARENT) bool Traverse##CLASS(CLASS *S);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000268#include "clang/AST/StmtNodes.inc"
269 // The above header #undefs ABSTRACT_STMT and STMT upon exit.
270
271 // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
272 bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
273 bool VisitStmt(Stmt *S) { return true; }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700274#define STMT(CLASS, PARENT) \
275 bool WalkUpFrom##CLASS(CLASS *S) { \
276 TRY_TO(WalkUpFrom##PARENT(S)); \
277 TRY_TO(Visit##CLASS(S)); \
278 return true; \
279 } \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000280 bool Visit##CLASS(CLASS *S) { return true; }
281#include "clang/AST/StmtNodes.inc"
282
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700283// Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
284// operator methods. Unary operators are not classes in themselves
285// (they're all opcodes in UnaryOperator) but do have visitors.
286#define OPERATOR(NAME) \
287 bool TraverseUnary##NAME(UnaryOperator *S) { \
288 TRY_TO(WalkUpFromUnary##NAME(S)); \
289 StmtQueueAction StmtQueue(*this); \
290 StmtQueue.queue(S->getSubExpr()); \
291 return true; \
292 } \
293 bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
294 TRY_TO(WalkUpFromUnaryOperator(S)); \
295 TRY_TO(VisitUnary##NAME(S)); \
296 return true; \
297 } \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000298 bool VisitUnary##NAME(UnaryOperator *S) { return true; }
299
300 UNARYOP_LIST()
301#undef OPERATOR
302
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700303// Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
304// operator methods. Binary operators are not classes in themselves
305// (they're all opcodes in BinaryOperator) but do have visitors.
306#define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \
307 bool TraverseBin##NAME(BINOP_TYPE *S) { \
308 TRY_TO(WalkUpFromBin##NAME(S)); \
309 StmtQueueAction StmtQueue(*this); \
310 StmtQueue.queue(S->getLHS()); \
311 StmtQueue.queue(S->getRHS()); \
312 return true; \
313 } \
314 bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
315 TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \
316 TRY_TO(VisitBin##NAME(S)); \
317 return true; \
318 } \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000319 bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
320
321#define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
322 BINOP_LIST()
323#undef OPERATOR
324
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700325// Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
326// assignment methods. Compound assignment operators are not
327// classes in themselves (they're all opcodes in
328// CompoundAssignOperator) but do have visitors.
329#define OPERATOR(NAME) \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000330 GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
331
332 CAO_LIST()
333#undef OPERATOR
334#undef GENERAL_BINOP_FALLBACK
335
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700336// ---- Methods on Types ----
337// FIXME: revamp to take TypeLoc's rather than Types.
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000338
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700339// Declare Traverse*() for all concrete Type classes.
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000340#define ABSTRACT_TYPE(CLASS, BASE)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700341#define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000342#include "clang/AST/TypeNodes.def"
343 // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
344
345 // Define WalkUpFrom*() and empty Visit*() for all Type classes.
346 bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
347 bool VisitType(Type *T) { return true; }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700348#define TYPE(CLASS, BASE) \
349 bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \
350 TRY_TO(WalkUpFrom##BASE(T)); \
351 TRY_TO(Visit##CLASS##Type(T)); \
352 return true; \
353 } \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000354 bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
355#include "clang/AST/TypeNodes.def"
356
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700357// ---- Methods on TypeLocs ----
358// FIXME: this currently just calls the matching Type methods
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000359
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700360// Declare Traverse*() for all concrete TypeLoc classes.
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000361#define ABSTRACT_TYPELOC(CLASS, BASE)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700362#define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000363#include "clang/AST/TypeLocNodes.def"
364 // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
365
366 // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
367 bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
368 bool VisitTypeLoc(TypeLoc TL) { return true; }
369
370 // QualifiedTypeLoc and UnqualTypeLoc are not declared in
371 // TypeNodes.def and thus need to be handled specially.
372 bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
373 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
374 }
375 bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
376 bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
377 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
378 }
379 bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
380
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700381// Note that BASE includes trailing 'Type' which CLASS doesn't.
382#define TYPE(CLASS, BASE) \
383 bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
384 TRY_TO(WalkUpFrom##BASE##Loc(TL)); \
385 TRY_TO(Visit##CLASS##TypeLoc(TL)); \
386 return true; \
387 } \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000388 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
389#include "clang/AST/TypeNodes.def"
390
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700391// ---- Methods on Decls ----
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000392
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700393// Declare Traverse*() for all concrete Decl classes.
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000394#define ABSTRACT_DECL(DECL)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700395#define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000396#include "clang/AST/DeclNodes.inc"
397 // The above header #undefs ABSTRACT_DECL and DECL upon exit.
398
399 // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
400 bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
401 bool VisitDecl(Decl *D) { return true; }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700402#define DECL(CLASS, BASE) \
403 bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \
404 TRY_TO(WalkUpFrom##BASE(D)); \
405 TRY_TO(Visit##CLASS##Decl(D)); \
406 return true; \
407 } \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000408 bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
409#include "clang/AST/DeclNodes.inc"
410
411private:
412 // These are helper methods used by more than one Traverse* method.
413 bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000414 bool TraverseClassInstantiations(ClassTemplateDecl *D);
Larisse Voufoef4579c2013-08-06 01:03:05 +0000415 bool TraverseVariableInstantiations(VarTemplateDecl *D);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700416 bool TraverseFunctionInstantiations(FunctionTemplateDecl *D);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000417 bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
418 unsigned Count);
419 bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
420 bool TraverseRecordHelper(RecordDecl *D);
421 bool TraverseCXXRecordHelper(CXXRecordDecl *D);
422 bool TraverseDeclaratorHelper(DeclaratorDecl *D);
423 bool TraverseDeclContextHelper(DeclContext *DC);
424 bool TraverseFunctionHelper(FunctionDecl *D);
425 bool TraverseVarHelper(VarDecl *D);
Stephen Hines651f13c2014-04-23 16:59:28 -0700426 bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
Stephen Hines176edba2014-12-01 14:53:08 -0800427 bool TraverseOMPLoopDirective(OMPLoopDirective *S);
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700428 bool TraverseOMPClause(OMPClause *C);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700429#define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000430#include "clang/Basic/OpenMPKinds.def"
Alexey Bataev543c4ae2013-09-24 03:17:45 +0000431 /// \brief Process clauses with list of variables.
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700432 template <typename T> bool VisitOMPClauseList(T *Node);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000433
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000434 typedef SmallVector<Stmt *, 16> StmtsTy;
435 typedef SmallVector<StmtsTy *, 4> QueuesTy;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700436
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000437 QueuesTy Queues;
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000438
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000439 class NewQueueRAII {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700440 RecursiveASTVisitor &RAV;
441
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000442 public:
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700443 NewQueueRAII(StmtsTy &queue, RecursiveASTVisitor &RAV) : RAV(RAV) {
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000444 RAV.Queues.push_back(&queue);
445 }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700446 ~NewQueueRAII() { RAV.Queues.pop_back(); }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000447 };
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000448
449 StmtsTy &getCurrentQueue() {
450 assert(!Queues.empty() && "base TraverseStmt was never called?");
451 return *Queues.back();
452 }
453
454public:
455 class StmtQueueAction {
456 StmtsTy &CurrQueue;
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000457
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700458 public:
459 explicit StmtQueueAction(RecursiveASTVisitor &RAV)
460 : CurrQueue(RAV.getCurrentQueue()) {}
461
462 void queue(Stmt *S) { CurrQueue.push_back(S); }
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000463 };
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000464};
465
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700466#define DISPATCH(NAME, CLASS, VAR) \
467 return getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000468
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700469template <typename Derived>
470bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000471 if (!S)
472 return true;
473
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700474 StmtsTy Queue, StmtsToEnqueue;
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000475 Queue.push_back(S);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700476 NewQueueRAII NQ(StmtsToEnqueue, *this);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000477
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000478 while (!Queue.empty()) {
479 S = Queue.pop_back_val();
480 if (!S)
481 continue;
482
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700483 StmtsToEnqueue.clear();
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000484
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700485#define DISPATCH_STMT(NAME, CLASS, VAR) \
486 TRY_TO(Traverse##NAME(static_cast<CLASS *>(VAR))); \
487 break
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000488
489 // If we have a binary expr, dispatch to the subcode of the binop. A smart
490 // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
491 // below.
492 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
493 switch (BinOp->getOpcode()) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700494#define OPERATOR(NAME) \
495 case BO_##NAME: \
496 DISPATCH_STMT(Bin##NAME, BinaryOperator, S);
497
498 BINOP_LIST()
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000499#undef OPERATOR
500#undef BINOP_LIST
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700501
502#define OPERATOR(NAME) \
503 case BO_##NAME##Assign: \
504 DISPATCH_STMT(Bin##NAME##Assign, CompoundAssignOperator, S);
505
506 CAO_LIST()
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000507#undef OPERATOR
508#undef CAO_LIST
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000509 }
510 } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
511 switch (UnOp->getOpcode()) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700512#define OPERATOR(NAME) \
513 case UO_##NAME: \
514 DISPATCH_STMT(Unary##NAME, UnaryOperator, S);
515
516 UNARYOP_LIST()
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000517#undef OPERATOR
518#undef UNARYOP_LIST
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000519 }
520 } else {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700521
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000522 // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
523 switch (S->getStmtClass()) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700524 case Stmt::NoStmtClass:
525 break;
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000526#define ABSTRACT_STMT(STMT)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700527#define STMT(CLASS, PARENT) \
528 case Stmt::CLASS##Class: \
529 DISPATCH_STMT(CLASS, CLASS, S);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000530#include "clang/AST/StmtNodes.inc"
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000531 }
532 }
533
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700534 for (SmallVectorImpl<Stmt *>::reverse_iterator RI = StmtsToEnqueue.rbegin(),
535 RE = StmtsToEnqueue.rend();
536 RI != RE; ++RI)
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +0000537 Queue.push_back(*RI);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000538 }
539
540 return true;
541}
542
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700543#undef DISPATCH_STMT
544
545template <typename Derived>
546bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000547 if (T.isNull())
548 return true;
549
550 switch (T->getTypeClass()) {
551#define ABSTRACT_TYPE(CLASS, BASE)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700552#define TYPE(CLASS, BASE) \
553 case Type::CLASS: \
554 DISPATCH(CLASS##Type, CLASS##Type, const_cast<Type *>(T.getTypePtr()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000555#include "clang/AST/TypeNodes.def"
556 }
557
558 return true;
559}
560
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700561template <typename Derived>
562bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000563 if (TL.isNull())
564 return true;
565
566 switch (TL.getTypeLocClass()) {
567#define ABSTRACT_TYPELOC(CLASS, BASE)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700568#define TYPELOC(CLASS, BASE) \
569 case TypeLoc::CLASS: \
David Blaikie39e6ab42013-02-18 22:06:02 +0000570 return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>());
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000571#include "clang/AST/TypeLocNodes.def"
572 }
573
574 return true;
575}
576
Stephen Hines651f13c2014-04-23 16:59:28 -0700577// Define the Traverse*Attr(Attr* A) methods
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700578#define VISITORCLASS RecursiveASTVisitor
Stephen Hines651f13c2014-04-23 16:59:28 -0700579#include "clang/AST/AttrVisitor.inc"
580#undef VISITORCLASS
581
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700582template <typename Derived>
583bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000584 if (!D)
585 return true;
586
587 // As a syntax visitor, we want to ignore declarations for
588 // implicitly-defined declarations (ones not typed explicitly by the
589 // user).
590 if (D->isImplicit())
591 return true;
592
593 switch (D->getKind()) {
594#define ABSTRACT_DECL(DECL)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700595#define DECL(CLASS, BASE) \
596 case Decl::CLASS: \
597 if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D))) \
598 return false; \
Stephen Hines651f13c2014-04-23 16:59:28 -0700599 break;
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000600#include "clang/AST/DeclNodes.inc"
Stephen Hines651f13c2014-04-23 16:59:28 -0700601 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000602
Stephen Hines651f13c2014-04-23 16:59:28 -0700603 // Visit any attributes attached to this declaration.
604 for (auto *I : D->attrs()) {
605 if (!getDerived().TraverseAttr(I))
606 return false;
607 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000608 return true;
609}
610
611#undef DISPATCH
612
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700613template <typename Derived>
614bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
615 NestedNameSpecifier *NNS) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000616 if (!NNS)
617 return true;
618
619 if (NNS->getPrefix())
620 TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
621
622 switch (NNS->getKind()) {
623 case NestedNameSpecifier::Identifier:
624 case NestedNameSpecifier::Namespace:
625 case NestedNameSpecifier::NamespaceAlias:
626 case NestedNameSpecifier::Global:
Stephen Hines176edba2014-12-01 14:53:08 -0800627 case NestedNameSpecifier::Super:
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000628 return true;
629
630 case NestedNameSpecifier::TypeSpec:
631 case NestedNameSpecifier::TypeSpecWithTemplate:
632 TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
633 }
634
635 return true;
636}
637
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700638template <typename Derived>
639bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc(
640 NestedNameSpecifierLoc NNS) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000641 if (!NNS)
642 return true;
643
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700644 if (NestedNameSpecifierLoc Prefix = NNS.getPrefix())
645 TRY_TO(TraverseNestedNameSpecifierLoc(Prefix));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000646
647 switch (NNS.getNestedNameSpecifier()->getKind()) {
648 case NestedNameSpecifier::Identifier:
649 case NestedNameSpecifier::Namespace:
650 case NestedNameSpecifier::NamespaceAlias:
651 case NestedNameSpecifier::Global:
Stephen Hines176edba2014-12-01 14:53:08 -0800652 case NestedNameSpecifier::Super:
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000653 return true;
654
655 case NestedNameSpecifier::TypeSpec:
656 case NestedNameSpecifier::TypeSpecWithTemplate:
657 TRY_TO(TraverseTypeLoc(NNS.getTypeLoc()));
658 break;
659 }
660
661 return true;
662}
663
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700664template <typename Derived>
665bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
666 DeclarationNameInfo NameInfo) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000667 switch (NameInfo.getName().getNameKind()) {
668 case DeclarationName::CXXConstructorName:
669 case DeclarationName::CXXDestructorName:
670 case DeclarationName::CXXConversionFunctionName:
671 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
672 TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc()));
673
674 break;
675
676 case DeclarationName::Identifier:
677 case DeclarationName::ObjCZeroArgSelector:
678 case DeclarationName::ObjCOneArgSelector:
679 case DeclarationName::ObjCMultiArgSelector:
680 case DeclarationName::CXXOperatorName:
681 case DeclarationName::CXXLiteralOperatorName:
682 case DeclarationName::CXXUsingDirective:
683 break;
684 }
685
686 return true;
687}
688
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700689template <typename Derived>
690bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000691 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
692 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
693 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
694 TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
695
696 return true;
697}
698
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700699template <typename Derived>
700bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
701 const TemplateArgument &Arg) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000702 switch (Arg.getKind()) {
703 case TemplateArgument::Null:
704 case TemplateArgument::Declaration:
705 case TemplateArgument::Integral:
Eli Friedmand7a6b162012-09-26 02:36:12 +0000706 case TemplateArgument::NullPtr:
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000707 return true;
708
709 case TemplateArgument::Type:
710 return getDerived().TraverseType(Arg.getAsType());
711
712 case TemplateArgument::Template:
713 case TemplateArgument::TemplateExpansion:
714 return getDerived().TraverseTemplateName(
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700715 Arg.getAsTemplateOrTemplatePattern());
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000716
717 case TemplateArgument::Expression:
718 return getDerived().TraverseStmt(Arg.getAsExpr());
719
720 case TemplateArgument::Pack:
721 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
722 Arg.pack_size());
723 }
724
725 return true;
726}
727
728// FIXME: no template name location?
729// FIXME: no source locations for a template argument pack?
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700730template <typename Derived>
731bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
732 const TemplateArgumentLoc &ArgLoc) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000733 const TemplateArgument &Arg = ArgLoc.getArgument();
734
735 switch (Arg.getKind()) {
736 case TemplateArgument::Null:
737 case TemplateArgument::Declaration:
738 case TemplateArgument::Integral:
Eli Friedmand7a6b162012-09-26 02:36:12 +0000739 case TemplateArgument::NullPtr:
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000740 return true;
741
742 case TemplateArgument::Type: {
743 // FIXME: how can TSI ever be NULL?
744 if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
745 return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
746 else
747 return getDerived().TraverseType(Arg.getAsType());
748 }
749
750 case TemplateArgument::Template:
751 case TemplateArgument::TemplateExpansion:
752 if (ArgLoc.getTemplateQualifierLoc())
753 TRY_TO(getDerived().TraverseNestedNameSpecifierLoc(
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700754 ArgLoc.getTemplateQualifierLoc()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000755 return getDerived().TraverseTemplateName(
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700756 Arg.getAsTemplateOrTemplatePattern());
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000757
758 case TemplateArgument::Expression:
759 return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
760
761 case TemplateArgument::Pack:
762 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
763 Arg.pack_size());
764 }
765
766 return true;
767}
768
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700769template <typename Derived>
770bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
771 const TemplateArgument *Args, unsigned NumArgs) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000772 for (unsigned I = 0; I != NumArgs; ++I) {
773 TRY_TO(TraverseTemplateArgument(Args[I]));
774 }
775
776 return true;
777}
778
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700779template <typename Derived>
780bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
781 CXXCtorInitializer *Init) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000782 if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo())
783 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
784
785 if (Init->isWritten())
786 TRY_TO(TraverseStmt(Init->getInit()));
787 return true;
788}
789
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700790template <typename Derived>
791bool
792RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE,
793 const LambdaCapture *C) {
794 if (C->isInitCapture())
795 TRY_TO(TraverseDecl(C->getCapturedVar()));
796 return true;
797}
798
799template <typename Derived>
800bool RecursiveASTVisitor<Derived>::TraverseLambdaBody(LambdaExpr *LE) {
801 StmtQueueAction StmtQueue(*this);
802 StmtQueue.queue(LE->getBody());
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000803 return true;
804}
805
806// ----------------- Type traversal -----------------
807
808// This macro makes available a variable T, the passed-in type.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700809#define DEF_TRAVERSE_TYPE(TYPE, CODE) \
810 template <typename Derived> \
811 bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) { \
812 TRY_TO(WalkUpFrom##TYPE(T)); \
813 { CODE; } \
814 return true; \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000815 }
816
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700817DEF_TRAVERSE_TYPE(BuiltinType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000818
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700819DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000820
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700821DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000822
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700823DEF_TRAVERSE_TYPE(BlockPointerType,
824 { TRY_TO(TraverseType(T->getPointeeType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000825
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700826DEF_TRAVERSE_TYPE(LValueReferenceType,
827 { TRY_TO(TraverseType(T->getPointeeType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000828
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700829DEF_TRAVERSE_TYPE(RValueReferenceType,
830 { TRY_TO(TraverseType(T->getPointeeType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000831
832DEF_TRAVERSE_TYPE(MemberPointerType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700833 TRY_TO(TraverseType(QualType(T->getClass(), 0)));
834 TRY_TO(TraverseType(T->getPointeeType()));
835})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000836
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700837DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); })
Reid Kleckner12df2462013-06-24 17:51:48 +0000838
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700839DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); })
Stephen Hines651f13c2014-04-23 16:59:28 -0700840
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700841DEF_TRAVERSE_TYPE(ConstantArrayType,
842 { TRY_TO(TraverseType(T->getElementType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000843
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700844DEF_TRAVERSE_TYPE(IncompleteArrayType,
845 { TRY_TO(TraverseType(T->getElementType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000846
847DEF_TRAVERSE_TYPE(VariableArrayType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700848 TRY_TO(TraverseType(T->getElementType()));
849 TRY_TO(TraverseStmt(T->getSizeExpr()));
850})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000851
852DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700853 TRY_TO(TraverseType(T->getElementType()));
854 if (T->getSizeExpr())
855 TRY_TO(TraverseStmt(T->getSizeExpr()));
856})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000857
858DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700859 if (T->getSizeExpr())
860 TRY_TO(TraverseStmt(T->getSizeExpr()));
861 TRY_TO(TraverseType(T->getElementType()));
862})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000863
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700864DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000865
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700866DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000867
Stephen Hines651f13c2014-04-23 16:59:28 -0700868DEF_TRAVERSE_TYPE(FunctionNoProtoType,
869 { TRY_TO(TraverseType(T->getReturnType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000870
871DEF_TRAVERSE_TYPE(FunctionProtoType, {
Stephen Hines651f13c2014-04-23 16:59:28 -0700872 TRY_TO(TraverseType(T->getReturnType()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000873
Stephen Hines651f13c2014-04-23 16:59:28 -0700874 for (const auto &A : T->param_types()) {
875 TRY_TO(TraverseType(A));
876 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000877
Stephen Hines651f13c2014-04-23 16:59:28 -0700878 for (const auto &E : T->exceptions()) {
879 TRY_TO(TraverseType(E));
880 }
Stephen Hines176edba2014-12-01 14:53:08 -0800881
882 if (Expr *NE = T->getNoexceptExpr())
883 TRY_TO(TraverseStmt(NE));
Stephen Hines651f13c2014-04-23 16:59:28 -0700884})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000885
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700886DEF_TRAVERSE_TYPE(UnresolvedUsingType, {})
887DEF_TRAVERSE_TYPE(TypedefType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000888
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700889DEF_TRAVERSE_TYPE(TypeOfExprType,
890 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000891
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700892DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnderlyingType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000893
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700894DEF_TRAVERSE_TYPE(DecltypeType,
895 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000896
897DEF_TRAVERSE_TYPE(UnaryTransformType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700898 TRY_TO(TraverseType(T->getBaseType()));
899 TRY_TO(TraverseType(T->getUnderlyingType()));
900})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000901
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700902DEF_TRAVERSE_TYPE(AutoType, { TRY_TO(TraverseType(T->getDeducedType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000903
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700904DEF_TRAVERSE_TYPE(RecordType, {})
905DEF_TRAVERSE_TYPE(EnumType, {})
906DEF_TRAVERSE_TYPE(TemplateTypeParmType, {})
907DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, {})
908DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000909
910DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700911 TRY_TO(TraverseTemplateName(T->getTemplateName()));
912 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
913})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000914
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700915DEF_TRAVERSE_TYPE(InjectedClassNameType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000916
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700917DEF_TRAVERSE_TYPE(AttributedType,
918 { TRY_TO(TraverseType(T->getModifiedType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000919
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700920DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000921
922DEF_TRAVERSE_TYPE(ElaboratedType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700923 if (T->getQualifier()) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000924 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700925 }
926 TRY_TO(TraverseType(T->getNamedType()));
927})
928
929DEF_TRAVERSE_TYPE(DependentNameType,
930 { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000931
932DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700933 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
934 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
935})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000936
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700937DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000938
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700939DEF_TRAVERSE_TYPE(ObjCInterfaceType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000940
941DEF_TRAVERSE_TYPE(ObjCObjectType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700942 // We have to watch out here because an ObjCInterfaceType's base
943 // type is itself.
944 if (T->getBaseType().getTypePtr() != T)
945 TRY_TO(TraverseType(T->getBaseType()));
946})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000947
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700948DEF_TRAVERSE_TYPE(ObjCObjectPointerType,
949 { TRY_TO(TraverseType(T->getPointeeType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000950
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700951DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000952
953#undef DEF_TRAVERSE_TYPE
954
955// ----------------- TypeLoc traversal -----------------
956
957// This macro makes available a variable TL, the passed-in TypeLoc.
958// If requested, it calls WalkUpFrom* for the Type in the given TypeLoc,
959// in addition to WalkUpFrom* for the TypeLoc itself, such that existing
960// clients that override the WalkUpFrom*Type() and/or Visit*Type() methods
961// continue to work.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700962#define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \
963 template <typename Derived> \
964 bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
965 if (getDerived().shouldWalkTypesOfTypeLocs()) \
966 TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \
967 TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
968 { CODE; } \
969 return true; \
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000970 }
971
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700972template <typename Derived>
973bool
974RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000975 // Move this over to the 'main' typeloc tree. Note that this is a
976 // move -- we pretend that we were really looking at the unqualified
977 // typeloc all along -- rather than a recursion, so we don't follow
978 // the normal CRTP plan of going through
979 // getDerived().TraverseTypeLoc. If we did, we'd be traversing
980 // twice for the same type (once as a QualifiedTypeLoc version of
981 // the type, once as an UnqualifiedTypeLoc version of the type),
982 // which in effect means we'd call VisitTypeLoc twice with the
983 // 'same' type. This solves that problem, at the cost of never
984 // seeing the qualified version of the type (unless the client
985 // subclasses TraverseQualifiedTypeLoc themselves). It's not a
986 // perfect solution. A perfect solution probably requires making
987 // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
988 // wrapper around Type* -- rather than being its own class in the
989 // type hierarchy.
990 return TraverseTypeLoc(TL.getUnqualifiedLoc());
991}
992
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700993DEF_TRAVERSE_TYPELOC(BuiltinType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000994
995// FIXME: ComplexTypeLoc is unfinished
996DEF_TRAVERSE_TYPELOC(ComplexType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700997 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
998})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +0000999
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001000DEF_TRAVERSE_TYPELOC(PointerType,
1001 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001002
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001003DEF_TRAVERSE_TYPELOC(BlockPointerType,
1004 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001005
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001006DEF_TRAVERSE_TYPELOC(LValueReferenceType,
1007 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001008
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001009DEF_TRAVERSE_TYPELOC(RValueReferenceType,
1010 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001011
1012// FIXME: location of base class?
1013// We traverse this in the type case as well, but how is it not reached through
1014// the pointee type?
1015DEF_TRAVERSE_TYPELOC(MemberPointerType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001016 TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
1017 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
1018})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001019
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001020DEF_TRAVERSE_TYPELOC(AdjustedType,
1021 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
Reid Kleckner12df2462013-06-24 17:51:48 +00001022
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001023DEF_TRAVERSE_TYPELOC(DecayedType,
1024 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); })
Stephen Hines651f13c2014-04-23 16:59:28 -07001025
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001026template <typename Derived>
1027bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001028 // This isn't available for ArrayType, but is for the ArrayTypeLoc.
1029 TRY_TO(TraverseStmt(TL.getSizeExpr()));
1030 return true;
1031}
1032
1033DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001034 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1035 return TraverseArrayTypeLocHelper(TL);
1036})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001037
1038DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001039 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1040 return TraverseArrayTypeLocHelper(TL);
1041})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001042
1043DEF_TRAVERSE_TYPELOC(VariableArrayType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001044 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1045 return TraverseArrayTypeLocHelper(TL);
1046})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001047
1048DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001049 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
1050 return TraverseArrayTypeLocHelper(TL);
1051})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001052
1053// FIXME: order? why not size expr first?
1054// FIXME: base VectorTypeLoc is unfinished
1055DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001056 if (TL.getTypePtr()->getSizeExpr())
1057 TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
1058 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1059})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001060
1061// FIXME: VectorTypeLoc is unfinished
1062DEF_TRAVERSE_TYPELOC(VectorType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001063 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1064})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001065
1066// FIXME: size and attributes
1067// FIXME: base VectorTypeLoc is unfinished
1068DEF_TRAVERSE_TYPELOC(ExtVectorType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001069 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
1070})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001071
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001072DEF_TRAVERSE_TYPELOC(FunctionNoProtoType,
1073 { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001074
1075// FIXME: location of exception specifications (attributes?)
1076DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001077 TRY_TO(TraverseTypeLoc(TL.getReturnLoc()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001078
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001079 const FunctionProtoType *T = TL.getTypePtr();
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001080
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001081 for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) {
1082 if (TL.getParam(I)) {
1083 TRY_TO(TraverseDecl(TL.getParam(I)));
1084 } else if (I < T->getNumParams()) {
1085 TRY_TO(TraverseType(T->getParamType(I)));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001086 }
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001087 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001088
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001089 for (const auto &E : T->exceptions()) {
1090 TRY_TO(TraverseType(E));
1091 }
Stephen Hines176edba2014-12-01 14:53:08 -08001092
1093 if (Expr *NE = T->getNoexceptExpr())
1094 TRY_TO(TraverseStmt(NE));
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001095})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001096
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001097DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {})
1098DEF_TRAVERSE_TYPELOC(TypedefType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001099
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001100DEF_TRAVERSE_TYPELOC(TypeOfExprType,
1101 { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001102
1103DEF_TRAVERSE_TYPELOC(TypeOfType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001104 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1105})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001106
1107// FIXME: location of underlying expr
1108DEF_TRAVERSE_TYPELOC(DecltypeType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001109 TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
1110})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001111
1112DEF_TRAVERSE_TYPELOC(UnaryTransformType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001113 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
1114})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001115
1116DEF_TRAVERSE_TYPELOC(AutoType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001117 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType()));
1118})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001119
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001120DEF_TRAVERSE_TYPELOC(RecordType, {})
1121DEF_TRAVERSE_TYPELOC(EnumType, {})
1122DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {})
1123DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, {})
1124DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001125
1126// FIXME: use the loc for the template name?
1127DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001128 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
1129 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1130 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1131 }
1132})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001133
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001134DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001135
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001136DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001137
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001138DEF_TRAVERSE_TYPELOC(AttributedType,
1139 { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001140
1141DEF_TRAVERSE_TYPELOC(ElaboratedType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001142 if (TL.getQualifierLoc()) {
1143 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1144 }
1145 TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
1146})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001147
1148DEF_TRAVERSE_TYPELOC(DependentNameType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001149 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1150})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001151
1152DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001153 if (TL.getQualifierLoc()) {
1154 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
1155 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001156
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001157 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
1158 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
1159 }
1160})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001161
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001162DEF_TRAVERSE_TYPELOC(PackExpansionType,
1163 { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001164
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001165DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001166
1167DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001168 // We have to watch out here because an ObjCInterfaceType's base
1169 // type is itself.
1170 if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
1171 TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
1172})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001173
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001174DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType,
1175 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001176
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001177DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001178
1179#undef DEF_TRAVERSE_TYPELOC
1180
1181// ----------------- Decl traversal -----------------
1182//
1183// For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
1184// the children that come from the DeclContext associated with it.
1185// Therefore each Traverse* only needs to worry about children other
1186// than those.
1187
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001188template <typename Derived>
1189bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001190 if (!DC)
1191 return true;
1192
Stephen Hines651f13c2014-04-23 16:59:28 -07001193 for (auto *Child : DC->decls()) {
Tareq A. Siraj6afcf882013-04-16 19:37:38 +00001194 // BlockDecls and CapturedDecls are traversed through BlockExprs and
1195 // CapturedStmts respectively.
Stephen Hines651f13c2014-04-23 16:59:28 -07001196 if (!isa<BlockDecl>(Child) && !isa<CapturedDecl>(Child))
1197 TRY_TO(TraverseDecl(Child));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001198 }
1199
1200 return true;
1201}
1202
1203// This macro makes available a variable D, the passed-in decl.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001204#define DEF_TRAVERSE_DECL(DECL, CODE) \
1205 template <typename Derived> \
1206 bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) { \
1207 TRY_TO(WalkUpFrom##DECL(D)); \
1208 { CODE; } \
1209 TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \
1210 return true; \
1211 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001212
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001213DEF_TRAVERSE_DECL(AccessSpecDecl, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001214
1215DEF_TRAVERSE_DECL(BlockDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001216 if (TypeSourceInfo *TInfo = D->getSignatureAsWritten())
1217 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
1218 TRY_TO(TraverseStmt(D->getBody()));
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001219 for (const auto &I : D->captures()) {
1220 if (I.hasCopyExpr()) {
1221 TRY_TO(TraverseStmt(I.getCopyExpr()));
1222 }
1223 }
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001224 // This return statement makes sure the traversal of nodes in
1225 // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1226 // is skipped - don't remove it.
1227 return true;
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001228})
1229
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001230DEF_TRAVERSE_DECL(CapturedDecl, {
1231 TRY_TO(TraverseStmt(D->getBody()));
1232 // This return statement makes sure the traversal of nodes in
1233 // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1234 // is skipped - don't remove it.
1235 return true;
1236})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001237
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001238DEF_TRAVERSE_DECL(EmptyDecl, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001239
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001240DEF_TRAVERSE_DECL(FileScopeAsmDecl,
1241 { TRY_TO(TraverseStmt(D->getAsmString())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001242
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001243DEF_TRAVERSE_DECL(ImportDecl, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001244
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001245DEF_TRAVERSE_DECL(FriendDecl, {
1246 // Friend is either decl or a type.
1247 if (D->getFriendType())
1248 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1249 else
1250 TRY_TO(TraverseDecl(D->getFriendDecl()));
1251})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001252
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001253DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1254 if (D->getFriendType())
1255 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc()));
1256 else
1257 TRY_TO(TraverseDecl(D->getFriendDecl()));
1258 for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1259 TemplateParameterList *TPL = D->getTemplateParameterList(I);
1260 for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end();
1261 ITPL != ETPL; ++ITPL) {
1262 TRY_TO(TraverseDecl(*ITPL));
1263 }
1264 }
1265})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001266
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001267DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl,
1268 { TRY_TO(TraverseDecl(D->getSpecialization())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001269
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001270DEF_TRAVERSE_DECL(LinkageSpecDecl, {})
1271
1272DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this
1273 })
1274
1275DEF_TRAVERSE_DECL(StaticAssertDecl, {
1276 TRY_TO(TraverseStmt(D->getAssertExpr()));
1277 TRY_TO(TraverseStmt(D->getMessage()));
1278})
1279
1280DEF_TRAVERSE_DECL(
1281 TranslationUnitDecl,
1282 {// Code in an unnamed namespace shows up automatically in
1283 // decls_begin()/decls_end(). Thus we don't need to recurse on
1284 // D->getAnonymousNamespace().
1285 })
1286
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -07001287DEF_TRAVERSE_DECL(ExternCContextDecl, {})
1288
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001289DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1290 // We shouldn't traverse an aliased namespace, since it will be
1291 // defined (and, therefore, traversed) somewhere else.
1292 //
1293 // This return statement makes sure the traversal of nodes in
1294 // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1295 // is skipped - don't remove it.
1296 return true;
1297})
1298
1299DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl.
1300 })
1301
1302DEF_TRAVERSE_DECL(
1303 NamespaceDecl,
1304 {// Code in an unnamed namespace shows up automatically in
1305 // decls_begin()/decls_end(). Thus we don't need to recurse on
1306 // D->getAnonymousNamespace().
1307 })
1308
1309DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement
1310 })
1311
1312DEF_TRAVERSE_DECL(ObjCCategoryDecl, {// FIXME: implement
1313 })
1314
1315DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement
1316 })
1317
1318DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
1319 })
1320
1321DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {// FIXME: implement
1322 })
1323
1324DEF_TRAVERSE_DECL(ObjCProtocolDecl, {// FIXME: implement
1325 })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001326
1327DEF_TRAVERSE_DECL(ObjCMethodDecl, {
Stephen Hines651f13c2014-04-23 16:59:28 -07001328 if (D->getReturnTypeSourceInfo()) {
1329 TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc()));
1330 }
1331 for (ObjCMethodDecl::param_iterator I = D->param_begin(), E = D->param_end();
1332 I != E; ++I) {
1333 TRY_TO(TraverseDecl(*I));
1334 }
1335 if (D->isThisDeclarationADefinition()) {
1336 TRY_TO(TraverseStmt(D->getBody()));
1337 }
1338 return true;
1339})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001340
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001341DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1342 if (D->getTypeSourceInfo())
1343 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1344 else
1345 TRY_TO(TraverseType(D->getType()));
1346 return true;
1347})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001348
1349DEF_TRAVERSE_DECL(UsingDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001350 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1351 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1352})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001353
1354DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001355 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1356})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001357
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001358DEF_TRAVERSE_DECL(UsingShadowDecl, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001359
Alexey Bataevc6400582013-03-22 06:34:35 +00001360DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001361 for (auto *I : D->varlists()) {
1362 TRY_TO(TraverseStmt(I));
1363 }
1364})
Alexey Bataevc6400582013-03-22 06:34:35 +00001365
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001366// A helper method for TemplateDecl's children.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001367template <typename Derived>
1368bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001369 TemplateParameterList *TPL) {
1370 if (TPL) {
1371 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1372 I != E; ++I) {
1373 TRY_TO(TraverseDecl(*I));
1374 }
1375 }
1376 return true;
1377}
1378
1379// A helper method for traversing the implicit instantiations of a
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00001380// class template.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001381template <typename Derived>
1382bool RecursiveASTVisitor<Derived>::TraverseClassInstantiations(
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00001383 ClassTemplateDecl *D) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001384 for (auto *SD : D->specializations()) {
1385 for (auto *RD : SD->redecls()) {
1386 // We don't want to visit injected-class-names in this traversal.
1387 if (cast<CXXRecordDecl>(RD)->isInjectedClassName())
1388 continue;
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001389
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001390 switch (
1391 cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001392 // Visit the implicit instantiations with the requested pattern.
1393 case TSK_Undeclared:
1394 case TSK_ImplicitInstantiation:
1395 TRY_TO(TraverseDecl(RD));
1396 break;
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001397
Stephen Hines651f13c2014-04-23 16:59:28 -07001398 // We don't need to do anything on an explicit instantiation
1399 // or explicit specialization because there will be an explicit
1400 // node for it elsewhere.
1401 case TSK_ExplicitInstantiationDeclaration:
1402 case TSK_ExplicitInstantiationDefinition:
1403 case TSK_ExplicitSpecialization:
1404 break;
1405 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001406 }
1407 }
1408
1409 return true;
1410}
1411
1412DEF_TRAVERSE_DECL(ClassTemplateDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001413 CXXRecordDecl *TempDecl = D->getTemplatedDecl();
1414 TRY_TO(TraverseDecl(TempDecl));
1415 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001416
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001417 // By default, we do not traverse the instantiations of
1418 // class templates since they do not appear in the user code. The
1419 // following code optionally traverses them.
1420 //
1421 // We only traverse the class instantiations when we see the canonical
1422 // declaration of the template, to ensure we only visit them once.
1423 if (getDerived().shouldVisitTemplateInstantiations() &&
1424 D == D->getCanonicalDecl())
1425 TRY_TO(TraverseClassInstantiations(D));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001426
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001427 // Note that getInstantiatedFromMemberTemplate() is just a link
1428 // from a template instantiation back to the template from which
1429 // it was instantiated, and thus should not be traversed.
1430})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001431
Larisse Voufoef4579c2013-08-06 01:03:05 +00001432// A helper method for traversing the implicit instantiations of a
1433// class template.
1434template <typename Derived>
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001435bool RecursiveASTVisitor<Derived>::TraverseVariableInstantiations(
Larisse Voufoef4579c2013-08-06 01:03:05 +00001436 VarTemplateDecl *D) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001437 for (auto *SD : D->specializations()) {
1438 for (auto *RD : SD->redecls()) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001439 switch (
1440 cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001441 // Visit the implicit instantiations with the requested pattern.
1442 case TSK_Undeclared:
1443 case TSK_ImplicitInstantiation:
1444 TRY_TO(TraverseDecl(RD));
1445 break;
Larisse Voufoef4579c2013-08-06 01:03:05 +00001446
Stephen Hines651f13c2014-04-23 16:59:28 -07001447 // We don't need to do anything on an explicit instantiation
1448 // or explicit specialization because there will be an explicit
1449 // node for it elsewhere.
1450 case TSK_ExplicitInstantiationDeclaration:
1451 case TSK_ExplicitInstantiationDefinition:
1452 case TSK_ExplicitSpecialization:
1453 break;
1454 }
Larisse Voufoef4579c2013-08-06 01:03:05 +00001455 }
1456 }
1457
1458 return true;
1459}
1460
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001461DEF_TRAVERSE_DECL(VarTemplateDecl, {
Larisse Voufoef4579c2013-08-06 01:03:05 +00001462 VarDecl *TempDecl = D->getTemplatedDecl();
1463 TRY_TO(TraverseDecl(TempDecl));
1464 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1465
1466 // By default, we do not traverse the instantiations of
1467 // variable templates since they do not appear in the user code. The
1468 // following code optionally traverses them.
1469 //
1470 // We only traverse the variable instantiations when we see the canonical
1471 // declaration of the template, to ensure we only visit them once.
1472 if (getDerived().shouldVisitTemplateInstantiations() &&
1473 D == D->getCanonicalDecl())
1474 TRY_TO(TraverseVariableInstantiations(D));
1475
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001476 // Note that getInstantiatedFromMemberTemplate() is just a link
1477 // from a template instantiation back to the template from which
1478 // it was instantiated, and thus should not be traversed.
Larisse Voufoef4579c2013-08-06 01:03:05 +00001479})
1480
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001481// A helper method for traversing the instantiations of a
1482// function while skipping its specializations.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001483template <typename Derived>
1484bool RecursiveASTVisitor<Derived>::TraverseFunctionInstantiations(
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00001485 FunctionTemplateDecl *D) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001486 for (auto *FD : D->specializations()) {
1487 for (auto *RD : FD->redecls()) {
1488 switch (RD->getTemplateSpecializationKind()) {
1489 case TSK_Undeclared:
1490 case TSK_ImplicitInstantiation:
1491 // We don't know what kind of FunctionDecl this is.
1492 TRY_TO(TraverseDecl(RD));
1493 break;
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001494
Stephen Hines651f13c2014-04-23 16:59:28 -07001495 // No need to visit explicit instantiations, we'll find the node
1496 // eventually.
1497 // FIXME: This is incorrect; there is no other node for an explicit
1498 // instantiation of a function template specialization.
1499 case TSK_ExplicitInstantiationDeclaration:
1500 case TSK_ExplicitInstantiationDefinition:
1501 break;
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001502
Stephen Hines651f13c2014-04-23 16:59:28 -07001503 case TSK_ExplicitSpecialization:
1504 break;
1505 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001506 }
1507 }
1508
1509 return true;
1510}
1511
1512DEF_TRAVERSE_DECL(FunctionTemplateDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001513 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1514 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001515
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001516 // By default, we do not traverse the instantiations of
1517 // function templates since they do not appear in the user code. The
1518 // following code optionally traverses them.
1519 //
1520 // We only traverse the function instantiations when we see the canonical
1521 // declaration of the template, to ensure we only visit them once.
1522 if (getDerived().shouldVisitTemplateInstantiations() &&
1523 D == D->getCanonicalDecl())
1524 TRY_TO(TraverseFunctionInstantiations(D));
1525})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001526
1527DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001528 // D is the "T" in something like
1529 // template <template <typename> class T> class container { };
1530 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1531 if (D->hasDefaultArgument()) {
1532 TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1533 }
1534 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1535})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001536
1537DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001538 // D is the "T" in something like "template<typename T> class vector;"
1539 if (D->getTypeForDecl())
1540 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1541 if (D->hasDefaultArgument())
1542 TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1543})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001544
1545DEF_TRAVERSE_DECL(TypedefDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001546 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1547 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1548 // declaring the typedef, not something that was written in the
1549 // source.
1550})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001551
1552DEF_TRAVERSE_DECL(TypeAliasDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001553 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1554 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1555 // declaring the type alias, not something that was written in the
1556 // source.
1557})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001558
1559DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001560 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1561 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1562})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001563
1564DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001565 // A dependent using declaration which was marked with 'typename'.
1566 // template<class T> class A : public B<T> { using typename B<T>::foo; };
1567 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1568 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1569 // declaring the type, not something that was written in the
1570 // source.
1571})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001572
1573DEF_TRAVERSE_DECL(EnumDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001574 if (D->getTypeForDecl())
1575 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001576
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001577 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1578 // The enumerators are already traversed by
1579 // decls_begin()/decls_end().
1580})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001581
1582// Helper methods for RecordDecl and its children.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001583template <typename Derived>
1584bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001585 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1586 // declaring the type, not something that was written in the source.
1587
1588 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1589 return true;
1590}
1591
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001592template <typename Derived>
1593bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001594 if (!TraverseRecordHelper(D))
1595 return false;
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00001596 if (D->isCompleteDefinition()) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001597 for (const auto &I : D->bases()) {
1598 TRY_TO(TraverseTypeLoc(I.getTypeSourceInfo()->getTypeLoc()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001599 }
1600 // We don't traverse the friends or the conversions, as they are
1601 // already in decls_begin()/decls_end().
1602 }
1603 return true;
1604}
1605
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001606DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001607
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001608DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001609
1610DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001611 // For implicit instantiations ("set<int> x;"), we don't want to
1612 // recurse at all, since the instatiated class isn't written in
1613 // the source code anywhere. (Note the instatiated *type* --
1614 // set<int> -- is written, and will still get a callback of
1615 // TemplateSpecializationType). For explicit instantiations
1616 // ("template set<int>;"), we do need a callback, since this
1617 // is the only callback that's made for this instantiation.
1618 // We use getTypeAsWritten() to distinguish.
1619 if (TypeSourceInfo *TSI = D->getTypeAsWritten())
1620 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001621
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001622 if (!getDerived().shouldVisitTemplateInstantiations() &&
1623 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)
1624 // Returning from here skips traversing the
1625 // declaration context of the ClassTemplateSpecializationDecl
1626 // (embedded in the DEF_TRAVERSE_DECL() macro)
1627 // which contains the instantiated members of the class.
1628 return true;
1629})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001630
1631template <typename Derived>
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001632bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001633 const TemplateArgumentLoc *TAL, unsigned Count) {
1634 for (unsigned I = 0; I < Count; ++I) {
1635 TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1636 }
1637 return true;
1638}
1639
1640DEF_TRAVERSE_DECL(ClassTemplatePartialSpecializationDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001641 // The partial specialization.
1642 if (TemplateParameterList *TPL = D->getTemplateParameters()) {
1643 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1644 I != E; ++I) {
1645 TRY_TO(TraverseDecl(*I));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001646 }
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001647 }
1648 // The args that remains unspecialized.
1649 TRY_TO(TraverseTemplateArgumentLocsHelper(
1650 D->getTemplateArgsAsWritten()->getTemplateArgs(),
1651 D->getTemplateArgsAsWritten()->NumTemplateArgs));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001652
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001653 // Don't need the ClassTemplatePartialSpecializationHelper, even
1654 // though that's our parent class -- we already visit all the
1655 // template args here.
1656 TRY_TO(TraverseCXXRecordHelper(D));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001657
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001658 // Instantiations will have been visited with the primary template.
1659})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001660
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001661DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001662
1663DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001664 // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1665 // template <class T> Class A : public Base<T> { using Base<T>::foo; };
1666 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1667 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1668})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001669
1670DEF_TRAVERSE_DECL(IndirectFieldDecl, {})
1671
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001672template <typename Derived>
1673bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001674 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1675 if (D->getTypeSourceInfo())
1676 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1677 else
1678 TRY_TO(TraverseType(D->getType()));
1679 return true;
1680}
1681
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001682DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001683
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001684DEF_TRAVERSE_DECL(FieldDecl, {
1685 TRY_TO(TraverseDeclaratorHelper(D));
1686 if (D->isBitField())
1687 TRY_TO(TraverseStmt(D->getBitWidth()));
1688 else if (D->hasInClassInitializer())
1689 TRY_TO(TraverseStmt(D->getInClassInitializer()));
1690})
John McCall76da55d2013-04-16 07:28:30 +00001691
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001692DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001693 TRY_TO(TraverseDeclaratorHelper(D));
1694 if (D->isBitField())
1695 TRY_TO(TraverseStmt(D->getBitWidth()));
1696 // FIXME: implement the rest.
1697})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001698
1699DEF_TRAVERSE_DECL(ObjCIvarDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001700 TRY_TO(TraverseDeclaratorHelper(D));
1701 if (D->isBitField())
1702 TRY_TO(TraverseStmt(D->getBitWidth()));
1703 // FIXME: implement the rest.
1704})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001705
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001706template <typename Derived>
1707bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001708 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
1709 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo()));
1710
1711 // If we're an explicit template specialization, iterate over the
1712 // template args that were explicitly specified. If we were doing
1713 // this in typing order, we'd do it between the return type and
1714 // the function args, but both are handled by the FunctionTypeLoc
1715 // above, so we have to choose one side. I've decided to do before.
1716 if (const FunctionTemplateSpecializationInfo *FTSI =
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001717 D->getTemplateSpecializationInfo()) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001718 if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1719 FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1720 // A specialization might not have explicit template arguments if it has
1721 // a templated return type and concrete arguments.
1722 if (const ASTTemplateArgumentListInfo *TALI =
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001723 FTSI->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001724 TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(),
1725 TALI->NumTemplateArgs));
1726 }
1727 }
1728 }
1729
1730 // Visit the function type itself, which can be either
1731 // FunctionNoProtoType or FunctionProtoType, or a typedef. This
1732 // also covers the return type and the function parameters,
1733 // including exception specifications.
1734 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1735
1736 if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1737 // Constructor initializers.
Stephen Hines651f13c2014-04-23 16:59:28 -07001738 for (auto *I : Ctor->inits()) {
1739 TRY_TO(TraverseConstructorInitializer(I));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001740 }
1741 }
1742
1743 if (D->isThisDeclarationADefinition()) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001744 TRY_TO(TraverseStmt(D->getBody())); // Function body.
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001745 }
1746 return true;
1747}
1748
1749DEF_TRAVERSE_DECL(FunctionDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001750 // We skip decls_begin/decls_end, which are already covered by
1751 // TraverseFunctionHelper().
1752 return TraverseFunctionHelper(D);
1753})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001754
1755DEF_TRAVERSE_DECL(CXXMethodDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001756 // We skip decls_begin/decls_end, which are already covered by
1757 // TraverseFunctionHelper().
1758 return TraverseFunctionHelper(D);
1759})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001760
1761DEF_TRAVERSE_DECL(CXXConstructorDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001762 // We skip decls_begin/decls_end, which are already covered by
1763 // TraverseFunctionHelper().
1764 return TraverseFunctionHelper(D);
1765})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001766
1767// CXXConversionDecl is the declaration of a type conversion operator.
1768// It's not a cast expression.
1769DEF_TRAVERSE_DECL(CXXConversionDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001770 // We skip decls_begin/decls_end, which are already covered by
1771 // TraverseFunctionHelper().
1772 return TraverseFunctionHelper(D);
1773})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001774
1775DEF_TRAVERSE_DECL(CXXDestructorDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001776 // We skip decls_begin/decls_end, which are already covered by
1777 // TraverseFunctionHelper().
1778 return TraverseFunctionHelper(D);
1779})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001780
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001781template <typename Derived>
1782bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001783 TRY_TO(TraverseDeclaratorHelper(D));
1784 // Default params are taken care of when we traverse the ParmVarDecl.
1785 if (!isa<ParmVarDecl>(D))
1786 TRY_TO(TraverseStmt(D->getInit()));
1787 return true;
1788}
1789
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001790DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001791
Larisse Voufoef4579c2013-08-06 01:03:05 +00001792DEF_TRAVERSE_DECL(VarTemplateSpecializationDecl, {
1793 // For implicit instantiations, we don't want to
1794 // recurse at all, since the instatiated class isn't written in
1795 // the source code anywhere.
1796 if (TypeSourceInfo *TSI = D->getTypeAsWritten())
1797 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1798
1799 if (!getDerived().shouldVisitTemplateInstantiations() &&
1800 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)
1801 // Returning from here skips traversing the
1802 // declaration context of the VarTemplateSpecializationDecl
1803 // (embedded in the DEF_TRAVERSE_DECL() macro).
1804 return true;
1805})
1806
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001807DEF_TRAVERSE_DECL(VarTemplatePartialSpecializationDecl, {
Larisse Voufoef4579c2013-08-06 01:03:05 +00001808 // The partial specialization.
1809 if (TemplateParameterList *TPL = D->getTemplateParameters()) {
1810 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1811 I != E; ++I) {
1812 TRY_TO(TraverseDecl(*I));
1813 }
1814 }
1815 // The args that remains unspecialized.
Enea Zaffanellac1cef082013-08-10 07:24:53 +00001816 TRY_TO(TraverseTemplateArgumentLocsHelper(
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001817 D->getTemplateArgsAsWritten()->getTemplateArgs(),
1818 D->getTemplateArgsAsWritten()->NumTemplateArgs));
Larisse Voufoef4579c2013-08-06 01:03:05 +00001819
1820 // Don't need the VarTemplatePartialSpecializationHelper, even
1821 // though that's our parent class -- we already visit all the
1822 // template args here.
1823 TRY_TO(TraverseVarHelper(D));
1824
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001825 // Instantiations will have been visited with the primary
1826 // template.
Larisse Voufoef4579c2013-08-06 01:03:05 +00001827})
1828
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001829DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001830
1831DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001832 // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
1833 TRY_TO(TraverseDeclaratorHelper(D));
1834 TRY_TO(TraverseStmt(D->getDefaultArgument()));
1835})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001836
1837DEF_TRAVERSE_DECL(ParmVarDecl, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001838 TRY_TO(TraverseVarHelper(D));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001839
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001840 if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() &&
1841 !D->hasUnparsedDefaultArg())
1842 TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001843
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001844 if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() &&
1845 !D->hasUnparsedDefaultArg())
1846 TRY_TO(TraverseStmt(D->getDefaultArg()));
1847})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001848
1849#undef DEF_TRAVERSE_DECL
1850
1851// ----------------- Stmt traversal -----------------
1852//
1853// For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
1854// over the children defined in children() (every stmt defines these,
1855// though sometimes the range is empty). Each individual Traverse*
1856// method only needs to worry about children other than those. To see
1857// what children() does for a given class, see, e.g.,
1858// http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
1859
1860// This macro makes available a variable S, the passed-in stmt.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001861#define DEF_TRAVERSE_STMT(STMT, CODE) \
1862 template <typename Derived> \
1863 bool RecursiveASTVisitor<Derived>::Traverse##STMT(STMT *S) { \
1864 TRY_TO(WalkUpFrom##STMT(S)); \
1865 StmtQueueAction StmtQueue(*this); \
1866 { CODE; } \
1867 for (Stmt::child_range range = S->children(); range; ++range) { \
1868 StmtQueue.queue(*range); \
1869 } \
1870 return true; \
1871 }
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001872
Chad Rosierdf5faf52012-08-25 00:11:56 +00001873DEF_TRAVERSE_STMT(GCCAsmStmt, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001874 StmtQueue.queue(S->getAsmString());
1875 for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
1876 StmtQueue.queue(S->getInputConstraintLiteral(I));
1877 }
1878 for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
1879 StmtQueue.queue(S->getOutputConstraintLiteral(I));
1880 }
1881 for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
1882 StmtQueue.queue(S->getClobberStringLiteral(I));
1883 }
1884 // children() iterates over inputExpr and outputExpr.
1885})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001886
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001887DEF_TRAVERSE_STMT(
1888 MSAsmStmt,
1889 {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc. Once
1890 // added this needs to be implemented.
1891 })
Chad Rosier8cd64b42012-06-11 20:47:18 +00001892
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001893DEF_TRAVERSE_STMT(CXXCatchStmt, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001894 TRY_TO(TraverseDecl(S->getExceptionDecl()));
1895 // children() iterates over the handler block.
1896})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001897
1898DEF_TRAVERSE_STMT(DeclStmt, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001899 for (auto *I : S->decls()) {
1900 TRY_TO(TraverseDecl(I));
1901 }
1902 // Suppress the default iteration over children() by
1903 // returning. Here's why: A DeclStmt looks like 'type var [=
1904 // initializer]'. The decls above already traverse over the
1905 // initializers, so we don't have to do it again (which
1906 // children() would do).
1907 return true;
1908})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001909
1910// These non-expr stmts (most of them), do not need any action except
1911// iterating over the children.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001912DEF_TRAVERSE_STMT(BreakStmt, {})
1913DEF_TRAVERSE_STMT(CXXTryStmt, {})
1914DEF_TRAVERSE_STMT(CaseStmt, {})
1915DEF_TRAVERSE_STMT(CompoundStmt, {})
1916DEF_TRAVERSE_STMT(ContinueStmt, {})
1917DEF_TRAVERSE_STMT(DefaultStmt, {})
1918DEF_TRAVERSE_STMT(DoStmt, {})
1919DEF_TRAVERSE_STMT(ForStmt, {})
1920DEF_TRAVERSE_STMT(GotoStmt, {})
1921DEF_TRAVERSE_STMT(IfStmt, {})
1922DEF_TRAVERSE_STMT(IndirectGotoStmt, {})
1923DEF_TRAVERSE_STMT(LabelStmt, {})
1924DEF_TRAVERSE_STMT(AttributedStmt, {})
1925DEF_TRAVERSE_STMT(NullStmt, {})
1926DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {})
1927DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {})
1928DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {})
1929DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {})
1930DEF_TRAVERSE_STMT(ObjCAtTryStmt, {})
1931DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {})
1932DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {})
1933DEF_TRAVERSE_STMT(CXXForRangeStmt, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001934DEF_TRAVERSE_STMT(MSDependentExistsStmt, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001935 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1936 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001937})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001938DEF_TRAVERSE_STMT(ReturnStmt, {})
1939DEF_TRAVERSE_STMT(SwitchStmt, {})
1940DEF_TRAVERSE_STMT(WhileStmt, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001941
1942DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001943 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1944 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
1945 if (S->hasExplicitTemplateArgs()) {
1946 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
1947 S->getNumTemplateArgs()));
1948 }
1949})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001950
1951DEF_TRAVERSE_STMT(DeclRefExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001952 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1953 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
1954 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
1955 S->getNumTemplateArgs()));
1956})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001957
1958DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001959 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1960 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo()));
1961 if (S->hasExplicitTemplateArgs()) {
1962 TRY_TO(TraverseTemplateArgumentLocsHelper(
1963 S->getExplicitTemplateArgs().getTemplateArgs(),
1964 S->getNumTemplateArgs()));
1965 }
1966})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001967
1968DEF_TRAVERSE_STMT(MemberExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001969 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
1970 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo()));
1971 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
1972 S->getNumTemplateArgs()));
1973})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001974
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001975DEF_TRAVERSE_STMT(
1976 ImplicitCastExpr,
1977 {// We don't traverse the cast type, as it's not written in the
1978 // source code.
1979 })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001980
1981DEF_TRAVERSE_STMT(CStyleCastExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001982 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1983})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001984
1985DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001986 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1987})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001988
1989DEF_TRAVERSE_STMT(CXXConstCastExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001990 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1991})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001992
1993DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001994 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1995})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00001996
1997DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001998 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
1999})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002000
2001DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002002 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2003})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002004
2005// InitListExpr is a tricky one, because we want to do all our work on
2006// the syntactic form of the listexpr, but this method takes the
2007// semantic form by default. We can't use the macro helper because it
2008// calls WalkUp*() on the semantic form, before our code can convert
2009// to the syntactic form.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002010template <typename Derived>
2011bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002012 if (InitListExpr *Syn = S->getSyntacticForm())
2013 S = Syn;
2014 TRY_TO(WalkUpFromInitListExpr(S));
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00002015 StmtQueueAction StmtQueue(*this);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002016 // All we need are the default actions. FIXME: use a helper function.
2017 for (Stmt::child_range range = S->children(); range; ++range) {
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00002018 StmtQueue.queue(*range);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002019 }
2020 return true;
2021}
2022
2023// GenericSelectionExpr is a special case because the types and expressions
2024// are interleaved. We also need to watch out for null types (default
2025// generic associations).
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002026template <typename Derived>
2027bool RecursiveASTVisitor<Derived>::TraverseGenericSelectionExpr(
2028 GenericSelectionExpr *S) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002029 TRY_TO(WalkUpFromGenericSelectionExpr(S));
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00002030 StmtQueueAction StmtQueue(*this);
2031 StmtQueue.queue(S->getControllingExpr());
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002032 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
2033 if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i))
2034 TRY_TO(TraverseTypeLoc(TS->getTypeLoc()));
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00002035 StmtQueue.queue(S->getAssocExpr(i));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002036 }
2037 return true;
2038}
2039
2040// PseudoObjectExpr is a special case because of the wierdness with
2041// syntactic expressions and opaque values.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002042template <typename Derived>
2043bool
2044RecursiveASTVisitor<Derived>::TraversePseudoObjectExpr(PseudoObjectExpr *S) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002045 TRY_TO(WalkUpFromPseudoObjectExpr(S));
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00002046 StmtQueueAction StmtQueue(*this);
2047 StmtQueue.queue(S->getSyntacticForm());
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002048 for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(),
2049 e = S->semantics_end();
2050 i != e; ++i) {
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002051 Expr *sub = *i;
2052 if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub))
2053 sub = OVE->getSourceExpr();
Argyrios Kyrtzidis428499e2012-05-07 23:23:03 +00002054 StmtQueue.queue(sub);
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002055 }
2056 return true;
2057}
2058
2059DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002060 // This is called for code like 'return T()' where T is a built-in
2061 // (i.e. non-class) type.
2062 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2063})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002064
2065DEF_TRAVERSE_STMT(CXXNewExpr, {
2066 // The child-iterator will pick up the other arguments.
2067 TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc()));
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002068})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002069
2070DEF_TRAVERSE_STMT(OffsetOfExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002071 // The child-iterator will pick up the expression representing
2072 // the field.
2073 // FIMXE: for code like offsetof(Foo, a.b.c), should we get
2074 // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
2075 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2076})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002077
2078DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002079 // The child-iterator will pick up the arg if it's an expression,
2080 // but not if it's a type.
2081 if (S->isArgumentType())
2082 TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
2083})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002084
2085DEF_TRAVERSE_STMT(CXXTypeidExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002086 // The child-iterator will pick up the arg if it's an expression,
2087 // but not if it's a type.
2088 if (S->isTypeOperand())
2089 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2090})
2091
2092DEF_TRAVERSE_STMT(MSPropertyRefExpr, {
2093 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2094})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002095
2096DEF_TRAVERSE_STMT(CXXUuidofExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002097 // The child-iterator will pick up the arg if it's an expression,
2098 // but not if it's a type.
2099 if (S->isTypeOperand())
2100 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
2101})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002102
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002103DEF_TRAVERSE_STMT(TypeTraitExpr, {
2104 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2105 TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc()));
2106})
2107
2108DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002109 TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc()));
2110})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002111
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002112DEF_TRAVERSE_STMT(ExpressionTraitExpr,
2113 { StmtQueue.queue(S->getQueriedExpression()); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002114
2115DEF_TRAVERSE_STMT(VAArgExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002116 // The child-iterator will pick up the expression argument.
2117 TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
2118})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002119
2120DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002121 // This is called for code like 'return T()' where T is a class type.
2122 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2123})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002124
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002125// Walk only the visible parts of lambda expressions.
2126template <typename Derived>
2127bool RecursiveASTVisitor<Derived>::TraverseLambdaExpr(LambdaExpr *S) {
James Dennett89faf862013-06-30 03:13:35 +00002128 TRY_TO(WalkUpFromLambdaExpr(S));
2129
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002130 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002131 CEnd = S->explicit_capture_end();
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002132 C != CEnd; ++C) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002133 TRY_TO(TraverseLambdaCapture(S, C));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002134 }
2135
Stephen Hines176edba2014-12-01 14:53:08 -08002136 TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
2137 FunctionProtoTypeLoc Proto = TL.castAs<FunctionProtoTypeLoc>();
2138
2139 if (S->hasExplicitParameters() && S->hasExplicitResultType()) {
2140 // Visit the whole type.
2141 TRY_TO(TraverseTypeLoc(TL));
2142 } else {
2143 if (S->hasExplicitParameters()) {
2144 // Visit parameters.
2145 for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) {
2146 TRY_TO(TraverseDecl(Proto.getParam(I)));
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002147 }
Stephen Hines176edba2014-12-01 14:53:08 -08002148 } else if (S->hasExplicitResultType()) {
2149 TRY_TO(TraverseTypeLoc(Proto.getReturnLoc()));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002150 }
Stephen Hines176edba2014-12-01 14:53:08 -08002151
2152 auto *T = Proto.getTypePtr();
2153 for (const auto &E : T->exceptions()) {
2154 TRY_TO(TraverseType(E));
2155 }
2156
2157 if (Expr *NE = T->getNoexceptExpr())
2158 TRY_TO(TraverseStmt(NE));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002159 }
2160
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002161 TRY_TO(TraverseLambdaBody(S));
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002162 return true;
2163}
2164
2165DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002166 // This is called for code like 'T()', where T is a template argument.
2167 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2168})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002169
2170// These expressions all might take explicit template arguments.
2171// We traverse those if so. FIXME: implement these.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002172DEF_TRAVERSE_STMT(CXXConstructExpr, {})
2173DEF_TRAVERSE_STMT(CallExpr, {})
2174DEF_TRAVERSE_STMT(CXXMemberCallExpr, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002175
2176// These exprs (most of them), do not need any action except iterating
2177// over the children.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002178DEF_TRAVERSE_STMT(AddrLabelExpr, {})
2179DEF_TRAVERSE_STMT(ArraySubscriptExpr, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002180DEF_TRAVERSE_STMT(BlockExpr, {
2181 TRY_TO(TraverseDecl(S->getBlockDecl()));
2182 return true; // no child statements to loop through.
2183})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002184DEF_TRAVERSE_STMT(ChooseExpr, {})
2185DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
2186 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
2187})
2188DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
2189DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
2190DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
2191DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
2192DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
2193DEF_TRAVERSE_STMT(ExprWithCleanups, {})
2194DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {})
2195DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002196DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, {
2197 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2198 if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo())
2199 TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc()));
2200 if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo())
2201 TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc()));
2202})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002203DEF_TRAVERSE_STMT(CXXThisExpr, {})
2204DEF_TRAVERSE_STMT(CXXThrowExpr, {})
2205DEF_TRAVERSE_STMT(UserDefinedLiteral, {})
2206DEF_TRAVERSE_STMT(DesignatedInitExpr, {})
2207DEF_TRAVERSE_STMT(ExtVectorElementExpr, {})
2208DEF_TRAVERSE_STMT(GNUNullExpr, {})
2209DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {})
2210DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {})
Argyrios Kyrtzidis87014f32012-05-16 19:22:47 +00002211DEF_TRAVERSE_STMT(ObjCEncodeExpr, {
2212 if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo())
2213 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2214})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002215DEF_TRAVERSE_STMT(ObjCIsaExpr, {})
2216DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {})
Argyrios Kyrtzidis12706732013-05-06 19:08:57 +00002217DEF_TRAVERSE_STMT(ObjCMessageExpr, {
2218 if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo())
2219 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc()));
2220})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002221DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, {})
2222DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {})
2223DEF_TRAVERSE_STMT(ObjCProtocolExpr, {})
2224DEF_TRAVERSE_STMT(ObjCSelectorExpr, {})
2225DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002226DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, {
2227 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc()));
2228})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002229DEF_TRAVERSE_STMT(ParenExpr, {})
2230DEF_TRAVERSE_STMT(ParenListExpr, {})
2231DEF_TRAVERSE_STMT(PredefinedExpr, {})
2232DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
2233DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
2234DEF_TRAVERSE_STMT(StmtExpr, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002235DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
2236 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2237 if (S->hasExplicitTemplateArgs()) {
2238 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2239 S->getNumTemplateArgs()));
2240 }
2241})
2242
2243DEF_TRAVERSE_STMT(UnresolvedMemberExpr, {
2244 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
2245 if (S->hasExplicitTemplateArgs()) {
2246 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(),
2247 S->getNumTemplateArgs()));
2248 }
2249})
2250
2251DEF_TRAVERSE_STMT(SEHTryStmt, {})
2252DEF_TRAVERSE_STMT(SEHExceptStmt, {})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002253DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002254DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002255DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002256
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002257DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
2258DEF_TRAVERSE_STMT(OpaqueValueExpr, {})
Stephen Hines176edba2014-12-01 14:53:08 -08002259DEF_TRAVERSE_STMT(TypoExpr, {})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002260DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002261
2262// These operators (all of them) do not need any action except
2263// iterating over the children.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002264DEF_TRAVERSE_STMT(BinaryConditionalOperator, {})
2265DEF_TRAVERSE_STMT(ConditionalOperator, {})
2266DEF_TRAVERSE_STMT(UnaryOperator, {})
2267DEF_TRAVERSE_STMT(BinaryOperator, {})
2268DEF_TRAVERSE_STMT(CompoundAssignOperator, {})
2269DEF_TRAVERSE_STMT(CXXNoexceptExpr, {})
2270DEF_TRAVERSE_STMT(PackExpansionExpr, {})
2271DEF_TRAVERSE_STMT(SizeOfPackExpr, {})
2272DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {})
2273DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {})
2274DEF_TRAVERSE_STMT(FunctionParmPackExpr, {})
2275DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, {})
Stephen Hines176edba2014-12-01 14:53:08 -08002276DEF_TRAVERSE_STMT(CXXFoldExpr, {})
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002277DEF_TRAVERSE_STMT(AtomicExpr, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002278
2279// These literals (all of them) do not need any action.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002280DEF_TRAVERSE_STMT(IntegerLiteral, {})
2281DEF_TRAVERSE_STMT(CharacterLiteral, {})
2282DEF_TRAVERSE_STMT(FloatingLiteral, {})
2283DEF_TRAVERSE_STMT(ImaginaryLiteral, {})
2284DEF_TRAVERSE_STMT(StringLiteral, {})
2285DEF_TRAVERSE_STMT(ObjCStringLiteral, {})
2286DEF_TRAVERSE_STMT(ObjCBoxedExpr, {})
2287DEF_TRAVERSE_STMT(ObjCArrayLiteral, {})
2288DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {})
2289
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002290// Traverse OpenCL: AsType, Convert.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002291DEF_TRAVERSE_STMT(AsTypeExpr, {})
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002292
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002293// OpenMP directives.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002294template <typename Derived>
2295bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective(
2296 OMPExecutableDirective *S) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002297 for (auto *C : S->clauses()) {
2298 TRY_TO(TraverseOMPClause(C));
2299 }
Stephen Hines651f13c2014-04-23 16:59:28 -07002300 return true;
2301}
2302
Stephen Hines176edba2014-12-01 14:53:08 -08002303template <typename Derived>
2304bool
2305RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) {
2306 return TraverseOMPExecutableDirective(S);
2307}
2308
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002309DEF_TRAVERSE_STMT(OMPParallelDirective,
2310 { TRY_TO(TraverseOMPExecutableDirective(S)); })
Stephen Hines651f13c2014-04-23 16:59:28 -07002311
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002312DEF_TRAVERSE_STMT(OMPSimdDirective,
2313 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2314
2315DEF_TRAVERSE_STMT(OMPForDirective,
2316 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2317
Stephen Hines176edba2014-12-01 14:53:08 -08002318DEF_TRAVERSE_STMT(OMPForSimdDirective,
2319 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2320
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002321DEF_TRAVERSE_STMT(OMPSectionsDirective,
2322 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2323
2324DEF_TRAVERSE_STMT(OMPSectionDirective,
2325 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2326
2327DEF_TRAVERSE_STMT(OMPSingleDirective,
2328 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2329
Stephen Hines176edba2014-12-01 14:53:08 -08002330DEF_TRAVERSE_STMT(OMPMasterDirective,
2331 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2332
2333DEF_TRAVERSE_STMT(OMPCriticalDirective, {
2334 TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName()));
2335 TRY_TO(TraverseOMPExecutableDirective(S));
2336})
2337
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002338DEF_TRAVERSE_STMT(OMPParallelForDirective,
2339 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2340
Stephen Hines176edba2014-12-01 14:53:08 -08002341DEF_TRAVERSE_STMT(OMPParallelForSimdDirective,
2342 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2343
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002344DEF_TRAVERSE_STMT(OMPParallelSectionsDirective,
2345 { TRY_TO(TraverseOMPExecutableDirective(S)); })
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002346
Stephen Hines176edba2014-12-01 14:53:08 -08002347DEF_TRAVERSE_STMT(OMPTaskDirective,
2348 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2349
2350DEF_TRAVERSE_STMT(OMPTaskyieldDirective,
2351 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2352
2353DEF_TRAVERSE_STMT(OMPBarrierDirective,
2354 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2355
2356DEF_TRAVERSE_STMT(OMPTaskwaitDirective,
2357 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2358
2359DEF_TRAVERSE_STMT(OMPFlushDirective,
2360 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2361
2362DEF_TRAVERSE_STMT(OMPOrderedDirective,
2363 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2364
2365DEF_TRAVERSE_STMT(OMPAtomicDirective,
2366 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2367
2368DEF_TRAVERSE_STMT(OMPTargetDirective,
2369 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2370
2371DEF_TRAVERSE_STMT(OMPTeamsDirective,
2372 { TRY_TO(TraverseOMPExecutableDirective(S)); })
2373
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002374// OpenMP clauses.
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002375template <typename Derived>
2376bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
2377 if (!C)
2378 return true;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002379 switch (C->getClauseKind()) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002380#define OPENMP_CLAUSE(Name, Class) \
2381 case OMPC_##Name: \
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002382 TRY_TO(Visit##Class(static_cast<Class *>(C))); \
2383 break;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002384#include "clang/Basic/OpenMPKinds.def"
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002385 case OMPC_threadprivate:
2386 case OMPC_unknown:
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002387 break;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002388 }
2389 return true;
2390}
2391
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002392template <typename Derived>
2393bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002394 TRY_TO(TraverseStmt(C->getCondition()));
Stephen Hines651f13c2014-04-23 16:59:28 -07002395 return true;
2396}
2397
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002398template <typename Derived>
Stephen Hines176edba2014-12-01 14:53:08 -08002399bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) {
2400 TRY_TO(TraverseStmt(C->getCondition()));
2401 return true;
2402}
2403
2404template <typename Derived>
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002405bool
2406RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002407 TRY_TO(TraverseStmt(C->getNumThreads()));
Stephen Hines651f13c2014-04-23 16:59:28 -07002408 return true;
2409}
2410
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002411template <typename Derived>
2412bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002413 TRY_TO(TraverseStmt(C->getSafelen()));
Stephen Hines651f13c2014-04-23 16:59:28 -07002414 return true;
2415}
2416
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002417template <typename Derived>
2418bool
2419RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002420 TRY_TO(TraverseStmt(C->getNumForLoops()));
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002421 return true;
2422}
2423
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002424template <typename Derived>
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002425bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) {
2426 return true;
2427}
2428
2429template <typename Derived>
2430bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002431 return true;
2432}
2433
2434template <typename Derived>
2435bool
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002436RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
2437 TRY_TO(TraverseStmt(C->getChunkSize()));
2438 return true;
2439}
2440
2441template <typename Derived>
2442bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
2443 return true;
2444}
2445
2446template <typename Derived>
2447bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002448 return true;
2449}
2450
2451template <typename Derived>
Stephen Hines176edba2014-12-01 14:53:08 -08002452bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) {
2453 return true;
2454}
2455
2456template <typename Derived>
2457bool
2458RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
2459 return true;
2460}
2461
2462template <typename Derived>
2463bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) {
2464 return true;
2465}
2466
2467template <typename Derived>
2468bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) {
2469 return true;
2470}
2471
2472template <typename Derived>
2473bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) {
2474 return true;
2475}
2476
2477template <typename Derived>
2478bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) {
2479 return true;
2480}
2481
2482template <typename Derived>
2483bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) {
2484 return true;
2485}
2486
2487template <typename Derived>
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002488template <typename T>
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002489bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
2490 for (auto *E : Node->varlists()) {
2491 TRY_TO(TraverseStmt(E));
2492 }
2493 return true;
Alexey Bataev543c4ae2013-09-24 03:17:45 +00002494}
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002495
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002496template <typename Derived>
2497bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002498 TRY_TO(VisitOMPClauseList(C));
Stephen Hines176edba2014-12-01 14:53:08 -08002499 for (auto *E : C->private_copies()) {
2500 TRY_TO(TraverseStmt(E));
2501 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002502 return true;
2503}
2504
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002505template <typename Derived>
2506bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause(
2507 OMPFirstprivateClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002508 TRY_TO(VisitOMPClauseList(C));
Stephen Hines176edba2014-12-01 14:53:08 -08002509 for (auto *E : C->private_copies()) {
2510 TRY_TO(TraverseStmt(E));
2511 }
2512 for (auto *E : C->inits()) {
2513 TRY_TO(TraverseStmt(E));
2514 }
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002515 return true;
2516}
2517
2518template <typename Derived>
2519bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause(
2520 OMPLastprivateClause *C) {
2521 TRY_TO(VisitOMPClauseList(C));
Alexey Bataevd195bc32013-10-01 05:32:34 +00002522 return true;
2523}
2524
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002525template <typename Derived>
2526bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002527 TRY_TO(VisitOMPClauseList(C));
Stephen Hines651f13c2014-04-23 16:59:28 -07002528 return true;
2529}
2530
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002531template <typename Derived>
2532bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002533 TRY_TO(TraverseStmt(C->getStep()));
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -07002534 TRY_TO(TraverseStmt(C->getCalcStep()));
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002535 TRY_TO(VisitOMPClauseList(C));
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -07002536 for (auto *E : C->inits()) {
2537 TRY_TO(TraverseStmt(E));
2538 }
2539 for (auto *E : C->updates()) {
2540 TRY_TO(TraverseStmt(E));
2541 }
2542 for (auto *E : C->finals()) {
2543 TRY_TO(TraverseStmt(E));
2544 }
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002545 return true;
2546}
2547
2548template <typename Derived>
2549bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) {
2550 TRY_TO(TraverseStmt(C->getAlignment()));
2551 TRY_TO(VisitOMPClauseList(C));
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002552 return true;
2553}
2554
2555template <typename Derived>
2556bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002557 TRY_TO(VisitOMPClauseList(C));
2558 return true;
2559}
2560
2561template <typename Derived>
2562bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause(
2563 OMPCopyprivateClause *C) {
2564 TRY_TO(VisitOMPClauseList(C));
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -07002565 for (auto *E : C->source_exprs()) {
2566 TRY_TO(TraverseStmt(E));
2567 }
2568 for (auto *E : C->destination_exprs()) {
2569 TRY_TO(TraverseStmt(E));
2570 }
2571 for (auto *E : C->assignment_ops()) {
2572 TRY_TO(TraverseStmt(E));
2573 }
Stephen Hinesc568f1e2014-07-21 00:47:37 -07002574 return true;
2575}
2576
2577template <typename Derived>
2578bool
2579RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) {
2580 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc()));
2581 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo()));
2582 TRY_TO(VisitOMPClauseList(C));
Alexey Bataev0c018352013-09-06 18:03:48 +00002583 return true;
2584}
2585
Stephen Hines176edba2014-12-01 14:53:08 -08002586template <typename Derived>
2587bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) {
2588 TRY_TO(VisitOMPClauseList(C));
2589 return true;
2590}
2591
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002592// FIXME: look at the following tricky-seeming exprs to see if we
2593// need to recurse on anything. These are ones that have methods
2594// returning decls or qualtypes or nestednamespecifier -- though I'm
2595// not sure if they own them -- or just seemed very complicated, or
2596// had lots of sub-types to explore.
2597//
2598// VisitOverloadExpr and its children: recurse on template args? etc?
2599
2600// FIXME: go through all the stmts and exprs again, and see which of them
2601// create new types, and recurse on the types (TypeLocs?) of those.
2602// Candidates:
2603//
2604// http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
2605// http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html
2606// http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
2607// Every class that has getQualifier.
2608
2609#undef DEF_TRAVERSE_STMT
2610
2611#undef TRY_TO
2612
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002613#undef RecursiveASTVisitor
2614
Argyrios Kyrtzidisdec35a92012-05-07 22:16:46 +00002615} // end namespace clang
2616
2617#endif // LLVM_CLANG_LIBCLANG_RECURSIVEASTVISITOR_H