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