diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-08-05 17:35:55 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-08-05 17:35:55 +0000 |
commit | 970c12eade40bd721e365e14285b97188cba9d8c (patch) | |
tree | 43b8629caf00c3d39f47b776611220c9427d38c1 /llvm/lib/CodeGen/MIRParser/MILexer.cpp | |
parent | 69e3eb3c79f5013fd7a602c5c06423f70faf44b6 (diff) | |
download | bcm5719-llvm-970c12eade40bd721e365e14285b97188cba9d8c.tar.gz bcm5719-llvm-970c12eade40bd721e365e14285b97188cba9d8c.zip |
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
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser/MILexer.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index adc72e2a566..624ef664620 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -69,13 +69,14 @@ static bool isIdentifierChar(char C) { C == '$'; } -void MIToken::unescapeQuotedStringValue(std::string &Str) const { - assert(isStringValueQuoted() && "String value isn't quoted"); - StringRef Value = Range.drop_front(StringOffset); +/// Unescapes the given string value. +/// +/// Expects the string value to be quoted. +static std::string unescapeQuotedString(StringRef Value) { assert(Value.front() == '"' && Value.back() == '"'); Cursor C = Cursor(Value.substr(1, Value.size() - 2)); - Str.clear(); + std::string Str; Str.reserve(C.remaining().size()); while (!C.isEOF()) { char Char = C.peek(); @@ -95,6 +96,7 @@ void MIToken::unescapeQuotedStringValue(std::string &Str) const { Str += Char; C.advance(); } + return Str; } /// Lex a string constant using the following regular expression: \"[^\"]*\" @@ -115,14 +117,16 @@ static Cursor lexStringConstant( } static Cursor lexName( - Cursor C, MIToken &Token, MIToken::TokenKind Type, - MIToken::TokenKind QuotedType, unsigned PrefixLength, + Cursor C, MIToken &Token, MIToken::TokenKind Type, unsigned PrefixLength, function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { auto Range = C; C.advance(PrefixLength); if (C.peek() == '"') { if (Cursor R = lexStringConstant(C, ErrorCallback)) { - Token = MIToken(QuotedType, Range.upto(R), PrefixLength); + StringRef String = Range.upto(R); + Token = MIToken(Type, String, + unescapeQuotedString(String.drop_front(PrefixLength)), + PrefixLength); return R; } Token = MIToken(MIToken::Error, Range.remaining()); @@ -257,8 +261,7 @@ static Cursor maybeLexIRBlock( return None; if (isdigit(C.peek(Rule.size()))) return maybeLexIndex(C, Token, Rule, MIToken::IRBlock); - return lexName(C, Token, MIToken::NamedIRBlock, MIToken::QuotedNamedIRBlock, - Rule.size(), ErrorCallback); + return lexName(C, Token, MIToken::NamedIRBlock, Rule.size(), ErrorCallback); } static Cursor maybeLexIRValue( @@ -267,8 +270,7 @@ static Cursor maybeLexIRValue( const StringRef Rule = "%ir."; if (!C.remaining().startswith(Rule)) return None; - return lexName(C, Token, MIToken::NamedIRValue, MIToken::QuotedNamedIRValue, - Rule.size(), ErrorCallback); + return lexName(C, Token, MIToken::NamedIRValue, Rule.size(), ErrorCallback); } static Cursor lexVirtualRegister(Cursor C, MIToken &Token) { @@ -302,8 +304,7 @@ static Cursor maybeLexGlobalValue( if (C.peek() != '@') return None; if (!isdigit(C.peek(1))) - return lexName(C, Token, MIToken::NamedGlobalValue, - MIToken::QuotedNamedGlobalValue, /*PrefixLength=*/1, + return lexName(C, Token, MIToken::NamedGlobalValue, /*PrefixLength=*/1, ErrorCallback); auto Range = C; C.advance(1); // Skip the '@' @@ -320,9 +321,8 @@ static Cursor maybeLexExternalSymbol( function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { if (C.peek() != '$') return None; - return lexName(C, Token, MIToken::ExternalSymbol, - MIToken::QuotedExternalSymbol, - /*PrefixLength=*/1, ErrorCallback); + return lexName(C, Token, MIToken::ExternalSymbol, /*PrefixLength=*/1, + ErrorCallback); } static bool isValidHexFloatingPointPrefix(char C) { |