From: River Riddle Date: Wed, 13 Nov 2019 17:31:45 +0000 (-0800) Subject: Rename the current parseSymbolName to parseOptionalSymbolName X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6df83699418c6a6d6105728cdec59c78212aa841;p=platform%2Fupstream%2Fllvm.git Rename the current parseSymbolName to parseOptionalSymbolName The current implementation silently fails if the '@' identifier isn't present, making it similar to the 'optional' parse methods. This change renames the current implementation to 'Optional' and adds a new 'parseSymbolName' that emits an error. PiperOrigin-RevId: 280214610 --- diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index a167a7d..46c6701 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -357,9 +357,21 @@ public: // Identifier Parsing //===--------------------------------------------------------------------===// + /// Parse an @-identifier and store it (without the '@' symbol) in a string + /// attribute named 'attrName'. + ParseResult parseSymbolName(StringAttr &result, StringRef attrName, + SmallVectorImpl &attrs) { + if (failed(parseOptionalSymbolName(result, attrName, attrs))) + return emitError(getCurrentLocation()) + << "expected valid '@'-identifier for symbol name"; + return success(); + } + + /// Parse an optional @-identifier and store it (without the '@' symbol) in a + /// string attribute named 'attrName'. virtual ParseResult - parseSymbolName(StringAttr &result, StringRef attrName, - SmallVectorImpl &attrs) = 0; + parseOptionalSymbolName(StringAttr &result, StringRef attrName, + SmallVectorImpl &attrs) = 0; //===--------------------------------------------------------------------===// // Operand Parsing diff --git a/mlir/lib/IR/FunctionSupport.cpp b/mlir/lib/IR/FunctionSupport.cpp index 29cae17..6b27eb8 100644 --- a/mlir/lib/IR/FunctionSupport.cpp +++ b/mlir/lib/IR/FunctionSupport.cpp @@ -159,12 +159,10 @@ mlir::impl::parseFunctionLikeOp(OpAsmParser &parser, OperationState &result, auto &builder = parser.getBuilder(); // Parse the name as a symbol reference attribute. - FlatSymbolRefAttr nameAttr; - if (parser.parseAttribute(nameAttr, ::mlir::SymbolTable::getSymbolAttrName(), - result.attributes)) + StringAttr nameAttr; + if (parser.parseSymbolName(nameAttr, ::mlir::SymbolTable::getSymbolAttrName(), + result.attributes)) return failure(); - // Convert the parsed function attr into a string attr. - result.attributes.back().second = builder.getStringAttr(nameAttr.getValue()); // Parse the function signature. auto signatureLocation = parser.getCurrentLocation(); diff --git a/mlir/lib/IR/Module.cpp b/mlir/lib/IR/Module.cpp index f5cc98e..79e0452 100644 --- a/mlir/lib/IR/Module.cpp +++ b/mlir/lib/IR/Module.cpp @@ -44,8 +44,8 @@ ModuleOp ModuleOp::create(Location loc, Optional name) { ParseResult ModuleOp::parse(OpAsmParser &parser, OperationState &result) { // If the name is present, parse it. StringAttr nameAttr; - (void)parser.parseSymbolName(nameAttr, mlir::SymbolTable::getSymbolAttrName(), - result.attributes); + (void)parser.parseOptionalSymbolName( + nameAttr, mlir::SymbolTable::getSymbolAttrName(), result.attributes); // If module attributes are present, parse them. if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 2843aae..9dd6d50 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -847,12 +847,13 @@ static T parseSymbol(llvm::StringRef inputStr, MLIRContext *context, //===----------------------------------------------------------------------===// InFlightDiagnostic Parser::emitError(SMLoc loc, const Twine &message) { + auto diag = mlir::emitError(getEncodedSourceLocation(loc), message); + // If we hit a parse error in response to a lexer error, then the lexer // already reported the error. if (getToken().is(Token::error)) - return InFlightDiagnostic(); - - return mlir::emitError(getEncodedSourceLocation(loc), message); + diag.abandon(); + return diag; } //===----------------------------------------------------------------------===// @@ -3937,10 +3938,11 @@ public: return success(); } - /// Parse an @-identifier and store it (without the '@' symbol) in a string - /// attribute named 'attrName'. - ParseResult parseSymbolName(StringAttr &result, StringRef attrName, - SmallVectorImpl &attrs) override { + /// Parse an optional @-identifier and store it (without the '@' symbol) in a + /// string attribute named 'attrName'. + ParseResult + parseOptionalSymbolName(StringAttr &result, StringRef attrName, + SmallVectorImpl &attrs) override { Token atToken = parser.getToken(); if (atToken.isNot(Token::at_identifier)) return failure(); diff --git a/mlir/test/IR/invalid-func-op.mlir b/mlir/test/IR/invalid-func-op.mlir index 1554736..20af5ec 100644 --- a/mlir/test/IR/invalid-func-op.mlir +++ b/mlir/test/IR/invalid-func-op.mlir @@ -3,7 +3,7 @@ // ----- func @func_op() { - // expected-error@+1 {{expected non-function type}} + // expected-error@+1 {{expected valid '@'-identifier for symbol name}} func missingsigil() -> (i1, index, f32) return }