1 | //===- ASTMatchersInternal.cpp - Structural query framework ---------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // Implements the base layer of the matcher framework. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "clang/ASTMatchers/ASTMatchersInternal.h" |
14 | #include "clang/AST/ASTContext.h" |
15 | #include "clang/AST/ASTTypeTraits.h" |
16 | #include "clang/AST/Decl.h" |
17 | #include "clang/AST/DeclTemplate.h" |
18 | #include "clang/AST/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" |
34 | #include <algorithm> |
35 | #include <cassert> |
36 | #include <cstddef> |
37 | #include <optional> |
38 | #include <string> |
39 | #include <utility> |
40 | #include <vector> |
41 | |
42 | namespace clang { |
43 | namespace ast_matchers { |
44 | |
45 | AST_MATCHER_P(ObjCMessageExpr, hasAnySelectorMatcher, std::vector<std::string>, |
46 | Matches) { |
47 | return llvm::is_contained(Range: Matches, Element: Node.getSelector().getAsString()); |
48 | } |
49 | |
50 | namespace internal { |
51 | |
52 | static bool notUnaryOperator(const DynTypedNode &DynNode, |
53 | ASTMatchFinder *Finder, |
54 | BoundNodesTreeBuilder *Builder, |
55 | ArrayRef<DynTypedMatcher> InnerMatchers); |
56 | |
57 | static bool allOfVariadicOperator(const DynTypedNode &DynNode, |
58 | ASTMatchFinder *Finder, |
59 | BoundNodesTreeBuilder *Builder, |
60 | ArrayRef<DynTypedMatcher> InnerMatchers); |
61 | |
62 | static bool eachOfVariadicOperator(const DynTypedNode &DynNode, |
63 | ASTMatchFinder *Finder, |
64 | BoundNodesTreeBuilder *Builder, |
65 | ArrayRef<DynTypedMatcher> InnerMatchers); |
66 | |
67 | static bool anyOfVariadicOperator(const DynTypedNode &DynNode, |
68 | ASTMatchFinder *Finder, |
69 | BoundNodesTreeBuilder *Builder, |
70 | ArrayRef<DynTypedMatcher> InnerMatchers); |
71 | |
72 | static bool optionallyVariadicOperator(const DynTypedNode &DynNode, |
73 | ASTMatchFinder *Finder, |
74 | BoundNodesTreeBuilder *Builder, |
75 | ArrayRef<DynTypedMatcher> InnerMatchers); |
76 | |
77 | bool matchesAnyBase(const CXXRecordDecl &Node, |
78 | const Matcher<CXXBaseSpecifier> &BaseSpecMatcher, |
79 | ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) { |
80 | if (!Node.hasDefinition()) |
81 | return false; |
82 | |
83 | CXXBasePaths Paths; |
84 | Paths.setOrigin(&Node); |
85 | |
86 | const auto basePredicate = |
87 | [Finder, Builder, &BaseSpecMatcher](const CXXBaseSpecifier *BaseSpec, |
88 | CXXBasePath &IgnoredParam) { |
89 | BoundNodesTreeBuilder Result(*Builder); |
90 | if (BaseSpecMatcher.matches(Node: *BaseSpec, Finder, Builder: &Result)) { |
91 | *Builder = std::move(Result); |
92 | return true; |
93 | } |
94 | return false; |
95 | }; |
96 | |
97 | return Node.lookupInBases(BaseMatches: basePredicate, Paths, |
98 | /*LookupInDependent =*/true); |
99 | } |
100 | |
101 | void BoundNodesTreeBuilder::visitMatches(Visitor *ResultVisitor) { |
102 | if (Bindings.empty()) |
103 | Bindings.push_back(Elt: BoundNodesMap()); |
104 | for (BoundNodesMap &Binding : Bindings) { |
105 | ResultVisitor->visitMatch(BoundNodesView: BoundNodes(Binding)); |
106 | } |
107 | } |
108 | |
109 | namespace { |
110 | |
111 | using VariadicOperatorFunction = bool (*)( |
112 | const DynTypedNode &DynNode, ASTMatchFinder *Finder, |
113 | BoundNodesTreeBuilder *Builder, ArrayRef<DynTypedMatcher> InnerMatchers); |
114 | |
115 | template <VariadicOperatorFunction Func> |
116 | class VariadicMatcher : public DynMatcherInterface { |
117 | public: |
118 | VariadicMatcher(std::vector<DynTypedMatcher> InnerMatchers) |
119 | : InnerMatchers(std::move(InnerMatchers)) {} |
120 | |
121 | bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder, |
122 | BoundNodesTreeBuilder *Builder) const override { |
123 | return Func(DynNode, Finder, Builder, InnerMatchers); |
124 | } |
125 | |
126 | private: |
127 | std::vector<DynTypedMatcher> InnerMatchers; |
128 | }; |
129 | |
130 | class IdDynMatcher : public DynMatcherInterface { |
131 | public: |
132 | IdDynMatcher(StringRef ID, |
133 | IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher) |
134 | : ID(ID), InnerMatcher(std::move(InnerMatcher)) {} |
135 | |
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: ID, DynNode); |
140 | return Result; |
141 | } |
142 | |
143 | std::optional<clang::TraversalKind> TraversalKind() const override { |
144 | return InnerMatcher->TraversalKind(); |
145 | } |
146 | |
147 | private: |
148 | const std::string ID; |
149 | const IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher; |
150 | }; |
151 | |
152 | /// A matcher that always returns true. |
153 | class TrueMatcherImpl : public DynMatcherInterface { |
154 | public: |
155 | TrueMatcherImpl() = default; |
156 | |
157 | bool dynMatches(const DynTypedNode &, ASTMatchFinder *, |
158 | BoundNodesTreeBuilder *) const override { |
159 | return true; |
160 | } |
161 | }; |
162 | |
163 | /// A matcher that specifies a particular \c TraversalKind. |
164 | /// |
165 | /// The kind provided to the constructor overrides any kind that may be |
166 | /// specified by the `InnerMatcher`. |
167 | class DynTraversalMatcherImpl : public DynMatcherInterface { |
168 | public: |
169 | explicit DynTraversalMatcherImpl( |
170 | clang::TraversalKind TK, |
171 | IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher) |
172 | : TK(TK), InnerMatcher(std::move(InnerMatcher)) {} |
173 | |
174 | bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder, |
175 | BoundNodesTreeBuilder *Builder) const override { |
176 | return this->InnerMatcher->dynMatches(DynNode, Finder, Builder); |
177 | } |
178 | |
179 | std::optional<clang::TraversalKind> TraversalKind() const override { |
180 | return TK; |
181 | } |
182 | |
183 | private: |
184 | clang::TraversalKind TK; |
185 | IntrusiveRefCntPtr<DynMatcherInterface> InnerMatcher; |
186 | }; |
187 | |
188 | } // namespace |
189 | |
190 | bool ASTMatchFinder::isTraversalIgnoringImplicitNodes() const { |
191 | return getASTContext().getParentMapContext().getTraversalKind() == |
192 | TK_IgnoreUnlessSpelledInSource; |
193 | } |
194 | |
195 | DynTypedMatcher |
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); |
203 | }) && |
204 | "InnerMatchers must be convertible to SupportedKind!" ); |
205 | |
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; |
211 | |
212 | switch (Op) { |
213 | case VO_AllOf: |
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 |
217 | // matcher. |
218 | for (auto &IM : InnerMatchers) { |
219 | RestrictKind = |
220 | ASTNodeKind::getMostDerivedType(Kind1: RestrictKind, Kind2: IM.RestrictKind); |
221 | } |
222 | return DynTypedMatcher( |
223 | SupportedKind, RestrictKind, |
224 | new VariadicMatcher<allOfVariadicOperator>(std::move(InnerMatchers))); |
225 | |
226 | case VO_AnyOf: |
227 | return DynTypedMatcher( |
228 | SupportedKind, RestrictKind, |
229 | new VariadicMatcher<anyOfVariadicOperator>(std::move(InnerMatchers))); |
230 | |
231 | case VO_EachOf: |
232 | return DynTypedMatcher( |
233 | SupportedKind, RestrictKind, |
234 | new VariadicMatcher<eachOfVariadicOperator>(std::move(InnerMatchers))); |
235 | |
236 | case VO_Optionally: |
237 | return DynTypedMatcher(SupportedKind, RestrictKind, |
238 | new VariadicMatcher<optionallyVariadicOperator>( |
239 | std::move(InnerMatchers))); |
240 | |
241 | case VO_UnaryNot: |
242 | // FIXME: Implement the Not operator to take a single matcher instead of a |
243 | // vector. |
244 | return DynTypedMatcher( |
245 | SupportedKind, RestrictKind, |
246 | new VariadicMatcher<notUnaryOperator>(std::move(InnerMatchers))); |
247 | } |
248 | llvm_unreachable("Invalid Op value." ); |
249 | } |
250 | |
251 | DynTypedMatcher |
252 | DynTypedMatcher::constructRestrictedWrapper(const DynTypedMatcher &InnerMatcher, |
253 | ASTNodeKind RestrictKind) { |
254 | DynTypedMatcher Copy = InnerMatcher; |
255 | Copy.RestrictKind = RestrictKind; |
256 | return Copy; |
257 | } |
258 | |
259 | DynTypedMatcher DynTypedMatcher::withTraversalKind(TraversalKind TK) { |
260 | auto Copy = *this; |
261 | Copy.Implementation = |
262 | new DynTraversalMatcherImpl(TK, std::move(Copy.Implementation)); |
263 | return Copy; |
264 | } |
265 | |
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); |
273 | } |
274 | |
275 | bool DynTypedMatcher::canMatchNodesOfKind(ASTNodeKind Kind) const { |
276 | return RestrictKind.isBaseOf(Other: Kind); |
277 | } |
278 | |
279 | DynTypedMatcher DynTypedMatcher::dynCastTo(const ASTNodeKind Kind) const { |
280 | auto Copy = *this; |
281 | Copy.SupportedKind = Kind; |
282 | Copy.RestrictKind = ASTNodeKind::getMostDerivedType(Kind1: Kind, Kind2: RestrictKind); |
283 | return Copy; |
284 | } |
285 | |
286 | bool DynTypedMatcher::matches(const DynTypedNode &DynNode, |
287 | ASTMatchFinder *Finder, |
288 | BoundNodesTreeBuilder *Builder) const { |
289 | TraversalKindScope RAII(Finder->getASTContext(), |
290 | Implementation->TraversalKind()); |
291 | |
292 | if (Finder->isTraversalIgnoringImplicitNodes() && |
293 | Finder->IsMatchingInASTNodeNotSpelledInSource()) |
294 | return false; |
295 | |
296 | if (!Finder->isTraversalIgnoringImplicitNodes() && |
297 | Finder->IsMatchingInASTNodeNotAsIs()) |
298 | return false; |
299 | |
300 | auto N = |
301 | Finder->getASTContext().getParentMapContext().traverseIgnored(N: DynNode); |
302 | |
303 | if (RestrictKind.isBaseOf(Other: N.getNodeKind()) && |
304 | Implementation->dynMatches(DynNode: N, Finder, Builder)) { |
305 | return true; |
306 | } |
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(Predicate: [](const BoundNodesMap &) { return true; }); |
311 | return false; |
312 | } |
313 | |
314 | bool DynTypedMatcher::matchesNoKindCheck(const DynTypedNode &DynNode, |
315 | ASTMatchFinder *Finder, |
316 | BoundNodesTreeBuilder *Builder) const { |
317 | TraversalKindScope raii(Finder->getASTContext(), |
318 | Implementation->TraversalKind()); |
319 | |
320 | if (Finder->isTraversalIgnoringImplicitNodes() && |
321 | Finder->IsMatchingInASTNodeNotSpelledInSource()) |
322 | return false; |
323 | |
324 | if (!Finder->isTraversalIgnoringImplicitNodes() && |
325 | Finder->IsMatchingInASTNodeNotAsIs()) |
326 | return false; |
327 | |
328 | auto N = |
329 | Finder->getASTContext().getParentMapContext().traverseIgnored(N: DynNode); |
330 | |
331 | assert(RestrictKind.isBaseOf(N.getNodeKind())); |
332 | if (Implementation->dynMatches(DynNode: N, Finder, Builder)) { |
333 | return true; |
334 | } |
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(Predicate: [](const BoundNodesMap &) { return true; }); |
339 | return false; |
340 | } |
341 | |
342 | std::optional<DynTypedMatcher> DynTypedMatcher::tryBind(StringRef ID) const { |
343 | if (!AllowBind) |
344 | return std::nullopt; |
345 | auto Result = *this; |
346 | Result.Implementation = |
347 | new IdDynMatcher(ID, std::move(Result.Implementation)); |
348 | return std::move(Result); |
349 | } |
350 | |
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(Other: TypeKind) && To.isSame(Other: QualKind)) return true; |
358 | /// - From Matcher<Base> to Matcher<Derived> |
359 | return From.isBaseOf(Other: To); |
360 | } |
361 | |
362 | void BoundNodesTreeBuilder::addMatch(const BoundNodesTreeBuilder &Other) { |
363 | Bindings.append(in_start: Other.Bindings.begin(), in_end: Other.Bindings.end()); |
364 | } |
365 | |
366 | static bool notUnaryOperator(const DynTypedNode &DynNode, |
367 | ASTMatchFinder *Finder, |
368 | BoundNodesTreeBuilder *Builder, |
369 | ArrayRef<DynTypedMatcher> InnerMatchers) { |
370 | if (InnerMatchers.size() != 1) |
371 | return false; |
372 | |
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, Builder: &Discard); |
385 | } |
386 | |
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(Range&: InnerMatchers, P: [&](const DynTypedMatcher &InnerMatcher) { |
395 | return InnerMatcher.matchesNoKindCheck(DynNode, Finder, Builder); |
396 | }); |
397 | } |
398 | |
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, Builder: &BuilderInner)) { |
408 | Matched = true; |
409 | Result.addMatch(Other: BuilderInner); |
410 | } |
411 | } |
412 | *Builder = std::move(Result); |
413 | return Matched; |
414 | } |
415 | |
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, Builder: &Result)) { |
423 | *Builder = std::move(Result); |
424 | return true; |
425 | } |
426 | } |
427 | return false; |
428 | } |
429 | |
430 | static bool |
431 | optionallyVariadicOperator(const DynTypedNode &DynNode, ASTMatchFinder *Finder, |
432 | BoundNodesTreeBuilder *Builder, |
433 | ArrayRef<DynTypedMatcher> InnerMatchers) { |
434 | if (InnerMatchers.size() != 1) |
435 | return false; |
436 | |
437 | BoundNodesTreeBuilder Result(*Builder); |
438 | if (InnerMatchers[0].matches(DynNode, Finder, Builder: &Result)) |
439 | *Builder = std::move(Result); |
440 | return true; |
441 | } |
442 | |
443 | inline static |
444 | std::vector<std::string> vectorFromRefs(ArrayRef<const StringRef *> NameRefs) { |
445 | std::vector<std::string> Names; |
446 | Names.reserve(n: NameRefs.size()); |
447 | for (auto *Name : NameRefs) |
448 | Names.emplace_back(args: *Name); |
449 | return Names; |
450 | } |
451 | |
452 | Matcher<NamedDecl> hasAnyNameFunc(ArrayRef<const StringRef *> NameRefs) { |
453 | return internal::Matcher<NamedDecl>( |
454 | new internal::HasNameMatcher(vectorFromRefs(NameRefs))); |
455 | } |
456 | |
457 | Matcher<ObjCMessageExpr> hasAnySelectorFunc( |
458 | ArrayRef<const StringRef *> NameRefs) { |
459 | return hasAnySelectorMatcher(Matches: vectorFromRefs(NameRefs)); |
460 | } |
461 | |
462 | HasOpNameMatcher hasAnyOperatorNameFunc(ArrayRef<const StringRef *> NameRefs) { |
463 | return HasOpNameMatcher(vectorFromRefs(NameRefs)); |
464 | } |
465 | |
466 | HasOverloadOpNameMatcher |
467 | hasAnyOverloadedOperatorNameFunc(ArrayRef<const StringRef *> NameRefs) { |
468 | return HasOverloadOpNameMatcher(vectorFromRefs(NameRefs)); |
469 | } |
470 | |
471 | HasNameMatcher::HasNameMatcher(std::vector<std::string> N) |
472 | : UseUnqualifiedMatch( |
473 | llvm::all_of(Range&: N, P: [](StringRef Name) { return !Name.contains(Other: "::" ); })), |
474 | Names(std::move(N)) { |
475 | #ifndef NDEBUG |
476 | for (StringRef Name : Names) |
477 | assert(!Name.empty()); |
478 | #endif |
479 | } |
480 | |
481 | static bool consumeNameSuffix(StringRef &FullName, StringRef Suffix) { |
482 | StringRef Name = FullName; |
483 | if (!Name.ends_with(Suffix)) |
484 | return false; |
485 | Name = Name.drop_back(N: Suffix.size()); |
486 | if (!Name.empty()) { |
487 | if (!Name.ends_with(Suffix: "::" )) |
488 | return false; |
489 | Name = Name.drop_back(N: 2); |
490 | } |
491 | FullName = Name; |
492 | return true; |
493 | } |
494 | |
495 | static StringRef getNodeName(const NamedDecl &Node, |
496 | llvm::SmallString<128> &Scratch) { |
497 | // Simple name. |
498 | if (Node.getIdentifier()) |
499 | return Node.getName(); |
500 | |
501 | if (Node.getDeclName()) { |
502 | // Name needs to be constructed. |
503 | Scratch.clear(); |
504 | llvm::raw_svector_ostream OS(Scratch); |
505 | Node.printName(OS); |
506 | return OS.str(); |
507 | } |
508 | |
509 | return "(anonymous)" ; |
510 | } |
511 | |
512 | static StringRef getNodeName(const RecordDecl &Node, |
513 | llvm::SmallString<128> &Scratch) { |
514 | if (Node.getIdentifier()) { |
515 | return Node.getName(); |
516 | } |
517 | Scratch.clear(); |
518 | return ("(anonymous " + Node.getKindName() + ")" ).toStringRef(Out&: Scratch); |
519 | } |
520 | |
521 | static StringRef getNodeName(const NamespaceDecl &Node, |
522 | llvm::SmallString<128> &Scratch) { |
523 | return Node.isAnonymousNamespace() ? "(anonymous namespace)" : Node.getName(); |
524 | } |
525 | |
526 | namespace { |
527 | |
528 | class PatternSet { |
529 | public: |
530 | PatternSet(ArrayRef<std::string> Names) { |
531 | Patterns.reserve(N: Names.size()); |
532 | for (StringRef Name : Names) |
533 | Patterns.push_back(Elt: {.P: Name, .IsFullyQualified: Name.starts_with(Prefix: "::" )}); |
534 | } |
535 | |
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) { |
540 | for (size_t I = 0; I < Patterns.size();) { |
541 | if (::clang::ast_matchers::internal::consumeNameSuffix(FullName&: Patterns[I].P, |
542 | Suffix: NodeName) || |
543 | CanSkip) { |
544 | ++I; |
545 | } else { |
546 | Patterns.erase(CI: Patterns.begin() + I); |
547 | } |
548 | } |
549 | return !Patterns.empty(); |
550 | } |
551 | |
552 | /// Check if any of the patterns are a match. |
553 | /// A match will be a pattern that was fully consumed, that also matches the |
554 | /// 'fully qualified' requirement. |
555 | bool foundMatch(bool AllowFullyQualified) const { |
556 | return llvm::any_of(Range: Patterns, P: [&](const Pattern &Pattern) { |
557 | return Pattern.P.empty() && |
558 | (AllowFullyQualified || !Pattern.IsFullyQualified); |
559 | }); |
560 | } |
561 | |
562 | private: |
563 | struct Pattern { |
564 | StringRef P; |
565 | bool IsFullyQualified; |
566 | }; |
567 | |
568 | llvm::SmallVector<Pattern, 8> Patterns; |
569 | }; |
570 | |
571 | } // namespace |
572 | |
573 | bool HasNameMatcher::matchesNodeUnqualified(const NamedDecl &Node) const { |
574 | assert(UseUnqualifiedMatch); |
575 | llvm::SmallString<128> Scratch; |
576 | StringRef NodeName = getNodeName(Node, Scratch); |
577 | return llvm::any_of(Range: Names, P: [&](StringRef Name) { |
578 | return consumeNameSuffix(FullName&: Name, Suffix: NodeName) && Name.empty(); |
579 | }); |
580 | } |
581 | |
582 | bool HasNameMatcher::matchesNodeFullFast(const NamedDecl &Node) const { |
583 | PatternSet Patterns(Names); |
584 | llvm::SmallString<128> Scratch; |
585 | |
586 | // This function is copied and adapted from NamedDecl::printQualifiedName() |
587 | // By matching each part individually we optimize in a couple of ways: |
588 | // - We can exit early on the first failure. |
589 | // - We can skip inline/anonymous namespaces without another pass. |
590 | // - We print one name at a time, reducing the chance of overflowing the |
591 | // inlined space of the SmallString. |
592 | |
593 | // First, match the name. |
594 | if (!Patterns.consumeNameSuffix(NodeName: getNodeName(Node, Scratch), |
595 | /*CanSkip=*/false)) |
596 | return false; |
597 | |
598 | // Try to match each declaration context. |
599 | // We are allowed to skip anonymous and inline namespaces if they don't match. |
600 | const DeclContext *Ctx = Node.getDeclContext(); |
601 | |
602 | if (Ctx->isFunctionOrMethod()) |
603 | return Patterns.foundMatch(/*AllowFullyQualified=*/false); |
604 | |
605 | for (; Ctx; Ctx = Ctx->getParent()) { |
606 | // Linkage Spec can just be ignored |
607 | // FIXME: Any other DeclContext kinds that can be safely disregarded |
608 | if (isa<LinkageSpecDecl>(Val: Ctx)) |
609 | continue; |
610 | if (!isa<NamedDecl>(Val: Ctx)) |
611 | break; |
612 | if (Patterns.foundMatch(/*AllowFullyQualified=*/false)) |
613 | return true; |
614 | |
615 | if (const auto *ND = dyn_cast<NamespaceDecl>(Val: Ctx)) { |
616 | // If it matches (or we can skip it), continue. |
617 | if (Patterns.consumeNameSuffix(NodeName: getNodeName(Node: *ND, Scratch), |
618 | /*CanSkip=*/ND->isAnonymousNamespace() || |
619 | ND->isInline())) |
620 | continue; |
621 | return false; |
622 | } |
623 | if (const auto *RD = dyn_cast<RecordDecl>(Val: Ctx)) { |
624 | if (!isa<ClassTemplateSpecializationDecl>(Val: Ctx)) { |
625 | if (Patterns.consumeNameSuffix(NodeName: getNodeName(Node: *RD, Scratch), |
626 | /*CanSkip=*/false)) |
627 | continue; |
628 | |
629 | return false; |
630 | } |
631 | } |
632 | |
633 | // We don't know how to deal with this DeclContext. |
634 | // Fallback to the slow version of the code. |
635 | return matchesNodeFullSlow(Node); |
636 | } |
637 | |
638 | return Patterns.foundMatch(/*AllowFullyQualified=*/true); |
639 | } |
640 | |
641 | bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const { |
642 | const bool SkipUnwrittenCases[] = {false, true}; |
643 | for (bool SkipUnwritten : SkipUnwrittenCases) { |
644 | llvm::SmallString<128> NodeName = StringRef("::" ); |
645 | llvm::raw_svector_ostream OS(NodeName); |
646 | |
647 | PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy(); |
648 | Policy.SuppressUnwrittenScope = SkipUnwritten; |
649 | Policy.SuppressInlineNamespace = SkipUnwritten; |
650 | Node.printQualifiedName(OS, Policy); |
651 | |
652 | const StringRef FullName = OS.str(); |
653 | |
654 | for (const StringRef Pattern : Names) { |
655 | if (Pattern.starts_with(Prefix: "::" )) { |
656 | if (FullName == Pattern) |
657 | return true; |
658 | } else if (FullName.ends_with(Suffix: Pattern) && |
659 | FullName.drop_back(N: Pattern.size()).ends_with(Suffix: "::" )) { |
660 | return true; |
661 | } |
662 | } |
663 | } |
664 | |
665 | return false; |
666 | } |
667 | |
668 | bool HasNameMatcher::matchesNode(const NamedDecl &Node) const { |
669 | assert(matchesNodeFullFast(Node) == matchesNodeFullSlow(Node)); |
670 | if (UseUnqualifiedMatch) { |
671 | assert(matchesNodeUnqualified(Node) == matchesNodeFullFast(Node)); |
672 | return matchesNodeUnqualified(Node); |
673 | } |
674 | return matchesNodeFullFast(Node); |
675 | } |
676 | |
677 | // Checks whether \p Loc points to a token with source text of \p TokenText. |
678 | static bool isTokenAtLoc(const SourceManager &SM, const LangOptions &LangOpts, |
679 | StringRef Text, SourceLocation Loc) { |
680 | llvm::SmallString<16> Buffer; |
681 | bool Invalid = false; |
682 | // Since `Loc` may point into an expansion buffer, which has no corresponding |
683 | // source, we need to look at the spelling location to read the actual source. |
684 | StringRef TokenText = Lexer::getSpelling(loc: SM.getSpellingLoc(Loc), buffer&: Buffer, SM, |
685 | options: LangOpts, invalid: &Invalid); |
686 | return !Invalid && Text == TokenText; |
687 | } |
688 | |
689 | std::optional<SourceLocation> |
690 | getExpansionLocOfMacro(StringRef MacroName, SourceLocation Loc, |
691 | const ASTContext &Context) { |
692 | auto &SM = Context.getSourceManager(); |
693 | const LangOptions &LangOpts = Context.getLangOpts(); |
694 | while (Loc.isMacroID()) { |
695 | SrcMgr::ExpansionInfo Expansion = |
696 | SM.getSLocEntry(FID: SM.getFileID(SpellingLoc: Loc)).getExpansion(); |
697 | if (Expansion.isMacroArgExpansion()) |
698 | // Check macro argument for an expansion of the given macro. For example, |
699 | // `F(G(3))`, where `MacroName` is `G`. |
700 | if (std::optional<SourceLocation> ArgLoc = getExpansionLocOfMacro( |
701 | MacroName, Loc: Expansion.getSpellingLoc(), Context)) |
702 | return ArgLoc; |
703 | Loc = Expansion.getExpansionLocStart(); |
704 | if (isTokenAtLoc(SM, LangOpts, Text: MacroName, Loc)) |
705 | return Loc; |
706 | } |
707 | return std::nullopt; |
708 | } |
709 | |
710 | std::shared_ptr<llvm::Regex> createAndVerifyRegex(StringRef Regex, |
711 | llvm::Regex::RegexFlags Flags, |
712 | StringRef MatcherID) { |
713 | assert(!Regex.empty() && "Empty regex string" ); |
714 | auto SharedRegex = std::make_shared<llvm::Regex>(args&: Regex, args&: Flags); |
715 | std::string Error; |
716 | if (!SharedRegex->isValid(Error)) { |
717 | llvm::WithColor::error() |
718 | << "building matcher '" << MatcherID << "': " << Error << "\n" ; |
719 | llvm::WithColor::note() << " input was '" << Regex << "'\n" ; |
720 | } |
721 | return SharedRegex; |
722 | } |
723 | } // end namespace internal |
724 | |
725 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAutoreleasePoolStmt> |
726 | autoreleasePoolStmt; |
727 | const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl> |
728 | translationUnitDecl; |
729 | const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl> typedefDecl; |
730 | const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl> |
731 | typedefNameDecl; |
732 | const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl> typeAliasDecl; |
733 | const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl> |
734 | typeAliasTemplateDecl; |
735 | const internal::VariadicAllOfMatcher<Decl> decl; |
736 | const internal::VariadicDynCastAllOfMatcher<Decl, DecompositionDecl> decompositionDecl; |
737 | const internal::VariadicDynCastAllOfMatcher<Decl, BindingDecl> bindingDecl; |
738 | const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl> |
739 | linkageSpecDecl; |
740 | const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl; |
741 | const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl; |
742 | const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> namespaceDecl; |
743 | const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl> |
744 | namespaceAliasDecl; |
745 | const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl; |
746 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl> cxxRecordDecl; |
747 | const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl> |
748 | classTemplateDecl; |
749 | const internal::VariadicDynCastAllOfMatcher<Decl, |
750 | ClassTemplateSpecializationDecl> |
751 | classTemplateSpecializationDecl; |
752 | const internal::VariadicDynCastAllOfMatcher< |
753 | Decl, ClassTemplatePartialSpecializationDecl> |
754 | classTemplatePartialSpecializationDecl; |
755 | const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl> |
756 | declaratorDecl; |
757 | const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl> parmVarDecl; |
758 | const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl> |
759 | accessSpecDecl; |
760 | const internal::VariadicAllOfMatcher<CXXBaseSpecifier> cxxBaseSpecifier; |
761 | const internal::VariadicAllOfMatcher<CXXCtorInitializer> cxxCtorInitializer; |
762 | const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument; |
763 | const internal::VariadicAllOfMatcher<TemplateArgumentLoc> templateArgumentLoc; |
764 | const internal::VariadicAllOfMatcher<TemplateName> templateName; |
765 | const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl> |
766 | nonTypeTemplateParmDecl; |
767 | const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl> |
768 | templateTypeParmDecl; |
769 | const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTemplateParmDecl> |
770 | templateTemplateParmDecl; |
771 | |
772 | const internal::VariadicAllOfMatcher<LambdaCapture> lambdaCapture; |
773 | const internal::VariadicAllOfMatcher<QualType> qualType; |
774 | const internal::VariadicAllOfMatcher<Type> type; |
775 | const internal::VariadicAllOfMatcher<TypeLoc> typeLoc; |
776 | |
777 | const internal::VariadicDynCastAllOfMatcher<TypeLoc, QualifiedTypeLoc> |
778 | qualifiedTypeLoc; |
779 | const internal::VariadicDynCastAllOfMatcher<TypeLoc, PointerTypeLoc> |
780 | pointerTypeLoc; |
781 | const internal::VariadicDynCastAllOfMatcher<TypeLoc, ReferenceTypeLoc> |
782 | referenceTypeLoc; |
783 | const internal::VariadicDynCastAllOfMatcher<TypeLoc, |
784 | TemplateSpecializationTypeLoc> |
785 | templateSpecializationTypeLoc; |
786 | const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc> |
787 | elaboratedTypeLoc; |
788 | |
789 | const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryExprOrTypeTraitExpr> |
790 | unaryExprOrTypeTraitExpr; |
791 | const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl; |
792 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl> |
793 | cxxConstructorDecl; |
794 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl> |
795 | cxxDestructorDecl; |
796 | const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl; |
797 | const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl> |
798 | enumConstantDecl; |
799 | const internal::VariadicDynCastAllOfMatcher<Decl, TagDecl> tagDecl; |
800 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> cxxMethodDecl; |
801 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl> |
802 | cxxConversionDecl; |
803 | const internal::VariadicDynCastAllOfMatcher<Decl, ConceptDecl> conceptDecl; |
804 | const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl; |
805 | const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl; |
806 | const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl> |
807 | indirectFieldDecl; |
808 | const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> functionDecl; |
809 | const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl> |
810 | functionTemplateDecl; |
811 | const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl; |
812 | const internal::VariadicAllOfMatcher<Stmt> stmt; |
813 | const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt; |
814 | const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr; |
815 | const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr> |
816 | unresolvedMemberExpr; |
817 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDependentScopeMemberExpr> |
818 | cxxDependentScopeMemberExpr; |
819 | const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr; |
820 | const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr; |
821 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr> |
822 | cxxMemberCallExpr; |
823 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr> |
824 | objcMessageExpr; |
825 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl> |
826 | objcInterfaceDecl; |
827 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl> |
828 | objcImplementationDecl; |
829 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl> |
830 | objcProtocolDecl; |
831 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl> |
832 | objcCategoryDecl; |
833 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl> |
834 | objcCategoryImplDecl; |
835 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl> |
836 | objcMethodDecl; |
837 | const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> |
838 | blockDecl; |
839 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl> objcIvarDecl; |
840 | const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl> |
841 | objcPropertyDecl; |
842 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt> |
843 | objcThrowStmt; |
844 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt> objcTryStmt; |
845 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt> |
846 | objcCatchStmt; |
847 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt> |
848 | objcFinallyStmt; |
849 | const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups> |
850 | exprWithCleanups; |
851 | const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> initListExpr; |
852 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStdInitializerListExpr> |
853 | cxxStdInitializerListExpr; |
854 | const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr> |
855 | implicitValueInitExpr; |
856 | const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr> parenListExpr; |
857 | const internal::VariadicDynCastAllOfMatcher<Stmt, SubstNonTypeTemplateParmExpr> |
858 | substNonTypeTemplateParmExpr; |
859 | const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl; |
860 | const internal::VariadicDynCastAllOfMatcher<Decl, UsingEnumDecl> usingEnumDecl; |
861 | const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl> |
862 | usingDirectiveDecl; |
863 | const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr> |
864 | unresolvedLookupExpr; |
865 | const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingValueDecl> |
866 | unresolvedUsingValueDecl; |
867 | const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingTypenameDecl> |
868 | unresolvedUsingTypenameDecl; |
869 | const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr> constantExpr; |
870 | const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr; |
871 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr> |
872 | cxxConstructExpr; |
873 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXUnresolvedConstructExpr> |
874 | cxxUnresolvedConstructExpr; |
875 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> cxxThisExpr; |
876 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr> |
877 | cxxBindTemporaryExpr; |
878 | const internal::VariadicDynCastAllOfMatcher<Stmt, MaterializeTemporaryExpr> |
879 | materializeTemporaryExpr; |
880 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr; |
881 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> cxxDeleteExpr; |
882 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr> |
883 | cxxNoexceptExpr; |
884 | const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr> |
885 | arraySubscriptExpr; |
886 | const internal::VariadicDynCastAllOfMatcher<Stmt, ArrayInitIndexExpr> |
887 | arrayInitIndexExpr; |
888 | const internal::VariadicDynCastAllOfMatcher<Stmt, ArrayInitLoopExpr> |
889 | arrayInitLoopExpr; |
890 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr> |
891 | cxxDefaultArgExpr; |
892 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr> |
893 | cxxOperatorCallExpr; |
894 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXRewrittenBinaryOperator> |
895 | cxxRewrittenBinaryOperator; |
896 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFoldExpr> cxxFoldExpr; |
897 | const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr; |
898 | const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr; |
899 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr> objcIvarRefExpr; |
900 | const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr; |
901 | const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt; |
902 | const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt; |
903 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt> |
904 | cxxForRangeStmt; |
905 | const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt; |
906 | const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt; |
907 | const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt; |
908 | const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt> continueStmt; |
909 | const internal::VariadicDynCastAllOfMatcher<Stmt, CoreturnStmt> coreturnStmt; |
910 | const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt; |
911 | const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt; |
912 | const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt; |
913 | const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr> addrLabelExpr; |
914 | const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt; |
915 | const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase; |
916 | const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt; |
917 | const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt> defaultStmt; |
918 | const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> compoundStmt; |
919 | const internal::VariadicDynCastAllOfMatcher<Stmt, CoroutineBodyStmt> |
920 | coroutineBodyStmt; |
921 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> cxxCatchStmt; |
922 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt; |
923 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr; |
924 | const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt; |
925 | const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt; |
926 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr> |
927 | cxxBoolLiteral; |
928 | const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral; |
929 | const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCStringLiteral> objcStringLiteral; |
930 | const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral> |
931 | characterLiteral; |
932 | const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral> |
933 | integerLiteral; |
934 | const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral; |
935 | const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> imaginaryLiteral; |
936 | const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral> |
937 | fixedPointLiteral; |
938 | const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral> |
939 | userDefinedLiteral; |
940 | const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr> |
941 | compoundLiteralExpr; |
942 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr> |
943 | cxxNullPtrLiteralExpr; |
944 | const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> chooseExpr; |
945 | const internal::VariadicDynCastAllOfMatcher<Stmt, ConvertVectorExpr> |
946 | convertVectorExpr; |
947 | const internal::VariadicDynCastAllOfMatcher<Stmt, CoawaitExpr> |
948 | coawaitExpr; |
949 | const internal::VariadicDynCastAllOfMatcher<Stmt, DependentCoawaitExpr> |
950 | dependentCoawaitExpr; |
951 | const internal::VariadicDynCastAllOfMatcher<Stmt, CoyieldExpr> |
952 | coyieldExpr; |
953 | const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr> gnuNullExpr; |
954 | const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr> |
955 | genericSelectionExpr; |
956 | const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr; |
957 | const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr; |
958 | const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator> |
959 | binaryOperator; |
960 | const internal::MapAnyOfMatcher<BinaryOperator, CXXOperatorCallExpr, |
961 | CXXRewrittenBinaryOperator> |
962 | binaryOperation; |
963 | const internal::MapAnyOfMatcher<CallExpr, CXXConstructExpr> invocation; |
964 | const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator> unaryOperator; |
965 | const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator> |
966 | conditionalOperator; |
967 | const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryConditionalOperator> |
968 | binaryConditionalOperator; |
969 | const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr> |
970 | opaqueValueExpr; |
971 | const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl> |
972 | staticAssertDecl; |
973 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr> |
974 | cxxReinterpretCastExpr; |
975 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr> |
976 | cxxStaticCastExpr; |
977 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr> |
978 | cxxDynamicCastExpr; |
979 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr> |
980 | cxxConstCastExpr; |
981 | const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr> |
982 | cStyleCastExpr; |
983 | const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr> |
984 | explicitCastExpr; |
985 | const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr> |
986 | implicitCastExpr; |
987 | const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr; |
988 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr> |
989 | cxxFunctionalCastExpr; |
990 | const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr> |
991 | cxxTemporaryObjectExpr; |
992 | const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr> |
993 | predefinedExpr; |
994 | const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr> |
995 | designatedInitExpr; |
996 | const internal::VariadicOperatorMatcherFunc< |
997 | 2, std::numeric_limits<unsigned>::max()> |
998 | eachOf = {.Op: internal::DynTypedMatcher::VO_EachOf}; |
999 | const internal::VariadicOperatorMatcherFunc< |
1000 | 2, std::numeric_limits<unsigned>::max()> |
1001 | anyOf = {.Op: internal::DynTypedMatcher::VO_AnyOf}; |
1002 | const internal::VariadicOperatorMatcherFunc< |
1003 | 2, std::numeric_limits<unsigned>::max()> |
1004 | allOf = {.Op: internal::DynTypedMatcher::VO_AllOf}; |
1005 | const internal::VariadicOperatorMatcherFunc<1, 1> optionally = { |
1006 | .Op: internal::DynTypedMatcher::VO_Optionally}; |
1007 | const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef, |
1008 | internal::hasAnyNameFunc> |
1009 | hasAnyName = {}; |
1010 | |
1011 | const internal::VariadicFunction<internal::HasOpNameMatcher, StringRef, |
1012 | internal::hasAnyOperatorNameFunc> |
1013 | hasAnyOperatorName = {}; |
1014 | const internal::VariadicFunction<internal::HasOverloadOpNameMatcher, StringRef, |
1015 | internal::hasAnyOverloadedOperatorNameFunc> |
1016 | hasAnyOverloadedOperatorName = {}; |
1017 | const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>, StringRef, |
1018 | internal::hasAnySelectorFunc> |
1019 | hasAnySelector = {}; |
1020 | const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has = {}; |
1021 | const internal::ArgumentAdaptingMatcherFunc<internal::HasDescendantMatcher> |
1022 | hasDescendant = {}; |
1023 | const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> forEach = |
1024 | {}; |
1025 | const internal::ArgumentAdaptingMatcherFunc<internal::ForEachDescendantMatcher> |
1026 | forEachDescendant = {}; |
1027 | const internal::ArgumentAdaptingMatcherFunc< |
1028 | internal::HasParentMatcher, |
1029 | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>, |
1030 | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>> |
1031 | hasParent = {}; |
1032 | const internal::ArgumentAdaptingMatcherFunc< |
1033 | internal::HasAncestorMatcher, |
1034 | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>, |
1035 | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>> |
1036 | hasAncestor = {}; |
1037 | const internal::VariadicOperatorMatcherFunc<1, 1> unless = { |
1038 | .Op: internal::DynTypedMatcher::VO_UnaryNot}; |
1039 | const internal::VariadicAllOfMatcher<NestedNameSpecifier> nestedNameSpecifier; |
1040 | const internal::VariadicAllOfMatcher<NestedNameSpecifierLoc> |
1041 | nestedNameSpecifierLoc; |
1042 | const internal::VariadicAllOfMatcher<Attr> attr; |
1043 | const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr> |
1044 | cudaKernelCallExpr; |
1045 | const AstTypeMatcher<BuiltinType> builtinType; |
1046 | const AstTypeMatcher<ArrayType> arrayType; |
1047 | const AstTypeMatcher<ComplexType> complexType; |
1048 | const AstTypeMatcher<ConstantArrayType> constantArrayType; |
1049 | const AstTypeMatcher<DeducedTemplateSpecializationType> |
1050 | deducedTemplateSpecializationType; |
1051 | const AstTypeMatcher<DependentSizedArrayType> dependentSizedArrayType; |
1052 | const AstTypeMatcher<DependentSizedExtVectorType> dependentSizedExtVectorType; |
1053 | const AstTypeMatcher<IncompleteArrayType> incompleteArrayType; |
1054 | const AstTypeMatcher<VariableArrayType> variableArrayType; |
1055 | const AstTypeMatcher<AtomicType> atomicType; |
1056 | const AstTypeMatcher<AutoType> autoType; |
1057 | const AstTypeMatcher<DecltypeType> decltypeType; |
1058 | const AstTypeMatcher<FunctionType> functionType; |
1059 | const AstTypeMatcher<FunctionProtoType> functionProtoType; |
1060 | const AstTypeMatcher<ParenType> parenType; |
1061 | const AstTypeMatcher<BlockPointerType> blockPointerType; |
1062 | const AstTypeMatcher<MacroQualifiedType> macroQualifiedType; |
1063 | const AstTypeMatcher<MemberPointerType> memberPointerType; |
1064 | const AstTypeMatcher<PointerType> pointerType; |
1065 | const AstTypeMatcher<ObjCObjectPointerType> objcObjectPointerType; |
1066 | const AstTypeMatcher<ReferenceType> referenceType; |
1067 | const AstTypeMatcher<LValueReferenceType> lValueReferenceType; |
1068 | const AstTypeMatcher<RValueReferenceType> rValueReferenceType; |
1069 | const AstTypeMatcher<TypedefType> typedefType; |
1070 | const AstTypeMatcher<EnumType> enumType; |
1071 | const AstTypeMatcher<TemplateSpecializationType> templateSpecializationType; |
1072 | const AstTypeMatcher<UnaryTransformType> unaryTransformType; |
1073 | const AstTypeMatcher<RecordType> recordType; |
1074 | const AstTypeMatcher<TagType> tagType; |
1075 | const AstTypeMatcher<ElaboratedType> elaboratedType; |
1076 | const AstTypeMatcher<UsingType> usingType; |
1077 | const AstTypeMatcher<SubstTemplateTypeParmType> substTemplateTypeParmType; |
1078 | const AstTypeMatcher<TemplateTypeParmType> templateTypeParmType; |
1079 | const AstTypeMatcher<InjectedClassNameType> injectedClassNameType; |
1080 | const AstTypeMatcher<DecayedType> decayedType; |
1081 | AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType, |
1082 | AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType, |
1083 | ComplexType)); |
1084 | AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasValueType, |
1085 | AST_POLYMORPHIC_SUPPORTED_TYPES(AtomicType)); |
1086 | AST_TYPELOC_TRAVERSE_MATCHER_DEF( |
1087 | pointee, |
1088 | AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType, |
1089 | PointerType, ReferenceType)); |
1090 | |
1091 | const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective> |
1092 | ompExecutableDirective; |
1093 | const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPDefaultClause> |
1094 | ompDefaultClause; |
1095 | const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl> |
1096 | cxxDeductionGuideDecl; |
1097 | |
1098 | } // end namespace ast_matchers |
1099 | } // end namespace clang |
1100 | |