add a static form of the efficient PP::getSpelling method.

llvm-svn: 119469
This commit is contained in:
Chris Lattner 2010-11-17 06:31:48 +00:00
parent 7a02bfdfce
commit 30d4c928ac
3 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -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