Implement C++0x user-defined string literals.
The extra data stored on user-defined literal Tokens is stored in extra
allocated memory, which is managed by the PreprocessorLexer because there isn't
a better place to put it that makes sure it gets deallocated, but only after
it's used up. My testing has shown no significant slowdown as a result, but
independent testing would be appreciated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112458 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 6cd1873..b4cafb4 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -548,6 +548,11 @@
isInited = true;
}
+/// isIdentifierStart - Return true if this is the start character of an
+/// identifier, which is [a-zA-Z_].
+static inline bool isIdentifierStart(unsigned char c) {
+ return (CharInfo[c] & (CHAR_LETTER|CHAR_UNDER)) ? true : false;
+}
/// isIdentifierBody - Return true if this is the body character of an
/// identifier, which is [a-zA-Z0-9_].
@@ -982,8 +987,30 @@
// Update the location of the token as well as the BufferPtr instance var.
const char *TokStart = BufferPtr;
- FormTokenWithChars(Result, CurPtr,
- Wide ? tok::wide_string_literal : tok::string_literal);
+ tok::TokenKind Kind = Wide ? tok::wide_string_literal : tok::string_literal;
+
+ // FIXME: Handle UCNs
+ unsigned Size;
+ if (PP && PP->getLangOptions().CPlusPlus0x &&
+ isIdentifierStart(getCharAndSize(CurPtr, Size))) {
+ Result.makeUserDefinedLiteral(ExtraDataAllocator);
+ Result.setFlagValue(Token::LiteralPortionClean, !Result.needsCleaning());
+ Result.setKind(Kind);
+ Result.setLiteralLength(CurPtr - BufferPtr);
+
+ // FIXME: We hack around the lexer's routines a lot here.
+ BufferPtr = CurPtr;
+ bool OldRawMode = LexingRawMode;
+ LexingRawMode = true;
+ LexIdentifier(Result, ConsumeChar(CurPtr, Size, Result));
+ LexingRawMode = OldRawMode;
+ PP->LookUpIdentifierInfo(Result, CurPtr);
+
+ CurPtr = BufferPtr;
+ BufferPtr = TokStart;
+ }
+
+ FormTokenWithChars(Result, CurPtr, Kind);
Result.setLiteralData(TokStart);
}