diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-01-08 02:47:16 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-01-08 02:47:16 +0000 |
commit | b70e3dafb9618f34017061400dc19ac5e3539a6d (patch) | |
tree | b99741b597b3bb15aaaf9fb76bcfca9d962d0e70 /lib/Lex/Preprocessor.cpp | |
parent | 500bab244c7f50779ba9dcf7cf0a5537854dd73f (diff) |
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
Diffstat (limited to 'lib/Lex/Preprocessor.cpp')
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 1fe23216e7..ee6b0f888c 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -236,7 +236,25 @@ unsigned Preprocessor::getSpelling(const Token &Tok, 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()); |