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();
Str += Char;
C.advance();
}
+ return Str;
}
/// Lex a string constant using the following regular expression: \"[^\"]*\"
}
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());
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(
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) {
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 '@'
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) {