aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Preprocessor.cpp
diff options
context:
space:
mode:
authorSean Hunt <scshunt@csclub.uwaterloo.ca>2010-08-29 21:26:48 +0000
committerSean Hunt <scshunt@csclub.uwaterloo.ca>2010-08-29 21:26:48 +0000
commit0016d519b831859526b79405cdae4c64c73731c8 (patch)
tree135462aff4053d3400e0046e831e518d598f6569 /lib/Lex/Preprocessor.cpp
parentaba480862485ea1140a81f25c23f43bb080edc90 (diff)
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
Diffstat (limited to 'lib/Lex/Preprocessor.cpp')
-rw-r--r--lib/Lex/Preprocessor.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 5160acf19e..f52d35494a 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -352,15 +352,25 @@ std::string Preprocessor::getSpelling(const Token &Tok, bool *Invalid) const {
/// to point to a constant buffer with the data already in it (avoiding a
/// copy). The caller is not allowed to modify the returned buffer pointer
/// if an internal buffer is returned.
-unsigned Preprocessor::getSpelling(const Token &Tok,
- const char *&Buffer, bool *Invalid) const {
+///
+/// If LiteralOnly is specified, only the literal portion of the token is
+/// processed.
+unsigned Preprocessor::getSpelling(const Token &Tok, const char *&Buffer,
+ bool *Invalid, bool LiteralOnly) const {
assert((int)Tok.getLength() >= 0 && "Token character range is bogus!");
+ assert((!LiteralOnly || Tok.isLiteral()) &&
+ "LiteralOnly used on a non-literal token");
+
+ unsigned (Token::*getLength) () const =
+ LiteralOnly ? &Token::getLiteralLength : &Token::getLength;
// If this token is an identifier, just return the string from the identifier
// table, which is very quick.
if (const IdentifierInfo *II = Tok.getIdentifierInfo()) {
- Buffer = II->getNameStart();
- return II->getLength();
+ if (!Tok.isUserDefinedLiteral()) {
+ Buffer = II->getNameStart();
+ return II->getLength();
+ }
}
// Otherwise, compute the start of the token in the input lexer buffer.
@@ -381,20 +391,20 @@ unsigned Preprocessor::getSpelling(const Token &Tok,
}
// If this token contains nothing interesting, return it directly.
- if (!Tok.needsCleaning()) {
+ if (!(LiteralOnly ? Tok.literalNeedsCleaning() : Tok.needsCleaning())) {
Buffer = TokStart;
- return Tok.getLength();
+ return (Tok.*getLength)();
}
// Otherwise, hard case, relex the characters into the string.
char *OutBuf = const_cast<char*>(Buffer);
- for (const char *Ptr = TokStart, *End = TokStart+Tok.getLength();
+ for (const char *Ptr = TokStart, *End = TokStart+(Tok.*getLength)();
Ptr != End; ) {
unsigned CharSize;
*OutBuf++ = Lexer::getCharAndSizeNoWarn(Ptr, CharSize, Features);
Ptr += CharSize;
}
- assert(unsigned(OutBuf-Buffer) != Tok.getLength() &&
+ assert(unsigned(OutBuf-Buffer) != (Tok.*getLength)() &&
"NeedsCleaning flag set on something that didn't need cleaning!");
return OutBuf-Buffer;