2008-11-13 05:37:15 +08:00
|
|
|
//===--- PTHLexer.cpp - Lex from a token stream ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the PTHLexer interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-12-03 08:38:03 +08:00
|
|
|
#include "clang/Basic/TokenKinds.h"
|
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2008-11-13 05:37:15 +08:00
|
|
|
#include "clang/Lex/PTHLexer.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2008-12-03 08:38:03 +08:00
|
|
|
#include "clang/Lex/PTHManager.h"
|
|
|
|
#include "clang/Lex/Token.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
|
|
|
|
2008-11-13 05:37:15 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2008-12-13 02:34:08 +08:00
|
|
|
#define DISK_TOKEN_SIZE (2+3*4)
|
|
|
|
|
2008-12-03 08:38:03 +08:00
|
|
|
PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D,
|
2008-12-13 02:34:08 +08:00
|
|
|
const char* ppcond, PTHManager& PM)
|
2008-12-12 06:41:47 +08:00
|
|
|
: PreprocessorLexer(&pp, fileloc), TokBuf(D), CurPtr(D), LastHashTokPtr(0),
|
2008-12-13 02:34:08 +08:00
|
|
|
PPCond(ppcond), CurPPCondPtr(ppcond), PTHMgr(PM), NeedsFetching(true) {
|
2008-12-03 08:38:03 +08:00
|
|
|
// Make sure the EofToken is completely clean.
|
|
|
|
EofToken.startToken();
|
|
|
|
}
|
2008-11-13 05:37:15 +08:00
|
|
|
|
2008-12-03 08:38:03 +08:00
|
|
|
Token PTHLexer::GetToken() {
|
|
|
|
// Read the next token, or if we haven't advanced yet, get the last
|
|
|
|
// token read.
|
|
|
|
if (NeedsFetching) {
|
|
|
|
NeedsFetching = false;
|
|
|
|
ReadToken(LastFetched);
|
|
|
|
}
|
|
|
|
|
|
|
|
Token Tok = LastFetched;
|
2008-11-21 03:49:00 +08:00
|
|
|
|
|
|
|
// If we are in raw mode, zero out identifier pointers. This is
|
|
|
|
// needed for 'pragma poison'. Note that this requires that the Preprocessor
|
|
|
|
// can go back to the original source when it calls getSpelling().
|
|
|
|
if (LexingRawMode && Tok.is(tok::identifier))
|
|
|
|
Tok.setIdentifierInfo(0);
|
|
|
|
|
|
|
|
return Tok;
|
|
|
|
}
|
|
|
|
|
2008-11-13 05:37:15 +08:00
|
|
|
void PTHLexer::Lex(Token& Tok) {
|
2008-11-20 15:58:05 +08:00
|
|
|
LexNextToken:
|
2008-11-21 08:58:35 +08:00
|
|
|
Tok = GetToken();
|
|
|
|
|
2008-11-21 00:32:22 +08:00
|
|
|
if (AtLastToken()) {
|
2008-11-21 08:58:35 +08:00
|
|
|
Preprocessor *PPCache = PP;
|
|
|
|
|
|
|
|
if (LexEndOfFile(Tok))
|
2008-11-20 15:58:05 +08:00
|
|
|
return;
|
2008-11-13 05:37:15 +08:00
|
|
|
|
2008-11-21 08:58:35 +08:00
|
|
|
assert(PPCache && "Raw buffer::LexEndOfFile should return a token");
|
|
|
|
return PPCache->Lex(Tok);
|
|
|
|
}
|
2008-11-13 05:37:15 +08:00
|
|
|
|
2008-11-20 15:58:05 +08:00
|
|
|
// Don't advance to the next token yet. Check if we are at the
|
|
|
|
// start of a new line and we're processing a directive. If so, we
|
|
|
|
// consume this token twice, once as an tok::eom.
|
|
|
|
if (Tok.isAtStartOfLine() && ParsingPreprocessorDirective) {
|
|
|
|
ParsingPreprocessorDirective = false;
|
|
|
|
Tok.setKind(tok::eom);
|
2008-11-13 05:37:15 +08:00
|
|
|
MIOpt.ReadToken();
|
|
|
|
return;
|
|
|
|
}
|
2008-11-20 15:58:05 +08:00
|
|
|
|
|
|
|
// Advance to the next token.
|
2008-11-21 00:32:22 +08:00
|
|
|
AdvanceToken();
|
2008-11-20 15:58:05 +08:00
|
|
|
|
|
|
|
if (Tok.is(tok::hash)) {
|
2008-12-13 02:34:08 +08:00
|
|
|
if (Tok.isAtStartOfLine()) {
|
|
|
|
LastHashTokPtr = CurPtr - DISK_TOKEN_SIZE;
|
|
|
|
if (!LexingRawMode) {
|
|
|
|
PP->HandleDirective(Tok);
|
2008-11-20 15:58:05 +08:00
|
|
|
|
2008-12-13 02:34:08 +08:00
|
|
|
if (PP->isCurrentLexer(this))
|
|
|
|
goto LexNextToken;
|
|
|
|
|
|
|
|
return PP->Lex(Tok);
|
|
|
|
}
|
2008-11-20 15:58:05 +08:00
|
|
|
}
|
2008-11-13 05:37:15 +08:00
|
|
|
}
|
2008-11-20 15:58:05 +08:00
|
|
|
|
2008-11-13 05:37:15 +08:00
|
|
|
MIOpt.ReadToken();
|
2008-11-20 15:58:05 +08:00
|
|
|
|
|
|
|
if (Tok.is(tok::identifier)) {
|
|
|
|
if (LexingRawMode) return;
|
|
|
|
return PP->HandleIdentifier(Tok);
|
|
|
|
}
|
2008-11-13 05:37:15 +08:00
|
|
|
}
|
|
|
|
|
2008-11-21 08:58:35 +08:00
|
|
|
bool PTHLexer::LexEndOfFile(Token &Tok) {
|
|
|
|
|
|
|
|
if (ParsingPreprocessorDirective) {
|
|
|
|
ParsingPreprocessorDirective = false;
|
|
|
|
Tok.setKind(tok::eom);
|
|
|
|
MIOpt.ReadToken();
|
|
|
|
return true; // Have a token.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LexingRawMode) {
|
|
|
|
MIOpt.ReadToken();
|
|
|
|
return true; // Have an eof token.
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Issue diagnostics similar to Lexer.
|
|
|
|
return PP->HandleEndOfFile(Tok, false);
|
|
|
|
}
|
|
|
|
|
2008-11-13 05:37:15 +08:00
|
|
|
void PTHLexer::setEOF(Token& Tok) {
|
2008-12-03 08:38:03 +08:00
|
|
|
assert(!EofToken.is(tok::eof));
|
|
|
|
Tok = EofToken;
|
2008-11-13 05:37:15 +08:00
|
|
|
}
|
2008-11-20 06:21:33 +08:00
|
|
|
|
|
|
|
void PTHLexer::DiscardToEndOfLine() {
|
|
|
|
assert(ParsingPreprocessorDirective && ParsingFilename == false &&
|
|
|
|
"Must be in a preprocessing directive!");
|
2008-11-20 09:16:50 +08:00
|
|
|
|
|
|
|
// Already at end-of-file?
|
2008-11-21 00:32:22 +08:00
|
|
|
if (AtLastToken())
|
2008-11-20 09:16:50 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Find the first token that is not the start of the *current* line.
|
2008-11-22 07:28:56 +08:00
|
|
|
Token T;
|
|
|
|
for (Lex(T); !AtLastToken(); Lex(T))
|
2008-11-21 00:32:22 +08:00
|
|
|
if (GetToken().isAtStartOfLine())
|
2008-11-20 09:16:50 +08:00
|
|
|
return;
|
2008-11-20 06:21:33 +08:00
|
|
|
}
|
2008-12-03 08:38:03 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods for reading from the mmap'ed PTH file.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static inline uint8_t Read8(const char*& data) {
|
|
|
|
return (uint8_t) *(data++);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t Read32(const char*& data) {
|
|
|
|
uint32_t V = (uint32_t) Read8(data);
|
|
|
|
V |= (((uint32_t) Read8(data)) << 8);
|
|
|
|
V |= (((uint32_t) Read8(data)) << 16);
|
|
|
|
V |= (((uint32_t) Read8(data)) << 24);
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
2008-12-13 02:34:08 +08:00
|
|
|
/// SkipBlock - Used by Preprocessor to skip the current conditional block.
|
|
|
|
bool PTHLexer::SkipBlock() {
|
|
|
|
assert(CurPPCondPtr && "No cached PP conditional information.");
|
|
|
|
assert(LastHashTokPtr && "No known '#' token.");
|
|
|
|
|
|
|
|
const char* Next = 0;
|
|
|
|
uint32_t Offset;
|
|
|
|
uint32_t TableIdx;
|
|
|
|
|
|
|
|
do {
|
|
|
|
Offset = Read32(CurPPCondPtr);
|
|
|
|
TableIdx = Read32(CurPPCondPtr);
|
|
|
|
Next = TokBuf + Offset;
|
|
|
|
}
|
|
|
|
while (Next < LastHashTokPtr);
|
|
|
|
assert(Next == LastHashTokPtr && "No PP-cond entry found for '#'");
|
|
|
|
assert(TableIdx && "No jumping from #endifs.");
|
|
|
|
|
|
|
|
// Update our side-table iterator.
|
|
|
|
const char* NextPPCondPtr = PPCond + TableIdx*(sizeof(uint32_t)*2);
|
|
|
|
assert(NextPPCondPtr >= CurPPCondPtr);
|
|
|
|
CurPPCondPtr = NextPPCondPtr;
|
|
|
|
|
|
|
|
// Read where we should jump to.
|
|
|
|
Next = TokBuf + Read32(NextPPCondPtr);
|
|
|
|
uint32_t NextIdx = Read32(NextPPCondPtr);
|
|
|
|
|
|
|
|
// By construction NextIdx will be zero if this is a #endif. This is useful
|
|
|
|
// to know to obviate lexing another token.
|
|
|
|
bool isEndif = NextIdx == 0;
|
|
|
|
NeedsFetching = true;
|
|
|
|
|
|
|
|
// This case can occur when we see something like this:
|
|
|
|
//
|
|
|
|
// #if ...
|
|
|
|
// /* a comment or nothing */
|
|
|
|
// #elif
|
|
|
|
//
|
|
|
|
// If we are skipping the first #if block it will be the case that CurPtr
|
|
|
|
// already points 'elif'. Just return.
|
|
|
|
|
|
|
|
if (CurPtr > Next) {
|
|
|
|
assert(CurPtr == Next + DISK_TOKEN_SIZE);
|
|
|
|
// Did we reach a #endif? If so, go ahead and consume that token as well.
|
|
|
|
if (isEndif)
|
|
|
|
CurPtr += DISK_TOKEN_SIZE;
|
|
|
|
else
|
|
|
|
LastHashTokPtr = Next;
|
|
|
|
|
|
|
|
return isEndif;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we need to advance. Update CurPtr to point to the '#' token.
|
|
|
|
CurPtr = Next;
|
|
|
|
|
|
|
|
// Update the location of the last observed '#'. This is useful if we
|
|
|
|
// are skipping multiple blocks.
|
|
|
|
LastHashTokPtr = CurPtr;
|
|
|
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
// In a debug build we should verify that the token is really a '#' that
|
|
|
|
// appears at the start of the line.
|
|
|
|
Token Tok;
|
|
|
|
ReadToken(Tok);
|
|
|
|
assert(Tok.isAtStartOfLine() && Tok.is(tok::hash));
|
|
|
|
#else
|
|
|
|
// In a full release build we can just skip the token entirely.
|
|
|
|
CurPtr += DISK_TOKEN_SIZE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Did we reach a #endif? If so, go ahead and consume that token as well.
|
|
|
|
if (isEndif) { CurPtr += DISK_TOKEN_SIZE; }
|
|
|
|
|
|
|
|
return isEndif;
|
|
|
|
}
|
|
|
|
|
2008-12-03 08:38:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Token reconstruction from the PTH file.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void PTHLexer::ReadToken(Token& T) {
|
|
|
|
// Clear the token.
|
|
|
|
// FIXME: Setting the flags directly should obviate this step.
|
|
|
|
T.startToken();
|
|
|
|
|
|
|
|
// Read the type of the token.
|
2008-12-12 06:41:47 +08:00
|
|
|
T.setKind((tok::TokenKind) Read8(CurPtr));
|
2008-12-03 08:38:03 +08:00
|
|
|
|
|
|
|
// Set flags. This is gross, since we are really setting multiple flags.
|
2008-12-12 06:41:47 +08:00
|
|
|
T.setFlag((Token::TokenFlags) Read8(CurPtr));
|
2008-12-03 08:38:03 +08:00
|
|
|
|
|
|
|
// Set the IdentifierInfo* (if any).
|
2008-12-12 06:41:47 +08:00
|
|
|
T.setIdentifierInfo(PTHMgr.ReadIdentifierInfo(CurPtr));
|
2008-12-03 08:38:03 +08:00
|
|
|
|
|
|
|
// Set the SourceLocation. Since all tokens are constructed using a
|
|
|
|
// raw lexer, they will all be offseted from the same FileID.
|
2008-12-12 06:41:47 +08:00
|
|
|
T.setLocation(SourceLocation::getFileLoc(FileID, Read32(CurPtr)));
|
2008-12-03 08:38:03 +08:00
|
|
|
|
|
|
|
// Finally, read and set the length of the token.
|
2008-12-13 02:34:08 +08:00
|
|
|
T.setLength(Read32(CurPtr));
|
2008-12-03 08:38:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Internal Data Structures for PTH file lookup and resolving identifiers.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
|
/// PTHFileLookup - This internal data structure is used by the PTHManager
|
|
|
|
/// to map from FileEntry objects managed by FileManager to offsets within
|
|
|
|
/// the PTH file.
|
|
|
|
namespace {
|
|
|
|
class VISIBILITY_HIDDEN PTHFileLookup {
|
|
|
|
public:
|
|
|
|
class Val {
|
2008-12-12 07:36:38 +08:00
|
|
|
uint32_t TokenOff;
|
|
|
|
uint32_t PPCondOff;
|
2008-12-03 08:38:03 +08:00
|
|
|
|
|
|
|
public:
|
2008-12-12 07:36:38 +08:00
|
|
|
Val() : TokenOff(~0) {}
|
|
|
|
Val(uint32_t toff, uint32_t poff) : TokenOff(toff), PPCondOff(poff) {}
|
2008-12-03 08:38:03 +08:00
|
|
|
|
2008-12-12 07:36:38 +08:00
|
|
|
uint32_t getTokenOffset() const {
|
|
|
|
assert(TokenOff != ~((uint32_t)0) && "PTHFileLookup entry initialized.");
|
|
|
|
return TokenOff;
|
2008-12-03 08:38:03 +08:00
|
|
|
}
|
|
|
|
|
2008-12-12 07:36:38 +08:00
|
|
|
uint32_t gettPPCondOffset() const {
|
|
|
|
assert(TokenOff != ~((uint32_t)0) && "PTHFileLookup entry initialized.");
|
|
|
|
return PPCondOff;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const { return TokenOff != ~((uint32_t)0); }
|
2008-12-03 08:38:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
llvm::StringMap<Val> FileMap;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PTHFileLookup() {};
|
|
|
|
|
|
|
|
Val Lookup(const FileEntry* FE) {
|
|
|
|
const char* s = FE->getName();
|
|
|
|
unsigned size = strlen(s);
|
|
|
|
return FileMap.GetOrCreateValue(s, s+size).getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReadTable(const char* D) {
|
|
|
|
uint32_t N = Read32(D); // Read the length of the table.
|
|
|
|
|
|
|
|
for ( ; N > 0; --N) { // The rest of the data is the table itself.
|
|
|
|
uint32_t len = Read32(D);
|
|
|
|
const char* s = D;
|
|
|
|
D += len;
|
2008-12-12 07:36:38 +08:00
|
|
|
uint32_t TokenOff = Read32(D);
|
|
|
|
FileMap.GetOrCreateValue(s, s+len).getValue() = Val(TokenOff, Read32(D));
|
2008-12-03 08:38:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PTHManager methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
PTHManager::PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
|
2008-12-11 03:40:23 +08:00
|
|
|
const char* idDataTable, IdentifierInfo** perIDCache,
|
2008-12-03 09:16:39 +08:00
|
|
|
Preprocessor& pp)
|
|
|
|
: Buf(buf), PerIDCache(perIDCache), FileLookup(fileLookup),
|
|
|
|
IdDataTable(idDataTable), ITable(pp.getIdentifierTable()), PP(pp) {}
|
2008-12-03 08:38:03 +08:00
|
|
|
|
|
|
|
PTHManager::~PTHManager() {
|
|
|
|
delete Buf;
|
|
|
|
delete (PTHFileLookup*) FileLookup;
|
2008-12-05 06:47:11 +08:00
|
|
|
free(PerIDCache);
|
2008-12-03 08:38:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PTHManager* PTHManager::Create(const std::string& file, Preprocessor& PP) {
|
|
|
|
|
|
|
|
// Memory map the PTH file.
|
|
|
|
llvm::OwningPtr<llvm::MemoryBuffer>
|
|
|
|
File(llvm::MemoryBuffer::getFile(file.c_str()));
|
|
|
|
|
|
|
|
if (!File)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Get the buffer ranges and check if there are at least three 32-bit
|
|
|
|
// words at the end of the file.
|
|
|
|
const char* BufBeg = File->getBufferStart();
|
|
|
|
const char* BufEnd = File->getBufferEnd();
|
|
|
|
|
|
|
|
if(!(BufEnd > BufBeg + sizeof(uint32_t)*3)) {
|
|
|
|
assert(false && "Invalid PTH file.");
|
|
|
|
return 0; // FIXME: Proper error diagnostic?
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the address of the index table at the end of the PTH file.
|
|
|
|
// This table contains the offset of the file lookup table, the
|
|
|
|
// persistent ID -> identifer data table.
|
|
|
|
const char* EndTable = BufEnd - sizeof(uint32_t)*3;
|
|
|
|
|
|
|
|
// Construct the file lookup table. This will be used for mapping from
|
|
|
|
// FileEntry*'s to cached tokens.
|
|
|
|
const char* FileTableOffset = EndTable + sizeof(uint32_t)*2;
|
|
|
|
const char* FileTable = BufBeg + Read32(FileTableOffset);
|
|
|
|
|
|
|
|
if (!(FileTable > BufBeg && FileTable < BufEnd)) {
|
|
|
|
assert(false && "Invalid PTH file.");
|
|
|
|
return 0; // FIXME: Proper error diagnostic?
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::OwningPtr<PTHFileLookup> FL(new PTHFileLookup());
|
|
|
|
FL->ReadTable(FileTable);
|
|
|
|
|
|
|
|
// Get the location of the table mapping from persistent ids to the
|
|
|
|
// data needed to reconstruct identifiers.
|
|
|
|
const char* IDTableOffset = EndTable + sizeof(uint32_t)*1;
|
|
|
|
const char* IData = BufBeg + Read32(IDTableOffset);
|
|
|
|
if (!(IData > BufBeg && IData < BufEnd)) {
|
|
|
|
assert(false && "Invalid PTH file.");
|
|
|
|
return 0; // FIXME: Proper error diagnostic?
|
|
|
|
}
|
|
|
|
|
2008-12-03 09:16:39 +08:00
|
|
|
// Get the number of IdentifierInfos and pre-allocate the identifier cache.
|
|
|
|
uint32_t NumIds = Read32(IData);
|
|
|
|
|
|
|
|
// Pre-allocate the peristent ID -> IdentifierInfo* cache. We use calloc()
|
|
|
|
// so that we in the best case only zero out memory once when the OS returns
|
|
|
|
// us new pages.
|
|
|
|
IdentifierInfo** PerIDCache =
|
|
|
|
(IdentifierInfo**) calloc(NumIds, sizeof(*PerIDCache));
|
|
|
|
|
|
|
|
if (!PerIDCache) {
|
|
|
|
assert(false && "Could not allocate Persistent ID cache.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the new lexer.
|
|
|
|
return new PTHManager(File.take(), FL.take(), IData, PerIDCache, PP);
|
2008-12-03 08:38:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
IdentifierInfo* PTHManager::ReadIdentifierInfo(const char*& D) {
|
|
|
|
// Read the persistent ID from the PTH file.
|
|
|
|
uint32_t persistentID = Read32(D);
|
|
|
|
|
|
|
|
// A persistent ID of '0' always maps to NULL.
|
|
|
|
if (!persistentID)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Adjust the persistent ID by subtracting '1' so that it can be used
|
|
|
|
// as an index within a table in the PTH file.
|
|
|
|
--persistentID;
|
|
|
|
|
|
|
|
// Check if the IdentifierInfo has already been resolved.
|
2008-12-11 03:40:23 +08:00
|
|
|
IdentifierInfo*& II = PerIDCache[persistentID];
|
2008-12-03 08:38:03 +08:00
|
|
|
if (II) return II;
|
|
|
|
|
|
|
|
// Look in the PTH file for the string data for the IdentifierInfo object.
|
|
|
|
const char* TableEntry = IdDataTable + sizeof(uint32_t) * persistentID;
|
|
|
|
const char* IDData = Buf->getBufferStart() + Read32(TableEntry);
|
|
|
|
assert(IDData < Buf->getBufferEnd());
|
|
|
|
|
|
|
|
// Read the length of the string.
|
|
|
|
uint32_t len = Read32(IDData);
|
|
|
|
|
|
|
|
// Get the IdentifierInfo* with the specified string.
|
|
|
|
II = &ITable.get(IDData, IDData+len);
|
|
|
|
return II;
|
|
|
|
}
|
|
|
|
|
|
|
|
PTHLexer* PTHManager::CreateLexer(unsigned FileID, const FileEntry* FE) {
|
|
|
|
|
|
|
|
if (!FE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Lookup the FileEntry object in our file lookup data structure. It will
|
|
|
|
// return a variant that indicates whether or not there is an offset within
|
|
|
|
// the PTH file that contains cached tokens.
|
2008-12-12 07:36:38 +08:00
|
|
|
PTHFileLookup::Val FileData = ((PTHFileLookup*) FileLookup)->Lookup(FE);
|
2008-12-03 08:38:03 +08:00
|
|
|
|
2008-12-12 07:36:38 +08:00
|
|
|
if (!FileData.isValid()) // No tokens available.
|
2008-12-03 08:38:03 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Compute the offset of the token data within the buffer.
|
2008-12-12 07:36:38 +08:00
|
|
|
const char* data = Buf->getBufferStart() + FileData.getTokenOffset();
|
2008-12-13 02:34:08 +08:00
|
|
|
|
|
|
|
// Get the location of pp-conditional table.
|
|
|
|
const char* ppcond = Buf->getBufferStart() + FileData.gettPPCondOffset();
|
|
|
|
uint32_t len = Read32(ppcond);
|
|
|
|
if (len == 0) ppcond = 0;
|
|
|
|
|
2008-12-03 08:38:03 +08:00
|
|
|
assert(data < Buf->getBufferEnd());
|
2008-12-13 02:34:08 +08:00
|
|
|
return new PTHLexer(PP, SourceLocation::getFileLoc(FileID, 0), data, ppcond,
|
|
|
|
*this);
|
2008-12-03 08:38:03 +08:00
|
|
|
}
|