[PATCH] D54403: Add new API for returning matching matchers
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 12 14:41:12 PST 2018
steveire updated this revision to Diff 173765.
steveire added a comment.
Update
Repository:
rC Clang
https://reviews.llvm.org/D54403
Files:
include/clang/ASTMatchers/Dynamic/Registry.h
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
@@ -555,6 +555,32 @@
EXPECT_FALSE(matches("int x = 120;", CharStmt));
}
+TEST_F(RegistryTest, MatchingMatchers) {
+
+ auto Matchers = Registry::getMatchingMatchers(
+ ast_type_traits::ASTNodeKind::getFromNodeKind<FunctionDecl>());
+
+ auto Contains = [](const std::vector<MatchingMatcher> &C, StringRef Name) {
+ return llvm::find_if(C, [Name](const MatchingMatcher &M) {
+ return M.MatcherString == Name;
+ }) != C.end();
+ };
+
+ EXPECT_TRUE(Contains(Matchers, "isPublic()"));
+ EXPECT_TRUE(Contains(Matchers, "hasName()"));
+ EXPECT_TRUE(Contains(Matchers, "hasType()"));
+ EXPECT_TRUE(Contains(Matchers, "hasTypeLoc()"));
+ EXPECT_TRUE(Contains(Matchers, "parameterCountIs()"));
+
+ EXPECT_TRUE(!Contains(Matchers, "decl()"));
+ EXPECT_TRUE(!Contains(Matchers, "namedDecl()"));
+ EXPECT_TRUE(!Contains(Matchers, "valueDecl()"));
+ EXPECT_TRUE(!Contains(Matchers, "declaratorDecl()"));
+ EXPECT_TRUE(!Contains(Matchers, "functionDecl()"));
+
+ EXPECT_TRUE(Contains(Matchers, "cxxMethodDecl()"));
+}
+
} // end anonymous namespace
} // end namespace dynamic
} // end namespace ast_matchers
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -597,6 +597,21 @@
}
}
+std::vector<MatchingMatcher>
+Registry::getMatchingMatchers(ast_type_traits::ASTNodeKind StaticType) {
+ std::vector<MatchingMatcher> Result;
+
+ 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()); });
+
+ return Result;
+}
+
std::vector<MatcherCompletion>
Registry::getMatcherCompletions(ArrayRef<ArgKind> AcceptedTypes) {
std::vector<MatcherCompletion> Completions;
Index: include/clang/ASTMatchers/Dynamic/Registry.h
===================================================================
--- include/clang/ASTMatchers/Dynamic/Registry.h
+++ include/clang/ASTMatchers/Dynamic/Registry.h
@@ -63,6 +63,12 @@
unsigned Specificity;
};
+struct MatchingMatcher {
+ MatchingMatcher(std::string MatcherString)
+ : MatcherString(std::move(MatcherString)) {}
+ std::string MatcherString;
+};
+
class Registry {
public:
Registry() = delete;
@@ -96,6 +102,11 @@
static std::vector<MatcherCompletion>
getMatcherCompletions(ArrayRef<ArgKind> AcceptedTypes);
+ /// Compute matchers which can be used within a matcher of
+ /// type @p StaticType.
+ static std::vector<MatchingMatcher>
+ getMatchingMatchers(ast_type_traits::ASTNodeKind StaticType);
+
/// Construct a matcher from the registry.
///
/// \param Ctor The matcher constructor to instantiate.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54403.173765.patch
Type: text/x-patch
Size: 3137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181112/83f3509d/attachment.bin>
More information about the cfe-commits
mailing list