clang 20.0.0git
ASTMatchersInternal.cpp
Go to the documentation of this file.
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
16#include "clang/AST/Decl.h"
21#include "clang/Basic/LLVM.h"
22#include "clang/Lex/Lexer.h"
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/DenseSet.h"
25#include "llvm/ADT/IntrusiveRefCntPtr.h"
26#include "llvm/ADT/SmallString.h"
27#include "llvm/ADT/SmallVector.h"
28#include "llvm/ADT/StringRef.h"
29#include "llvm/Support/Casting.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/ManagedStatic.h"
32#include "llvm/Support/Regex.h"
33#include "llvm/Support/WithColor.h"
34#include "llvm/Support/raw_ostream.h"
35#include <algorithm>
36#include <cassert>
37#include <cstddef>
38#include <optional>
39#include <string>
40#include <utility>
41#include <vector>
42
43namespace clang {
44namespace ast_matchers {
45
46AST_MATCHER_P(ObjCMessageExpr, hasAnySelectorMatcher, std::vector<std::string>,
47 Matches) {
48 return llvm::is_contained(Matches, Node.getSelector().getAsString());
49}
50
51namespace internal {
52
53static bool notUnaryOperator(const DynTypedNode &DynNode,
54 ASTMatchFinder *Finder,
55 BoundNodesTreeBuilder *Builder,
56 ArrayRef<DynTypedMatcher> InnerMatchers);
57
58static bool allOfVariadicOperator(const DynTypedNode &DynNode,
59 ASTMatchFinder *Finder,
60 BoundNodesTreeBuilder *Builder,
61 ArrayRef<DynTypedMatcher> InnerMatchers);
62
63static bool eachOfVariadicOperator(const DynTypedNode &DynNode,
64 ASTMatchFinder *Finder,
65 BoundNodesTreeBuilder *Builder,
66 ArrayRef<DynTypedMatcher> InnerMatchers);
67
68static bool anyOfVariadicOperator(const DynTypedNode &DynNode,
69 ASTMatchFinder *Finder,
70 BoundNodesTreeBuilder *Builder,
71 ArrayRef<DynTypedMatcher> InnerMatchers);
72
73static bool optionallyVariadicOperator(const DynTypedNode &DynNode,
74 ASTMatchFinder *Finder,
75 BoundNodesTreeBuilder *Builder,
76 ArrayRef<DynTypedMatcher> InnerMatchers);
77
79 const Matcher<CXXBaseSpecifier> &BaseSpecMatcher,
80 ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) {
81 if (!Node.hasDefinition())
82 return false;
83
84 CXXBasePaths Paths;
85 Paths.setOrigin(&Node);
86
87 const auto basePredicate =
88 [Finder, Builder, &BaseSpecMatcher](const CXXBaseSpecifier *BaseSpec,
89 CXXBasePath &IgnoredParam) {
90 BoundNodesTreeBuilder Result(*Builder);
91 if (BaseSpecMatcher.matches(*BaseSpec, Finder, &Result)) {
92 *Builder = std::move(Result);
93 return true;
94 }
95 return false;
96 };
97
98 return Node.lookupInBases(basePredicate, Paths,
99 /*LookupInDependent =*/true);
100}
101
102void BoundNodesTreeBuilder::visitMatches(Visitor *ResultVisitor) {
103 if (Bindings.empty())
104 Bindings.push_back(BoundNodesMap());
105 for (BoundNodesMap &Binding : Bindings) {
106 ResultVisitor->visitMatch(BoundNodes(Binding));
107 }
108}
109
110namespace {
111
112using VariadicOperatorFunction = bool (*)(
113 const DynTypedNode &DynNode, ASTMatchFinder *Finder,
114 BoundNodesTreeBuilder *Builder, ArrayRef<DynTypedMatcher> InnerMatchers);
115
116template <VariadicOperatorFunction Func>
117class VariadicMatcher : public DynMatcherInterface {
118public:
119 VariadicMatcher(std::vector<DynTypedMatcher> InnerMatchers)
120 : InnerMatchers(std::move(InnerMatchers)) {}
121
122 bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
123 BoundNodesTreeBuilder *Builder) const override {
124 return Func(DynNode, Finder, Builder, InnerMatchers);
125 }
126
127private:
128 std::vector<DynTypedMatcher> InnerMatchers;
129};
130
131class IdDynMatcher : public DynMatcherInterface {
132public:
133 IdDynMatcher(StringRef ID,
134 IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher)
135 : ID(ID), InnerMatcher(std::move(InnerMatcher)) {}
136
137 bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
138 BoundNodesTreeBuilder *Builder) const override {
139 bool Result = InnerMatcher->dynMatches(DynNode, Finder, Builder);
140 if (Result) Builder->setBinding(ID, DynNode);
141 return Result;
142 }
143
144 std::optional<clang::TraversalKind> TraversalKind() const override {
145 return InnerMatcher->TraversalKind();
146 }
147
148private:
149 const std::string ID;
150 const IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher;
151};
152
153/// A matcher that always returns true.
154class TrueMatcherImpl : public DynMatcherInterface {
155public:
156 TrueMatcherImpl() = default;
157
158 bool dynMatches(const DynTypedNode &, ASTMatchFinder *,
159 BoundNodesTreeBuilder *) const override {
160 return true;
161 }
162};
163
164/// A matcher that specifies a particular \c TraversalKind.
165///
166/// The kind provided to the constructor overrides any kind that may be
167/// specified by the `InnerMatcher`.
168class DynTraversalMatcherImpl : public DynMatcherInterface {
169public:
170 explicit DynTraversalMatcherImpl(
172 IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher)
173 : TK(TK), InnerMatcher(std::move(InnerMatcher)) {}
174
175 bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
176 BoundNodesTreeBuilder *Builder) const override {
177 return this->InnerMatcher->dynMatches(DynNode, Finder, Builder);
178 }
179
180 std::optional<clang::TraversalKind> TraversalKind() const override {
181 return TK;
182 }
183
184private:
186 IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher;
187};
188
189} // namespace
190
191bool ASTMatchFinder::isTraversalIgnoringImplicitNodes() const {
192 return getASTContext().getParentMapContext().getTraversalKind() ==
194}
195
196DynTypedMatcher
197DynTypedMatcher::constructVariadic(DynTypedMatcher::VariadicOperator Op,
198 ASTNodeKind SupportedKind,
199 std::vector<DynTypedMatcher> InnerMatchers) {
200 assert(!InnerMatchers.empty() && "Array must not be empty.");
201 assert(llvm::all_of(InnerMatchers,
202 [SupportedKind](const DynTypedMatcher &M) {
203 return M.canConvertTo(SupportedKind);
204 }) &&
205 "InnerMatchers must be convertible to SupportedKind!");
206
207 // We must relax the restrict kind here.
208 // The different operators might deal differently with a mismatch.
209 // Make it the same as SupportedKind, since that is the broadest type we are
210 // allowed to accept.
211 auto RestrictKind = SupportedKind;
212
213 switch (Op) {
214 case VO_AllOf:
215 // In the case of allOf() we must pass all the checks, so making
216 // RestrictKind the most restrictive can save us time. This way we reject
217 // invalid types earlier and we can elide the kind checks inside the
218 // matcher.
219 for (auto &IM : InnerMatchers) {
220 RestrictKind =
221 ASTNodeKind::getMostDerivedType(RestrictKind, IM.RestrictKind);
222 }
223 return DynTypedMatcher(
224 SupportedKind, RestrictKind,
225 new VariadicMatcher<allOfVariadicOperator>(std::move(InnerMatchers)));
226
227 case VO_AnyOf:
228 return DynTypedMatcher(
229 SupportedKind, RestrictKind,
230 new VariadicMatcher<anyOfVariadicOperator>(std::move(InnerMatchers)));
231
232 case VO_EachOf:
233 return DynTypedMatcher(
234 SupportedKind, RestrictKind,
235 new VariadicMatcher<eachOfVariadicOperator>(std::move(InnerMatchers)));
236
237 case VO_Optionally:
238 return DynTypedMatcher(SupportedKind, RestrictKind,
239 new VariadicMatcher<optionallyVariadicOperator>(
240 std::move(InnerMatchers)));
241
242 case VO_UnaryNot:
243 // FIXME: Implement the Not operator to take a single matcher instead of a
244 // vector.
245 return DynTypedMatcher(
246 SupportedKind, RestrictKind,
247 new VariadicMatcher<notUnaryOperator>(std::move(InnerMatchers)));
248 }
249 llvm_unreachable("Invalid Op value.");
250}
251
252DynTypedMatcher
253DynTypedMatcher::constructRestrictedWrapper(const DynTypedMatcher &InnerMatcher,
254 ASTNodeKind RestrictKind) {
255 DynTypedMatcher Copy = InnerMatcher;
256 Copy.RestrictKind = RestrictKind;
257 return Copy;
258}
259
260DynTypedMatcher DynTypedMatcher::withTraversalKind(TraversalKind TK) {
261 auto Copy = *this;
262 Copy.Implementation =
263 new DynTraversalMatcherImpl(TK, std::move(Copy.Implementation));
264 return Copy;
265}
266
267DynTypedMatcher DynTypedMatcher::trueMatcher(ASTNodeKind NodeKind) {
268 // We only ever need one instance of TrueMatcherImpl, so we create a static
269 // instance and reuse it to reduce the overhead of the matcher and increase
270 // the chance of cache hits.
271 static const llvm::IntrusiveRefCntPtr<TrueMatcherImpl> Instance =
272 new TrueMatcherImpl();
273 return DynTypedMatcher(NodeKind, NodeKind, Instance);
274}
275
276bool DynTypedMatcher::canMatchNodesOfKind(ASTNodeKind Kind) const {
277 return RestrictKind.isBaseOf(Kind);
278}
279
280DynTypedMatcher DynTypedMatcher::dynCastTo(const ASTNodeKind Kind) const {
281 auto Copy = *this;
282 Copy.SupportedKind = Kind;
283 Copy.RestrictKind = ASTNodeKind::getMostDerivedType(Kind, RestrictKind);
284 return Copy;
285}
286
287bool DynTypedMatcher::matches(const DynTypedNode &DynNode,
288 ASTMatchFinder *Finder,
289 BoundNodesTreeBuilder *Builder) const {
290 TraversalKindScope RAII(Finder->getASTContext(),
291 Implementation->TraversalKind());
292
293 if (Finder->isTraversalIgnoringImplicitNodes() &&
294 Finder->IsMatchingInASTNodeNotSpelledInSource())
295 return false;
296
297 if (!Finder->isTraversalIgnoringImplicitNodes() &&
298 Finder->IsMatchingInASTNodeNotAsIs())
299 return false;
300
301 auto N =
302 Finder->getASTContext().getParentMapContext().traverseIgnored(DynNode);
303
304 if (RestrictKind.isBaseOf(N.getNodeKind()) &&
305 Implementation->dynMatches(N, Finder, Builder)) {
306 return true;
307 }
308 // Delete all bindings when a matcher does not match.
309 // This prevents unexpected exposure of bound nodes in unmatches
310 // branches of the match tree.
311 Builder->removeBindings([](const BoundNodesMap &) { return true; });
312 return false;
313}
314
315bool DynTypedMatcher::matchesNoKindCheck(const DynTypedNode &DynNode,
316 ASTMatchFinder *Finder,
317 BoundNodesTreeBuilder *Builder) const {
318 TraversalKindScope raii(Finder->getASTContext(),
319 Implementation->TraversalKind());
320
321 if (Finder->isTraversalIgnoringImplicitNodes() &&
322 Finder->IsMatchingInASTNodeNotSpelledInSource())
323 return false;
324
325 if (!Finder->isTraversalIgnoringImplicitNodes() &&
326 Finder->IsMatchingInASTNodeNotAsIs())
327 return false;
328
329 auto N =
330 Finder->getASTContext().getParentMapContext().traverseIgnored(DynNode);
331
332 assert(RestrictKind.isBaseOf(N.getNodeKind()));
333 if (Implementation->dynMatches(N, Finder, Builder)) {
334 return true;
335 }
336 // Delete all bindings when a matcher does not match.
337 // This prevents unexpected exposure of bound nodes in unmatches
338 // branches of the match tree.
339 Builder->removeBindings([](const BoundNodesMap &) { return true; });
340 return false;
341}
342
343std::optional<DynTypedMatcher> DynTypedMatcher::tryBind(StringRef ID) const {
344 if (!AllowBind)
345 return std::nullopt;
346 auto Result = *this;
347 Result.Implementation =
348 new IdDynMatcher(ID, std::move(Result.Implementation));
349 return std::move(Result);
350}
351
352bool DynTypedMatcher::canConvertTo(ASTNodeKind To) const {
353 const auto From = getSupportedKind();
354 auto QualKind = ASTNodeKind::getFromNodeKind<QualType>();
355 auto TypeKind = ASTNodeKind::getFromNodeKind<Type>();
356 /// Mimic the implicit conversions of Matcher<>.
357 /// - From Matcher<Type> to Matcher<QualType>
358 if (From.isSame(TypeKind) && To.isSame(QualKind)) return true;
359 /// - From Matcher<Base> to Matcher<Derived>
360 return From.isBaseOf(To);
361}
362
363void BoundNodesTreeBuilder::addMatch(const BoundNodesTreeBuilder &Other) {
364 Bindings.append(Other.Bindings.begin(), Other.Bindings.end());
365}
366
367static bool notUnaryOperator(const DynTypedNode &DynNode,
368 ASTMatchFinder *Finder,
369 BoundNodesTreeBuilder *Builder,
370 ArrayRef<DynTypedMatcher> InnerMatchers) {
371 if (InnerMatchers.size() != 1)
372 return false;
373
374 // The 'unless' matcher will always discard the result:
375 // If the inner matcher doesn't match, unless returns true,
376 // but the inner matcher cannot have bound anything.
377 // If the inner matcher matches, the result is false, and
378 // any possible binding will be discarded.
379 // We still need to hand in all the bound nodes up to this
380 // point so the inner matcher can depend on bound nodes,
381 // and we need to actively discard the bound nodes, otherwise
382 // the inner matcher will reset the bound nodes if it doesn't
383 // match, but this would be inversed by 'unless'.
384 BoundNodesTreeBuilder Discard(*Builder);
385 return !InnerMatchers[0].matches(DynNode, Finder, &Discard);
386}
387
388static bool allOfVariadicOperator(const DynTypedNode &DynNode,
389 ASTMatchFinder *Finder,
390 BoundNodesTreeBuilder *Builder,
391 ArrayRef<DynTypedMatcher> InnerMatchers) {
392 // allOf leads to one matcher for each alternative in the first
393 // matcher combined with each alternative in the second matcher.
394 // Thus, we can reuse the same Builder.
395 return llvm::all_of(InnerMatchers, [&](const DynTypedMatcher &InnerMatcher) {
396 return InnerMatcher.matchesNoKindCheck(DynNode, Finder, Builder);
397 });
398}
399
400static bool eachOfVariadicOperator(const DynTypedNode &DynNode,
401 ASTMatchFinder *Finder,
402 BoundNodesTreeBuilder *Builder,
403 ArrayRef<DynTypedMatcher> InnerMatchers) {
404 BoundNodesTreeBuilder Result;
405 bool Matched = false;
406 for (const DynTypedMatcher &InnerMatcher : InnerMatchers) {
407 BoundNodesTreeBuilder BuilderInner(*Builder);
408 if (InnerMatcher.matches(DynNode, Finder, &BuilderInner)) {
409 Matched = true;
410 Result.addMatch(BuilderInner);
411 }
412 }
413 *Builder = std::move(Result);
414 return Matched;
415}
416
417static bool anyOfVariadicOperator(const DynTypedNode &DynNode,
418 ASTMatchFinder *Finder,
419 BoundNodesTreeBuilder *Builder,
420 ArrayRef<DynTypedMatcher> InnerMatchers) {
421 for (const DynTypedMatcher &InnerMatcher : InnerMatchers) {
422 BoundNodesTreeBuilder Result = *Builder;
423 if (InnerMatcher.matches(DynNode, Finder, &Result)) {
424 *Builder = std::move(Result);
425 return true;
426 }
427 }
428 return false;
429}
430
431static bool
432optionallyVariadicOperator(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
433 BoundNodesTreeBuilder *Builder,
434 ArrayRef<DynTypedMatcher> InnerMatchers) {
435 if (InnerMatchers.size() != 1)
436 return false;
437
438 BoundNodesTreeBuilder Result(*Builder);
439 if (InnerMatchers[0].matches(DynNode, Finder, &Result))
440 *Builder = std::move(Result);
441 return true;
442}
443
444inline static
445std::vector<std::string> vectorFromRefs(ArrayRef<const StringRef *> NameRefs) {
446 std::vector<std::string> Names;
447 Names.reserve(NameRefs.size());
448 for (auto *Name : NameRefs)
449 Names.emplace_back(*Name);
450 return Names;
451}
452
453Matcher<NamedDecl> hasAnyNameFunc(ArrayRef<const StringRef *> NameRefs) {
454 return internal::Matcher<NamedDecl>(
455 new internal::HasNameMatcher(vectorFromRefs(NameRefs)));
456}
457
458Matcher<ObjCMessageExpr> hasAnySelectorFunc(
460 return hasAnySelectorMatcher(vectorFromRefs(NameRefs));
461}
462
464 return HasOpNameMatcher(vectorFromRefs(NameRefs));
465}
466
467HasOverloadOpNameMatcher
469 return HasOverloadOpNameMatcher(vectorFromRefs(NameRefs));
470}
471
472HasNameMatcher::HasNameMatcher(std::vector<std::string> N)
473 : UseUnqualifiedMatch(
474 llvm::all_of(N, [](StringRef Name) { return !Name.contains("::"); })),
475 Names(std::move(N)) {
476#ifndef NDEBUG
477 for (StringRef Name : Names)
478 assert(!Name.empty());
479#endif
480}
481
482static bool consumeNameSuffix(StringRef &FullName, StringRef Suffix) {
483 StringRef Name = FullName;
484 if (!Name.ends_with(Suffix))
485 return false;
486 Name = Name.drop_back(Suffix.size());
487 if (!Name.empty()) {
488 if (!Name.ends_with("::"))
489 return false;
490 Name = Name.drop_back(2);
491 }
492 FullName = Name;
493 return true;
494}
495
496static StringRef getNodeName(const NamedDecl &Node,
497 llvm::SmallString<128> &Scratch) {
498 // Simple name.
499 if (Node.getIdentifier())
500 return Node.getName();
501
502 if (Node.getDeclName()) {
503 // Name needs to be constructed.
504 Scratch.clear();
505 llvm::raw_svector_ostream OS(Scratch);
506 Node.printName(OS);
507 return OS.str();
508 }
509
510 return "(anonymous)";
511}
512
513static StringRef getNodeName(const RecordDecl &Node,
514 llvm::SmallString<128> &Scratch) {
515 if (Node.getIdentifier()) {
516 return Node.getName();
517 }
518 Scratch.clear();
519 return ("(anonymous " + Node.getKindName() + ")").toStringRef(Scratch);
520}
521
522static StringRef getNodeName(const NamespaceDecl &Node,
523 llvm::SmallString<128> &Scratch) {
524 return Node.isAnonymousNamespace() ? "(anonymous namespace)" : Node.getName();
525}
526
527namespace {
528
529class PatternSet {
530public:
531 PatternSet(ArrayRef<std::string> Names) {
532 Patterns.reserve(Names.size());
533 for (StringRef Name : Names)
534 Patterns.push_back({Name, Name.starts_with("::")});
535 }
536
537 /// Consumes the name suffix from each pattern in the set and removes the ones
538 /// that didn't match.
539 /// Return true if there are still any patterns left.
540 bool consumeNameSuffix(StringRef NodeName, bool CanSkip) {
541 if (CanSkip) {
542 // If we can skip the node, then we need to handle the case where a
543 // skipped node has the same name as its parent.
544 // namespace a { inline namespace a { class A; } }
545 // cxxRecordDecl(hasName("::a::A"))
546 // To do this, any patterns that match should be duplicated in our set,
547 // one of them with the tail removed.
548 for (size_t I = 0, E = Patterns.size(); I != E; ++I) {
549 StringRef Pattern = Patterns[I].P;
550 if (ast_matchers::internal::consumeNameSuffix(Patterns[I].P, NodeName))
551 Patterns.push_back({Pattern, Patterns[I].IsFullyQualified});
552 }
553 } else {
554 llvm::erase_if(Patterns, [&NodeName](auto &Pattern) {
556 NodeName);
557 });
558 }
559 return !Patterns.empty();
560 }
561
562 /// Check if any of the patterns are a match.
563 /// A match will be a pattern that was fully consumed, that also matches the
564 /// 'fully qualified' requirement.
565 bool foundMatch(bool AllowFullyQualified) const {
566 return llvm::any_of(Patterns, [&](const Pattern &Pattern) {
567 return Pattern.P.empty() &&
568 (AllowFullyQualified || !Pattern.IsFullyQualified);
569 });
570 }
571
572private:
573 struct Pattern {
574 StringRef P;
576 };
577
579};
580
581} // namespace
582
583bool HasNameMatcher::matchesNodeUnqualified(const NamedDecl &Node) const {
584 assert(UseUnqualifiedMatch);
586 StringRef NodeName = getNodeName(Node, Scratch);
587 return llvm::any_of(Names, [&](StringRef Name) {
588 return consumeNameSuffix(Name, NodeName) && Name.empty();
589 });
590}
591
592bool HasNameMatcher::matchesNodeFullFast(const NamedDecl &Node) const {
593 PatternSet Patterns(Names);
595
596 // This function is copied and adapted from NamedDecl::printQualifiedName()
597 // By matching each part individually we optimize in a couple of ways:
598 // - We can exit early on the first failure.
599 // - We can skip inline/anonymous namespaces without another pass.
600 // - We print one name at a time, reducing the chance of overflowing the
601 // inlined space of the SmallString.
602
603 // First, match the name.
604 if (!Patterns.consumeNameSuffix(getNodeName(Node, Scratch),
605 /*CanSkip=*/false))
606 return false;
607
608 // Try to match each declaration context.
609 // We are allowed to skip anonymous and inline namespaces if they don't match.
610 const DeclContext *Ctx = Node.getDeclContext();
611
612 if (Ctx->isFunctionOrMethod())
613 return Patterns.foundMatch(/*AllowFullyQualified=*/false);
614
615 for (; Ctx; Ctx = Ctx->getParent()) {
616 // Linkage Spec can just be ignored
617 // FIXME: Any other DeclContext kinds that can be safely disregarded
618 if (isa<LinkageSpecDecl>(Ctx))
619 continue;
620 if (!isa<NamedDecl>(Ctx))
621 break;
622 if (Patterns.foundMatch(/*AllowFullyQualified=*/false))
623 return true;
624
625 if (const auto *ND = dyn_cast<NamespaceDecl>(Ctx)) {
626 // If it matches (or we can skip it), continue.
627 if (Patterns.consumeNameSuffix(getNodeName(*ND, Scratch),
628 /*CanSkip=*/ND->isAnonymousNamespace() ||
629 ND->isInline()))
630 continue;
631 return false;
632 }
633 if (const auto *RD = dyn_cast<RecordDecl>(Ctx)) {
634 if (!isa<ClassTemplateSpecializationDecl>(Ctx)) {
635 if (Patterns.consumeNameSuffix(getNodeName(*RD, Scratch),
636 /*CanSkip=*/false))
637 continue;
638
639 return false;
640 }
641 }
642
643 // We don't know how to deal with this DeclContext.
644 // Fallback to the slow version of the code.
645 return matchesNodeFullSlow(Node);
646 }
647
648 return Patterns.foundMatch(/*AllowFullyQualified=*/true);
649}
650
651bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const {
652 const bool SkipUnwrittenCases[] = {false, true};
653 for (bool SkipUnwritten : SkipUnwrittenCases) {
654 llvm::SmallString<128> NodeName = StringRef("::");
655 llvm::raw_svector_ostream OS(NodeName);
656
657 PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
658 Policy.SuppressUnwrittenScope = SkipUnwritten;
659 Policy.SuppressInlineNamespace =
662 Node.printQualifiedName(OS, Policy);
663
664 const StringRef FullName = OS.str();
665
666 for (const StringRef Pattern : Names) {
667 if (Pattern.starts_with("::")) {
668 if (FullName == Pattern)
669 return true;
670 } else if (FullName.ends_with(Pattern) &&
671 FullName.drop_back(Pattern.size()).ends_with("::")) {
672 return true;
673 }
674 }
675 }
676
677 return false;
678}
679
680bool HasNameMatcher::matchesNode(const NamedDecl &Node) const {
681 assert(matchesNodeFullFast(Node) == matchesNodeFullSlow(Node));
682 if (UseUnqualifiedMatch) {
683 assert(matchesNodeUnqualified(Node) == matchesNodeFullFast(Node));
684 return matchesNodeUnqualified(Node);
685 }
686 return matchesNodeFullFast(Node);
687}
688
689// Checks whether \p Loc points to a token with source text of \p TokenText.
690static bool isTokenAtLoc(const SourceManager &SM, const LangOptions &LangOpts,
691 StringRef Text, SourceLocation Loc) {
693 bool Invalid = false;
694 // Since `Loc` may point into an expansion buffer, which has no corresponding
695 // source, we need to look at the spelling location to read the actual source.
696 StringRef TokenText = Lexer::getSpelling(SM.getSpellingLoc(Loc), Buffer, SM,
697 LangOpts, &Invalid);
698 return !Invalid && Text == TokenText;
699}
700
701static std::optional<SourceLocation> getExpansionLocOfMacroRecursive(
702 StringRef MacroName, SourceLocation Loc, const ASTContext &Context,
703 llvm::DenseSet<SourceLocation> &CheckedLocations) {
704 auto &SM = Context.getSourceManager();
705 const LangOptions &LangOpts = Context.getLangOpts();
706 while (Loc.isMacroID()) {
707 if (CheckedLocations.count(Loc))
708 return std::nullopt;
709 CheckedLocations.insert(Loc);
710 SrcMgr::ExpansionInfo Expansion =
711 SM.getSLocEntry(SM.getFileID(Loc)).getExpansion();
712 if (Expansion.isMacroArgExpansion()) {
713 // Check macro argument for an expansion of the given macro. For example,
714 // `F(G(3))`, where `MacroName` is `G`.
715 if (std::optional<SourceLocation> ArgLoc =
717 Expansion.getSpellingLoc(),
718 Context, CheckedLocations)) {
719 return ArgLoc;
720 }
721 }
722 Loc = Expansion.getExpansionLocStart();
723 if (isTokenAtLoc(SM, LangOpts, MacroName, Loc))
724 return Loc;
725 }
726 return std::nullopt;
727}
728
729std::optional<SourceLocation>
731 const ASTContext &Context) {
732 llvm::DenseSet<SourceLocation> CheckedLocations;
733 return getExpansionLocOfMacroRecursive(MacroName, Loc, Context,
734 CheckedLocations);
735}
736
737std::shared_ptr<llvm::Regex> createAndVerifyRegex(StringRef Regex,
738 llvm::Regex::RegexFlags Flags,
739 StringRef MatcherID) {
740 assert(!Regex.empty() && "Empty regex string");
741 auto SharedRegex = std::make_shared<llvm::Regex>(Regex, Flags);
742 std::string Error;
743 if (!SharedRegex->isValid(Error)) {
744 llvm::WithColor::error()
745 << "building matcher '" << MatcherID << "': " << Error << "\n";
746 llvm::WithColor::note() << " input was '" << Regex << "'\n";
747 }
748 return SharedRegex;
749}
750} // end namespace internal
751
752const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAutoreleasePoolStmt>
754const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl>
756const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl> typedefDecl;
757const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
759const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl> typeAliasDecl;
760const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl>
762const internal::VariadicAllOfMatcher<Decl> decl;
763const internal::VariadicDynCastAllOfMatcher<Decl, DecompositionDecl> decompositionDecl;
764const internal::VariadicDynCastAllOfMatcher<Decl, BindingDecl> bindingDecl;
765const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl>
767const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl;
768const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl;
769const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> namespaceDecl;
770const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl>
772const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl;
773const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl> cxxRecordDecl;
774const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl>
776const internal::VariadicDynCastAllOfMatcher<Decl,
779const internal::VariadicDynCastAllOfMatcher<
782const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl>
784const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl> parmVarDecl;
785const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl>
787const internal::VariadicAllOfMatcher<CXXBaseSpecifier> cxxBaseSpecifier;
788const internal::VariadicAllOfMatcher<CXXCtorInitializer> cxxCtorInitializer;
789const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument;
790const internal::VariadicAllOfMatcher<TemplateArgumentLoc> templateArgumentLoc;
791const internal::VariadicAllOfMatcher<TemplateName> templateName;
792const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl>
794const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
796const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTemplateParmDecl>
798
799const internal::VariadicAllOfMatcher<LambdaCapture> lambdaCapture;
800const internal::VariadicAllOfMatcher<QualType> qualType;
801const internal::VariadicAllOfMatcher<Type> type;
802const internal::VariadicAllOfMatcher<TypeLoc> typeLoc;
803
804const internal::VariadicDynCastAllOfMatcher<TypeLoc, QualifiedTypeLoc>
806const internal::VariadicDynCastAllOfMatcher<TypeLoc, PointerTypeLoc>
808const internal::VariadicDynCastAllOfMatcher<TypeLoc, ReferenceTypeLoc>
810const internal::VariadicDynCastAllOfMatcher<TypeLoc,
813const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
815
816const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryExprOrTypeTraitExpr>
818const internal::VariadicDynCastAllOfMatcher<Decl, ExportDecl> exportDecl;
819const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl;
820const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl>
822const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl>
824const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl;
825const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl>
827const internal::VariadicDynCastAllOfMatcher<Decl, TagDecl> tagDecl;
828const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> cxxMethodDecl;
829const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl>
831const internal::VariadicDynCastAllOfMatcher<Decl, ConceptDecl> conceptDecl;
832const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl;
833const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl;
834const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl>
836const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> functionDecl;
837const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl>
839const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl;
840const internal::VariadicAllOfMatcher<Stmt> stmt;
841const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt;
842const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr;
843const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr>
845const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDependentScopeMemberExpr>
847const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr;
848const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr;
849const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr>
851const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr>
853const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl>
855const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl>
857const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl>
859const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl>
861const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl>
863const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl>
865const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl>
867const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl> objcIvarDecl;
868const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl>
870const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt>
872const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt> objcTryStmt;
873const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt>
875const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt>
877const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups>
879const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> initListExpr;
880const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStdInitializerListExpr>
882const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr>
884const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr> parenListExpr;
885const internal::VariadicDynCastAllOfMatcher<Stmt, SubstNonTypeTemplateParmExpr>
887const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl;
888const internal::VariadicDynCastAllOfMatcher<Decl, UsingEnumDecl> usingEnumDecl;
889const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl>
891const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr>
893const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingValueDecl>
895const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingTypenameDecl>
897const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr> constantExpr;
898const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr;
899const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr>
901const internal::VariadicDynCastAllOfMatcher<Stmt, CXXUnresolvedConstructExpr>
903const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> cxxThisExpr;
904const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr>
906const internal::VariadicDynCastAllOfMatcher<Stmt, MaterializeTemporaryExpr>
908const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr;
909const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> cxxDeleteExpr;
910const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr>
912const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr>
914const internal::VariadicDynCastAllOfMatcher<Stmt, ArrayInitIndexExpr>
916const internal::VariadicDynCastAllOfMatcher<Stmt, ArrayInitLoopExpr>
918const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr>
920const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr>
922const internal::VariadicDynCastAllOfMatcher<Stmt, CXXRewrittenBinaryOperator>
924const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFoldExpr> cxxFoldExpr;
925const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr;
926const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr;
927const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr> objcIvarRefExpr;
928const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr;
929const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt;
930const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt;
931const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt>
933const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt;
934const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt;
935const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt;
936const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt> continueStmt;
937const internal::VariadicDynCastAllOfMatcher<Stmt, CoreturnStmt> coreturnStmt;
938const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt;
939const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt;
940const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt;
941const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr> addrLabelExpr;
942const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt;
943const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase;
944const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt;
945const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt> defaultStmt;
946const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> compoundStmt;
947const internal::VariadicDynCastAllOfMatcher<Stmt, CoroutineBodyStmt>
949const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> cxxCatchStmt;
950const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt;
951const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr;
952const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt;
953const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
954const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr>
956const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral;
957const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCStringLiteral> objcStringLiteral;
958const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral>
960const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral>
962const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral;
963const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> imaginaryLiteral;
964const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral>
966const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral>
968const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr>
970const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr>
972const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> chooseExpr;
973const internal::VariadicDynCastAllOfMatcher<Stmt, ConvertVectorExpr>
975const internal::VariadicDynCastAllOfMatcher<Stmt, CoawaitExpr>
977const internal::VariadicDynCastAllOfMatcher<Stmt, DependentCoawaitExpr>
979const internal::VariadicDynCastAllOfMatcher<Stmt, CoyieldExpr>
981const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr> gnuNullExpr;
982const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr>
984const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr;
985const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr;
986const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator>
988const internal::MapAnyOfMatcher<BinaryOperator, CXXOperatorCallExpr,
991const internal::MapAnyOfMatcher<CallExpr, CXXConstructExpr> invocation;
992const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator> unaryOperator;
993const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator>
995const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryConditionalOperator>
997const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr>
999const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl>
1001const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr>
1003const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr>
1005const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr>
1007const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr>
1009const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr>
1011const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr>
1013const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr>
1015const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr;
1016const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr>
1018const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr>
1020const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr>
1022const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr>
1024const internal::VariadicOperatorMatcherFunc<
1025 2, std::numeric_limits<unsigned>::max()>
1026 eachOf = {internal::DynTypedMatcher::VO_EachOf};
1027const internal::VariadicOperatorMatcherFunc<
1028 2, std::numeric_limits<unsigned>::max()>
1029 anyOf = {internal::DynTypedMatcher::VO_AnyOf};
1030const internal::VariadicOperatorMatcherFunc<
1031 2, std::numeric_limits<unsigned>::max()>
1032 allOf = {internal::DynTypedMatcher::VO_AllOf};
1033const internal::VariadicOperatorMatcherFunc<1, 1> optionally = {
1034 internal::DynTypedMatcher::VO_Optionally};
1035const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef,
1036 internal::hasAnyNameFunc>
1038
1039const internal::VariadicFunction<internal::HasOpNameMatcher, StringRef,
1040 internal::hasAnyOperatorNameFunc>
1042const internal::VariadicFunction<internal::HasOverloadOpNameMatcher, StringRef,
1043 internal::hasAnyOverloadedOperatorNameFunc>
1045const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>, StringRef,
1046 internal::hasAnySelectorFunc>
1048const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has = {};
1049const internal::ArgumentAdaptingMatcherFunc<internal::HasDescendantMatcher>
1051const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> forEach =
1052 {};
1053const internal::ArgumentAdaptingMatcherFunc<internal::ForEachDescendantMatcher>
1055const internal::ArgumentAdaptingMatcherFunc<
1056 internal::HasParentMatcher,
1057 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
1058 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
1060const internal::ArgumentAdaptingMatcherFunc<
1061 internal::HasAncestorMatcher,
1062 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
1063 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
1065const internal::VariadicOperatorMatcherFunc<1, 1> unless = {
1066 internal::DynTypedMatcher::VO_UnaryNot};
1067const internal::VariadicAllOfMatcher<NestedNameSpecifier> nestedNameSpecifier;
1068const internal::VariadicAllOfMatcher<NestedNameSpecifierLoc>
1070const internal::VariadicAllOfMatcher<Attr> attr;
1071const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr>
1111 ComplexType));
1115 pointee,
1119
1120const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective>
1122const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPDefaultClause>
1124const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl>
1126
1127} // end namespace ast_matchers
1128} // end namespace clang
Defines the clang::ASTContext interface.
DynTypedNode Node
DynTypedMatcher::MatcherIDType MatcherID
bool IsFullyQualified
StringRef P
#define AST_POLYMORPHIC_SUPPORTED_TYPES(...)
Construct a type-list to be passed to the AST_POLYMORPHIC_MATCHER* macros.
#define AST_TYPELOC_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF)
#define AST_MATCHER_P(Type, DefineMatcher, ParamType, Param)
AST_MATCHER_P(Type, DefineMatcher, ParamType, Param) { ... } defines a single-parameter function name...
static char ID
Definition: Arena.cpp:183
#define SM(sm)
Definition: Cuda.cpp:84
Expr * E
enum clang::sema::@1718::IndirectLocalPathEntry::EntryKind Kind
Defines the C++ template declaration subclasses.
StringRef Text
Definition: Format.cpp:3033
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
int32_t FullName
Definition: SemaARM.cpp:1135
SourceLocation Loc
Definition: SemaObjC.cpp:759
#define bool
Definition: amdgpuintrin.h:20
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
static ASTNodeKind getMostDerivedType(ASTNodeKind Kind1, ASTNodeKind Kind2)
Return the most derived type between Kind1 and Kind2.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3577
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3909
Pointer to a block type.
Definition: Type.h:3408
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:81
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
Represents a class template specialization, which refers to a class template with a given set of temp...
Complex values, per C99 6.2.5p11.
Definition: Type.h:3145
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
A dynamically typed AST node container.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:499
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer,...
Definition: Lexer.cpp:451
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3519
This represents a decl that may have a name.
Definition: Decl.h:253
Represent a C++ namespace.
Definition: Decl.h:551
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:941
Represents a pointer to an Objective C object.
Definition: Type.h:7580
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3198
Represents a struct/union/class.
Definition: Decl.h:4148
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3439
Encodes a location in the source.
This class handles loading and caching of source files into memory.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
Maps string IDs to AST nodes matched by parts of a matcher.
Definition: ASTMatchers.h:109
HasOverloadOpNameMatcher hasAnyOverloadedOperatorNameFunc(ArrayRef< const StringRef * > NameRefs)
static std::vector< std::string > vectorFromRefs(ArrayRef< const StringRef * > NameRefs)
std::shared_ptr< llvm::Regex > createAndVerifyRegex(StringRef Regex, llvm::Regex::RegexFlags Flags, StringRef MatcherID)
Matcher< ObjCMessageExpr > hasAnySelectorFunc(ArrayRef< const StringRef * > NameRefs)
static bool eachOfVariadicOperator(const DynTypedNode &DynNode, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, ArrayRef< DynTypedMatcher > InnerMatchers)
static bool isTokenAtLoc(const SourceManager &SM, const LangOptions &LangOpts, StringRef Text, SourceLocation Loc)
static StringRef getNodeName(const NamedDecl &Node, llvm::SmallString< 128 > &Scratch)
static bool anyOfVariadicOperator(const DynTypedNode &DynNode, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, ArrayRef< DynTypedMatcher > InnerMatchers)
static bool optionallyVariadicOperator(const DynTypedNode &DynNode, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, ArrayRef< DynTypedMatcher > InnerMatchers)
Matcher< NamedDecl > hasAnyNameFunc(ArrayRef< const StringRef * > NameRefs)
HasOpNameMatcher hasAnyOperatorNameFunc(ArrayRef< const StringRef * > NameRefs)
static bool notUnaryOperator(const DynTypedNode &DynNode, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, ArrayRef< DynTypedMatcher > InnerMatchers)
std::optional< SourceLocation > getExpansionLocOfMacro(StringRef MacroName, SourceLocation Loc, const ASTContext &Context)
static bool consumeNameSuffix(StringRef &FullName, StringRef Suffix)
bool matchesAnyBase(const CXXRecordDecl &Node, const Matcher< CXXBaseSpecifier > &BaseSpecMatcher, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder)
static std::optional< SourceLocation > getExpansionLocOfMacroRecursive(StringRef MacroName, SourceLocation Loc, const ASTContext &Context, llvm::DenseSet< SourceLocation > &CheckedLocations)
static bool allOfVariadicOperator(const DynTypedNode &DynNode, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder, ArrayRef< DynTypedMatcher > InnerMatchers)
const internal::VariadicDynCastAllOfMatcher< Stmt, FixedPointLiteral > fixedPointLiteral
Matches fixed point literals.
const internal::VariadicDynCastAllOfMatcher< Stmt, CStyleCastExpr > cStyleCastExpr
Matches a C-style cast expression.
const internal::VariadicDynCastAllOfMatcher< Decl, TagDecl > tagDecl
Matches tag declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXReinterpretCastExpr > cxxReinterpretCastExpr
Matches a reinterpret_cast expression.
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
const internal::VariadicDynCastAllOfMatcher< TypeLoc, ElaboratedTypeLoc > elaboratedTypeLoc
Matches C or C++ elaborated TypeLocs.
const internal::VariadicDynCastAllOfMatcher< Stmt, StmtExpr > stmtExpr
Matches statement expression (GNU extension).
const internal::VariadicDynCastAllOfMatcher< Stmt, ExprWithCleanups > exprWithCleanups
Matches expressions that introduce cleanups to be run at the end of the sub-expression's evaluation.
const internal::VariadicDynCastAllOfMatcher< Stmt, DeclRefExpr > declRefExpr
Matches expressions that refer to declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, TypedefNameDecl > typedefNameDecl
Matches typedef name declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCIvarDecl > objcIvarDecl
Matches Objective-C instance variable declarations.
const AstTypeMatcher< EnumType > enumType
Matches enum types.
const AstTypeMatcher< FunctionProtoType > functionProtoType
Matches FunctionProtoType nodes.
const AstTypeMatcher< ElaboratedType > elaboratedType
Matches types specified with an elaborated type keyword or with a qualified name.
const internal::VariadicDynCastAllOfMatcher< Decl, TypeAliasDecl > typeAliasDecl
Matches type alias declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, UsingEnumDecl > usingEnumDecl
Matches using-enum declarations.
const AstTypeMatcher< ObjCObjectPointerType > objcObjectPointerType
Matches an Objective-C object pointer type, which is different from a pointer type,...
const internal::VariadicDynCastAllOfMatcher< Stmt, ConstantExpr > constantExpr
Matches a constant expression wrapper.
const internal::VariadicDynCastAllOfMatcher< Stmt, ArrayInitLoopExpr > arrayInitLoopExpr
Matches a loop initializing the elements of an array in a number of contexts:
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCIvarRefExpr > objcIvarRefExpr
Matches a reference to an ObjCIvar.
const AstTypeMatcher< BuiltinType > builtinType
Matches builtin Types.
const internal::VariadicOperatorMatcherFunc< 1, 1 > unless
Matches if the provided matcher does not match.
const internal::VariadicDynCastAllOfMatcher< Decl, ConceptDecl > conceptDecl
Matches concept declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CoyieldExpr > coyieldExpr
Matches co_yield expressions.
const AstTypeMatcher< DependentSizedExtVectorType > dependentSizedExtVectorType
Matches C++ extended vector type where either the type or size is dependent.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDeleteExpr > cxxDeleteExpr
Matches delete expressions.
const internal::VariadicAllOfMatcher< TemplateName > templateName
Matches template name.
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCProtocolDecl > objcProtocolDecl
Matches Objective-C protocol declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, ImplicitCastExpr > implicitCastExpr
Matches the implicit cast nodes of Clang's AST.
const internal::VariadicOperatorMatcherFunc< 1, 1 > optionally
Matches any node regardless of the submatcher.
const internal::VariadicDynCastAllOfMatcher< Decl, UsingDecl > usingDecl
Matches using declarations.
const internal::ArgumentAdaptingMatcherFunc< internal::HasDescendantMatcher > hasDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher.
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCPropertyDecl > objcPropertyDecl
Matches Objective-C property declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, StringLiteral > stringLiteral
Matches string literals (also matches wide string literals).
const internal::VariadicAllOfMatcher< CXXCtorInitializer > cxxCtorInitializer
Matches constructor initializers.
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCAtFinallyStmt > objcFinallyStmt
Matches Objective-C @finally statements.
const AstTypeMatcher< DependentSizedArrayType > dependentSizedArrayType
Matches C++ arrays whose size is a value-dependent expression.
const AstTypeMatcher< TemplateSpecializationType > templateSpecializationType
Matches template specialization types.
const internal::VariadicDynCastAllOfMatcher< Stmt, AtomicExpr > atomicExpr
Matches atomic builtins.
const AstTypeMatcher< DeducedTemplateSpecializationType > deducedTemplateSpecializationType
Matches C++17 deduced template specialization types, e.g.
const internal::VariadicDynCastAllOfMatcher< Stmt, CoawaitExpr > coawaitExpr
Matches co_await expressions.
const internal::VariadicDynCastAllOfMatcher< Decl, EnumDecl > enumDecl
Matches enum declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, ConvertVectorExpr > convertVectorExpr
Matches builtin function __builtin_convertvector.
const internal::VariadicDynCastAllOfMatcher< Stmt, AddrLabelExpr > addrLabelExpr
Matches address of label statements (GNU extension).
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDependentScopeMemberExpr > cxxDependentScopeMemberExpr
Matches member expressions where the actual member referenced could not be resolved because the base ...
const internal::VariadicDynCastAllOfMatcher< Stmt, PredefinedExpr > predefinedExpr
Matches predefined identifier expressions [C99 6.4.2.2].
const internal::VariadicAllOfMatcher< NestedNameSpecifier > nestedNameSpecifier
Matches nested name specifiers.
const AstTypeMatcher< PointerType > pointerType
Matches pointer types, but does not match Objective-C object pointer types.
const internal::VariadicDynCastAllOfMatcher< Stmt, DependentCoawaitExpr > dependentCoawaitExpr
Matches co_await expressions where the type of the promise is dependent.
const internal::VariadicDynCastAllOfMatcher< Stmt, BreakStmt > breakStmt
Matches break statements.
const internal::VariadicDynCastAllOfMatcher< Decl, BindingDecl > bindingDecl
Matches binding declarations Example matches foo and bar (matcher = bindingDecl()
const internal::VariadicDynCastAllOfMatcher< Stmt, UnresolvedLookupExpr > unresolvedLookupExpr
Matches reference to a name that can be looked up during parsing but could not be resolved to a speci...
const internal::VariadicDynCastAllOfMatcher< Stmt, OMPExecutableDirective > ompExecutableDirective
Matches any #pragma omp executable directive.
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCStringLiteral > objcStringLiteral
Matches ObjectiveC String literal expressions.
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCMethodDecl > objcMethodDecl
Matches Objective-C method declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, ParmVarDecl > parmVarDecl
Matches parameter variable declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXRewrittenBinaryOperator > cxxRewrittenBinaryOperator
Matches rewritten binary operators.
const internal::VariadicDynCastAllOfMatcher< Decl, TypedefDecl > typedefDecl
Matches typedef declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, GenericSelectionExpr > genericSelectionExpr
Matches C11 _Generic expression.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXDeductionGuideDecl > cxxDeductionGuideDecl
Matches user-defined and implicitly generated deduction guide.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXBoolLiteralExpr > cxxBoolLiteral
Matches bool literals.
const internal::VariadicDynCastAllOfMatcher< Stmt, ReturnStmt > returnStmt
Matches return statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, AsmStmt > asmStmt
Matches asm statements.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDynamicCastExpr > cxxDynamicCastExpr
Matches a dynamic_cast expression.
const internal::VariadicDynCastAllOfMatcher< Stmt, CoreturnStmt > coreturnStmt
Matches co_return statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, LambdaExpr > lambdaExpr
Matches lambda expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, CompoundStmt > compoundStmt
Matches compound statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, FloatingLiteral > floatLiteral
Matches float literals of all sizes / encodings, e.g.
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCAutoreleasePoolStmt > autoreleasePoolStmt
Matches an Objective-C autorelease pool statement.
const internal::VariadicFunction< internal::PolymorphicMatcher< internal::HasOverloadedOperatorNameMatcher, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl), std::vector< std::string > >, StringRef, internal::hasAnyOverloadedOperatorNameFunc > hasAnyOverloadedOperatorName
Matches overloaded operator names.
const internal::VariadicDynCastAllOfMatcher< Decl, NonTypeTemplateParmDecl > nonTypeTemplateParmDecl
Matches non-type template parameter declarations.
const AstTypeMatcher< VariableArrayType > variableArrayType
Matches C arrays with a specified size that is not an integer-constant-expression.
const internal::VariadicDynCastAllOfMatcher< Stmt, UnaryExprOrTypeTraitExpr > unaryExprOrTypeTraitExpr
Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
const internal::VariadicDynCastAllOfMatcher< Stmt, NullStmt > nullStmt
Matches null statements.
const internal::VariadicDynCastAllOfMatcher< TypeLoc, TemplateSpecializationTypeLoc > templateSpecializationTypeLoc
Matches template specialization TypeLocs.
const internal::ArgumentAdaptingMatcherFunc< internal::ForEachDescendantMatcher > forEachDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher.
const internal::VariadicAllOfMatcher< CXXBaseSpecifier > cxxBaseSpecifier
Matches class bases.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXDefaultArgExpr > cxxDefaultArgExpr
Matches the value of a default argument at the call site.
const internal::VariadicAllOfMatcher< TemplateArgument > templateArgument
Matches template arguments.
const internal::ArgumentAdaptingMatcherFunc< internal::ForEachMatcher > forEach
Matches AST nodes that have child AST nodes that match the provided matcher.
const internal::VariadicDynCastAllOfMatcher< Stmt, CaseStmt > caseStmt
Matches case statements inside switch statements.
const internal::VariadicAllOfMatcher< NestedNameSpecifierLoc > nestedNameSpecifierLoc
Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.
const internal::VariadicDynCastAllOfMatcher< Decl, NamedDecl > namedDecl
Matches a declaration of anything that could have a name.
const internal::VariadicDynCastAllOfMatcher< Decl, UnresolvedUsingTypenameDecl > unresolvedUsingTypenameDecl
Matches unresolved using value declarations that involve the typename.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< DecltypeType > decltypeType
Matches types nodes representing C++11 decltype(<expr>) types.
const internal::VariadicAllOfMatcher< TypeLoc > typeLoc
Matches TypeLocs in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, ParenListExpr > parenListExpr
Matches paren list expressions.
const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplatePartialSpecializationDecl > classTemplatePartialSpecializationDecl
Matches C++ class template partial specializations.
const internal::VariadicDynCastAllOfMatcher< Stmt, WhileStmt > whileStmt
Matches while statements.
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCCategoryDecl > objcCategoryDecl
Matches Objective-C category declarations.
const internal::VariadicFunction< internal::Matcher< ObjCMessageExpr >, StringRef, internal::hasAnySelectorFunc > hasAnySelector
Matches when at least one of the supplied string equals to the Selector.getAsString()
const AstTypeMatcher< AutoType > autoType
Matches types nodes representing C++11 auto types.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXConversionDecl > cxxConversionDecl
Matches conversion operator declarations.
const AstTypeMatcher< ParenType > parenType
Matches ParenType nodes.
const internal::VariadicDynCastAllOfMatcher< Decl, LabelDecl > labelDecl
Matches a declaration of label.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXFunctionalCastExpr > cxxFunctionalCastExpr
Matches functional cast expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstCastExpr > cxxConstCastExpr
Matches a const_cast expression.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXTemporaryObjectExpr > cxxTemporaryObjectExpr
Matches functional cast expressions having N != 1 arguments.
const internal::VariadicDynCastAllOfMatcher< Stmt, UnaryOperator > unaryOperator
Matches unary operator expressions.
const internal::VariadicDynCastAllOfMatcher< TypeLoc, ReferenceTypeLoc > referenceTypeLoc
Matches reference TypeLocs.
const internal::VariadicFunction< internal::Matcher< NamedDecl >, StringRef, internal::hasAnyNameFunc > hasAnyName
Matches NamedDecl nodes that have any of the specified names.
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCMessageExpr > objcMessageExpr
Matches ObjectiveC Message invocation expressions.
const internal::MapAnyOfMatcher< BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator > binaryOperation
Matches nodes which can be used with binary operators.
const internal::VariadicDynCastAllOfMatcher< Stmt, ArraySubscriptExpr > arraySubscriptExpr
Matches array subscript expressions.
const internal::VariadicDynCastAllOfMatcher< OMPClause, OMPDefaultClause > ompDefaultClause
Matches OpenMP default clause.
const internal::VariadicDynCastAllOfMatcher< Decl, AccessSpecDecl > accessSpecDecl
Matches C++ access specifier declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, LinkageSpecDecl > linkageSpecDecl
Matches a declaration of a linkage specification.
const AstTypeMatcher< InjectedClassNameType > injectedClassNameType
Matches injected class name types.
const internal::VariadicDynCastAllOfMatcher< Stmt, GNUNullExpr > gnuNullExpr
Matches GNU __null expression.
const internal::VariadicDynCastAllOfMatcher< TypeLoc, PointerTypeLoc > pointerTypeLoc
Matches pointer TypeLocs.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXForRangeStmt > cxxForRangeStmt
Matches range-based for statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXMemberCallExpr > cxxMemberCallExpr
Matches member call expressions.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXConstructorDecl > cxxConstructorDecl
Matches C++ constructor declarations.
const AstTypeMatcher< BlockPointerType > blockPointerType
Matches block pointer types, i.e.
const internal::VariadicDynCastAllOfMatcher< Stmt, InitListExpr > initListExpr
Matches init list expressions.
const AstTypeMatcher< AtomicType > atomicType
Matches atomic types.
const internal::VariadicDynCastAllOfMatcher< Decl, TypeAliasTemplateDecl > typeAliasTemplateDecl
Matches type alias template declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXNoexceptExpr > cxxNoexceptExpr
Matches noexcept expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, ArrayInitIndexExpr > arrayInitIndexExpr
The arrayInitIndexExpr consists of two subexpressions: a common expression (the source array) that is...
internal::VariadicDynCastAllOfMatcher< Type, NodeType > AstTypeMatcher
Definition: ASTMatchers.h:7027
const AstTypeMatcher< UsingType > usingType
Matches types specified through a using declaration.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXNewExpr > cxxNewExpr
Matches new expressions.
const internal::VariadicDynCastAllOfMatcher< Decl, EnumConstantDecl > enumConstantDecl
Matches enum constants.
const internal::VariadicDynCastAllOfMatcher< Stmt, ForStmt > forStmt
Matches for statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, GotoStmt > gotoStmt
Matches goto statements.
const internal::VariadicDynCastAllOfMatcher< Decl, DeclaratorDecl > declaratorDecl
Matches declarator declarations (field, variable, function and non-type template parameter declaratio...
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCAtCatchStmt > objcCatchStmt
Matches Objective-C @catch statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, BinaryOperator > binaryOperator
Matches binary operator expressions.
const internal::VariadicDynCastAllOfMatcher< TypeLoc, QualifiedTypeLoc > qualifiedTypeLoc
Matches QualifiedTypeLocs in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, TemplateTypeParmDecl > templateTypeParmDecl
Matches template type parameter declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, BlockExpr > blockExpr
Matches a reference to a block.
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionTemplateDecl > functionTemplateDecl
Matches C++ function template declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, ParenExpr > parenExpr
Matches parentheses used in expressions.
const internal::VariadicDynCastAllOfMatcher< Decl, StaticAssertDecl > staticAssertDecl
Matches a C++ static_assert declaration.
const internal::ArgumentAdaptingMatcherFunc< internal::HasMatcher > has
Matches AST nodes that have child AST nodes that match the provided matcher.
const internal::VariadicDynCastAllOfMatcher< Stmt, CoroutineBodyStmt > coroutineBodyStmt
Matches coroutine body statements.
const AstTypeMatcher< MacroQualifiedType > macroQualifiedType
Matches qualified types when the qualifier is applied via a macro.
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCCategoryImplDecl > objcCategoryImplDecl
Matches Objective-C category definitions.
const AstTypeMatcher< TypedefType > typedefType
Matches typedef types.
const internal::VariadicDynCastAllOfMatcher< Stmt, MaterializeTemporaryExpr > materializeTemporaryExpr
Matches nodes where temporaries are materialized.
const AstTypeMatcher< TagType > tagType
Matches tag types (record and enum types).
const internal::VariadicDynCastAllOfMatcher< Stmt, BinaryConditionalOperator > binaryConditionalOperator
Matches binary conditional operator expressions (GNU extension).
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCAtTryStmt > objcTryStmt
Matches Objective-C @try statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, ExplicitCastExpr > explicitCastExpr
Matches explicit cast expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXStaticCastExpr > cxxStaticCastExpr
Matches a C++ static_cast expression.
const internal::VariadicDynCastAllOfMatcher< Decl, ValueDecl > valueDecl
Matches any value declaration.
const internal::VariadicDynCastAllOfMatcher< Decl, TranslationUnitDecl > translationUnitDecl
Matches the top declaration context.
const AstTypeMatcher< TemplateTypeParmType > templateTypeParmType
Matches template type parameter types.
const AstTypeMatcher< ConstantArrayType > constantArrayType
Matches C arrays with a specified constant size.
const internal::VariadicAllOfMatcher< LambdaCapture > lambdaCapture
Matches lambda captures.
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> eachOf
Matches if any of the given matchers matches.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstructExpr > cxxConstructExpr
Matches constructor call expressions (including implicit ones).
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCInterfaceDecl > objcInterfaceDecl
Matches Objective-C interface declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, TemplateTemplateParmDecl > templateTemplateParmDecl
Matches template template parameter declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, FieldDecl > fieldDecl
Matches field declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, UserDefinedLiteral > userDefinedLiteral
Matches user defined literal operator call.
const internal::VariadicDynCastAllOfMatcher< Stmt, ChooseExpr > chooseExpr
Matches GNU __builtin_choose_expr.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXOperatorCallExpr > cxxOperatorCallExpr
Matches overloaded operator calls.
const internal::VariadicDynCastAllOfMatcher< Decl, NamespaceAliasDecl > namespaceAliasDecl
Matches a declaration of a namespace alias.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXBindTemporaryExpr > cxxBindTemporaryExpr
Matches nodes where temporaries are created.
const internal::VariadicDynCastAllOfMatcher< Stmt, SwitchCase > switchCase
Matches case and default statements inside switch statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, DefaultStmt > defaultStmt
Matches default statements inside switch statements.
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> allOf
Matches if all given matchers match.
const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplateSpecializationDecl > classTemplateSpecializationDecl
Matches C++ class template specializations.
const internal::VariadicDynCastAllOfMatcher< Decl, DecompositionDecl > decompositionDecl
Matches decomposition-declarations.
const AstTypeMatcher< SubstTemplateTypeParmType > substTemplateTypeParmType
Matches types that represent the result of substituting a type for a template type parameter.
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionDecl > functionDecl
Matches function declarations.
const AstTypeMatcher< UnaryTransformType > unaryTransformType
Matches types nodes representing unary type transformations.
const internal::VariadicDynCastAllOfMatcher< Stmt, UnresolvedMemberExpr > unresolvedMemberExpr
Matches unresolved member expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, ObjCAtThrowStmt > objcThrowStmt
Matches Objective-C @throw statements.
const internal::MapAnyOfMatcher< CallExpr, CXXConstructExpr > invocation
Matches function calls and constructor calls.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXThrowExpr > cxxThrowExpr
Matches throw expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, SwitchStmt > switchStmt
Matches switch statements.
const AstTypeMatcher< RecordType > recordType
Matches record types (e.g.
const internal::VariadicDynCastAllOfMatcher< Stmt, MemberExpr > memberExpr
Matches member expressions.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXRecordDecl > cxxRecordDecl
Matches C++ class declarations.
const internal::VariadicAllOfMatcher< TemplateArgumentLoc > templateArgumentLoc
Matches template arguments (with location info).
const AstTypeMatcher< ReferenceType > referenceType
Matches both lvalue and rvalue reference types.
const internal::VariadicDynCastAllOfMatcher< Stmt, DesignatedInitExpr > designatedInitExpr
Matches C99 designated initializer expressions [C99 6.7.8].
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXDestructorDecl > cxxDestructorDecl
Matches explicit C++ destructor declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXUnresolvedConstructExpr > cxxUnresolvedConstructExpr
Matches unresolved constructor call expressions.
const internal::VariadicDynCastAllOfMatcher< Decl, ObjCImplementationDecl > objcImplementationDecl
Matches Objective-C implementation declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, RecordDecl > recordDecl
Matches class, struct, and union declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, IntegerLiteral > integerLiteral
Matches integer literals of all sizes / encodings, e.g.
const internal::VariadicDynCastAllOfMatcher< Decl, ExportDecl > exportDecl
Matches any export declaration.
const internal::VariadicDynCastAllOfMatcher< Stmt, ImplicitValueInitExpr > implicitValueInitExpr
Matches implicit initializers of init list expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, DoStmt > doStmt
Matches do statements.
const internal::VariadicDynCastAllOfMatcher< Decl, NamespaceDecl > namespaceDecl
Matches a declaration of a namespace.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXNullPtrLiteralExpr > cxxNullPtrLiteralExpr
Matches nullptr literal.
const AstTypeMatcher< DecayedType > decayedType
Matches decayed type Example matches i[] in declaration of f.
const internal::VariadicDynCastAllOfMatcher< Stmt, DeclStmt > declStmt
Matches declaration statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, CompoundLiteralExpr > compoundLiteralExpr
Matches compound (i.e.
const AstTypeMatcher< MemberPointerType > memberPointerType
Matches member pointer types.
const internal::VariadicDynCastAllOfMatcher< Stmt, LabelStmt > labelStmt
Matches label statements.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
const internal::VariadicDynCastAllOfMatcher< Decl, FriendDecl > friendDecl
Matches friend declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
const AstTypeMatcher< IncompleteArrayType > incompleteArrayType
Matches C arrays with unspecified size.
const internal::VariadicDynCastAllOfMatcher< Stmt, CharacterLiteral > characterLiteral
Matches character literals (also matches wchar_t).
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXFoldExpr > cxxFoldExpr
Matches C++17 fold expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, ConditionalOperator > conditionalOperator
Matches conditional operator expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXStdInitializerListExpr > cxxStdInitializerListExpr
Matches C++ initializer list expressions.
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> anyOf
Matches if any of the given matchers matches.
const internal::VariadicFunction< internal::PolymorphicMatcher< internal::HasAnyOperatorNameMatcher, AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, UnaryOperator), std::vector< std::string > >, StringRef, internal::hasAnyOperatorNameFunc > hasAnyOperatorName
Matches operator expressions (binary or unary) that have any of the specified names.
const internal::VariadicDynCastAllOfMatcher< Stmt, OpaqueValueExpr > opaqueValueExpr
Matches opaque value expressions.
const AstTypeMatcher< ComplexType > complexType
Matches C99 complex types.
const internal::VariadicDynCastAllOfMatcher< Stmt, CUDAKernelCallExpr > cudaKernelCallExpr
Matches CUDA kernel call expression.
const internal::VariadicDynCastAllOfMatcher< Decl, IndirectFieldDecl > indirectFieldDecl
Matches indirect field declarations.
const AstTypeMatcher< FunctionType > functionType
Matches FunctionType nodes.
const internal::VariadicDynCastAllOfMatcher< Decl, BlockDecl > blockDecl
Matches block declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXMethodDecl > cxxMethodDecl
Matches method declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXCatchStmt > cxxCatchStmt
Matches catch statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
const internal::VariadicAllOfMatcher< QualType > qualType
Matches QualTypes in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXTryStmt > cxxTryStmt
Matches try statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, SubstNonTypeTemplateParmExpr > substNonTypeTemplateParmExpr
Matches substitutions of non-type template parameters.
const internal::VariadicDynCastAllOfMatcher< Decl, UsingDirectiveDecl > usingDirectiveDecl
Matches using namespace declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, UnresolvedUsingValueDecl > unresolvedUsingValueDecl
Matches unresolved using value declarations.
const internal::ArgumentAdaptingMatcherFunc< internal::HasAncestorMatcher, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr >, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr > > hasAncestor
Matches AST nodes that have an ancestor that matches the provided matcher.
const internal::ArgumentAdaptingMatcherFunc< internal::HasParentMatcher, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr >, internal::TypeList< Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr > > hasParent
Matches AST nodes that have a parent that matches the provided matcher.
const internal::VariadicDynCastAllOfMatcher< Stmt, IfStmt > ifStmt
Matches if statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXThisExpr > cxxThisExpr
Matches implicit and explicit this expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, ImaginaryLiteral > imaginaryLiteral
Matches imaginary literals, which are based on integer and floating point literals e....
const AstTypeMatcher< RValueReferenceType > rValueReferenceType
Matches rvalue reference types.
const internal::VariadicDynCastAllOfMatcher< Stmt, ContinueStmt > continueStmt
Matches continue statements.
const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplateDecl > classTemplateDecl
Matches C++ class template declarations.
const AstTypeMatcher< LValueReferenceType > lValueReferenceType
Matches lvalue reference types.
The JSON file list parser is used to communicate input to InstallAPI.
TraversalKind
Defines how we descend a level in the AST when we pass through expressions.
Definition: ASTTypeTraits.h:38
@ TK_IgnoreUnlessSpelledInSource
Ignore AST nodes not written in the source.
Definition: ASTTypeTraits.h:43
@ Result
The result type of a method or function.
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30