diff options
author | Roman Divacky <rdivacky@freebsd.org> | 2010-12-18 08:56:37 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@freebsd.org> | 2010-12-18 08:56:37 +0000 |
commit | 7529b164104f802b59fbf96f5a88d9709ac3ff1a (patch) | |
tree | 697242b1336763503af572cb2907c4f8e4fadf7e /lib | |
parent | fffa8635361639acadb78089c5b9b445c0aa1d30 (diff) |
Add support for lexing single quotes like 'c'.
This fixed 8615.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122150 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCParser/AsmLexer.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/MC/MCParser/AsmLexer.cpp b/lib/MC/MCParser/AsmLexer.cpp index 867cb208ce..085d519406 100644 --- a/lib/MC/MCParser/AsmLexer.cpp +++ b/lib/MC/MCParser/AsmLexer.cpp @@ -265,6 +265,42 @@ AsmToken AsmLexer::LexDigit() { return AsmToken(AsmToken::Integer, Result, Value); } +/// LexSingleQuote: Integer: 'b' +AsmToken AsmLexer::LexSingleQuote() { + int CurChar = getNextChar(); + + if (CurChar == '\\') + CurChar = getNextChar(); + + if (CurChar == EOF) + return ReturnError(TokStart, "unterminated single quote"); + + CurChar = getNextChar(); + + if (CurChar != '\'') + return ReturnError(TokStart, "single quote way too long"); + + // The idea here being that 'c' is basically just an integral + // constant. + StringRef Res = StringRef(TokStart,CurPtr - TokStart); + long long Value; + + if (Res.startswith("\'\\")) { + char theChar = Res[2]; + switch (theChar) { + default: Value = theChar; break; + case '\'': Value = '\''; break; + case 't': Value = '\t'; break; + case 'n': Value = '\n'; break; + case 'b': Value = '\b'; break; + } + } else + Value = TokStart[1]; + + return AsmToken(AsmToken::Integer, Res, Value); +} + + /// LexQuote: String: "..." AsmToken AsmLexer::LexQuote() { int CurChar = getNextChar(); @@ -361,6 +397,7 @@ AsmToken AsmLexer::LexToken() { case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1)); case '/': return LexSlash(); case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1)); + case '\'': return LexSingleQuote(); case '"': return LexQuote(); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': |