-
Notifications
You must be signed in to change notification settings - Fork 13.3k
/
Copy pathRegistryManager.h
71 lines (56 loc) · 2.45 KB
/
RegistryManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//===--- RegistryManager.h - Matcher registry -------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// RegistryManager to manage registry of all known matchers.
//
// The registry provides a generic interface to construct any matcher by name.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRYMANAGER_H
#define MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRYMANAGER_H
#include "Diagnostics.h"
#include "mlir/Query/Matcher/Marshallers.h"
#include "mlir/Query/Matcher/Registry.h"
#include "mlir/Query/Matcher/VariantValue.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include <string>
namespace mlir::query::matcher {
using MatcherCtor = const internal::MatcherDescriptor *;
struct MatcherCompletion {
MatcherCompletion() = default;
MatcherCompletion(llvm::StringRef typedText, llvm::StringRef matcherDecl)
: typedText(typedText.str()), matcherDecl(matcherDecl.str()) {}
bool operator==(const MatcherCompletion &other) const {
return typedText == other.typedText && matcherDecl == other.matcherDecl;
}
// The text to type to select this matcher.
std::string typedText;
// The "declaration" of the matcher, with type information.
std::string matcherDecl;
};
class RegistryManager {
public:
RegistryManager() = delete;
static std::optional<MatcherCtor>
lookupMatcherCtor(llvm::StringRef matcherName,
const Registry &matcherRegistry);
static std::vector<ArgKind> getAcceptedCompletionTypes(
llvm::ArrayRef<std::pair<MatcherCtor, unsigned>> context);
static std::vector<MatcherCompletion>
getMatcherCompletions(ArrayRef<ArgKind> acceptedTypes,
const Registry &matcherRegistry);
static VariantMatcher constructMatcher(MatcherCtor ctor,
internal::SourceRange nameRange,
llvm::StringRef functionName,
ArrayRef<ParserValue> args,
internal::Diagnostics *error);
};
} // namespace mlir::query::matcher
#endif // MLIR_TOOLS_MLIRQUERY_MATCHER_REGISTRYMANAGER_H