//===--------------------------------------------------------------------===//
/// Parse an @-identifier and store it (without the '@' symbol) in a string
+ /// attribute.
+ ParseResult parseSymbolName(StringAttr &result) {
+ if (failed(parseOptionalSymbolName(result)))
+ return emitError(getCurrentLocation())
+ << "expected valid '@'-identifier for symbol name";
+ return success();
+ }
+
+ /// Parse an @-identifier and store it (without the '@' symbol) in a string
/// attribute named 'attrName'.
ParseResult parseSymbolName(StringAttr &result, StringRef attrName,
NamedAttrList &attrs) {
- if (failed(parseOptionalSymbolName(result, attrName, attrs)))
- return emitError(getCurrentLocation())
- << "expected valid '@'-identifier for symbol name";
+ if (parseSymbolName(result))
+ return failure();
+ attrs.append(attrName, result);
return success();
}
/// Parse an optional @-identifier and store it (without the '@' symbol) in a
+ /// string attribute.
+ virtual ParseResult parseOptionalSymbolName(StringAttr &result) = 0;
+
+ /// Parse an optional @-identifier and store it (without the '@' symbol) in a
/// string attribute named 'attrName'.
- virtual ParseResult parseOptionalSymbolName(StringAttr &result,
- StringRef attrName,
- NamedAttrList &attrs) = 0;
+ ParseResult parseOptionalSymbolName(StringAttr &result, StringRef attrName,
+ NamedAttrList &attrs) {
+ if (succeeded(parseOptionalSymbolName(result))) {
+ attrs.append(attrName, result);
+ return success();
+ }
+ return failure();
+ }
//===--------------------------------------------------------------------===//
// Resource Parsing
/// Parse an optional @-identifier and store it (without the '@' symbol) in a
/// string attribute named 'attrName'.
- ParseResult parseOptionalSymbolName(StringAttr &result, StringRef attrName,
- NamedAttrList &attrs) override {
+ ParseResult parseOptionalSymbolName(StringAttr &result) override {
Token atToken = parser.getToken();
if (atToken.isNot(Token::at_identifier))
return failure();
result = getBuilder().getStringAttr(atToken.getSymbolReference());
- attrs.push_back(getBuilder().getNamedAttr(attrName, result));
parser.consumeToken();
// If we are populating the assembly parser state, record this as a symbol