[PATCH] D54404: Exclude matchers which can have multiple results

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 11 14:35:40 PST 2018


steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D54404

Files:
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/Dynamic/RegistryTest.cpp


Index: unittests/ASTMatchers/Dynamic/RegistryTest.cpp
===================================================================
--- unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -579,6 +579,8 @@
   EXPECT_TRUE(!Contains(Matchers, "functionDecl()"));
 
   EXPECT_TRUE(Contains(Matchers, "cxxMethodDecl()"));
+
+  EXPECT_TRUE(!Contains(Matchers, "has()"));
 }
 
 } // end anonymous namespace
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -601,15 +601,54 @@
 Registry::getMatchingMatchers(ast_type_traits::ASTNodeKind StaticType) {
   std::vector<MatchingMatcher> Result;
 
+  static std::vector<StringRef> excludedMatchers{
+      "allOf",
+      "anyOf",
+      "anything",
+      "containsDeclaration",
+      "eachOf",
+      "equalsNode",
+      "findAll",
+      "forEach",
+      "forEachConstructorInitializer",
+      "forEachDescendant",
+      "forEachOverridden",
+      "forEachSwitchCase",
+      "has",
+      "hasAncestor",
+      "hasAnyArgument",
+      "hasAnyConstructorInitializer",
+      "hasAnyDeclaration",
+      "hasAnyName",
+      "hasAnyParameter",
+      "hasAnySelector",
+      "hasAnySubstatement",
+      "hasAnyTemplateArgument",
+      "hasAnyUsingShadowDecl",
+      "hasArgumentOfType",
+      "hasDescendant",
+      "hasEitherOperand",
+      "hasMethod",
+      "hasParent",
+      "isExpansionInFileMatching",
+      "isSameOrDerivedFrom",
+      "matchesName",
+      "matchesSelector",
+      "unless"};
+  assert(std::is_sorted(excludedMatchers.begin(), excludedMatchers.end()));
+
   std::vector<ArgKind> AcceptedTypes;
   AcceptedTypes.push_back(StaticType);
 
   processAcceptableMatchers(
       AcceptedTypes, [&Result](StringRef Name, const MatcherDescriptor &Matcher,
                                std::set<ASTNodeKind> &RetKinds,
                                std::vector<std::vector<ArgKind>> ArgsKinds,
                                unsigned MaxSpecificity) {
-        Result.emplace_back((Name + "()").str());
+        if (!std::binary_search(excludedMatchers.begin(),
+                                excludedMatchers.end(), Name)) {
+          Result.emplace_back((Name + "()").str());
+        }
       });
 
   return Result;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54404.173587.patch
Type: text/x-patch
Size: 2390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181111/18723652/attachment.bin>


More information about the cfe-commits mailing list