1 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the RecursiveASTVisitor interface, which recursively
11 // traverses the entire AST.
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
15 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H
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"
34 // The following three macros are used for meta programming. The code
35 // using them is responsible for defining macro OPERATOR().
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) \
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) \
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) \
62 // All compound assign operators.
64 OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \
65 OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor)
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
73 #define TRY_TO(CALL_EXPR) \
74 do { if (!getDerived().CALL_EXPR) return false; } while (0)
76 /// \brief A class that does preorder depth-first traversal on the
77 /// entire Clang AST and visits each node.
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.
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
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.
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.
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()).
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.
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.
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.
137 template<typename Derived>
138 class RecursiveASTVisitor {
140 /// \brief Return a reference to the derived class.
141 Derived &getDerived() { return *static_cast<Derived*>(this); }
143 /// \brief Return whether this visitor should recurse into
144 /// template instantiations.
145 bool shouldVisitTemplateInstantiations() const { return false; }
147 /// \brief Recursively visit a statement or expression, by
148 /// dispatching to Traverse*() based on the argument's dynamic type.
150 /// \returns false if the visitation was terminated early, true
151 /// otherwise (including when the argument is NULL).
152 bool TraverseStmt(Stmt *S);
154 /// \brief Recursively visit a type, by dispatching to
155 /// Traverse*Type() based on the argument's getTypeClass() property.
157 /// \returns false if the visitation was terminated early, true
158 /// otherwise (including when the argument is a Null type).
159 bool TraverseType(QualType T);
161 /// \brief Recursively visit a type with location, by dispatching to
162 /// Traverse*TypeLoc() based on the argument type's getTypeClass() property.
164 /// \returns false if the visitation was terminated early, true
165 /// otherwise (including when the argument is a Null type location).
166 bool TraverseTypeLoc(TypeLoc TL);
168 /// \brief Recursively visit a declaration, by dispatching to
169 /// Traverse*Decl() based on the argument's dynamic type.
171 /// \returns false if the visitation was terminated early, true
172 /// otherwise (including when the argument is NULL).
173 bool TraverseDecl(Decl *D);
175 /// \brief Recursively visit a C++ nested-name-specifier.
177 /// \returns false if the visitation was terminated early, true otherwise.
178 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
180 /// \brief Recursively visit a template name and dispatch to the
181 /// appropriate method.
183 /// \returns false if the visitation was terminated early, true otherwise.
184 bool TraverseTemplateName(TemplateName Template);
186 /// \brief Recursively visit a template argument and dispatch to the
187 /// appropriate method for the argument type.
189 /// \returns false if the visitation was terminated early, true otherwise.
190 // FIXME: migrate callers to TemplateArgumentLoc instead.
191 bool TraverseTemplateArgument(const TemplateArgument &Arg);
193 /// \brief Recursively visit a template argument location and dispatch to the
194 /// appropriate method for the argument type.
196 /// \returns false if the visitation was terminated early, true otherwise.
197 bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);
199 /// \brief Recursively visit a set of template arguments.
200 /// This can be overridden by a subclass, but it's not expected that
201 /// will be needed -- this visitor always dispatches to another.
203 /// \returns false if the visitation was terminated early, true otherwise.
204 // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead.
205 bool TraverseTemplateArguments(const TemplateArgument *Args,
208 /// \brief Recursively visit a constructor initializer. This
209 /// automatically dispatches to another visitor for the initializer
210 /// expression, but not for the name of the initializer, so may
211 /// be overridden for clients that need access to the name.
213 /// \returns false if the visitation was terminated early, true otherwise.
214 bool TraverseConstructorInitializer(CXXBaseOrMemberInitializer *Init);
216 // ---- Methods on Stmts ----
218 // Declare Traverse*() for all concrete Stmt classes.
219 #define ABSTRACT_STMT(STMT)
220 #define STMT(CLASS, PARENT) \
221 bool Traverse##CLASS(CLASS *S);
222 #include "clang/AST/StmtNodes.inc"
223 // The above header #undefs ABSTRACT_STMT and STMT upon exit.
225 // Define WalkUpFrom*() and empty Visit*() for all Stmt classes.
226 bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); }
227 bool VisitStmt(Stmt *S) { return true; }
228 #define STMT(CLASS, PARENT) \
229 bool WalkUpFrom##CLASS(CLASS *S) { \
230 TRY_TO(WalkUpFrom##PARENT(S)); \
231 TRY_TO(Visit##CLASS(S)); \
234 bool Visit##CLASS(CLASS *S) { return true; }
235 #include "clang/AST/StmtNodes.inc"
237 // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary
238 // operator methods. Unary operators are not classes in themselves
239 // (they're all opcodes in UnaryOperator) but do have visitors.
240 #define OPERATOR(NAME) \
241 bool TraverseUnary##NAME(UnaryOperator *S) { \
242 TRY_TO(WalkUpFromUnary##NAME(S)); \
243 TRY_TO(TraverseStmt(S->getSubExpr())); \
246 bool WalkUpFromUnary##NAME(UnaryOperator *S) { \
247 TRY_TO(WalkUpFromUnaryOperator(S)); \
248 TRY_TO(VisitUnary##NAME(S)); \
251 bool VisitUnary##NAME(UnaryOperator *S) { return true; }
256 // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary
257 // operator methods. Binary operators are not classes in themselves
258 // (they're all opcodes in BinaryOperator) but do have visitors.
259 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \
260 bool TraverseBin##NAME(BINOP_TYPE *S) { \
261 TRY_TO(WalkUpFromBin##NAME(S)); \
262 TRY_TO(TraverseStmt(S->getLHS())); \
263 TRY_TO(TraverseStmt(S->getRHS())); \
266 bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \
267 TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \
268 TRY_TO(VisitBin##NAME(S)); \
271 bool VisitBin##NAME(BINOP_TYPE *S) { return true; }
273 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator)
277 // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound
278 // assignment methods. Compound assignment operators are not
279 // classes in themselves (they're all opcodes in
280 // CompoundAssignOperator) but do have visitors.
281 #define OPERATOR(NAME) \
282 GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator)
286 #undef GENERAL_BINOP_FALLBACK
288 // ---- Methods on Types ----
289 // FIXME: revamp to take TypeLoc's rather than Types.
291 // Declare Traverse*() for all concrete Type classes.
292 #define ABSTRACT_TYPE(CLASS, BASE)
293 #define TYPE(CLASS, BASE) \
294 bool Traverse##CLASS##Type(CLASS##Type *T);
295 #include "clang/AST/TypeNodes.def"
296 // The above header #undefs ABSTRACT_TYPE and TYPE upon exit.
298 // Define WalkUpFrom*() and empty Visit*() for all Type classes.
299 bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); }
300 bool VisitType(Type *T) { return true; }
301 #define TYPE(CLASS, BASE) \
302 bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \
303 TRY_TO(WalkUpFrom##BASE(T)); \
304 TRY_TO(Visit##CLASS##Type(T)); \
307 bool Visit##CLASS##Type(CLASS##Type *T) { return true; }
308 #include "clang/AST/TypeNodes.def"
310 // ---- Methods on TypeLocs ----
311 // FIXME: this currently just calls the matching Type methods
313 // Declare Traverse*() for all concrete Type classes.
314 #define ABSTRACT_TYPELOC(CLASS, BASE)
315 #define TYPELOC(CLASS, BASE) \
316 bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL);
317 #include "clang/AST/TypeLocNodes.def"
318 // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit.
320 // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes.
321 bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); }
322 bool VisitTypeLoc(TypeLoc TL) { return true; }
324 // QualifiedTypeLoc and UnqualTypeLoc are not declared in
325 // TypeNodes.def and thus need to be handled specially.
326 bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) {
327 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
329 bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; }
330 bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) {
331 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc());
333 bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; }
335 // Note that BASE includes trailing 'Type' which CLASS doesn't.
336 #define TYPE(CLASS, BASE) \
337 bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
338 TRY_TO(WalkUpFrom##BASE##Loc(TL)); \
339 TRY_TO(Visit##CLASS##TypeLoc(TL)); \
342 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; }
343 #include "clang/AST/TypeNodes.def"
345 // ---- Methods on Decls ----
347 // Declare Traverse*() for all concrete Decl classes.
348 #define ABSTRACT_DECL(DECL)
349 #define DECL(CLASS, BASE) \
350 bool Traverse##CLASS##Decl(CLASS##Decl *D);
351 #include "clang/AST/DeclNodes.inc"
352 // The above header #undefs ABSTRACT_DECL and DECL upon exit.
354 // Define WalkUpFrom*() and empty Visit*() for all Decl classes.
355 bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); }
356 bool VisitDecl(Decl *D) { return true; }
357 #define DECL(CLASS, BASE) \
358 bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \
359 TRY_TO(WalkUpFrom##BASE(D)); \
360 TRY_TO(Visit##CLASS##Decl(D)); \
363 bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; }
364 #include "clang/AST/DeclNodes.inc"
367 // These are helper methods used by more than one Traverse* method.
368 bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
369 bool TraverseClassInstantiations(ClassTemplateDecl* D, Decl *Pattern);
370 bool TraverseFunctionInstantiations(FunctionTemplateDecl* D) ;
371 bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
373 bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
374 bool TraverseRecordHelper(RecordDecl *D);
375 bool TraverseCXXRecordHelper(CXXRecordDecl *D);
376 bool TraverseDeclaratorHelper(DeclaratorDecl *D);
377 bool TraverseDeclContextHelper(DeclContext *DC);
378 bool TraverseFunctionHelper(FunctionDecl *D);
379 bool TraverseVarHelper(VarDecl *D);
382 #define DISPATCH(NAME, CLASS, VAR) \
383 return getDerived().Traverse##NAME(static_cast<CLASS*>(VAR))
385 template<typename Derived>
386 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S) {
390 // If we have a binary expr, dispatch to the subcode of the binop. A smart
391 // optimizer (e.g. LLVM) will fold this comparison into the switch stmt
393 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
394 switch (BinOp->getOpcode()) {
395 #define OPERATOR(NAME) \
396 case BO_##NAME: DISPATCH(Bin##PtrMemD, BinaryOperator, S);
402 #define OPERATOR(NAME) \
403 case BO_##NAME##Assign: \
404 DISPATCH(Bin##NAME##Assign, CompoundAssignOperator, S);
410 } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) {
411 switch (UnOp->getOpcode()) {
412 #define OPERATOR(NAME) \
413 case UO_##NAME: DISPATCH(Unary##NAME, UnaryOperator, S);
421 // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt.
422 switch (S->getStmtClass()) {
423 case Stmt::NoStmtClass: break;
424 #define ABSTRACT_STMT(STMT)
425 #define STMT(CLASS, PARENT) \
426 case Stmt::CLASS##Class: DISPATCH(CLASS, CLASS, S);
427 #include "clang/AST/StmtNodes.inc"
433 template<typename Derived>
434 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) {
438 switch (T->getTypeClass()) {
439 #define ABSTRACT_TYPE(CLASS, BASE)
440 #define TYPE(CLASS, BASE) \
441 case Type::CLASS: DISPATCH(CLASS##Type, CLASS##Type, T.getTypePtr());
442 #include "clang/AST/TypeNodes.def"
448 template<typename Derived>
449 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) {
453 switch (TL.getTypeLocClass()) {
454 #define ABSTRACT_TYPELOC(CLASS, BASE)
455 #define TYPELOC(CLASS, BASE) \
456 case TypeLoc::CLASS: \
457 return getDerived().Traverse##CLASS##TypeLoc(*cast<CLASS##TypeLoc>(&TL));
458 #include "clang/AST/TypeLocNodes.def"
465 template<typename Derived>
466 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
470 // As a syntax visitor, we want to ignore declarations for
471 // implicitly-defined declarations (ones not typed explicitly by the
476 switch (D->getKind()) {
477 #define ABSTRACT_DECL(DECL)
478 #define DECL(CLASS, BASE) \
479 case Decl::CLASS: DISPATCH(CLASS##Decl, CLASS##Decl, D);
480 #include "clang/AST/DeclNodes.inc"
488 template<typename Derived>
489 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier(
490 NestedNameSpecifier *NNS) {
494 if (NNS->getPrefix())
495 TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix()));
497 switch (NNS->getKind()) {
498 case NestedNameSpecifier::Identifier:
499 case NestedNameSpecifier::Namespace:
500 case NestedNameSpecifier::Global:
503 case NestedNameSpecifier::TypeSpec:
504 case NestedNameSpecifier::TypeSpecWithTemplate:
505 TRY_TO(TraverseType(QualType(NNS->getAsType(), 0)));
511 template<typename Derived>
512 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
513 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
514 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
515 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
516 TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
521 template<typename Derived>
522 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
523 const TemplateArgument &Arg) {
524 switch (Arg.getKind()) {
525 case TemplateArgument::Null:
526 case TemplateArgument::Declaration:
527 case TemplateArgument::Integral:
530 case TemplateArgument::Type:
531 return getDerived().TraverseType(Arg.getAsType());
533 case TemplateArgument::Template:
534 return getDerived().TraverseTemplateName(Arg.getAsTemplate());
536 case TemplateArgument::Expression:
537 return getDerived().TraverseStmt(Arg.getAsExpr());
539 case TemplateArgument::Pack:
540 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
547 // FIXME: no template name location?
548 // FIXME: no source locations for a template argument pack?
549 template<typename Derived>
550 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
551 const TemplateArgumentLoc &ArgLoc) {
552 const TemplateArgument &Arg = ArgLoc.getArgument();
554 switch (Arg.getKind()) {
555 case TemplateArgument::Null:
556 case TemplateArgument::Declaration:
557 case TemplateArgument::Integral:
560 case TemplateArgument::Type: {
561 // FIXME: how can TSI ever be NULL?
562 if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo())
563 return getDerived().TraverseTypeLoc(TSI->getTypeLoc());
568 case TemplateArgument::Template:
569 return getDerived().TraverseTemplateName(Arg.getAsTemplate());
571 case TemplateArgument::Expression:
572 return getDerived().TraverseStmt(ArgLoc.getSourceExpression());
574 case TemplateArgument::Pack:
575 return getDerived().TraverseTemplateArguments(Arg.pack_begin(),
582 template<typename Derived>
583 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments(
584 const TemplateArgument *Args,
586 for (unsigned I = 0; I != NumArgs; ++I) {
587 TRY_TO(TraverseTemplateArgument(Args[I]));
593 template<typename Derived>
594 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer(
595 CXXBaseOrMemberInitializer *Init) {
596 // FIXME: recurse on TypeLoc of the base initializer if isBaseInitializer()?
597 if (Init->isWritten())
598 TRY_TO(TraverseStmt(Init->getInit()));
603 // ----------------- Type traversal -----------------
605 // This macro makes available a variable T, the passed-in type.
606 #define DEF_TRAVERSE_TYPE(TYPE, CODE) \
607 template<typename Derived> \
608 bool RecursiveASTVisitor<Derived>::Traverse##TYPE (TYPE *T) { \
609 TRY_TO(WalkUpFrom##TYPE (T)); \
614 DEF_TRAVERSE_TYPE(BuiltinType, { })
616 DEF_TRAVERSE_TYPE(ComplexType, {
617 TRY_TO(TraverseType(T->getElementType()));
620 DEF_TRAVERSE_TYPE(PointerType, {
621 TRY_TO(TraverseType(T->getPointeeType()));
624 DEF_TRAVERSE_TYPE(BlockPointerType, {
625 TRY_TO(TraverseType(T->getPointeeType()));
628 DEF_TRAVERSE_TYPE(LValueReferenceType, {
629 TRY_TO(TraverseType(T->getPointeeType()));
632 DEF_TRAVERSE_TYPE(RValueReferenceType, {
633 TRY_TO(TraverseType(T->getPointeeType()));
636 DEF_TRAVERSE_TYPE(MemberPointerType, {
637 TRY_TO(TraverseType(QualType(T->getClass(), 0)));
638 TRY_TO(TraverseType(T->getPointeeType()));
641 DEF_TRAVERSE_TYPE(ConstantArrayType, {
642 TRY_TO(TraverseType(T->getElementType()));
645 DEF_TRAVERSE_TYPE(IncompleteArrayType, {
646 TRY_TO(TraverseType(T->getElementType()));
649 DEF_TRAVERSE_TYPE(VariableArrayType, {
650 TRY_TO(TraverseType(T->getElementType()));
651 TRY_TO(TraverseStmt(T->getSizeExpr()));
654 DEF_TRAVERSE_TYPE(DependentSizedArrayType, {
655 TRY_TO(TraverseType(T->getElementType()));
656 if (T->getSizeExpr())
657 TRY_TO(TraverseStmt(T->getSizeExpr()));
660 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, {
661 if (T->getSizeExpr())
662 TRY_TO(TraverseStmt(T->getSizeExpr()));
663 TRY_TO(TraverseType(T->getElementType()));
666 DEF_TRAVERSE_TYPE(VectorType, {
667 TRY_TO(TraverseType(T->getElementType()));
670 DEF_TRAVERSE_TYPE(ExtVectorType, {
671 TRY_TO(TraverseType(T->getElementType()));
674 DEF_TRAVERSE_TYPE(FunctionNoProtoType, {
675 TRY_TO(TraverseType(T->getResultType()));
678 DEF_TRAVERSE_TYPE(FunctionProtoType, {
679 TRY_TO(TraverseType(T->getResultType()));
681 for (FunctionProtoType::arg_type_iterator A = T->arg_type_begin(),
682 AEnd = T->arg_type_end();
684 TRY_TO(TraverseType(*A));
687 for (FunctionProtoType::exception_iterator E = T->exception_begin(),
688 EEnd = T->exception_end();
690 TRY_TO(TraverseType(*E));
694 DEF_TRAVERSE_TYPE(UnresolvedUsingType, { })
695 DEF_TRAVERSE_TYPE(TypedefType, { })
697 DEF_TRAVERSE_TYPE(TypeOfExprType, {
698 TRY_TO(TraverseStmt(T->getUnderlyingExpr()));
701 DEF_TRAVERSE_TYPE(TypeOfType, {
702 TRY_TO(TraverseType(T->getUnderlyingType()));
705 DEF_TRAVERSE_TYPE(DecltypeType, {
706 TRY_TO(TraverseStmt(T->getUnderlyingExpr()));
709 DEF_TRAVERSE_TYPE(RecordType, { })
710 DEF_TRAVERSE_TYPE(EnumType, { })
711 DEF_TRAVERSE_TYPE(TemplateTypeParmType, { })
712 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, { })
714 DEF_TRAVERSE_TYPE(TemplateSpecializationType, {
715 TRY_TO(TraverseTemplateName(T->getTemplateName()));
716 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
719 DEF_TRAVERSE_TYPE(InjectedClassNameType, { })
721 DEF_TRAVERSE_TYPE(ElaboratedType, {
722 if (T->getQualifier()) {
723 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
725 TRY_TO(TraverseType(T->getNamedType()));
728 DEF_TRAVERSE_TYPE(DependentNameType, {
729 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
732 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, {
733 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
734 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs()));
737 DEF_TRAVERSE_TYPE(ObjCInterfaceType, { })
739 DEF_TRAVERSE_TYPE(ObjCObjectType, {
740 // We have to watch out here because an ObjCInterfaceType's base
742 if (T->getBaseType().getTypePtr() != T)
743 TRY_TO(TraverseType(T->getBaseType()));
746 DEF_TRAVERSE_TYPE(ObjCObjectPointerType, {
747 TRY_TO(TraverseType(T->getPointeeType()));
750 #undef DEF_TRAVERSE_TYPE
752 // ----------------- TypeLoc traversal -----------------
754 // This macro makes available a variable TL, the passed-in TypeLoc.
755 // It calls WalkUpFrom* for the Type in the given TypeLoc, in addition
756 // to WalkUpFrom* for the TypeLoc itself, such that existing clients
757 // that override the WalkUpFrom*Type() and/or Visit*Type() methods
759 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \
760 template<typename Derived> \
761 bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \
762 TRY_TO(WalkUpFrom##TYPE(TL.getTypePtr())); \
763 TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \
768 template<typename Derived>
769 bool RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(
770 QualifiedTypeLoc TL) {
771 // Move this over to the 'main' typeloc tree. Note that this is a
772 // move -- we pretend that we were really looking at the unqualified
773 // typeloc all along -- rather than a recursion, so we don't follow
774 // the normal CRTP plan of going through
775 // getDerived().TraverseTypeLoc. If we did, we'd be traversing
776 // twice for the same type (once as a QualifiedTypeLoc version of
777 // the type, once as an UnqualifiedTypeLoc version of the type),
778 // which in effect means we'd call VisitTypeLoc twice with the
779 // 'same' type. This solves that problem, at the cost of never
780 // seeing the qualified version of the type (unless the client
781 // subclasses TraverseQualifiedTypeLoc themselves). It's not a
782 // perfect solution. A perfect solution probably requires making
783 // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a
784 // wrapper around Type* -- rather than being its own class in the
786 return TraverseTypeLoc(TL.getUnqualifiedLoc());
789 DEF_TRAVERSE_TYPELOC(BuiltinType, { })
791 // FIXME: ComplexTypeLoc is unfinished
792 DEF_TRAVERSE_TYPELOC(ComplexType, {
793 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
796 DEF_TRAVERSE_TYPELOC(PointerType, {
797 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
800 DEF_TRAVERSE_TYPELOC(BlockPointerType, {
801 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
804 DEF_TRAVERSE_TYPELOC(LValueReferenceType, {
805 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
808 DEF_TRAVERSE_TYPELOC(RValueReferenceType, {
809 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
812 // FIXME: location of base class?
813 // We traverse this in the type case as well, but how is it not reached through
815 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
816 TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
817 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
820 template<typename Derived>
821 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
822 // This isn't available for ArrayType, but is for the ArrayTypeLoc.
823 TRY_TO(TraverseStmt(TL.getSizeExpr()));
827 DEF_TRAVERSE_TYPELOC(ConstantArrayType, {
828 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
829 return TraverseArrayTypeLocHelper(TL);
832 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, {
833 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
834 return TraverseArrayTypeLocHelper(TL);
837 DEF_TRAVERSE_TYPELOC(VariableArrayType, {
838 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
839 return TraverseArrayTypeLocHelper(TL);
842 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, {
843 TRY_TO(TraverseTypeLoc(TL.getElementLoc()));
844 return TraverseArrayTypeLocHelper(TL);
847 // FIXME: order? why not size expr first?
848 // FIXME: base VectorTypeLoc is unfinished
849 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, {
850 if (TL.getTypePtr()->getSizeExpr())
851 TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr()));
852 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
855 // FIXME: VectorTypeLoc is unfinished
856 DEF_TRAVERSE_TYPELOC(VectorType, {
857 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
860 // FIXME: size and attributes
861 // FIXME: base VectorTypeLoc is unfinished
862 DEF_TRAVERSE_TYPELOC(ExtVectorType, {
863 TRY_TO(TraverseType(TL.getTypePtr()->getElementType()));
866 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType, {
867 TRY_TO(TraverseTypeLoc(TL.getResultLoc()));
870 // FIXME: location of arguments, exception specifications (attributes?)
871 // Note that we have the ParmVarDecl's here. Do we want to use them?
872 DEF_TRAVERSE_TYPELOC(FunctionProtoType, {
873 TRY_TO(TraverseTypeLoc(TL.getResultLoc()));
875 FunctionProtoType *T = TL.getTypePtr();
877 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
878 TRY_TO(TraverseDecl(TL.getArg(I)));
881 for (FunctionProtoType::arg_type_iterator A = T->arg_type_begin(),
882 AEnd = T->arg_type_end();
884 TRY_TO(TraverseType(*A));
886 for (FunctionProtoType::exception_iterator E = T->exception_begin(),
887 EEnd = T->exception_end();
889 TRY_TO(TraverseType(*E));
893 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, { })
894 DEF_TRAVERSE_TYPELOC(TypedefType, { })
896 DEF_TRAVERSE_TYPELOC(TypeOfExprType, {
897 TRY_TO(TraverseStmt(TL.getUnderlyingExpr()));
900 DEF_TRAVERSE_TYPELOC(TypeOfType, {
901 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc()));
904 // FIXME: location of underlying expr
905 DEF_TRAVERSE_TYPELOC(DecltypeType, {
906 TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr()));
909 DEF_TRAVERSE_TYPELOC(RecordType, { })
910 DEF_TRAVERSE_TYPELOC(EnumType, { })
911 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, { })
912 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, { })
914 // FIXME: use the loc for the template name?
915 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, {
916 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName()));
917 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
918 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
922 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, { })
924 // FIXME: use the sourceloc on qualifier?
925 DEF_TRAVERSE_TYPELOC(ElaboratedType, {
926 if (TL.getTypePtr()->getQualifier()) {
927 TRY_TO(TraverseNestedNameSpecifier(TL.getTypePtr()->getQualifier()));
929 TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc()));
932 // FIXME: use the sourceloc on qualifier?
933 DEF_TRAVERSE_TYPELOC(DependentNameType, {
934 TRY_TO(TraverseNestedNameSpecifier(TL.getTypePtr()->getQualifier()));
937 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, {
938 TRY_TO(TraverseNestedNameSpecifier(TL.getTypePtr()->getQualifier()));
939 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
940 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I)));
944 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, { })
946 DEF_TRAVERSE_TYPELOC(ObjCObjectType, {
947 // We have to watch out here because an ObjCInterfaceType's base
949 if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr())
950 TRY_TO(TraverseTypeLoc(TL.getBaseLoc()));
953 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType, {
954 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
957 #undef DEF_TRAVERSE_TYPELOC
959 // ----------------- Decl traversal -----------------
961 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing
962 // the children that come from the DeclContext associated with it.
963 // Therefore each Traverse* only needs to worry about children other
966 template<typename Derived>
967 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) {
971 for (DeclContext::decl_iterator Child = DC->decls_begin(),
972 ChildEnd = DC->decls_end();
973 Child != ChildEnd; ++Child) {
974 TRY_TO(TraverseDecl(*Child));
980 // This macro makes available a variable D, the passed-in decl.
981 #define DEF_TRAVERSE_DECL(DECL, CODE) \
982 template<typename Derived> \
983 bool RecursiveASTVisitor<Derived>::Traverse##DECL (DECL *D) { \
984 TRY_TO(WalkUpFrom##DECL (D)); \
986 TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \
990 DEF_TRAVERSE_DECL(AccessSpecDecl, { })
992 DEF_TRAVERSE_DECL(BlockDecl, {
993 // We don't traverse nodes in param_begin()/param_end(), as they
994 // appear in decls_begin()/decls_end() and thus are handled by the
995 // DEF_TRAVERSE_DECL macro already.
996 TRY_TO(TraverseStmt(D->getBody()));
999 DEF_TRAVERSE_DECL(FileScopeAsmDecl, {
1000 TRY_TO(TraverseStmt(D->getAsmString()));
1003 DEF_TRAVERSE_DECL(FriendDecl, {
1004 TRY_TO(TraverseDecl(D->getFriendDecl()));
1007 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
1008 TRY_TO(TraverseDecl(D->getFriendDecl()));
1009 for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) {
1010 TemplateParameterList *TPL = D->getTemplateParameterList(I);
1011 for (TemplateParameterList::iterator ITPL = TPL->begin(),
1013 ITPL != ETPL; ++ITPL) {
1014 TRY_TO(TraverseDecl(*ITPL));
1019 DEF_TRAVERSE_DECL(LinkageSpecDecl, { })
1021 DEF_TRAVERSE_DECL(ObjCClassDecl, {
1022 // FIXME: implement this
1025 DEF_TRAVERSE_DECL(ObjCForwardProtocolDecl, {
1026 // FIXME: implement this
1029 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {
1030 // FIXME: implement this
1033 DEF_TRAVERSE_DECL(StaticAssertDecl, {
1034 TRY_TO(TraverseStmt(D->getAssertExpr()));
1035 TRY_TO(TraverseStmt(D->getMessage()));
1038 DEF_TRAVERSE_DECL(TranslationUnitDecl, {
1039 // Code in an unnamed namespace shows up automatically in
1040 // decls_begin()/decls_end(). Thus we don't need to recurse on
1041 // D->getAnonymousNamespace().
1044 DEF_TRAVERSE_DECL(NamespaceAliasDecl, {
1045 // We shouldn't traverse an aliased namespace, since it will be
1046 // defined (and, therefore, traversed) somewhere else.
1048 // This return statement makes sure the traversal of nodes in
1049 // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro)
1050 // is skipped - don't remove it.
1054 DEF_TRAVERSE_DECL(NamespaceDecl, {
1055 // Code in an unnamed namespace shows up automatically in
1056 // decls_begin()/decls_end(). Thus we don't need to recurse on
1057 // D->getAnonymousNamespace().
1060 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {
1064 DEF_TRAVERSE_DECL(ObjCCategoryDecl, {
1068 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {
1072 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {
1076 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {
1080 DEF_TRAVERSE_DECL(ObjCProtocolDecl, {
1084 DEF_TRAVERSE_DECL(ObjCMethodDecl, {
1088 DEF_TRAVERSE_DECL(ObjCPropertyDecl, {
1092 DEF_TRAVERSE_DECL(UsingDecl, {
1093 TRY_TO(TraverseNestedNameSpecifier(D->getTargetNestedNameDecl()));
1096 DEF_TRAVERSE_DECL(UsingDirectiveDecl, {
1097 TRY_TO(TraverseNestedNameSpecifier(D->getQualifier()));
1100 DEF_TRAVERSE_DECL(UsingShadowDecl, { })
1102 // A helper method for TemplateDecl's children.
1103 template<typename Derived>
1104 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
1105 TemplateParameterList *TPL) {
1107 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1109 TRY_TO(TraverseDecl(*I));
1115 // A helper method for traversing the implicit instantiations of a
1117 template<typename Derived>
1118 bool RecursiveASTVisitor<Derived>::TraverseClassInstantiations(
1119 ClassTemplateDecl* D, Decl *Pattern) {
1120 assert(isa<ClassTemplateDecl>(Pattern) ||
1121 isa<ClassTemplatePartialSpecializationDecl>(Pattern));
1123 ClassTemplateDecl::spec_iterator end = D->spec_end();
1124 for (ClassTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) {
1125 ClassTemplateSpecializationDecl* SD = *it;
1127 switch (SD->getSpecializationKind()) {
1128 // Visit the implicit instantiations with the requested pattern.
1129 case TSK_ImplicitInstantiation: {
1130 llvm::PointerUnion<ClassTemplateDecl *,
1131 ClassTemplatePartialSpecializationDecl *> U
1132 = SD->getInstantiatedFrom();
1135 if (U.is<ClassTemplateDecl*>())
1136 ShouldVisit = (U.get<ClassTemplateDecl*>() == Pattern);
1139 = (U.get<ClassTemplatePartialSpecializationDecl*>() == Pattern);
1142 TRY_TO(TraverseClassTemplateSpecializationDecl(SD));
1146 // We don't need to do anything on an explicit instantiation
1147 // or explicit specialization because there will be an explicit
1148 // node for it elsewhere.
1149 case TSK_ExplicitInstantiationDeclaration:
1150 case TSK_ExplicitInstantiationDefinition:
1151 case TSK_ExplicitSpecialization:
1154 // We don't need to do anything for an uninstantiated
1156 case TSK_Undeclared:
1164 DEF_TRAVERSE_DECL(ClassTemplateDecl, {
1165 CXXRecordDecl* TempDecl = D->getTemplatedDecl();
1166 TRY_TO(TraverseDecl(TempDecl));
1167 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1169 // By default, we do not traverse the instantiations of
1170 // class templates since they do not apprear in the user code. The
1171 // following code optionally traverses them.
1172 if (getDerived().shouldVisitTemplateInstantiations()) {
1173 // If this is the definition of the primary template, visit
1174 // instantiations which were formed from this pattern.
1175 if (D->isThisDeclarationADefinition())
1176 TRY_TO(TraverseClassInstantiations(D, D));
1179 // Note that getInstantiatedFromMemberTemplate() is just a link
1180 // from a template instantiation back to the template from which
1181 // it was instantiated, and thus should not be traversed.
1184 // A helper method for traversing the instantiations of a
1185 // function while skipping its specializations.
1186 template<typename Derived>
1187 bool RecursiveASTVisitor<Derived>::TraverseFunctionInstantiations(
1188 FunctionTemplateDecl* D) {
1189 FunctionTemplateDecl::spec_iterator end = D->spec_end();
1190 for (FunctionTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) {
1191 FunctionDecl* FD = *it;
1192 switch (FD->getTemplateSpecializationKind()) {
1193 case TSK_ImplicitInstantiation:
1194 // We don't know what kind of FunctionDecl this is.
1195 TRY_TO(TraverseDecl(FD));
1198 // No need to visit explicit instantiations, we'll find the node
1200 case TSK_ExplicitInstantiationDeclaration:
1201 case TSK_ExplicitInstantiationDefinition:
1204 case TSK_Undeclared: // Declaration of the template definition.
1205 case TSK_ExplicitSpecialization:
1208 assert(false && "Unknown specialization kind.");
1215 DEF_TRAVERSE_DECL(FunctionTemplateDecl, {
1216 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1217 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1219 // By default, we do not traverse the instantiations of
1220 // function templates since they do not apprear in the user code. The
1221 // following code optionally traverses them.
1222 if (getDerived().shouldVisitTemplateInstantiations()) {
1223 // Explicit function specializations will be traversed from the
1224 // context of their declaration. There is therefore no need to
1225 // traverse them for here.
1227 // In addition, we only traverse the function instantiations when
1228 // the function template is a function template definition.
1229 if (D->isThisDeclarationADefinition()) {
1230 TRY_TO(TraverseFunctionInstantiations(D));
1235 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
1236 // D is the "T" in something like
1237 // template <template <typename> class T> class container { };
1238 TRY_TO(TraverseDecl(D->getTemplatedDecl()));
1239 if (D->hasDefaultArgument()) {
1240 TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument()));
1242 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
1245 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1246 // D is the "T" in something like "template<typename T> class vector;"
1247 if (D->getTypeForDecl())
1248 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1249 if (D->hasDefaultArgument())
1250 TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
1253 DEF_TRAVERSE_DECL(TypedefDecl, {
1254 TRY_TO(TraverseType(D->getUnderlyingType()));
1255 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1256 // declaring the typedef, not something that was written in the
1260 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, {
1261 // A dependent using declaration which was marked with 'typename'.
1262 // template<class T> class A : public B<T> { using typename B<T>::foo; };
1263 TRY_TO(TraverseNestedNameSpecifier(D->getTargetNestedNameSpecifier()));
1264 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1265 // declaring the type, not something that was written in the
1269 DEF_TRAVERSE_DECL(EnumDecl, {
1270 if (D->getTypeForDecl())
1271 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1273 TRY_TO(TraverseNestedNameSpecifier(D->getQualifier()));
1274 // The enumerators are already traversed by
1275 // decls_begin()/decls_end().
1279 // Helper methods for RecordDecl and its children.
1280 template<typename Derived>
1281 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(
1283 // We shouldn't traverse D->getTypeForDecl(); it's a result of
1284 // declaring the type, not something that was written in the source.
1286 // The anonymous struct or union object is the variable or field
1287 // whose type is the anonymous struct or union. We shouldn't
1288 // traverse D->getAnonymousStructOrUnionObject(), as it's not
1289 // something that is explicitly written in the source.
1290 TRY_TO(TraverseNestedNameSpecifier(D->getQualifier()));
1294 template<typename Derived>
1295 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(
1297 if (!TraverseRecordHelper(D))
1299 if (D->hasDefinition()) {
1300 for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
1303 TRY_TO(TraverseTypeLoc(I->getTypeSourceInfo()->getTypeLoc()));
1305 // We don't traverse the friends or the conversions, as they are
1306 // already in decls_begin()/decls_end().
1311 DEF_TRAVERSE_DECL(RecordDecl, {
1312 TRY_TO(TraverseRecordHelper(D));
1315 DEF_TRAVERSE_DECL(CXXRecordDecl, {
1316 TRY_TO(TraverseCXXRecordHelper(D));
1319 DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, {
1320 // For implicit instantiations ("set<int> x;"), we don't want to
1321 // recurse at all, since the instatiated class isn't written in
1322 // the source code anywhere. (Note the instatiated *type* --
1323 // set<int> -- is written, and will still get a callback of
1324 // TemplateSpecializationType). For explicit instantiations
1325 // ("template set<int>;"), we do need a callback, since this
1326 // is the only callback that's made for this instantiation.
1327 // We use getTypeAsWritten() to distinguish.
1328 if (TypeSourceInfo *TSI = D->getTypeAsWritten())
1329 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
1331 if (!getDerived().shouldVisitTemplateInstantiations() &&
1332 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)
1333 // Returning from here skips traversing the
1334 // declaration context of the ClassTemplateSpecializationDecl
1335 // (embedded in the DEF_TRAVERSE_DECL() macro)
1336 // which contains the instantiated members of the class.
1340 template <typename Derived>
1341 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper(
1342 const TemplateArgumentLoc *TAL, unsigned Count) {
1343 for (unsigned I = 0; I < Count; ++I) {
1344 TRY_TO(TraverseTemplateArgumentLoc(TAL[I]));
1349 DEF_TRAVERSE_DECL(ClassTemplatePartialSpecializationDecl, {
1350 // The partial specialization.
1351 if (TemplateParameterList *TPL = D->getTemplateParameters()) {
1352 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end();
1354 TRY_TO(TraverseDecl(*I));
1357 // The args that remains unspecialized.
1358 TRY_TO(TraverseTemplateArgumentLocsHelper(
1359 D->getTemplateArgsAsWritten(), D->getNumTemplateArgsAsWritten()));
1361 // Don't need the ClassTemplatePartialSpecializationHelper, even
1362 // though that's our parent class -- we already visit all the
1363 // template args here.
1364 TRY_TO(TraverseCXXRecordHelper(D));
1366 // If we're visiting instantiations, visit the instantiations of
1367 // this template now.
1368 if (getDerived().shouldVisitTemplateInstantiations() &&
1369 D->isThisDeclarationADefinition())
1370 TRY_TO(TraverseClassInstantiations(D->getSpecializedTemplate(), D));
1373 DEF_TRAVERSE_DECL(EnumConstantDecl, {
1374 TRY_TO(TraverseStmt(D->getInitExpr()));
1377 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, {
1378 // Like UnresolvedUsingTypenameDecl, but without the 'typename':
1379 // template <class T> Class A : public Base<T> { using Base<T>::foo; };
1380 TRY_TO(TraverseNestedNameSpecifier(D->getTargetNestedNameSpecifier()));
1383 template<typename Derived>
1384 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) {
1385 TRY_TO(TraverseNestedNameSpecifier(D->getQualifier()));
1386 if (D->getTypeSourceInfo())
1387 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
1391 DEF_TRAVERSE_DECL(FieldDecl, {
1392 TRY_TO(TraverseDeclaratorHelper(D));
1393 if (D->isBitField())
1394 TRY_TO(TraverseStmt(D->getBitWidth()));
1397 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, {
1398 TRY_TO(TraverseDeclaratorHelper(D));
1399 if (D->isBitField())
1400 TRY_TO(TraverseStmt(D->getBitWidth()));
1401 // FIXME: implement the rest.
1404 DEF_TRAVERSE_DECL(ObjCIvarDecl, {
1405 TRY_TO(TraverseDeclaratorHelper(D));
1406 if (D->isBitField())
1407 TRY_TO(TraverseStmt(D->getBitWidth()));
1408 // FIXME: implement the rest.
1411 template<typename Derived>
1412 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) {
1413 TRY_TO(TraverseNestedNameSpecifier(D->getQualifier()));
1415 // Visit the function type itself, which can be either
1416 // FunctionNoProtoType or FunctionProtoType, or a typedef. If it's
1417 // not a Function*ProtoType, then it can't have a body or arguments,
1418 // so we have to do less work.
1419 Type *FuncType = D->getType().getTypePtr();
1420 if (FunctionProtoType *FuncProto = dyn_cast<FunctionProtoType>(FuncType)) {
1421 if (D->isThisDeclarationADefinition()) {
1422 // Don't call Traverse*, or the result type and parameter types
1423 // will be double counted.
1424 TRY_TO(WalkUpFromFunctionProtoType(FuncProto));
1426 // This works around a bug in Clang that does not add the parameters
1427 // to decls_begin/end for function declarations (as opposed to
1429 // http://llvm.org/PR7442
1430 // We work around this here by traversing the function type.
1431 // This isn't perfect because we don't traverse the default
1432 // values, if any. It also may not interact great with
1433 // templates. But it's the best we can do until the bug is
1435 // FIXME: replace the entire 'if' statement with
1436 // TRY_TO(WalkUpFromFunctionProtoType(FuncProto));
1437 // when the bug is fixed.
1438 TRY_TO(TraverseFunctionProtoType(FuncProto));
1441 } else if (FunctionNoProtoType *FuncNoProto =
1442 dyn_cast<FunctionNoProtoType>(FuncType)) {
1443 // Don't call Traverse*, or the result type will be double
1445 TRY_TO(WalkUpFromFunctionNoProtoType(FuncNoProto));
1446 } else { // a typedef type, or who knows what
1447 assert(!D->isThisDeclarationADefinition() && "Unexpected function type");
1448 TRY_TO(TraverseType(D->getType()));
1452 TRY_TO(TraverseType(D->getResultType()));
1454 // If we're an explicit template specialization, iterate over the
1455 // template args that were explicitly specified.
1456 if (const FunctionTemplateSpecializationInfo *FTSI =
1457 D->getTemplateSpecializationInfo()) {
1458 if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared &&
1459 FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
1460 // A specialization might not have explicit template arguments if it has
1461 // a templated return type and concrete arguments.
1462 if (const TemplateArgumentListInfo *TALI =
1463 FTSI->TemplateArgumentsAsWritten) {
1464 TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getArgumentArray(),
1470 for (FunctionDecl::param_iterator I = D->param_begin(), E = D->param_end();
1472 TRY_TO(TraverseDecl(*I));
1475 if (FunctionProtoType *FuncProto = dyn_cast<FunctionProtoType>(FuncType)) {
1476 if (D->isThisDeclarationADefinition()) {
1477 // This would be visited if we called TraverseType(D->getType())
1478 // above, but we don't (at least, not in the
1479 // declaration-is-a-definition case), in order to avoid duplicate
1480 // visiting for parameters. (We need to check parameters here,
1481 // rather than letting D->getType() do it, so we visit default
1482 // parameter values). So we need to re-do some of the work the
1484 for (FunctionProtoType::exception_iterator
1485 E = FuncProto->exception_begin(),
1486 EEnd = FuncProto->exception_end();
1488 TRY_TO(TraverseType(*E));
1493 if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
1494 // Constructor initializers.
1495 for (CXXConstructorDecl::init_iterator I = Ctor->init_begin(),
1496 E = Ctor->init_end();
1498 TRY_TO(TraverseConstructorInitializer(*I));
1502 if (D->isThisDeclarationADefinition()) {
1503 TRY_TO(TraverseStmt(D->getBody())); // Function body.
1508 DEF_TRAVERSE_DECL(FunctionDecl, {
1509 // We skip decls_begin/decls_end, which are already covered by
1510 // TraverseFunctionHelper().
1511 return TraverseFunctionHelper(D);
1514 DEF_TRAVERSE_DECL(CXXMethodDecl, {
1515 // We skip decls_begin/decls_end, which are already covered by
1516 // TraverseFunctionHelper().
1517 return TraverseFunctionHelper(D);
1520 DEF_TRAVERSE_DECL(CXXConstructorDecl, {
1521 // We skip decls_begin/decls_end, which are already covered by
1522 // TraverseFunctionHelper().
1523 return TraverseFunctionHelper(D);
1526 // CXXConversionDecl is the declaration of a type conversion operator.
1527 // It's not a cast expression.
1528 DEF_TRAVERSE_DECL(CXXConversionDecl, {
1529 // We skip decls_begin/decls_end, which are already covered by
1530 // TraverseFunctionHelper().
1531 return TraverseFunctionHelper(D);
1534 DEF_TRAVERSE_DECL(CXXDestructorDecl, {
1535 // We skip decls_begin/decls_end, which are already covered by
1536 // TraverseFunctionHelper().
1537 return TraverseFunctionHelper(D);
1540 template<typename Derived>
1541 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) {
1542 TRY_TO(TraverseDeclaratorHelper(D));
1543 TRY_TO(TraverseStmt(D->getInit()));
1547 DEF_TRAVERSE_DECL(VarDecl, {
1548 TRY_TO(TraverseVarHelper(D));
1551 DEF_TRAVERSE_DECL(ImplicitParamDecl, {
1552 TRY_TO(TraverseVarHelper(D));
1555 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, {
1556 // A non-type template parameter, e.g. "S" in template<int S> class Foo ...
1557 TRY_TO(TraverseVarHelper(D));
1558 TRY_TO(TraverseStmt(D->getDefaultArgument()));
1561 DEF_TRAVERSE_DECL(ParmVarDecl, {
1562 TRY_TO(TraverseVarHelper(D));
1564 if (D->hasDefaultArg() &&
1565 D->hasUninstantiatedDefaultArg() &&
1566 !D->hasUnparsedDefaultArg())
1567 TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg()));
1569 if (D->hasDefaultArg() &&
1570 !D->hasUninstantiatedDefaultArg() &&
1571 !D->hasUnparsedDefaultArg())
1572 TRY_TO(TraverseStmt(D->getDefaultArg()));
1575 #undef DEF_TRAVERSE_DECL
1577 // ----------------- Stmt traversal -----------------
1579 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating
1580 // over the children defined in child_begin/child_end (every stmt
1581 // defines these, though sometimes the range is empty). Each
1582 // individual Traverse* method only needs to worry about children
1583 // other than those. To see what child_begin()/end() does for a given
1584 // class, see, e.g.,
1585 // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html
1587 // This macro makes available a variable S, the passed-in stmt.
1588 #define DEF_TRAVERSE_STMT(STMT, CODE) \
1589 template<typename Derived> \
1590 bool RecursiveASTVisitor<Derived>::Traverse##STMT (STMT *S) { \
1591 TRY_TO(WalkUpFrom##STMT(S)); \
1593 for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end(); \
1595 TRY_TO(TraverseStmt(*C)); \
1600 DEF_TRAVERSE_STMT(AsmStmt, {
1601 TRY_TO(TraverseStmt(S->getAsmString()));
1602 for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
1603 TRY_TO(TraverseStmt(S->getInputConstraintLiteral(I)));
1605 for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
1606 TRY_TO(TraverseStmt(S->getOutputConstraintLiteral(I)));
1608 for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
1609 TRY_TO(TraverseStmt(S->getClobber(I)));
1611 // child_begin()/end() iterates over inputExpr and outputExpr.
1614 DEF_TRAVERSE_STMT(CXXCatchStmt, {
1615 TRY_TO(TraverseDecl(S->getExceptionDecl()));
1616 // child_begin()/end() iterates over the handler block.
1619 DEF_TRAVERSE_STMT(DeclStmt, {
1620 for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end();
1622 TRY_TO(TraverseDecl(*I));
1624 // Suppress the default iteration over child_begin/end by
1625 // returning. Here's why: A DeclStmt looks like 'type var [=
1626 // initializer]'. The decls above already traverse over the
1627 // initializers, so we don't have to do it again (which
1628 // child_begin/end would do).
1633 // These non-expr stmts (most of them), do not need any action except
1634 // iterating over the children.
1635 DEF_TRAVERSE_STMT(BreakStmt, { })
1636 DEF_TRAVERSE_STMT(CXXTryStmt, { })
1637 DEF_TRAVERSE_STMT(CaseStmt, { })
1638 DEF_TRAVERSE_STMT(CompoundStmt, { })
1639 DEF_TRAVERSE_STMT(ContinueStmt, { })
1640 DEF_TRAVERSE_STMT(DefaultStmt, { })
1641 DEF_TRAVERSE_STMT(DoStmt, { })
1642 DEF_TRAVERSE_STMT(ForStmt, { })
1643 DEF_TRAVERSE_STMT(GotoStmt, { })
1644 DEF_TRAVERSE_STMT(IfStmt, { })
1645 DEF_TRAVERSE_STMT(IndirectGotoStmt, { })
1646 DEF_TRAVERSE_STMT(LabelStmt, { })
1647 DEF_TRAVERSE_STMT(NullStmt, { })
1648 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, { })
1649 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, { })
1650 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, { })
1651 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, { })
1652 DEF_TRAVERSE_STMT(ObjCAtTryStmt, { })
1653 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, { })
1654 DEF_TRAVERSE_STMT(ReturnStmt, { })
1655 DEF_TRAVERSE_STMT(SwitchCase, { })
1656 DEF_TRAVERSE_STMT(SwitchStmt, { })
1657 DEF_TRAVERSE_STMT(WhileStmt, { })
1660 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, {
1661 if (S->hasExplicitTemplateArgs()) {
1662 TRY_TO(TraverseTemplateArgumentLocsHelper(
1663 S->getTemplateArgs(), S->getNumTemplateArgs()));
1665 TRY_TO(TraverseNestedNameSpecifier(S->getQualifier()));
1668 DEF_TRAVERSE_STMT(DeclRefExpr, {
1669 TRY_TO(TraverseTemplateArgumentLocsHelper(
1670 S->getTemplateArgs(), S->getNumTemplateArgs()));
1671 // FIXME: Should we be recursing on the qualifier?
1672 TRY_TO(TraverseNestedNameSpecifier(S->getQualifier()));
1675 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, {
1676 // FIXME: Should we be recursing on these two things?
1677 if (S->hasExplicitTemplateArgs()) {
1678 TRY_TO(TraverseTemplateArgumentLocsHelper(
1679 S->getExplicitTemplateArgs().getTemplateArgs(),
1680 S->getNumTemplateArgs()));
1682 TRY_TO(TraverseNestedNameSpecifier(S->getQualifier()));
1685 DEF_TRAVERSE_STMT(MemberExpr, {
1686 TRY_TO(TraverseTemplateArgumentLocsHelper(
1687 S->getTemplateArgs(), S->getNumTemplateArgs()));
1688 // FIXME: Should we be recursing on the qualifier?
1689 TRY_TO(TraverseNestedNameSpecifier(S->getQualifier()));
1692 DEF_TRAVERSE_STMT(ImplicitCastExpr, {
1693 // We don't traverse the cast type, as it's not written in the
1697 DEF_TRAVERSE_STMT(CStyleCastExpr, {
1698 TRY_TO(TraverseType(S->getTypeAsWritten()));
1701 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, {
1702 TRY_TO(TraverseType(S->getTypeAsWritten()));
1705 DEF_TRAVERSE_STMT(CXXConstCastExpr, {
1706 TRY_TO(TraverseType(S->getTypeAsWritten()));
1709 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, {
1710 TRY_TO(TraverseType(S->getTypeAsWritten()));
1713 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, {
1714 TRY_TO(TraverseType(S->getTypeAsWritten()));
1717 DEF_TRAVERSE_STMT(CXXStaticCastExpr, {
1718 TRY_TO(TraverseType(S->getTypeAsWritten()));
1721 // InitListExpr is a tricky one, because we want to do all our work on
1722 // the syntactic form of the listexpr, but this method takes the
1723 // semantic form by default. We can't use the macro helper because it
1724 // calls WalkUp*() on the semantic form, before our code can convert
1725 // to the syntactic form.
1726 template<typename Derived>
1727 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) {
1728 if (InitListExpr *Syn = S->getSyntacticForm())
1730 TRY_TO(WalkUpFromInitListExpr(S));
1731 // All we need are the default actions. FIXME: use a helper function.
1732 for (Stmt::child_iterator C = S->child_begin(), CEnd = S->child_end();
1734 TRY_TO(TraverseStmt(*C));
1739 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
1740 // This is called for code like 'return T()' where T is a built-in
1741 // (i.e. non-class) type.
1742 if (!S->isImplicit())
1743 TRY_TO(TraverseType(S->getType()));
1746 DEF_TRAVERSE_STMT(CXXNewExpr, {
1747 TRY_TO(TraverseType(S->getAllocatedType()));
1750 DEF_TRAVERSE_STMT(OffsetOfExpr, {
1751 // The child-iterator will pick up the expression representing
1753 // FIMXE: for code like offsetof(Foo, a.b.c), should we get
1754 // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c?
1755 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc()));
1758 DEF_TRAVERSE_STMT(SizeOfAlignOfExpr, {
1759 // The child-iterator will pick up the arg if it's an expression,
1760 // but not if it's a type.
1761 if (S->isArgumentType())
1762 TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc()));
1765 DEF_TRAVERSE_STMT(CXXTypeidExpr, {
1766 // The child-iterator will pick up the arg if it's an expression,
1767 // but not if it's a type.
1768 if (S->isTypeOperand())
1769 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc()));
1772 DEF_TRAVERSE_STMT(TypesCompatibleExpr, {
1773 TRY_TO(TraverseTypeLoc(S->getArgTInfo1()->getTypeLoc()));
1774 TRY_TO(TraverseTypeLoc(S->getArgTInfo2()->getTypeLoc()));
1777 DEF_TRAVERSE_STMT(UnaryTypeTraitExpr, {
1778 TRY_TO(TraverseType(S->getQueriedType()));
1781 // These exprs (most of them), do not need any action except iterating
1782 // over the children.
1783 DEF_TRAVERSE_STMT(AddrLabelExpr, { })
1784 DEF_TRAVERSE_STMT(ArraySubscriptExpr, { })
1785 DEF_TRAVERSE_STMT(BlockDeclRefExpr, { })
1786 DEF_TRAVERSE_STMT(BlockExpr, { })
1787 DEF_TRAVERSE_STMT(ChooseExpr, { })
1788 DEF_TRAVERSE_STMT(CompoundLiteralExpr, { })
1789 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, { })
1790 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, { })
1791 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, { })
1792 DEF_TRAVERSE_STMT(CXXDeleteExpr, { })
1793 DEF_TRAVERSE_STMT(CXXExprWithTemporaries, { })
1794 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, { })
1795 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, { })
1796 DEF_TRAVERSE_STMT(CXXThisExpr, { })
1797 DEF_TRAVERSE_STMT(CXXThrowExpr, { })
1798 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, { })
1799 DEF_TRAVERSE_STMT(DesignatedInitExpr, { })
1800 DEF_TRAVERSE_STMT(ExtVectorElementExpr, { })
1801 DEF_TRAVERSE_STMT(GNUNullExpr, { })
1802 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, { })
1803 DEF_TRAVERSE_STMT(ObjCEncodeExpr, { })
1804 DEF_TRAVERSE_STMT(ObjCImplicitSetterGetterRefExpr, { })
1805 DEF_TRAVERSE_STMT(ObjCIsaExpr, { })
1806 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, { })
1807 DEF_TRAVERSE_STMT(ObjCMessageExpr, { })
1808 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, { })
1809 DEF_TRAVERSE_STMT(ObjCProtocolExpr, { })
1810 DEF_TRAVERSE_STMT(ObjCSelectorExpr, { })
1811 DEF_TRAVERSE_STMT(ObjCSuperExpr, { })
1812 DEF_TRAVERSE_STMT(ParenExpr, { })
1813 DEF_TRAVERSE_STMT(ParenListExpr, { })
1814 DEF_TRAVERSE_STMT(PredefinedExpr, { })
1815 DEF_TRAVERSE_STMT(ShuffleVectorExpr, { })
1816 DEF_TRAVERSE_STMT(StmtExpr, { })
1817 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, { })
1818 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, { })
1819 DEF_TRAVERSE_STMT(VAArgExpr, {
1820 // The child-iterator will pick up the expression argument.
1821 TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc()));
1823 DEF_TRAVERSE_STMT(CXXConstructExpr, { })
1825 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, {
1826 // This is called for code like 'return T()' where T is a class type.
1827 TRY_TO(TraverseType(S->getType()));
1830 DEF_TRAVERSE_STMT(CallExpr, { })
1831 DEF_TRAVERSE_STMT(CXXMemberCallExpr, { })
1832 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, { })
1834 // These operators (all of them) do not need any action except
1835 // iterating over the children.
1836 DEF_TRAVERSE_STMT(ConditionalOperator, { })
1837 DEF_TRAVERSE_STMT(UnaryOperator, { })
1838 DEF_TRAVERSE_STMT(BinaryOperator, { })
1839 DEF_TRAVERSE_STMT(CompoundAssignOperator, { })
1841 // These literals (all of them) do not need any action.
1842 DEF_TRAVERSE_STMT(IntegerLiteral, { })
1843 DEF_TRAVERSE_STMT(CharacterLiteral, { })
1844 DEF_TRAVERSE_STMT(FloatingLiteral, { })
1845 DEF_TRAVERSE_STMT(ImaginaryLiteral, { })
1846 DEF_TRAVERSE_STMT(StringLiteral, { })
1847 DEF_TRAVERSE_STMT(ObjCStringLiteral, { })
1849 // FIXME: look at the following tricky-seeming exprs to see if we
1850 // need to recurse on anything. These are ones that have methods
1851 // returning decls or qualtypes or nestednamespecifier -- though I'm
1852 // not sure if they own them -- or just seemed very complicated, or
1853 // had lots of sub-types to explore.
1855 // VisitOverloadExpr and its children: recurse on template args? etc?
1857 // FIXME: go through all the stmts and exprs again, and see which of them
1858 // create new types, and recurse on the types (TypeLocs?) of those.
1861 // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html
1862 // http://clang.llvm.org/doxygen/classclang_1_1SizeOfAlignOfExpr.html
1863 // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html
1864 // http://clang.llvm.org/doxygen/classclang_1_1CXXUnresolvedConstructExpr.html
1865 // Every class that has getQualifier.
1867 #undef DEF_TRAVERSE_STMT
1871 } // end namespace clang
1873 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H