diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Lex/PTHLexer.cpp | 28 | ||||
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 20 |
2 files changed, 41 insertions, 7 deletions
diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp index 3924c9cd2d3..ef7cfb18d61 100644 --- a/clang/lib/Lex/PTHLexer.cpp +++ b/clang/lib/Lex/PTHLexer.cpp @@ -285,6 +285,10 @@ SourceLocation PTHLexer::getSourceLocation() { return SourceLocation::getFileLoc(FileID, offset); } +unsigned PTHLexer::getSpelling(SourceLocation sloc, const char *&Buffer) { + return 0; +} + //===----------------------------------------------------------------------===// // Internal Data Structures for PTH file lookup and resolving identifiers. //===----------------------------------------------------------------------===// @@ -299,21 +303,28 @@ public: class Val { uint32_t TokenOff; uint32_t PPCondOff; + uint32_t SpellingOff; public: Val() : TokenOff(~0) {} - Val(uint32_t toff, uint32_t poff) : TokenOff(toff), PPCondOff(poff) {} + Val(uint32_t toff, uint32_t poff, uint32_t soff) + : TokenOff(toff), PPCondOff(poff), SpellingOff(soff) {} uint32_t getTokenOffset() const { assert(TokenOff != ~((uint32_t)0) && "PTHFileLookup entry initialized."); return TokenOff; } - uint32_t gettPPCondOffset() const { + uint32_t getPPCondOffset() const { assert(TokenOff != ~((uint32_t)0) && "PTHFileLookup entry initialized."); return PPCondOff; } + uint32_t getSpellingOffset() const { + assert(TokenOff != ~((uint32_t)0) && "PTHFileLookup entry initialized."); + return SpellingOff; + } + bool isValid() const { return TokenOff != ~((uint32_t)0); } }; @@ -336,8 +347,13 @@ public: uint32_t len = Read32(D); const char* s = D; D += len; + uint32_t TokenOff = Read32(D); - FileMap.GetOrCreateValue(s, s+len).getValue() = Val(TokenOff, Read32(D)); + uint32_t PPCondOff = Read32(D); + uint32_t SpellingOff = Read32(D); + + FileMap.GetOrCreateValue(s, s+len).getValue() = + Val(TokenOff, PPCondOff, SpellingOff); } } }; @@ -459,10 +475,10 @@ PTHLexer* PTHManager::CreateLexer(unsigned FileID, const FileEntry* FE) { const char* data = Buf->getBufferStart() + FileData.getTokenOffset(); // Get the location of pp-conditional table. - const char* ppcond = Buf->getBufferStart() + FileData.gettPPCondOffset(); - uint32_t len = Read32(ppcond); + const char* ppcond = Buf->getBufferStart() + FileData.getPPCondOffset(); + uint32_t len = Read32(ppcond); if (len == 0) ppcond = 0; - + assert(data < Buf->getBufferEnd()); return new PTHLexer(PP, SourceLocation::getFileLoc(FileID, 0), data, ppcond, *this); diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 1fe23216e71..ee6b0f888cf 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/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()); |