public:
Registry() = delete;
+ static ASTNodeKind nodeMatcherType(MatcherCtor);
+
/// Look up a matcher in the registry by name,
///
/// \return An opaque value which may be used to refer to the matcher
ArrayRef<ParserValue> Args,
Diagnostics *Error) const = 0;
+ virtual ASTNodeKind nodeMatcherType() const { return ASTNodeKind(); }
+
/// Returns whether the matcher is variadic. Variadic matchers can take any
/// number of arguments, but they must be of the same type.
virtual bool isVariadic() const = 0;
LeastDerivedKind);
}
+ ASTNodeKind nodeMatcherType() const override { return RetKinds[0]; }
+
private:
const RunFunc Func;
const std::string MatcherName;
}
}
+ ASTNodeKind nodeMatcherType() const override { return DerivedKind; }
+
private:
const ASTNodeKind DerivedKind;
};
static llvm::ManagedStatic<RegistryMaps> RegistryData;
+ASTNodeKind Registry::nodeMatcherType(MatcherCtor Ctor) {
+ return Ctor->nodeMatcherType();
+}
+
// static
llvm::Optional<MatcherCtor> Registry::lookupMatcherCtor(StringRef MatcherName) {
auto it = RegistryData->constructors().find(MatcherName);
"Matcher<CXXRecordDecl> isSameOrDerivedFrom(string|Matcher<NamedDecl>)"));
}
+TEST_F(RegistryTest, NodeType) {
+ EXPECT_TRUE(Registry::nodeMatcherType(*lookupMatcherCtor("callExpr")).isSame(ASTNodeKind::getFromNodeKind<CallExpr>()));
+ EXPECT_TRUE(Registry::nodeMatcherType(*lookupMatcherCtor("has")).isNone());
+ EXPECT_TRUE(Registry::nodeMatcherType(*lookupMatcherCtor("allOf")).isNone());
+}
+
TEST_F(RegistryTest, HasArgs) {
Matcher<Decl> Value = constructMatcher(
"decl", constructMatcher("hasAttr", StringRef("attr::WarnUnused")))