Skip to content

Commit c95127f

Browse files
committed
Minor changes and modernization
1 parent 7f9fe1e commit c95127f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

mlir/lib/Tools/mlir-query/Matcher/Parser.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ struct Parser::ScopedContextEntry {
264264
Parser *parser;
265265

266266
ScopedContextEntry(Parser *parser, MatcherCtor c) : parser(parser) {
267-
parser->contextStack.push_back(std::make_pair(c, 0u));
267+
parser->contextStack.push_back({c, 0u});
268268
}
269269

270270
~ScopedContextEntry() { parser->contextStack.pop_back(); }
@@ -273,8 +273,8 @@ struct Parser::ScopedContextEntry {
273273
};
274274

275275
// Parse and validate expressions starting with an identifier.
276-
// This function can parse named values and matchers. In case of failure it will
277-
// try to determine the user's intent to give an appropriate error message.
276+
// This function can parse named values and matchers. In case of failure, it
277+
// will try to determine the user's intent to give an appropriate error message.
278278
bool Parser::parseIdentifierPrefixImpl(VariantValue *value) {
279279
const TokenInfo nameToken = tokenizer->consumeNextToken();
280280

@@ -297,7 +297,7 @@ bool Parser::parseIdentifierPrefixImpl(VariantValue *value) {
297297
}
298298

299299
// If the syntax is correct and the name is not a matcher either, report
300-
// unknown named value.
300+
// an unknown named value.
301301
if ((tokenizer->nextTokenKind() == TokenInfo::TK_Comma ||
302302
tokenizer->nextTokenKind() == TokenInfo::TK_CloseParen ||
303303
tokenizer->nextTokenKind() == TokenInfo::TK_NewLine ||
@@ -495,12 +495,13 @@ void Parser::addCompletion(const TokenInfo &compToken,
495495
std::vector<MatcherCompletion>
496496
Parser::getNamedValueCompletions(ArrayRef<ArgKind> acceptedTypes) {
497497
if (!namedValues)
498-
return std::vector<MatcherCompletion>();
498+
return {};
499+
499500
std::vector<MatcherCompletion> result;
500501
for (const auto &entry : *namedValues) {
501-
std::string Decl =
502+
std::string decl =
502503
(entry.getValue().getTypeAsString() + " " + entry.getKey()).str();
503-
result.emplace_back(entry.getKey(), Decl);
504+
result.emplace_back(entry.getKey(), decl);
504505
}
505506
return result;
506507
}
@@ -511,10 +512,8 @@ void Parser::addExpressionCompletions() {
511512

512513
// We cannot complete code if there is an invalid element on the context
513514
// stack.
514-
for (ContextStackTy::iterator I = contextStack.begin(),
515-
E = contextStack.end();
516-
I != E; ++I) {
517-
if (!I->first)
515+
for (const auto &entry : contextStack) {
516+
if (!entry.first)
518517
return;
519518
}
520519

@@ -607,10 +606,12 @@ bool Parser::parseExpression(llvm::StringRef &code, Sema *sema,
607606
const NamedValueMap *namedValues,
608607
VariantValue *value, Diagnostics *error) {
609608
CodeTokenizer tokenizer(code, error);
610-
if (!Parser(&tokenizer, sema, namedValues, error).parseExpressionImpl(value))
609+
Parser parser(&tokenizer, sema, namedValues, error);
610+
if (!parser.parseExpressionImpl(value))
611611
return false;
612-
auto NT = tokenizer.peekNextToken();
613-
if (NT.kind != TokenInfo::TK_Eof && NT.kind != TokenInfo::TK_NewLine) {
612+
auto nextToken = tokenizer.peekNextToken();
613+
if (nextToken.kind != TokenInfo::TK_Eof &&
614+
nextToken.kind != TokenInfo::TK_NewLine) {
614615
error->addError(tokenizer.peekNextToken().range,
615616
error->ET_ParserTrailingCode);
616617
return false;
@@ -623,11 +624,11 @@ Parser::completeExpression(llvm::StringRef &code, unsigned completionOffset,
623624
Sema *sema, const NamedValueMap *namedValues) {
624625
Diagnostics error;
625626
CodeTokenizer tokenizer(code, &error, completionOffset);
626-
Parser P(&tokenizer, sema, namedValues, &error);
627+
Parser parser(&tokenizer, sema, namedValues, &error);
627628
VariantValue dummy;
628-
P.parseExpressionImpl(&dummy);
629+
parser.parseExpressionImpl(&dummy);
629630

630-
return P.completions;
631+
return parser.completions;
631632
}
632633

633634
std::optional<DynMatcher>

0 commit comments

Comments
 (0)