[mlir] Update DialectAsmParser::parseString to use std::string instead of StringRef
authorRiver Riddle <riddleriver@gmail.com>
Wed, 25 Aug 2021 09:26:39 +0000 (09:26 +0000)
committerRiver Riddle <riddleriver@gmail.com>
Wed, 25 Aug 2021 09:27:35 +0000 (09:27 +0000)
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

mlir/include/mlir/IR/DialectImplementation.h
mlir/lib/Dialect/DLTI/DLTI.cpp
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
mlir/lib/Parser/DialectSymbolParser.cpp

index 6cd99dc..1e4b7bb 100644 (file)
@@ -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 = "") {
index 2061512..c6ae792 100644 (file)
@@ -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()))
index e99eb7b..81868e5 100644 (file)
@@ -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";
index 12730d7..eb9145e 100644 (file)
@@ -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;
 
index a203a3f..acf0328 100644 (file)
@@ -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)) {
index 62a0379..80b7436 100644 (file)
@@ -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();
   }