[Mlir-commits] [mlir] 9658b06 - [mlir] Update DialectAsmParser::parseString to use std::string instead of StringRef

River Riddle llvmlistbot at llvm.org
Wed Aug 25 02:38:05 PDT 2021


Author: River Riddle
Date: 2021-08-25T09:27:35Z
New Revision: 9658b061dd2970a5bd939c92e5e72f82d28de19a

URL: https://github.com/llvm/llvm-project/commit/9658b061dd2970a5bd939c92e5e72f82d28de19a
DIFF: https://github.com/llvm/llvm-project/commit/9658b061dd2970a5bd939c92e5e72f82d28de19a.diff

LOG: [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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/DialectImplementation.h b/mlir/include/mlir/IR/DialectImplementation.h
index 6cd99dc4ef357..1e4b7bb04ebf9 100644
--- a/mlir/include/mlir/IR/DialectImplementation.h
+++ b/mlir/include/mlir/IR/DialectImplementation.h
@@ -229,7 +229,7 @@ class DialectAsmParser {
   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 @@ class DialectAsmParser {
   }
 
   /// 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 = "") {

diff  --git a/mlir/lib/Dialect/DLTI/DLTI.cpp b/mlir/lib/Dialect/DLTI/DLTI.cpp
index 20615124bd91d..c6ae79227cd06 100644
--- a/mlir/lib/Dialect/DLTI/DLTI.cpp
+++ b/mlir/lib/Dialect/DLTI/DLTI.cpp
@@ -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()))

diff  --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index e99eb7b9afb2a..81868e5d50bf0 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -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";

diff  --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 12730d78d2530..eb9145ee83839 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -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;
 

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
index a203a3fcd3857..acf0328f48786 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
@@ -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)) {

diff  --git a/mlir/lib/Parser/DialectSymbolParser.cpp b/mlir/lib/Parser/DialectSymbolParser.cpp
index 62a03795b8415..80b743675f44c 100644
--- a/mlir/lib/Parser/DialectSymbolParser.cpp
+++ b/mlir/lib/Parser/DialectSymbolParser.cpp
@@ -238,12 +238,12 @@ class CustomDialectAsmParser : public DialectAsmParser {
   }
 
   /// 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();
   }


        


More information about the Mlir-commits mailing list