PTH:
- Added stub PTHLexer::getSpelling() that will be used for fetching cached
spellings from the PTH file. This doesn't do anything yet.
- Added a hook in Preprocessor::getSpelling() to call PTHLexer::getSpelling()
when using a PTHLexer.
- Updated PTHLexer to read the offsets of spelling tables in the PTH file.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61911 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 1fe2321..ee6b0f8 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -236,7 +236,25 @@
Buffer = II->getName();
return II->getLength();
}
-
+
+ // 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);
+
+ // 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;
+ }
+
// Otherwise, compute the start of the token in the input lexer buffer.
const char *TokStart = SourceMgr.getCharacterData(Tok.getLocation());