1 //===- ASTMatchersInternal.cpp - Structural query framework ---------------===// 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 // Implements the base layer of the matcher framework. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "clang/ASTMatchers/ASTMatchersInternal.h" 14 #include "clang/AST/ASTContext.h" 15 #include "clang/AST/ASTTypeTraits.h" 16 #include "clang/AST/Decl.h" 17 #include "clang/AST/DeclTemplate.h" 18 #include "clang/AST/PrettyPrinter.h" 19 #include "clang/ASTMatchers/ASTMatchers.h" 20 #include "clang/Basic/LLVM.h" 21 #include "llvm/ADT/ArrayRef.h" 22 #include "llvm/ADT/IntrusiveRefCntPtr.h" 23 #include "llvm/ADT/None.h" 24 #include "llvm/ADT/SmallString.h" 25 #include "llvm/ADT/SmallVector.h" 26 #include "llvm/ADT/StringRef.h" 27 #include "llvm/Support/Casting.h" 28 #include "llvm/Support/ErrorHandling.h" 29 #include "llvm/Support/ManagedStatic.h" 30 #include "llvm/Support/raw_ostream.h" 31 #include <algorithm> 32 #include <cassert> 33 #include <cstddef> 34 #include <string> 35 #include <utility> 36 #include <vector> 37 38 namespace clang { 39 namespace ast_matchers { 40 41 AST_MATCHER_P(ObjCMessageExpr, hasAnySelectorMatcher, std::vector<std::string>, 42 Matches) { 43 std::string SelString = Node.getSelector().getAsString(); 44 for (const std::string &S : Matches) 45 if (S == SelString) 46 return true; 47 return false; 48 } 49 50 namespace internal { 51 52 bool NotUnaryOperator(const ast_type_traits::DynTypedNode &DynNode, 53 ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, 54 ArrayRef<DynTypedMatcher> InnerMatchers); 55 56 bool AllOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, 57 ASTMatchFinder *Finder, 58 BoundNodesTreeBuilder *Builder, 59 ArrayRef<DynTypedMatcher> InnerMatchers); 60 61 bool EachOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, 62 ASTMatchFinder *Finder, 63 BoundNodesTreeBuilder *Builder, 64 ArrayRef<DynTypedMatcher> InnerMatchers); 65 66 bool AnyOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, 67 ASTMatchFinder *Finder, 68 BoundNodesTreeBuilder *Builder, 69 ArrayRef<DynTypedMatcher> InnerMatchers); 70 71 bool OptionallyVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, 72 ASTMatchFinder *Finder, 73 BoundNodesTreeBuilder *Builder, 74 ArrayRef<DynTypedMatcher> InnerMatchers); 75 76 void BoundNodesTreeBuilder::visitMatches(Visitor *ResultVisitor) { 77 if (Bindings.empty()) 78 Bindings.push_back(BoundNodesMap()); 79 for (BoundNodesMap &Binding : Bindings) { 80 ResultVisitor->visitMatch(BoundNodes(Binding)); 81 } 82 } 83 84 namespace { 85 86 using VariadicOperatorFunction = bool (*)( 87 const ast_type_traits::DynTypedNode &DynNode, ASTMatchFinder *Finder, 88 BoundNodesTreeBuilder *Builder, ArrayRef<DynTypedMatcher> InnerMatchers); 89 90 template <VariadicOperatorFunction Func> 91 class VariadicMatcher : public DynMatcherInterface { 92 public: 93 VariadicMatcher(std::vector<DynTypedMatcher> InnerMatchers) 94 : InnerMatchers(std::move(InnerMatchers)) {} 95 96 bool dynMatches(const ast_type_traits::DynTypedNode &DynNode, 97 ASTMatchFinder *Finder, 98 BoundNodesTreeBuilder *Builder) const override { 99 return Func(DynNode, Finder, Builder, InnerMatchers); 100 } 101 102 private: 103 std::vector<DynTypedMatcher> InnerMatchers; 104 }; 105 106 class IdDynMatcher : public DynMatcherInterface { 107 public: 108 IdDynMatcher(StringRef ID, 109 IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher) 110 : ID(ID), InnerMatcher(std::move(InnerMatcher)) {} 111 112 bool dynMatches(const ast_type_traits::DynTypedNode &DynNode, 113 ASTMatchFinder *Finder, 114 BoundNodesTreeBuilder *Builder) const override { 115 bool Result = InnerMatcher->dynMatches(DynNode, Finder, Builder); 116 if (Result) Builder->setBinding(ID, DynNode); 117 return Result; 118 } 119 120 llvm::Optional<ast_type_traits::TraversalKind> 121 TraversalKind() const override { 122 return InnerMatcher->TraversalKind(); 123 } 124 125 private: 126 const std::string ID; 127 const IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher; 128 }; 129 130 /// A matcher that always returns true. 131 /// 132 /// We only ever need one instance of this matcher, so we create a global one 133 /// and reuse it to reduce the overhead of the matcher and increase the chance 134 /// of cache hits. 135 class TrueMatcherImpl : public DynMatcherInterface { 136 public: 137 TrueMatcherImpl() { 138 Retain(); // Reference count will never become zero. 139 } 140 141 bool dynMatches(const ast_type_traits::DynTypedNode &, ASTMatchFinder *, 142 BoundNodesTreeBuilder *) const override { 143 return true; 144 } 145 }; 146 147 } // namespace 148 149 static llvm::ManagedStatic<TrueMatcherImpl> TrueMatcherInstance; 150 151 DynTypedMatcher DynTypedMatcher::constructVariadic( 152 DynTypedMatcher::VariadicOperator Op, 153 ast_type_traits::ASTNodeKind SupportedKind, 154 std::vector<DynTypedMatcher> InnerMatchers) { 155 assert(!InnerMatchers.empty() && "Array must not be empty."); 156 assert(llvm::all_of(InnerMatchers, 157 [SupportedKind](const DynTypedMatcher &M) { 158 return M.canConvertTo(SupportedKind); 159 }) && 160 "InnerMatchers must be convertible to SupportedKind!"); 161 162 // We must relax the restrict kind here. 163 // The different operators might deal differently with a mismatch. 164 // Make it the same as SupportedKind, since that is the broadest type we are 165 // allowed to accept. 166 auto RestrictKind = SupportedKind; 167 168 switch (Op) { 169 case VO_AllOf: 170 // In the case of allOf() we must pass all the checks, so making 171 // RestrictKind the most restrictive can save us time. This way we reject 172 // invalid types earlier and we can elide the kind checks inside the 173 // matcher. 174 for (auto &IM : InnerMatchers) { 175 RestrictKind = ast_type_traits::ASTNodeKind::getMostDerivedType( 176 RestrictKind, IM.RestrictKind); 177 } 178 return DynTypedMatcher( 179 SupportedKind, RestrictKind, 180 new VariadicMatcher<AllOfVariadicOperator>(std::move(InnerMatchers))); 181 182 case VO_AnyOf: 183 return DynTypedMatcher( 184 SupportedKind, RestrictKind, 185 new VariadicMatcher<AnyOfVariadicOperator>(std::move(InnerMatchers))); 186 187 case VO_EachOf: 188 return DynTypedMatcher( 189 SupportedKind, RestrictKind, 190 new VariadicMatcher<EachOfVariadicOperator>(std::move(InnerMatchers))); 191 192 case VO_Optionally: 193 return DynTypedMatcher(SupportedKind, RestrictKind, 194 new VariadicMatcher<OptionallyVariadicOperator>( 195 std::move(InnerMatchers))); 196 197 case VO_UnaryNot: 198 // FIXME: Implement the Not operator to take a single matcher instead of a 199 // vector. 200 return DynTypedMatcher( 201 SupportedKind, RestrictKind, 202 new VariadicMatcher<NotUnaryOperator>(std::move(InnerMatchers))); 203 } 204 llvm_unreachable("Invalid Op value."); 205 } 206 207 DynTypedMatcher DynTypedMatcher::constructRestrictedWrapper( 208 const DynTypedMatcher &InnerMatcher, 209 ast_type_traits::ASTNodeKind RestrictKind) { 210 DynTypedMatcher Copy = InnerMatcher; 211 Copy.RestrictKind = RestrictKind; 212 return Copy; 213 } 214 215 DynTypedMatcher DynTypedMatcher::trueMatcher( 216 ast_type_traits::ASTNodeKind NodeKind) { 217 return DynTypedMatcher(NodeKind, NodeKind, &*TrueMatcherInstance); 218 } 219 220 bool DynTypedMatcher::canMatchNodesOfKind( 221 ast_type_traits::ASTNodeKind Kind) const { 222 return RestrictKind.isBaseOf(Kind); 223 } 224 225 DynTypedMatcher DynTypedMatcher::dynCastTo( 226 const ast_type_traits::ASTNodeKind Kind) const { 227 auto Copy = *this; 228 Copy.SupportedKind = Kind; 229 Copy.RestrictKind = 230 ast_type_traits::ASTNodeKind::getMostDerivedType(Kind, RestrictKind); 231 return Copy; 232 } 233 234 bool DynTypedMatcher::matches(const ast_type_traits::DynTypedNode &DynNode, 235 ASTMatchFinder *Finder, 236 BoundNodesTreeBuilder *Builder) const { 237 TraversalKindScope RAII(Finder->getASTContext(), 238 Implementation->TraversalKind()); 239 240 auto N = Finder->getASTContext().traverseIgnored(DynNode); 241 242 if (RestrictKind.isBaseOf(N.getNodeKind()) && 243 Implementation->dynMatches(N, Finder, Builder)) { 244 return true; 245 } 246 // Delete all bindings when a matcher does not match. 247 // This prevents unexpected exposure of bound nodes in unmatches 248 // branches of the match tree. 249 Builder->removeBindings([](const BoundNodesMap &) { return true; }); 250 return false; 251 } 252 253 bool DynTypedMatcher::matchesNoKindCheck( 254 const ast_type_traits::DynTypedNode &DynNode, ASTMatchFinder *Finder, 255 BoundNodesTreeBuilder *Builder) const { 256 TraversalKindScope raii(Finder->getASTContext(), 257 Implementation->TraversalKind()); 258 259 auto N = Finder->getASTContext().traverseIgnored(DynNode); 260 261 assert(RestrictKind.isBaseOf(N.getNodeKind())); 262 if (Implementation->dynMatches(N, Finder, Builder)) { 263 return true; 264 } 265 // Delete all bindings when a matcher does not match. 266 // This prevents unexpected exposure of bound nodes in unmatches 267 // branches of the match tree. 268 Builder->removeBindings([](const BoundNodesMap &) { return true; }); 269 return false; 270 } 271 272 llvm::Optional<DynTypedMatcher> DynTypedMatcher::tryBind(StringRef ID) const { 273 if (!AllowBind) return llvm::None; 274 auto Result = *this; 275 Result.Implementation = 276 new IdDynMatcher(ID, std::move(Result.Implementation)); 277 return std::move(Result); 278 } 279 280 bool DynTypedMatcher::canConvertTo(ast_type_traits::ASTNodeKind To) const { 281 const auto From = getSupportedKind(); 282 auto QualKind = ast_type_traits::ASTNodeKind::getFromNodeKind<QualType>(); 283 auto TypeKind = ast_type_traits::ASTNodeKind::getFromNodeKind<Type>(); 284 /// Mimic the implicit conversions of Matcher<>. 285 /// - From Matcher<Type> to Matcher<QualType> 286 if (From.isSame(TypeKind) && To.isSame(QualKind)) return true; 287 /// - From Matcher<Base> to Matcher<Derived> 288 return From.isBaseOf(To); 289 } 290 291 void BoundNodesTreeBuilder::addMatch(const BoundNodesTreeBuilder &Other) { 292 Bindings.append(Other.Bindings.begin(), Other.Bindings.end()); 293 } 294 295 bool NotUnaryOperator(const ast_type_traits::DynTypedNode &DynNode, 296 ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, 297 ArrayRef<DynTypedMatcher> InnerMatchers) { 298 if (InnerMatchers.size() != 1) 299 return false; 300 301 // The 'unless' matcher will always discard the result: 302 // If the inner matcher doesn't match, unless returns true, 303 // but the inner matcher cannot have bound anything. 304 // If the inner matcher matches, the result is false, and 305 // any possible binding will be discarded. 306 // We still need to hand in all the bound nodes up to this 307 // point so the inner matcher can depend on bound nodes, 308 // and we need to actively discard the bound nodes, otherwise 309 // the inner matcher will reset the bound nodes if it doesn't 310 // match, but this would be inversed by 'unless'. 311 BoundNodesTreeBuilder Discard(*Builder); 312 return !InnerMatchers[0].matches(DynNode, Finder, &Discard); 313 } 314 315 bool AllOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, 316 ASTMatchFinder *Finder, 317 BoundNodesTreeBuilder *Builder, 318 ArrayRef<DynTypedMatcher> InnerMatchers) { 319 // allOf leads to one matcher for each alternative in the first 320 // matcher combined with each alternative in the second matcher. 321 // Thus, we can reuse the same Builder. 322 for (const DynTypedMatcher &InnerMatcher : InnerMatchers) { 323 if (!InnerMatcher.matchesNoKindCheck(DynNode, Finder, Builder)) 324 return false; 325 } 326 return true; 327 } 328 329 bool EachOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, 330 ASTMatchFinder *Finder, 331 BoundNodesTreeBuilder *Builder, 332 ArrayRef<DynTypedMatcher> InnerMatchers) { 333 BoundNodesTreeBuilder Result; 334 bool Matched = false; 335 for (const DynTypedMatcher &InnerMatcher : InnerMatchers) { 336 BoundNodesTreeBuilder BuilderInner(*Builder); 337 if (InnerMatcher.matches(DynNode, Finder, &BuilderInner)) { 338 Matched = true; 339 Result.addMatch(BuilderInner); 340 } 341 } 342 *Builder = std::move(Result); 343 return Matched; 344 } 345 346 bool AnyOfVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, 347 ASTMatchFinder *Finder, 348 BoundNodesTreeBuilder *Builder, 349 ArrayRef<DynTypedMatcher> InnerMatchers) { 350 for (const DynTypedMatcher &InnerMatcher : InnerMatchers) { 351 BoundNodesTreeBuilder Result = *Builder; 352 if (InnerMatcher.matches(DynNode, Finder, &Result)) { 353 *Builder = std::move(Result); 354 return true; 355 } 356 } 357 return false; 358 } 359 360 bool OptionallyVariadicOperator(const ast_type_traits::DynTypedNode &DynNode, 361 ASTMatchFinder *Finder, 362 BoundNodesTreeBuilder *Builder, 363 ArrayRef<DynTypedMatcher> InnerMatchers) { 364 BoundNodesTreeBuilder Result; 365 for (const DynTypedMatcher &InnerMatcher : InnerMatchers) { 366 BoundNodesTreeBuilder BuilderInner(*Builder); 367 if (InnerMatcher.matches(DynNode, Finder, &BuilderInner)) 368 Result.addMatch(BuilderInner); 369 } 370 *Builder = std::move(Result); 371 return true; 372 } 373 374 inline static 375 std::vector<std::string> vectorFromRefs(ArrayRef<const StringRef *> NameRefs) { 376 std::vector<std::string> Names; 377 for (auto *Name : NameRefs) 378 Names.emplace_back(*Name); 379 return Names; 380 } 381 382 Matcher<NamedDecl> hasAnyNameFunc(ArrayRef<const StringRef *> NameRefs) { 383 std::vector<std::string> Names = vectorFromRefs(NameRefs); 384 return internal::Matcher<NamedDecl>(new internal::HasNameMatcher(Names)); 385 } 386 387 Matcher<ObjCMessageExpr> hasAnySelectorFunc( 388 ArrayRef<const StringRef *> NameRefs) { 389 return hasAnySelectorMatcher(vectorFromRefs(NameRefs)); 390 } 391 392 HasNameMatcher::HasNameMatcher(std::vector<std::string> N) 393 : UseUnqualifiedMatch(std::all_of( 394 N.begin(), N.end(), 395 [](StringRef Name) { return Name.find("::") == Name.npos; })), 396 Names(std::move(N)) { 397 #ifndef NDEBUG 398 for (StringRef Name : Names) 399 assert(!Name.empty()); 400 #endif 401 } 402 403 static bool consumeNameSuffix(StringRef &FullName, StringRef Suffix) { 404 StringRef Name = FullName; 405 if (!Name.endswith(Suffix)) 406 return false; 407 Name = Name.drop_back(Suffix.size()); 408 if (!Name.empty()) { 409 if (!Name.endswith("::")) 410 return false; 411 Name = Name.drop_back(2); 412 } 413 FullName = Name; 414 return true; 415 } 416 417 static StringRef getNodeName(const NamedDecl &Node, 418 llvm::SmallString<128> &Scratch) { 419 // Simple name. 420 if (Node.getIdentifier()) 421 return Node.getName(); 422 423 if (Node.getDeclName()) { 424 // Name needs to be constructed. 425 Scratch.clear(); 426 llvm::raw_svector_ostream OS(Scratch); 427 Node.printName(OS); 428 return OS.str(); 429 } 430 431 return "(anonymous)"; 432 } 433 434 static StringRef getNodeName(const RecordDecl &Node, 435 llvm::SmallString<128> &Scratch) { 436 if (Node.getIdentifier()) { 437 return Node.getName(); 438 } 439 Scratch.clear(); 440 return ("(anonymous " + Node.getKindName() + ")").toStringRef(Scratch); 441 } 442 443 static StringRef getNodeName(const NamespaceDecl &Node, 444 llvm::SmallString<128> &Scratch) { 445 return Node.isAnonymousNamespace() ? "(anonymous namespace)" : Node.getName(); 446 } 447 448 namespace { 449 450 class PatternSet { 451 public: 452 PatternSet(ArrayRef<std::string> Names) { 453 for (StringRef Name : Names) 454 Patterns.push_back({Name, Name.startswith("::")}); 455 } 456 457 /// Consumes the name suffix from each pattern in the set and removes the ones 458 /// that didn't match. 459 /// Return true if there are still any patterns left. 460 bool consumeNameSuffix(StringRef NodeName, bool CanSkip) { 461 for (size_t I = 0; I < Patterns.size();) { 462 if (::clang::ast_matchers::internal::consumeNameSuffix(Patterns[I].P, 463 NodeName) || 464 CanSkip) { 465 ++I; 466 } else { 467 Patterns.erase(Patterns.begin() + I); 468 } 469 } 470 return !Patterns.empty(); 471 } 472 473 /// Check if any of the patterns are a match. 474 /// A match will be a pattern that was fully consumed, that also matches the 475 /// 'fully qualified' requirement. 476 bool foundMatch(bool AllowFullyQualified) const { 477 for (auto& P: Patterns) 478 if (P.P.empty() && (AllowFullyQualified || !P.IsFullyQualified)) 479 return true; 480 return false; 481 } 482 483 private: 484 struct Pattern { 485 StringRef P; 486 bool IsFullyQualified; 487 }; 488 489 llvm::SmallVector<Pattern, 8> Patterns; 490 }; 491 492 } // namespace 493 494 bool HasNameMatcher::matchesNodeUnqualified(const NamedDecl &Node) const { 495 assert(UseUnqualifiedMatch); 496 llvm::SmallString<128> Scratch; 497 StringRef NodeName = getNodeName(Node, Scratch); 498 return llvm::any_of(Names, [&](StringRef Name) { 499 return consumeNameSuffix(Name, NodeName) && Name.empty(); 500 }); 501 } 502 503 bool HasNameMatcher::matchesNodeFullFast(const NamedDecl &Node) const { 504 PatternSet Patterns(Names); 505 llvm::SmallString<128> Scratch; 506 507 // This function is copied and adapted from NamedDecl::printQualifiedName() 508 // By matching each part individually we optimize in a couple of ways: 509 // - We can exit early on the first failure. 510 // - We can skip inline/anonymous namespaces without another pass. 511 // - We print one name at a time, reducing the chance of overflowing the 512 // inlined space of the SmallString. 513 514 // First, match the name. 515 if (!Patterns.consumeNameSuffix(getNodeName(Node, Scratch), 516 /*CanSkip=*/false)) 517 return false; 518 519 // Try to match each declaration context. 520 // We are allowed to skip anonymous and inline namespaces if they don't match. 521 const DeclContext *Ctx = Node.getDeclContext(); 522 523 if (Ctx->isFunctionOrMethod()) 524 return Patterns.foundMatch(/*AllowFullyQualified=*/false); 525 526 for (; Ctx; Ctx = Ctx->getParent()) { 527 // Linkage Spec can just be ignored 528 // FIXME: Any other DeclContext kinds that can be safely disregarded 529 if (isa<LinkageSpecDecl>(Ctx)) 530 continue; 531 if (!isa<NamedDecl>(Ctx)) 532 break; 533 if (Patterns.foundMatch(/*AllowFullyQualified=*/false)) 534 return true; 535 536 if (const auto *ND = dyn_cast<NamespaceDecl>(Ctx)) { 537 // If it matches (or we can skip it), continue. 538 if (Patterns.consumeNameSuffix(getNodeName(*ND, Scratch), 539 /*CanSkip=*/ND->isAnonymousNamespace() || 540 ND->isInline())) 541 continue; 542 return false; 543 } 544 if (const auto *RD = dyn_cast<RecordDecl>(Ctx)) { 545 if (!isa<ClassTemplateSpecializationDecl>(Ctx)) { 546 if (Patterns.consumeNameSuffix(getNodeName(*RD, Scratch), 547 /*CanSkip=*/false)) 548 continue; 549 550 return false; 551 } 552 } 553 554 // We don't know how to deal with this DeclContext. 555 // Fallback to the slow version of the code. 556 return matchesNodeFullSlow(Node); 557 } 558 559 return Patterns.foundMatch(/*AllowFullyQualified=*/true); 560 } 561 562 bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const { 563 const bool SkipUnwrittenCases[] = {false, true}; 564 for (bool SkipUnwritten : SkipUnwrittenCases) { 565 llvm::SmallString<128> NodeName = StringRef("::"); 566 llvm::raw_svector_ostream OS(NodeName); 567 568 if (SkipUnwritten) { 569 PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy(); 570 Policy.SuppressUnwrittenScope = true; 571 Node.printQualifiedName(OS, Policy); 572 } else { 573 Node.printQualifiedName(OS); 574 } 575 576 const StringRef FullName = OS.str(); 577 578 for (const StringRef Pattern : Names) { 579 if (Pattern.startswith("::")) { 580 if (FullName == Pattern) 581 return true; 582 } else if (FullName.endswith(Pattern) && 583 FullName.drop_back(Pattern.size()).endswith("::")) { 584 return true; 585 } 586 } 587 } 588 589 return false; 590 } 591 592 bool HasNameMatcher::matchesNode(const NamedDecl &Node) const { 593 assert(matchesNodeFullFast(Node) == matchesNodeFullSlow(Node)); 594 if (UseUnqualifiedMatch) { 595 assert(matchesNodeUnqualified(Node) == matchesNodeFullFast(Node)); 596 return matchesNodeUnqualified(Node); 597 } 598 return matchesNodeFullFast(Node); 599 } 600 601 } // end namespace internal 602 603 const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAutoreleasePoolStmt> 604 autoreleasePoolStmt; 605 const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl> 606 translationUnitDecl; 607 const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl> typedefDecl; 608 const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl> 609 typedefNameDecl; 610 const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl> typeAliasDecl; 611 const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl> 612 typeAliasTemplateDecl; 613 const internal::VariadicAllOfMatcher<Decl> decl; 614 const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl> 615 linkageSpecDecl; 616 const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl; 617 const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl; 618 const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> namespaceDecl; 619 const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl> 620 namespaceAliasDecl; 621 const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl; 622 const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl> cxxRecordDecl; 623 const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl> 624 classTemplateDecl; 625 const internal::VariadicDynCastAllOfMatcher<Decl, 626 ClassTemplateSpecializationDecl> 627 classTemplateSpecializationDecl; 628 const internal::VariadicDynCastAllOfMatcher< 629 Decl, ClassTemplatePartialSpecializationDecl> 630 classTemplatePartialSpecializationDecl; 631 const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl> 632 declaratorDecl; 633 const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl> parmVarDecl; 634 const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl> 635 accessSpecDecl; 636 const internal::VariadicAllOfMatcher<CXXCtorInitializer> cxxCtorInitializer; 637 const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument; 638 const internal::VariadicAllOfMatcher<TemplateName> templateName; 639 const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl> 640 nonTypeTemplateParmDecl; 641 const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl> 642 templateTypeParmDecl; 643 const internal::VariadicAllOfMatcher<QualType> qualType; 644 const internal::VariadicAllOfMatcher<Type> type; 645 const internal::VariadicAllOfMatcher<TypeLoc> typeLoc; 646 const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryExprOrTypeTraitExpr> 647 unaryExprOrTypeTraitExpr; 648 const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl; 649 const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl> 650 cxxConstructorDecl; 651 const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl> 652 cxxDestructorDecl; 653 const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl; 654 const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl> 655 enumConstantDecl; 656 const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> cxxMethodDecl; 657 const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl> 658 cxxConversionDecl; 659 const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl; 660 const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl; 661 const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl> 662 indirectFieldDecl; 663 const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> functionDecl; 664 const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl> 665 functionTemplateDecl; 666 const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl; 667 const internal::VariadicAllOfMatcher<Stmt> stmt; 668 const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt; 669 const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr; 670 const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr> 671 unresolvedMemberExpr; 672 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDependentScopeMemberExpr> 673 cxxDependentScopeMemberExpr; 674 const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr; 675 const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr; 676 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr> 677 cxxMemberCallExpr; 678 const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr> 679 objcMessageExpr; 680 const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl> 681 objcInterfaceDecl; 682 const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl> 683 objcImplementationDecl; 684 const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl> 685 objcProtocolDecl; 686 const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl> 687 objcCategoryDecl; 688 const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl> 689 objcCategoryImplDecl; 690 const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl> 691 objcMethodDecl; 692 const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> 693 blockDecl; 694 const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl> objcIvarDecl; 695 const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl> 696 objcPropertyDecl; 697 const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt> 698 objcThrowStmt; 699 const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt> objcTryStmt; 700 const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt> 701 objcCatchStmt; 702 const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt> 703 objcFinallyStmt; 704 const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups> 705 exprWithCleanups; 706 const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> initListExpr; 707 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStdInitializerListExpr> 708 cxxStdInitializerListExpr; 709 const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr> 710 implicitValueInitExpr; 711 const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr> parenListExpr; 712 const internal::VariadicDynCastAllOfMatcher<Stmt, SubstNonTypeTemplateParmExpr> 713 substNonTypeTemplateParmExpr; 714 const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl; 715 const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl> 716 usingDirectiveDecl; 717 const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr> 718 unresolvedLookupExpr; 719 const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingValueDecl> 720 unresolvedUsingValueDecl; 721 const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingTypenameDecl> 722 unresolvedUsingTypenameDecl; 723 const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr> constantExpr; 724 const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr; 725 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr> 726 cxxConstructExpr; 727 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXUnresolvedConstructExpr> 728 cxxUnresolvedConstructExpr; 729 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> cxxThisExpr; 730 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr> 731 cxxBindTemporaryExpr; 732 const internal::VariadicDynCastAllOfMatcher<Stmt, MaterializeTemporaryExpr> 733 materializeTemporaryExpr; 734 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr; 735 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> cxxDeleteExpr; 736 const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr> 737 arraySubscriptExpr; 738 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr> 739 cxxDefaultArgExpr; 740 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr> 741 cxxOperatorCallExpr; 742 const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr; 743 const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr; 744 const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr> objcIvarRefExpr; 745 const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr; 746 const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt; 747 const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt; 748 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt> 749 cxxForRangeStmt; 750 const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt; 751 const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt; 752 const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt; 753 const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt> continueStmt; 754 const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt; 755 const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt; 756 const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt; 757 const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr> addrLabelExpr; 758 const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt; 759 const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase; 760 const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt; 761 const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt> defaultStmt; 762 const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> compoundStmt; 763 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> cxxCatchStmt; 764 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt; 765 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr; 766 const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt; 767 const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt; 768 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr> 769 cxxBoolLiteral; 770 const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral; 771 const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral> 772 characterLiteral; 773 const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral> 774 integerLiteral; 775 const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral; 776 const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> imaginaryLiteral; 777 const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral> 778 userDefinedLiteral; 779 const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr> 780 compoundLiteralExpr; 781 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr> 782 cxxNullPtrLiteralExpr; 783 const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> chooseExpr; 784 const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr> gnuNullExpr; 785 const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr; 786 const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr; 787 const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator> 788 binaryOperator; 789 const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator> unaryOperator; 790 const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator> 791 conditionalOperator; 792 const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryConditionalOperator> 793 binaryConditionalOperator; 794 const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr> 795 opaqueValueExpr; 796 const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl> 797 staticAssertDecl; 798 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr> 799 cxxReinterpretCastExpr; 800 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr> 801 cxxStaticCastExpr; 802 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr> 803 cxxDynamicCastExpr; 804 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr> 805 cxxConstCastExpr; 806 const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr> 807 cStyleCastExpr; 808 const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr> 809 explicitCastExpr; 810 const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr> 811 implicitCastExpr; 812 const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr; 813 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr> 814 cxxFunctionalCastExpr; 815 const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr> 816 cxxTemporaryObjectExpr; 817 const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr> 818 predefinedExpr; 819 const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr> 820 designatedInitExpr; 821 const internal::VariadicOperatorMatcherFunc< 822 2, std::numeric_limits<unsigned>::max()> 823 eachOf = {internal::DynTypedMatcher::VO_EachOf}; 824 const internal::VariadicOperatorMatcherFunc< 825 2, std::numeric_limits<unsigned>::max()> 826 anyOf = {internal::DynTypedMatcher::VO_AnyOf}; 827 const internal::VariadicOperatorMatcherFunc< 828 2, std::numeric_limits<unsigned>::max()> 829 allOf = {internal::DynTypedMatcher::VO_AllOf}; 830 const internal::VariadicOperatorMatcherFunc< 831 1, std::numeric_limits<unsigned>::max()> 832 optionally = {internal::DynTypedMatcher::VO_Optionally}; 833 const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef, 834 internal::hasAnyNameFunc> 835 hasAnyName = {}; 836 const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>, StringRef, 837 internal::hasAnySelectorFunc> 838 hasAnySelector = {}; 839 const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has = {}; 840 const internal::ArgumentAdaptingMatcherFunc<internal::HasDescendantMatcher> 841 hasDescendant = {}; 842 const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> forEach = 843 {}; 844 const internal::ArgumentAdaptingMatcherFunc<internal::ForEachDescendantMatcher> 845 forEachDescendant = {}; 846 const internal::ArgumentAdaptingMatcherFunc< 847 internal::HasParentMatcher, 848 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>, 849 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>> 850 hasParent = {}; 851 const internal::ArgumentAdaptingMatcherFunc< 852 internal::HasAncestorMatcher, 853 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>, 854 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>> 855 hasAncestor = {}; 856 const internal::VariadicOperatorMatcherFunc<1, 1> unless = { 857 internal::DynTypedMatcher::VO_UnaryNot}; 858 const internal::VariadicAllOfMatcher<NestedNameSpecifier> nestedNameSpecifier; 859 const internal::VariadicAllOfMatcher<NestedNameSpecifierLoc> 860 nestedNameSpecifierLoc; 861 const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr> 862 cudaKernelCallExpr; 863 const AstTypeMatcher<BuiltinType> builtinType; 864 const AstTypeMatcher<ArrayType> arrayType; 865 const AstTypeMatcher<ComplexType> complexType; 866 const AstTypeMatcher<ConstantArrayType> constantArrayType; 867 const AstTypeMatcher<DependentSizedArrayType> dependentSizedArrayType; 868 const AstTypeMatcher<IncompleteArrayType> incompleteArrayType; 869 const AstTypeMatcher<VariableArrayType> variableArrayType; 870 const AstTypeMatcher<AtomicType> atomicType; 871 const AstTypeMatcher<AutoType> autoType; 872 const AstTypeMatcher<DecltypeType> decltypeType; 873 const AstTypeMatcher<FunctionType> functionType; 874 const AstTypeMatcher<FunctionProtoType> functionProtoType; 875 const AstTypeMatcher<ParenType> parenType; 876 const AstTypeMatcher<BlockPointerType> blockPointerType; 877 const AstTypeMatcher<MemberPointerType> memberPointerType; 878 const AstTypeMatcher<PointerType> pointerType; 879 const AstTypeMatcher<ObjCObjectPointerType> objcObjectPointerType; 880 const AstTypeMatcher<ReferenceType> referenceType; 881 const AstTypeMatcher<LValueReferenceType> lValueReferenceType; 882 const AstTypeMatcher<RValueReferenceType> rValueReferenceType; 883 const AstTypeMatcher<TypedefType> typedefType; 884 const AstTypeMatcher<EnumType> enumType; 885 const AstTypeMatcher<TemplateSpecializationType> templateSpecializationType; 886 const AstTypeMatcher<UnaryTransformType> unaryTransformType; 887 const AstTypeMatcher<RecordType> recordType; 888 const AstTypeMatcher<TagType> tagType; 889 const AstTypeMatcher<ElaboratedType> elaboratedType; 890 const AstTypeMatcher<SubstTemplateTypeParmType> substTemplateTypeParmType; 891 const AstTypeMatcher<TemplateTypeParmType> templateTypeParmType; 892 const AstTypeMatcher<InjectedClassNameType> injectedClassNameType; 893 const AstTypeMatcher<DecayedType> decayedType; 894 AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType, 895 AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType, 896 ComplexType)); 897 AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasValueType, 898 AST_POLYMORPHIC_SUPPORTED_TYPES(AtomicType)); 899 AST_TYPELOC_TRAVERSE_MATCHER_DEF( 900 pointee, 901 AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType, 902 PointerType, ReferenceType)); 903 904 const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective> 905 ompExecutableDirective; 906 const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPDefaultClause> 907 ompDefaultClause; 908 const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl> 909 cxxDeductionGuideDecl; 910 911 } // end namespace ast_matchers 912 } // end namespace clang 913