clang API Documentation
00001 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the RecursiveASTVisitor interface, which recursively 00011 // traverses the entire AST. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H 00015 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H 00016 00017 #include "clang/AST/Decl.h" 00018 #include "clang/AST/DeclCXX.h" 00019 #include "clang/AST/DeclFriend.h" 00020 #include "clang/AST/DeclObjC.h" 00021 #include "clang/AST/DeclTemplate.h" 00022 #include "clang/AST/Expr.h" 00023 #include "clang/AST/ExprCXX.h" 00024 #include "clang/AST/ExprObjC.h" 00025 #include "clang/AST/NestedNameSpecifier.h" 00026 #include "clang/AST/Stmt.h" 00027 #include "clang/AST/StmtCXX.h" 00028 #include "clang/AST/StmtObjC.h" 00029 #include "clang/AST/TemplateBase.h" 00030 #include "clang/AST/TemplateName.h" 00031 #include "clang/AST/Type.h" 00032 #include "clang/AST/TypeLoc.h" 00033 00034 // The following three macros are used for meta programming. The code 00035 // using them is responsible for defining macro OPERATOR(). 00036 00037 // All unary operators. 00038 #define UNARYOP_LIST() \ 00039 OPERATOR(PostInc) OPERATOR(PostDec) \ 00040 OPERATOR(PreInc) OPERATOR(PreDec) \ 00041 OPERATOR(AddrOf) OPERATOR(Deref) \ 00042 OPERATOR(Plus) OPERATOR(Minus) \ 00043 OPERATOR(Not) OPERATOR(LNot) \ 00044 OPERATOR(Real) OPERATOR(Imag) \ 00045 OPERATOR(Extension) 00046 00047 // All binary operators (excluding compound assign operators). 00048 #define BINOP_LIST() \ 00049 OPERATOR(PtrMemD) OPERATOR(PtrMemI) \ 00050 OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) \ 00051 OPERATOR(Add) OPERATOR(Sub) OPERATOR(Shl) \ 00052 OPERATOR(Shr) \ 00053 \ 00054 OPERATOR(LT) OPERATOR(GT) OPERATOR(LE) \ 00055 OPERATOR(GE) OPERATOR(EQ) OPERATOR(NE) \ 00056 OPERATOR(And) OPERATOR(Xor) OPERATOR(Or) \ 00057 OPERATOR(LAnd) OPERATOR(LOr) \ 00058 \ 00059 OPERATOR(Assign) \ 00060 OPERATOR(Comma) 00061 00062 // All compound assign operators. 00063 #define CAO_LIST() \ 00064 OPERATOR(Mul) OPERATOR(Div) OPERATOR(Rem) OPERATOR(Add) OPERATOR(Sub) \ 00065 OPERATOR(Shl) OPERATOR(Shr) OPERATOR(And) OPERATOR(Or) OPERATOR(Xor) 00066 00067 namespace clang { 00068 00069 // A helper macro to implement short-circuiting when recursing. It 00070 // invokes CALL_EXPR, which must be a method call, on the derived 00071 // object (s.t. a user of RecursiveASTVisitor can override the method 00072 // in CALL_EXPR). 00073 #define TRY_TO(CALL_EXPR) \ 00074 do { if (!getDerived().CALL_EXPR) return false; } while (0) 00075 00076 /// \brief A class that does preorder depth-first traversal on the 00077 /// entire Clang AST and visits each node. 00078 /// 00079 /// This class performs three distinct tasks: 00080 /// 1. traverse the AST (i.e. go to each node); 00081 /// 2. at a given node, walk up the class hierarchy, starting from 00082 /// the node's dynamic type, until the top-most class (e.g. Stmt, 00083 /// Decl, or Type) is reached. 00084 /// 3. given a (node, class) combination, where 'class' is some base 00085 /// class of the dynamic type of 'node', call a user-overridable 00086 /// function to actually visit the node. 00087 /// 00088 /// These tasks are done by three groups of methods, respectively: 00089 /// 1. TraverseDecl(Decl *x) does task #1. It is the entry point 00090 /// for traversing an AST rooted at x. This method simply 00091 /// dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo 00092 /// is the dynamic type of *x, which calls WalkUpFromFoo(x) and 00093 /// then recursively visits the child nodes of x. 00094 /// TraverseStmt(Stmt *x) and TraverseType(QualType x) work 00095 /// similarly. 00096 /// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit 00097 /// any child node of x. Instead, it first calls WalkUpFromBar(x) 00098 /// where Bar is the direct parent class of Foo (unless Foo has 00099 /// no parent), and then calls VisitFoo(x) (see the next list item). 00100 /// 3. VisitFoo(Foo *x) does task #3. 00101 /// 00102 /// These three method groups are tiered (Traverse* > WalkUpFrom* > 00103 /// Visit*). A method (e.g. Traverse*) may call methods from the same 00104 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*). 00105 /// It may not call methods from a higher tier. 00106 /// 00107 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar 00108 /// is Foo's super class) before calling VisitFoo(), the result is 00109 /// that the Visit*() methods for a given node are called in the 00110 /// top-down order (e.g. for a node of type NamedDecl, the order will 00111 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()). 00112 /// 00113 /// This scheme guarantees that all Visit*() calls for the same AST 00114 /// node are grouped together. In other words, Visit*() methods for 00115 /// different nodes are never interleaved. 00116 /// 00117 /// Clients of this visitor should subclass the visitor (providing 00118 /// themselves as the template argument, using the curiously recurring 00119 /// template pattern) and override any of the Traverse*, WalkUpFrom*, 00120 /// and Visit* methods for declarations, types, statements, 00121 /// expressions, or other AST nodes where the visitor should customize 00122 /// behavior. Most users only need to override Visit*. Advanced 00123 /// users may override Traverse* and WalkUpFrom* to implement custom 00124 /// traversal strategies. Returning false from one of these overridden 00125 /// functions will abort the entire traversal. 00126 /// 00127 /// By default, this visitor tries to visit every part of the explicit 00128 /// source code exactly once. The default policy towards templates 00129 /// is to descend into the 'pattern' class or function body, not any 00130 /// explicit or implicit instantiations. Explicit specializations 00131 /// are still visited, and the patterns of partial specializations 00132 /// are visited separately. This behavior can be changed by 00133 /// overriding shouldVisitTemplateInstantiations() in the derived class 00134 /// to return true, in which case all known implicit and explicit 00135 /// instantiations will be visited at the same time as the pattern 00136 /// from which they were produced. 00137 template<typename Derived> 00138 class RecursiveASTVisitor { 00139 public: 00140 /// \brief Return a reference to the derived class. 00141 Derived &getDerived() { return *static_cast<Derived*>(this); } 00142 00143 /// \brief Return whether this visitor should recurse into 00144 /// template instantiations. 00145 bool shouldVisitTemplateInstantiations() const { return false; } 00146 00147 /// \brief Return whether this visitor should recurse into the types of 00148 /// TypeLocs. 00149 bool shouldWalkTypesOfTypeLocs() const { return true; } 00150 00151 /// \brief Return whether \param S should be traversed using data recursion 00152 /// to avoid a stack overflow with extreme cases. 00153 bool shouldUseDataRecursionFor(Stmt *S) const { 00154 return isa<BinaryOperator>(S) || isa<UnaryOperator>(S) || 00155 isa<CaseStmt>(S) || isa<CXXOperatorCallExpr>(S); 00156 } 00157 00158 /// \brief Recursively visit a statement or expression, by 00159 /// dispatching to Traverse*() based on the argument's dynamic type. 00160 /// 00161 /// \returns false if the visitation was terminated early, true 00162 /// otherwise (including when the argument is NULL). 00163 bool TraverseStmt(Stmt *S); 00164 00165 /// \brief Recursively visit a type, by dispatching to 00166 /// Traverse*Type() based on the argument's getTypeClass() property. 00167 /// 00168 /// \returns false if the visitation was terminated early, true 00169 /// otherwise (including when the argument is a Null type). 00170 bool TraverseType(QualType T); 00171 00172 /// \brief Recursively visit a type with location, by dispatching to 00173 /// Traverse*TypeLoc() based on the argument type's getTypeClass() property. 00174 /// 00175 /// \returns false if the visitation was terminated early, true 00176 /// otherwise (including when the argument is a Null type location). 00177 bool TraverseTypeLoc(TypeLoc TL); 00178 00179 /// \brief Recursively visit a declaration, by dispatching to 00180 /// Traverse*Decl() based on the argument's dynamic type. 00181 /// 00182 /// \returns false if the visitation was terminated early, true 00183 /// otherwise (including when the argument is NULL). 00184 bool TraverseDecl(Decl *D); 00185 00186 /// \brief Recursively visit a C++ nested-name-specifier. 00187 /// 00188 /// \returns false if the visitation was terminated early, true otherwise. 00189 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS); 00190 00191 /// \brief Recursively visit a C++ nested-name-specifier with location 00192 /// information. 00193 /// 00194 /// \returns false if the visitation was terminated early, true otherwise. 00195 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS); 00196 00197 /// \brief Recursively visit a name with its location information. 00198 /// 00199 /// \returns false if the visitation was terminated early, true otherwise. 00200 bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo); 00201 00202 /// \brief Recursively visit a template name and dispatch to the 00203 /// appropriate method. 00204 /// 00205 /// \returns false if the visitation was terminated early, true otherwise. 00206 bool TraverseTemplateName(TemplateName Template); 00207 00208 /// \brief Recursively visit a template argument and dispatch to the 00209 /// appropriate method for the argument type. 00210 /// 00211 /// \returns false if the visitation was terminated early, true otherwise. 00212 // FIXME: migrate callers to TemplateArgumentLoc instead. 00213 bool TraverseTemplateArgument(const TemplateArgument &Arg); 00214 00215 /// \brief Recursively visit a template argument location and dispatch to the 00216 /// appropriate method for the argument type. 00217 /// 00218 /// \returns false if the visitation was terminated early, true otherwise. 00219 bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc); 00220 00221 /// \brief Recursively visit a set of template arguments. 00222 /// This can be overridden by a subclass, but it's not expected that 00223 /// will be needed -- this visitor always dispatches to another. 00224 /// 00225 /// \returns false if the visitation was terminated early, true otherwise. 00226 // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead. 00227 bool TraverseTemplateArguments(const TemplateArgument *Args, 00228 unsigned NumArgs); 00229 00230 /// \brief Recursively visit a constructor initializer. This 00231 /// automatically dispatches to another visitor for the initializer 00232 /// expression, but not for the name of the initializer, so may 00233 /// be overridden for clients that need access to the name. 00234 /// 00235 /// \returns false if the visitation was terminated early, true otherwise. 00236 bool TraverseConstructorInitializer(CXXCtorInitializer *Init); 00237 00238 /// \brief Recursively visit a lambda capture. 00239 /// 00240 /// \returns false if the visitation was terminated early, true otherwise. 00241 bool TraverseLambdaCapture(LambdaExpr::Capture C); 00242 00243 // ---- Methods on Stmts ---- 00244 00245 // Declare Traverse*() for all concrete Stmt classes. 00246 #define ABSTRACT_STMT(STMT) 00247 #define STMT(CLASS, PARENT) \ 00248 bool Traverse##CLASS(CLASS *S); 00249 #include "clang/AST/StmtNodes.inc" 00250 // The above header #undefs ABSTRACT_STMT and STMT upon exit. 00251 00252 // Define WalkUpFrom*() and empty Visit*() for all Stmt classes. 00253 bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); } 00254 bool VisitStmt(Stmt *S) { return true; } 00255 #define STMT(CLASS, PARENT) \ 00256 bool WalkUpFrom##CLASS(CLASS *S) { \ 00257 TRY_TO(WalkUpFrom##PARENT(S)); \ 00258 TRY_TO(Visit##CLASS(S)); \ 00259 return true; \ 00260 } \ 00261 bool Visit##CLASS(CLASS *S) { return true; } 00262 #include "clang/AST/StmtNodes.inc" 00263 00264 // Define Traverse*(), WalkUpFrom*(), and Visit*() for unary 00265 // operator methods. Unary operators are not classes in themselves 00266 // (they're all opcodes in UnaryOperator) but do have visitors. 00267 #define OPERATOR(NAME) \ 00268 bool TraverseUnary##NAME(UnaryOperator *S) { \ 00269 TRY_TO(WalkUpFromUnary##NAME(S)); \ 00270 TRY_TO(TraverseStmt(S->getSubExpr())); \ 00271 return true; \ 00272 } \ 00273 bool WalkUpFromUnary##NAME(UnaryOperator *S) { \ 00274 TRY_TO(WalkUpFromUnaryOperator(S)); \ 00275 TRY_TO(VisitUnary##NAME(S)); \ 00276 return true; \ 00277 } \ 00278 bool VisitUnary##NAME(UnaryOperator *S) { return true; } 00279 00280 UNARYOP_LIST() 00281 #undef OPERATOR 00282 00283 // Define Traverse*(), WalkUpFrom*(), and Visit*() for binary 00284 // operator methods. Binary operators are not classes in themselves 00285 // (they're all opcodes in BinaryOperator) but do have visitors. 00286 #define GENERAL_BINOP_FALLBACK(NAME, BINOP_TYPE) \ 00287 bool TraverseBin##NAME(BINOP_TYPE *S) { \ 00288 TRY_TO(WalkUpFromBin##NAME(S)); \ 00289 TRY_TO(TraverseStmt(S->getLHS())); \ 00290 TRY_TO(TraverseStmt(S->getRHS())); \ 00291 return true; \ 00292 } \ 00293 bool WalkUpFromBin##NAME(BINOP_TYPE *S) { \ 00294 TRY_TO(WalkUpFrom##BINOP_TYPE(S)); \ 00295 TRY_TO(VisitBin##NAME(S)); \ 00296 return true; \ 00297 } \ 00298 bool VisitBin##NAME(BINOP_TYPE *S) { return true; } 00299 00300 #define OPERATOR(NAME) GENERAL_BINOP_FALLBACK(NAME, BinaryOperator) 00301 BINOP_LIST() 00302 #undef OPERATOR 00303 00304 // Define Traverse*(), WalkUpFrom*(), and Visit*() for compound 00305 // assignment methods. Compound assignment operators are not 00306 // classes in themselves (they're all opcodes in 00307 // CompoundAssignOperator) but do have visitors. 00308 #define OPERATOR(NAME) \ 00309 GENERAL_BINOP_FALLBACK(NAME##Assign, CompoundAssignOperator) 00310 00311 CAO_LIST() 00312 #undef OPERATOR 00313 #undef GENERAL_BINOP_FALLBACK 00314 00315 // ---- Methods on Types ---- 00316 // FIXME: revamp to take TypeLoc's rather than Types. 00317 00318 // Declare Traverse*() for all concrete Type classes. 00319 #define ABSTRACT_TYPE(CLASS, BASE) 00320 #define TYPE(CLASS, BASE) \ 00321 bool Traverse##CLASS##Type(CLASS##Type *T); 00322 #include "clang/AST/TypeNodes.def" 00323 // The above header #undefs ABSTRACT_TYPE and TYPE upon exit. 00324 00325 // Define WalkUpFrom*() and empty Visit*() for all Type classes. 00326 bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); } 00327 bool VisitType(Type *T) { return true; } 00328 #define TYPE(CLASS, BASE) \ 00329 bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \ 00330 TRY_TO(WalkUpFrom##BASE(T)); \ 00331 TRY_TO(Visit##CLASS##Type(T)); \ 00332 return true; \ 00333 } \ 00334 bool Visit##CLASS##Type(CLASS##Type *T) { return true; } 00335 #include "clang/AST/TypeNodes.def" 00336 00337 // ---- Methods on TypeLocs ---- 00338 // FIXME: this currently just calls the matching Type methods 00339 00340 // Declare Traverse*() for all concrete Type classes. 00341 #define ABSTRACT_TYPELOC(CLASS, BASE) 00342 #define TYPELOC(CLASS, BASE) \ 00343 bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL); 00344 #include "clang/AST/TypeLocNodes.def" 00345 // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit. 00346 00347 // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes. 00348 bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); } 00349 bool VisitTypeLoc(TypeLoc TL) { return true; } 00350 00351 // QualifiedTypeLoc and UnqualTypeLoc are not declared in 00352 // TypeNodes.def and thus need to be handled specially. 00353 bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) { 00354 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc()); 00355 } 00356 bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; } 00357 bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) { 00358 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc()); 00359 } 00360 bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; } 00361 00362 // Note that BASE includes trailing 'Type' which CLASS doesn't. 00363 #define TYPE(CLASS, BASE) \ 00364 bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ 00365 TRY_TO(WalkUpFrom##BASE##Loc(TL)); \ 00366 TRY_TO(Visit##CLASS##TypeLoc(TL)); \ 00367 return true; \ 00368 } \ 00369 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; } 00370 #include "clang/AST/TypeNodes.def" 00371 00372 // ---- Methods on Decls ---- 00373 00374 // Declare Traverse*() for all concrete Decl classes. 00375 #define ABSTRACT_DECL(DECL) 00376 #define DECL(CLASS, BASE) \ 00377 bool Traverse##CLASS##Decl(CLASS##Decl *D); 00378 #include "clang/AST/DeclNodes.inc" 00379 // The above header #undefs ABSTRACT_DECL and DECL upon exit. 00380 00381 // Define WalkUpFrom*() and empty Visit*() for all Decl classes. 00382 bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); } 00383 bool VisitDecl(Decl *D) { return true; } 00384 #define DECL(CLASS, BASE) \ 00385 bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \ 00386 TRY_TO(WalkUpFrom##BASE(D)); \ 00387 TRY_TO(Visit##CLASS##Decl(D)); \ 00388 return true; \ 00389 } \ 00390 bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; } 00391 #include "clang/AST/DeclNodes.inc" 00392 00393 private: 00394 // These are helper methods used by more than one Traverse* method. 00395 bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL); 00396 bool TraverseClassInstantiations(ClassTemplateDecl *D); 00397 bool TraverseFunctionInstantiations(FunctionTemplateDecl *D) ; 00398 bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL, 00399 unsigned Count); 00400 bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL); 00401 bool TraverseRecordHelper(RecordDecl *D); 00402 bool TraverseCXXRecordHelper(CXXRecordDecl *D); 00403 bool TraverseDeclaratorHelper(DeclaratorDecl *D); 00404 bool TraverseDeclContextHelper(DeclContext *DC); 00405 bool TraverseFunctionHelper(FunctionDecl *D); 00406 bool TraverseVarHelper(VarDecl *D); 00407 00408 struct EnqueueJob { 00409 Stmt *S; 00410 Stmt::child_iterator StmtIt; 00411 00412 EnqueueJob(Stmt *S) : S(S), StmtIt() {} 00413 }; 00414 bool dataTraverse(Stmt *S); 00415 bool dataTraverseNode(Stmt *S, bool &EnqueueChildren); 00416 }; 00417 00418 template<typename Derived> 00419 bool RecursiveASTVisitor<Derived>::dataTraverse(Stmt *S) { 00420 00421 SmallVector<EnqueueJob, 16> Queue; 00422 Queue.push_back(S); 00423 00424 while (!Queue.empty()) { 00425 EnqueueJob &job = Queue.back(); 00426 Stmt *CurrS = job.S; 00427 if (!CurrS) { 00428 Queue.pop_back(); 00429 continue; 00430 } 00431 00432 if (getDerived().shouldUseDataRecursionFor(CurrS)) { 00433 if (job.StmtIt == Stmt::child_iterator()) { 00434 bool EnqueueChildren = true; 00435 if (!dataTraverseNode(CurrS, EnqueueChildren)) return false; 00436 if (!EnqueueChildren) { 00437 Queue.pop_back(); 00438 continue; 00439 } 00440 job.StmtIt = CurrS->child_begin(); 00441 } else { 00442 ++job.StmtIt; 00443 } 00444 00445 if (job.StmtIt != CurrS->child_end()) 00446 Queue.push_back(*job.StmtIt); 00447 else 00448 Queue.pop_back(); 00449 continue; 00450 } 00451 00452 Queue.pop_back(); 00453 TRY_TO(TraverseStmt(CurrS)); 00454 } 00455 00456 return true; 00457 } 00458 00459 template<typename Derived> 00460 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S, 00461 bool &EnqueueChildren) { 00462 00463 // Dispatch to the corresponding WalkUpFrom* function only if the derived 00464 // class didn't override Traverse* (and thus the traversal is trivial). 00465 // The cast here is necessary to work around a bug in old versions of g++. 00466 #define DISPATCH_WALK(NAME, CLASS, VAR) \ 00467 if (&RecursiveASTVisitor::Traverse##NAME == \ 00468 (bool (RecursiveASTVisitor::*)(CLASS*))&Derived::Traverse##NAME) \ 00469 return getDerived().WalkUpFrom##NAME(static_cast<CLASS*>(VAR)); \ 00470 EnqueueChildren = false; \ 00471 return getDerived().Traverse##NAME(static_cast<CLASS*>(VAR)); 00472 00473 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) { 00474 switch (BinOp->getOpcode()) { 00475 #define OPERATOR(NAME) \ 00476 case BO_##NAME: DISPATCH_WALK(Bin##NAME, BinaryOperator, S); 00477 00478 BINOP_LIST() 00479 #undef OPERATOR 00480 00481 #define OPERATOR(NAME) \ 00482 case BO_##NAME##Assign: \ 00483 DISPATCH_WALK(Bin##NAME##Assign, CompoundAssignOperator, S); 00484 00485 CAO_LIST() 00486 #undef OPERATOR 00487 } 00488 } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) { 00489 switch (UnOp->getOpcode()) { 00490 #define OPERATOR(NAME) \ 00491 case UO_##NAME: DISPATCH_WALK(Unary##NAME, UnaryOperator, S); 00492 00493 UNARYOP_LIST() 00494 #undef OPERATOR 00495 } 00496 } 00497 00498 // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt. 00499 switch (S->getStmtClass()) { 00500 case Stmt::NoStmtClass: break; 00501 #define ABSTRACT_STMT(STMT) 00502 #define STMT(CLASS, PARENT) \ 00503 case Stmt::CLASS##Class: DISPATCH_WALK(CLASS, CLASS, S); 00504 #include "clang/AST/StmtNodes.inc" 00505 } 00506 00507 #undef DISPATCH_WALK 00508 00509 return true; 00510 } 00511 00512 #define DISPATCH(NAME, CLASS, VAR) \ 00513 return getDerived().Traverse##NAME(static_cast<CLASS*>(VAR)) 00514 00515 template<typename Derived> 00516 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S) { 00517 if (!S) 00518 return true; 00519 00520 if (getDerived().shouldUseDataRecursionFor(S)) 00521 return dataTraverse(S); 00522 00523 // If we have a binary expr, dispatch to the subcode of the binop. A smart 00524 // optimizer (e.g. LLVM) will fold this comparison into the switch stmt 00525 // below. 00526 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) { 00527 switch (BinOp->getOpcode()) { 00528 #define OPERATOR(NAME) \ 00529 case BO_##NAME: DISPATCH(Bin##NAME, BinaryOperator, S); 00530 00531 BINOP_LIST() 00532 #undef OPERATOR 00533 #undef BINOP_LIST 00534 00535 #define OPERATOR(NAME) \ 00536 case BO_##NAME##Assign: \ 00537 DISPATCH(Bin##NAME##Assign, CompoundAssignOperator, S); 00538 00539 CAO_LIST() 00540 #undef OPERATOR 00541 #undef CAO_LIST 00542 } 00543 } else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(S)) { 00544 switch (UnOp->getOpcode()) { 00545 #define OPERATOR(NAME) \ 00546 case UO_##NAME: DISPATCH(Unary##NAME, UnaryOperator, S); 00547 00548 UNARYOP_LIST() 00549 #undef OPERATOR 00550 #undef UNARYOP_LIST 00551 } 00552 } 00553 00554 // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt. 00555 switch (S->getStmtClass()) { 00556 case Stmt::NoStmtClass: break; 00557 #define ABSTRACT_STMT(STMT) 00558 #define STMT(CLASS, PARENT) \ 00559 case Stmt::CLASS##Class: DISPATCH(CLASS, CLASS, S); 00560 #include "clang/AST/StmtNodes.inc" 00561 } 00562 00563 return true; 00564 } 00565 00566 template<typename Derived> 00567 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) { 00568 if (T.isNull()) 00569 return true; 00570 00571 switch (T->getTypeClass()) { 00572 #define ABSTRACT_TYPE(CLASS, BASE) 00573 #define TYPE(CLASS, BASE) \ 00574 case Type::CLASS: DISPATCH(CLASS##Type, CLASS##Type, \ 00575 const_cast<Type*>(T.getTypePtr())); 00576 #include "clang/AST/TypeNodes.def" 00577 } 00578 00579 return true; 00580 } 00581 00582 template<typename Derived> 00583 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) { 00584 if (TL.isNull()) 00585 return true; 00586 00587 switch (TL.getTypeLocClass()) { 00588 #define ABSTRACT_TYPELOC(CLASS, BASE) 00589 #define TYPELOC(CLASS, BASE) \ 00590 case TypeLoc::CLASS: \ 00591 return getDerived().Traverse##CLASS##TypeLoc(*cast<CLASS##TypeLoc>(&TL)); 00592 #include "clang/AST/TypeLocNodes.def" 00593 } 00594 00595 return true; 00596 } 00597 00598 00599 template<typename Derived> 00600 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) { 00601 if (!D) 00602 return true; 00603 00604 // As a syntax visitor, we want to ignore declarations for 00605 // implicitly-defined declarations (ones not typed explicitly by the 00606 // user). 00607 if (D->isImplicit()) 00608 return true; 00609 00610 switch (D->getKind()) { 00611 #define ABSTRACT_DECL(DECL) 00612 #define DECL(CLASS, BASE) \ 00613 case Decl::CLASS: DISPATCH(CLASS##Decl, CLASS##Decl, D); 00614 #include "clang/AST/DeclNodes.inc" 00615 } 00616 00617 return true; 00618 } 00619 00620 #undef DISPATCH 00621 00622 template<typename Derived> 00623 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier( 00624 NestedNameSpecifier *NNS) { 00625 if (!NNS) 00626 return true; 00627 00628 if (NNS->getPrefix()) 00629 TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix())); 00630 00631 switch (NNS->getKind()) { 00632 case NestedNameSpecifier::Identifier: 00633 case NestedNameSpecifier::Namespace: 00634 case NestedNameSpecifier::NamespaceAlias: 00635 case NestedNameSpecifier::Global: 00636 return true; 00637 00638 case NestedNameSpecifier::TypeSpec: 00639 case NestedNameSpecifier::TypeSpecWithTemplate: 00640 TRY_TO(TraverseType(QualType(NNS->getAsType(), 0))); 00641 } 00642 00643 return true; 00644 } 00645 00646 template<typename Derived> 00647 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc( 00648 NestedNameSpecifierLoc NNS) { 00649 if (!NNS) 00650 return true; 00651 00652 if (NestedNameSpecifierLoc Prefix = NNS.getPrefix()) 00653 TRY_TO(TraverseNestedNameSpecifierLoc(Prefix)); 00654 00655 switch (NNS.getNestedNameSpecifier()->getKind()) { 00656 case NestedNameSpecifier::Identifier: 00657 case NestedNameSpecifier::Namespace: 00658 case NestedNameSpecifier::NamespaceAlias: 00659 case NestedNameSpecifier::Global: 00660 return true; 00661 00662 case NestedNameSpecifier::TypeSpec: 00663 case NestedNameSpecifier::TypeSpecWithTemplate: 00664 TRY_TO(TraverseTypeLoc(NNS.getTypeLoc())); 00665 break; 00666 } 00667 00668 return true; 00669 } 00670 00671 template<typename Derived> 00672 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo( 00673 DeclarationNameInfo NameInfo) { 00674 switch (NameInfo.getName().getNameKind()) { 00675 case DeclarationName::CXXConstructorName: 00676 case DeclarationName::CXXDestructorName: 00677 case DeclarationName::CXXConversionFunctionName: 00678 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo()) 00679 TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc())); 00680 00681 break; 00682 00683 case DeclarationName::Identifier: 00684 case DeclarationName::ObjCZeroArgSelector: 00685 case DeclarationName::ObjCOneArgSelector: 00686 case DeclarationName::ObjCMultiArgSelector: 00687 case DeclarationName::CXXOperatorName: 00688 case DeclarationName::CXXLiteralOperatorName: 00689 case DeclarationName::CXXUsingDirective: 00690 break; 00691 } 00692 00693 return true; 00694 } 00695 00696 template<typename Derived> 00697 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) { 00698 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) 00699 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier())); 00700 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 00701 TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier())); 00702 00703 return true; 00704 } 00705 00706 template<typename Derived> 00707 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument( 00708 const TemplateArgument &Arg) { 00709 switch (Arg.getKind()) { 00710 case TemplateArgument::Null: 00711 case TemplateArgument::Declaration: 00712 case TemplateArgument::Integral: 00713 return true; 00714 00715 case TemplateArgument::Type: 00716 return getDerived().TraverseType(Arg.getAsType()); 00717 00718 case TemplateArgument::Template: 00719 case TemplateArgument::TemplateExpansion: 00720 return getDerived().TraverseTemplateName( 00721 Arg.getAsTemplateOrTemplatePattern()); 00722 00723 case TemplateArgument::Expression: 00724 return getDerived().TraverseStmt(Arg.getAsExpr()); 00725 00726 case TemplateArgument::Pack: 00727 return getDerived().TraverseTemplateArguments(Arg.pack_begin(), 00728 Arg.pack_size()); 00729 } 00730 00731 return true; 00732 } 00733 00734 // FIXME: no template name location? 00735 // FIXME: no source locations for a template argument pack? 00736 template<typename Derived> 00737 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc( 00738 const TemplateArgumentLoc &ArgLoc) { 00739 const TemplateArgument &Arg = ArgLoc.getArgument(); 00740 00741 switch (Arg.getKind()) { 00742 case TemplateArgument::Null: 00743 case TemplateArgument::Declaration: 00744 case TemplateArgument::Integral: 00745 return true; 00746 00747 case TemplateArgument::Type: { 00748 // FIXME: how can TSI ever be NULL? 00749 if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo()) 00750 return getDerived().TraverseTypeLoc(TSI->getTypeLoc()); 00751 else 00752 return getDerived().TraverseType(Arg.getAsType()); 00753 } 00754 00755 case TemplateArgument::Template: 00756 case TemplateArgument::TemplateExpansion: 00757 if (ArgLoc.getTemplateQualifierLoc()) 00758 TRY_TO(getDerived().TraverseNestedNameSpecifierLoc( 00759 ArgLoc.getTemplateQualifierLoc())); 00760 return getDerived().TraverseTemplateName( 00761 Arg.getAsTemplateOrTemplatePattern()); 00762 00763 case TemplateArgument::Expression: 00764 return getDerived().TraverseStmt(ArgLoc.getSourceExpression()); 00765 00766 case TemplateArgument::Pack: 00767 return getDerived().TraverseTemplateArguments(Arg.pack_begin(), 00768 Arg.pack_size()); 00769 } 00770 00771 return true; 00772 } 00773 00774 template<typename Derived> 00775 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments( 00776 const TemplateArgument *Args, 00777 unsigned NumArgs) { 00778 for (unsigned I = 0; I != NumArgs; ++I) { 00779 TRY_TO(TraverseTemplateArgument(Args[I])); 00780 } 00781 00782 return true; 00783 } 00784 00785 template<typename Derived> 00786 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer( 00787 CXXCtorInitializer *Init) { 00788 if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo()) 00789 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); 00790 00791 if (Init->isWritten()) 00792 TRY_TO(TraverseStmt(Init->getInit())); 00793 return true; 00794 } 00795 00796 template<typename Derived> 00797 bool RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr::Capture C){ 00798 return true; 00799 } 00800 00801 // ----------------- Type traversal ----------------- 00802 00803 // This macro makes available a variable T, the passed-in type. 00804 #define DEF_TRAVERSE_TYPE(TYPE, CODE) \ 00805 template<typename Derived> \ 00806 bool RecursiveASTVisitor<Derived>::Traverse##TYPE (TYPE *T) { \ 00807 TRY_TO(WalkUpFrom##TYPE (T)); \ 00808 { CODE; } \ 00809 return true; \ 00810 } 00811 00812 DEF_TRAVERSE_TYPE(BuiltinType, { }) 00813 00814 DEF_TRAVERSE_TYPE(ComplexType, { 00815 TRY_TO(TraverseType(T->getElementType())); 00816 }) 00817 00818 DEF_TRAVERSE_TYPE(PointerType, { 00819 TRY_TO(TraverseType(T->getPointeeType())); 00820 }) 00821 00822 DEF_TRAVERSE_TYPE(BlockPointerType, { 00823 TRY_TO(TraverseType(T->getPointeeType())); 00824 }) 00825 00826 DEF_TRAVERSE_TYPE(LValueReferenceType, { 00827 TRY_TO(TraverseType(T->getPointeeType())); 00828 }) 00829 00830 DEF_TRAVERSE_TYPE(RValueReferenceType, { 00831 TRY_TO(TraverseType(T->getPointeeType())); 00832 }) 00833 00834 DEF_TRAVERSE_TYPE(MemberPointerType, { 00835 TRY_TO(TraverseType(QualType(T->getClass(), 0))); 00836 TRY_TO(TraverseType(T->getPointeeType())); 00837 }) 00838 00839 DEF_TRAVERSE_TYPE(ConstantArrayType, { 00840 TRY_TO(TraverseType(T->getElementType())); 00841 }) 00842 00843 DEF_TRAVERSE_TYPE(IncompleteArrayType, { 00844 TRY_TO(TraverseType(T->getElementType())); 00845 }) 00846 00847 DEF_TRAVERSE_TYPE(VariableArrayType, { 00848 TRY_TO(TraverseType(T->getElementType())); 00849 TRY_TO(TraverseStmt(T->getSizeExpr())); 00850 }) 00851 00852 DEF_TRAVERSE_TYPE(DependentSizedArrayType, { 00853 TRY_TO(TraverseType(T->getElementType())); 00854 if (T->getSizeExpr()) 00855 TRY_TO(TraverseStmt(T->getSizeExpr())); 00856 }) 00857 00858 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, { 00859 if (T->getSizeExpr()) 00860 TRY_TO(TraverseStmt(T->getSizeExpr())); 00861 TRY_TO(TraverseType(T->getElementType())); 00862 }) 00863 00864 DEF_TRAVERSE_TYPE(VectorType, { 00865 TRY_TO(TraverseType(T->getElementType())); 00866 }) 00867 00868 DEF_TRAVERSE_TYPE(ExtVectorType, { 00869 TRY_TO(TraverseType(T->getElementType())); 00870 }) 00871 00872 DEF_TRAVERSE_TYPE(FunctionNoProtoType, { 00873 TRY_TO(TraverseType(T->getResultType())); 00874 }) 00875 00876 DEF_TRAVERSE_TYPE(FunctionProtoType, { 00877 TRY_TO(TraverseType(T->getResultType())); 00878 00879 for (FunctionProtoType::arg_type_iterator A = T->arg_type_begin(), 00880 AEnd = T->arg_type_end(); 00881 A != AEnd; ++A) { 00882 TRY_TO(TraverseType(*A)); 00883 } 00884 00885 for (FunctionProtoType::exception_iterator E = T->exception_begin(), 00886 EEnd = T->exception_end(); 00887 E != EEnd; ++E) { 00888 TRY_TO(TraverseType(*E)); 00889 } 00890 }) 00891 00892 DEF_TRAVERSE_TYPE(UnresolvedUsingType, { }) 00893 DEF_TRAVERSE_TYPE(TypedefType, { }) 00894 00895 DEF_TRAVERSE_TYPE(TypeOfExprType, { 00896 TRY_TO(TraverseStmt(T->getUnderlyingExpr())); 00897 }) 00898 00899 DEF_TRAVERSE_TYPE(TypeOfType, { 00900 TRY_TO(TraverseType(T->getUnderlyingType())); 00901 }) 00902 00903 DEF_TRAVERSE_TYPE(DecltypeType, { 00904 TRY_TO(TraverseStmt(T->getUnderlyingExpr())); 00905 }) 00906 00907 DEF_TRAVERSE_TYPE(UnaryTransformType, { 00908 TRY_TO(TraverseType(T->getBaseType())); 00909 TRY_TO(TraverseType(T->getUnderlyingType())); 00910 }) 00911 00912 DEF_TRAVERSE_TYPE(AutoType, { 00913 TRY_TO(TraverseType(T->getDeducedType())); 00914 }) 00915 00916 DEF_TRAVERSE_TYPE(RecordType, { }) 00917 DEF_TRAVERSE_TYPE(EnumType, { }) 00918 DEF_TRAVERSE_TYPE(TemplateTypeParmType, { }) 00919 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, { }) 00920 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, { }) 00921 00922 DEF_TRAVERSE_TYPE(TemplateSpecializationType, { 00923 TRY_TO(TraverseTemplateName(T->getTemplateName())); 00924 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs())); 00925 }) 00926 00927 DEF_TRAVERSE_TYPE(InjectedClassNameType, { }) 00928 00929 DEF_TRAVERSE_TYPE(AttributedType, { 00930 TRY_TO(TraverseType(T->getModifiedType())); 00931 }) 00932 00933 DEF_TRAVERSE_TYPE(ParenType, { 00934 TRY_TO(TraverseType(T->getInnerType())); 00935 }) 00936 00937 DEF_TRAVERSE_TYPE(ElaboratedType, { 00938 if (T->getQualifier()) { 00939 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); 00940 } 00941 TRY_TO(TraverseType(T->getNamedType())); 00942 }) 00943 00944 DEF_TRAVERSE_TYPE(DependentNameType, { 00945 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); 00946 }) 00947 00948 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, { 00949 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); 00950 TRY_TO(TraverseTemplateArguments(T->getArgs(), T->getNumArgs())); 00951 }) 00952 00953 DEF_TRAVERSE_TYPE(PackExpansionType, { 00954 TRY_TO(TraverseType(T->getPattern())); 00955 }) 00956 00957 DEF_TRAVERSE_TYPE(ObjCInterfaceType, { }) 00958 00959 DEF_TRAVERSE_TYPE(ObjCObjectType, { 00960 // We have to watch out here because an ObjCInterfaceType's base 00961 // type is itself. 00962 if (T->getBaseType().getTypePtr() != T) 00963 TRY_TO(TraverseType(T->getBaseType())); 00964 }) 00965 00966 DEF_TRAVERSE_TYPE(ObjCObjectPointerType, { 00967 TRY_TO(TraverseType(T->getPointeeType())); 00968 }) 00969 00970 DEF_TRAVERSE_TYPE(AtomicType, { 00971 TRY_TO(TraverseType(T->getValueType())); 00972 }) 00973 00974 #undef DEF_TRAVERSE_TYPE 00975 00976 // ----------------- TypeLoc traversal ----------------- 00977 00978 // This macro makes available a variable TL, the passed-in TypeLoc. 00979 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc, 00980 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing 00981 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods 00982 // continue to work. 00983 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \ 00984 template<typename Derived> \ 00985 bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \ 00986 if (getDerived().shouldWalkTypesOfTypeLocs()) \ 00987 TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE*>(TL.getTypePtr()))); \ 00988 TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \ 00989 { CODE; } \ 00990 return true; \ 00991 } 00992 00993 template<typename Derived> 00994 bool RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc( 00995 QualifiedTypeLoc TL) { 00996 // Move this over to the 'main' typeloc tree. Note that this is a 00997 // move -- we pretend that we were really looking at the unqualified 00998 // typeloc all along -- rather than a recursion, so we don't follow 00999 // the normal CRTP plan of going through 01000 // getDerived().TraverseTypeLoc. If we did, we'd be traversing 01001 // twice for the same type (once as a QualifiedTypeLoc version of 01002 // the type, once as an UnqualifiedTypeLoc version of the type), 01003 // which in effect means we'd call VisitTypeLoc twice with the 01004 // 'same' type. This solves that problem, at the cost of never 01005 // seeing the qualified version of the type (unless the client 01006 // subclasses TraverseQualifiedTypeLoc themselves). It's not a 01007 // perfect solution. A perfect solution probably requires making 01008 // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a 01009 // wrapper around Type* -- rather than being its own class in the 01010 // type hierarchy. 01011 return TraverseTypeLoc(TL.getUnqualifiedLoc()); 01012 } 01013 01014 DEF_TRAVERSE_TYPELOC(BuiltinType, { }) 01015 01016 // FIXME: ComplexTypeLoc is unfinished 01017 DEF_TRAVERSE_TYPELOC(ComplexType, { 01018 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 01019 }) 01020 01021 DEF_TRAVERSE_TYPELOC(PointerType, { 01022 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); 01023 }) 01024 01025 DEF_TRAVERSE_TYPELOC(BlockPointerType, { 01026 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); 01027 }) 01028 01029 DEF_TRAVERSE_TYPELOC(LValueReferenceType, { 01030 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); 01031 }) 01032 01033 DEF_TRAVERSE_TYPELOC(RValueReferenceType, { 01034 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); 01035 }) 01036 01037 // FIXME: location of base class? 01038 // We traverse this in the type case as well, but how is it not reached through 01039 // the pointee type? 01040 DEF_TRAVERSE_TYPELOC(MemberPointerType, { 01041 TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0))); 01042 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); 01043 }) 01044 01045 template<typename Derived> 01046 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) { 01047 // This isn't available for ArrayType, but is for the ArrayTypeLoc. 01048 TRY_TO(TraverseStmt(TL.getSizeExpr())); 01049 return true; 01050 } 01051 01052 DEF_TRAVERSE_TYPELOC(ConstantArrayType, { 01053 TRY_TO(TraverseTypeLoc(TL.getElementLoc())); 01054 return TraverseArrayTypeLocHelper(TL); 01055 }) 01056 01057 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, { 01058 TRY_TO(TraverseTypeLoc(TL.getElementLoc())); 01059 return TraverseArrayTypeLocHelper(TL); 01060 }) 01061 01062 DEF_TRAVERSE_TYPELOC(VariableArrayType, { 01063 TRY_TO(TraverseTypeLoc(TL.getElementLoc())); 01064 return TraverseArrayTypeLocHelper(TL); 01065 }) 01066 01067 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, { 01068 TRY_TO(TraverseTypeLoc(TL.getElementLoc())); 01069 return TraverseArrayTypeLocHelper(TL); 01070 }) 01071 01072 // FIXME: order? why not size expr first? 01073 // FIXME: base VectorTypeLoc is unfinished 01074 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, { 01075 if (TL.getTypePtr()->getSizeExpr()) 01076 TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr())); 01077 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 01078 }) 01079 01080 // FIXME: VectorTypeLoc is unfinished 01081 DEF_TRAVERSE_TYPELOC(VectorType, { 01082 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 01083 }) 01084 01085 // FIXME: size and attributes 01086 // FIXME: base VectorTypeLoc is unfinished 01087 DEF_TRAVERSE_TYPELOC(ExtVectorType, { 01088 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 01089 }) 01090 01091 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType, { 01092 TRY_TO(TraverseTypeLoc(TL.getResultLoc())); 01093 }) 01094 01095 // FIXME: location of exception specifications (attributes?) 01096 DEF_TRAVERSE_TYPELOC(FunctionProtoType, { 01097 TRY_TO(TraverseTypeLoc(TL.getResultLoc())); 01098 01099 const FunctionProtoType *T = TL.getTypePtr(); 01100 01101 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { 01102 if (TL.getArg(I)) { 01103 TRY_TO(TraverseDecl(TL.getArg(I))); 01104 } else if (I < T->getNumArgs()) { 01105 TRY_TO(TraverseType(T->getArgType(I))); 01106 } 01107 } 01108 01109 for (FunctionProtoType::exception_iterator E = T->exception_begin(), 01110 EEnd = T->exception_end(); 01111 E != EEnd; ++E) { 01112 TRY_TO(TraverseType(*E)); 01113 } 01114 }) 01115 01116 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, { }) 01117 DEF_TRAVERSE_TYPELOC(TypedefType, { }) 01118 01119 DEF_TRAVERSE_TYPELOC(TypeOfExprType, { 01120 TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); 01121 }) 01122 01123 DEF_TRAVERSE_TYPELOC(TypeOfType, { 01124 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc())); 01125 }) 01126 01127 // FIXME: location of underlying expr 01128 DEF_TRAVERSE_TYPELOC(DecltypeType, { 01129 TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr())); 01130 }) 01131 01132 DEF_TRAVERSE_TYPELOC(UnaryTransformType, { 01133 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc())); 01134 }) 01135 01136 DEF_TRAVERSE_TYPELOC(AutoType, { 01137 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType())); 01138 }) 01139 01140 DEF_TRAVERSE_TYPELOC(RecordType, { }) 01141 DEF_TRAVERSE_TYPELOC(EnumType, { }) 01142 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, { }) 01143 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, { }) 01144 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, { }) 01145 01146 // FIXME: use the loc for the template name? 01147 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, { 01148 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName())); 01149 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { 01150 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); 01151 } 01152 }) 01153 01154 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, { }) 01155 01156 DEF_TRAVERSE_TYPELOC(ParenType, { 01157 TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); 01158 }) 01159 01160 DEF_TRAVERSE_TYPELOC(AttributedType, { 01161 TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); 01162 }) 01163 01164 DEF_TRAVERSE_TYPELOC(ElaboratedType, { 01165 if (TL.getQualifierLoc()) { 01166 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); 01167 } 01168 TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc())); 01169 }) 01170 01171 DEF_TRAVERSE_TYPELOC(DependentNameType, { 01172 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); 01173 }) 01174 01175 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, { 01176 if (TL.getQualifierLoc()) { 01177 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); 01178 } 01179 01180 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { 01181 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); 01182 } 01183 }) 01184 01185 DEF_TRAVERSE_TYPELOC(PackExpansionType, { 01186 TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); 01187 }) 01188 01189 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, { }) 01190 01191 DEF_TRAVERSE_TYPELOC(ObjCObjectType, { 01192 // We have to watch out here because an ObjCInterfaceType's base 01193 // type is itself. 01194 if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr()) 01195 TRY_TO(TraverseTypeLoc(TL.getBaseLoc())); 01196 }) 01197 01198 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType, { 01199 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); 01200 }) 01201 01202 DEF_TRAVERSE_TYPELOC(AtomicType, { 01203 TRY_TO(TraverseTypeLoc(TL.getValueLoc())); 01204 }) 01205 01206 #undef DEF_TRAVERSE_TYPELOC 01207 01208 // ----------------- Decl traversal ----------------- 01209 // 01210 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing 01211 // the children that come from the DeclContext associated with it. 01212 // Therefore each Traverse* only needs to worry about children other 01213 // than those. 01214 01215 template<typename Derived> 01216 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) { 01217 if (!DC) 01218 return true; 01219 01220 for (DeclContext::decl_iterator Child = DC->decls_begin(), 01221 ChildEnd = DC->decls_end(); 01222 Child != ChildEnd; ++Child) { 01223 // BlockDecls are traversed through BlockExprs. 01224 if (!isa<BlockDecl>(*Child)) 01225 TRY_TO(TraverseDecl(*Child)); 01226 } 01227 01228 return true; 01229 } 01230 01231 // This macro makes available a variable D, the passed-in decl. 01232 #define DEF_TRAVERSE_DECL(DECL, CODE) \ 01233 template<typename Derived> \ 01234 bool RecursiveASTVisitor<Derived>::Traverse##DECL (DECL *D) { \ 01235 TRY_TO(WalkUpFrom##DECL (D)); \ 01236 { CODE; } \ 01237 TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \ 01238 return true; \ 01239 } 01240 01241 DEF_TRAVERSE_DECL(AccessSpecDecl, { }) 01242 01243 DEF_TRAVERSE_DECL(BlockDecl, { 01244 if (TypeSourceInfo *TInfo = D->getSignatureAsWritten()) 01245 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); 01246 TRY_TO(TraverseStmt(D->getBody())); 01247 // This return statement makes sure the traversal of nodes in 01248 // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) 01249 // is skipped - don't remove it. 01250 return true; 01251 }) 01252 01253 DEF_TRAVERSE_DECL(FileScopeAsmDecl, { 01254 TRY_TO(TraverseStmt(D->getAsmString())); 01255 }) 01256 01257 DEF_TRAVERSE_DECL(ImportDecl, { }) 01258 01259 DEF_TRAVERSE_DECL(FriendDecl, { 01260 // Friend is either decl or a type. 01261 if (D->getFriendType()) 01262 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc())); 01263 else 01264 TRY_TO(TraverseDecl(D->getFriendDecl())); 01265 }) 01266 01267 DEF_TRAVERSE_DECL(FriendTemplateDecl, { 01268 if (D->getFriendType()) 01269 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc())); 01270 else 01271 TRY_TO(TraverseDecl(D->getFriendDecl())); 01272 for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) { 01273 TemplateParameterList *TPL = D->getTemplateParameterList(I); 01274 for (TemplateParameterList::iterator ITPL = TPL->begin(), 01275 ETPL = TPL->end(); 01276 ITPL != ETPL; ++ITPL) { 01277 TRY_TO(TraverseDecl(*ITPL)); 01278 } 01279 } 01280 }) 01281 01282 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, { 01283 TRY_TO(TraverseDecl(D->getSpecialization())); 01284 }) 01285 01286 DEF_TRAVERSE_DECL(LinkageSpecDecl, { }) 01287 01288 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, { 01289 // FIXME: implement this 01290 }) 01291 01292 DEF_TRAVERSE_DECL(StaticAssertDecl, { 01293 TRY_TO(TraverseStmt(D->getAssertExpr())); 01294 TRY_TO(TraverseStmt(D->getMessage())); 01295 }) 01296 01297 DEF_TRAVERSE_DECL(TranslationUnitDecl, { 01298 // Code in an unnamed namespace shows up automatically in 01299 // decls_begin()/decls_end(). Thus we don't need to recurse on 01300 // D->getAnonymousNamespace(). 01301 }) 01302 01303 DEF_TRAVERSE_DECL(NamespaceAliasDecl, { 01304 // We shouldn't traverse an aliased namespace, since it will be 01305 // defined (and, therefore, traversed) somewhere else. 01306 // 01307 // This return statement makes sure the traversal of nodes in 01308 // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) 01309 // is skipped - don't remove it. 01310 return true; 01311 }) 01312 01313 DEF_TRAVERSE_DECL(LabelDecl, { 01314 // There is no code in a LabelDecl. 01315 }) 01316 01317 01318 DEF_TRAVERSE_DECL(NamespaceDecl, { 01319 // Code in an unnamed namespace shows up automatically in 01320 // decls_begin()/decls_end(). Thus we don't need to recurse on 01321 // D->getAnonymousNamespace(). 01322 }) 01323 01324 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, { 01325 // FIXME: implement 01326 }) 01327 01328 DEF_TRAVERSE_DECL(ObjCCategoryDecl, { 01329 // FIXME: implement 01330 }) 01331 01332 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, { 01333 // FIXME: implement 01334 }) 01335 01336 DEF_TRAVERSE_DECL(ObjCImplementationDecl, { 01337 // FIXME: implement 01338 }) 01339 01340 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, { 01341 // FIXME: implement 01342 }) 01343 01344 DEF_TRAVERSE_DECL(ObjCProtocolDecl, { 01345 // FIXME: implement 01346 }) 01347 01348 DEF_TRAVERSE_DECL(ObjCMethodDecl, { 01349 if (D->getResultTypeSourceInfo()) { 01350 TRY_TO(TraverseTypeLoc(D->getResultTypeSourceInfo()->getTypeLoc())); 01351 } 01352 for (ObjCMethodDecl::param_iterator 01353 I = D->param_begin(), E = D->param_end(); I != E; ++I) { 01354 TRY_TO(TraverseDecl(*I)); 01355 } 01356 if (D->isThisDeclarationADefinition()) { 01357 TRY_TO(TraverseStmt(D->getBody())); 01358 } 01359 return true; 01360 }) 01361 01362 DEF_TRAVERSE_DECL(ObjCPropertyDecl, { 01363 // FIXME: implement 01364 }) 01365 01366 DEF_TRAVERSE_DECL(UsingDecl, { 01367 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 01368 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); 01369 }) 01370 01371 DEF_TRAVERSE_DECL(UsingDirectiveDecl, { 01372 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 01373 }) 01374 01375 DEF_TRAVERSE_DECL(UsingShadowDecl, { }) 01376 01377 // A helper method for TemplateDecl's children. 01378 template<typename Derived> 01379 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper( 01380 TemplateParameterList *TPL) { 01381 if (TPL) { 01382 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); 01383 I != E; ++I) { 01384 TRY_TO(TraverseDecl(*I)); 01385 } 01386 } 01387 return true; 01388 } 01389 01390 // A helper method for traversing the implicit instantiations of a 01391 // class template. 01392 template<typename Derived> 01393 bool RecursiveASTVisitor<Derived>::TraverseClassInstantiations( 01394 ClassTemplateDecl *D) { 01395 ClassTemplateDecl::spec_iterator end = D->spec_end(); 01396 for (ClassTemplateDecl::spec_iterator it = D->spec_begin(); it != end; ++it) { 01397 ClassTemplateSpecializationDecl* SD = *it; 01398 01399 switch (SD->getSpecializationKind()) { 01400 // Visit the implicit instantiations with the requested pattern. 01401 case TSK_Undeclared: 01402 case TSK_ImplicitInstantiation: 01403 TRY_TO(TraverseDecl(SD)); 01404 break; 01405 01406 // We don't need to do anything on an explicit instantiation 01407 // or explicit specialization because there will be an explicit 01408 // node for it elsewhere. 01409 case TSK_ExplicitInstantiationDeclaration: 01410 case TSK_ExplicitInstantiationDefinition: 01411 case TSK_ExplicitSpecialization: 01412 break; 01413 } 01414 } 01415 01416 return true; 01417 } 01418 01419 DEF_TRAVERSE_DECL(ClassTemplateDecl, { 01420 CXXRecordDecl* TempDecl = D->getTemplatedDecl(); 01421 TRY_TO(TraverseDecl(TempDecl)); 01422 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); 01423 01424 // By default, we do not traverse the instantiations of 01425 // class templates since they do not appear in the user code. The 01426 // following code optionally traverses them. 01427 // 01428 // We only traverse the class instantiations when we see the canonical 01429 // declaration of the template, to ensure we only visit them once. 01430 if (getDerived().shouldVisitTemplateInstantiations() && 01431 D == D->getCanonicalDecl()) 01432 TRY_TO(TraverseClassInstantiations(D)); 01433 01434 // Note that getInstantiatedFromMemberTemplate() is just a link 01435 // from a template instantiation back to the template from which 01436 // it was instantiated, and thus should not be traversed. 01437 }) 01438 01439 // A helper method for traversing the instantiations of a 01440 // function while skipping its specializations. 01441 template<typename Derived> 01442 bool RecursiveASTVisitor<Derived>::TraverseFunctionInstantiations( 01443 FunctionTemplateDecl *D) { 01444 FunctionTemplateDecl::spec_iterator end = D->spec_end(); 01445 for (FunctionTemplateDecl::spec_iterator it = D->spec_begin(); it != end; 01446 ++it) { 01447 FunctionDecl* FD = *it; 01448 switch (FD->getTemplateSpecializationKind()) { 01449 case TSK_Undeclared: 01450 case TSK_ImplicitInstantiation: 01451 // We don't know what kind of FunctionDecl this is. 01452 TRY_TO(TraverseDecl(FD)); 01453 break; 01454 01455 // FIXME: For now traverse explicit instantiations here. Change that 01456 // once they are represented as dedicated nodes in the AST. 01457 case TSK_ExplicitInstantiationDeclaration: 01458 case TSK_ExplicitInstantiationDefinition: 01459 TRY_TO(TraverseDecl(FD)); 01460 break; 01461 01462 case TSK_ExplicitSpecialization: 01463 break; 01464 } 01465 } 01466 01467 return true; 01468 } 01469 01470 DEF_TRAVERSE_DECL(FunctionTemplateDecl, { 01471 TRY_TO(TraverseDecl(D->getTemplatedDecl())); 01472 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); 01473 01474 // By default, we do not traverse the instantiations of 01475 // function templates since they do not appear in the user code. The 01476 // following code optionally traverses them. 01477 // 01478 // We only traverse the function instantiations when we see the canonical 01479 // declaration of the template, to ensure we only visit them once. 01480 if (getDerived().shouldVisitTemplateInstantiations() && 01481 D == D->getCanonicalDecl()) 01482 TRY_TO(TraverseFunctionInstantiations(D)); 01483 }) 01484 01485 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, { 01486 // D is the "T" in something like 01487 // template <template <typename> class T> class container { }; 01488 TRY_TO(TraverseDecl(D->getTemplatedDecl())); 01489 if (D->hasDefaultArgument()) { 01490 TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument())); 01491 } 01492 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); 01493 }) 01494 01495 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, { 01496 // D is the "T" in something like "template<typename T> class vector;" 01497 if (D->getTypeForDecl()) 01498 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0))); 01499 if (D->hasDefaultArgument()) 01500 TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc())); 01501 }) 01502 01503 DEF_TRAVERSE_DECL(TypedefDecl, { 01504 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 01505 // We shouldn't traverse D->getTypeForDecl(); it's a result of 01506 // declaring the typedef, not something that was written in the 01507 // source. 01508 }) 01509 01510 DEF_TRAVERSE_DECL(TypeAliasDecl, { 01511 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 01512 // We shouldn't traverse D->getTypeForDecl(); it's a result of 01513 // declaring the type alias, not something that was written in the 01514 // source. 01515 }) 01516 01517 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, { 01518 TRY_TO(TraverseDecl(D->getTemplatedDecl())); 01519 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); 01520 }) 01521 01522 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, { 01523 // A dependent using declaration which was marked with 'typename'. 01524 // template<class T> class A : public B<T> { using typename B<T>::foo; }; 01525 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 01526 // We shouldn't traverse D->getTypeForDecl(); it's a result of 01527 // declaring the type, not something that was written in the 01528 // source. 01529 }) 01530 01531 DEF_TRAVERSE_DECL(EnumDecl, { 01532 if (D->getTypeForDecl()) 01533 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0))); 01534 01535 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 01536 // The enumerators are already traversed by 01537 // decls_begin()/decls_end(). 01538 }) 01539 01540 01541 // Helper methods for RecordDecl and its children. 01542 template<typename Derived> 01543 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper( 01544 RecordDecl *D) { 01545 // We shouldn't traverse D->getTypeForDecl(); it's a result of 01546 // declaring the type, not something that was written in the source. 01547 01548 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 01549 return true; 01550 } 01551 01552 template<typename Derived> 01553 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper( 01554 CXXRecordDecl *D) { 01555 if (!TraverseRecordHelper(D)) 01556 return false; 01557 if (D->isCompleteDefinition()) { 01558 for (CXXRecordDecl::base_class_iterator I = D->bases_begin(), 01559 E = D->bases_end(); 01560 I != E; ++I) { 01561 TRY_TO(TraverseTypeLoc(I->getTypeSourceInfo()->getTypeLoc())); 01562 } 01563 // We don't traverse the friends or the conversions, as they are 01564 // already in decls_begin()/decls_end(). 01565 } 01566 return true; 01567 } 01568 01569 DEF_TRAVERSE_DECL(RecordDecl, { 01570 TRY_TO(TraverseRecordHelper(D)); 01571 }) 01572 01573 DEF_TRAVERSE_DECL(CXXRecordDecl, { 01574 TRY_TO(TraverseCXXRecordHelper(D)); 01575 }) 01576 01577 DEF_TRAVERSE_DECL(ClassTemplateSpecializationDecl, { 01578 // For implicit instantiations ("set<int> x;"), we don't want to 01579 // recurse at all, since the instatiated class isn't written in 01580 // the source code anywhere. (Note the instatiated *type* -- 01581 // set<int> -- is written, and will still get a callback of 01582 // TemplateSpecializationType). For explicit instantiations 01583 // ("template set<int>;"), we do need a callback, since this 01584 // is the only callback that's made for this instantiation. 01585 // We use getTypeAsWritten() to distinguish. 01586 if (TypeSourceInfo *TSI = D->getTypeAsWritten()) 01587 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); 01588 01589 if (!getDerived().shouldVisitTemplateInstantiations() && 01590 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) 01591 // Returning from here skips traversing the 01592 // declaration context of the ClassTemplateSpecializationDecl 01593 // (embedded in the DEF_TRAVERSE_DECL() macro) 01594 // which contains the instantiated members of the class. 01595 return true; 01596 }) 01597 01598 template <typename Derived> 01599 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper( 01600 const TemplateArgumentLoc *TAL, unsigned Count) { 01601 for (unsigned I = 0; I < Count; ++I) { 01602 TRY_TO(TraverseTemplateArgumentLoc(TAL[I])); 01603 } 01604 return true; 01605 } 01606 01607 DEF_TRAVERSE_DECL(ClassTemplatePartialSpecializationDecl, { 01608 // The partial specialization. 01609 if (TemplateParameterList *TPL = D->getTemplateParameters()) { 01610 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); 01611 I != E; ++I) { 01612 TRY_TO(TraverseDecl(*I)); 01613 } 01614 } 01615 // The args that remains unspecialized. 01616 TRY_TO(TraverseTemplateArgumentLocsHelper( 01617 D->getTemplateArgsAsWritten(), D->getNumTemplateArgsAsWritten())); 01618 01619 // Don't need the ClassTemplatePartialSpecializationHelper, even 01620 // though that's our parent class -- we already visit all the 01621 // template args here. 01622 TRY_TO(TraverseCXXRecordHelper(D)); 01623 01624 // Instantiations will have been visited with the primary template. 01625 }) 01626 01627 DEF_TRAVERSE_DECL(EnumConstantDecl, { 01628 TRY_TO(TraverseStmt(D->getInitExpr())); 01629 }) 01630 01631 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, { 01632 // Like UnresolvedUsingTypenameDecl, but without the 'typename': 01633 // template <class T> Class A : public Base<T> { using Base<T>::foo; }; 01634 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 01635 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); 01636 }) 01637 01638 DEF_TRAVERSE_DECL(IndirectFieldDecl, {}) 01639 01640 template<typename Derived> 01641 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) { 01642 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 01643 if (D->getTypeSourceInfo()) 01644 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 01645 else 01646 TRY_TO(TraverseType(D->getType())); 01647 return true; 01648 } 01649 01650 DEF_TRAVERSE_DECL(FieldDecl, { 01651 TRY_TO(TraverseDeclaratorHelper(D)); 01652 if (D->isBitField()) 01653 TRY_TO(TraverseStmt(D->getBitWidth())); 01654 else if (D->hasInClassInitializer()) 01655 TRY_TO(TraverseStmt(D->getInClassInitializer())); 01656 }) 01657 01658 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, { 01659 TRY_TO(TraverseDeclaratorHelper(D)); 01660 if (D->isBitField()) 01661 TRY_TO(TraverseStmt(D->getBitWidth())); 01662 // FIXME: implement the rest. 01663 }) 01664 01665 DEF_TRAVERSE_DECL(ObjCIvarDecl, { 01666 TRY_TO(TraverseDeclaratorHelper(D)); 01667 if (D->isBitField()) 01668 TRY_TO(TraverseStmt(D->getBitWidth())); 01669 // FIXME: implement the rest. 01670 }) 01671 01672 template<typename Derived> 01673 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) { 01674 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 01675 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); 01676 01677 // If we're an explicit template specialization, iterate over the 01678 // template args that were explicitly specified. If we were doing 01679 // this in typing order, we'd do it between the return type and 01680 // the function args, but both are handled by the FunctionTypeLoc 01681 // above, so we have to choose one side. I've decided to do before. 01682 if (const FunctionTemplateSpecializationInfo *FTSI = 01683 D->getTemplateSpecializationInfo()) { 01684 if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared && 01685 FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) { 01686 // A specialization might not have explicit template arguments if it has 01687 // a templated return type and concrete arguments. 01688 if (const ASTTemplateArgumentListInfo *TALI = 01689 FTSI->TemplateArgumentsAsWritten) { 01690 TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(), 01691 TALI->NumTemplateArgs)); 01692 } 01693 } 01694 } 01695 01696 // Visit the function type itself, which can be either 01697 // FunctionNoProtoType or FunctionProtoType, or a typedef. This 01698 // also covers the return type and the function parameters, 01699 // including exception specifications. 01700 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 01701 01702 if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) { 01703 // Constructor initializers. 01704 for (CXXConstructorDecl::init_iterator I = Ctor->init_begin(), 01705 E = Ctor->init_end(); 01706 I != E; ++I) { 01707 TRY_TO(TraverseConstructorInitializer(*I)); 01708 } 01709 } 01710 01711 if (D->isThisDeclarationADefinition()) { 01712 TRY_TO(TraverseStmt(D->getBody())); // Function body. 01713 } 01714 return true; 01715 } 01716 01717 DEF_TRAVERSE_DECL(FunctionDecl, { 01718 // We skip decls_begin/decls_end, which are already covered by 01719 // TraverseFunctionHelper(). 01720 return TraverseFunctionHelper(D); 01721 }) 01722 01723 DEF_TRAVERSE_DECL(CXXMethodDecl, { 01724 // We skip decls_begin/decls_end, which are already covered by 01725 // TraverseFunctionHelper(). 01726 return TraverseFunctionHelper(D); 01727 }) 01728 01729 DEF_TRAVERSE_DECL(CXXConstructorDecl, { 01730 // We skip decls_begin/decls_end, which are already covered by 01731 // TraverseFunctionHelper(). 01732 return TraverseFunctionHelper(D); 01733 }) 01734 01735 // CXXConversionDecl is the declaration of a type conversion operator. 01736 // It's not a cast expression. 01737 DEF_TRAVERSE_DECL(CXXConversionDecl, { 01738 // We skip decls_begin/decls_end, which are already covered by 01739 // TraverseFunctionHelper(). 01740 return TraverseFunctionHelper(D); 01741 }) 01742 01743 DEF_TRAVERSE_DECL(CXXDestructorDecl, { 01744 // We skip decls_begin/decls_end, which are already covered by 01745 // TraverseFunctionHelper(). 01746 return TraverseFunctionHelper(D); 01747 }) 01748 01749 template<typename Derived> 01750 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) { 01751 TRY_TO(TraverseDeclaratorHelper(D)); 01752 // Default params are taken care of when we traverse the ParmVarDecl. 01753 if (!isa<ParmVarDecl>(D)) 01754 TRY_TO(TraverseStmt(D->getInit())); 01755 return true; 01756 } 01757 01758 DEF_TRAVERSE_DECL(VarDecl, { 01759 TRY_TO(TraverseVarHelper(D)); 01760 }) 01761 01762 DEF_TRAVERSE_DECL(ImplicitParamDecl, { 01763 TRY_TO(TraverseVarHelper(D)); 01764 }) 01765 01766 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, { 01767 // A non-type template parameter, e.g. "S" in template<int S> class Foo ... 01768 TRY_TO(TraverseDeclaratorHelper(D)); 01769 TRY_TO(TraverseStmt(D->getDefaultArgument())); 01770 }) 01771 01772 DEF_TRAVERSE_DECL(ParmVarDecl, { 01773 TRY_TO(TraverseVarHelper(D)); 01774 01775 if (D->hasDefaultArg() && 01776 D->hasUninstantiatedDefaultArg() && 01777 !D->hasUnparsedDefaultArg()) 01778 TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg())); 01779 01780 if (D->hasDefaultArg() && 01781 !D->hasUninstantiatedDefaultArg() && 01782 !D->hasUnparsedDefaultArg()) 01783 TRY_TO(TraverseStmt(D->getDefaultArg())); 01784 }) 01785 01786 #undef DEF_TRAVERSE_DECL 01787 01788 // ----------------- Stmt traversal ----------------- 01789 // 01790 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating 01791 // over the children defined in children() (every stmt defines these, 01792 // though sometimes the range is empty). Each individual Traverse* 01793 // method only needs to worry about children other than those. To see 01794 // what children() does for a given class, see, e.g., 01795 // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html 01796 01797 // This macro makes available a variable S, the passed-in stmt. 01798 #define DEF_TRAVERSE_STMT(STMT, CODE) \ 01799 template<typename Derived> \ 01800 bool RecursiveASTVisitor<Derived>::Traverse##STMT (STMT *S) { \ 01801 TRY_TO(WalkUpFrom##STMT(S)); \ 01802 { CODE; } \ 01803 for (Stmt::child_range range = S->children(); range; ++range) { \ 01804 TRY_TO(TraverseStmt(*range)); \ 01805 } \ 01806 return true; \ 01807 } 01808 01809 DEF_TRAVERSE_STMT(AsmStmt, { 01810 TRY_TO(TraverseStmt(S->getAsmString())); 01811 for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) { 01812 TRY_TO(TraverseStmt(S->getInputConstraintLiteral(I))); 01813 } 01814 for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) { 01815 TRY_TO(TraverseStmt(S->getOutputConstraintLiteral(I))); 01816 } 01817 for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) { 01818 TRY_TO(TraverseStmt(S->getClobber(I))); 01819 } 01820 // children() iterates over inputExpr and outputExpr. 01821 }) 01822 01823 DEF_TRAVERSE_STMT(CXXCatchStmt, { 01824 TRY_TO(TraverseDecl(S->getExceptionDecl())); 01825 // children() iterates over the handler block. 01826 }) 01827 01828 DEF_TRAVERSE_STMT(DeclStmt, { 01829 for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end(); 01830 I != E; ++I) { 01831 TRY_TO(TraverseDecl(*I)); 01832 } 01833 // Suppress the default iteration over children() by 01834 // returning. Here's why: A DeclStmt looks like 'type var [= 01835 // initializer]'. The decls above already traverse over the 01836 // initializers, so we don't have to do it again (which 01837 // children() would do). 01838 return true; 01839 }) 01840 01841 01842 // These non-expr stmts (most of them), do not need any action except 01843 // iterating over the children. 01844 DEF_TRAVERSE_STMT(BreakStmt, { }) 01845 DEF_TRAVERSE_STMT(CXXTryStmt, { }) 01846 DEF_TRAVERSE_STMT(CaseStmt, { }) 01847 DEF_TRAVERSE_STMT(CompoundStmt, { }) 01848 DEF_TRAVERSE_STMT(ContinueStmt, { }) 01849 DEF_TRAVERSE_STMT(DefaultStmt, { }) 01850 DEF_TRAVERSE_STMT(DoStmt, { }) 01851 DEF_TRAVERSE_STMT(ForStmt, { }) 01852 DEF_TRAVERSE_STMT(GotoStmt, { }) 01853 DEF_TRAVERSE_STMT(IfStmt, { }) 01854 DEF_TRAVERSE_STMT(IndirectGotoStmt, { }) 01855 DEF_TRAVERSE_STMT(LabelStmt, { }) 01856 DEF_TRAVERSE_STMT(AttributedStmt, { }) 01857 DEF_TRAVERSE_STMT(NullStmt, { }) 01858 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, { }) 01859 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, { }) 01860 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, { }) 01861 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, { }) 01862 DEF_TRAVERSE_STMT(ObjCAtTryStmt, { }) 01863 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, { }) 01864 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, { }) 01865 DEF_TRAVERSE_STMT(CXXForRangeStmt, { }) 01866 DEF_TRAVERSE_STMT(MSDependentExistsStmt, { 01867 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 01868 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo())); 01869 }) 01870 DEF_TRAVERSE_STMT(ReturnStmt, { }) 01871 DEF_TRAVERSE_STMT(SwitchStmt, { }) 01872 DEF_TRAVERSE_STMT(WhileStmt, { }) 01873 01874 01875 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, { 01876 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 01877 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo())); 01878 if (S->hasExplicitTemplateArgs()) { 01879 TRY_TO(TraverseTemplateArgumentLocsHelper( 01880 S->getTemplateArgs(), S->getNumTemplateArgs())); 01881 } 01882 }) 01883 01884 DEF_TRAVERSE_STMT(DeclRefExpr, { 01885 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 01886 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo())); 01887 TRY_TO(TraverseTemplateArgumentLocsHelper( 01888 S->getTemplateArgs(), S->getNumTemplateArgs())); 01889 }) 01890 01891 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, { 01892 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 01893 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo())); 01894 if (S->hasExplicitTemplateArgs()) { 01895 TRY_TO(TraverseTemplateArgumentLocsHelper( 01896 S->getExplicitTemplateArgs().getTemplateArgs(), 01897 S->getNumTemplateArgs())); 01898 } 01899 }) 01900 01901 DEF_TRAVERSE_STMT(MemberExpr, { 01902 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 01903 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo())); 01904 TRY_TO(TraverseTemplateArgumentLocsHelper( 01905 S->getTemplateArgs(), S->getNumTemplateArgs())); 01906 }) 01907 01908 DEF_TRAVERSE_STMT(ImplicitCastExpr, { 01909 // We don't traverse the cast type, as it's not written in the 01910 // source code. 01911 }) 01912 01913 DEF_TRAVERSE_STMT(CStyleCastExpr, { 01914 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 01915 }) 01916 01917 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, { 01918 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 01919 }) 01920 01921 DEF_TRAVERSE_STMT(CXXConstCastExpr, { 01922 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 01923 }) 01924 01925 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, { 01926 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 01927 }) 01928 01929 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, { 01930 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 01931 }) 01932 01933 DEF_TRAVERSE_STMT(CXXStaticCastExpr, { 01934 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 01935 }) 01936 01937 // InitListExpr is a tricky one, because we want to do all our work on 01938 // the syntactic form of the listexpr, but this method takes the 01939 // semantic form by default. We can't use the macro helper because it 01940 // calls WalkUp*() on the semantic form, before our code can convert 01941 // to the syntactic form. 01942 template<typename Derived> 01943 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr(InitListExpr *S) { 01944 if (InitListExpr *Syn = S->getSyntacticForm()) 01945 S = Syn; 01946 TRY_TO(WalkUpFromInitListExpr(S)); 01947 // All we need are the default actions. FIXME: use a helper function. 01948 for (Stmt::child_range range = S->children(); range; ++range) { 01949 TRY_TO(TraverseStmt(*range)); 01950 } 01951 return true; 01952 } 01953 01954 // GenericSelectionExpr is a special case because the types and expressions 01955 // are interleaved. We also need to watch out for null types (default 01956 // generic associations). 01957 template<typename Derived> 01958 bool RecursiveASTVisitor<Derived>:: 01959 TraverseGenericSelectionExpr(GenericSelectionExpr *S) { 01960 TRY_TO(WalkUpFromGenericSelectionExpr(S)); 01961 TRY_TO(TraverseStmt(S->getControllingExpr())); 01962 for (unsigned i = 0; i != S->getNumAssocs(); ++i) { 01963 if (TypeSourceInfo *TS = S->getAssocTypeSourceInfo(i)) 01964 TRY_TO(TraverseTypeLoc(TS->getTypeLoc())); 01965 TRY_TO(TraverseStmt(S->getAssocExpr(i))); 01966 } 01967 return true; 01968 } 01969 01970 // PseudoObjectExpr is a special case because of the wierdness with 01971 // syntactic expressions and opaque values. 01972 template<typename Derived> 01973 bool RecursiveASTVisitor<Derived>:: 01974 TraversePseudoObjectExpr(PseudoObjectExpr *S) { 01975 TRY_TO(WalkUpFromPseudoObjectExpr(S)); 01976 TRY_TO(TraverseStmt(S->getSyntacticForm())); 01977 for (PseudoObjectExpr::semantics_iterator 01978 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) { 01979 Expr *sub = *i; 01980 if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub)) 01981 sub = OVE->getSourceExpr(); 01982 TRY_TO(TraverseStmt(sub)); 01983 } 01984 return true; 01985 } 01986 01987 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, { 01988 // This is called for code like 'return T()' where T is a built-in 01989 // (i.e. non-class) type. 01990 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 01991 }) 01992 01993 DEF_TRAVERSE_STMT(CXXNewExpr, { 01994 // The child-iterator will pick up the other arguments. 01995 TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc())); 01996 }) 01997 01998 DEF_TRAVERSE_STMT(OffsetOfExpr, { 01999 // The child-iterator will pick up the expression representing 02000 // the field. 02001 // FIMXE: for code like offsetof(Foo, a.b.c), should we get 02002 // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c? 02003 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 02004 }) 02005 02006 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, { 02007 // The child-iterator will pick up the arg if it's an expression, 02008 // but not if it's a type. 02009 if (S->isArgumentType()) 02010 TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc())); 02011 }) 02012 02013 DEF_TRAVERSE_STMT(CXXTypeidExpr, { 02014 // The child-iterator will pick up the arg if it's an expression, 02015 // but not if it's a type. 02016 if (S->isTypeOperand()) 02017 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc())); 02018 }) 02019 02020 DEF_TRAVERSE_STMT(CXXUuidofExpr, { 02021 // The child-iterator will pick up the arg if it's an expression, 02022 // but not if it's a type. 02023 if (S->isTypeOperand()) 02024 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc())); 02025 }) 02026 02027 DEF_TRAVERSE_STMT(UnaryTypeTraitExpr, { 02028 TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc())); 02029 }) 02030 02031 DEF_TRAVERSE_STMT(BinaryTypeTraitExpr, { 02032 TRY_TO(TraverseTypeLoc(S->getLhsTypeSourceInfo()->getTypeLoc())); 02033 TRY_TO(TraverseTypeLoc(S->getRhsTypeSourceInfo()->getTypeLoc())); 02034 }) 02035 02036 DEF_TRAVERSE_STMT(TypeTraitExpr, { 02037 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 02038 TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc())); 02039 }) 02040 02041 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, { 02042 TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc())); 02043 }) 02044 02045 DEF_TRAVERSE_STMT(ExpressionTraitExpr, { 02046 TRY_TO(TraverseStmt(S->getQueriedExpression())); 02047 }) 02048 02049 DEF_TRAVERSE_STMT(VAArgExpr, { 02050 // The child-iterator will pick up the expression argument. 02051 TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc())); 02052 }) 02053 02054 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, { 02055 // This is called for code like 'return T()' where T is a class type. 02056 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 02057 }) 02058 02059 // Walk only the visible parts of lambda expressions. 02060 template<typename Derived> 02061 bool RecursiveASTVisitor<Derived>::TraverseLambdaExpr(LambdaExpr *S) { 02062 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), 02063 CEnd = S->explicit_capture_end(); 02064 C != CEnd; ++C) { 02065 TRY_TO(TraverseLambdaCapture(*C)); 02066 } 02067 02068 if (S->hasExplicitParameters() || S->hasExplicitResultType()) { 02069 TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); 02070 if (S->hasExplicitParameters() && S->hasExplicitResultType()) { 02071 // Visit the whole type. 02072 TRY_TO(TraverseTypeLoc(TL)); 02073 } else if (isa<FunctionProtoTypeLoc>(TL)) { 02074 FunctionProtoTypeLoc Proto = cast<FunctionProtoTypeLoc>(TL); 02075 if (S->hasExplicitParameters()) { 02076 // Visit parameters. 02077 for (unsigned I = 0, N = Proto.getNumArgs(); I != N; ++I) { 02078 TRY_TO(TraverseDecl(Proto.getArg(I))); 02079 } 02080 } else { 02081 TRY_TO(TraverseTypeLoc(Proto.getResultLoc())); 02082 } 02083 } 02084 } 02085 02086 TRY_TO(TraverseStmt(S->getBody())); 02087 return true; 02088 } 02089 02090 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, { 02091 // This is called for code like 'T()', where T is a template argument. 02092 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 02093 }) 02094 02095 // These expressions all might take explicit template arguments. 02096 // We traverse those if so. FIXME: implement these. 02097 DEF_TRAVERSE_STMT(CXXConstructExpr, { }) 02098 DEF_TRAVERSE_STMT(CallExpr, { }) 02099 DEF_TRAVERSE_STMT(CXXMemberCallExpr, { }) 02100 02101 // These exprs (most of them), do not need any action except iterating 02102 // over the children. 02103 DEF_TRAVERSE_STMT(AddrLabelExpr, { }) 02104 DEF_TRAVERSE_STMT(ArraySubscriptExpr, { }) 02105 DEF_TRAVERSE_STMT(BlockExpr, { 02106 TRY_TO(TraverseDecl(S->getBlockDecl())); 02107 return true; // no child statements to loop through. 02108 }) 02109 DEF_TRAVERSE_STMT(ChooseExpr, { }) 02110 DEF_TRAVERSE_STMT(CompoundLiteralExpr, { }) 02111 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, { }) 02112 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, { }) 02113 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, { }) 02114 DEF_TRAVERSE_STMT(CXXDeleteExpr, { }) 02115 DEF_TRAVERSE_STMT(ExprWithCleanups, { }) 02116 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, { }) 02117 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, { 02118 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 02119 if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo()) 02120 TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc())); 02121 if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo()) 02122 TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc())); 02123 }) 02124 DEF_TRAVERSE_STMT(CXXThisExpr, { }) 02125 DEF_TRAVERSE_STMT(CXXThrowExpr, { }) 02126 DEF_TRAVERSE_STMT(UserDefinedLiteral, { }) 02127 DEF_TRAVERSE_STMT(DesignatedInitExpr, { }) 02128 DEF_TRAVERSE_STMT(ExtVectorElementExpr, { }) 02129 DEF_TRAVERSE_STMT(GNUNullExpr, { }) 02130 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, { }) 02131 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, { }) 02132 DEF_TRAVERSE_STMT(ObjCEncodeExpr, { 02133 if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo()) 02134 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); 02135 }) 02136 DEF_TRAVERSE_STMT(ObjCIsaExpr, { }) 02137 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, { }) 02138 DEF_TRAVERSE_STMT(ObjCMessageExpr, { }) 02139 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, { }) 02140 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, { }) 02141 DEF_TRAVERSE_STMT(ObjCProtocolExpr, { }) 02142 DEF_TRAVERSE_STMT(ObjCSelectorExpr, { }) 02143 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, { }) 02144 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, { 02145 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 02146 }) 02147 DEF_TRAVERSE_STMT(ParenExpr, { }) 02148 DEF_TRAVERSE_STMT(ParenListExpr, { }) 02149 DEF_TRAVERSE_STMT(PredefinedExpr, { }) 02150 DEF_TRAVERSE_STMT(ShuffleVectorExpr, { }) 02151 DEF_TRAVERSE_STMT(StmtExpr, { }) 02152 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, { 02153 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 02154 if (S->hasExplicitTemplateArgs()) { 02155 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(), 02156 S->getNumTemplateArgs())); 02157 } 02158 }) 02159 02160 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, { 02161 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 02162 if (S->hasExplicitTemplateArgs()) { 02163 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(), 02164 S->getNumTemplateArgs())); 02165 } 02166 }) 02167 02168 DEF_TRAVERSE_STMT(SEHTryStmt, {}) 02169 DEF_TRAVERSE_STMT(SEHExceptStmt, {}) 02170 DEF_TRAVERSE_STMT(SEHFinallyStmt,{}) 02171 02172 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, { }) 02173 DEF_TRAVERSE_STMT(OpaqueValueExpr, { }) 02174 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, { }) 02175 02176 // These operators (all of them) do not need any action except 02177 // iterating over the children. 02178 DEF_TRAVERSE_STMT(BinaryConditionalOperator, { }) 02179 DEF_TRAVERSE_STMT(ConditionalOperator, { }) 02180 DEF_TRAVERSE_STMT(UnaryOperator, { }) 02181 DEF_TRAVERSE_STMT(BinaryOperator, { }) 02182 DEF_TRAVERSE_STMT(CompoundAssignOperator, { }) 02183 DEF_TRAVERSE_STMT(CXXNoexceptExpr, { }) 02184 DEF_TRAVERSE_STMT(PackExpansionExpr, { }) 02185 DEF_TRAVERSE_STMT(SizeOfPackExpr, { }) 02186 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, { }) 02187 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, { }) 02188 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, { }) 02189 DEF_TRAVERSE_STMT(AtomicExpr, { }) 02190 02191 // These literals (all of them) do not need any action. 02192 DEF_TRAVERSE_STMT(IntegerLiteral, { }) 02193 DEF_TRAVERSE_STMT(CharacterLiteral, { }) 02194 DEF_TRAVERSE_STMT(FloatingLiteral, { }) 02195 DEF_TRAVERSE_STMT(ImaginaryLiteral, { }) 02196 DEF_TRAVERSE_STMT(StringLiteral, { }) 02197 DEF_TRAVERSE_STMT(ObjCStringLiteral, { }) 02198 DEF_TRAVERSE_STMT(ObjCBoxedExpr, { }) 02199 DEF_TRAVERSE_STMT(ObjCArrayLiteral, { }) 02200 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, { }) 02201 02202 // Traverse OpenCL: AsType, Convert. 02203 DEF_TRAVERSE_STMT(AsTypeExpr, { }) 02204 02205 // FIXME: look at the following tricky-seeming exprs to see if we 02206 // need to recurse on anything. These are ones that have methods 02207 // returning decls or qualtypes or nestednamespecifier -- though I'm 02208 // not sure if they own them -- or just seemed very complicated, or 02209 // had lots of sub-types to explore. 02210 // 02211 // VisitOverloadExpr and its children: recurse on template args? etc? 02212 02213 // FIXME: go through all the stmts and exprs again, and see which of them 02214 // create new types, and recurse on the types (TypeLocs?) of those. 02215 // Candidates: 02216 // 02217 // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html 02218 // http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html 02219 // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html 02220 // Every class that has getQualifier. 02221 02222 #undef DEF_TRAVERSE_STMT 02223 02224 #undef TRY_TO 02225 02226 } // end namespace clang 02227 02228 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H