summaryrefslogtreecommitdiffstats
path: root/clang/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
commitb0b4f74b6b088f4319f2941b8e74ff41e1aa0f10 (patch)
tree0f3034307b72371bdbee3533349afb7f6089cd58 /clang/lib/Lex/Preprocessor.cpp
parentdd25a9d0aac7df7db53a80efeb108032b724910c (diff)
downloadbcm5719-llvm-b0b4f74b6b088f4319f2941b8e74ff41e1aa0f10.tar.gz
bcm5719-llvm-b0b4f74b6b088f4319f2941b8e74ff41e1aa0f10.zip
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
llvm-svn: 62186
Diffstat (limited to 'clang/lib/Lex/Preprocessor.cpp')
-rw-r--r--clang/lib/Lex/Preprocessor.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index ee6b0f888cf..a815265e7c9 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/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.
OpenPOWER on IntegriCloud