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