1 //===--- RecursiveASTVisitor.h - Recursive AST Visitor ----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines the RecursiveASTVisitor interface, which recursively 10 // traverses the entire AST. 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef LLVM_CLANG_AST_RECURSIVEASTVISITOR_H 14 #define LLVM_CLANG_AST_RECURSIVEASTVISITOR_H 15 16 #include "clang/AST/ASTConcept.h" 17 #include "clang/AST/Attr.h" 18 #include "clang/AST/Decl.h" 19 #include "clang/AST/DeclBase.h" 20 #include "clang/AST/DeclCXX.h" 21 #include "clang/AST/DeclFriend.h" 22 #include "clang/AST/DeclObjC.h" 23 #include "clang/AST/DeclOpenMP.h" 24 #include "clang/AST/DeclTemplate.h" 25 #include "clang/AST/DeclarationName.h" 26 #include "clang/AST/Expr.h" 27 #include "clang/AST/ExprCXX.h" 28 #include "clang/AST/ExprConcepts.h" 29 #include "clang/AST/ExprObjC.h" 30 #include "clang/AST/ExprOpenMP.h" 31 #include "clang/AST/LambdaCapture.h" 32 #include "clang/AST/NestedNameSpecifier.h" 33 #include "clang/AST/OpenMPClause.h" 34 #include "clang/AST/Stmt.h" 35 #include "clang/AST/StmtCXX.h" 36 #include "clang/AST/StmtObjC.h" 37 #include "clang/AST/StmtOpenMP.h" 38 #include "clang/AST/TemplateBase.h" 39 #include "clang/AST/TemplateName.h" 40 #include "clang/AST/Type.h" 41 #include "clang/AST/TypeLoc.h" 42 #include "clang/Basic/LLVM.h" 43 #include "clang/Basic/OpenMPKinds.h" 44 #include "clang/Basic/Specifiers.h" 45 #include "llvm/ADT/PointerIntPair.h" 46 #include "llvm/ADT/SmallVector.h" 47 #include "llvm/Support/Casting.h" 48 #include <algorithm> 49 #include <cstddef> 50 #include <type_traits> 51 52 namespace clang { 53 54 // A helper macro to implement short-circuiting when recursing. It 55 // invokes CALL_EXPR, which must be a method call, on the derived 56 // object (s.t. a user of RecursiveASTVisitor can override the method 57 // in CALL_EXPR). 58 #define TRY_TO(CALL_EXPR) \ 59 do { \ 60 if (!getDerived().CALL_EXPR) \ 61 return false; \ 62 } while (false) 63 64 namespace detail { 65 66 template <typename T, typename U> 67 struct has_same_member_pointer_type : std::false_type {}; 68 template <typename T, typename U, typename R, typename... P> 69 struct has_same_member_pointer_type<R (T::*)(P...), R (U::*)(P...)> 70 : std::true_type {}; 71 72 /// Returns true if and only if \p FirstMethodPtr and \p SecondMethodPtr 73 /// are pointers to the same non-static member function. 74 template <typename FirstMethodPtrTy, typename SecondMethodPtrTy> 75 LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_NODEBUG auto 76 isSameMethod([[maybe_unused]] FirstMethodPtrTy FirstMethodPtr, 77 [[maybe_unused]] SecondMethodPtrTy SecondMethodPtr) 78 -> bool { 79 if constexpr (has_same_member_pointer_type<FirstMethodPtrTy, 80 SecondMethodPtrTy>::value) 81 return FirstMethodPtr == SecondMethodPtr; 82 return false; 83 } 84 85 } // end namespace detail 86 87 /// A class that does preorder or postorder 88 /// depth-first traversal on the entire Clang AST and visits each node. 89 /// 90 /// This class performs three distinct tasks: 91 /// 1. traverse the AST (i.e. go to each node); 92 /// 2. at a given node, walk up the class hierarchy, starting from 93 /// the node's dynamic type, until the top-most class (e.g. Stmt, 94 /// Decl, or Type) is reached. 95 /// 3. given a (node, class) combination, where 'class' is some base 96 /// class of the dynamic type of 'node', call a user-overridable 97 /// function to actually visit the node. 98 /// 99 /// These tasks are done by three groups of methods, respectively: 100 /// 1. TraverseDecl(Decl *x) does task #1. It is the entry point 101 /// for traversing an AST rooted at x. This method simply 102 /// dispatches (i.e. forwards) to TraverseFoo(Foo *x) where Foo 103 /// is the dynamic type of *x, which calls WalkUpFromFoo(x) and 104 /// then recursively visits the child nodes of x. 105 /// TraverseStmt(Stmt *x) and TraverseType(QualType x) work 106 /// similarly. 107 /// 2. WalkUpFromFoo(Foo *x) does task #2. It does not try to visit 108 /// any child node of x. Instead, it first calls WalkUpFromBar(x) 109 /// where Bar is the direct parent class of Foo (unless Foo has 110 /// no parent), and then calls VisitFoo(x) (see the next list item). 111 /// 3. VisitFoo(Foo *x) does task #3. 112 /// 113 /// These three method groups are tiered (Traverse* > WalkUpFrom* > 114 /// Visit*). A method (e.g. Traverse*) may call methods from the same 115 /// tier (e.g. other Traverse*) or one tier lower (e.g. WalkUpFrom*). 116 /// It may not call methods from a higher tier. 117 /// 118 /// Note that since WalkUpFromFoo() calls WalkUpFromBar() (where Bar 119 /// is Foo's super class) before calling VisitFoo(), the result is 120 /// that the Visit*() methods for a given node are called in the 121 /// top-down order (e.g. for a node of type NamespaceDecl, the order will 122 /// be VisitDecl(), VisitNamedDecl(), and then VisitNamespaceDecl()). 123 /// 124 /// This scheme guarantees that all Visit*() calls for the same AST 125 /// node are grouped together. In other words, Visit*() methods for 126 /// different nodes are never interleaved. 127 /// 128 /// Clients of this visitor should subclass the visitor (providing 129 /// themselves as the template argument, using the curiously recurring 130 /// template pattern) and override any of the Traverse*, WalkUpFrom*, 131 /// and Visit* methods for declarations, types, statements, 132 /// expressions, or other AST nodes where the visitor should customize 133 /// behavior. Most users only need to override Visit*. Advanced 134 /// users may override Traverse* and WalkUpFrom* to implement custom 135 /// traversal strategies. Returning false from one of these overridden 136 /// functions will abort the entire traversal. 137 /// 138 /// By default, this visitor tries to visit every part of the explicit 139 /// source code exactly once. The default policy towards templates 140 /// is to descend into the 'pattern' class or function body, not any 141 /// explicit or implicit instantiations. Explicit specializations 142 /// are still visited, and the patterns of partial specializations 143 /// are visited separately. This behavior can be changed by 144 /// overriding shouldVisitTemplateInstantiations() in the derived class 145 /// to return true, in which case all known implicit and explicit 146 /// instantiations will be visited at the same time as the pattern 147 /// from which they were produced. 148 /// 149 /// By default, this visitor preorder traverses the AST. If postorder traversal 150 /// is needed, the \c shouldTraversePostOrder method needs to be overridden 151 /// to return \c true. 152 template <typename Derived> class RecursiveASTVisitor { 153 public: 154 /// A queue used for performing data recursion over statements. 155 /// Parameters involving this type are used to implement data 156 /// recursion over Stmts and Exprs within this class, and should 157 /// typically not be explicitly specified by derived classes. 158 /// The bool bit indicates whether the statement has been traversed or not. 159 typedef SmallVectorImpl<llvm::PointerIntPair<Stmt *, 1, bool>> 160 DataRecursionQueue; 161 162 /// Return a reference to the derived class. 163 Derived &getDerived() { return *static_cast<Derived *>(this); } 164 165 /// Return whether this visitor should recurse into 166 /// template instantiations. 167 bool shouldVisitTemplateInstantiations() const { return false; } 168 169 /// Return whether this visitor should recurse into the types of 170 /// TypeLocs. 171 bool shouldWalkTypesOfTypeLocs() const { return true; } 172 173 /// Return whether this visitor should recurse into implicit 174 /// code, e.g., implicit constructors and destructors. 175 bool shouldVisitImplicitCode() const { return false; } 176 177 /// Return whether this visitor should recurse into lambda body 178 bool shouldVisitLambdaBody() const { return true; } 179 180 /// Return whether this visitor should traverse post-order. 181 bool shouldTraversePostOrder() const { return false; } 182 183 /// Recursively visits an entire AST, starting from the TranslationUnitDecl. 184 /// \returns false if visitation was terminated early. 185 bool TraverseAST(ASTContext &AST) { 186 // Currently just an alias for TraverseDecl(TUDecl), but kept in case 187 // we change the implementation again. 188 return getDerived().TraverseDecl(AST.getTranslationUnitDecl()); 189 } 190 191 /// Recursively visit a statement or expression, by 192 /// dispatching to Traverse*() based on the argument's dynamic type. 193 /// 194 /// \returns false if the visitation was terminated early, true 195 /// otherwise (including when the argument is nullptr). 196 bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue = nullptr); 197 198 /// Invoked before visiting a statement or expression via data recursion. 199 /// 200 /// \returns false to skip visiting the node, true otherwise. 201 bool dataTraverseStmtPre(Stmt *S) { return true; } 202 203 /// Invoked after visiting a statement or expression via data recursion. 204 /// This is not invoked if the previously invoked \c dataTraverseStmtPre 205 /// returned false. 206 /// 207 /// \returns false if the visitation was terminated early, true otherwise. 208 bool dataTraverseStmtPost(Stmt *S) { return true; } 209 210 /// Recursively visit a type, by dispatching to 211 /// Traverse*Type() based on the argument's getTypeClass() property. 212 /// 213 /// \returns false if the visitation was terminated early, true 214 /// otherwise (including when the argument is a Null type). 215 bool TraverseType(QualType T); 216 217 /// Recursively visit a type with location, by dispatching to 218 /// Traverse*TypeLoc() based on the argument type's getTypeClass() property. 219 /// 220 /// \returns false if the visitation was terminated early, true 221 /// otherwise (including when the argument is a Null type location). 222 bool TraverseTypeLoc(TypeLoc TL); 223 224 /// Recursively visit an attribute, by dispatching to 225 /// Traverse*Attr() based on the argument's dynamic type. 226 /// 227 /// \returns false if the visitation was terminated early, true 228 /// otherwise (including when the argument is a Null type location). 229 bool TraverseAttr(Attr *At); 230 231 /// Recursively visit a declaration, by dispatching to 232 /// Traverse*Decl() based on the argument's dynamic type. 233 /// 234 /// \returns false if the visitation was terminated early, true 235 /// otherwise (including when the argument is NULL). 236 bool TraverseDecl(Decl *D); 237 238 /// Recursively visit a C++ nested-name-specifier. 239 /// 240 /// \returns false if the visitation was terminated early, true otherwise. 241 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS); 242 243 /// Recursively visit a C++ nested-name-specifier with location 244 /// information. 245 /// 246 /// \returns false if the visitation was terminated early, true otherwise. 247 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS); 248 249 /// Recursively visit a name with its location information. 250 /// 251 /// \returns false if the visitation was terminated early, true otherwise. 252 bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo); 253 254 /// Recursively visit a template name and dispatch to the 255 /// appropriate method. 256 /// 257 /// \returns false if the visitation was terminated early, true otherwise. 258 bool TraverseTemplateName(TemplateName Template); 259 260 /// Recursively visit a template argument and dispatch to the 261 /// appropriate method for the argument type. 262 /// 263 /// \returns false if the visitation was terminated early, true otherwise. 264 // FIXME: migrate callers to TemplateArgumentLoc instead. 265 bool TraverseTemplateArgument(const TemplateArgument &Arg); 266 267 /// Recursively visit a template argument location and dispatch to the 268 /// appropriate method for the argument type. 269 /// 270 /// \returns false if the visitation was terminated early, true otherwise. 271 bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc); 272 273 /// Recursively visit a set of template arguments. 274 /// This can be overridden by a subclass, but it's not expected that 275 /// will be needed -- this visitor always dispatches to another. 276 /// 277 /// \returns false if the visitation was terminated early, true otherwise. 278 // FIXME: take a TemplateArgumentLoc* (or TemplateArgumentListInfo) instead. 279 bool TraverseTemplateArguments(ArrayRef<TemplateArgument> Args); 280 281 /// Recursively visit a base specifier. This can be overridden by a 282 /// subclass. 283 /// 284 /// \returns false if the visitation was terminated early, true otherwise. 285 bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base); 286 287 /// Recursively visit a constructor initializer. This 288 /// automatically dispatches to another visitor for the initializer 289 /// expression, but not for the name of the initializer, so may 290 /// be overridden for clients that need access to the name. 291 /// 292 /// \returns false if the visitation was terminated early, true otherwise. 293 bool TraverseConstructorInitializer(CXXCtorInitializer *Init); 294 295 /// Recursively visit a lambda capture. \c Init is the expression that 296 /// will be used to initialize the capture. 297 /// 298 /// \returns false if the visitation was terminated early, true otherwise. 299 bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C, 300 Expr *Init); 301 302 /// Recursively visit the syntactic or semantic form of an 303 /// initialization list. 304 /// 305 /// \returns false if the visitation was terminated early, true otherwise. 306 bool TraverseSynOrSemInitListExpr(InitListExpr *S, 307 DataRecursionQueue *Queue = nullptr); 308 309 /// Recursively visit an Objective-C protocol reference with location 310 /// information. 311 /// 312 /// \returns false if the visitation was terminated early, true otherwise. 313 bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLoc); 314 315 // ---- Methods on Attrs ---- 316 317 // Visit an attribute. 318 bool VisitAttr(Attr *A) { return true; } 319 320 // Declare Traverse* and empty Visit* for all Attr classes. 321 #define ATTR_VISITOR_DECLS_ONLY 322 #include "clang/AST/AttrVisitor.inc" 323 #undef ATTR_VISITOR_DECLS_ONLY 324 325 // ---- Methods on Stmts ---- 326 327 Stmt::child_range getStmtChildren(Stmt *S) { return S->children(); } 328 329 private: 330 // Traverse the given statement. If the most-derived traverse function takes a 331 // data recursion queue, pass it on; otherwise, discard it. Note that the 332 // first branch of this conditional must compile whether or not the derived 333 // class can take a queue, so if we're taking the second arm, make the first 334 // arm call our function rather than the derived class version. 335 #define TRAVERSE_STMT_BASE(NAME, CLASS, VAR, QUEUE) \ 336 (::clang::detail::has_same_member_pointer_type< \ 337 decltype(&RecursiveASTVisitor::Traverse##NAME), \ 338 decltype(&Derived::Traverse##NAME)>::value \ 339 ? static_cast<std::conditional_t< \ 340 ::clang::detail::has_same_member_pointer_type< \ 341 decltype(&RecursiveASTVisitor::Traverse##NAME), \ 342 decltype(&Derived::Traverse##NAME)>::value, \ 343 Derived &, RecursiveASTVisitor &>>(*this) \ 344 .Traverse##NAME(static_cast<CLASS *>(VAR), QUEUE) \ 345 : getDerived().Traverse##NAME(static_cast<CLASS *>(VAR))) 346 347 // Try to traverse the given statement, or enqueue it if we're performing data 348 // recursion in the middle of traversing another statement. Can only be called 349 // from within a DEF_TRAVERSE_STMT body or similar context. 350 #define TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S) \ 351 do { \ 352 if (!TRAVERSE_STMT_BASE(Stmt, Stmt, S, Queue)) \ 353 return false; \ 354 } while (false) 355 356 public: 357 // Declare Traverse*() for all concrete Stmt classes. 358 #define ABSTRACT_STMT(STMT) 359 #define STMT(CLASS, PARENT) \ 360 bool Traverse##CLASS(CLASS *S, DataRecursionQueue *Queue = nullptr); 361 #include "clang/AST/StmtNodes.inc" 362 // The above header #undefs ABSTRACT_STMT and STMT upon exit. 363 364 // Define WalkUpFrom*() and empty Visit*() for all Stmt classes. 365 bool WalkUpFromStmt(Stmt *S) { return getDerived().VisitStmt(S); } 366 bool VisitStmt(Stmt *S) { return true; } 367 #define STMT(CLASS, PARENT) \ 368 bool WalkUpFrom##CLASS(CLASS *S) { \ 369 TRY_TO(WalkUpFrom##PARENT(S)); \ 370 TRY_TO(Visit##CLASS(S)); \ 371 return true; \ 372 } \ 373 bool Visit##CLASS(CLASS *S) { return true; } 374 #include "clang/AST/StmtNodes.inc" 375 376 // ---- Methods on Types ---- 377 // FIXME: revamp to take TypeLoc's rather than Types. 378 379 // Declare Traverse*() for all concrete Type classes. 380 #define ABSTRACT_TYPE(CLASS, BASE) 381 #define TYPE(CLASS, BASE) bool Traverse##CLASS##Type(CLASS##Type *T); 382 #include "clang/AST/TypeNodes.inc" 383 // The above header #undefs ABSTRACT_TYPE and TYPE upon exit. 384 385 // Define WalkUpFrom*() and empty Visit*() for all Type classes. 386 bool WalkUpFromType(Type *T) { return getDerived().VisitType(T); } 387 bool VisitType(Type *T) { return true; } 388 #define TYPE(CLASS, BASE) \ 389 bool WalkUpFrom##CLASS##Type(CLASS##Type *T) { \ 390 TRY_TO(WalkUpFrom##BASE(T)); \ 391 TRY_TO(Visit##CLASS##Type(T)); \ 392 return true; \ 393 } \ 394 bool Visit##CLASS##Type(CLASS##Type *T) { return true; } 395 #include "clang/AST/TypeNodes.inc" 396 397 // ---- Methods on TypeLocs ---- 398 // FIXME: this currently just calls the matching Type methods 399 400 // Declare Traverse*() for all concrete TypeLoc classes. 401 #define ABSTRACT_TYPELOC(CLASS, BASE) 402 #define TYPELOC(CLASS, BASE) bool Traverse##CLASS##TypeLoc(CLASS##TypeLoc TL); 403 #include "clang/AST/TypeLocNodes.def" 404 // The above header #undefs ABSTRACT_TYPELOC and TYPELOC upon exit. 405 406 // Define WalkUpFrom*() and empty Visit*() for all TypeLoc classes. 407 bool WalkUpFromTypeLoc(TypeLoc TL) { return getDerived().VisitTypeLoc(TL); } 408 bool VisitTypeLoc(TypeLoc TL) { return true; } 409 410 // QualifiedTypeLoc and UnqualTypeLoc are not declared in 411 // TypeNodes.inc and thus need to be handled specially. 412 bool WalkUpFromQualifiedTypeLoc(QualifiedTypeLoc TL) { 413 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc()); 414 } 415 bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { return true; } 416 bool WalkUpFromUnqualTypeLoc(UnqualTypeLoc TL) { 417 return getDerived().VisitUnqualTypeLoc(TL.getUnqualifiedLoc()); 418 } 419 bool VisitUnqualTypeLoc(UnqualTypeLoc TL) { return true; } 420 421 // Note that BASE includes trailing 'Type' which CLASS doesn't. 422 #define TYPE(CLASS, BASE) \ 423 bool WalkUpFrom##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ 424 TRY_TO(WalkUpFrom##BASE##Loc(TL)); \ 425 TRY_TO(Visit##CLASS##TypeLoc(TL)); \ 426 return true; \ 427 } \ 428 bool Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { return true; } 429 #include "clang/AST/TypeNodes.inc" 430 431 // ---- Methods on Decls ---- 432 433 // Declare Traverse*() for all concrete Decl classes. 434 #define ABSTRACT_DECL(DECL) 435 #define DECL(CLASS, BASE) bool Traverse##CLASS##Decl(CLASS##Decl *D); 436 #include "clang/AST/DeclNodes.inc" 437 // The above header #undefs ABSTRACT_DECL and DECL upon exit. 438 439 // Define WalkUpFrom*() and empty Visit*() for all Decl classes. 440 bool WalkUpFromDecl(Decl *D) { return getDerived().VisitDecl(D); } 441 bool VisitDecl(Decl *D) { return true; } 442 #define DECL(CLASS, BASE) \ 443 bool WalkUpFrom##CLASS##Decl(CLASS##Decl *D) { \ 444 TRY_TO(WalkUpFrom##BASE(D)); \ 445 TRY_TO(Visit##CLASS##Decl(D)); \ 446 return true; \ 447 } \ 448 bool Visit##CLASS##Decl(CLASS##Decl *D) { return true; } 449 #include "clang/AST/DeclNodes.inc" 450 451 bool canIgnoreChildDeclWhileTraversingDeclContext(const Decl *Child); 452 453 #define DEF_TRAVERSE_TMPL_INST(TMPLDECLKIND) \ 454 bool TraverseTemplateInstantiations(TMPLDECLKIND##TemplateDecl *D); 455 DEF_TRAVERSE_TMPL_INST(Class) 456 DEF_TRAVERSE_TMPL_INST(Var) 457 DEF_TRAVERSE_TMPL_INST(Function) 458 #undef DEF_TRAVERSE_TMPL_INST 459 460 bool TraverseTypeConstraint(const TypeConstraint *C); 461 462 bool TraverseConceptRequirement(concepts::Requirement *R); 463 bool TraverseConceptTypeRequirement(concepts::TypeRequirement *R); 464 bool TraverseConceptExprRequirement(concepts::ExprRequirement *R); 465 bool TraverseConceptNestedRequirement(concepts::NestedRequirement *R); 466 467 bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue); 468 469 private: 470 // These are helper methods used by more than one Traverse* method. 471 bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL); 472 /// Traverses the qualifier, name and template arguments of a concept 473 /// reference. 474 bool TraverseConceptReferenceHelper(const ConceptReference &C); 475 476 // Traverses template parameter lists of either a DeclaratorDecl or TagDecl. 477 template <typename T> 478 bool TraverseDeclTemplateParameterLists(T *D); 479 480 bool TraverseTemplateTypeParamDeclConstraints(const TemplateTypeParmDecl *D); 481 482 bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL, 483 unsigned Count); 484 bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL); 485 bool TraverseRecordHelper(RecordDecl *D); 486 bool TraverseCXXRecordHelper(CXXRecordDecl *D); 487 bool TraverseDeclaratorHelper(DeclaratorDecl *D); 488 bool TraverseDeclContextHelper(DeclContext *DC); 489 bool TraverseFunctionHelper(FunctionDecl *D); 490 bool TraverseVarHelper(VarDecl *D); 491 bool TraverseOMPExecutableDirective(OMPExecutableDirective *S); 492 bool TraverseOMPLoopDirective(OMPLoopDirective *S); 493 bool TraverseOMPClause(OMPClause *C); 494 #define GEN_CLANG_CLAUSE_CLASS 495 #define CLAUSE_CLASS(Enum, Str, Class) bool Visit##Class(Class *C); 496 #include "llvm/Frontend/OpenMP/OMP.inc" 497 /// Process clauses with list of variables. 498 template <typename T> bool VisitOMPClauseList(T *Node); 499 /// Process clauses with pre-initis. 500 bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node); 501 bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node); 502 503 bool PostVisitStmt(Stmt *S); 504 }; 505 506 template <typename Derived> 507 bool RecursiveASTVisitor<Derived>::TraverseTypeConstraint( 508 const TypeConstraint *C) { 509 if (!getDerived().shouldVisitImplicitCode()) { 510 TRY_TO(TraverseConceptReferenceHelper(*C)); 511 return true; 512 } 513 if (Expr *IDC = C->getImmediatelyDeclaredConstraint()) { 514 TRY_TO(TraverseStmt(IDC)); 515 } else { 516 // Avoid traversing the ConceptReference in the TypeConstraint 517 // if we have an immediately-declared-constraint, otherwise 518 // we'll end up visiting the concept and the arguments in 519 // the TC twice. 520 TRY_TO(TraverseConceptReferenceHelper(*C)); 521 } 522 return true; 523 } 524 525 template <typename Derived> 526 bool RecursiveASTVisitor<Derived>::TraverseConceptRequirement( 527 concepts::Requirement *R) { 528 switch (R->getKind()) { 529 case concepts::Requirement::RK_Type: 530 return getDerived().TraverseConceptTypeRequirement( 531 cast<concepts::TypeRequirement>(R)); 532 case concepts::Requirement::RK_Simple: 533 case concepts::Requirement::RK_Compound: 534 return getDerived().TraverseConceptExprRequirement( 535 cast<concepts::ExprRequirement>(R)); 536 case concepts::Requirement::RK_Nested: 537 return getDerived().TraverseConceptNestedRequirement( 538 cast<concepts::NestedRequirement>(R)); 539 } 540 llvm_unreachable("unexpected case"); 541 } 542 543 template <typename Derived> 544 bool RecursiveASTVisitor<Derived>::TraverseConceptReferenceHelper( 545 const ConceptReference &C) { 546 TRY_TO(TraverseNestedNameSpecifierLoc(C.getNestedNameSpecifierLoc())); 547 TRY_TO(TraverseDeclarationNameInfo(C.getConceptNameInfo())); 548 if (C.hasExplicitTemplateArgs()) 549 TRY_TO(TraverseTemplateArgumentLocsHelper( 550 C.getTemplateArgsAsWritten()->getTemplateArgs(), 551 C.getTemplateArgsAsWritten()->NumTemplateArgs)); 552 return true; 553 } 554 555 template <typename Derived> 556 bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S, 557 DataRecursionQueue *Queue) { 558 // Top switch stmt: dispatch to TraverseFooStmt for each concrete FooStmt. 559 switch (S->getStmtClass()) { 560 case Stmt::NoStmtClass: 561 break; 562 #define ABSTRACT_STMT(STMT) 563 #define STMT(CLASS, PARENT) \ 564 case Stmt::CLASS##Class: \ 565 return TRAVERSE_STMT_BASE(CLASS, CLASS, S, Queue); 566 #include "clang/AST/StmtNodes.inc" 567 } 568 569 return true; 570 } 571 572 #undef DISPATCH_STMT 573 574 template <typename Derived> 575 bool RecursiveASTVisitor<Derived>::TraverseConceptTypeRequirement( 576 concepts::TypeRequirement *R) { 577 if (R->isSubstitutionFailure()) 578 return true; 579 return getDerived().TraverseTypeLoc(R->getType()->getTypeLoc()); 580 } 581 582 template <typename Derived> 583 bool RecursiveASTVisitor<Derived>::TraverseConceptExprRequirement( 584 concepts::ExprRequirement *R) { 585 if (!R->isExprSubstitutionFailure()) 586 TRY_TO(TraverseStmt(R->getExpr())); 587 auto &RetReq = R->getReturnTypeRequirement(); 588 if (RetReq.isTypeConstraint()) { 589 if (getDerived().shouldVisitImplicitCode()) { 590 TRY_TO(TraverseTemplateParameterListHelper( 591 RetReq.getTypeConstraintTemplateParameterList())); 592 } else { 593 // Template parameter list is implicit, visit constraint directly. 594 TRY_TO(TraverseTypeConstraint(RetReq.getTypeConstraint())); 595 } 596 } 597 return true; 598 } 599 600 template <typename Derived> 601 bool RecursiveASTVisitor<Derived>::TraverseConceptNestedRequirement( 602 concepts::NestedRequirement *R) { 603 if (!R->hasInvalidConstraint()) 604 return getDerived().TraverseStmt(R->getConstraintExpr()); 605 return true; 606 } 607 608 template <typename Derived> 609 bool RecursiveASTVisitor<Derived>::PostVisitStmt(Stmt *S) { 610 // In pre-order traversal mode, each Traverse##STMT method is responsible for 611 // calling WalkUpFrom. Therefore, if the user overrides Traverse##STMT and 612 // does not call the default implementation, the WalkUpFrom callback is not 613 // called. Post-order traversal mode should provide the same behavior 614 // regarding method overrides. 615 // 616 // In post-order traversal mode the Traverse##STMT method, when it receives a 617 // DataRecursionQueue, can't call WalkUpFrom after traversing children because 618 // it only enqueues the children and does not traverse them. TraverseStmt 619 // traverses the enqueued children, and we call WalkUpFrom here. 620 // 621 // However, to make pre-order and post-order modes identical with regards to 622 // whether they call WalkUpFrom at all, we call WalkUpFrom if and only if the 623 // user did not override the Traverse##STMT method. We implement the override 624 // check with isSameMethod calls below. 625 626 switch (S->getStmtClass()) { 627 case Stmt::NoStmtClass: 628 break; 629 #define ABSTRACT_STMT(STMT) 630 #define STMT(CLASS, PARENT) \ 631 case Stmt::CLASS##Class: \ 632 if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS, \ 633 &Derived::Traverse##CLASS)) { \ 634 TRY_TO(WalkUpFrom##CLASS(static_cast<CLASS *>(S))); \ 635 } \ 636 break; 637 #define INITLISTEXPR(CLASS, PARENT) \ 638 case Stmt::CLASS##Class: \ 639 if (::clang::detail::isSameMethod(&RecursiveASTVisitor::Traverse##CLASS, \ 640 &Derived::Traverse##CLASS)) { \ 641 auto ILE = static_cast<CLASS *>(S); \ 642 if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE) \ 643 TRY_TO(WalkUpFrom##CLASS(Syn)); \ 644 if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \ 645 TRY_TO(WalkUpFrom##CLASS(Sem)); \ 646 } \ 647 break; 648 #include "clang/AST/StmtNodes.inc" 649 } 650 651 return true; 652 } 653 654 #undef DISPATCH_STMT 655 656 template <typename Derived> 657 bool RecursiveASTVisitor<Derived>::TraverseStmt(Stmt *S, 658 DataRecursionQueue *Queue) { 659 if (!S) 660 return true; 661 662 if (Queue) { 663 Queue->push_back({S, false}); 664 return true; 665 } 666 667 SmallVector<llvm::PointerIntPair<Stmt *, 1, bool>, 8> LocalQueue; 668 LocalQueue.push_back({S, false}); 669 670 while (!LocalQueue.empty()) { 671 auto &CurrSAndVisited = LocalQueue.back(); 672 Stmt *CurrS = CurrSAndVisited.getPointer(); 673 bool Visited = CurrSAndVisited.getInt(); 674 if (Visited) { 675 LocalQueue.pop_back(); 676 TRY_TO(dataTraverseStmtPost(CurrS)); 677 if (getDerived().shouldTraversePostOrder()) { 678 TRY_TO(PostVisitStmt(CurrS)); 679 } 680 continue; 681 } 682 683 if (getDerived().dataTraverseStmtPre(CurrS)) { 684 CurrSAndVisited.setInt(true); 685 size_t N = LocalQueue.size(); 686 TRY_TO(dataTraverseNode(CurrS, &LocalQueue)); 687 // Process new children in the order they were added. 688 std::reverse(LocalQueue.begin() + N, LocalQueue.end()); 689 } else { 690 LocalQueue.pop_back(); 691 } 692 } 693 694 return true; 695 } 696 697 template <typename Derived> 698 bool RecursiveASTVisitor<Derived>::TraverseType(QualType T) { 699 if (T.isNull()) 700 return true; 701 702 switch (T->getTypeClass()) { 703 #define ABSTRACT_TYPE(CLASS, BASE) 704 #define TYPE(CLASS, BASE) \ 705 case Type::CLASS: \ 706 return getDerived().Traverse##CLASS##Type( \ 707 static_cast<CLASS##Type *>(const_cast<Type *>(T.getTypePtr()))); 708 #include "clang/AST/TypeNodes.inc" 709 } 710 711 return true; 712 } 713 714 template <typename Derived> 715 bool RecursiveASTVisitor<Derived>::TraverseTypeLoc(TypeLoc TL) { 716 if (TL.isNull()) 717 return true; 718 719 switch (TL.getTypeLocClass()) { 720 #define ABSTRACT_TYPELOC(CLASS, BASE) 721 #define TYPELOC(CLASS, BASE) \ 722 case TypeLoc::CLASS: \ 723 return getDerived().Traverse##CLASS##TypeLoc(TL.castAs<CLASS##TypeLoc>()); 724 #include "clang/AST/TypeLocNodes.def" 725 } 726 727 return true; 728 } 729 730 // Define the Traverse*Attr(Attr* A) methods 731 #define VISITORCLASS RecursiveASTVisitor 732 #include "clang/AST/AttrVisitor.inc" 733 #undef VISITORCLASS 734 735 template <typename Derived> 736 bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) { 737 if (!D) 738 return true; 739 740 // As a syntax visitor, by default we want to ignore declarations for 741 // implicit declarations (ones not typed explicitly by the user). 742 if (!getDerived().shouldVisitImplicitCode() && D->isImplicit()) { 743 // For an implicit template type parameter, its type constraints are not 744 // implicit and are not represented anywhere else. We still need to visit 745 // them. 746 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(D)) 747 return TraverseTemplateTypeParamDeclConstraints(TTPD); 748 return true; 749 } 750 751 switch (D->getKind()) { 752 #define ABSTRACT_DECL(DECL) 753 #define DECL(CLASS, BASE) \ 754 case Decl::CLASS: \ 755 if (!getDerived().Traverse##CLASS##Decl(static_cast<CLASS##Decl *>(D))) \ 756 return false; \ 757 break; 758 #include "clang/AST/DeclNodes.inc" 759 } 760 return true; 761 } 762 763 template <typename Derived> 764 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifier( 765 NestedNameSpecifier *NNS) { 766 if (!NNS) 767 return true; 768 769 if (NNS->getPrefix()) 770 TRY_TO(TraverseNestedNameSpecifier(NNS->getPrefix())); 771 772 switch (NNS->getKind()) { 773 case NestedNameSpecifier::Identifier: 774 case NestedNameSpecifier::Namespace: 775 case NestedNameSpecifier::NamespaceAlias: 776 case NestedNameSpecifier::Global: 777 case NestedNameSpecifier::Super: 778 return true; 779 780 case NestedNameSpecifier::TypeSpec: 781 case NestedNameSpecifier::TypeSpecWithTemplate: 782 TRY_TO(TraverseType(QualType(NNS->getAsType(), 0))); 783 } 784 785 return true; 786 } 787 788 template <typename Derived> 789 bool RecursiveASTVisitor<Derived>::TraverseNestedNameSpecifierLoc( 790 NestedNameSpecifierLoc NNS) { 791 if (!NNS) 792 return true; 793 794 if (NestedNameSpecifierLoc Prefix = NNS.getPrefix()) 795 TRY_TO(TraverseNestedNameSpecifierLoc(Prefix)); 796 797 switch (NNS.getNestedNameSpecifier()->getKind()) { 798 case NestedNameSpecifier::Identifier: 799 case NestedNameSpecifier::Namespace: 800 case NestedNameSpecifier::NamespaceAlias: 801 case NestedNameSpecifier::Global: 802 case NestedNameSpecifier::Super: 803 return true; 804 805 case NestedNameSpecifier::TypeSpec: 806 case NestedNameSpecifier::TypeSpecWithTemplate: 807 TRY_TO(TraverseTypeLoc(NNS.getTypeLoc())); 808 break; 809 } 810 811 return true; 812 } 813 814 template <typename Derived> 815 bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo( 816 DeclarationNameInfo NameInfo) { 817 switch (NameInfo.getName().getNameKind()) { 818 case DeclarationName::CXXConstructorName: 819 case DeclarationName::CXXDestructorName: 820 case DeclarationName::CXXConversionFunctionName: 821 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo()) 822 TRY_TO(TraverseTypeLoc(TSInfo->getTypeLoc())); 823 break; 824 825 case DeclarationName::CXXDeductionGuideName: 826 TRY_TO(TraverseTemplateName( 827 TemplateName(NameInfo.getName().getCXXDeductionGuideTemplate()))); 828 break; 829 830 case DeclarationName::Identifier: 831 case DeclarationName::ObjCZeroArgSelector: 832 case DeclarationName::ObjCOneArgSelector: 833 case DeclarationName::ObjCMultiArgSelector: 834 case DeclarationName::CXXOperatorName: 835 case DeclarationName::CXXLiteralOperatorName: 836 case DeclarationName::CXXUsingDirective: 837 break; 838 } 839 840 return true; 841 } 842 843 template <typename Derived> 844 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) { 845 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) 846 TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier())); 847 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 848 TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier())); 849 850 return true; 851 } 852 853 template <typename Derived> 854 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument( 855 const TemplateArgument &Arg) { 856 switch (Arg.getKind()) { 857 case TemplateArgument::Null: 858 case TemplateArgument::Declaration: 859 case TemplateArgument::Integral: 860 case TemplateArgument::NullPtr: 861 return true; 862 863 case TemplateArgument::Type: 864 return getDerived().TraverseType(Arg.getAsType()); 865 866 case TemplateArgument::Template: 867 case TemplateArgument::TemplateExpansion: 868 return getDerived().TraverseTemplateName( 869 Arg.getAsTemplateOrTemplatePattern()); 870 871 case TemplateArgument::Expression: 872 return getDerived().TraverseStmt(Arg.getAsExpr()); 873 874 case TemplateArgument::Pack: 875 return getDerived().TraverseTemplateArguments(Arg.pack_elements()); 876 } 877 878 return true; 879 } 880 881 // FIXME: no template name location? 882 // FIXME: no source locations for a template argument pack? 883 template <typename Derived> 884 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc( 885 const TemplateArgumentLoc &ArgLoc) { 886 const TemplateArgument &Arg = ArgLoc.getArgument(); 887 888 switch (Arg.getKind()) { 889 case TemplateArgument::Null: 890 case TemplateArgument::Declaration: 891 case TemplateArgument::Integral: 892 case TemplateArgument::NullPtr: 893 return true; 894 895 case TemplateArgument::Type: { 896 // FIXME: how can TSI ever be NULL? 897 if (TypeSourceInfo *TSI = ArgLoc.getTypeSourceInfo()) 898 return getDerived().TraverseTypeLoc(TSI->getTypeLoc()); 899 else 900 return getDerived().TraverseType(Arg.getAsType()); 901 } 902 903 case TemplateArgument::Template: 904 case TemplateArgument::TemplateExpansion: 905 if (ArgLoc.getTemplateQualifierLoc()) 906 TRY_TO(getDerived().TraverseNestedNameSpecifierLoc( 907 ArgLoc.getTemplateQualifierLoc())); 908 return getDerived().TraverseTemplateName( 909 Arg.getAsTemplateOrTemplatePattern()); 910 911 case TemplateArgument::Expression: 912 return getDerived().TraverseStmt(ArgLoc.getSourceExpression()); 913 914 case TemplateArgument::Pack: 915 return getDerived().TraverseTemplateArguments(Arg.pack_elements()); 916 } 917 918 return true; 919 } 920 921 template <typename Derived> 922 bool RecursiveASTVisitor<Derived>::TraverseTemplateArguments( 923 ArrayRef<TemplateArgument> Args) { 924 for (const TemplateArgument &Arg : Args) 925 TRY_TO(TraverseTemplateArgument(Arg)); 926 927 return true; 928 } 929 930 template <typename Derived> 931 bool RecursiveASTVisitor<Derived>::TraverseConstructorInitializer( 932 CXXCtorInitializer *Init) { 933 if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo()) 934 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); 935 936 if (Init->isWritten() || getDerived().shouldVisitImplicitCode()) 937 TRY_TO(TraverseStmt(Init->getInit())); 938 939 return true; 940 } 941 942 template <typename Derived> 943 bool 944 RecursiveASTVisitor<Derived>::TraverseLambdaCapture(LambdaExpr *LE, 945 const LambdaCapture *C, 946 Expr *Init) { 947 if (LE->isInitCapture(C)) 948 TRY_TO(TraverseDecl(C->getCapturedVar())); 949 else 950 TRY_TO(TraverseStmt(Init)); 951 return true; 952 } 953 954 // ----------------- Type traversal ----------------- 955 956 // This macro makes available a variable T, the passed-in type. 957 #define DEF_TRAVERSE_TYPE(TYPE, CODE) \ 958 template <typename Derived> \ 959 bool RecursiveASTVisitor<Derived>::Traverse##TYPE(TYPE *T) { \ 960 if (!getDerived().shouldTraversePostOrder()) \ 961 TRY_TO(WalkUpFrom##TYPE(T)); \ 962 { CODE; } \ 963 if (getDerived().shouldTraversePostOrder()) \ 964 TRY_TO(WalkUpFrom##TYPE(T)); \ 965 return true; \ 966 } 967 968 DEF_TRAVERSE_TYPE(BuiltinType, {}) 969 970 DEF_TRAVERSE_TYPE(ComplexType, { TRY_TO(TraverseType(T->getElementType())); }) 971 972 DEF_TRAVERSE_TYPE(PointerType, { TRY_TO(TraverseType(T->getPointeeType())); }) 973 974 DEF_TRAVERSE_TYPE(BlockPointerType, 975 { TRY_TO(TraverseType(T->getPointeeType())); }) 976 977 DEF_TRAVERSE_TYPE(LValueReferenceType, 978 { TRY_TO(TraverseType(T->getPointeeType())); }) 979 980 DEF_TRAVERSE_TYPE(RValueReferenceType, 981 { TRY_TO(TraverseType(T->getPointeeType())); }) 982 983 DEF_TRAVERSE_TYPE(MemberPointerType, { 984 TRY_TO(TraverseType(QualType(T->getClass(), 0))); 985 TRY_TO(TraverseType(T->getPointeeType())); 986 }) 987 988 DEF_TRAVERSE_TYPE(AdjustedType, { TRY_TO(TraverseType(T->getOriginalType())); }) 989 990 DEF_TRAVERSE_TYPE(DecayedType, { TRY_TO(TraverseType(T->getOriginalType())); }) 991 992 DEF_TRAVERSE_TYPE(ConstantArrayType, { 993 TRY_TO(TraverseType(T->getElementType())); 994 if (T->getSizeExpr()) 995 TRY_TO(TraverseStmt(const_cast<Expr*>(T->getSizeExpr()))); 996 }) 997 998 DEF_TRAVERSE_TYPE(IncompleteArrayType, 999 { TRY_TO(TraverseType(T->getElementType())); }) 1000 1001 DEF_TRAVERSE_TYPE(VariableArrayType, { 1002 TRY_TO(TraverseType(T->getElementType())); 1003 TRY_TO(TraverseStmt(T->getSizeExpr())); 1004 }) 1005 1006 DEF_TRAVERSE_TYPE(DependentSizedArrayType, { 1007 TRY_TO(TraverseType(T->getElementType())); 1008 if (T->getSizeExpr()) 1009 TRY_TO(TraverseStmt(T->getSizeExpr())); 1010 }) 1011 1012 DEF_TRAVERSE_TYPE(DependentAddressSpaceType, { 1013 TRY_TO(TraverseStmt(T->getAddrSpaceExpr())); 1014 TRY_TO(TraverseType(T->getPointeeType())); 1015 }) 1016 1017 DEF_TRAVERSE_TYPE(DependentVectorType, { 1018 if (T->getSizeExpr()) 1019 TRY_TO(TraverseStmt(T->getSizeExpr())); 1020 TRY_TO(TraverseType(T->getElementType())); 1021 }) 1022 1023 DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, { 1024 if (T->getSizeExpr()) 1025 TRY_TO(TraverseStmt(T->getSizeExpr())); 1026 TRY_TO(TraverseType(T->getElementType())); 1027 }) 1028 1029 DEF_TRAVERSE_TYPE(VectorType, { TRY_TO(TraverseType(T->getElementType())); }) 1030 1031 DEF_TRAVERSE_TYPE(ExtVectorType, { TRY_TO(TraverseType(T->getElementType())); }) 1032 1033 DEF_TRAVERSE_TYPE(ConstantMatrixType, 1034 { TRY_TO(TraverseType(T->getElementType())); }) 1035 1036 DEF_TRAVERSE_TYPE(DependentSizedMatrixType, { 1037 if (T->getRowExpr()) 1038 TRY_TO(TraverseStmt(T->getRowExpr())); 1039 if (T->getColumnExpr()) 1040 TRY_TO(TraverseStmt(T->getColumnExpr())); 1041 TRY_TO(TraverseType(T->getElementType())); 1042 }) 1043 1044 DEF_TRAVERSE_TYPE(FunctionNoProtoType, 1045 { TRY_TO(TraverseType(T->getReturnType())); }) 1046 1047 DEF_TRAVERSE_TYPE(FunctionProtoType, { 1048 TRY_TO(TraverseType(T->getReturnType())); 1049 1050 for (const auto &A : T->param_types()) { 1051 TRY_TO(TraverseType(A)); 1052 } 1053 1054 for (const auto &E : T->exceptions()) { 1055 TRY_TO(TraverseType(E)); 1056 } 1057 1058 if (Expr *NE = T->getNoexceptExpr()) 1059 TRY_TO(TraverseStmt(NE)); 1060 }) 1061 1062 DEF_TRAVERSE_TYPE(UsingType, {}) 1063 DEF_TRAVERSE_TYPE(UnresolvedUsingType, {}) 1064 DEF_TRAVERSE_TYPE(TypedefType, {}) 1065 1066 DEF_TRAVERSE_TYPE(TypeOfExprType, 1067 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); }) 1068 1069 DEF_TRAVERSE_TYPE(TypeOfType, { TRY_TO(TraverseType(T->getUnmodifiedType())); }) 1070 1071 DEF_TRAVERSE_TYPE(DecltypeType, 1072 { TRY_TO(TraverseStmt(T->getUnderlyingExpr())); }) 1073 1074 DEF_TRAVERSE_TYPE(UnaryTransformType, { 1075 TRY_TO(TraverseType(T->getBaseType())); 1076 TRY_TO(TraverseType(T->getUnderlyingType())); 1077 }) 1078 1079 DEF_TRAVERSE_TYPE(AutoType, { 1080 TRY_TO(TraverseType(T->getDeducedType())); 1081 if (T->isConstrained()) { 1082 TRY_TO(TraverseTemplateArguments(T->getTypeConstraintArguments())); 1083 } 1084 }) 1085 DEF_TRAVERSE_TYPE(DeducedTemplateSpecializationType, { 1086 TRY_TO(TraverseTemplateName(T->getTemplateName())); 1087 TRY_TO(TraverseType(T->getDeducedType())); 1088 }) 1089 1090 DEF_TRAVERSE_TYPE(RecordType, {}) 1091 DEF_TRAVERSE_TYPE(EnumType, {}) 1092 DEF_TRAVERSE_TYPE(TemplateTypeParmType, {}) 1093 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmType, { 1094 TRY_TO(TraverseType(T->getReplacementType())); 1095 }) 1096 DEF_TRAVERSE_TYPE(SubstTemplateTypeParmPackType, { 1097 TRY_TO(TraverseTemplateArgument(T->getArgumentPack())); 1098 }) 1099 1100 DEF_TRAVERSE_TYPE(TemplateSpecializationType, { 1101 TRY_TO(TraverseTemplateName(T->getTemplateName())); 1102 TRY_TO(TraverseTemplateArguments(T->template_arguments())); 1103 }) 1104 1105 DEF_TRAVERSE_TYPE(InjectedClassNameType, {}) 1106 1107 DEF_TRAVERSE_TYPE(AttributedType, 1108 { TRY_TO(TraverseType(T->getModifiedType())); }) 1109 1110 DEF_TRAVERSE_TYPE(BTFTagAttributedType, 1111 { TRY_TO(TraverseType(T->getWrappedType())); }) 1112 1113 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); }) 1114 1115 DEF_TRAVERSE_TYPE(MacroQualifiedType, 1116 { TRY_TO(TraverseType(T->getUnderlyingType())); }) 1117 1118 DEF_TRAVERSE_TYPE(ElaboratedType, { 1119 if (T->getQualifier()) { 1120 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); 1121 } 1122 TRY_TO(TraverseType(T->getNamedType())); 1123 }) 1124 1125 DEF_TRAVERSE_TYPE(DependentNameType, 1126 { TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); }) 1127 1128 DEF_TRAVERSE_TYPE(DependentTemplateSpecializationType, { 1129 TRY_TO(TraverseNestedNameSpecifier(T->getQualifier())); 1130 TRY_TO(TraverseTemplateArguments(T->template_arguments())); 1131 }) 1132 1133 DEF_TRAVERSE_TYPE(PackExpansionType, { TRY_TO(TraverseType(T->getPattern())); }) 1134 1135 DEF_TRAVERSE_TYPE(ObjCTypeParamType, {}) 1136 1137 DEF_TRAVERSE_TYPE(ObjCInterfaceType, {}) 1138 1139 DEF_TRAVERSE_TYPE(ObjCObjectType, { 1140 // We have to watch out here because an ObjCInterfaceType's base 1141 // type is itself. 1142 if (T->getBaseType().getTypePtr() != T) 1143 TRY_TO(TraverseType(T->getBaseType())); 1144 for (auto typeArg : T->getTypeArgsAsWritten()) { 1145 TRY_TO(TraverseType(typeArg)); 1146 } 1147 }) 1148 1149 DEF_TRAVERSE_TYPE(ObjCObjectPointerType, 1150 { TRY_TO(TraverseType(T->getPointeeType())); }) 1151 1152 DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); }) 1153 1154 DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); }) 1155 1156 DEF_TRAVERSE_TYPE(BitIntType, {}) 1157 DEF_TRAVERSE_TYPE(DependentBitIntType, 1158 { TRY_TO(TraverseStmt(T->getNumBitsExpr())); }) 1159 1160 #undef DEF_TRAVERSE_TYPE 1161 1162 // ----------------- TypeLoc traversal ----------------- 1163 1164 // This macro makes available a variable TL, the passed-in TypeLoc. 1165 // If requested, it calls WalkUpFrom* for the Type in the given TypeLoc, 1166 // in addition to WalkUpFrom* for the TypeLoc itself, such that existing 1167 // clients that override the WalkUpFrom*Type() and/or Visit*Type() methods 1168 // continue to work. 1169 #define DEF_TRAVERSE_TYPELOC(TYPE, CODE) \ 1170 template <typename Derived> \ 1171 bool RecursiveASTVisitor<Derived>::Traverse##TYPE##Loc(TYPE##Loc TL) { \ 1172 if (!getDerived().shouldTraversePostOrder()) { \ 1173 TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \ 1174 if (getDerived().shouldWalkTypesOfTypeLocs()) \ 1175 TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \ 1176 } \ 1177 { CODE; } \ 1178 if (getDerived().shouldTraversePostOrder()) { \ 1179 TRY_TO(WalkUpFrom##TYPE##Loc(TL)); \ 1180 if (getDerived().shouldWalkTypesOfTypeLocs()) \ 1181 TRY_TO(WalkUpFrom##TYPE(const_cast<TYPE *>(TL.getTypePtr()))); \ 1182 } \ 1183 return true; \ 1184 } 1185 1186 template <typename Derived> 1187 bool 1188 RecursiveASTVisitor<Derived>::TraverseQualifiedTypeLoc(QualifiedTypeLoc TL) { 1189 // Move this over to the 'main' typeloc tree. Note that this is a 1190 // move -- we pretend that we were really looking at the unqualified 1191 // typeloc all along -- rather than a recursion, so we don't follow 1192 // the normal CRTP plan of going through 1193 // getDerived().TraverseTypeLoc. If we did, we'd be traversing 1194 // twice for the same type (once as a QualifiedTypeLoc version of 1195 // the type, once as an UnqualifiedTypeLoc version of the type), 1196 // which in effect means we'd call VisitTypeLoc twice with the 1197 // 'same' type. This solves that problem, at the cost of never 1198 // seeing the qualified version of the type (unless the client 1199 // subclasses TraverseQualifiedTypeLoc themselves). It's not a 1200 // perfect solution. A perfect solution probably requires making 1201 // QualifiedTypeLoc a wrapper around TypeLoc -- like QualType is a 1202 // wrapper around Type* -- rather than being its own class in the 1203 // type hierarchy. 1204 return TraverseTypeLoc(TL.getUnqualifiedLoc()); 1205 } 1206 1207 DEF_TRAVERSE_TYPELOC(BuiltinType, {}) 1208 1209 // FIXME: ComplexTypeLoc is unfinished 1210 DEF_TRAVERSE_TYPELOC(ComplexType, { 1211 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 1212 }) 1213 1214 DEF_TRAVERSE_TYPELOC(PointerType, 1215 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) 1216 1217 DEF_TRAVERSE_TYPELOC(BlockPointerType, 1218 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) 1219 1220 DEF_TRAVERSE_TYPELOC(LValueReferenceType, 1221 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) 1222 1223 DEF_TRAVERSE_TYPELOC(RValueReferenceType, 1224 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) 1225 1226 // We traverse this in the type case as well, but how is it not reached through 1227 // the pointee type? 1228 DEF_TRAVERSE_TYPELOC(MemberPointerType, { 1229 if (auto *TSI = TL.getClassTInfo()) 1230 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); 1231 else 1232 TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0))); 1233 TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); 1234 }) 1235 1236 DEF_TRAVERSE_TYPELOC(AdjustedType, 1237 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); }) 1238 1239 DEF_TRAVERSE_TYPELOC(DecayedType, 1240 { TRY_TO(TraverseTypeLoc(TL.getOriginalLoc())); }) 1241 1242 template <typename Derived> 1243 bool RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) { 1244 // This isn't available for ArrayType, but is for the ArrayTypeLoc. 1245 TRY_TO(TraverseStmt(TL.getSizeExpr())); 1246 return true; 1247 } 1248 1249 DEF_TRAVERSE_TYPELOC(ConstantArrayType, { 1250 TRY_TO(TraverseTypeLoc(TL.getElementLoc())); 1251 TRY_TO(TraverseArrayTypeLocHelper(TL)); 1252 }) 1253 1254 DEF_TRAVERSE_TYPELOC(IncompleteArrayType, { 1255 TRY_TO(TraverseTypeLoc(TL.getElementLoc())); 1256 TRY_TO(TraverseArrayTypeLocHelper(TL)); 1257 }) 1258 1259 DEF_TRAVERSE_TYPELOC(VariableArrayType, { 1260 TRY_TO(TraverseTypeLoc(TL.getElementLoc())); 1261 TRY_TO(TraverseArrayTypeLocHelper(TL)); 1262 }) 1263 1264 DEF_TRAVERSE_TYPELOC(DependentSizedArrayType, { 1265 TRY_TO(TraverseTypeLoc(TL.getElementLoc())); 1266 TRY_TO(TraverseArrayTypeLocHelper(TL)); 1267 }) 1268 1269 DEF_TRAVERSE_TYPELOC(DependentAddressSpaceType, { 1270 TRY_TO(TraverseStmt(TL.getTypePtr()->getAddrSpaceExpr())); 1271 TRY_TO(TraverseType(TL.getTypePtr()->getPointeeType())); 1272 }) 1273 1274 // FIXME: order? why not size expr first? 1275 // FIXME: base VectorTypeLoc is unfinished 1276 DEF_TRAVERSE_TYPELOC(DependentSizedExtVectorType, { 1277 if (TL.getTypePtr()->getSizeExpr()) 1278 TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr())); 1279 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 1280 }) 1281 1282 // FIXME: VectorTypeLoc is unfinished 1283 DEF_TRAVERSE_TYPELOC(VectorType, { 1284 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 1285 }) 1286 1287 DEF_TRAVERSE_TYPELOC(DependentVectorType, { 1288 if (TL.getTypePtr()->getSizeExpr()) 1289 TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr())); 1290 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 1291 }) 1292 1293 // FIXME: size and attributes 1294 // FIXME: base VectorTypeLoc is unfinished 1295 DEF_TRAVERSE_TYPELOC(ExtVectorType, { 1296 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 1297 }) 1298 1299 DEF_TRAVERSE_TYPELOC(ConstantMatrixType, { 1300 TRY_TO(TraverseStmt(TL.getAttrRowOperand())); 1301 TRY_TO(TraverseStmt(TL.getAttrColumnOperand())); 1302 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 1303 }) 1304 1305 DEF_TRAVERSE_TYPELOC(DependentSizedMatrixType, { 1306 TRY_TO(TraverseStmt(TL.getAttrRowOperand())); 1307 TRY_TO(TraverseStmt(TL.getAttrColumnOperand())); 1308 TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); 1309 }) 1310 1311 DEF_TRAVERSE_TYPELOC(FunctionNoProtoType, 1312 { TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); }) 1313 1314 // FIXME: location of exception specifications (attributes?) 1315 DEF_TRAVERSE_TYPELOC(FunctionProtoType, { 1316 TRY_TO(TraverseTypeLoc(TL.getReturnLoc())); 1317 1318 const FunctionProtoType *T = TL.getTypePtr(); 1319 1320 for (unsigned I = 0, E = TL.getNumParams(); I != E; ++I) { 1321 if (TL.getParam(I)) { 1322 TRY_TO(TraverseDecl(TL.getParam(I))); 1323 } else if (I < T->getNumParams()) { 1324 TRY_TO(TraverseType(T->getParamType(I))); 1325 } 1326 } 1327 1328 for (const auto &E : T->exceptions()) { 1329 TRY_TO(TraverseType(E)); 1330 } 1331 1332 if (Expr *NE = T->getNoexceptExpr()) 1333 TRY_TO(TraverseStmt(NE)); 1334 }) 1335 1336 DEF_TRAVERSE_TYPELOC(UsingType, {}) 1337 DEF_TRAVERSE_TYPELOC(UnresolvedUsingType, {}) 1338 DEF_TRAVERSE_TYPELOC(TypedefType, {}) 1339 1340 DEF_TRAVERSE_TYPELOC(TypeOfExprType, 1341 { TRY_TO(TraverseStmt(TL.getUnderlyingExpr())); }) 1342 1343 DEF_TRAVERSE_TYPELOC(TypeOfType, { 1344 TRY_TO(TraverseTypeLoc(TL.getUnmodifiedTInfo()->getTypeLoc())); 1345 }) 1346 1347 // FIXME: location of underlying expr 1348 DEF_TRAVERSE_TYPELOC(DecltypeType, { 1349 TRY_TO(TraverseStmt(TL.getTypePtr()->getUnderlyingExpr())); 1350 }) 1351 1352 DEF_TRAVERSE_TYPELOC(UnaryTransformType, { 1353 TRY_TO(TraverseTypeLoc(TL.getUnderlyingTInfo()->getTypeLoc())); 1354 }) 1355 1356 DEF_TRAVERSE_TYPELOC(AutoType, { 1357 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType())); 1358 if (TL.isConstrained()) { 1359 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getNestedNameSpecifierLoc())); 1360 TRY_TO(TraverseDeclarationNameInfo(TL.getConceptNameInfo())); 1361 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) 1362 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); 1363 } 1364 }) 1365 1366 DEF_TRAVERSE_TYPELOC(DeducedTemplateSpecializationType, { 1367 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName())); 1368 TRY_TO(TraverseType(TL.getTypePtr()->getDeducedType())); 1369 }) 1370 1371 DEF_TRAVERSE_TYPELOC(RecordType, {}) 1372 DEF_TRAVERSE_TYPELOC(EnumType, {}) 1373 DEF_TRAVERSE_TYPELOC(TemplateTypeParmType, {}) 1374 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmType, { 1375 TRY_TO(TraverseType(TL.getTypePtr()->getReplacementType())); 1376 }) 1377 DEF_TRAVERSE_TYPELOC(SubstTemplateTypeParmPackType, { 1378 TRY_TO(TraverseTemplateArgument(TL.getTypePtr()->getArgumentPack())); 1379 }) 1380 1381 // FIXME: use the loc for the template name? 1382 DEF_TRAVERSE_TYPELOC(TemplateSpecializationType, { 1383 TRY_TO(TraverseTemplateName(TL.getTypePtr()->getTemplateName())); 1384 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { 1385 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); 1386 } 1387 }) 1388 1389 DEF_TRAVERSE_TYPELOC(InjectedClassNameType, {}) 1390 1391 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); }) 1392 1393 DEF_TRAVERSE_TYPELOC(MacroQualifiedType, 1394 { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); }) 1395 1396 DEF_TRAVERSE_TYPELOC(AttributedType, 1397 { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); }) 1398 1399 DEF_TRAVERSE_TYPELOC(BTFTagAttributedType, 1400 { TRY_TO(TraverseTypeLoc(TL.getWrappedLoc())); }) 1401 1402 DEF_TRAVERSE_TYPELOC(ElaboratedType, { 1403 if (TL.getQualifierLoc()) { 1404 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); 1405 } 1406 TRY_TO(TraverseTypeLoc(TL.getNamedTypeLoc())); 1407 }) 1408 1409 DEF_TRAVERSE_TYPELOC(DependentNameType, { 1410 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); 1411 }) 1412 1413 DEF_TRAVERSE_TYPELOC(DependentTemplateSpecializationType, { 1414 if (TL.getQualifierLoc()) { 1415 TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc())); 1416 } 1417 1418 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { 1419 TRY_TO(TraverseTemplateArgumentLoc(TL.getArgLoc(I))); 1420 } 1421 }) 1422 1423 DEF_TRAVERSE_TYPELOC(PackExpansionType, 1424 { TRY_TO(TraverseTypeLoc(TL.getPatternLoc())); }) 1425 1426 DEF_TRAVERSE_TYPELOC(ObjCTypeParamType, { 1427 for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) { 1428 ObjCProtocolLoc ProtocolLoc(TL.getProtocol(I), TL.getProtocolLoc(I)); 1429 TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc)); 1430 } 1431 }) 1432 1433 DEF_TRAVERSE_TYPELOC(ObjCInterfaceType, {}) 1434 1435 DEF_TRAVERSE_TYPELOC(ObjCObjectType, { 1436 // We have to watch out here because an ObjCInterfaceType's base 1437 // type is itself. 1438 if (TL.getTypePtr()->getBaseType().getTypePtr() != TL.getTypePtr()) 1439 TRY_TO(TraverseTypeLoc(TL.getBaseLoc())); 1440 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) 1441 TRY_TO(TraverseTypeLoc(TL.getTypeArgTInfo(i)->getTypeLoc())); 1442 for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) { 1443 ObjCProtocolLoc ProtocolLoc(TL.getProtocol(I), TL.getProtocolLoc(I)); 1444 TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc)); 1445 } 1446 }) 1447 1448 DEF_TRAVERSE_TYPELOC(ObjCObjectPointerType, 1449 { TRY_TO(TraverseTypeLoc(TL.getPointeeLoc())); }) 1450 1451 DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); }) 1452 1453 DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); }) 1454 1455 DEF_TRAVERSE_TYPELOC(BitIntType, {}) 1456 DEF_TRAVERSE_TYPELOC(DependentBitIntType, { 1457 TRY_TO(TraverseStmt(TL.getTypePtr()->getNumBitsExpr())); 1458 }) 1459 1460 #undef DEF_TRAVERSE_TYPELOC 1461 1462 // ----------------- Decl traversal ----------------- 1463 // 1464 // For a Decl, we automate (in the DEF_TRAVERSE_DECL macro) traversing 1465 // the children that come from the DeclContext associated with it. 1466 // Therefore each Traverse* only needs to worry about children other 1467 // than those. 1468 1469 template <typename Derived> 1470 bool RecursiveASTVisitor<Derived>::canIgnoreChildDeclWhileTraversingDeclContext( 1471 const Decl *Child) { 1472 // BlockDecls are traversed through BlockExprs, 1473 // CapturedDecls are traversed through CapturedStmts. 1474 if (isa<BlockDecl>(Child) || isa<CapturedDecl>(Child)) 1475 return true; 1476 // Lambda classes are traversed through LambdaExprs. 1477 if (const CXXRecordDecl* Cls = dyn_cast<CXXRecordDecl>(Child)) 1478 return Cls->isLambda(); 1479 return false; 1480 } 1481 1482 template <typename Derived> 1483 bool RecursiveASTVisitor<Derived>::TraverseDeclContextHelper(DeclContext *DC) { 1484 if (!DC) 1485 return true; 1486 1487 for (auto *Child : DC->decls()) { 1488 if (!canIgnoreChildDeclWhileTraversingDeclContext(Child)) 1489 TRY_TO(TraverseDecl(Child)); 1490 } 1491 1492 return true; 1493 } 1494 1495 // This macro makes available a variable D, the passed-in decl. 1496 #define DEF_TRAVERSE_DECL(DECL, CODE) \ 1497 template <typename Derived> \ 1498 bool RecursiveASTVisitor<Derived>::Traverse##DECL(DECL *D) { \ 1499 bool ShouldVisitChildren = true; \ 1500 bool ReturnValue = true; \ 1501 if (!getDerived().shouldTraversePostOrder()) \ 1502 TRY_TO(WalkUpFrom##DECL(D)); \ 1503 { CODE; } \ 1504 if (ReturnValue && ShouldVisitChildren) \ 1505 TRY_TO(TraverseDeclContextHelper(dyn_cast<DeclContext>(D))); \ 1506 if (ReturnValue) { \ 1507 /* Visit any attributes attached to this declaration. */ \ 1508 for (auto *I : D->attrs()) \ 1509 TRY_TO(getDerived().TraverseAttr(I)); \ 1510 } \ 1511 if (ReturnValue && getDerived().shouldTraversePostOrder()) \ 1512 TRY_TO(WalkUpFrom##DECL(D)); \ 1513 return ReturnValue; \ 1514 } 1515 1516 DEF_TRAVERSE_DECL(AccessSpecDecl, {}) 1517 1518 DEF_TRAVERSE_DECL(BlockDecl, { 1519 if (TypeSourceInfo *TInfo = D->getSignatureAsWritten()) 1520 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); 1521 TRY_TO(TraverseStmt(D->getBody())); 1522 for (const auto &I : D->captures()) { 1523 if (I.hasCopyExpr()) { 1524 TRY_TO(TraverseStmt(I.getCopyExpr())); 1525 } 1526 } 1527 ShouldVisitChildren = false; 1528 }) 1529 1530 DEF_TRAVERSE_DECL(CapturedDecl, { 1531 TRY_TO(TraverseStmt(D->getBody())); 1532 ShouldVisitChildren = false; 1533 }) 1534 1535 DEF_TRAVERSE_DECL(EmptyDecl, {}) 1536 1537 DEF_TRAVERSE_DECL(HLSLBufferDecl, {}) 1538 1539 DEF_TRAVERSE_DECL(LifetimeExtendedTemporaryDecl, { 1540 TRY_TO(TraverseStmt(D->getTemporaryExpr())); 1541 }) 1542 1543 DEF_TRAVERSE_DECL(FileScopeAsmDecl, 1544 { TRY_TO(TraverseStmt(D->getAsmString())); }) 1545 1546 DEF_TRAVERSE_DECL(TopLevelStmtDecl, { TRY_TO(TraverseStmt(D->getStmt())); }) 1547 1548 DEF_TRAVERSE_DECL(ImportDecl, {}) 1549 1550 DEF_TRAVERSE_DECL(FriendDecl, { 1551 // Friend is either decl or a type. 1552 if (D->getFriendType()) { 1553 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc())); 1554 // Traverse any CXXRecordDecl owned by this type, since 1555 // it will not be in the parent context: 1556 if (auto *ET = D->getFriendType()->getType()->getAs<ElaboratedType>()) 1557 TRY_TO(TraverseDecl(ET->getOwnedTagDecl())); 1558 } else { 1559 TRY_TO(TraverseDecl(D->getFriendDecl())); 1560 } 1561 }) 1562 1563 DEF_TRAVERSE_DECL(FriendTemplateDecl, { 1564 if (D->getFriendType()) 1565 TRY_TO(TraverseTypeLoc(D->getFriendType()->getTypeLoc())); 1566 else 1567 TRY_TO(TraverseDecl(D->getFriendDecl())); 1568 for (unsigned I = 0, E = D->getNumTemplateParameters(); I < E; ++I) { 1569 TemplateParameterList *TPL = D->getTemplateParameterList(I); 1570 for (TemplateParameterList::iterator ITPL = TPL->begin(), ETPL = TPL->end(); 1571 ITPL != ETPL; ++ITPL) { 1572 TRY_TO(TraverseDecl(*ITPL)); 1573 } 1574 } 1575 }) 1576 1577 DEF_TRAVERSE_DECL(ClassScopeFunctionSpecializationDecl, { 1578 TRY_TO(TraverseDecl(D->getSpecialization())); 1579 1580 if (D->hasExplicitTemplateArgs()) { 1581 TRY_TO(TraverseTemplateArgumentLocsHelper( 1582 D->getTemplateArgsAsWritten()->getTemplateArgs(), 1583 D->getTemplateArgsAsWritten()->NumTemplateArgs)); 1584 } 1585 }) 1586 1587 DEF_TRAVERSE_DECL(LinkageSpecDecl, {}) 1588 1589 DEF_TRAVERSE_DECL(ExportDecl, {}) 1590 1591 DEF_TRAVERSE_DECL(ObjCPropertyImplDecl, {// FIXME: implement this 1592 }) 1593 1594 DEF_TRAVERSE_DECL(StaticAssertDecl, { 1595 TRY_TO(TraverseStmt(D->getAssertExpr())); 1596 TRY_TO(TraverseStmt(D->getMessage())); 1597 }) 1598 1599 DEF_TRAVERSE_DECL(TranslationUnitDecl, { 1600 // Code in an unnamed namespace shows up automatically in 1601 // decls_begin()/decls_end(). Thus we don't need to recurse on 1602 // D->getAnonymousNamespace(). 1603 1604 // If the traversal scope is set, then consider them to be the children of 1605 // the TUDecl, rather than traversing (and loading?) all top-level decls. 1606 auto Scope = D->getASTContext().getTraversalScope(); 1607 bool HasLimitedScope = 1608 Scope.size() != 1 || !isa<TranslationUnitDecl>(Scope.front()); 1609 if (HasLimitedScope) { 1610 ShouldVisitChildren = false; // we'll do that here instead 1611 for (auto *Child : Scope) { 1612 if (!canIgnoreChildDeclWhileTraversingDeclContext(Child)) 1613 TRY_TO(TraverseDecl(Child)); 1614 } 1615 } 1616 }) 1617 1618 DEF_TRAVERSE_DECL(PragmaCommentDecl, {}) 1619 1620 DEF_TRAVERSE_DECL(PragmaDetectMismatchDecl, {}) 1621 1622 DEF_TRAVERSE_DECL(ExternCContextDecl, {}) 1623 1624 DEF_TRAVERSE_DECL(NamespaceAliasDecl, { 1625 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 1626 1627 // We shouldn't traverse an aliased namespace, since it will be 1628 // defined (and, therefore, traversed) somewhere else. 1629 ShouldVisitChildren = false; 1630 }) 1631 1632 DEF_TRAVERSE_DECL(LabelDecl, {// There is no code in a LabelDecl. 1633 }) 1634 1635 DEF_TRAVERSE_DECL( 1636 NamespaceDecl, 1637 {// Code in an unnamed namespace shows up automatically in 1638 // decls_begin()/decls_end(). Thus we don't need to recurse on 1639 // D->getAnonymousNamespace(). 1640 }) 1641 1642 DEF_TRAVERSE_DECL(ObjCCompatibleAliasDecl, {// FIXME: implement 1643 }) 1644 1645 DEF_TRAVERSE_DECL(ObjCCategoryDecl, { 1646 if (ObjCTypeParamList *typeParamList = D->getTypeParamList()) { 1647 for (auto typeParam : *typeParamList) { 1648 TRY_TO(TraverseObjCTypeParamDecl(typeParam)); 1649 } 1650 } 1651 for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) { 1652 ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It)); 1653 TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc)); 1654 } 1655 }) 1656 1657 DEF_TRAVERSE_DECL(ObjCCategoryImplDecl, {// FIXME: implement 1658 }) 1659 1660 DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement 1661 }) 1662 1663 DEF_TRAVERSE_DECL(ObjCInterfaceDecl, { 1664 if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) { 1665 for (auto typeParam : *typeParamList) { 1666 TRY_TO(TraverseObjCTypeParamDecl(typeParam)); 1667 } 1668 } 1669 1670 if (TypeSourceInfo *superTInfo = D->getSuperClassTInfo()) { 1671 TRY_TO(TraverseTypeLoc(superTInfo->getTypeLoc())); 1672 } 1673 if (D->isThisDeclarationADefinition()) { 1674 for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) { 1675 ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It)); 1676 TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc)); 1677 } 1678 } 1679 }) 1680 1681 DEF_TRAVERSE_DECL(ObjCProtocolDecl, { 1682 if (D->isThisDeclarationADefinition()) { 1683 for (auto It : llvm::zip(D->protocols(), D->protocol_locs())) { 1684 ObjCProtocolLoc ProtocolLoc(std::get<0>(It), std::get<1>(It)); 1685 TRY_TO(TraverseObjCProtocolLoc(ProtocolLoc)); 1686 } 1687 } 1688 }) 1689 1690 DEF_TRAVERSE_DECL(ObjCMethodDecl, { 1691 if (D->getReturnTypeSourceInfo()) { 1692 TRY_TO(TraverseTypeLoc(D->getReturnTypeSourceInfo()->getTypeLoc())); 1693 } 1694 for (ParmVarDecl *Parameter : D->parameters()) { 1695 TRY_TO(TraverseDecl(Parameter)); 1696 } 1697 if (D->isThisDeclarationADefinition()) { 1698 TRY_TO(TraverseStmt(D->getBody())); 1699 } 1700 ShouldVisitChildren = false; 1701 }) 1702 1703 DEF_TRAVERSE_DECL(ObjCTypeParamDecl, { 1704 if (D->hasExplicitBound()) { 1705 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 1706 // We shouldn't traverse D->getTypeForDecl(); it's a result of 1707 // declaring the type alias, not something that was written in the 1708 // source. 1709 } 1710 }) 1711 1712 DEF_TRAVERSE_DECL(ObjCPropertyDecl, { 1713 if (D->getTypeSourceInfo()) 1714 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 1715 else 1716 TRY_TO(TraverseType(D->getType())); 1717 ShouldVisitChildren = false; 1718 }) 1719 1720 DEF_TRAVERSE_DECL(UsingDecl, { 1721 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 1722 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); 1723 }) 1724 1725 DEF_TRAVERSE_DECL(UsingEnumDecl, 1726 { TRY_TO(TraverseTypeLoc(D->getEnumTypeLoc())); }) 1727 1728 DEF_TRAVERSE_DECL(UsingPackDecl, {}) 1729 1730 DEF_TRAVERSE_DECL(UsingDirectiveDecl, { 1731 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 1732 }) 1733 1734 DEF_TRAVERSE_DECL(UsingShadowDecl, {}) 1735 1736 DEF_TRAVERSE_DECL(ConstructorUsingShadowDecl, {}) 1737 1738 DEF_TRAVERSE_DECL(OMPThreadPrivateDecl, { 1739 for (auto *I : D->varlists()) { 1740 TRY_TO(TraverseStmt(I)); 1741 } 1742 }) 1743 1744 DEF_TRAVERSE_DECL(OMPRequiresDecl, { 1745 for (auto *C : D->clauselists()) { 1746 TRY_TO(TraverseOMPClause(C)); 1747 } 1748 }) 1749 1750 DEF_TRAVERSE_DECL(OMPDeclareReductionDecl, { 1751 TRY_TO(TraverseStmt(D->getCombiner())); 1752 if (auto *Initializer = D->getInitializer()) 1753 TRY_TO(TraverseStmt(Initializer)); 1754 TRY_TO(TraverseType(D->getType())); 1755 return true; 1756 }) 1757 1758 DEF_TRAVERSE_DECL(OMPDeclareMapperDecl, { 1759 for (auto *C : D->clauselists()) 1760 TRY_TO(TraverseOMPClause(C)); 1761 TRY_TO(TraverseType(D->getType())); 1762 return true; 1763 }) 1764 1765 DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); }) 1766 1767 DEF_TRAVERSE_DECL(OMPAllocateDecl, { 1768 for (auto *I : D->varlists()) 1769 TRY_TO(TraverseStmt(I)); 1770 for (auto *C : D->clauselists()) 1771 TRY_TO(TraverseOMPClause(C)); 1772 }) 1773 1774 // A helper method for TemplateDecl's children. 1775 template <typename Derived> 1776 bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper( 1777 TemplateParameterList *TPL) { 1778 if (TPL) { 1779 for (NamedDecl *D : *TPL) { 1780 TRY_TO(TraverseDecl(D)); 1781 } 1782 if (Expr *RequiresClause = TPL->getRequiresClause()) { 1783 TRY_TO(TraverseStmt(RequiresClause)); 1784 } 1785 } 1786 return true; 1787 } 1788 1789 template <typename Derived> 1790 template <typename T> 1791 bool RecursiveASTVisitor<Derived>::TraverseDeclTemplateParameterLists(T *D) { 1792 for (unsigned i = 0; i < D->getNumTemplateParameterLists(); i++) { 1793 TemplateParameterList *TPL = D->getTemplateParameterList(i); 1794 TraverseTemplateParameterListHelper(TPL); 1795 } 1796 return true; 1797 } 1798 1799 template <typename Derived> 1800 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations( 1801 ClassTemplateDecl *D) { 1802 for (auto *SD : D->specializations()) { 1803 for (auto *RD : SD->redecls()) { 1804 assert(!cast<CXXRecordDecl>(RD)->isInjectedClassName()); 1805 switch ( 1806 cast<ClassTemplateSpecializationDecl>(RD)->getSpecializationKind()) { 1807 // Visit the implicit instantiations with the requested pattern. 1808 case TSK_Undeclared: 1809 case TSK_ImplicitInstantiation: 1810 TRY_TO(TraverseDecl(RD)); 1811 break; 1812 1813 // We don't need to do anything on an explicit instantiation 1814 // or explicit specialization because there will be an explicit 1815 // node for it elsewhere. 1816 case TSK_ExplicitInstantiationDeclaration: 1817 case TSK_ExplicitInstantiationDefinition: 1818 case TSK_ExplicitSpecialization: 1819 break; 1820 } 1821 } 1822 } 1823 1824 return true; 1825 } 1826 1827 template <typename Derived> 1828 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations( 1829 VarTemplateDecl *D) { 1830 for (auto *SD : D->specializations()) { 1831 for (auto *RD : SD->redecls()) { 1832 switch ( 1833 cast<VarTemplateSpecializationDecl>(RD)->getSpecializationKind()) { 1834 case TSK_Undeclared: 1835 case TSK_ImplicitInstantiation: 1836 TRY_TO(TraverseDecl(RD)); 1837 break; 1838 1839 case TSK_ExplicitInstantiationDeclaration: 1840 case TSK_ExplicitInstantiationDefinition: 1841 case TSK_ExplicitSpecialization: 1842 break; 1843 } 1844 } 1845 } 1846 1847 return true; 1848 } 1849 1850 // A helper method for traversing the instantiations of a 1851 // function while skipping its specializations. 1852 template <typename Derived> 1853 bool RecursiveASTVisitor<Derived>::TraverseTemplateInstantiations( 1854 FunctionTemplateDecl *D) { 1855 for (auto *FD : D->specializations()) { 1856 for (auto *RD : FD->redecls()) { 1857 switch (RD->getTemplateSpecializationKind()) { 1858 case TSK_Undeclared: 1859 case TSK_ImplicitInstantiation: 1860 // We don't know what kind of FunctionDecl this is. 1861 TRY_TO(TraverseDecl(RD)); 1862 break; 1863 1864 // FIXME: For now traverse explicit instantiations here. Change that 1865 // once they are represented as dedicated nodes in the AST. 1866 case TSK_ExplicitInstantiationDeclaration: 1867 case TSK_ExplicitInstantiationDefinition: 1868 TRY_TO(TraverseDecl(RD)); 1869 break; 1870 1871 case TSK_ExplicitSpecialization: 1872 break; 1873 } 1874 } 1875 } 1876 1877 return true; 1878 } 1879 1880 // This macro unifies the traversal of class, variable and function 1881 // template declarations. 1882 #define DEF_TRAVERSE_TMPL_DECL(TMPLDECLKIND) \ 1883 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateDecl, { \ 1884 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); \ 1885 TRY_TO(TraverseDecl(D->getTemplatedDecl())); \ 1886 \ 1887 /* By default, we do not traverse the instantiations of \ 1888 class templates since they do not appear in the user code. The \ 1889 following code optionally traverses them. \ 1890 \ 1891 We only traverse the class instantiations when we see the canonical \ 1892 declaration of the template, to ensure we only visit them once. */ \ 1893 if (getDerived().shouldVisitTemplateInstantiations() && \ 1894 D == D->getCanonicalDecl()) \ 1895 TRY_TO(TraverseTemplateInstantiations(D)); \ 1896 \ 1897 /* Note that getInstantiatedFromMemberTemplate() is just a link \ 1898 from a template instantiation back to the template from which \ 1899 it was instantiated, and thus should not be traversed. */ \ 1900 }) 1901 1902 DEF_TRAVERSE_TMPL_DECL(Class) 1903 DEF_TRAVERSE_TMPL_DECL(Var) 1904 DEF_TRAVERSE_TMPL_DECL(Function) 1905 1906 DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, { 1907 // D is the "T" in something like 1908 // template <template <typename> class T> class container { }; 1909 TRY_TO(TraverseDecl(D->getTemplatedDecl())); 1910 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) 1911 TRY_TO(TraverseTemplateArgumentLoc(D->getDefaultArgument())); 1912 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); 1913 }) 1914 1915 DEF_TRAVERSE_DECL(BuiltinTemplateDecl, { 1916 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); 1917 }) 1918 1919 template <typename Derived> 1920 bool RecursiveASTVisitor<Derived>::TraverseTemplateTypeParamDeclConstraints( 1921 const TemplateTypeParmDecl *D) { 1922 if (const auto *TC = D->getTypeConstraint()) 1923 TRY_TO(TraverseTypeConstraint(TC)); 1924 return true; 1925 } 1926 1927 DEF_TRAVERSE_DECL(TemplateTypeParmDecl, { 1928 // D is the "T" in something like "template<typename T> class vector;" 1929 if (D->getTypeForDecl()) 1930 TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0))); 1931 TRY_TO(TraverseTemplateTypeParamDeclConstraints(D)); 1932 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) 1933 TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc())); 1934 }) 1935 1936 DEF_TRAVERSE_DECL(TypedefDecl, { 1937 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 1938 // We shouldn't traverse D->getTypeForDecl(); it's a result of 1939 // declaring the typedef, not something that was written in the 1940 // source. 1941 }) 1942 1943 DEF_TRAVERSE_DECL(TypeAliasDecl, { 1944 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 1945 // We shouldn't traverse D->getTypeForDecl(); it's a result of 1946 // declaring the type alias, not something that was written in the 1947 // source. 1948 }) 1949 1950 DEF_TRAVERSE_DECL(TypeAliasTemplateDecl, { 1951 TRY_TO(TraverseDecl(D->getTemplatedDecl())); 1952 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); 1953 }) 1954 1955 DEF_TRAVERSE_DECL(ConceptDecl, { 1956 TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); 1957 TRY_TO(TraverseStmt(D->getConstraintExpr())); 1958 }) 1959 1960 DEF_TRAVERSE_DECL(UnresolvedUsingTypenameDecl, { 1961 // A dependent using declaration which was marked with 'typename'. 1962 // template<class T> class A : public B<T> { using typename B<T>::foo; }; 1963 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 1964 // We shouldn't traverse D->getTypeForDecl(); it's a result of 1965 // declaring the type, not something that was written in the 1966 // source. 1967 }) 1968 1969 DEF_TRAVERSE_DECL(UnresolvedUsingIfExistsDecl, {}) 1970 1971 DEF_TRAVERSE_DECL(EnumDecl, { 1972 TRY_TO(TraverseDeclTemplateParameterLists(D)); 1973 1974 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 1975 if (auto *TSI = D->getIntegerTypeSourceInfo()) 1976 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); 1977 // The enumerators are already traversed by 1978 // decls_begin()/decls_end(). 1979 }) 1980 1981 // Helper methods for RecordDecl and its children. 1982 template <typename Derived> 1983 bool RecursiveASTVisitor<Derived>::TraverseRecordHelper(RecordDecl *D) { 1984 // We shouldn't traverse D->getTypeForDecl(); it's a result of 1985 // declaring the type, not something that was written in the source. 1986 1987 TRY_TO(TraverseDeclTemplateParameterLists(D)); 1988 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 1989 return true; 1990 } 1991 1992 template <typename Derived> 1993 bool RecursiveASTVisitor<Derived>::TraverseCXXBaseSpecifier( 1994 const CXXBaseSpecifier &Base) { 1995 TRY_TO(TraverseTypeLoc(Base.getTypeSourceInfo()->getTypeLoc())); 1996 return true; 1997 } 1998 1999 template <typename Derived> 2000 bool RecursiveASTVisitor<Derived>::TraverseCXXRecordHelper(CXXRecordDecl *D) { 2001 if (!TraverseRecordHelper(D)) 2002 return false; 2003 if (D->isCompleteDefinition()) { 2004 for (const auto &I : D->bases()) { 2005 TRY_TO(TraverseCXXBaseSpecifier(I)); 2006 } 2007 // We don't traverse the friends or the conversions, as they are 2008 // already in decls_begin()/decls_end(). 2009 } 2010 return true; 2011 } 2012 2013 DEF_TRAVERSE_DECL(RecordDecl, { TRY_TO(TraverseRecordHelper(D)); }) 2014 2015 DEF_TRAVERSE_DECL(CXXRecordDecl, { TRY_TO(TraverseCXXRecordHelper(D)); }) 2016 2017 #define DEF_TRAVERSE_TMPL_SPEC_DECL(TMPLDECLKIND, DECLKIND) \ 2018 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplateSpecializationDecl, { \ 2019 /* For implicit instantiations ("set<int> x;"), we don't want to \ 2020 recurse at all, since the instatiated template isn't written in \ 2021 the source code anywhere. (Note the instatiated *type* -- \ 2022 set<int> -- is written, and will still get a callback of \ 2023 TemplateSpecializationType). For explicit instantiations \ 2024 ("template set<int>;"), we do need a callback, since this \ 2025 is the only callback that's made for this instantiation. \ 2026 We use getTypeAsWritten() to distinguish. */ \ 2027 if (TypeSourceInfo *TSI = D->getTypeAsWritten()) \ 2028 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); \ 2029 \ 2030 if (getDerived().shouldVisitTemplateInstantiations() || \ 2031 D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) { \ 2032 /* Traverse base definition for explicit specializations */ \ 2033 TRY_TO(Traverse##DECLKIND##Helper(D)); \ 2034 } else { \ 2035 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); \ 2036 \ 2037 /* Returning from here skips traversing the \ 2038 declaration context of the *TemplateSpecializationDecl \ 2039 (embedded in the DEF_TRAVERSE_DECL() macro) \ 2040 which contains the instantiated members of the template. */ \ 2041 return true; \ 2042 } \ 2043 }) 2044 2045 DEF_TRAVERSE_TMPL_SPEC_DECL(Class, CXXRecord) 2046 DEF_TRAVERSE_TMPL_SPEC_DECL(Var, Var) 2047 2048 template <typename Derived> 2049 bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLocsHelper( 2050 const TemplateArgumentLoc *TAL, unsigned Count) { 2051 for (unsigned I = 0; I < Count; ++I) { 2052 TRY_TO(TraverseTemplateArgumentLoc(TAL[I])); 2053 } 2054 return true; 2055 } 2056 2057 #define DEF_TRAVERSE_TMPL_PART_SPEC_DECL(TMPLDECLKIND, DECLKIND) \ 2058 DEF_TRAVERSE_DECL(TMPLDECLKIND##TemplatePartialSpecializationDecl, { \ 2059 /* The partial specialization. */ \ 2060 if (TemplateParameterList *TPL = D->getTemplateParameters()) { \ 2061 for (TemplateParameterList::iterator I = TPL->begin(), E = TPL->end(); \ 2062 I != E; ++I) { \ 2063 TRY_TO(TraverseDecl(*I)); \ 2064 } \ 2065 } \ 2066 /* The args that remains unspecialized. */ \ 2067 TRY_TO(TraverseTemplateArgumentLocsHelper( \ 2068 D->getTemplateArgsAsWritten()->getTemplateArgs(), \ 2069 D->getTemplateArgsAsWritten()->NumTemplateArgs)); \ 2070 \ 2071 /* Don't need the *TemplatePartialSpecializationHelper, even \ 2072 though that's our parent class -- we already visit all the \ 2073 template args here. */ \ 2074 TRY_TO(Traverse##DECLKIND##Helper(D)); \ 2075 \ 2076 /* Instantiations will have been visited with the primary template. */ \ 2077 }) 2078 2079 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Class, CXXRecord) 2080 DEF_TRAVERSE_TMPL_PART_SPEC_DECL(Var, Var) 2081 2082 DEF_TRAVERSE_DECL(EnumConstantDecl, { TRY_TO(TraverseStmt(D->getInitExpr())); }) 2083 2084 DEF_TRAVERSE_DECL(UnresolvedUsingValueDecl, { 2085 // Like UnresolvedUsingTypenameDecl, but without the 'typename': 2086 // template <class T> Class A : public Base<T> { using Base<T>::foo; }; 2087 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 2088 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); 2089 }) 2090 2091 DEF_TRAVERSE_DECL(IndirectFieldDecl, {}) 2092 2093 template <typename Derived> 2094 bool RecursiveASTVisitor<Derived>::TraverseDeclaratorHelper(DeclaratorDecl *D) { 2095 TRY_TO(TraverseDeclTemplateParameterLists(D)); 2096 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 2097 if (D->getTypeSourceInfo()) 2098 TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc())); 2099 else 2100 TRY_TO(TraverseType(D->getType())); 2101 return true; 2102 } 2103 2104 DEF_TRAVERSE_DECL(DecompositionDecl, { 2105 TRY_TO(TraverseVarHelper(D)); 2106 for (auto *Binding : D->bindings()) { 2107 TRY_TO(TraverseDecl(Binding)); 2108 } 2109 }) 2110 2111 DEF_TRAVERSE_DECL(BindingDecl, { 2112 if (getDerived().shouldVisitImplicitCode()) 2113 TRY_TO(TraverseStmt(D->getBinding())); 2114 }) 2115 2116 DEF_TRAVERSE_DECL(MSPropertyDecl, { TRY_TO(TraverseDeclaratorHelper(D)); }) 2117 2118 DEF_TRAVERSE_DECL(MSGuidDecl, {}) 2119 DEF_TRAVERSE_DECL(UnnamedGlobalConstantDecl, {}) 2120 2121 DEF_TRAVERSE_DECL(TemplateParamObjectDecl, {}) 2122 2123 DEF_TRAVERSE_DECL(FieldDecl, { 2124 TRY_TO(TraverseDeclaratorHelper(D)); 2125 if (D->isBitField()) 2126 TRY_TO(TraverseStmt(D->getBitWidth())); 2127 else if (D->hasInClassInitializer()) 2128 TRY_TO(TraverseStmt(D->getInClassInitializer())); 2129 }) 2130 2131 DEF_TRAVERSE_DECL(ObjCAtDefsFieldDecl, { 2132 TRY_TO(TraverseDeclaratorHelper(D)); 2133 if (D->isBitField()) 2134 TRY_TO(TraverseStmt(D->getBitWidth())); 2135 // FIXME: implement the rest. 2136 }) 2137 2138 DEF_TRAVERSE_DECL(ObjCIvarDecl, { 2139 TRY_TO(TraverseDeclaratorHelper(D)); 2140 if (D->isBitField()) 2141 TRY_TO(TraverseStmt(D->getBitWidth())); 2142 // FIXME: implement the rest. 2143 }) 2144 2145 template <typename Derived> 2146 bool RecursiveASTVisitor<Derived>::TraverseFunctionHelper(FunctionDecl *D) { 2147 TRY_TO(TraverseDeclTemplateParameterLists(D)); 2148 TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); 2149 TRY_TO(TraverseDeclarationNameInfo(D->getNameInfo())); 2150 2151 // If we're an explicit template specialization, iterate over the 2152 // template args that were explicitly specified. If we were doing 2153 // this in typing order, we'd do it between the return type and 2154 // the function args, but both are handled by the FunctionTypeLoc 2155 // above, so we have to choose one side. I've decided to do before. 2156 if (const FunctionTemplateSpecializationInfo *FTSI = 2157 D->getTemplateSpecializationInfo()) { 2158 if (FTSI->getTemplateSpecializationKind() != TSK_Undeclared && 2159 FTSI->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) { 2160 // A specialization might not have explicit template arguments if it has 2161 // a templated return type and concrete arguments. 2162 if (const ASTTemplateArgumentListInfo *TALI = 2163 FTSI->TemplateArgumentsAsWritten) { 2164 TRY_TO(TraverseTemplateArgumentLocsHelper(TALI->getTemplateArgs(), 2165 TALI->NumTemplateArgs)); 2166 } 2167 } 2168 } 2169 2170 // Visit the function type itself, which can be either 2171 // FunctionNoProtoType or FunctionProtoType, or a typedef. This 2172 // also covers the return type and the function parameters, 2173 // including exception specifications. 2174 if (TypeSourceInfo *TSI = D->getTypeSourceInfo()) { 2175 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); 2176 } else if (getDerived().shouldVisitImplicitCode()) { 2177 // Visit parameter variable declarations of the implicit function 2178 // if the traverser is visiting implicit code. Parameter variable 2179 // declarations do not have valid TypeSourceInfo, so to visit them 2180 // we need to traverse the declarations explicitly. 2181 for (ParmVarDecl *Parameter : D->parameters()) { 2182 TRY_TO(TraverseDecl(Parameter)); 2183 } 2184 } 2185 2186 // Visit the trailing requires clause, if any. 2187 if (Expr *TrailingRequiresClause = D->getTrailingRequiresClause()) { 2188 TRY_TO(TraverseStmt(TrailingRequiresClause)); 2189 } 2190 2191 if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) { 2192 // Constructor initializers. 2193 for (auto *I : Ctor->inits()) { 2194 if (I->isWritten() || getDerived().shouldVisitImplicitCode()) 2195 TRY_TO(TraverseConstructorInitializer(I)); 2196 } 2197 } 2198 2199 bool VisitBody = 2200 D->isThisDeclarationADefinition() && 2201 // Don't visit the function body if the function definition is generated 2202 // by clang. 2203 (!D->isDefaulted() || getDerived().shouldVisitImplicitCode()); 2204 2205 if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) { 2206 if (const CXXRecordDecl *RD = MD->getParent()) { 2207 if (RD->isLambda() && 2208 declaresSameEntity(RD->getLambdaCallOperator(), MD)) { 2209 VisitBody = VisitBody && getDerived().shouldVisitLambdaBody(); 2210 } 2211 } 2212 } 2213 2214 if (VisitBody) { 2215 TRY_TO(TraverseStmt(D->getBody())); 2216 // Body may contain using declarations whose shadows are parented to the 2217 // FunctionDecl itself. 2218 for (auto *Child : D->decls()) { 2219 if (isa<UsingShadowDecl>(Child)) 2220 TRY_TO(TraverseDecl(Child)); 2221 } 2222 } 2223 return true; 2224 } 2225 2226 DEF_TRAVERSE_DECL(FunctionDecl, { 2227 // We skip decls_begin/decls_end, which are already covered by 2228 // TraverseFunctionHelper(). 2229 ShouldVisitChildren = false; 2230 ReturnValue = TraverseFunctionHelper(D); 2231 }) 2232 2233 DEF_TRAVERSE_DECL(CXXDeductionGuideDecl, { 2234 // We skip decls_begin/decls_end, which are already covered by 2235 // TraverseFunctionHelper(). 2236 ShouldVisitChildren = false; 2237 ReturnValue = TraverseFunctionHelper(D); 2238 }) 2239 2240 DEF_TRAVERSE_DECL(CXXMethodDecl, { 2241 // We skip decls_begin/decls_end, which are already covered by 2242 // TraverseFunctionHelper(). 2243 ShouldVisitChildren = false; 2244 ReturnValue = TraverseFunctionHelper(D); 2245 }) 2246 2247 DEF_TRAVERSE_DECL(CXXConstructorDecl, { 2248 // We skip decls_begin/decls_end, which are already covered by 2249 // TraverseFunctionHelper(). 2250 ShouldVisitChildren = false; 2251 ReturnValue = TraverseFunctionHelper(D); 2252 }) 2253 2254 // CXXConversionDecl is the declaration of a type conversion operator. 2255 // It's not a cast expression. 2256 DEF_TRAVERSE_DECL(CXXConversionDecl, { 2257 // We skip decls_begin/decls_end, which are already covered by 2258 // TraverseFunctionHelper(). 2259 ShouldVisitChildren = false; 2260 ReturnValue = TraverseFunctionHelper(D); 2261 }) 2262 2263 DEF_TRAVERSE_DECL(CXXDestructorDecl, { 2264 // We skip decls_begin/decls_end, which are already covered by 2265 // TraverseFunctionHelper(). 2266 ShouldVisitChildren = false; 2267 ReturnValue = TraverseFunctionHelper(D); 2268 }) 2269 2270 template <typename Derived> 2271 bool RecursiveASTVisitor<Derived>::TraverseVarHelper(VarDecl *D) { 2272 TRY_TO(TraverseDeclaratorHelper(D)); 2273 // Default params are taken care of when we traverse the ParmVarDecl. 2274 if (!isa<ParmVarDecl>(D) && 2275 (!D->isCXXForRangeDecl() || getDerived().shouldVisitImplicitCode())) 2276 TRY_TO(TraverseStmt(D->getInit())); 2277 return true; 2278 } 2279 2280 DEF_TRAVERSE_DECL(VarDecl, { TRY_TO(TraverseVarHelper(D)); }) 2281 2282 DEF_TRAVERSE_DECL(ImplicitParamDecl, { TRY_TO(TraverseVarHelper(D)); }) 2283 2284 DEF_TRAVERSE_DECL(NonTypeTemplateParmDecl, { 2285 // A non-type template parameter, e.g. "S" in template<int S> class Foo ... 2286 TRY_TO(TraverseDeclaratorHelper(D)); 2287 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) 2288 TRY_TO(TraverseStmt(D->getDefaultArgument())); 2289 }) 2290 2291 DEF_TRAVERSE_DECL(ParmVarDecl, { 2292 TRY_TO(TraverseVarHelper(D)); 2293 2294 if (D->hasDefaultArg() && D->hasUninstantiatedDefaultArg() && 2295 !D->hasUnparsedDefaultArg()) 2296 TRY_TO(TraverseStmt(D->getUninstantiatedDefaultArg())); 2297 2298 if (D->hasDefaultArg() && !D->hasUninstantiatedDefaultArg() && 2299 !D->hasUnparsedDefaultArg()) 2300 TRY_TO(TraverseStmt(D->getDefaultArg())); 2301 }) 2302 2303 DEF_TRAVERSE_DECL(RequiresExprBodyDecl, {}) 2304 2305 DEF_TRAVERSE_DECL(ImplicitConceptSpecializationDecl, { 2306 TRY_TO(TraverseTemplateArguments(D->getTemplateArguments())); 2307 }) 2308 2309 #undef DEF_TRAVERSE_DECL 2310 2311 // ----------------- Stmt traversal ----------------- 2312 // 2313 // For stmts, we automate (in the DEF_TRAVERSE_STMT macro) iterating 2314 // over the children defined in children() (every stmt defines these, 2315 // though sometimes the range is empty). Each individual Traverse* 2316 // method only needs to worry about children other than those. To see 2317 // what children() does for a given class, see, e.g., 2318 // http://clang.llvm.org/doxygen/Stmt_8cpp_source.html 2319 2320 // This macro makes available a variable S, the passed-in stmt. 2321 #define DEF_TRAVERSE_STMT(STMT, CODE) \ 2322 template <typename Derived> \ 2323 bool RecursiveASTVisitor<Derived>::Traverse##STMT( \ 2324 STMT *S, DataRecursionQueue *Queue) { \ 2325 bool ShouldVisitChildren = true; \ 2326 bool ReturnValue = true; \ 2327 if (!getDerived().shouldTraversePostOrder()) \ 2328 TRY_TO(WalkUpFrom##STMT(S)); \ 2329 { CODE; } \ 2330 if (ShouldVisitChildren) { \ 2331 for (Stmt * SubStmt : getDerived().getStmtChildren(S)) { \ 2332 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt); \ 2333 } \ 2334 } \ 2335 /* Call WalkUpFrom if TRY_TO_TRAVERSE_OR_ENQUEUE_STMT has traversed the \ 2336 * children already. If TRY_TO_TRAVERSE_OR_ENQUEUE_STMT only enqueued the \ 2337 * children, PostVisitStmt will call WalkUpFrom after we are done visiting \ 2338 * children. */ \ 2339 if (!Queue && ReturnValue && getDerived().shouldTraversePostOrder()) { \ 2340 TRY_TO(WalkUpFrom##STMT(S)); \ 2341 } \ 2342 return ReturnValue; \ 2343 } 2344 2345 DEF_TRAVERSE_STMT(GCCAsmStmt, { 2346 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString()); 2347 for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) { 2348 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I)); 2349 } 2350 for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) { 2351 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I)); 2352 } 2353 for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) { 2354 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I)); 2355 } 2356 // children() iterates over inputExpr and outputExpr. 2357 }) 2358 2359 DEF_TRAVERSE_STMT( 2360 MSAsmStmt, 2361 {// FIXME: MS Asm doesn't currently parse Constraints, Clobbers, etc. Once 2362 // added this needs to be implemented. 2363 }) 2364 2365 DEF_TRAVERSE_STMT(CXXCatchStmt, { 2366 TRY_TO(TraverseDecl(S->getExceptionDecl())); 2367 // children() iterates over the handler block. 2368 }) 2369 2370 DEF_TRAVERSE_STMT(DeclStmt, { 2371 for (auto *I : S->decls()) { 2372 TRY_TO(TraverseDecl(I)); 2373 } 2374 // Suppress the default iteration over children() by 2375 // returning. Here's why: A DeclStmt looks like 'type var [= 2376 // initializer]'. The decls above already traverse over the 2377 // initializers, so we don't have to do it again (which 2378 // children() would do). 2379 ShouldVisitChildren = false; 2380 }) 2381 2382 // These non-expr stmts (most of them), do not need any action except 2383 // iterating over the children. 2384 DEF_TRAVERSE_STMT(BreakStmt, {}) 2385 DEF_TRAVERSE_STMT(CXXTryStmt, {}) 2386 DEF_TRAVERSE_STMT(CaseStmt, {}) 2387 DEF_TRAVERSE_STMT(CompoundStmt, {}) 2388 DEF_TRAVERSE_STMT(ContinueStmt, {}) 2389 DEF_TRAVERSE_STMT(DefaultStmt, {}) 2390 DEF_TRAVERSE_STMT(DoStmt, {}) 2391 DEF_TRAVERSE_STMT(ForStmt, {}) 2392 DEF_TRAVERSE_STMT(GotoStmt, {}) 2393 DEF_TRAVERSE_STMT(IfStmt, {}) 2394 DEF_TRAVERSE_STMT(IndirectGotoStmt, {}) 2395 DEF_TRAVERSE_STMT(LabelStmt, {}) 2396 DEF_TRAVERSE_STMT(AttributedStmt, {}) 2397 DEF_TRAVERSE_STMT(NullStmt, {}) 2398 DEF_TRAVERSE_STMT(ObjCAtCatchStmt, {}) 2399 DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, {}) 2400 DEF_TRAVERSE_STMT(ObjCAtSynchronizedStmt, {}) 2401 DEF_TRAVERSE_STMT(ObjCAtThrowStmt, {}) 2402 DEF_TRAVERSE_STMT(ObjCAtTryStmt, {}) 2403 DEF_TRAVERSE_STMT(ObjCForCollectionStmt, {}) 2404 DEF_TRAVERSE_STMT(ObjCAutoreleasePoolStmt, {}) 2405 2406 DEF_TRAVERSE_STMT(CXXForRangeStmt, { 2407 if (!getDerived().shouldVisitImplicitCode()) { 2408 if (S->getInit()) 2409 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInit()); 2410 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getLoopVarStmt()); 2411 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getRangeInit()); 2412 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody()); 2413 // Visit everything else only if shouldVisitImplicitCode(). 2414 ShouldVisitChildren = false; 2415 } 2416 }) 2417 2418 DEF_TRAVERSE_STMT(MSDependentExistsStmt, { 2419 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2420 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo())); 2421 }) 2422 2423 DEF_TRAVERSE_STMT(ReturnStmt, {}) 2424 DEF_TRAVERSE_STMT(SwitchStmt, {}) 2425 DEF_TRAVERSE_STMT(WhileStmt, {}) 2426 2427 DEF_TRAVERSE_STMT(ConstantExpr, {}) 2428 2429 DEF_TRAVERSE_STMT(CXXDependentScopeMemberExpr, { 2430 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2431 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo())); 2432 if (S->hasExplicitTemplateArgs()) { 2433 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(), 2434 S->getNumTemplateArgs())); 2435 } 2436 }) 2437 2438 DEF_TRAVERSE_STMT(DeclRefExpr, { 2439 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2440 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo())); 2441 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(), 2442 S->getNumTemplateArgs())); 2443 }) 2444 2445 DEF_TRAVERSE_STMT(DependentScopeDeclRefExpr, { 2446 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2447 TRY_TO(TraverseDeclarationNameInfo(S->getNameInfo())); 2448 if (S->hasExplicitTemplateArgs()) { 2449 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(), 2450 S->getNumTemplateArgs())); 2451 } 2452 }) 2453 2454 DEF_TRAVERSE_STMT(MemberExpr, { 2455 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2456 TRY_TO(TraverseDeclarationNameInfo(S->getMemberNameInfo())); 2457 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(), 2458 S->getNumTemplateArgs())); 2459 }) 2460 2461 DEF_TRAVERSE_STMT( 2462 ImplicitCastExpr, 2463 {// We don't traverse the cast type, as it's not written in the 2464 // source code. 2465 }) 2466 2467 DEF_TRAVERSE_STMT(CStyleCastExpr, { 2468 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2469 }) 2470 2471 DEF_TRAVERSE_STMT(CXXFunctionalCastExpr, { 2472 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2473 }) 2474 2475 DEF_TRAVERSE_STMT(CXXAddrspaceCastExpr, { 2476 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2477 }) 2478 2479 DEF_TRAVERSE_STMT(CXXConstCastExpr, { 2480 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2481 }) 2482 2483 DEF_TRAVERSE_STMT(CXXDynamicCastExpr, { 2484 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2485 }) 2486 2487 DEF_TRAVERSE_STMT(CXXReinterpretCastExpr, { 2488 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2489 }) 2490 2491 DEF_TRAVERSE_STMT(CXXStaticCastExpr, { 2492 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2493 }) 2494 2495 DEF_TRAVERSE_STMT(BuiltinBitCastExpr, { 2496 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2497 }) 2498 2499 template <typename Derived> 2500 bool RecursiveASTVisitor<Derived>::TraverseSynOrSemInitListExpr( 2501 InitListExpr *S, DataRecursionQueue *Queue) { 2502 if (S) { 2503 // Skip this if we traverse postorder. We will visit it later 2504 // in PostVisitStmt. 2505 if (!getDerived().shouldTraversePostOrder()) 2506 TRY_TO(WalkUpFromInitListExpr(S)); 2507 2508 // All we need are the default actions. FIXME: use a helper function. 2509 for (Stmt *SubStmt : S->children()) { 2510 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(SubStmt); 2511 } 2512 2513 if (!Queue && getDerived().shouldTraversePostOrder()) 2514 TRY_TO(WalkUpFromInitListExpr(S)); 2515 } 2516 return true; 2517 } 2518 2519 template <typename Derived> 2520 bool RecursiveASTVisitor<Derived>::TraverseObjCProtocolLoc( 2521 ObjCProtocolLoc ProtocolLoc) { 2522 return true; 2523 } 2524 2525 // If shouldVisitImplicitCode() returns false, this method traverses only the 2526 // syntactic form of InitListExpr. 2527 // If shouldVisitImplicitCode() return true, this method is called once for 2528 // each pair of syntactic and semantic InitListExpr, and it traverses the 2529 // subtrees defined by the two forms. This may cause some of the children to be 2530 // visited twice, if they appear both in the syntactic and the semantic form. 2531 // 2532 // There is no guarantee about which form \p S takes when this method is called. 2533 template <typename Derived> 2534 bool RecursiveASTVisitor<Derived>::TraverseInitListExpr( 2535 InitListExpr *S, DataRecursionQueue *Queue) { 2536 if (S->isSemanticForm() && S->isSyntacticForm()) { 2537 // `S` does not have alternative forms, traverse only once. 2538 TRY_TO(TraverseSynOrSemInitListExpr(S, Queue)); 2539 return true; 2540 } 2541 TRY_TO(TraverseSynOrSemInitListExpr( 2542 S->isSemanticForm() ? S->getSyntacticForm() : S, Queue)); 2543 if (getDerived().shouldVisitImplicitCode()) { 2544 // Only visit the semantic form if the clients are interested in implicit 2545 // compiler-generated. 2546 TRY_TO(TraverseSynOrSemInitListExpr( 2547 S->isSemanticForm() ? S : S->getSemanticForm(), Queue)); 2548 } 2549 return true; 2550 } 2551 2552 // GenericSelectionExpr is a special case because the types and expressions 2553 // are interleaved. We also need to watch out for null types (default 2554 // generic associations). 2555 DEF_TRAVERSE_STMT(GenericSelectionExpr, { 2556 if (S->isExprPredicate()) 2557 TRY_TO(TraverseStmt(S->getControllingExpr())); 2558 else 2559 TRY_TO(TraverseTypeLoc(S->getControllingType()->getTypeLoc())); 2560 2561 for (const GenericSelectionExpr::Association Assoc : S->associations()) { 2562 if (TypeSourceInfo *TSI = Assoc.getTypeSourceInfo()) 2563 TRY_TO(TraverseTypeLoc(TSI->getTypeLoc())); 2564 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Assoc.getAssociationExpr()); 2565 } 2566 ShouldVisitChildren = false; 2567 }) 2568 2569 // PseudoObjectExpr is a special case because of the weirdness with 2570 // syntactic expressions and opaque values. 2571 DEF_TRAVERSE_STMT(PseudoObjectExpr, { 2572 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSyntacticForm()); 2573 for (PseudoObjectExpr::semantics_iterator i = S->semantics_begin(), 2574 e = S->semantics_end(); 2575 i != e; ++i) { 2576 Expr *sub = *i; 2577 if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(sub)) 2578 sub = OVE->getSourceExpr(); 2579 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub); 2580 } 2581 ShouldVisitChildren = false; 2582 }) 2583 2584 DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, { 2585 // This is called for code like 'return T()' where T is a built-in 2586 // (i.e. non-class) type. 2587 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 2588 }) 2589 2590 DEF_TRAVERSE_STMT(CXXNewExpr, { 2591 // The child-iterator will pick up the other arguments. 2592 TRY_TO(TraverseTypeLoc(S->getAllocatedTypeSourceInfo()->getTypeLoc())); 2593 }) 2594 2595 DEF_TRAVERSE_STMT(OffsetOfExpr, { 2596 // The child-iterator will pick up the expression representing 2597 // the field. 2598 // FIMXE: for code like offsetof(Foo, a.b.c), should we get 2599 // making a MemberExpr callbacks for Foo.a, Foo.a.b, and Foo.a.b.c? 2600 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 2601 }) 2602 2603 DEF_TRAVERSE_STMT(UnaryExprOrTypeTraitExpr, { 2604 // The child-iterator will pick up the arg if it's an expression, 2605 // but not if it's a type. 2606 if (S->isArgumentType()) 2607 TRY_TO(TraverseTypeLoc(S->getArgumentTypeInfo()->getTypeLoc())); 2608 }) 2609 2610 DEF_TRAVERSE_STMT(CXXTypeidExpr, { 2611 // The child-iterator will pick up the arg if it's an expression, 2612 // but not if it's a type. 2613 if (S->isTypeOperand()) 2614 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc())); 2615 }) 2616 2617 DEF_TRAVERSE_STMT(MSPropertyRefExpr, { 2618 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2619 }) 2620 2621 DEF_TRAVERSE_STMT(MSPropertySubscriptExpr, {}) 2622 2623 DEF_TRAVERSE_STMT(CXXUuidofExpr, { 2624 // The child-iterator will pick up the arg if it's an expression, 2625 // but not if it's a type. 2626 if (S->isTypeOperand()) 2627 TRY_TO(TraverseTypeLoc(S->getTypeOperandSourceInfo()->getTypeLoc())); 2628 }) 2629 2630 DEF_TRAVERSE_STMT(TypeTraitExpr, { 2631 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 2632 TRY_TO(TraverseTypeLoc(S->getArg(I)->getTypeLoc())); 2633 }) 2634 2635 DEF_TRAVERSE_STMT(ArrayTypeTraitExpr, { 2636 TRY_TO(TraverseTypeLoc(S->getQueriedTypeSourceInfo()->getTypeLoc())); 2637 }) 2638 2639 DEF_TRAVERSE_STMT(ExpressionTraitExpr, 2640 { TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getQueriedExpression()); }) 2641 2642 DEF_TRAVERSE_STMT(VAArgExpr, { 2643 // The child-iterator will pick up the expression argument. 2644 TRY_TO(TraverseTypeLoc(S->getWrittenTypeInfo()->getTypeLoc())); 2645 }) 2646 2647 DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr, { 2648 // This is called for code like 'return T()' where T is a class type. 2649 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 2650 }) 2651 2652 // Walk only the visible parts of lambda expressions. 2653 DEF_TRAVERSE_STMT(LambdaExpr, { 2654 // Visit the capture list. 2655 for (unsigned I = 0, N = S->capture_size(); I != N; ++I) { 2656 const LambdaCapture *C = S->capture_begin() + I; 2657 if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) { 2658 TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I])); 2659 } 2660 } 2661 2662 if (getDerived().shouldVisitImplicitCode()) { 2663 // The implicit model is simple: everything else is in the lambda class. 2664 TRY_TO(TraverseDecl(S->getLambdaClass())); 2665 } else { 2666 // We need to poke around to find the bits that might be explicitly written. 2667 TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); 2668 FunctionProtoTypeLoc Proto = TL.getAsAdjusted<FunctionProtoTypeLoc>(); 2669 2670 TRY_TO(TraverseTemplateParameterListHelper(S->getTemplateParameterList())); 2671 if (S->hasExplicitParameters()) { 2672 // Visit parameters. 2673 for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I) 2674 TRY_TO(TraverseDecl(Proto.getParam(I))); 2675 } 2676 2677 auto *T = Proto.getTypePtr(); 2678 for (const auto &E : T->exceptions()) 2679 TRY_TO(TraverseType(E)); 2680 2681 if (Expr *NE = T->getNoexceptExpr()) 2682 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(NE); 2683 2684 if (S->hasExplicitResultType()) 2685 TRY_TO(TraverseTypeLoc(Proto.getReturnLoc())); 2686 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getTrailingRequiresClause()); 2687 2688 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody()); 2689 } 2690 ShouldVisitChildren = false; 2691 }) 2692 2693 DEF_TRAVERSE_STMT(CXXUnresolvedConstructExpr, { 2694 // This is called for code like 'T()', where T is a template argument. 2695 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 2696 }) 2697 2698 // These expressions all might take explicit template arguments. 2699 // We traverse those if so. FIXME: implement these. 2700 DEF_TRAVERSE_STMT(CXXConstructExpr, {}) 2701 DEF_TRAVERSE_STMT(CallExpr, {}) 2702 DEF_TRAVERSE_STMT(CXXMemberCallExpr, {}) 2703 2704 // These exprs (most of them), do not need any action except iterating 2705 // over the children. 2706 DEF_TRAVERSE_STMT(AddrLabelExpr, {}) 2707 DEF_TRAVERSE_STMT(ArraySubscriptExpr, {}) 2708 DEF_TRAVERSE_STMT(MatrixSubscriptExpr, {}) 2709 DEF_TRAVERSE_STMT(OMPArraySectionExpr, {}) 2710 DEF_TRAVERSE_STMT(OMPArrayShapingExpr, {}) 2711 DEF_TRAVERSE_STMT(OMPIteratorExpr, {}) 2712 2713 DEF_TRAVERSE_STMT(BlockExpr, { 2714 TRY_TO(TraverseDecl(S->getBlockDecl())); 2715 return true; // no child statements to loop through. 2716 }) 2717 2718 DEF_TRAVERSE_STMT(ChooseExpr, {}) 2719 DEF_TRAVERSE_STMT(CompoundLiteralExpr, { 2720 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 2721 }) 2722 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {}) 2723 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {}) 2724 2725 DEF_TRAVERSE_STMT(CXXDefaultArgExpr, { 2726 if (getDerived().shouldVisitImplicitCode()) 2727 TRY_TO(TraverseStmt(S->getExpr())); 2728 }) 2729 2730 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, { 2731 if (getDerived().shouldVisitImplicitCode()) 2732 TRY_TO(TraverseStmt(S->getExpr())); 2733 }) 2734 2735 DEF_TRAVERSE_STMT(CXXDeleteExpr, {}) 2736 DEF_TRAVERSE_STMT(ExprWithCleanups, {}) 2737 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {}) 2738 DEF_TRAVERSE_STMT(CXXNullPtrLiteralExpr, {}) 2739 DEF_TRAVERSE_STMT(CXXStdInitializerListExpr, {}) 2740 2741 DEF_TRAVERSE_STMT(CXXPseudoDestructorExpr, { 2742 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2743 if (TypeSourceInfo *ScopeInfo = S->getScopeTypeInfo()) 2744 TRY_TO(TraverseTypeLoc(ScopeInfo->getTypeLoc())); 2745 if (TypeSourceInfo *DestroyedTypeInfo = S->getDestroyedTypeInfo()) 2746 TRY_TO(TraverseTypeLoc(DestroyedTypeInfo->getTypeLoc())); 2747 }) 2748 2749 DEF_TRAVERSE_STMT(CXXThisExpr, {}) 2750 DEF_TRAVERSE_STMT(CXXThrowExpr, {}) 2751 DEF_TRAVERSE_STMT(UserDefinedLiteral, {}) 2752 DEF_TRAVERSE_STMT(DesignatedInitExpr, {}) 2753 DEF_TRAVERSE_STMT(DesignatedInitUpdateExpr, {}) 2754 DEF_TRAVERSE_STMT(ExtVectorElementExpr, {}) 2755 DEF_TRAVERSE_STMT(GNUNullExpr, {}) 2756 DEF_TRAVERSE_STMT(ImplicitValueInitExpr, {}) 2757 DEF_TRAVERSE_STMT(NoInitExpr, {}) 2758 DEF_TRAVERSE_STMT(ArrayInitLoopExpr, { 2759 // FIXME: The source expression of the OVE should be listed as 2760 // a child of the ArrayInitLoopExpr. 2761 if (OpaqueValueExpr *OVE = S->getCommonExpr()) 2762 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(OVE->getSourceExpr()); 2763 }) 2764 DEF_TRAVERSE_STMT(ArrayInitIndexExpr, {}) 2765 DEF_TRAVERSE_STMT(ObjCBoolLiteralExpr, {}) 2766 2767 DEF_TRAVERSE_STMT(ObjCEncodeExpr, { 2768 if (TypeSourceInfo *TInfo = S->getEncodedTypeSourceInfo()) 2769 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); 2770 }) 2771 2772 DEF_TRAVERSE_STMT(ObjCIsaExpr, {}) 2773 DEF_TRAVERSE_STMT(ObjCIvarRefExpr, {}) 2774 2775 DEF_TRAVERSE_STMT(ObjCMessageExpr, { 2776 if (TypeSourceInfo *TInfo = S->getClassReceiverTypeInfo()) 2777 TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); 2778 }) 2779 2780 DEF_TRAVERSE_STMT(ObjCPropertyRefExpr, { 2781 if (S->isClassReceiver()) { 2782 ObjCInterfaceDecl *IDecl = S->getClassReceiver(); 2783 QualType Type = IDecl->getASTContext().getObjCInterfaceType(IDecl); 2784 ObjCInterfaceLocInfo Data; 2785 Data.NameLoc = S->getReceiverLocation(); 2786 Data.NameEndLoc = Data.NameLoc; 2787 TRY_TO(TraverseTypeLoc(TypeLoc(Type, &Data))); 2788 } 2789 }) 2790 DEF_TRAVERSE_STMT(ObjCSubscriptRefExpr, {}) 2791 DEF_TRAVERSE_STMT(ObjCProtocolExpr, {}) 2792 DEF_TRAVERSE_STMT(ObjCSelectorExpr, {}) 2793 DEF_TRAVERSE_STMT(ObjCIndirectCopyRestoreExpr, {}) 2794 2795 DEF_TRAVERSE_STMT(ObjCBridgedCastExpr, { 2796 TRY_TO(TraverseTypeLoc(S->getTypeInfoAsWritten()->getTypeLoc())); 2797 }) 2798 2799 DEF_TRAVERSE_STMT(ObjCAvailabilityCheckExpr, {}) 2800 DEF_TRAVERSE_STMT(ParenExpr, {}) 2801 DEF_TRAVERSE_STMT(ParenListExpr, {}) 2802 DEF_TRAVERSE_STMT(SYCLUniqueStableNameExpr, { 2803 TRY_TO(TraverseTypeLoc(S->getTypeSourceInfo()->getTypeLoc())); 2804 }) 2805 DEF_TRAVERSE_STMT(PredefinedExpr, {}) 2806 DEF_TRAVERSE_STMT(ShuffleVectorExpr, {}) 2807 DEF_TRAVERSE_STMT(ConvertVectorExpr, {}) 2808 DEF_TRAVERSE_STMT(StmtExpr, {}) 2809 DEF_TRAVERSE_STMT(SourceLocExpr, {}) 2810 2811 DEF_TRAVERSE_STMT(UnresolvedLookupExpr, { 2812 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2813 if (S->hasExplicitTemplateArgs()) { 2814 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(), 2815 S->getNumTemplateArgs())); 2816 } 2817 }) 2818 2819 DEF_TRAVERSE_STMT(UnresolvedMemberExpr, { 2820 TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); 2821 if (S->hasExplicitTemplateArgs()) { 2822 TRY_TO(TraverseTemplateArgumentLocsHelper(S->getTemplateArgs(), 2823 S->getNumTemplateArgs())); 2824 } 2825 }) 2826 2827 DEF_TRAVERSE_STMT(SEHTryStmt, {}) 2828 DEF_TRAVERSE_STMT(SEHExceptStmt, {}) 2829 DEF_TRAVERSE_STMT(SEHFinallyStmt, {}) 2830 DEF_TRAVERSE_STMT(SEHLeaveStmt, {}) 2831 DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); }) 2832 2833 DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {}) 2834 DEF_TRAVERSE_STMT(CXXRewrittenBinaryOperator, { 2835 if (!getDerived().shouldVisitImplicitCode()) { 2836 CXXRewrittenBinaryOperator::DecomposedForm Decomposed = 2837 S->getDecomposedForm(); 2838 TRY_TO(TraverseStmt(const_cast<Expr*>(Decomposed.LHS))); 2839 TRY_TO(TraverseStmt(const_cast<Expr*>(Decomposed.RHS))); 2840 ShouldVisitChildren = false; 2841 } 2842 }) 2843 DEF_TRAVERSE_STMT(OpaqueValueExpr, {}) 2844 DEF_TRAVERSE_STMT(TypoExpr, {}) 2845 DEF_TRAVERSE_STMT(RecoveryExpr, {}) 2846 DEF_TRAVERSE_STMT(CUDAKernelCallExpr, {}) 2847 2848 // These operators (all of them) do not need any action except 2849 // iterating over the children. 2850 DEF_TRAVERSE_STMT(BinaryConditionalOperator, {}) 2851 DEF_TRAVERSE_STMT(ConditionalOperator, {}) 2852 DEF_TRAVERSE_STMT(UnaryOperator, {}) 2853 DEF_TRAVERSE_STMT(BinaryOperator, {}) 2854 DEF_TRAVERSE_STMT(CompoundAssignOperator, {}) 2855 DEF_TRAVERSE_STMT(CXXNoexceptExpr, {}) 2856 DEF_TRAVERSE_STMT(PackExpansionExpr, {}) 2857 DEF_TRAVERSE_STMT(SizeOfPackExpr, {}) 2858 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmPackExpr, {}) 2859 DEF_TRAVERSE_STMT(SubstNonTypeTemplateParmExpr, {}) 2860 DEF_TRAVERSE_STMT(FunctionParmPackExpr, {}) 2861 DEF_TRAVERSE_STMT(CXXFoldExpr, {}) 2862 DEF_TRAVERSE_STMT(AtomicExpr, {}) 2863 DEF_TRAVERSE_STMT(CXXParenListInitExpr, {}) 2864 2865 DEF_TRAVERSE_STMT(MaterializeTemporaryExpr, { 2866 if (S->getLifetimeExtendedTemporaryDecl()) { 2867 TRY_TO(TraverseLifetimeExtendedTemporaryDecl( 2868 S->getLifetimeExtendedTemporaryDecl())); 2869 ShouldVisitChildren = false; 2870 } 2871 }) 2872 // For coroutines expressions, traverse either the operand 2873 // as written or the implied calls, depending on what the 2874 // derived class requests. 2875 DEF_TRAVERSE_STMT(CoroutineBodyStmt, { 2876 if (!getDerived().shouldVisitImplicitCode()) { 2877 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getBody()); 2878 ShouldVisitChildren = false; 2879 } 2880 }) 2881 DEF_TRAVERSE_STMT(CoreturnStmt, { 2882 if (!getDerived().shouldVisitImplicitCode()) { 2883 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand()); 2884 ShouldVisitChildren = false; 2885 } 2886 }) 2887 DEF_TRAVERSE_STMT(CoawaitExpr, { 2888 if (!getDerived().shouldVisitImplicitCode()) { 2889 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand()); 2890 ShouldVisitChildren = false; 2891 } 2892 }) 2893 DEF_TRAVERSE_STMT(DependentCoawaitExpr, { 2894 if (!getDerived().shouldVisitImplicitCode()) { 2895 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand()); 2896 ShouldVisitChildren = false; 2897 } 2898 }) 2899 DEF_TRAVERSE_STMT(CoyieldExpr, { 2900 if (!getDerived().shouldVisitImplicitCode()) { 2901 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOperand()); 2902 ShouldVisitChildren = false; 2903 } 2904 }) 2905 2906 DEF_TRAVERSE_STMT(ConceptSpecializationExpr, 2907 { TRY_TO(TraverseConceptReferenceHelper(*S)); }) 2908 2909 DEF_TRAVERSE_STMT(RequiresExpr, { 2910 TRY_TO(TraverseDecl(S->getBody())); 2911 for (ParmVarDecl *Parm : S->getLocalParameters()) 2912 TRY_TO(TraverseDecl(Parm)); 2913 for (concepts::Requirement *Req : S->getRequirements()) 2914 TRY_TO(TraverseConceptRequirement(Req)); 2915 }) 2916 2917 // These literals (all of them) do not need any action. 2918 DEF_TRAVERSE_STMT(IntegerLiteral, {}) 2919 DEF_TRAVERSE_STMT(FixedPointLiteral, {}) 2920 DEF_TRAVERSE_STMT(CharacterLiteral, {}) 2921 DEF_TRAVERSE_STMT(FloatingLiteral, {}) 2922 DEF_TRAVERSE_STMT(ImaginaryLiteral, {}) 2923 DEF_TRAVERSE_STMT(StringLiteral, {}) 2924 DEF_TRAVERSE_STMT(ObjCStringLiteral, {}) 2925 DEF_TRAVERSE_STMT(ObjCBoxedExpr, {}) 2926 DEF_TRAVERSE_STMT(ObjCArrayLiteral, {}) 2927 DEF_TRAVERSE_STMT(ObjCDictionaryLiteral, {}) 2928 2929 // Traverse OpenCL: AsType, Convert. 2930 DEF_TRAVERSE_STMT(AsTypeExpr, {}) 2931 2932 // OpenMP directives. 2933 template <typename Derived> 2934 bool RecursiveASTVisitor<Derived>::TraverseOMPExecutableDirective( 2935 OMPExecutableDirective *S) { 2936 for (auto *C : S->clauses()) { 2937 TRY_TO(TraverseOMPClause(C)); 2938 } 2939 return true; 2940 } 2941 2942 DEF_TRAVERSE_STMT(OMPCanonicalLoop, { 2943 if (!getDerived().shouldVisitImplicitCode()) { 2944 // Visit only the syntactical loop. 2945 TRY_TO(TraverseStmt(S->getLoopStmt())); 2946 ShouldVisitChildren = false; 2947 } 2948 }) 2949 2950 template <typename Derived> 2951 bool 2952 RecursiveASTVisitor<Derived>::TraverseOMPLoopDirective(OMPLoopDirective *S) { 2953 return TraverseOMPExecutableDirective(S); 2954 } 2955 2956 DEF_TRAVERSE_STMT(OMPMetaDirective, 2957 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2958 2959 DEF_TRAVERSE_STMT(OMPParallelDirective, 2960 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2961 2962 DEF_TRAVERSE_STMT(OMPSimdDirective, 2963 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2964 2965 DEF_TRAVERSE_STMT(OMPTileDirective, 2966 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2967 2968 DEF_TRAVERSE_STMT(OMPUnrollDirective, 2969 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2970 2971 DEF_TRAVERSE_STMT(OMPForDirective, 2972 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2973 2974 DEF_TRAVERSE_STMT(OMPForSimdDirective, 2975 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2976 2977 DEF_TRAVERSE_STMT(OMPSectionsDirective, 2978 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2979 2980 DEF_TRAVERSE_STMT(OMPSectionDirective, 2981 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2982 2983 DEF_TRAVERSE_STMT(OMPSingleDirective, 2984 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2985 2986 DEF_TRAVERSE_STMT(OMPMasterDirective, 2987 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2988 2989 DEF_TRAVERSE_STMT(OMPCriticalDirective, { 2990 TRY_TO(TraverseDeclarationNameInfo(S->getDirectiveName())); 2991 TRY_TO(TraverseOMPExecutableDirective(S)); 2992 }) 2993 2994 DEF_TRAVERSE_STMT(OMPParallelForDirective, 2995 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2996 2997 DEF_TRAVERSE_STMT(OMPParallelForSimdDirective, 2998 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 2999 3000 DEF_TRAVERSE_STMT(OMPParallelMasterDirective, 3001 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3002 3003 DEF_TRAVERSE_STMT(OMPParallelMaskedDirective, 3004 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3005 3006 DEF_TRAVERSE_STMT(OMPParallelSectionsDirective, 3007 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3008 3009 DEF_TRAVERSE_STMT(OMPTaskDirective, 3010 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3011 3012 DEF_TRAVERSE_STMT(OMPTaskyieldDirective, 3013 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3014 3015 DEF_TRAVERSE_STMT(OMPBarrierDirective, 3016 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3017 3018 DEF_TRAVERSE_STMT(OMPTaskwaitDirective, 3019 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3020 3021 DEF_TRAVERSE_STMT(OMPTaskgroupDirective, 3022 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3023 3024 DEF_TRAVERSE_STMT(OMPCancellationPointDirective, 3025 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3026 3027 DEF_TRAVERSE_STMT(OMPCancelDirective, 3028 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3029 3030 DEF_TRAVERSE_STMT(OMPFlushDirective, 3031 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3032 3033 DEF_TRAVERSE_STMT(OMPDepobjDirective, 3034 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3035 3036 DEF_TRAVERSE_STMT(OMPScanDirective, 3037 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3038 3039 DEF_TRAVERSE_STMT(OMPOrderedDirective, 3040 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3041 3042 DEF_TRAVERSE_STMT(OMPAtomicDirective, 3043 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3044 3045 DEF_TRAVERSE_STMT(OMPTargetDirective, 3046 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3047 3048 DEF_TRAVERSE_STMT(OMPTargetDataDirective, 3049 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3050 3051 DEF_TRAVERSE_STMT(OMPTargetEnterDataDirective, 3052 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3053 3054 DEF_TRAVERSE_STMT(OMPTargetExitDataDirective, 3055 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3056 3057 DEF_TRAVERSE_STMT(OMPTargetParallelDirective, 3058 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3059 3060 DEF_TRAVERSE_STMT(OMPTargetParallelForDirective, 3061 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3062 3063 DEF_TRAVERSE_STMT(OMPTeamsDirective, 3064 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3065 3066 DEF_TRAVERSE_STMT(OMPTargetUpdateDirective, 3067 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3068 3069 DEF_TRAVERSE_STMT(OMPTaskLoopDirective, 3070 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3071 3072 DEF_TRAVERSE_STMT(OMPTaskLoopSimdDirective, 3073 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3074 3075 DEF_TRAVERSE_STMT(OMPMasterTaskLoopDirective, 3076 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3077 3078 DEF_TRAVERSE_STMT(OMPMasterTaskLoopSimdDirective, 3079 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3080 3081 DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopDirective, 3082 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3083 3084 DEF_TRAVERSE_STMT(OMPParallelMasterTaskLoopSimdDirective, 3085 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3086 3087 DEF_TRAVERSE_STMT(OMPMaskedTaskLoopDirective, 3088 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3089 3090 DEF_TRAVERSE_STMT(OMPMaskedTaskLoopSimdDirective, 3091 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3092 3093 DEF_TRAVERSE_STMT(OMPParallelMaskedTaskLoopDirective, 3094 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3095 3096 DEF_TRAVERSE_STMT(OMPParallelMaskedTaskLoopSimdDirective, 3097 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3098 3099 DEF_TRAVERSE_STMT(OMPDistributeDirective, 3100 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3101 3102 DEF_TRAVERSE_STMT(OMPDistributeParallelForDirective, 3103 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3104 3105 DEF_TRAVERSE_STMT(OMPDistributeParallelForSimdDirective, 3106 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3107 3108 DEF_TRAVERSE_STMT(OMPDistributeSimdDirective, 3109 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3110 3111 DEF_TRAVERSE_STMT(OMPTargetParallelForSimdDirective, 3112 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3113 3114 DEF_TRAVERSE_STMT(OMPTargetSimdDirective, 3115 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3116 3117 DEF_TRAVERSE_STMT(OMPTeamsDistributeDirective, 3118 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3119 3120 DEF_TRAVERSE_STMT(OMPTeamsDistributeSimdDirective, 3121 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3122 3123 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForSimdDirective, 3124 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3125 3126 DEF_TRAVERSE_STMT(OMPTeamsDistributeParallelForDirective, 3127 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3128 3129 DEF_TRAVERSE_STMT(OMPTargetTeamsDirective, 3130 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3131 3132 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeDirective, 3133 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3134 3135 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForDirective, 3136 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3137 3138 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeParallelForSimdDirective, 3139 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3140 3141 DEF_TRAVERSE_STMT(OMPTargetTeamsDistributeSimdDirective, 3142 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3143 3144 DEF_TRAVERSE_STMT(OMPInteropDirective, 3145 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3146 3147 DEF_TRAVERSE_STMT(OMPDispatchDirective, 3148 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3149 3150 DEF_TRAVERSE_STMT(OMPMaskedDirective, 3151 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3152 3153 DEF_TRAVERSE_STMT(OMPGenericLoopDirective, 3154 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3155 3156 DEF_TRAVERSE_STMT(OMPTeamsGenericLoopDirective, 3157 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3158 3159 DEF_TRAVERSE_STMT(OMPTargetTeamsGenericLoopDirective, 3160 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3161 3162 DEF_TRAVERSE_STMT(OMPParallelGenericLoopDirective, 3163 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3164 3165 DEF_TRAVERSE_STMT(OMPTargetParallelGenericLoopDirective, 3166 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3167 3168 DEF_TRAVERSE_STMT(OMPErrorDirective, 3169 { TRY_TO(TraverseOMPExecutableDirective(S)); }) 3170 3171 // OpenMP clauses. 3172 template <typename Derived> 3173 bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) { 3174 if (!C) 3175 return true; 3176 switch (C->getClauseKind()) { 3177 #define GEN_CLANG_CLAUSE_CLASS 3178 #define CLAUSE_CLASS(Enum, Str, Class) \ 3179 case llvm::omp::Clause::Enum: \ 3180 TRY_TO(Visit##Class(static_cast<Class *>(C))); \ 3181 break; 3182 #define CLAUSE_NO_CLASS(Enum, Str) \ 3183 case llvm::omp::Clause::Enum: \ 3184 break; 3185 #include "llvm/Frontend/OpenMP/OMP.inc" 3186 } 3187 return true; 3188 } 3189 3190 template <typename Derived> 3191 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPreInit( 3192 OMPClauseWithPreInit *Node) { 3193 TRY_TO(TraverseStmt(Node->getPreInitStmt())); 3194 return true; 3195 } 3196 3197 template <typename Derived> 3198 bool RecursiveASTVisitor<Derived>::VisitOMPClauseWithPostUpdate( 3199 OMPClauseWithPostUpdate *Node) { 3200 TRY_TO(VisitOMPClauseWithPreInit(Node)); 3201 TRY_TO(TraverseStmt(Node->getPostUpdateExpr())); 3202 return true; 3203 } 3204 3205 template <typename Derived> 3206 bool RecursiveASTVisitor<Derived>::VisitOMPAllocatorClause( 3207 OMPAllocatorClause *C) { 3208 TRY_TO(TraverseStmt(C->getAllocator())); 3209 return true; 3210 } 3211 3212 template <typename Derived> 3213 bool RecursiveASTVisitor<Derived>::VisitOMPAllocateClause(OMPAllocateClause *C) { 3214 TRY_TO(TraverseStmt(C->getAllocator())); 3215 TRY_TO(VisitOMPClauseList(C)); 3216 return true; 3217 } 3218 3219 template <typename Derived> 3220 bool RecursiveASTVisitor<Derived>::VisitOMPIfClause(OMPIfClause *C) { 3221 TRY_TO(VisitOMPClauseWithPreInit(C)); 3222 TRY_TO(TraverseStmt(C->getCondition())); 3223 return true; 3224 } 3225 3226 template <typename Derived> 3227 bool RecursiveASTVisitor<Derived>::VisitOMPFinalClause(OMPFinalClause *C) { 3228 TRY_TO(VisitOMPClauseWithPreInit(C)); 3229 TRY_TO(TraverseStmt(C->getCondition())); 3230 return true; 3231 } 3232 3233 template <typename Derived> 3234 bool 3235 RecursiveASTVisitor<Derived>::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { 3236 TRY_TO(VisitOMPClauseWithPreInit(C)); 3237 TRY_TO(TraverseStmt(C->getNumThreads())); 3238 return true; 3239 } 3240 3241 template <typename Derived> 3242 bool RecursiveASTVisitor<Derived>::VisitOMPAlignClause(OMPAlignClause *C) { 3243 TRY_TO(TraverseStmt(C->getAlignment())); 3244 return true; 3245 } 3246 3247 template <typename Derived> 3248 bool RecursiveASTVisitor<Derived>::VisitOMPSafelenClause(OMPSafelenClause *C) { 3249 TRY_TO(TraverseStmt(C->getSafelen())); 3250 return true; 3251 } 3252 3253 template <typename Derived> 3254 bool RecursiveASTVisitor<Derived>::VisitOMPSimdlenClause(OMPSimdlenClause *C) { 3255 TRY_TO(TraverseStmt(C->getSimdlen())); 3256 return true; 3257 } 3258 3259 template <typename Derived> 3260 bool RecursiveASTVisitor<Derived>::VisitOMPSizesClause(OMPSizesClause *C) { 3261 for (Expr *E : C->getSizesRefs()) 3262 TRY_TO(TraverseStmt(E)); 3263 return true; 3264 } 3265 3266 template <typename Derived> 3267 bool RecursiveASTVisitor<Derived>::VisitOMPFullClause(OMPFullClause *C) { 3268 return true; 3269 } 3270 3271 template <typename Derived> 3272 bool RecursiveASTVisitor<Derived>::VisitOMPPartialClause(OMPPartialClause *C) { 3273 TRY_TO(TraverseStmt(C->getFactor())); 3274 return true; 3275 } 3276 3277 template <typename Derived> 3278 bool 3279 RecursiveASTVisitor<Derived>::VisitOMPCollapseClause(OMPCollapseClause *C) { 3280 TRY_TO(TraverseStmt(C->getNumForLoops())); 3281 return true; 3282 } 3283 3284 template <typename Derived> 3285 bool RecursiveASTVisitor<Derived>::VisitOMPDefaultClause(OMPDefaultClause *) { 3286 return true; 3287 } 3288 3289 template <typename Derived> 3290 bool RecursiveASTVisitor<Derived>::VisitOMPProcBindClause(OMPProcBindClause *) { 3291 return true; 3292 } 3293 3294 template <typename Derived> 3295 bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedAddressClause( 3296 OMPUnifiedAddressClause *) { 3297 return true; 3298 } 3299 3300 template <typename Derived> 3301 bool RecursiveASTVisitor<Derived>::VisitOMPUnifiedSharedMemoryClause( 3302 OMPUnifiedSharedMemoryClause *) { 3303 return true; 3304 } 3305 3306 template <typename Derived> 3307 bool RecursiveASTVisitor<Derived>::VisitOMPReverseOffloadClause( 3308 OMPReverseOffloadClause *) { 3309 return true; 3310 } 3311 3312 template <typename Derived> 3313 bool RecursiveASTVisitor<Derived>::VisitOMPDynamicAllocatorsClause( 3314 OMPDynamicAllocatorsClause *) { 3315 return true; 3316 } 3317 3318 template <typename Derived> 3319 bool RecursiveASTVisitor<Derived>::VisitOMPAtomicDefaultMemOrderClause( 3320 OMPAtomicDefaultMemOrderClause *) { 3321 return true; 3322 } 3323 3324 template <typename Derived> 3325 bool RecursiveASTVisitor<Derived>::VisitOMPAtClause(OMPAtClause *) { 3326 return true; 3327 } 3328 3329 template <typename Derived> 3330 bool RecursiveASTVisitor<Derived>::VisitOMPSeverityClause(OMPSeverityClause *) { 3331 return true; 3332 } 3333 3334 template <typename Derived> 3335 bool RecursiveASTVisitor<Derived>::VisitOMPMessageClause(OMPMessageClause *C) { 3336 TRY_TO(TraverseStmt(C->getMessageString())); 3337 return true; 3338 } 3339 3340 template <typename Derived> 3341 bool 3342 RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) { 3343 TRY_TO(VisitOMPClauseWithPreInit(C)); 3344 TRY_TO(TraverseStmt(C->getChunkSize())); 3345 return true; 3346 } 3347 3348 template <typename Derived> 3349 bool RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *C) { 3350 TRY_TO(TraverseStmt(C->getNumForLoops())); 3351 return true; 3352 } 3353 3354 template <typename Derived> 3355 bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) { 3356 return true; 3357 } 3358 3359 template <typename Derived> 3360 bool RecursiveASTVisitor<Derived>::VisitOMPUntiedClause(OMPUntiedClause *) { 3361 return true; 3362 } 3363 3364 template <typename Derived> 3365 bool 3366 RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) { 3367 return true; 3368 } 3369 3370 template <typename Derived> 3371 bool RecursiveASTVisitor<Derived>::VisitOMPReadClause(OMPReadClause *) { 3372 return true; 3373 } 3374 3375 template <typename Derived> 3376 bool RecursiveASTVisitor<Derived>::VisitOMPWriteClause(OMPWriteClause *) { 3377 return true; 3378 } 3379 3380 template <typename Derived> 3381 bool RecursiveASTVisitor<Derived>::VisitOMPUpdateClause(OMPUpdateClause *) { 3382 return true; 3383 } 3384 3385 template <typename Derived> 3386 bool RecursiveASTVisitor<Derived>::VisitOMPCaptureClause(OMPCaptureClause *) { 3387 return true; 3388 } 3389 3390 template <typename Derived> 3391 bool RecursiveASTVisitor<Derived>::VisitOMPCompareClause(OMPCompareClause *) { 3392 return true; 3393 } 3394 3395 template <typename Derived> 3396 bool RecursiveASTVisitor<Derived>::VisitOMPSeqCstClause(OMPSeqCstClause *) { 3397 return true; 3398 } 3399 3400 template <typename Derived> 3401 bool RecursiveASTVisitor<Derived>::VisitOMPAcqRelClause(OMPAcqRelClause *) { 3402 return true; 3403 } 3404 3405 template <typename Derived> 3406 bool RecursiveASTVisitor<Derived>::VisitOMPAcquireClause(OMPAcquireClause *) { 3407 return true; 3408 } 3409 3410 template <typename Derived> 3411 bool RecursiveASTVisitor<Derived>::VisitOMPReleaseClause(OMPReleaseClause *) { 3412 return true; 3413 } 3414 3415 template <typename Derived> 3416 bool RecursiveASTVisitor<Derived>::VisitOMPRelaxedClause(OMPRelaxedClause *) { 3417 return true; 3418 } 3419 3420 template <typename Derived> 3421 bool RecursiveASTVisitor<Derived>::VisitOMPThreadsClause(OMPThreadsClause *) { 3422 return true; 3423 } 3424 3425 template <typename Derived> 3426 bool RecursiveASTVisitor<Derived>::VisitOMPSIMDClause(OMPSIMDClause *) { 3427 return true; 3428 } 3429 3430 template <typename Derived> 3431 bool RecursiveASTVisitor<Derived>::VisitOMPNogroupClause(OMPNogroupClause *) { 3432 return true; 3433 } 3434 3435 template <typename Derived> 3436 bool RecursiveASTVisitor<Derived>::VisitOMPInitClause(OMPInitClause *C) { 3437 TRY_TO(VisitOMPClauseList(C)); 3438 return true; 3439 } 3440 3441 template <typename Derived> 3442 bool RecursiveASTVisitor<Derived>::VisitOMPUseClause(OMPUseClause *C) { 3443 TRY_TO(TraverseStmt(C->getInteropVar())); 3444 return true; 3445 } 3446 3447 template <typename Derived> 3448 bool RecursiveASTVisitor<Derived>::VisitOMPDestroyClause(OMPDestroyClause *C) { 3449 TRY_TO(TraverseStmt(C->getInteropVar())); 3450 return true; 3451 } 3452 3453 template <typename Derived> 3454 bool RecursiveASTVisitor<Derived>::VisitOMPNovariantsClause( 3455 OMPNovariantsClause *C) { 3456 TRY_TO(VisitOMPClauseWithPreInit(C)); 3457 TRY_TO(TraverseStmt(C->getCondition())); 3458 return true; 3459 } 3460 3461 template <typename Derived> 3462 bool RecursiveASTVisitor<Derived>::VisitOMPNocontextClause( 3463 OMPNocontextClause *C) { 3464 TRY_TO(VisitOMPClauseWithPreInit(C)); 3465 TRY_TO(TraverseStmt(C->getCondition())); 3466 return true; 3467 } 3468 3469 template <typename Derived> 3470 template <typename T> 3471 bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) { 3472 for (auto *E : Node->varlists()) { 3473 TRY_TO(TraverseStmt(E)); 3474 } 3475 return true; 3476 } 3477 3478 template <typename Derived> 3479 bool RecursiveASTVisitor<Derived>::VisitOMPInclusiveClause( 3480 OMPInclusiveClause *C) { 3481 TRY_TO(VisitOMPClauseList(C)); 3482 return true; 3483 } 3484 3485 template <typename Derived> 3486 bool RecursiveASTVisitor<Derived>::VisitOMPExclusiveClause( 3487 OMPExclusiveClause *C) { 3488 TRY_TO(VisitOMPClauseList(C)); 3489 return true; 3490 } 3491 3492 template <typename Derived> 3493 bool RecursiveASTVisitor<Derived>::VisitOMPPrivateClause(OMPPrivateClause *C) { 3494 TRY_TO(VisitOMPClauseList(C)); 3495 for (auto *E : C->private_copies()) { 3496 TRY_TO(TraverseStmt(E)); 3497 } 3498 return true; 3499 } 3500 3501 template <typename Derived> 3502 bool RecursiveASTVisitor<Derived>::VisitOMPFirstprivateClause( 3503 OMPFirstprivateClause *C) { 3504 TRY_TO(VisitOMPClauseList(C)); 3505 TRY_TO(VisitOMPClauseWithPreInit(C)); 3506 for (auto *E : C->private_copies()) { 3507 TRY_TO(TraverseStmt(E)); 3508 } 3509 for (auto *E : C->inits()) { 3510 TRY_TO(TraverseStmt(E)); 3511 } 3512 return true; 3513 } 3514 3515 template <typename Derived> 3516 bool RecursiveASTVisitor<Derived>::VisitOMPLastprivateClause( 3517 OMPLastprivateClause *C) { 3518 TRY_TO(VisitOMPClauseList(C)); 3519 TRY_TO(VisitOMPClauseWithPostUpdate(C)); 3520 for (auto *E : C->private_copies()) { 3521 TRY_TO(TraverseStmt(E)); 3522 } 3523 for (auto *E : C->source_exprs()) { 3524 TRY_TO(TraverseStmt(E)); 3525 } 3526 for (auto *E : C->destination_exprs()) { 3527 TRY_TO(TraverseStmt(E)); 3528 } 3529 for (auto *E : C->assignment_ops()) { 3530 TRY_TO(TraverseStmt(E)); 3531 } 3532 return true; 3533 } 3534 3535 template <typename Derived> 3536 bool RecursiveASTVisitor<Derived>::VisitOMPSharedClause(OMPSharedClause *C) { 3537 TRY_TO(VisitOMPClauseList(C)); 3538 return true; 3539 } 3540 3541 template <typename Derived> 3542 bool RecursiveASTVisitor<Derived>::VisitOMPLinearClause(OMPLinearClause *C) { 3543 TRY_TO(TraverseStmt(C->getStep())); 3544 TRY_TO(TraverseStmt(C->getCalcStep())); 3545 TRY_TO(VisitOMPClauseList(C)); 3546 TRY_TO(VisitOMPClauseWithPostUpdate(C)); 3547 for (auto *E : C->privates()) { 3548 TRY_TO(TraverseStmt(E)); 3549 } 3550 for (auto *E : C->inits()) { 3551 TRY_TO(TraverseStmt(E)); 3552 } 3553 for (auto *E : C->updates()) { 3554 TRY_TO(TraverseStmt(E)); 3555 } 3556 for (auto *E : C->finals()) { 3557 TRY_TO(TraverseStmt(E)); 3558 } 3559 return true; 3560 } 3561 3562 template <typename Derived> 3563 bool RecursiveASTVisitor<Derived>::VisitOMPAlignedClause(OMPAlignedClause *C) { 3564 TRY_TO(TraverseStmt(C->getAlignment())); 3565 TRY_TO(VisitOMPClauseList(C)); 3566 return true; 3567 } 3568 3569 template <typename Derived> 3570 bool RecursiveASTVisitor<Derived>::VisitOMPCopyinClause(OMPCopyinClause *C) { 3571 TRY_TO(VisitOMPClauseList(C)); 3572 for (auto *E : C->source_exprs()) { 3573 TRY_TO(TraverseStmt(E)); 3574 } 3575 for (auto *E : C->destination_exprs()) { 3576 TRY_TO(TraverseStmt(E)); 3577 } 3578 for (auto *E : C->assignment_ops()) { 3579 TRY_TO(TraverseStmt(E)); 3580 } 3581 return true; 3582 } 3583 3584 template <typename Derived> 3585 bool RecursiveASTVisitor<Derived>::VisitOMPCopyprivateClause( 3586 OMPCopyprivateClause *C) { 3587 TRY_TO(VisitOMPClauseList(C)); 3588 for (auto *E : C->source_exprs()) { 3589 TRY_TO(TraverseStmt(E)); 3590 } 3591 for (auto *E : C->destination_exprs()) { 3592 TRY_TO(TraverseStmt(E)); 3593 } 3594 for (auto *E : C->assignment_ops()) { 3595 TRY_TO(TraverseStmt(E)); 3596 } 3597 return true; 3598 } 3599 3600 template <typename Derived> 3601 bool 3602 RecursiveASTVisitor<Derived>::VisitOMPReductionClause(OMPReductionClause *C) { 3603 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc())); 3604 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo())); 3605 TRY_TO(VisitOMPClauseList(C)); 3606 TRY_TO(VisitOMPClauseWithPostUpdate(C)); 3607 for (auto *E : C->privates()) { 3608 TRY_TO(TraverseStmt(E)); 3609 } 3610 for (auto *E : C->lhs_exprs()) { 3611 TRY_TO(TraverseStmt(E)); 3612 } 3613 for (auto *E : C->rhs_exprs()) { 3614 TRY_TO(TraverseStmt(E)); 3615 } 3616 for (auto *E : C->reduction_ops()) { 3617 TRY_TO(TraverseStmt(E)); 3618 } 3619 if (C->getModifier() == OMPC_REDUCTION_inscan) { 3620 for (auto *E : C->copy_ops()) { 3621 TRY_TO(TraverseStmt(E)); 3622 } 3623 for (auto *E : C->copy_array_temps()) { 3624 TRY_TO(TraverseStmt(E)); 3625 } 3626 for (auto *E : C->copy_array_elems()) { 3627 TRY_TO(TraverseStmt(E)); 3628 } 3629 } 3630 return true; 3631 } 3632 3633 template <typename Derived> 3634 bool RecursiveASTVisitor<Derived>::VisitOMPTaskReductionClause( 3635 OMPTaskReductionClause *C) { 3636 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc())); 3637 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo())); 3638 TRY_TO(VisitOMPClauseList(C)); 3639 TRY_TO(VisitOMPClauseWithPostUpdate(C)); 3640 for (auto *E : C->privates()) { 3641 TRY_TO(TraverseStmt(E)); 3642 } 3643 for (auto *E : C->lhs_exprs()) { 3644 TRY_TO(TraverseStmt(E)); 3645 } 3646 for (auto *E : C->rhs_exprs()) { 3647 TRY_TO(TraverseStmt(E)); 3648 } 3649 for (auto *E : C->reduction_ops()) { 3650 TRY_TO(TraverseStmt(E)); 3651 } 3652 return true; 3653 } 3654 3655 template <typename Derived> 3656 bool RecursiveASTVisitor<Derived>::VisitOMPInReductionClause( 3657 OMPInReductionClause *C) { 3658 TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc())); 3659 TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo())); 3660 TRY_TO(VisitOMPClauseList(C)); 3661 TRY_TO(VisitOMPClauseWithPostUpdate(C)); 3662 for (auto *E : C->privates()) { 3663 TRY_TO(TraverseStmt(E)); 3664 } 3665 for (auto *E : C->lhs_exprs()) { 3666 TRY_TO(TraverseStmt(E)); 3667 } 3668 for (auto *E : C->rhs_exprs()) { 3669 TRY_TO(TraverseStmt(E)); 3670 } 3671 for (auto *E : C->reduction_ops()) { 3672 TRY_TO(TraverseStmt(E)); 3673 } 3674 for (auto *E : C->taskgroup_descriptors()) 3675 TRY_TO(TraverseStmt(E)); 3676 return true; 3677 } 3678 3679 template <typename Derived> 3680 bool RecursiveASTVisitor<Derived>::VisitOMPFlushClause(OMPFlushClause *C) { 3681 TRY_TO(VisitOMPClauseList(C)); 3682 return true; 3683 } 3684 3685 template <typename Derived> 3686 bool RecursiveASTVisitor<Derived>::VisitOMPDepobjClause(OMPDepobjClause *C) { 3687 TRY_TO(TraverseStmt(C->getDepobj())); 3688 return true; 3689 } 3690 3691 template <typename Derived> 3692 bool RecursiveASTVisitor<Derived>::VisitOMPDependClause(OMPDependClause *C) { 3693 TRY_TO(VisitOMPClauseList(C)); 3694 return true; 3695 } 3696 3697 template <typename Derived> 3698 bool RecursiveASTVisitor<Derived>::VisitOMPDeviceClause(OMPDeviceClause *C) { 3699 TRY_TO(VisitOMPClauseWithPreInit(C)); 3700 TRY_TO(TraverseStmt(C->getDevice())); 3701 return true; 3702 } 3703 3704 template <typename Derived> 3705 bool RecursiveASTVisitor<Derived>::VisitOMPMapClause(OMPMapClause *C) { 3706 TRY_TO(VisitOMPClauseList(C)); 3707 return true; 3708 } 3709 3710 template <typename Derived> 3711 bool RecursiveASTVisitor<Derived>::VisitOMPNumTeamsClause( 3712 OMPNumTeamsClause *C) { 3713 TRY_TO(VisitOMPClauseWithPreInit(C)); 3714 TRY_TO(TraverseStmt(C->getNumTeams())); 3715 return true; 3716 } 3717 3718 template <typename Derived> 3719 bool RecursiveASTVisitor<Derived>::VisitOMPThreadLimitClause( 3720 OMPThreadLimitClause *C) { 3721 TRY_TO(VisitOMPClauseWithPreInit(C)); 3722 TRY_TO(TraverseStmt(C->getThreadLimit())); 3723 return true; 3724 } 3725 3726 template <typename Derived> 3727 bool RecursiveASTVisitor<Derived>::VisitOMPPriorityClause( 3728 OMPPriorityClause *C) { 3729 TRY_TO(VisitOMPClauseWithPreInit(C)); 3730 TRY_TO(TraverseStmt(C->getPriority())); 3731 return true; 3732 } 3733 3734 template <typename Derived> 3735 bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause( 3736 OMPGrainsizeClause *C) { 3737 TRY_TO(VisitOMPClauseWithPreInit(C)); 3738 TRY_TO(TraverseStmt(C->getGrainsize())); 3739 return true; 3740 } 3741 3742 template <typename Derived> 3743 bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause( 3744 OMPNumTasksClause *C) { 3745 TRY_TO(VisitOMPClauseWithPreInit(C)); 3746 TRY_TO(TraverseStmt(C->getNumTasks())); 3747 return true; 3748 } 3749 3750 template <typename Derived> 3751 bool RecursiveASTVisitor<Derived>::VisitOMPHintClause(OMPHintClause *C) { 3752 TRY_TO(TraverseStmt(C->getHint())); 3753 return true; 3754 } 3755 3756 template <typename Derived> 3757 bool RecursiveASTVisitor<Derived>::VisitOMPDistScheduleClause( 3758 OMPDistScheduleClause *C) { 3759 TRY_TO(VisitOMPClauseWithPreInit(C)); 3760 TRY_TO(TraverseStmt(C->getChunkSize())); 3761 return true; 3762 } 3763 3764 template <typename Derived> 3765 bool 3766 RecursiveASTVisitor<Derived>::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) { 3767 return true; 3768 } 3769 3770 template <typename Derived> 3771 bool RecursiveASTVisitor<Derived>::VisitOMPToClause(OMPToClause *C) { 3772 TRY_TO(VisitOMPClauseList(C)); 3773 return true; 3774 } 3775 3776 template <typename Derived> 3777 bool RecursiveASTVisitor<Derived>::VisitOMPFromClause(OMPFromClause *C) { 3778 TRY_TO(VisitOMPClauseList(C)); 3779 return true; 3780 } 3781 3782 template <typename Derived> 3783 bool RecursiveASTVisitor<Derived>::VisitOMPUseDevicePtrClause( 3784 OMPUseDevicePtrClause *C) { 3785 TRY_TO(VisitOMPClauseList(C)); 3786 return true; 3787 } 3788 3789 template <typename Derived> 3790 bool RecursiveASTVisitor<Derived>::VisitOMPUseDeviceAddrClause( 3791 OMPUseDeviceAddrClause *C) { 3792 TRY_TO(VisitOMPClauseList(C)); 3793 return true; 3794 } 3795 3796 template <typename Derived> 3797 bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause( 3798 OMPIsDevicePtrClause *C) { 3799 TRY_TO(VisitOMPClauseList(C)); 3800 return true; 3801 } 3802 3803 template <typename Derived> 3804 bool RecursiveASTVisitor<Derived>::VisitOMPHasDeviceAddrClause( 3805 OMPHasDeviceAddrClause *C) { 3806 TRY_TO(VisitOMPClauseList(C)); 3807 return true; 3808 } 3809 3810 template <typename Derived> 3811 bool RecursiveASTVisitor<Derived>::VisitOMPNontemporalClause( 3812 OMPNontemporalClause *C) { 3813 TRY_TO(VisitOMPClauseList(C)); 3814 for (auto *E : C->private_refs()) { 3815 TRY_TO(TraverseStmt(E)); 3816 } 3817 return true; 3818 } 3819 3820 template <typename Derived> 3821 bool RecursiveASTVisitor<Derived>::VisitOMPOrderClause(OMPOrderClause *) { 3822 return true; 3823 } 3824 3825 template <typename Derived> 3826 bool RecursiveASTVisitor<Derived>::VisitOMPDetachClause(OMPDetachClause *C) { 3827 TRY_TO(TraverseStmt(C->getEventHandler())); 3828 return true; 3829 } 3830 3831 template <typename Derived> 3832 bool RecursiveASTVisitor<Derived>::VisitOMPUsesAllocatorsClause( 3833 OMPUsesAllocatorsClause *C) { 3834 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) { 3835 const OMPUsesAllocatorsClause::Data Data = C->getAllocatorData(I); 3836 TRY_TO(TraverseStmt(Data.Allocator)); 3837 TRY_TO(TraverseStmt(Data.AllocatorTraits)); 3838 } 3839 return true; 3840 } 3841 3842 template <typename Derived> 3843 bool RecursiveASTVisitor<Derived>::VisitOMPAffinityClause( 3844 OMPAffinityClause *C) { 3845 TRY_TO(TraverseStmt(C->getModifier())); 3846 for (Expr *E : C->varlists()) 3847 TRY_TO(TraverseStmt(E)); 3848 return true; 3849 } 3850 3851 template <typename Derived> 3852 bool RecursiveASTVisitor<Derived>::VisitOMPFilterClause(OMPFilterClause *C) { 3853 TRY_TO(VisitOMPClauseWithPreInit(C)); 3854 TRY_TO(TraverseStmt(C->getThreadID())); 3855 return true; 3856 } 3857 3858 template <typename Derived> 3859 bool RecursiveASTVisitor<Derived>::VisitOMPBindClause(OMPBindClause *C) { 3860 return true; 3861 } 3862 3863 template <typename Derived> 3864 bool RecursiveASTVisitor<Derived>::VisitOMPXDynCGroupMemClause( 3865 OMPXDynCGroupMemClause *C) { 3866 TRY_TO(VisitOMPClauseWithPreInit(C)); 3867 TRY_TO(TraverseStmt(C->getSize())); 3868 return true; 3869 } 3870 3871 template <typename Derived> 3872 bool RecursiveASTVisitor<Derived>::VisitOMPDoacrossClause( 3873 OMPDoacrossClause *C) { 3874 TRY_TO(VisitOMPClauseList(C)); 3875 return true; 3876 } 3877 3878 // FIXME: look at the following tricky-seeming exprs to see if we 3879 // need to recurse on anything. These are ones that have methods 3880 // returning decls or qualtypes or nestednamespecifier -- though I'm 3881 // not sure if they own them -- or just seemed very complicated, or 3882 // had lots of sub-types to explore. 3883 // 3884 // VisitOverloadExpr and its children: recurse on template args? etc? 3885 3886 // FIXME: go through all the stmts and exprs again, and see which of them 3887 // create new types, and recurse on the types (TypeLocs?) of those. 3888 // Candidates: 3889 // 3890 // http://clang.llvm.org/doxygen/classclang_1_1CXXTypeidExpr.html 3891 // http://clang.llvm.org/doxygen/classclang_1_1UnaryExprOrTypeTraitExpr.html 3892 // http://clang.llvm.org/doxygen/classclang_1_1TypesCompatibleExpr.html 3893 // Every class that has getQualifier. 3894 3895 #undef DEF_TRAVERSE_STMT 3896 #undef TRAVERSE_STMT 3897 #undef TRAVERSE_STMT_BASE 3898 3899 #undef TRY_TO 3900 3901 } // end namespace clang 3902 3903 #endif // LLVM_CLANG_AST_RECURSIVEASTVISITOR_H 3904