23 using IsConstantOp = detail::constant_op_matcher();
24 using HasOpAttrName = detail::AttrOpMatcher(llvm::StringRef);
25 using HasOpName = detail::NameOpMatcher(llvm::StringRef);
28 static std::string asArgString(
ArgKind kind) {
35 llvm_unreachable(
"Unhandled ArgKind");
40 void Registry::registerMatcherDescriptor(
41 llvm::StringRef matcherName,
42 std::unique_ptr<internal::MatcherDescriptor> callback) {
43 assert(!constructorMap.contains(matcherName));
44 constructorMap[matcherName] = std::move(callback);
47 std::optional<MatcherCtor>
50 auto it = matcherRegistry.
constructors().find(matcherName);
52 ? std::optional<MatcherCtor>()
60 std::set<ArgKind> typeSet;
63 for (
const auto &ctxEntry : context) {
65 unsigned argNumber = ctxEntry.second;
66 std::vector<ArgKind> nextTypeSet;
68 if (argNumber < ctor->getNumArgs())
71 typeSet.insert(nextTypeSet.begin(), nextTypeSet.end());
74 return std::vector<ArgKind>(typeSet.begin(), typeSet.end());
77 std::vector<MatcherCompletion>
80 std::vector<MatcherCompletion> completions;
85 llvm::StringRef name = m.getKey();
88 std::vector<std::vector<ArgKind>> argKinds(numArgs);
90 for (
const ArgKind &kind : acceptedTypes) {
94 for (
unsigned arg = 0; arg != numArgs; ++arg)
99 llvm::raw_string_ostream os(decl);
101 std::string typedText = std::string(name);
102 os <<
"Matcher: " << name <<
"(";
104 for (
const std::vector<ArgKind> &arg : argKinds) {
105 if (&arg != &argKinds[0])
108 bool firstArgKind =
true;
110 for (
const ArgKind &argKind : arg) {
114 firstArgKind =
false;
115 os << asArgString(argKind);
122 if (argKinds.empty())
127 completions.emplace_back(typedText, decl);
138 if (functionName.empty() || out.
isNull())
141 if (std::optional<DynMatcher> result = out.
getDynMatcher()) {
142 result->setFunctionName(functionName);
static std::vector< MatcherCompletion > getMatcherCompletions(ArrayRef< ArgKind > acceptedTypes, const Registry &matcherRegistry)
static std::vector< ArgKind > getAcceptedCompletionTypes(llvm::ArrayRef< std::pair< MatcherCtor, unsigned >> context)
static std::optional< MatcherCtor > lookupMatcherCtor(llvm::StringRef matcherName, const Registry &matcherRegistry)
static VariantMatcher constructMatcher(MatcherCtor ctor, internal::SourceRange nameRange, llvm::StringRef functionName, ArrayRef< ParserValue > args, internal::Diagnostics *error)
const ConstructorMap & constructors() const
static VariantMatcher SingleMatcher(DynMatcher matcher)
std::optional< DynMatcher > getDynMatcher() const
ArgStream addError(SourceRange range, ErrorType error)
virtual VariantMatcher create(SourceRange nameRange, const llvm::ArrayRef< ParserValue > args, Diagnostics *error) const =0
virtual void getArgKinds(unsigned argNo, std::vector< ArgKind > &argKinds) const =0
virtual unsigned getNumArgs() const =0