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