// Identifier Parsing
//===--------------------------------------------------------------------===//
+ /// Parse an @-identifier and store it (without the '@' symbol) in a string
+ /// attribute named 'attrName'.
+ ParseResult parseSymbolName(StringAttr &result, StringRef attrName,
+ SmallVectorImpl<NamedAttribute> &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<NamedAttribute> &attrs) = 0;
+ parseOptionalSymbolName(StringAttr &result, StringRef attrName,
+ SmallVectorImpl<NamedAttribute> &attrs) = 0;
//===--------------------------------------------------------------------===//
// Operand Parsing
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();
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))
//===----------------------------------------------------------------------===//
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;
}
//===----------------------------------------------------------------------===//
return success();
}
- /// Parse an @-identifier and store it (without the '@' symbol) in a string
- /// attribute named 'attrName'.
- ParseResult parseSymbolName(StringAttr &result, StringRef attrName,
- SmallVectorImpl<NamedAttribute> &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<NamedAttribute> &attrs) override {
Token atToken = parser.getToken();
if (atToken.isNot(Token::at_identifier))
return failure();
// -----
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
}