Skip to content

Commit 8763f67

Browse files
committed
Working Argkind enum class
1 parent f5deb2e commit 8763f67

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

mlir/include/mlir/Query/Matcher/Marshallers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct ArgTypeTraits<StringRef> {
4141
return value.getString();
4242
}
4343

44-
static ArgKind getKind() { return ArgKind(ArgKind::AK_String); }
44+
static ArgKind getKind() { return ArgKind::String; }
4545

4646
static std::optional<std::string> getBestGuess(const VariantValue &) {
4747
return std::nullopt;
@@ -59,7 +59,7 @@ struct ArgTypeTraits<DynMatcher> {
5959
return *value.getMatcher().getDynMatcher();
6060
}
6161

62-
static ArgKind getKind() { return ArgKind(ArgKind::AK_Matcher); }
62+
static ArgKind getKind() { return ArgKind::Matcher; }
6363

6464
static std::optional<std::string> getBestGuess(const VariantValue &) {
6565
return std::nullopt;

mlir/include/mlir/Query/Matcher/VariantValue.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,8 @@
1919

2020
namespace mlir::query::matcher {
2121

22-
// Kind identifier that supports all types that VariantValue can contain.
23-
class ArgKind {
24-
public:
25-
enum Kind { AK_Matcher, AK_String };
26-
ArgKind(Kind k) : k(k) {}
27-
28-
Kind getArgKind() const { return k; }
29-
30-
bool operator<(const ArgKind &other) const { return k < other.k; }
31-
32-
// String representation of the type.
33-
std::string asString() const;
34-
35-
private:
36-
Kind k;
37-
};
22+
// All types that VariantValue can contain.
23+
enum class ArgKind { Matcher, String };
3824

3925
// A variant matcher object to abstract simple and complex matchers into a
4026
// single object type.

mlir/lib/Query/Matcher/Registry.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ using IsConstantOp = detail::constant_op_matcher();
2929
using HasOpAttrName = detail::AttrOpMatcher(StringRef);
3030
using HasOpName = detail::NameOpMatcher(StringRef);
3131

32+
// Enum to string for autocomplete.
33+
static std::string asArgString(ArgKind kind) {
34+
switch (kind) {
35+
case ArgKind::Matcher:
36+
return "Matcher";
37+
case ArgKind::String:
38+
return "String";
39+
}
40+
llvm_unreachable("Unhandled ArgKind");
41+
}
42+
3243
class RegistryMaps {
3344
public:
3445
RegistryMaps();
@@ -90,7 +101,7 @@ std::vector<ArgKind> Registry::getAcceptedCompletionTypes(
90101
// Starting with the above seed of acceptable top-level matcher types, compute
91102
// the acceptable type set for the argument indicated by each context element.
92103
std::set<ArgKind> typeSet;
93-
typeSet.insert(ArgKind(ArgKind::AK_Matcher));
104+
typeSet.insert(ArgKind::Matcher);
94105

95106
for (const auto &ctxEntry : context) {
96107
MatcherCtor ctor = ctxEntry.first;
@@ -119,7 +130,7 @@ Registry::getMatcherCompletions(ArrayRef<ArgKind> acceptedTypes) {
119130
std::vector<std::vector<ArgKind>> argKinds(numArgs);
120131

121132
for (const ArgKind &kind : acceptedTypes) {
122-
if (kind.getArgKind() != kind.AK_Matcher)
133+
if (kind != ArgKind::Matcher)
123134
continue;
124135

125136
for (unsigned arg = 0; arg != numArgs; ++arg)
@@ -143,7 +154,7 @@ Registry::getMatcherCompletions(ArrayRef<ArgKind> acceptedTypes) {
143154
OS << "|";
144155

145156
firstArgKind = false;
146-
OS << argKind.asString();
157+
OS << asArgString(argKind);
147158
}
148159
}
149160

@@ -152,7 +163,7 @@ Registry::getMatcherCompletions(ArrayRef<ArgKind> acceptedTypes) {
152163

153164
if (argKinds.empty())
154165
typedText += ")";
155-
else if (argKinds[0][0].getArgKind() == ArgKind::AK_String)
166+
else if (argKinds[0][0] == ArgKind::String)
156167
typedText += "\"";
157168

158169
completions.emplace_back(typedText, OS.str());

mlir/lib/Query/Matcher/VariantValue.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313

1414
namespace mlir::query::matcher {
1515

16-
std::string ArgKind::asString() const {
17-
switch (getArgKind()) {
18-
case AK_String:
19-
return "String";
20-
case AK_Matcher:
21-
return "Matcher";
22-
}
23-
llvm_unreachable("Unhandled ArgKind");
24-
}
25-
2616
VariantMatcher::Payload::~Payload() = default;
2717

2818
class VariantMatcher::SinglePayload : public VariantMatcher::Payload {

0 commit comments

Comments
 (0)