27 #ifndef MLIR_TOOLS_MLIRQUERY_MATCHER_PARSER_H
28 #define MLIR_TOOLS_MLIRQUERY_MATCHER_PARSER_H
32 #include "llvm/ADT/ArrayRef.h"
33 #include "llvm/ADT/StringMap.h"
34 #include "llvm/ADT/StringRef.h"
72 virtual std::optional<MatcherCtor>
80 virtual std::vector<MatcherCompletion>
89 : matcherRegistry(matcherRegistry) {}
92 std::optional<MatcherCtor>
97 StringRef functionName,
102 llvm::ArrayRef<std::pair<MatcherCtor, unsigned>> context)
override;
104 std::vector<MatcherCompletion>
115 static std::optional<DynMatcher>
119 static std::optional<DynMatcher>
138 static std::vector<MatcherCompletion>
142 static std::vector<MatcherCompletion>
150 struct ScopedContextEntry;
156 bool parseChainedExpression(std::string &argument);
160 bool parseMatcherArgs(std::vector<ParserValue> &args,
MatcherCtor ctor,
161 const TokenInfo &nameToken, TokenInfo &endToken);
163 bool parseMatcherExpressionImpl(
const TokenInfo &nameToken,
164 const TokenInfo &openToken,
165 std::optional<MatcherCtor> ctor,
170 void addCompletion(
const TokenInfo &compToken,
172 void addExpressionCompletions();
174 std::vector<MatcherCompletion>
177 CodeTokenizer *
const tokenizer;
178 std::unique_ptr<RegistrySema> sema;
182 using ContextStackTy = std::vector<std::pair<MatcherCtor, unsigned>>;
184 ContextStackTy contextStack;
185 std::vector<MatcherCompletion> completions;
RegistrySema(const Registry &matcherRegistry)
std::optional< MatcherCtor > lookupMatcherCtor(llvm::StringRef matcherName) override
std::vector< MatcherCompletion > getMatcherCompletions(llvm::ArrayRef< ArgKind > acceptedTypes) override
std::vector< ArgKind > getAcceptedCompletionTypes(llvm::ArrayRef< std::pair< MatcherCtor, unsigned >> context) override
VariantMatcher actOnMatcherExpression(MatcherCtor Ctor, SourceRange NameRange, StringRef functionName, ArrayRef< ParserValue > Args, Diagnostics *Error) override
virtual std::vector< MatcherCompletion > getMatcherCompletions(llvm::ArrayRef< ArgKind > acceptedTypes)
virtual std::optional< MatcherCtor > lookupMatcherCtor(llvm::StringRef matcherName)=0
virtual std::vector< ArgKind > getAcceptedCompletionTypes(llvm::ArrayRef< std::pair< MatcherCtor, unsigned >> Context)
virtual VariantMatcher actOnMatcherExpression(MatcherCtor ctor, SourceRange nameRange, llvm::StringRef functionName, llvm::ArrayRef< ParserValue > args, Diagnostics *error)=0
static bool parseExpression(llvm::StringRef &code, const Registry &matcherRegistry, const NamedValueMap *namedValues, VariantValue *value, Diagnostics *error)
static std::vector< MatcherCompletion > completeExpression(llvm::StringRef &code, unsigned completionOffset, const Registry &matcherRegistry)
llvm::StringMap< VariantValue > NamedValueMap
static bool parseExpression(llvm::StringRef &code, const Registry &matcherRegistry, VariantValue *value, Diagnostics *error)
static std::optional< DynMatcher > parseMatcherExpression(llvm::StringRef &matcherCode, const Registry &matcherRegistry, Diagnostics *error)
static std::vector< MatcherCompletion > completeExpression(llvm::StringRef &code, unsigned completionOffset, const Registry &matcherRegistry, const NamedValueMap *namedValues)
static std::optional< DynMatcher > parseMatcherExpression(llvm::StringRef &matcherCode, const Registry &matcherRegistry, const NamedValueMap *namedValues, Diagnostics *error)