From 1734d78f8802fca30da5ed20780ae591b3a2b4e0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 28 Jun 2018 20:45:33 -0700 Subject: Sketch out parser/IR support for OperationInst, and a new Instruction base class. Introduce an Identifier class to MLIRContext to represent uniqued identifiers, introduce string literal support to the lexer, introducing parser and printer support etc. PiperOrigin-RevId: 202592007 --- mlir/lib/Parser/Token.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'mlir/lib/Parser/Token.cpp') diff --git a/mlir/lib/Parser/Token.cpp b/mlir/lib/Parser/Token.cpp index c721cf1d625..a8affc7f504 100644 --- a/mlir/lib/Parser/Token.cpp +++ b/mlir/lib/Parser/Token.cpp @@ -39,7 +39,7 @@ SMRange Token::getLocRange() const { /// For an integer token, return its value as an unsigned. If it doesn't fit, /// return None. -Optional Token::getUnsignedIntegerValue() { +Optional Token::getUnsignedIntegerValue() const { bool isHex = spelling.size() > 1 && spelling[1] == 'x'; unsigned result = 0; @@ -47,3 +47,12 @@ Optional Token::getUnsignedIntegerValue() { return None; return result; } + +/// Given a 'string' token, return its value, including removing the quote +/// characters and unescaping the contents of the string. +std::string Token::getStringValue() const { + // TODO: Handle escaping. + + // Just drop the quotes off for now. + return getSpelling().drop_front().drop_back().str(); +} -- cgit v1.2.3