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