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