aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Preprocessor.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-01-13 22:05:50 +0000
committerTed Kremenek <kremenek@apple.com>2009-01-13 22:05:50 +0000
commitf02f6f0ee3e05b958bcf67f00f4503671d67eccd (patch)
treea2d4befb57bb7099f7735aaf69ae6182c6c85443 /lib/Lex/Preprocessor.cpp
parent3bd391b569e38c6ef7a6155641d4d3622b5616be (diff)
PTH: Fix remaining cases where the spelling cache in the PTH file was being missed when it shouldn't. This shaves another 7% off PTH time for -Eonly on Cocoa.h
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62186 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Preprocessor.cpp')
-rw-r--r--lib/Lex/Preprocessor.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index ee6b0f888c..a815265e7c 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -195,9 +195,20 @@ void Preprocessor::PrintStats() {
/// UCNs, etc.
std::string Preprocessor::getSpelling(const Token &Tok) const {
assert((int)Tok.getLength() >= 0 && "Token character range is bogus!");
+ const char* TokStart;
+
+ if (PTH) {
+ SourceLocation sloc = SourceMgr.getPhysicalLoc(Tok.getLocation());
+ unsigned fid = sloc.getFileID();
+ unsigned fpos = SourceMgr.getFullFilePos(sloc);
+ if (unsigned len = PTH->getSpelling(fid, fpos, TokStart)) {
+ assert(!Tok.needsCleaning());
+ return std::string(TokStart, TokStart+len);
+ }
+ }
// If this token contains nothing interesting, return it directly.
- const char *TokStart = SourceMgr.getCharacterData(Tok.getLocation());
+ TokStart = SourceMgr.getCharacterData(Tok.getLocation());
if (!Tok.needsCleaning())
return std::string(TokStart, TokStart+Tok.getLength());
@@ -238,21 +249,32 @@ unsigned Preprocessor::getSpelling(const Token &Tok,
}
// If using PTH, try and get the spelling from the PTH file.
- if (CurPTHLexer) {
- // We perform the const_cast<> here because we will only have a PTHLexer
- // when grabbing a stream of tokens from the PTH file (and thus the
- // Preprocessor state is allowed to change). The PTHLexer can assume we are
- // getting token spellings in the order of tokens, and thus can update
- // its internal state so that it can quickly fetch spellings from the PTH
- // file.
- unsigned len =
- const_cast<PTHLexer*>(CurPTHLexer.get())->getSpelling(Tok.getLocation(),
- Buffer);
+ if (PTH) {
+ unsigned len;
+ if (CurPTHLexer) {
+ // We perform the const_cast<> here because we will only have a PTHLexer
+ // when grabbing a stream of tokens from the PTH file (and thus the
+ // Preprocessor state is allowed to change). The PTHLexer can assume we are
+ // getting token spellings in the order of tokens, and thus can update
+ // its internal state so that it can quickly fetch spellings from the PTH
+ // file.
+ len =
+ const_cast<PTHLexer*>(CurPTHLexer.get())->getSpelling(Tok.getLocation(),
+ Buffer);
+ }
+ else {
+ SourceLocation sloc = SourceMgr.getPhysicalLoc(Tok.getLocation());
+ unsigned fid = sloc.getFileID();
+ unsigned fpos = SourceMgr.getFullFilePos(sloc);
+ len = PTH->getSpelling(fid, fpos, Buffer);
+ }
+
// Did we find a spelling? If so return its length. Otherwise fall
// back to the default behavior for getting the spelling by looking at
- // at the source code.
- if (len) return len;
+ // at the source code.
+ if (len)
+ return len;
}
// Otherwise, compute the start of the token in the input lexer buffer.