Skip to content

Commit 07d0234

Browse files
committed
Convert to enum class
1 parent aec0ce1 commit 07d0234

File tree

4 files changed

+50
-46
lines changed

4 files changed

+50
-46
lines changed

mlir/include/mlir/Query/Matcher/Diagnostics.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,26 @@ struct SourceRange {
3939
class Diagnostics {
4040
public:
4141
// All errors from the system.
42-
enum ErrorType {
43-
ET_None,
42+
enum class ErrorType {
43+
None,
4444

4545
// Parser Errors
46-
ET_ParserFailedToBuildMatcher,
47-
ET_ParserInvalidToken,
48-
ET_ParserNoCloseParen,
49-
ET_ParserNoCode,
50-
ET_ParserNoComma,
51-
ET_ParserNoOpenParen,
52-
ET_ParserNotAMatcher,
53-
ET_ParserOverloadedType,
54-
ET_ParserStringError,
55-
ET_ParserTrailingCode,
46+
ParserFailedToBuildMatcher,
47+
ParserInvalidToken,
48+
ParserNoCloseParen,
49+
ParserNoCode,
50+
ParserNoComma,
51+
ParserNoOpenParen,
52+
ParserNotAMatcher,
53+
ParserOverloadedType,
54+
ParserStringError,
55+
ParserTrailingCode,
5656

5757
// Registry Errors
58-
ET_RegistryMatcherNotFound,
59-
ET_RegistryValueNotFound,
60-
ET_RegistryWrongArgCount,
61-
ET_RegistryWrongArgType
58+
RegistryMatcherNotFound,
59+
RegistryValueNotFound,
60+
RegistryWrongArgCount,
61+
RegistryWrongArgType
6262
};
6363

6464
// Helper stream class for constructing error messages.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class FixedArgCountMatcherDescriptor : public MatcherDescriptor {
124124
inline bool checkArgCount(SourceRange nameRange, size_t expectedArgCount,
125125
ArrayRef<ParserValue> args, Diagnostics *error) {
126126
if (args.size() != expectedArgCount) {
127-
error->addError(nameRange, error->ET_RegistryWrongArgCount)
127+
error->addError(nameRange, Diagnostics::ErrorType::RegistryWrongArgCount)
128128
<< expectedArgCount << args.size();
129129
return false;
130130
}
@@ -137,7 +137,8 @@ inline bool checkArgTypeAtIndex(StringRef matcherName,
137137
ArrayRef<ParserValue> args,
138138
Diagnostics *error) {
139139
if (!ArgTypeTraits<ArgType>::hasCorrectType(args[Index].value)) {
140-
error->addError(args[Index].range, error->ET_RegistryWrongArgType)
140+
error->addError(args[Index].range,
141+
Diagnostics::ErrorType::RegistryWrongArgType)
141142
<< matcherName << Index + 1;
142143
return false;
143144
}

mlir/lib/Query/Matcher/Diagnostics.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ Diagnostics::ArgStream Diagnostics::addError(SourceRange range,
2929

3030
static llvm::StringRef errorTypeToFormatString(Diagnostics::ErrorType type) {
3131
switch (type) {
32-
case Diagnostics::ET_RegistryMatcherNotFound:
32+
case Diagnostics::ErrorType::RegistryMatcherNotFound:
3333
return "Matcher not found: $0";
34-
case Diagnostics::ET_RegistryWrongArgCount:
34+
case Diagnostics::ErrorType::RegistryWrongArgCount:
3535
return "Incorrect argument count. (Expected = $0) != (Actual = $1)";
36-
case Diagnostics::ET_RegistryWrongArgType:
36+
case Diagnostics::ErrorType::RegistryWrongArgType:
3737
return "Incorrect type for arg $0. (Expected = $1) != (Actual = $2)";
38-
case Diagnostics::ET_RegistryValueNotFound:
38+
case Diagnostics::ErrorType::RegistryValueNotFound:
3939
return "Value not found: $0";
4040

41-
case Diagnostics::ET_ParserStringError:
41+
case Diagnostics::ErrorType::ParserStringError:
4242
return "Error parsing string token: <$0>";
43-
case Diagnostics::ET_ParserNoOpenParen:
43+
case Diagnostics::ErrorType::ParserNoOpenParen:
4444
return "Error parsing matcher. Found token <$0> while looking for '('.";
45-
case Diagnostics::ET_ParserNoCloseParen:
45+
case Diagnostics::ErrorType::ParserNoCloseParen:
4646
return "Error parsing matcher. Found end-of-code while looking for ')'.";
47-
case Diagnostics::ET_ParserNoComma:
47+
case Diagnostics::ErrorType::ParserNoComma:
4848
return "Error parsing matcher. Found token <$0> while looking for ','.";
49-
case Diagnostics::ET_ParserNoCode:
49+
case Diagnostics::ErrorType::ParserNoCode:
5050
return "End of code found while looking for token.";
51-
case Diagnostics::ET_ParserNotAMatcher:
51+
case Diagnostics::ErrorType::ParserNotAMatcher:
5252
return "Input value is not a matcher expression.";
53-
case Diagnostics::ET_ParserInvalidToken:
53+
case Diagnostics::ErrorType::ParserInvalidToken:
5454
return "Invalid token <$0> found when looking for a value.";
55-
case Diagnostics::ET_ParserTrailingCode:
55+
case Diagnostics::ErrorType::ParserTrailingCode:
5656
return "Unexpected end of code.";
57-
case Diagnostics::ET_ParserOverloadedType:
57+
case Diagnostics::ErrorType::ParserOverloadedType:
5858
return "Input value has unresolved overloaded type: $0";
59-
case Diagnostics::ET_ParserFailedToBuildMatcher:
59+
case Diagnostics::ErrorType::ParserFailedToBuildMatcher:
6060
return "Failed to build matcher: $0.";
6161

62-
case Diagnostics::ET_None:
62+
case Diagnostics::ErrorType::None:
6363
return "<N/A>";
6464
}
6565
llvm_unreachable("Unknown ErrorType value.");

mlir/lib/Query/Matcher/Parser.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ class Parser::CodeTokenizer {
182182
SourceRange range;
183183
range.start = result->range.start;
184184
range.end = currentLocation();
185-
error->addError(range, error->ET_ParserStringError) << errorText;
185+
error->addError(range, Diagnostics::ErrorType::ParserStringError)
186+
<< errorText;
186187
result->kind = TokenInfo::TK_Error;
187188
}
188189

@@ -276,13 +277,13 @@ bool Parser::parseIdentifierPrefixImpl(VariantValue *value) {
276277

277278
if (!namedValue.isMatcher()) {
278279
error->addError(tokenizer->peekNextToken().range,
279-
error->ET_ParserNotAMatcher);
280+
Diagnostics::ErrorType::ParserNotAMatcher);
280281
return false;
281282
}
282283

283284
if (tokenizer->nextTokenKind() == TokenInfo::TK_NewLine) {
284285
error->addError(tokenizer->peekNextToken().range,
285-
error->ET_ParserNoOpenParen)
286+
Diagnostics::ErrorType::ParserNoOpenParen)
286287
<< "NewLine";
287288
return false;
288289
}
@@ -294,7 +295,8 @@ bool Parser::parseIdentifierPrefixImpl(VariantValue *value) {
294295
tokenizer->nextTokenKind() == TokenInfo::TK_NewLine ||
295296
tokenizer->nextTokenKind() == TokenInfo::TK_Eof) &&
296297
!sema->lookupMatcherCtor(nameToken.text)) {
297-
error->addError(nameToken.range, error->ET_RegistryValueNotFound)
298+
error->addError(nameToken.range,
299+
Diagnostics::ErrorType::RegistryValueNotFound)
298300
<< nameToken.text;
299301
return false;
300302
}
@@ -306,7 +308,7 @@ bool Parser::parseIdentifierPrefixImpl(VariantValue *value) {
306308
assert(nameToken.kind == TokenInfo::TK_Ident);
307309
TokenInfo openToken = tokenizer->consumeNextToken();
308310
if (openToken.kind != TokenInfo::TK_OpenParen) {
309-
error->addError(openToken.range, error->ET_ParserNoOpenParen)
311+
error->addError(openToken.range, Diagnostics::ErrorType::ParserNoOpenParen)
310312
<< openToken.text;
311313
return false;
312314
}
@@ -333,7 +335,7 @@ bool Parser::parseMatcherArgs(std::vector<ParserValue> &args, MatcherCtor ctor,
333335
// We must find a , token to continue.
334336
TokenInfo commaToken = tokenizer->consumeNextToken();
335337
if (commaToken.kind != TokenInfo::TK_Comma) {
336-
error->addError(commaToken.range, error->ET_ParserNoComma)
338+
error->addError(commaToken.range, Diagnostics::ErrorType::ParserNoComma)
337339
<< commaToken.text;
338340
return false;
339341
}
@@ -362,7 +364,8 @@ bool Parser::parseMatcherExpressionImpl(const TokenInfo &nameToken,
362364
std::optional<MatcherCtor> ctor,
363365
VariantValue *value) {
364366
if (!ctor) {
365-
error->addError(nameToken.range, error->ET_RegistryMatcherNotFound)
367+
error->addError(nameToken.range,
368+
Diagnostics::ErrorType::RegistryMatcherNotFound)
366369
<< nameToken.text;
367370
// Do not return here. We need to continue to give completion suggestions.
368371
}
@@ -378,7 +381,7 @@ bool Parser::parseMatcherExpressionImpl(const TokenInfo &nameToken,
378381

379382
// Check for the missing closing parenthesis
380383
if (endToken.kind != TokenInfo::TK_CloseParen) {
381-
error->addError(openToken.range, error->ET_ParserNoCloseParen)
384+
error->addError(openToken.range, Diagnostics::ErrorType::ParserNoCloseParen)
382385
<< nameToken.text;
383386
return false;
384387
}
@@ -454,7 +457,7 @@ bool Parser::parseExpressionImpl(VariantValue *value) {
454457
return false;
455458
case TokenInfo::TK_Eof:
456459
error->addError(tokenizer->consumeNextToken().range,
457-
error->ET_ParserNoCode);
460+
Diagnostics::ErrorType::ParserNoCode);
458461
return false;
459462

460463
case TokenInfo::TK_Error:
@@ -467,7 +470,7 @@ bool Parser::parseExpressionImpl(VariantValue *value) {
467470
case TokenInfo::TK_Period:
468471
case TokenInfo::TK_InvalidChar:
469472
const TokenInfo token = tokenizer->consumeNextToken();
470-
error->addError(token.range, error->ET_ParserInvalidToken)
473+
error->addError(token.range, Diagnostics::ErrorType::ParserInvalidToken)
471474
<< (token.kind == TokenInfo::TK_NewLine ? "NewLine" : token.text);
472475
return false;
473476
}
@@ -516,7 +519,7 @@ bool Parser::parseExpression(llvm::StringRef &code, Sema *sema,
516519
if (nextToken.kind != TokenInfo::TK_Eof &&
517520
nextToken.kind != TokenInfo::TK_NewLine) {
518521
error->addError(tokenizer.peekNextToken().range,
519-
error->ET_ParserTrailingCode);
522+
Diagnostics::ErrorType::ParserTrailingCode);
520523
return false;
521524
}
522525
return true;
@@ -542,12 +545,12 @@ Parser::parseMatcherExpression(llvm::StringRef &code, Sema *sema,
542545
if (!parseExpression(code, sema, namedValues, &value, error))
543546
return std::nullopt;
544547
if (!value.isMatcher()) {
545-
error->addError(SourceRange(), error->ET_ParserNotAMatcher);
548+
error->addError(SourceRange(), Diagnostics::ErrorType::ParserNotAMatcher);
546549
return std::nullopt;
547550
}
548551
std::optional<DynMatcher> result = value.getMatcher().getDynMatcher();
549552
if (!result) {
550-
error->addError(SourceRange(), error->ET_ParserOverloadedType)
553+
error->addError(SourceRange(), Diagnostics::ErrorType::ParserOverloadedType)
551554
<< value.getTypeAsString();
552555
}
553556
return result;

0 commit comments

Comments
 (0)