From 48cf9824fbad42995f4d91d59d08d2620effd683 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 17 Nov 2010 06:31:48 +0000 Subject: [PATCH] add a static form of the efficient PP::getSpelling method. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119469 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/Preprocessor.h | 8 +++++++- lib/Lex/LiteralSupport.cpp | 5 ++++- lib/Lex/Preprocessor.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index b45f47bf11..380d116386 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -664,7 +664,13 @@ public: /// copy). The caller is not allowed to modify the returned buffer pointer /// if an internal buffer is returned. unsigned getSpelling(const Token &Tok, const char *&Buffer, - bool *Invalid = 0) const; + bool *Invalid = 0) const { + return getSpelling(Tok, Buffer, SourceMgr, Features, Invalid); + } + static unsigned getSpelling(const Token &Tok, const char *&Buffer, + const SourceManager &SourceMgr, + const LangOptions &Features, + bool *Invalid = 0); /// getSpelling - This method is used to get the spelling of a token into a /// SmallVector. Note that the returned StringRef may not point to the diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index 10adb67814..26be1d0ae1 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -1016,7 +1016,10 @@ unsigned StringLiteralParser::getOffsetOfStringByte(const Token &Tok, bool StringInvalid = false; const char *SpellingPtr = &SpellingBuffer[0]; - unsigned TokLen = PP.getSpelling(Tok, SpellingPtr, &StringInvalid); + unsigned TokLen = Preprocessor::getSpelling(Tok, SpellingPtr, + PP.getSourceManager(), + PP.getLangOptions(), + &StringInvalid); if (StringInvalid) return 0; diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index ff18c3f324..e9b854306a 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -339,8 +339,10 @@ 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 { +unsigned Preprocessor::getSpelling(const Token &Tok, const char *&Buffer, + const SourceManager &SourceMgr, + const LangOptions &Features, + bool *Invalid) { assert((int)Tok.getLength() >= 0 && "Token character range is bogus!"); // If this token is an identifier, just return the string from the identifier -- 2.50.1