diff options
author | Chris Lattner <sabre@nondot.org> | 2010-11-17 07:26:20 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-11-17 07:26:20 +0000 |
commit | 39720111e0e8f5b63f9e46b7964af07cefec624b (patch) | |
tree | 451697a69f3859d8768a7e6214fa6b60ef333cfc /clang/lib/Lex/Preprocessor.cpp | |
parent | 366340298e2bbc8fc10a06422edbb95014568eff (diff) | |
download | bcm5719-llvm-39720111e0e8f5b63f9e46b7964af07cefec624b.tar.gz bcm5719-llvm-39720111e0e8f5b63f9e46b7964af07cefec624b.zip |
move getSpelling from Preprocessor to Lexer, which it is more conceptually related to.
llvm-svn: 119479
Diffstat (limited to 'clang/lib/Lex/Preprocessor.cpp')
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index e0eb6661d6a..0b2e970bdaa 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -278,116 +278,6 @@ void Preprocessor::CodeCompleteNaturalLanguage() { CodeComplete->CodeCompleteNaturalLanguage(); } -//===----------------------------------------------------------------------===// -// Token Spelling -//===----------------------------------------------------------------------===// - -/// getSpelling() - Return the 'spelling' of this token. The spelling of a -/// token are the characters used to represent the token in the source file -/// after trigraph expansion and escaped-newline folding. In particular, this -/// wants to get the true, uncanonicalized, spelling of things like digraphs -/// UCNs, etc. -std::string Preprocessor::getSpelling(const Token &Tok, - const SourceManager &SourceMgr, - const LangOptions &Features, - bool *Invalid) { - assert((int)Tok.getLength() >= 0 && "Token character range is bogus!"); - - // If this token contains nothing interesting, return it directly. - bool CharDataInvalid = false; - const char* TokStart = SourceMgr.getCharacterData(Tok.getLocation(), - &CharDataInvalid); - if (Invalid) - *Invalid = CharDataInvalid; - if (CharDataInvalid) - return std::string(); - - if (!Tok.needsCleaning()) - return std::string(TokStart, TokStart+Tok.getLength()); - - std::string Result; - Result.reserve(Tok.getLength()); - - // Otherwise, hard case, relex the characters into the string. - for (const char *Ptr = TokStart, *End = TokStart+Tok.getLength(); - Ptr != End; ) { - unsigned CharSize; - Result.push_back(Lexer::getCharAndSizeNoWarn(Ptr, CharSize, Features)); - Ptr += CharSize; - } - assert(Result.size() != unsigned(Tok.getLength()) && - "NeedsCleaning flag set on something that didn't need cleaning!"); - return Result; -} - -/// getSpelling() - Return the 'spelling' of this token. The spelling of a -/// token are the characters used to represent the token in the source file -/// after trigraph expansion and escaped-newline folding. In particular, this -/// wants to get the true, uncanonicalized, spelling of things like digraphs -/// UCNs, etc. -std::string Preprocessor::getSpelling(const Token &Tok, bool *Invalid) const { - return getSpelling(Tok, SourceMgr, Features, Invalid); -} - -/// getSpelling - This method is used to get the spelling of a token into a -/// preallocated buffer, instead of as an std::string. The caller is required -/// to allocate enough space for the token, which is guaranteed to be at least -/// Tok.getLength() bytes long. The actual length of the token is returned. -/// -/// Note that this method may do two possible things: it may either fill in -/// the buffer specified with characters, or it may *change the input pointer* -/// 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, - 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 - // table, which is very quick. - if (const IdentifierInfo *II = Tok.getIdentifierInfo()) { - Buffer = II->getNameStart(); - return II->getLength(); - } - - // Otherwise, compute the start of the token in the input lexer buffer. - const char *TokStart = 0; - - if (Tok.isLiteral()) - TokStart = Tok.getLiteralData(); - - if (TokStart == 0) { - bool CharDataInvalid = false; - TokStart = SourceMgr.getCharacterData(Tok.getLocation(), &CharDataInvalid); - if (Invalid) - *Invalid = CharDataInvalid; - if (CharDataInvalid) { - Buffer = ""; - return 0; - } - } - - // If this token contains nothing interesting, return it directly. - if (!Tok.needsCleaning()) { - Buffer = TokStart; - 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(); - Ptr != End; ) { - unsigned CharSize; - *OutBuf++ = Lexer::getCharAndSizeNoWarn(Ptr, CharSize, Features); - Ptr += CharSize; - } - assert(unsigned(OutBuf-Buffer) != Tok.getLength() && - "NeedsCleaning flag set on something that didn't need cleaning!"); - - return OutBuf-Buffer; -} /// 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 |