From 970c12eade40bd721e365e14285b97188cba9d8c Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Wed, 5 Aug 2015 17:35:55 +0000 Subject: MIR Parser: Simplify the handling of quoted tokens. NFC. The machine instructions lexer should not expose the difference between quoted and unquoted tokens to the parser. llvm-svn: 244068 --- llvm/lib/CodeGen/MIRParser/MILexer.h | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'llvm/lib/CodeGen/MIRParser/MILexer.h') diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index ccf8ffe15e5..f72897a5217 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -70,10 +70,8 @@ struct MIToken { StackObject, FixedStackObject, NamedGlobalValue, - QuotedNamedGlobalValue, GlobalValue, ExternalSymbol, - QuotedExternalSymbol, // Other tokens IntegerLiteral, @@ -82,25 +80,32 @@ struct MIToken { ConstantPoolItem, JumpTableIndex, NamedIRBlock, - QuotedNamedIRBlock, IRBlock, NamedIRValue, - QuotedNamedIRValue, }; private: TokenKind Kind; unsigned StringOffset; + bool HasStringValue; StringRef Range; + std::string StringValue; APSInt IntVal; public: MIToken(TokenKind Kind, StringRef Range, unsigned StringOffset = 0) - : Kind(Kind), StringOffset(StringOffset), Range(Range) {} + : Kind(Kind), StringOffset(StringOffset), HasStringValue(false), + Range(Range) {} + + MIToken(TokenKind Kind, StringRef Range, std::string StringValue, + unsigned StringOffset = 0) + : Kind(Kind), StringOffset(StringOffset), HasStringValue(true), + Range(Range), StringValue(std::move(StringValue)) {} MIToken(TokenKind Kind, StringRef Range, const APSInt &IntVal, unsigned StringOffset = 0) - : Kind(Kind), StringOffset(StringOffset), Range(Range), IntVal(IntVal) {} + : Kind(Kind), StringOffset(StringOffset), HasStringValue(false), + Range(Range), IntVal(IntVal) {} TokenKind kind() const { return Kind; } @@ -124,30 +129,18 @@ public: StringRef::iterator location() const { return Range.begin(); } - bool isStringValueQuoted() const { - return Kind == QuotedNamedGlobalValue || Kind == QuotedExternalSymbol || - Kind == QuotedNamedIRBlock || Kind == QuotedNamedIRValue; - } - /// Return the token's raw string value. /// /// If the string value is quoted, this method returns that quoted string as /// it is, without unescaping the string value. StringRef rawStringValue() const { return Range.drop_front(StringOffset); } - /// Return token's string value. - /// - /// Expects the string value to be unquoted. + /// Return the token's string value. StringRef stringValue() const { - assert(!isStringValueQuoted() && "String value is quoted"); - return Range.drop_front(StringOffset); + return HasStringValue ? StringRef(StringValue) + : Range.drop_front(StringOffset); } - /// Unescapes the token's string value. - /// - /// Expects the string value to be quoted. - void unescapeQuotedStringValue(std::string &Str) const; - const APSInt &integerValue() const { return IntVal; } bool hasIntegerValue() const { -- cgit v1.2.3