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

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 12 14:41:46 PST 2018


steveire updated this revision to Diff 173766.
steveire added a comment.

Update


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,13 +601,55 @@
 Registry::getMatchingMatchers(ast_type_traits::ASTNodeKind StaticType) {
   std::vector<MatchingMatcher> Result;
 
+  // Exclude matchers which can't unambiguously
+  // be used with particular arguments.
+  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{StaticType};
 
   processAcceptableMatchers(
-      AcceptedTypes,
-      [&Result](StringRef Name, const MatcherDescriptor &,
-                std::set<ASTNodeKind> &, std::vector<std::vector<ArgKind>>,
-                unsigned) { Result.emplace_back((Name + "()").str()); });
+      AcceptedTypes, [&Result](StringRef Name, const MatcherDescriptor &,
+                               std::set<ASTNodeKind> &,
+                               std::vector<std::vector<ArgKind>>, unsigned) {
+        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.173766.patch
Type: text/x-patch
Size: 2566 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181112/4ced3730/attachment.bin>


More information about the cfe-commits mailing list