1 //===- ASTMatchersInternal.cpp - Structural query framework ---------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Implements the base layer of the matcher framework.
11 //===----------------------------------------------------------------------===//
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/ParentMapContext.h"
19 #include "clang/AST/PrettyPrinter.h"
20 #include "clang/ASTMatchers/ASTMatchers.h"
21 #include "clang/Basic/LLVM.h"
22 #include "clang/Lex/Lexer.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/IntrusiveRefCntPtr.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/ADT/StringRef.h"
28 #include "llvm/Support/Casting.h"
29 #include "llvm/Support/ErrorHandling.h"
30 #include "llvm/Support/ManagedStatic.h"
31 #include "llvm/Support/Regex.h"
32 #include "llvm/Support/WithColor.h"
33 #include "llvm/Support/raw_ostream.h"
43 namespace ast_matchers
{
45 AST_MATCHER_P(ObjCMessageExpr
, hasAnySelectorMatcher
, std::vector
<std::string
>,
47 return llvm::is_contained(Matches
, Node
.getSelector().getAsString());
52 static bool notUnaryOperator(const DynTypedNode
&DynNode
,
53 ASTMatchFinder
*Finder
,
54 BoundNodesTreeBuilder
*Builder
,
55 ArrayRef
<DynTypedMatcher
> InnerMatchers
);
57 static bool allOfVariadicOperator(const DynTypedNode
&DynNode
,
58 ASTMatchFinder
*Finder
,
59 BoundNodesTreeBuilder
*Builder
,
60 ArrayRef
<DynTypedMatcher
> InnerMatchers
);
62 static bool eachOfVariadicOperator(const DynTypedNode
&DynNode
,
63 ASTMatchFinder
*Finder
,
64 BoundNodesTreeBuilder
*Builder
,
65 ArrayRef
<DynTypedMatcher
> InnerMatchers
);
67 static bool anyOfVariadicOperator(const DynTypedNode
&DynNode
,
68 ASTMatchFinder
*Finder
,
69 BoundNodesTreeBuilder
*Builder
,
70 ArrayRef
<DynTypedMatcher
> InnerMatchers
);
72 static bool optionallyVariadicOperator(const DynTypedNode
&DynNode
,
73 ASTMatchFinder
*Finder
,
74 BoundNodesTreeBuilder
*Builder
,
75 ArrayRef
<DynTypedMatcher
> InnerMatchers
);
77 bool matchesAnyBase(const CXXRecordDecl
&Node
,
78 const Matcher
<CXXBaseSpecifier
> &BaseSpecMatcher
,
79 ASTMatchFinder
*Finder
, BoundNodesTreeBuilder
*Builder
) {
80 if (!Node
.hasDefinition())
84 Paths
.setOrigin(&Node
);
86 const auto basePredicate
=
87 [Finder
, Builder
, &BaseSpecMatcher
](const CXXBaseSpecifier
*BaseSpec
,
88 CXXBasePath
&IgnoredParam
) {
89 BoundNodesTreeBuilder
Result(*Builder
);
90 if (BaseSpecMatcher
.matches(*BaseSpec
, Finder
, &Result
)) {
91 *Builder
= std::move(Result
);
97 return Node
.lookupInBases(basePredicate
, Paths
,
98 /*LookupInDependent =*/true);
101 void BoundNodesTreeBuilder::visitMatches(Visitor
*ResultVisitor
) {
102 if (Bindings
.empty())
103 Bindings
.push_back(BoundNodesMap());
104 for (BoundNodesMap
&Binding
: Bindings
) {
105 ResultVisitor
->visitMatch(BoundNodes(Binding
));
111 using VariadicOperatorFunction
= bool (*)(
112 const DynTypedNode
&DynNode
, ASTMatchFinder
*Finder
,
113 BoundNodesTreeBuilder
*Builder
, ArrayRef
<DynTypedMatcher
> InnerMatchers
);
115 template <VariadicOperatorFunction Func
>
116 class VariadicMatcher
: public DynMatcherInterface
{
118 VariadicMatcher(std::vector
<DynTypedMatcher
> InnerMatchers
)
119 : InnerMatchers(std::move(InnerMatchers
)) {}
121 bool dynMatches(const DynTypedNode
&DynNode
, ASTMatchFinder
*Finder
,
122 BoundNodesTreeBuilder
*Builder
) const override
{
123 return Func(DynNode
, Finder
, Builder
, InnerMatchers
);
127 std::vector
<DynTypedMatcher
> InnerMatchers
;
130 class IdDynMatcher
: public DynMatcherInterface
{
132 IdDynMatcher(StringRef ID
,
133 IntrusiveRefCntPtr
<DynMatcherInterface
> InnerMatcher
)
134 : ID(ID
), InnerMatcher(std::move(InnerMatcher
)) {}
136 bool dynMatches(const DynTypedNode
&DynNode
, ASTMatchFinder
*Finder
,
137 BoundNodesTreeBuilder
*Builder
) const override
{
138 bool Result
= InnerMatcher
->dynMatches(DynNode
, Finder
, Builder
);
139 if (Result
) Builder
->setBinding(ID
, DynNode
);
143 std::optional
<clang::TraversalKind
> TraversalKind() const override
{
144 return InnerMatcher
->TraversalKind();
148 const std::string ID
;
149 const IntrusiveRefCntPtr
<DynMatcherInterface
> InnerMatcher
;
152 /// A matcher that always returns true.
153 class TrueMatcherImpl
: public DynMatcherInterface
{
155 TrueMatcherImpl() = default;
157 bool dynMatches(const DynTypedNode
&, ASTMatchFinder
*,
158 BoundNodesTreeBuilder
*) const override
{
163 /// A matcher that specifies a particular \c TraversalKind.
165 /// The kind provided to the constructor overrides any kind that may be
166 /// specified by the `InnerMatcher`.
167 class DynTraversalMatcherImpl
: public DynMatcherInterface
{
169 explicit DynTraversalMatcherImpl(
170 clang::TraversalKind TK
,
171 IntrusiveRefCntPtr
<DynMatcherInterface
> InnerMatcher
)
172 : TK(TK
), InnerMatcher(std::move(InnerMatcher
)) {}
174 bool dynMatches(const DynTypedNode
&DynNode
, ASTMatchFinder
*Finder
,
175 BoundNodesTreeBuilder
*Builder
) const override
{
176 return this->InnerMatcher
->dynMatches(DynNode
, Finder
, Builder
);
179 std::optional
<clang::TraversalKind
> TraversalKind() const override
{
184 clang::TraversalKind TK
;
185 IntrusiveRefCntPtr
<DynMatcherInterface
> InnerMatcher
;
190 bool ASTMatchFinder::isTraversalIgnoringImplicitNodes() const {
191 return getASTContext().getParentMapContext().getTraversalKind() ==
192 TK_IgnoreUnlessSpelledInSource
;
196 DynTypedMatcher::constructVariadic(DynTypedMatcher::VariadicOperator Op
,
197 ASTNodeKind SupportedKind
,
198 std::vector
<DynTypedMatcher
> InnerMatchers
) {
199 assert(!InnerMatchers
.empty() && "Array must not be empty.");
200 assert(llvm::all_of(InnerMatchers
,
201 [SupportedKind
](const DynTypedMatcher
&M
) {
202 return M
.canConvertTo(SupportedKind
);
204 "InnerMatchers must be convertible to SupportedKind!");
206 // We must relax the restrict kind here.
207 // The different operators might deal differently with a mismatch.
208 // Make it the same as SupportedKind, since that is the broadest type we are
209 // allowed to accept.
210 auto RestrictKind
= SupportedKind
;
214 // In the case of allOf() we must pass all the checks, so making
215 // RestrictKind the most restrictive can save us time. This way we reject
216 // invalid types earlier and we can elide the kind checks inside the
218 for (auto &IM
: InnerMatchers
) {
220 ASTNodeKind::getMostDerivedType(RestrictKind
, IM
.RestrictKind
);
222 return DynTypedMatcher(
223 SupportedKind
, RestrictKind
,
224 new VariadicMatcher
<allOfVariadicOperator
>(std::move(InnerMatchers
)));
227 return DynTypedMatcher(
228 SupportedKind
, RestrictKind
,
229 new VariadicMatcher
<anyOfVariadicOperator
>(std::move(InnerMatchers
)));
232 return DynTypedMatcher(
233 SupportedKind
, RestrictKind
,
234 new VariadicMatcher
<eachOfVariadicOperator
>(std::move(InnerMatchers
)));
237 return DynTypedMatcher(SupportedKind
, RestrictKind
,
238 new VariadicMatcher
<optionallyVariadicOperator
>(
239 std::move(InnerMatchers
)));
242 // FIXME: Implement the Not operator to take a single matcher instead of a
244 return DynTypedMatcher(
245 SupportedKind
, RestrictKind
,
246 new VariadicMatcher
<notUnaryOperator
>(std::move(InnerMatchers
)));
248 llvm_unreachable("Invalid Op value.");
252 DynTypedMatcher::constructRestrictedWrapper(const DynTypedMatcher
&InnerMatcher
,
253 ASTNodeKind RestrictKind
) {
254 DynTypedMatcher Copy
= InnerMatcher
;
255 Copy
.RestrictKind
= RestrictKind
;
259 DynTypedMatcher
DynTypedMatcher::withTraversalKind(TraversalKind TK
) {
261 Copy
.Implementation
=
262 new DynTraversalMatcherImpl(TK
, std::move(Copy
.Implementation
));
266 DynTypedMatcher
DynTypedMatcher::trueMatcher(ASTNodeKind NodeKind
) {
267 // We only ever need one instance of TrueMatcherImpl, so we create a static
268 // instance and reuse it to reduce the overhead of the matcher and increase
269 // the chance of cache hits.
270 static const llvm::IntrusiveRefCntPtr
<TrueMatcherImpl
> Instance
=
271 new TrueMatcherImpl();
272 return DynTypedMatcher(NodeKind
, NodeKind
, Instance
);
275 bool DynTypedMatcher::canMatchNodesOfKind(ASTNodeKind Kind
) const {
276 return RestrictKind
.isBaseOf(Kind
);
279 DynTypedMatcher
DynTypedMatcher::dynCastTo(const ASTNodeKind Kind
) const {
281 Copy
.SupportedKind
= Kind
;
282 Copy
.RestrictKind
= ASTNodeKind::getMostDerivedType(Kind
, RestrictKind
);
286 bool DynTypedMatcher::matches(const DynTypedNode
&DynNode
,
287 ASTMatchFinder
*Finder
,
288 BoundNodesTreeBuilder
*Builder
) const {
289 TraversalKindScope
RAII(Finder
->getASTContext(),
290 Implementation
->TraversalKind());
292 if (Finder
->isTraversalIgnoringImplicitNodes() &&
293 Finder
->IsMatchingInASTNodeNotSpelledInSource())
296 if (!Finder
->isTraversalIgnoringImplicitNodes() &&
297 Finder
->IsMatchingInASTNodeNotAsIs())
301 Finder
->getASTContext().getParentMapContext().traverseIgnored(DynNode
);
303 if (RestrictKind
.isBaseOf(N
.getNodeKind()) &&
304 Implementation
->dynMatches(N
, Finder
, Builder
)) {
307 // Delete all bindings when a matcher does not match.
308 // This prevents unexpected exposure of bound nodes in unmatches
309 // branches of the match tree.
310 Builder
->removeBindings([](const BoundNodesMap
&) { return true; });
314 bool DynTypedMatcher::matchesNoKindCheck(const DynTypedNode
&DynNode
,
315 ASTMatchFinder
*Finder
,
316 BoundNodesTreeBuilder
*Builder
) const {
317 TraversalKindScope
raii(Finder
->getASTContext(),
318 Implementation
->TraversalKind());
320 if (Finder
->isTraversalIgnoringImplicitNodes() &&
321 Finder
->IsMatchingInASTNodeNotSpelledInSource())
324 if (!Finder
->isTraversalIgnoringImplicitNodes() &&
325 Finder
->IsMatchingInASTNodeNotAsIs())
329 Finder
->getASTContext().getParentMapContext().traverseIgnored(DynNode
);
331 assert(RestrictKind
.isBaseOf(N
.getNodeKind()));
332 if (Implementation
->dynMatches(N
, Finder
, Builder
)) {
335 // Delete all bindings when a matcher does not match.
336 // This prevents unexpected exposure of bound nodes in unmatches
337 // branches of the match tree.
338 Builder
->removeBindings([](const BoundNodesMap
&) { return true; });
342 std::optional
<DynTypedMatcher
> DynTypedMatcher::tryBind(StringRef ID
) const {
346 Result
.Implementation
=
347 new IdDynMatcher(ID
, std::move(Result
.Implementation
));
348 return std::move(Result
);
351 bool DynTypedMatcher::canConvertTo(ASTNodeKind To
) const {
352 const auto From
= getSupportedKind();
353 auto QualKind
= ASTNodeKind::getFromNodeKind
<QualType
>();
354 auto TypeKind
= ASTNodeKind::getFromNodeKind
<Type
>();
355 /// Mimic the implicit conversions of Matcher<>.
356 /// - From Matcher<Type> to Matcher<QualType>
357 if (From
.isSame(TypeKind
) && To
.isSame(QualKind
)) return true;
358 /// - From Matcher<Base> to Matcher<Derived>
359 return From
.isBaseOf(To
);
362 void BoundNodesTreeBuilder::addMatch(const BoundNodesTreeBuilder
&Other
) {
363 Bindings
.append(Other
.Bindings
.begin(), Other
.Bindings
.end());
366 static bool notUnaryOperator(const DynTypedNode
&DynNode
,
367 ASTMatchFinder
*Finder
,
368 BoundNodesTreeBuilder
*Builder
,
369 ArrayRef
<DynTypedMatcher
> InnerMatchers
) {
370 if (InnerMatchers
.size() != 1)
373 // The 'unless' matcher will always discard the result:
374 // If the inner matcher doesn't match, unless returns true,
375 // but the inner matcher cannot have bound anything.
376 // If the inner matcher matches, the result is false, and
377 // any possible binding will be discarded.
378 // We still need to hand in all the bound nodes up to this
379 // point so the inner matcher can depend on bound nodes,
380 // and we need to actively discard the bound nodes, otherwise
381 // the inner matcher will reset the bound nodes if it doesn't
382 // match, but this would be inversed by 'unless'.
383 BoundNodesTreeBuilder
Discard(*Builder
);
384 return !InnerMatchers
[0].matches(DynNode
, Finder
, &Discard
);
387 static bool allOfVariadicOperator(const DynTypedNode
&DynNode
,
388 ASTMatchFinder
*Finder
,
389 BoundNodesTreeBuilder
*Builder
,
390 ArrayRef
<DynTypedMatcher
> InnerMatchers
) {
391 // allOf leads to one matcher for each alternative in the first
392 // matcher combined with each alternative in the second matcher.
393 // Thus, we can reuse the same Builder.
394 return llvm::all_of(InnerMatchers
, [&](const DynTypedMatcher
&InnerMatcher
) {
395 return InnerMatcher
.matchesNoKindCheck(DynNode
, Finder
, Builder
);
399 static bool eachOfVariadicOperator(const DynTypedNode
&DynNode
,
400 ASTMatchFinder
*Finder
,
401 BoundNodesTreeBuilder
*Builder
,
402 ArrayRef
<DynTypedMatcher
> InnerMatchers
) {
403 BoundNodesTreeBuilder Result
;
404 bool Matched
= false;
405 for (const DynTypedMatcher
&InnerMatcher
: InnerMatchers
) {
406 BoundNodesTreeBuilder
BuilderInner(*Builder
);
407 if (InnerMatcher
.matches(DynNode
, Finder
, &BuilderInner
)) {
409 Result
.addMatch(BuilderInner
);
412 *Builder
= std::move(Result
);
416 static bool anyOfVariadicOperator(const DynTypedNode
&DynNode
,
417 ASTMatchFinder
*Finder
,
418 BoundNodesTreeBuilder
*Builder
,
419 ArrayRef
<DynTypedMatcher
> InnerMatchers
) {
420 for (const DynTypedMatcher
&InnerMatcher
: InnerMatchers
) {
421 BoundNodesTreeBuilder Result
= *Builder
;
422 if (InnerMatcher
.matches(DynNode
, Finder
, &Result
)) {
423 *Builder
= std::move(Result
);
431 optionallyVariadicOperator(const DynTypedNode
&DynNode
, ASTMatchFinder
*Finder
,
432 BoundNodesTreeBuilder
*Builder
,
433 ArrayRef
<DynTypedMatcher
> InnerMatchers
) {
434 if (InnerMatchers
.size() != 1)
437 BoundNodesTreeBuilder
Result(*Builder
);
438 if (InnerMatchers
[0].matches(DynNode
, Finder
, &Result
))
439 *Builder
= std::move(Result
);
444 std::vector
<std::string
> vectorFromRefs(ArrayRef
<const StringRef
*> NameRefs
) {
445 std::vector
<std::string
> Names
;
446 Names
.reserve(NameRefs
.size());
447 for (auto *Name
: NameRefs
)
448 Names
.emplace_back(*Name
);
452 Matcher
<NamedDecl
> hasAnyNameFunc(ArrayRef
<const StringRef
*> NameRefs
) {
453 return internal::Matcher
<NamedDecl
>(
454 new internal::HasNameMatcher(vectorFromRefs(NameRefs
)));
457 Matcher
<ObjCMessageExpr
> hasAnySelectorFunc(
458 ArrayRef
<const StringRef
*> NameRefs
) {
459 return hasAnySelectorMatcher(vectorFromRefs(NameRefs
));
462 HasOpNameMatcher
hasAnyOperatorNameFunc(ArrayRef
<const StringRef
*> NameRefs
) {
463 return HasOpNameMatcher(vectorFromRefs(NameRefs
));
466 HasOverloadOpNameMatcher
467 hasAnyOverloadedOperatorNameFunc(ArrayRef
<const StringRef
*> NameRefs
) {
468 return HasOverloadOpNameMatcher(vectorFromRefs(NameRefs
));
471 HasNameMatcher::HasNameMatcher(std::vector
<std::string
> N
)
472 : UseUnqualifiedMatch(
473 llvm::all_of(N
, [](StringRef Name
) { return !Name
.contains("::"); })),
474 Names(std::move(N
)) {
476 for (StringRef Name
: Names
)
477 assert(!Name
.empty());
481 static bool consumeNameSuffix(StringRef
&FullName
, StringRef Suffix
) {
482 StringRef Name
= FullName
;
483 if (!Name
.ends_with(Suffix
))
485 Name
= Name
.drop_back(Suffix
.size());
487 if (!Name
.ends_with("::"))
489 Name
= Name
.drop_back(2);
495 static StringRef
getNodeName(const NamedDecl
&Node
,
496 llvm::SmallString
<128> &Scratch
) {
498 if (Node
.getIdentifier())
499 return Node
.getName();
501 if (Node
.getDeclName()) {
502 // Name needs to be constructed.
504 llvm::raw_svector_ostream
OS(Scratch
);
509 return "(anonymous)";
512 static StringRef
getNodeName(const RecordDecl
&Node
,
513 llvm::SmallString
<128> &Scratch
) {
514 if (Node
.getIdentifier()) {
515 return Node
.getName();
518 return ("(anonymous " + Node
.getKindName() + ")").toStringRef(Scratch
);
521 static StringRef
getNodeName(const NamespaceDecl
&Node
,
522 llvm::SmallString
<128> &Scratch
) {
523 return Node
.isAnonymousNamespace() ? "(anonymous namespace)" : Node
.getName();
530 PatternSet(ArrayRef
<std::string
> Names
) {
531 Patterns
.reserve(Names
.size());
532 for (StringRef Name
: Names
)
533 Patterns
.push_back({Name
, Name
.starts_with("::")});
536 /// Consumes the name suffix from each pattern in the set and removes the ones
537 /// that didn't match.
538 /// Return true if there are still any patterns left.
539 bool consumeNameSuffix(StringRef NodeName
, bool CanSkip
) {
541 // If we can skip the node, then we need to handle the case where a
542 // skipped node has the same name as its parent.
543 // namespace a { inline namespace a { class A; } }
544 // cxxRecordDecl(hasName("::a::A"))
545 // To do this, any patterns that match should be duplicated in our set,
546 // one of them with the tail removed.
547 for (size_t I
= 0, E
= Patterns
.size(); I
!= E
; ++I
) {
548 StringRef Pattern
= Patterns
[I
].P
;
549 if (ast_matchers::internal::consumeNameSuffix(Patterns
[I
].P
, NodeName
))
550 Patterns
.push_back({Pattern
, Patterns
[I
].IsFullyQualified
});
553 llvm::erase_if(Patterns
, [&NodeName
](auto &Pattern
) {
554 return !::clang::ast_matchers::internal::consumeNameSuffix(Pattern
.P
,
558 return !Patterns
.empty();
561 /// Check if any of the patterns are a match.
562 /// A match will be a pattern that was fully consumed, that also matches the
563 /// 'fully qualified' requirement.
564 bool foundMatch(bool AllowFullyQualified
) const {
565 return llvm::any_of(Patterns
, [&](const Pattern
&Pattern
) {
566 return Pattern
.P
.empty() &&
567 (AllowFullyQualified
|| !Pattern
.IsFullyQualified
);
574 bool IsFullyQualified
;
577 llvm::SmallVector
<Pattern
, 8> Patterns
;
582 bool HasNameMatcher::matchesNodeUnqualified(const NamedDecl
&Node
) const {
583 assert(UseUnqualifiedMatch
);
584 llvm::SmallString
<128> Scratch
;
585 StringRef NodeName
= getNodeName(Node
, Scratch
);
586 return llvm::any_of(Names
, [&](StringRef Name
) {
587 return consumeNameSuffix(Name
, NodeName
) && Name
.empty();
591 bool HasNameMatcher::matchesNodeFullFast(const NamedDecl
&Node
) const {
592 PatternSet
Patterns(Names
);
593 llvm::SmallString
<128> Scratch
;
595 // This function is copied and adapted from NamedDecl::printQualifiedName()
596 // By matching each part individually we optimize in a couple of ways:
597 // - We can exit early on the first failure.
598 // - We can skip inline/anonymous namespaces without another pass.
599 // - We print one name at a time, reducing the chance of overflowing the
600 // inlined space of the SmallString.
602 // First, match the name.
603 if (!Patterns
.consumeNameSuffix(getNodeName(Node
, Scratch
),
607 // Try to match each declaration context.
608 // We are allowed to skip anonymous and inline namespaces if they don't match.
609 const DeclContext
*Ctx
= Node
.getDeclContext();
611 if (Ctx
->isFunctionOrMethod())
612 return Patterns
.foundMatch(/*AllowFullyQualified=*/false);
614 for (; Ctx
; Ctx
= Ctx
->getParent()) {
615 // Linkage Spec can just be ignored
616 // FIXME: Any other DeclContext kinds that can be safely disregarded
617 if (isa
<LinkageSpecDecl
>(Ctx
))
619 if (!isa
<NamedDecl
>(Ctx
))
621 if (Patterns
.foundMatch(/*AllowFullyQualified=*/false))
624 if (const auto *ND
= dyn_cast
<NamespaceDecl
>(Ctx
)) {
625 // If it matches (or we can skip it), continue.
626 if (Patterns
.consumeNameSuffix(getNodeName(*ND
, Scratch
),
627 /*CanSkip=*/ND
->isAnonymousNamespace() ||
632 if (const auto *RD
= dyn_cast
<RecordDecl
>(Ctx
)) {
633 if (!isa
<ClassTemplateSpecializationDecl
>(Ctx
)) {
634 if (Patterns
.consumeNameSuffix(getNodeName(*RD
, Scratch
),
642 // We don't know how to deal with this DeclContext.
643 // Fallback to the slow version of the code.
644 return matchesNodeFullSlow(Node
);
647 return Patterns
.foundMatch(/*AllowFullyQualified=*/true);
650 bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl
&Node
) const {
651 const bool SkipUnwrittenCases
[] = {false, true};
652 for (bool SkipUnwritten
: SkipUnwrittenCases
) {
653 llvm::SmallString
<128> NodeName
= StringRef("::");
654 llvm::raw_svector_ostream
OS(NodeName
);
656 PrintingPolicy Policy
= Node
.getASTContext().getPrintingPolicy();
657 Policy
.SuppressUnwrittenScope
= SkipUnwritten
;
658 Policy
.SuppressInlineNamespace
=
659 SkipUnwritten
? PrintingPolicy::SuppressInlineNamespaceMode::All
660 : PrintingPolicy::SuppressInlineNamespaceMode::None
;
661 Node
.printQualifiedName(OS
, Policy
);
663 const StringRef FullName
= OS
.str();
665 for (const StringRef Pattern
: Names
) {
666 if (Pattern
.starts_with("::")) {
667 if (FullName
== Pattern
)
669 } else if (FullName
.ends_with(Pattern
) &&
670 FullName
.drop_back(Pattern
.size()).ends_with("::")) {
679 bool HasNameMatcher::matchesNode(const NamedDecl
&Node
) const {
680 assert(matchesNodeFullFast(Node
) == matchesNodeFullSlow(Node
));
681 if (UseUnqualifiedMatch
) {
682 assert(matchesNodeUnqualified(Node
) == matchesNodeFullFast(Node
));
683 return matchesNodeUnqualified(Node
);
685 return matchesNodeFullFast(Node
);
688 // Checks whether \p Loc points to a token with source text of \p TokenText.
689 static bool isTokenAtLoc(const SourceManager
&SM
, const LangOptions
&LangOpts
,
690 StringRef Text
, SourceLocation Loc
) {
691 llvm::SmallString
<16> Buffer
;
692 bool Invalid
= false;
693 // Since `Loc` may point into an expansion buffer, which has no corresponding
694 // source, we need to look at the spelling location to read the actual source.
695 StringRef TokenText
= Lexer::getSpelling(SM
.getSpellingLoc(Loc
), Buffer
, SM
,
697 return !Invalid
&& Text
== TokenText
;
700 std::optional
<SourceLocation
>
701 getExpansionLocOfMacro(StringRef MacroName
, SourceLocation Loc
,
702 const ASTContext
&Context
) {
703 auto &SM
= Context
.getSourceManager();
704 const LangOptions
&LangOpts
= Context
.getLangOpts();
705 while (Loc
.isMacroID()) {
706 SrcMgr::ExpansionInfo Expansion
=
707 SM
.getSLocEntry(SM
.getFileID(Loc
)).getExpansion();
708 if (Expansion
.isMacroArgExpansion())
709 // Check macro argument for an expansion of the given macro. For example,
710 // `F(G(3))`, where `MacroName` is `G`.
711 if (std::optional
<SourceLocation
> ArgLoc
= getExpansionLocOfMacro(
712 MacroName
, Expansion
.getSpellingLoc(), Context
))
714 Loc
= Expansion
.getExpansionLocStart();
715 if (isTokenAtLoc(SM
, LangOpts
, MacroName
, Loc
))
721 std::shared_ptr
<llvm::Regex
> createAndVerifyRegex(StringRef Regex
,
722 llvm::Regex::RegexFlags Flags
,
723 StringRef MatcherID
) {
724 assert(!Regex
.empty() && "Empty regex string");
725 auto SharedRegex
= std::make_shared
<llvm::Regex
>(Regex
, Flags
);
727 if (!SharedRegex
->isValid(Error
)) {
728 llvm::WithColor::error()
729 << "building matcher '" << MatcherID
<< "': " << Error
<< "\n";
730 llvm::WithColor::note() << " input was '" << Regex
<< "'\n";
734 } // end namespace internal
736 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ObjCAutoreleasePoolStmt
>
738 const internal::VariadicDynCastAllOfMatcher
<Decl
, TranslationUnitDecl
>
740 const internal::VariadicDynCastAllOfMatcher
<Decl
, TypedefDecl
> typedefDecl
;
741 const internal::VariadicDynCastAllOfMatcher
<Decl
, TypedefNameDecl
>
743 const internal::VariadicDynCastAllOfMatcher
<Decl
, TypeAliasDecl
> typeAliasDecl
;
744 const internal::VariadicDynCastAllOfMatcher
<Decl
, TypeAliasTemplateDecl
>
745 typeAliasTemplateDecl
;
746 const internal::VariadicAllOfMatcher
<Decl
> decl
;
747 const internal::VariadicDynCastAllOfMatcher
<Decl
, DecompositionDecl
> decompositionDecl
;
748 const internal::VariadicDynCastAllOfMatcher
<Decl
, BindingDecl
> bindingDecl
;
749 const internal::VariadicDynCastAllOfMatcher
<Decl
, LinkageSpecDecl
>
751 const internal::VariadicDynCastAllOfMatcher
<Decl
, NamedDecl
> namedDecl
;
752 const internal::VariadicDynCastAllOfMatcher
<Decl
, LabelDecl
> labelDecl
;
753 const internal::VariadicDynCastAllOfMatcher
<Decl
, NamespaceDecl
> namespaceDecl
;
754 const internal::VariadicDynCastAllOfMatcher
<Decl
, NamespaceAliasDecl
>
756 const internal::VariadicDynCastAllOfMatcher
<Decl
, RecordDecl
> recordDecl
;
757 const internal::VariadicDynCastAllOfMatcher
<Decl
, CXXRecordDecl
> cxxRecordDecl
;
758 const internal::VariadicDynCastAllOfMatcher
<Decl
, ClassTemplateDecl
>
760 const internal::VariadicDynCastAllOfMatcher
<Decl
,
761 ClassTemplateSpecializationDecl
>
762 classTemplateSpecializationDecl
;
763 const internal::VariadicDynCastAllOfMatcher
<
764 Decl
, ClassTemplatePartialSpecializationDecl
>
765 classTemplatePartialSpecializationDecl
;
766 const internal::VariadicDynCastAllOfMatcher
<Decl
, DeclaratorDecl
>
768 const internal::VariadicDynCastAllOfMatcher
<Decl
, ParmVarDecl
> parmVarDecl
;
769 const internal::VariadicDynCastAllOfMatcher
<Decl
, AccessSpecDecl
>
771 const internal::VariadicAllOfMatcher
<CXXBaseSpecifier
> cxxBaseSpecifier
;
772 const internal::VariadicAllOfMatcher
<CXXCtorInitializer
> cxxCtorInitializer
;
773 const internal::VariadicAllOfMatcher
<TemplateArgument
> templateArgument
;
774 const internal::VariadicAllOfMatcher
<TemplateArgumentLoc
> templateArgumentLoc
;
775 const internal::VariadicAllOfMatcher
<TemplateName
> templateName
;
776 const internal::VariadicDynCastAllOfMatcher
<Decl
, NonTypeTemplateParmDecl
>
777 nonTypeTemplateParmDecl
;
778 const internal::VariadicDynCastAllOfMatcher
<Decl
, TemplateTypeParmDecl
>
779 templateTypeParmDecl
;
780 const internal::VariadicDynCastAllOfMatcher
<Decl
, TemplateTemplateParmDecl
>
781 templateTemplateParmDecl
;
783 const internal::VariadicAllOfMatcher
<LambdaCapture
> lambdaCapture
;
784 const internal::VariadicAllOfMatcher
<QualType
> qualType
;
785 const internal::VariadicAllOfMatcher
<Type
> type
;
786 const internal::VariadicAllOfMatcher
<TypeLoc
> typeLoc
;
788 const internal::VariadicDynCastAllOfMatcher
<TypeLoc
, QualifiedTypeLoc
>
790 const internal::VariadicDynCastAllOfMatcher
<TypeLoc
, PointerTypeLoc
>
792 const internal::VariadicDynCastAllOfMatcher
<TypeLoc
, ReferenceTypeLoc
>
794 const internal::VariadicDynCastAllOfMatcher
<TypeLoc
,
795 TemplateSpecializationTypeLoc
>
796 templateSpecializationTypeLoc
;
797 const internal::VariadicDynCastAllOfMatcher
<TypeLoc
, ElaboratedTypeLoc
>
800 const internal::VariadicDynCastAllOfMatcher
<Stmt
, UnaryExprOrTypeTraitExpr
>
801 unaryExprOrTypeTraitExpr
;
802 const internal::VariadicDynCastAllOfMatcher
<Decl
, ExportDecl
> exportDecl
;
803 const internal::VariadicDynCastAllOfMatcher
<Decl
, ValueDecl
> valueDecl
;
804 const internal::VariadicDynCastAllOfMatcher
<Decl
, CXXConstructorDecl
>
806 const internal::VariadicDynCastAllOfMatcher
<Decl
, CXXDestructorDecl
>
808 const internal::VariadicDynCastAllOfMatcher
<Decl
, EnumDecl
> enumDecl
;
809 const internal::VariadicDynCastAllOfMatcher
<Decl
, EnumConstantDecl
>
811 const internal::VariadicDynCastAllOfMatcher
<Decl
, TagDecl
> tagDecl
;
812 const internal::VariadicDynCastAllOfMatcher
<Decl
, CXXMethodDecl
> cxxMethodDecl
;
813 const internal::VariadicDynCastAllOfMatcher
<Decl
, CXXConversionDecl
>
815 const internal::VariadicDynCastAllOfMatcher
<Decl
, ConceptDecl
> conceptDecl
;
816 const internal::VariadicDynCastAllOfMatcher
<Decl
, VarDecl
> varDecl
;
817 const internal::VariadicDynCastAllOfMatcher
<Decl
, FieldDecl
> fieldDecl
;
818 const internal::VariadicDynCastAllOfMatcher
<Decl
, IndirectFieldDecl
>
820 const internal::VariadicDynCastAllOfMatcher
<Decl
, FunctionDecl
> functionDecl
;
821 const internal::VariadicDynCastAllOfMatcher
<Decl
, FunctionTemplateDecl
>
822 functionTemplateDecl
;
823 const internal::VariadicDynCastAllOfMatcher
<Decl
, FriendDecl
> friendDecl
;
824 const internal::VariadicAllOfMatcher
<Stmt
> stmt
;
825 const internal::VariadicDynCastAllOfMatcher
<Stmt
, DeclStmt
> declStmt
;
826 const internal::VariadicDynCastAllOfMatcher
<Stmt
, MemberExpr
> memberExpr
;
827 const internal::VariadicDynCastAllOfMatcher
<Stmt
, UnresolvedMemberExpr
>
828 unresolvedMemberExpr
;
829 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXDependentScopeMemberExpr
>
830 cxxDependentScopeMemberExpr
;
831 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CallExpr
> callExpr
;
832 const internal::VariadicDynCastAllOfMatcher
<Stmt
, LambdaExpr
> lambdaExpr
;
833 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXMemberCallExpr
>
835 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ObjCMessageExpr
>
837 const internal::VariadicDynCastAllOfMatcher
<Decl
, ObjCInterfaceDecl
>
839 const internal::VariadicDynCastAllOfMatcher
<Decl
, ObjCImplementationDecl
>
840 objcImplementationDecl
;
841 const internal::VariadicDynCastAllOfMatcher
<Decl
, ObjCProtocolDecl
>
843 const internal::VariadicDynCastAllOfMatcher
<Decl
, ObjCCategoryDecl
>
845 const internal::VariadicDynCastAllOfMatcher
<Decl
, ObjCCategoryImplDecl
>
846 objcCategoryImplDecl
;
847 const internal::VariadicDynCastAllOfMatcher
<Decl
, ObjCMethodDecl
>
849 const internal::VariadicDynCastAllOfMatcher
<Decl
, BlockDecl
>
851 const internal::VariadicDynCastAllOfMatcher
<Decl
, ObjCIvarDecl
> objcIvarDecl
;
852 const internal::VariadicDynCastAllOfMatcher
<Decl
, ObjCPropertyDecl
>
854 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ObjCAtThrowStmt
>
856 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ObjCAtTryStmt
> objcTryStmt
;
857 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ObjCAtCatchStmt
>
859 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ObjCAtFinallyStmt
>
861 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ExprWithCleanups
>
863 const internal::VariadicDynCastAllOfMatcher
<Stmt
, InitListExpr
> initListExpr
;
864 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXStdInitializerListExpr
>
865 cxxStdInitializerListExpr
;
866 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ImplicitValueInitExpr
>
867 implicitValueInitExpr
;
868 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ParenListExpr
> parenListExpr
;
869 const internal::VariadicDynCastAllOfMatcher
<Stmt
, SubstNonTypeTemplateParmExpr
>
870 substNonTypeTemplateParmExpr
;
871 const internal::VariadicDynCastAllOfMatcher
<Decl
, UsingDecl
> usingDecl
;
872 const internal::VariadicDynCastAllOfMatcher
<Decl
, UsingEnumDecl
> usingEnumDecl
;
873 const internal::VariadicDynCastAllOfMatcher
<Decl
, UsingDirectiveDecl
>
875 const internal::VariadicDynCastAllOfMatcher
<Stmt
, UnresolvedLookupExpr
>
876 unresolvedLookupExpr
;
877 const internal::VariadicDynCastAllOfMatcher
<Decl
, UnresolvedUsingValueDecl
>
878 unresolvedUsingValueDecl
;
879 const internal::VariadicDynCastAllOfMatcher
<Decl
, UnresolvedUsingTypenameDecl
>
880 unresolvedUsingTypenameDecl
;
881 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ConstantExpr
> constantExpr
;
882 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ParenExpr
> parenExpr
;
883 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXConstructExpr
>
885 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXUnresolvedConstructExpr
>
886 cxxUnresolvedConstructExpr
;
887 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXThisExpr
> cxxThisExpr
;
888 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXBindTemporaryExpr
>
889 cxxBindTemporaryExpr
;
890 const internal::VariadicDynCastAllOfMatcher
<Stmt
, MaterializeTemporaryExpr
>
891 materializeTemporaryExpr
;
892 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXNewExpr
> cxxNewExpr
;
893 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXDeleteExpr
> cxxDeleteExpr
;
894 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXNoexceptExpr
>
896 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ArraySubscriptExpr
>
898 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ArrayInitIndexExpr
>
900 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ArrayInitLoopExpr
>
902 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXDefaultArgExpr
>
904 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXOperatorCallExpr
>
906 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXRewrittenBinaryOperator
>
907 cxxRewrittenBinaryOperator
;
908 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXFoldExpr
> cxxFoldExpr
;
909 const internal::VariadicDynCastAllOfMatcher
<Stmt
, Expr
> expr
;
910 const internal::VariadicDynCastAllOfMatcher
<Stmt
, DeclRefExpr
> declRefExpr
;
911 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ObjCIvarRefExpr
> objcIvarRefExpr
;
912 const internal::VariadicDynCastAllOfMatcher
<Stmt
, BlockExpr
> blockExpr
;
913 const internal::VariadicDynCastAllOfMatcher
<Stmt
, IfStmt
> ifStmt
;
914 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ForStmt
> forStmt
;
915 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXForRangeStmt
>
917 const internal::VariadicDynCastAllOfMatcher
<Stmt
, WhileStmt
> whileStmt
;
918 const internal::VariadicDynCastAllOfMatcher
<Stmt
, DoStmt
> doStmt
;
919 const internal::VariadicDynCastAllOfMatcher
<Stmt
, BreakStmt
> breakStmt
;
920 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ContinueStmt
> continueStmt
;
921 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CoreturnStmt
> coreturnStmt
;
922 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ReturnStmt
> returnStmt
;
923 const internal::VariadicDynCastAllOfMatcher
<Stmt
, GotoStmt
> gotoStmt
;
924 const internal::VariadicDynCastAllOfMatcher
<Stmt
, LabelStmt
> labelStmt
;
925 const internal::VariadicDynCastAllOfMatcher
<Stmt
, AddrLabelExpr
> addrLabelExpr
;
926 const internal::VariadicDynCastAllOfMatcher
<Stmt
, SwitchStmt
> switchStmt
;
927 const internal::VariadicDynCastAllOfMatcher
<Stmt
, SwitchCase
> switchCase
;
928 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CaseStmt
> caseStmt
;
929 const internal::VariadicDynCastAllOfMatcher
<Stmt
, DefaultStmt
> defaultStmt
;
930 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CompoundStmt
> compoundStmt
;
931 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CoroutineBodyStmt
>
933 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXCatchStmt
> cxxCatchStmt
;
934 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXTryStmt
> cxxTryStmt
;
935 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXThrowExpr
> cxxThrowExpr
;
936 const internal::VariadicDynCastAllOfMatcher
<Stmt
, NullStmt
> nullStmt
;
937 const internal::VariadicDynCastAllOfMatcher
<Stmt
, AsmStmt
> asmStmt
;
938 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXBoolLiteralExpr
>
940 const internal::VariadicDynCastAllOfMatcher
<Stmt
, StringLiteral
> stringLiteral
;
941 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ObjCStringLiteral
> objcStringLiteral
;
942 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CharacterLiteral
>
944 const internal::VariadicDynCastAllOfMatcher
<Stmt
, IntegerLiteral
>
946 const internal::VariadicDynCastAllOfMatcher
<Stmt
, FloatingLiteral
> floatLiteral
;
947 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ImaginaryLiteral
> imaginaryLiteral
;
948 const internal::VariadicDynCastAllOfMatcher
<Stmt
, FixedPointLiteral
>
950 const internal::VariadicDynCastAllOfMatcher
<Stmt
, UserDefinedLiteral
>
952 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CompoundLiteralExpr
>
954 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXNullPtrLiteralExpr
>
955 cxxNullPtrLiteralExpr
;
956 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ChooseExpr
> chooseExpr
;
957 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ConvertVectorExpr
>
959 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CoawaitExpr
>
961 const internal::VariadicDynCastAllOfMatcher
<Stmt
, DependentCoawaitExpr
>
962 dependentCoawaitExpr
;
963 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CoyieldExpr
>
965 const internal::VariadicDynCastAllOfMatcher
<Stmt
, GNUNullExpr
> gnuNullExpr
;
966 const internal::VariadicDynCastAllOfMatcher
<Stmt
, GenericSelectionExpr
>
967 genericSelectionExpr
;
968 const internal::VariadicDynCastAllOfMatcher
<Stmt
, AtomicExpr
> atomicExpr
;
969 const internal::VariadicDynCastAllOfMatcher
<Stmt
, StmtExpr
> stmtExpr
;
970 const internal::VariadicDynCastAllOfMatcher
<Stmt
, BinaryOperator
>
972 const internal::MapAnyOfMatcher
<BinaryOperator
, CXXOperatorCallExpr
,
973 CXXRewrittenBinaryOperator
>
975 const internal::MapAnyOfMatcher
<CallExpr
, CXXConstructExpr
> invocation
;
976 const internal::VariadicDynCastAllOfMatcher
<Stmt
, UnaryOperator
> unaryOperator
;
977 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ConditionalOperator
>
979 const internal::VariadicDynCastAllOfMatcher
<Stmt
, BinaryConditionalOperator
>
980 binaryConditionalOperator
;
981 const internal::VariadicDynCastAllOfMatcher
<Stmt
, OpaqueValueExpr
>
983 const internal::VariadicDynCastAllOfMatcher
<Decl
, StaticAssertDecl
>
985 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXReinterpretCastExpr
>
986 cxxReinterpretCastExpr
;
987 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXStaticCastExpr
>
989 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXDynamicCastExpr
>
991 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXConstCastExpr
>
993 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CStyleCastExpr
>
995 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ExplicitCastExpr
>
997 const internal::VariadicDynCastAllOfMatcher
<Stmt
, ImplicitCastExpr
>
999 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CastExpr
> castExpr
;
1000 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXFunctionalCastExpr
>
1001 cxxFunctionalCastExpr
;
1002 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CXXTemporaryObjectExpr
>
1003 cxxTemporaryObjectExpr
;
1004 const internal::VariadicDynCastAllOfMatcher
<Stmt
, PredefinedExpr
>
1006 const internal::VariadicDynCastAllOfMatcher
<Stmt
, DesignatedInitExpr
>
1008 const internal::VariadicOperatorMatcherFunc
<
1009 2, std::numeric_limits
<unsigned>::max()>
1010 eachOf
= {internal::DynTypedMatcher::VO_EachOf
};
1011 const internal::VariadicOperatorMatcherFunc
<
1012 2, std::numeric_limits
<unsigned>::max()>
1013 anyOf
= {internal::DynTypedMatcher::VO_AnyOf
};
1014 const internal::VariadicOperatorMatcherFunc
<
1015 2, std::numeric_limits
<unsigned>::max()>
1016 allOf
= {internal::DynTypedMatcher::VO_AllOf
};
1017 const internal::VariadicOperatorMatcherFunc
<1, 1> optionally
= {
1018 internal::DynTypedMatcher::VO_Optionally
};
1019 const internal::VariadicFunction
<internal::Matcher
<NamedDecl
>, StringRef
,
1020 internal::hasAnyNameFunc
>
1023 const internal::VariadicFunction
<internal::HasOpNameMatcher
, StringRef
,
1024 internal::hasAnyOperatorNameFunc
>
1025 hasAnyOperatorName
= {};
1026 const internal::VariadicFunction
<internal::HasOverloadOpNameMatcher
, StringRef
,
1027 internal::hasAnyOverloadedOperatorNameFunc
>
1028 hasAnyOverloadedOperatorName
= {};
1029 const internal::VariadicFunction
<internal::Matcher
<ObjCMessageExpr
>, StringRef
,
1030 internal::hasAnySelectorFunc
>
1031 hasAnySelector
= {};
1032 const internal::ArgumentAdaptingMatcherFunc
<internal::HasMatcher
> has
= {};
1033 const internal::ArgumentAdaptingMatcherFunc
<internal::HasDescendantMatcher
>
1035 const internal::ArgumentAdaptingMatcherFunc
<internal::ForEachMatcher
> forEach
=
1037 const internal::ArgumentAdaptingMatcherFunc
<internal::ForEachDescendantMatcher
>
1038 forEachDescendant
= {};
1039 const internal::ArgumentAdaptingMatcherFunc
<
1040 internal::HasParentMatcher
,
1041 internal::TypeList
<Decl
, NestedNameSpecifierLoc
, Stmt
, TypeLoc
, Attr
>,
1042 internal::TypeList
<Decl
, NestedNameSpecifierLoc
, Stmt
, TypeLoc
, Attr
>>
1044 const internal::ArgumentAdaptingMatcherFunc
<
1045 internal::HasAncestorMatcher
,
1046 internal::TypeList
<Decl
, NestedNameSpecifierLoc
, Stmt
, TypeLoc
, Attr
>,
1047 internal::TypeList
<Decl
, NestedNameSpecifierLoc
, Stmt
, TypeLoc
, Attr
>>
1049 const internal::VariadicOperatorMatcherFunc
<1, 1> unless
= {
1050 internal::DynTypedMatcher::VO_UnaryNot
};
1051 const internal::VariadicAllOfMatcher
<NestedNameSpecifier
> nestedNameSpecifier
;
1052 const internal::VariadicAllOfMatcher
<NestedNameSpecifierLoc
>
1053 nestedNameSpecifierLoc
;
1054 const internal::VariadicAllOfMatcher
<Attr
> attr
;
1055 const internal::VariadicDynCastAllOfMatcher
<Stmt
, CUDAKernelCallExpr
>
1057 const AstTypeMatcher
<BuiltinType
> builtinType
;
1058 const AstTypeMatcher
<ArrayType
> arrayType
;
1059 const AstTypeMatcher
<ComplexType
> complexType
;
1060 const AstTypeMatcher
<ConstantArrayType
> constantArrayType
;
1061 const AstTypeMatcher
<DeducedTemplateSpecializationType
>
1062 deducedTemplateSpecializationType
;
1063 const AstTypeMatcher
<DependentSizedArrayType
> dependentSizedArrayType
;
1064 const AstTypeMatcher
<DependentSizedExtVectorType
> dependentSizedExtVectorType
;
1065 const AstTypeMatcher
<IncompleteArrayType
> incompleteArrayType
;
1066 const AstTypeMatcher
<VariableArrayType
> variableArrayType
;
1067 const AstTypeMatcher
<AtomicType
> atomicType
;
1068 const AstTypeMatcher
<AutoType
> autoType
;
1069 const AstTypeMatcher
<DecltypeType
> decltypeType
;
1070 const AstTypeMatcher
<FunctionType
> functionType
;
1071 const AstTypeMatcher
<FunctionProtoType
> functionProtoType
;
1072 const AstTypeMatcher
<ParenType
> parenType
;
1073 const AstTypeMatcher
<BlockPointerType
> blockPointerType
;
1074 const AstTypeMatcher
<MacroQualifiedType
> macroQualifiedType
;
1075 const AstTypeMatcher
<MemberPointerType
> memberPointerType
;
1076 const AstTypeMatcher
<PointerType
> pointerType
;
1077 const AstTypeMatcher
<ObjCObjectPointerType
> objcObjectPointerType
;
1078 const AstTypeMatcher
<ReferenceType
> referenceType
;
1079 const AstTypeMatcher
<LValueReferenceType
> lValueReferenceType
;
1080 const AstTypeMatcher
<RValueReferenceType
> rValueReferenceType
;
1081 const AstTypeMatcher
<TypedefType
> typedefType
;
1082 const AstTypeMatcher
<EnumType
> enumType
;
1083 const AstTypeMatcher
<TemplateSpecializationType
> templateSpecializationType
;
1084 const AstTypeMatcher
<UnaryTransformType
> unaryTransformType
;
1085 const AstTypeMatcher
<RecordType
> recordType
;
1086 const AstTypeMatcher
<TagType
> tagType
;
1087 const AstTypeMatcher
<ElaboratedType
> elaboratedType
;
1088 const AstTypeMatcher
<UsingType
> usingType
;
1089 const AstTypeMatcher
<SubstTemplateTypeParmType
> substTemplateTypeParmType
;
1090 const AstTypeMatcher
<TemplateTypeParmType
> templateTypeParmType
;
1091 const AstTypeMatcher
<InjectedClassNameType
> injectedClassNameType
;
1092 const AstTypeMatcher
<DecayedType
> decayedType
;
1093 AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType
,
1094 AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType
,
1096 AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasValueType
,
1097 AST_POLYMORPHIC_SUPPORTED_TYPES(AtomicType
));
1098 AST_TYPELOC_TRAVERSE_MATCHER_DEF(
1100 AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType
, MemberPointerType
,
1101 PointerType
, ReferenceType
));
1103 const internal::VariadicDynCastAllOfMatcher
<Stmt
, OMPExecutableDirective
>
1104 ompExecutableDirective
;
1105 const internal::VariadicDynCastAllOfMatcher
<OMPClause
, OMPDefaultClause
>
1107 const internal::VariadicDynCastAllOfMatcher
<Decl
, CXXDeductionGuideDecl
>
1108 cxxDeductionGuideDecl
;
1110 } // end namespace ast_matchers
1111 } // end namespace clang