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