forked from OSchip/llvm-project
[mlir] Update DialectAsmParser::parseString to use std::string instead of StringRef
This allows for parsing strings that have escape sequences, which require constructing a string (as they can't be represented by looking at the Token contents directly). Differential Revision: https://reviews.llvm.org/D108589
This commit is contained in:
parent
aea3026ea7
commit
9658b061dd
|
@ -229,7 +229,7 @@ public:
|
|||
virtual ParseResult parseOptionalEqual() = 0;
|
||||
|
||||
/// Parse a quoted string token.
|
||||
ParseResult parseString(StringRef *string) {
|
||||
ParseResult parseString(std::string *string) {
|
||||
auto loc = getCurrentLocation();
|
||||
if (parseOptionalString(string))
|
||||
return emitError(loc, "expected string");
|
||||
|
@ -237,7 +237,7 @@ public:
|
|||
}
|
||||
|
||||
/// Parse a quoted string token if present.
|
||||
virtual ParseResult parseOptionalString(StringRef *string) = 0;
|
||||
virtual ParseResult parseOptionalString(std::string *string) = 0;
|
||||
|
||||
/// Parse a given keyword.
|
||||
ParseResult parseKeyword(StringRef keyword, const Twine &msg = "") {
|
||||
|
|
|
@ -70,7 +70,7 @@ DataLayoutEntryAttr DataLayoutEntryAttr::parse(DialectAsmParser &parser) {
|
|||
return {};
|
||||
|
||||
Type type = nullptr;
|
||||
StringRef identifier;
|
||||
std::string identifier;
|
||||
llvm::SMLoc idLoc = parser.getCurrentLocation();
|
||||
OptionalParseResult parsedType = parser.parseOptionalType(type);
|
||||
if (parsedType.hasValue() && failed(parsedType.getValue()))
|
||||
|
|
|
@ -169,7 +169,7 @@ Attribute emitc::OpaqueAttr::parse(MLIRContext *context,
|
|||
DialectAsmParser &parser, Type type) {
|
||||
if (parser.parseLess())
|
||||
return Attribute();
|
||||
StringRef value;
|
||||
std::string value;
|
||||
llvm::SMLoc loc = parser.getCurrentLocation();
|
||||
if (parser.parseOptionalString(&value)) {
|
||||
parser.emitError(loc) << "expected string";
|
||||
|
@ -214,7 +214,7 @@ void emitc::OpaqueAttr::print(DialectAsmPrinter &printer) const {
|
|||
Type emitc::OpaqueType::parse(MLIRContext *context, DialectAsmParser &parser) {
|
||||
if (parser.parseLess())
|
||||
return Type();
|
||||
StringRef value;
|
||||
std::string value;
|
||||
llvm::SMLoc loc = parser.getCurrentLocation();
|
||||
if (parser.parseOptionalString(&value) || value.empty()) {
|
||||
parser.emitError(loc) << "expected non empty string";
|
||||
|
|
|
@ -139,7 +139,7 @@ Type GPUDialect::parseType(DialectAsmParser &parser) const {
|
|||
return nullptr;
|
||||
|
||||
// Parse operand.
|
||||
StringRef operand;
|
||||
std::string operand;
|
||||
if (failed(parser.parseOptionalString(&operand)))
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ static LLVMStructType parseStructType(DialectAsmParser &parser) {
|
|||
// If we are parsing a self-reference to a recursive struct, i.e. the parsing
|
||||
// stack already contains a struct with the same identifier, bail out after
|
||||
// the name.
|
||||
StringRef name;
|
||||
std::string name;
|
||||
bool isIdentified = succeeded(parser.parseOptionalString(&name));
|
||||
if (isIdentified) {
|
||||
if (knownStructNames.count(name)) {
|
||||
|
|
|
@ -238,12 +238,12 @@ public:
|
|||
}
|
||||
|
||||
/// Parses a quoted string token if present.
|
||||
ParseResult parseOptionalString(StringRef *string) override {
|
||||
ParseResult parseOptionalString(std::string *string) override {
|
||||
if (!parser.getToken().is(Token::string))
|
||||
return failure();
|
||||
|
||||
if (string)
|
||||
*string = parser.getTokenSpelling().drop_front().drop_back();
|
||||
*string = parser.getToken().getStringValue();
|
||||
parser.consumeToken();
|
||||
return success();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue