ASTMatchersInternal.cpp 44 KB

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