Skip to content
Snippets Groups Projects
Commit eb09754a authored by Chris Lattner's avatar Chris Lattner
Browse files

switch PTH lexer from using "const char*"s to "const unsigned char*"s

internally.  This is just a cleanup that reduces the need to cast to
unsigned char before assembling a larger integer.

llvm-svn: 62442
parent a79203be
No related branches found
No related tags found
No related merge requests found
...@@ -26,24 +26,24 @@ class PTHLexer : public PreprocessorLexer { ...@@ -26,24 +26,24 @@ class PTHLexer : public PreprocessorLexer {
SourceLocation FileStartLoc; SourceLocation FileStartLoc;
/// TokBuf - Buffer from PTH file containing raw token data. /// TokBuf - Buffer from PTH file containing raw token data.
const char* TokBuf; const unsigned char* TokBuf;
/// CurPtr - Pointer into current offset of the token buffer where /// CurPtr - Pointer into current offset of the token buffer where
/// the next token will be read. /// the next token will be read.
const char* CurPtr; const unsigned char* CurPtr;
/// LastHashTokPtr - Pointer into TokBuf of the last processed '#' /// LastHashTokPtr - Pointer into TokBuf of the last processed '#'
/// token that appears at the start of a line. /// token that appears at the start of a line.
const char* LastHashTokPtr; const unsigned char* LastHashTokPtr;
/// PPCond - Pointer to a side table in the PTH file that provides a /// PPCond - Pointer to a side table in the PTH file that provides a
/// a consise summary of the preproccessor conditional block structure. /// a consise summary of the preproccessor conditional block structure.
/// This is used to perform quick skipping of conditional blocks. /// This is used to perform quick skipping of conditional blocks.
const char* PPCond; const unsigned char* PPCond;
/// CurPPCondPtr - Pointer inside PPCond that refers to the next entry /// CurPPCondPtr - Pointer inside PPCond that refers to the next entry
/// to process when doing quick skipping of preprocessor blocks. /// to process when doing quick skipping of preprocessor blocks.
const char* CurPPCondPtr; const unsigned char* CurPPCondPtr;
/// MySpellingMgr - Reference to the spelling manager used to get spellings /// MySpellingMgr - Reference to the spelling manager used to get spellings
/// for the source file indicated by \c FileID. /// for the source file indicated by \c FileID.
...@@ -64,7 +64,8 @@ protected: ...@@ -64,7 +64,8 @@ protected:
friend class PTHManager; friend class PTHManager;
/// Create a PTHLexer for the specified token stream. /// Create a PTHLexer for the specified token stream.
PTHLexer(Preprocessor& pp, FileID FID, const char *D, const char* ppcond, PTHLexer(Preprocessor& pp, FileID FID, const unsigned char *D,
const unsigned char* ppcond,
PTHSpellingSearch& mySpellingSrch, PTHManager &PM); PTHSpellingSearch& mySpellingSrch, PTHManager &PM);
public: public:
...@@ -87,7 +88,7 @@ public: ...@@ -87,7 +88,7 @@ public:
// whether or not we are at a token with kind tok::eof or tok::l_paren. // whether or not we are at a token with kind tok::eof or tok::l_paren.
// Just read the first byte from the current token pointer to determine // Just read the first byte from the current token pointer to determine
// its kind. // its kind.
tok::TokenKind x = (tok::TokenKind) (unsigned char) *CurPtr; tok::TokenKind x = (tok::TokenKind)*CurPtr;
return x == tok::eof ? 2 : x == tok::l_paren; return x == tok::eof ? 2 : x == tok::l_paren;
} }
......
...@@ -34,11 +34,11 @@ class PTHManager; ...@@ -34,11 +34,11 @@ class PTHManager;
class PTHSpellingSearch { class PTHSpellingSearch {
PTHManager& PTHMgr; PTHManager& PTHMgr;
const char* const TableBeg; const unsigned char* const TableBeg;
const char* const TableEnd; const unsigned char* const TableEnd;
const unsigned NumSpellings; const unsigned NumSpellings;
const char* LinearItr; const unsigned char* LinearItr;
public: public:
enum { SpellingEntrySize = 4*2 }; enum { SpellingEntrySize = 4*2 };
...@@ -46,7 +46,8 @@ public: ...@@ -46,7 +46,8 @@ public:
unsigned getSpellingBinarySearch(unsigned fpos, const char *&Buffer); unsigned getSpellingBinarySearch(unsigned fpos, const char *&Buffer);
unsigned getSpellingLinearSearch(unsigned fpos, const char *&Buffer); unsigned getSpellingLinearSearch(unsigned fpos, const char *&Buffer);
PTHSpellingSearch(PTHManager& pm, unsigned numSpellings, const char* tableBeg) PTHSpellingSearch(PTHManager& pm, unsigned numSpellings,
const unsigned char* tableBeg)
: PTHMgr(pm), : PTHMgr(pm),
TableBeg(tableBeg), TableBeg(tableBeg),
TableEnd(tableBeg + numSpellings*SpellingEntrySize), TableEnd(tableBeg + numSpellings*SpellingEntrySize),
...@@ -78,11 +79,11 @@ class PTHManager : public IdentifierInfoLookup { ...@@ -78,11 +79,11 @@ class PTHManager : public IdentifierInfoLookup {
/// IdDataTable - Array representing the mapping from persistent IDs to the /// IdDataTable - Array representing the mapping from persistent IDs to the
/// data offset within the PTH file containing the information to /// data offset within the PTH file containing the information to
/// reconsitute an IdentifierInfo. /// reconsitute an IdentifierInfo.
const char* const IdDataTable; const unsigned char* const IdDataTable;
/// SortedIdTable - Array ordering persistent identifier IDs by the lexical /// SortedIdTable - Array ordering persistent identifier IDs by the lexical
/// order of their corresponding strings. This is used by get(). /// order of their corresponding strings. This is used by get().
const char* const SortedIdTable; const unsigned char* const SortedIdTable;
/// NumIds - The number of identifiers in the PTH file. /// NumIds - The number of identifiers in the PTH file.
const unsigned NumIds; const unsigned NumIds;
...@@ -94,8 +95,8 @@ class PTHManager : public IdentifierInfoLookup { ...@@ -94,8 +95,8 @@ class PTHManager : public IdentifierInfoLookup {
/// This constructor is intended to only be called by the static 'Create' /// This constructor is intended to only be called by the static 'Create'
/// method. /// method.
PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
const char* idDataTable, IdentifierInfo** perIDCache, const unsigned char* idDataTable, IdentifierInfo** perIDCache,
const char* sortedIdTable, unsigned numIds); const unsigned char* sortedIdTable, unsigned numIds);
// Do not implement. // Do not implement.
PTHManager(); PTHManager();
......
...@@ -31,24 +31,43 @@ using namespace clang; ...@@ -31,24 +31,43 @@ using namespace clang;
// Utility methods for reading from the mmap'ed PTH file. // Utility methods for reading from the mmap'ed PTH file.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
static inline uint8_t Read8(const char*& data) { static inline uint8_t Read8(const unsigned char *&Data) {
return (uint8_t) *(data++); uint8_t V = Data[0];
Data += 1;
return V;
}
static inline uint16_t Read16(const unsigned char *&Data) {
uint16_t V = ((uint16_t)Data[0] << 0) |
((uint16_t)Data[1] << 8);
Data += 2;
return V;
}
static inline uint32_t Read24(const unsigned char *&Data) {
uint32_t V = ((uint32_t)Data[0] << 0) |
((uint32_t)Data[1] << 8) |
((uint32_t)Data[2] << 16);
Data += 3;
return V;
} }
static inline uint32_t Read32(const char*& data) { static inline uint32_t Read32(const unsigned char *&Data) {
uint32_t V = (uint32_t) Read8(data); uint32_t V = ((uint32_t)Data[0] << 0) |
V |= (((uint32_t) Read8(data)) << 8); ((uint32_t)Data[1] << 8) |
V |= (((uint32_t) Read8(data)) << 16); ((uint32_t)Data[2] << 16) |
V |= (((uint32_t) Read8(data)) << 24); ((uint32_t)Data[3] << 24);
Data += 4;
return V; return V;
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// PTHLexer methods. // PTHLexer methods.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
PTHLexer::PTHLexer(Preprocessor &PP, FileID FID, const char *D, PTHLexer::PTHLexer(Preprocessor &PP, FileID FID, const unsigned char *D,
const char *ppcond, const unsigned char *ppcond,
PTHSpellingSearch &mySpellingSrch, PTHManager &PM) PTHSpellingSearch &mySpellingSrch, PTHManager &PM)
: PreprocessorLexer(&PP, FID), TokBuf(D), CurPtr(D), LastHashTokPtr(0), : PreprocessorLexer(&PP, FID), TokBuf(D), CurPtr(D), LastHashTokPtr(0),
PPCond(ppcond), CurPPCondPtr(ppcond), MySpellingSrch(mySpellingSrch), PPCond(ppcond), CurPPCondPtr(ppcond), MySpellingSrch(mySpellingSrch),
...@@ -65,7 +84,7 @@ LexNextToken: ...@@ -65,7 +84,7 @@ LexNextToken:
//===--------------------------------------==// //===--------------------------------------==//
// Shadow CurPtr into an automatic variable. // Shadow CurPtr into an automatic variable.
const unsigned char *CurPtrShadow = (const unsigned char*) CurPtr; const unsigned char *CurPtrShadow = CurPtr;
// Read in the data for the token. 14 bytes in total. // Read in the data for the token. 14 bytes in total.
tok::TokenKind k = (tok::TokenKind) CurPtrShadow[0]; tok::TokenKind k = (tok::TokenKind) CurPtrShadow[0];
...@@ -83,7 +102,7 @@ LexNextToken: ...@@ -83,7 +102,7 @@ LexNextToken:
uint32_t Len = ((uint32_t) CurPtrShadow[9]) uint32_t Len = ((uint32_t) CurPtrShadow[9])
| (((uint32_t) CurPtrShadow[10]) << 8); | (((uint32_t) CurPtrShadow[10]) << 8);
CurPtr = (const char*) (CurPtrShadow + DISK_TOKEN_SIZE); CurPtr = CurPtrShadow + DISK_TOKEN_SIZE;
//===--------------------------------------==// //===--------------------------------------==//
// Construct the token itself. // Construct the token itself.
...@@ -168,7 +187,7 @@ void PTHLexer::DiscardToEndOfLine() { ...@@ -168,7 +187,7 @@ void PTHLexer::DiscardToEndOfLine() {
// Skip tokens by only peeking at their token kind and the flags. // Skip tokens by only peeking at their token kind and the flags.
// We don't need to actually reconstruct full tokens from the token buffer. // We don't need to actually reconstruct full tokens from the token buffer.
// This saves some copies and it also reduces IdentifierInfo* lookup. // This saves some copies and it also reduces IdentifierInfo* lookup.
const char* p = CurPtr; const unsigned char* p = CurPtr;
while (1) { while (1) {
// Read the token kind. Are we at the end of the file? // Read the token kind. Are we at the end of the file?
tok::TokenKind x = (tok::TokenKind) (uint8_t) *p; tok::TokenKind x = (tok::TokenKind) (uint8_t) *p;
...@@ -190,7 +209,7 @@ bool PTHLexer::SkipBlock() { ...@@ -190,7 +209,7 @@ bool PTHLexer::SkipBlock() {
assert(CurPPCondPtr && "No cached PP conditional information."); assert(CurPPCondPtr && "No cached PP conditional information.");
assert(LastHashTokPtr && "No known '#' token."); assert(LastHashTokPtr && "No known '#' token.");
const char* HashEntryI = 0; const unsigned char* HashEntryI = 0;
uint32_t Offset; uint32_t Offset;
uint32_t TableIdx; uint32_t TableIdx;
...@@ -212,11 +231,12 @@ bool PTHLexer::SkipBlock() { ...@@ -212,11 +231,12 @@ bool PTHLexer::SkipBlock() {
// In the side-table we are still at an entry for a '#' token that // In the side-table we are still at an entry for a '#' token that
// is earlier than the last one we saw. Check if the location we would // is earlier than the last one we saw. Check if the location we would
// stride gets us closer. // stride gets us closer.
const char* NextPPCondPtr = PPCond + TableIdx*(sizeof(uint32_t)*2); const unsigned char* NextPPCondPtr =
PPCond + TableIdx*(sizeof(uint32_t)*2);
assert(NextPPCondPtr >= CurPPCondPtr); assert(NextPPCondPtr >= CurPPCondPtr);
// Read where we should jump to. // Read where we should jump to.
uint32_t TmpOffset = Read32(NextPPCondPtr); uint32_t TmpOffset = Read32(NextPPCondPtr);
const char* HashEntryJ = TokBuf + TmpOffset; const unsigned char* HashEntryJ = TokBuf + TmpOffset;
if (HashEntryJ <= LastHashTokPtr) { if (HashEntryJ <= LastHashTokPtr) {
// Jump directly to the next entry in the side table. // Jump directly to the next entry in the side table.
...@@ -232,7 +252,7 @@ bool PTHLexer::SkipBlock() { ...@@ -232,7 +252,7 @@ bool PTHLexer::SkipBlock() {
assert(TableIdx && "No jumping from #endifs."); assert(TableIdx && "No jumping from #endifs.");
// Update our side-table iterator. // Update our side-table iterator.
const char* NextPPCondPtr = PPCond + TableIdx*(sizeof(uint32_t)*2); const unsigned char* NextPPCondPtr = PPCond + TableIdx*(sizeof(uint32_t)*2);
assert(NextPPCondPtr >= CurPPCondPtr); assert(NextPPCondPtr >= CurPPCondPtr);
CurPPCondPtr = NextPPCondPtr; CurPPCondPtr = NextPPCondPtr;
...@@ -272,7 +292,7 @@ bool PTHLexer::SkipBlock() { ...@@ -272,7 +292,7 @@ bool PTHLexer::SkipBlock() {
LastHashTokPtr = CurPtr; LastHashTokPtr = CurPtr;
// Skip the '#' token. // Skip the '#' token.
assert(((tok::TokenKind) (unsigned char) *CurPtr) == tok::hash); assert(((tok::TokenKind)*CurPtr) == tok::hash);
CurPtr += DISK_TOKEN_SIZE; CurPtr += DISK_TOKEN_SIZE;
// Did we reach a #endif? If so, go ahead and consume that token as well. // Did we reach a #endif? If so, go ahead and consume that token as well.
...@@ -287,7 +307,7 @@ SourceLocation PTHLexer::getSourceLocation() { ...@@ -287,7 +307,7 @@ SourceLocation PTHLexer::getSourceLocation() {
// handling a #included file. Just read the necessary data from the token // handling a #included file. Just read the necessary data from the token
// data buffer to construct the SourceLocation object. // data buffer to construct the SourceLocation object.
// NOTE: This is a virtual function; hence it is defined out-of-line. // NOTE: This is a virtual function; hence it is defined out-of-line.
const char* p = CurPtr + (1 + 1 + 3); const unsigned char* p = CurPtr + (1 + 1 + 3);
uint32_t offset = uint32_t offset =
((uint32_t) ((uint8_t) p[0])) ((uint32_t) ((uint8_t) p[0]))
| (((uint32_t) ((uint8_t) p[1])) << 8) | (((uint32_t) ((uint8_t) p[1])) << 8)
...@@ -318,7 +338,7 @@ unsigned PTHManager::getSpelling(SourceLocation Loc, const char *&Buffer) { ...@@ -318,7 +338,7 @@ unsigned PTHManager::getSpelling(SourceLocation Loc, const char *&Buffer) {
} }
unsigned PTHManager::getSpellingAtPTHOffset(unsigned PTHOffset, unsigned PTHManager::getSpellingAtPTHOffset(unsigned PTHOffset,
const char *& Buffer) { const char *&Buffer) {
const char* p = Buf->getBufferStart() + PTHOffset; const char* p = Buf->getBufferStart() + PTHOffset;
assert(p < Buf->getBufferEnd()); assert(p < Buf->getBufferEnd());
...@@ -334,7 +354,7 @@ unsigned PTHManager::getSpellingAtPTHOffset(unsigned PTHOffset, ...@@ -334,7 +354,7 @@ unsigned PTHManager::getSpellingAtPTHOffset(unsigned PTHOffset,
unsigned PTHSpellingSearch::getSpellingLinearSearch(unsigned fpos, unsigned PTHSpellingSearch::getSpellingLinearSearch(unsigned fpos,
const char *&Buffer) { const char *&Buffer) {
const char* p = LinearItr; const unsigned char* p = LinearItr;
unsigned len = 0; unsigned len = 0;
if (p == TableEnd) if (p == TableEnd)
...@@ -372,8 +392,9 @@ unsigned PTHSpellingSearch::getSpellingLinearSearch(unsigned fpos, ...@@ -372,8 +392,9 @@ unsigned PTHSpellingSearch::getSpellingLinearSearch(unsigned fpos,
return len; return len;
} }
unsigned PTHSpellingSearch::getSpellingBinarySearch(unsigned fpos, unsigned PTHSpellingSearch::getSpellingBinarySearch(unsigned fpos,
const char *& Buffer) { const char *&Buffer) {
assert((TableEnd - TableBeg) % SpellingEntrySize == 0); assert((TableEnd - TableBeg) % SpellingEntrySize == 0);
...@@ -383,12 +404,12 @@ unsigned PTHSpellingSearch::getSpellingBinarySearch(unsigned fpos, ...@@ -383,12 +404,12 @@ unsigned PTHSpellingSearch::getSpellingBinarySearch(unsigned fpos,
assert(TableEnd > TableBeg); assert(TableEnd > TableBeg);
unsigned min = 0; unsigned min = 0;
const char* tb = TableBeg; const unsigned char* tb = TableBeg;
unsigned max = NumSpellings; unsigned max = NumSpellings;
do { do {
unsigned i = (max - min) / 2 + min; unsigned i = (max - min) / 2 + min;
const char* p = tb + (i * SpellingEntrySize); const unsigned char* p = tb + (i * SpellingEntrySize);
uint32_t TokOffset = uint32_t TokOffset =
((uint32_t) ((uint8_t) p[0])) ((uint32_t) ((uint8_t) p[0]))
...@@ -487,12 +508,12 @@ public: ...@@ -487,12 +508,12 @@ public:
return FileMap.GetOrCreateValue(s, s+size).getValue(); return FileMap.GetOrCreateValue(s, s+size).getValue();
} }
void ReadTable(const char* D) { void ReadTable(const unsigned char* D) {
uint32_t N = Read32(D); // Read the length of the table. uint32_t N = Read32(D); // Read the length of the table.
for ( ; N > 0; --N) { // The rest of the data is the table itself. for ( ; N > 0; --N) { // The rest of the data is the table itself.
uint32_t len = Read32(D); uint32_t len = Read32(D);
const char* s = D; const char* s = (const char *)D;
D += len; D += len;
uint32_t TokenOff = Read32(D); uint32_t TokenOff = Read32(D);
...@@ -511,8 +532,9 @@ public: ...@@ -511,8 +532,9 @@ public:
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
PTHManager::PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, PTHManager::PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
const char* idDataTable, IdentifierInfo** perIDCache, const unsigned char* idDataTable,
const char* sortedIdTable, unsigned numIds) IdentifierInfo** perIDCache,
const unsigned char* sortedIdTable, unsigned numIds)
: Buf(buf), PerIDCache(perIDCache), FileLookup(fileLookup), : Buf(buf), PerIDCache(perIDCache), FileLookup(fileLookup),
IdDataTable(idDataTable), SortedIdTable(sortedIdTable), IdDataTable(idDataTable), SortedIdTable(sortedIdTable),
NumIds(numIds), PP(0) {} NumIds(numIds), PP(0) {}
...@@ -534,8 +556,8 @@ PTHManager* PTHManager::Create(const std::string& file) { ...@@ -534,8 +556,8 @@ PTHManager* PTHManager::Create(const std::string& file) {
// Get the buffer ranges and check if there are at least three 32-bit // Get the buffer ranges and check if there are at least three 32-bit
// words at the end of the file. // words at the end of the file.
const char* BufBeg = File->getBufferStart(); const unsigned char* BufBeg = (unsigned char*)File->getBufferStart();
const char* BufEnd = File->getBufferEnd(); const unsigned char* BufEnd = (unsigned char*)File->getBufferEnd();
if(!(BufEnd > BufBeg + sizeof(uint32_t)*3)) { if(!(BufEnd > BufBeg + sizeof(uint32_t)*3)) {
assert(false && "Invalid PTH file."); assert(false && "Invalid PTH file.");
...@@ -546,12 +568,12 @@ PTHManager* PTHManager::Create(const std::string& file) { ...@@ -546,12 +568,12 @@ PTHManager* PTHManager::Create(const std::string& file) {
// This table contains the offset of the file lookup table, the // This table contains the offset of the file lookup table, the
// persistent ID -> identifer data table. // persistent ID -> identifer data table.
// FIXME: We should just embed this offset in the PTH file. // FIXME: We should just embed this offset in the PTH file.
const char* EndTable = BufEnd - sizeof(uint32_t)*4; const unsigned char* EndTable = BufEnd - sizeof(uint32_t)*4;
// Construct the file lookup table. This will be used for mapping from // Construct the file lookup table. This will be used for mapping from
// FileEntry*'s to cached tokens. // FileEntry*'s to cached tokens.
const char* FileTableOffset = EndTable + sizeof(uint32_t)*3; const unsigned char* FileTableOffset = EndTable + sizeof(uint32_t)*3;
const char* FileTable = BufBeg + Read32(FileTableOffset); const unsigned char* FileTable = BufBeg + Read32(FileTableOffset);
if (!(FileTable > BufBeg && FileTable < BufEnd)) { if (!(FileTable > BufBeg && FileTable < BufEnd)) {
assert(false && "Invalid PTH file."); assert(false && "Invalid PTH file.");
...@@ -563,16 +585,16 @@ PTHManager* PTHManager::Create(const std::string& file) { ...@@ -563,16 +585,16 @@ PTHManager* PTHManager::Create(const std::string& file) {
// Get the location of the table mapping from persistent ids to the // Get the location of the table mapping from persistent ids to the
// data needed to reconstruct identifiers. // data needed to reconstruct identifiers.
const char* IDTableOffset = EndTable + sizeof(uint32_t)*1; const unsigned char* IDTableOffset = EndTable + sizeof(uint32_t)*1;
const char* IData = BufBeg + Read32(IDTableOffset); const unsigned char* IData = BufBeg + Read32(IDTableOffset);
if (!(IData > BufBeg && IData < BufEnd)) { if (!(IData > BufBeg && IData < BufEnd)) {
assert(false && "Invalid PTH file."); assert(false && "Invalid PTH file.");
return 0; // FIXME: Proper error diagnostic? return 0; // FIXME: Proper error diagnostic?
} }
// Get the location of the lexigraphically-sorted table of persistent IDs. // Get the location of the lexigraphically-sorted table of persistent IDs.
const char* SortedIdTableOffset = EndTable + sizeof(uint32_t)*2; const unsigned char* SortedIdTableOffset = EndTable + sizeof(uint32_t)*2;
const char* SortedIdTable = BufBeg + Read32(SortedIdTableOffset); const unsigned char* SortedIdTable = BufBeg + Read32(SortedIdTableOffset);
if (!(SortedIdTable > BufBeg && SortedIdTable < BufEnd)) { if (!(SortedIdTable > BufBeg && SortedIdTable < BufEnd)) {
assert(false && "Invalid PTH file."); assert(false && "Invalid PTH file.");
return 0; // FIXME: Proper error diagnostic? return 0; // FIXME: Proper error diagnostic?
...@@ -585,7 +607,7 @@ PTHManager* PTHManager::Create(const std::string& file) { ...@@ -585,7 +607,7 @@ PTHManager* PTHManager::Create(const std::string& file) {
// so that we in the best case only zero out memory once when the OS returns // so that we in the best case only zero out memory once when the OS returns
// us new pages. // us new pages.
IdentifierInfo** PerIDCache = IdentifierInfo** PerIDCache =
(IdentifierInfo**) calloc(NumIds, sizeof(*PerIDCache)); (IdentifierInfo**)calloc(NumIds, sizeof(*PerIDCache));
if (!PerIDCache) { if (!PerIDCache) {
assert(false && "Could not allocate Persistent ID cache."); assert(false && "Could not allocate Persistent ID cache.");
...@@ -604,13 +626,14 @@ IdentifierInfo* PTHManager::GetIdentifierInfo(unsigned persistentID) { ...@@ -604,13 +626,14 @@ IdentifierInfo* PTHManager::GetIdentifierInfo(unsigned persistentID) {
if (II) return II; if (II) return II;
// Look in the PTH file for the string data for the IdentifierInfo object. // Look in the PTH file for the string data for the IdentifierInfo object.
const char* TableEntry = IdDataTable + sizeof(uint32_t) * persistentID; const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*persistentID;
const char* IDData = Buf->getBufferStart() + Read32(TableEntry); const unsigned char* IDData =
assert(IDData < Buf->getBufferEnd()); (const unsigned char*)Buf->getBufferStart() + Read32(TableEntry);
assert(IDData < (const unsigned char*)Buf->getBufferEnd());
// Allocate the object. // Allocate the object.
std::pair<IdentifierInfo,const char*> *Mem = std::pair<IdentifierInfo,const unsigned char*> *Mem =
Alloc.Allocate<std::pair<IdentifierInfo,const char*> >(); Alloc.Allocate<std::pair<IdentifierInfo,const unsigned char*> >();
Mem->second = IDData; Mem->second = IDData;
II = new ((void*) Mem) IdentifierInfo(true); II = new ((void*) Mem) IdentifierInfo(true);
...@@ -627,7 +650,7 @@ IdentifierInfo* PTHManager::get(const char *NameStart, const char *NameEnd) { ...@@ -627,7 +650,7 @@ IdentifierInfo* PTHManager::get(const char *NameStart, const char *NameEnd) {
do { do {
unsigned i = (max - min) / 2 + min; unsigned i = (max - min) / 2 + min;
const char* p = SortedIdTable + (i * 4); const unsigned char* p = SortedIdTable + (i * 4);
// Read the persistentID. // Read the persistentID.
unsigned perID = unsigned perID =
...@@ -681,22 +704,22 @@ PTHLexer *PTHManager::CreateLexer(FileID FID) { ...@@ -681,22 +704,22 @@ PTHLexer *PTHManager::CreateLexer(FileID FID) {
if (!FileData.isValid()) // No tokens available. if (!FileData.isValid()) // No tokens available.
return 0; return 0;
const unsigned char *BufStart = (const unsigned char *)Buf->getBufferStart();
// Compute the offset of the token data within the buffer. // Compute the offset of the token data within the buffer.
const char* data = Buf->getBufferStart() + FileData.getTokenOffset(); const unsigned char* data = BufStart + FileData.getTokenOffset();
// Get the location of pp-conditional table. // Get the location of pp-conditional table.
const char* ppcond = Buf->getBufferStart() + FileData.getPPCondOffset(); const unsigned char* ppcond = BufStart + FileData.getPPCondOffset();
uint32_t len = Read32(ppcond); uint32_t len = Read32(ppcond);
if (len == 0) ppcond = 0; if (len == 0) ppcond = 0;
// Get the location of the spelling table. // Get the location of the spelling table.
const char* spellingTable = Buf->getBufferStart() + const unsigned char* spellingTable = BufStart + FileData.getSpellingOffset();
FileData.getSpellingOffset();
len = Read32(spellingTable); len = Read32(spellingTable);
if (len == 0) spellingTable = 0; if (len == 0) spellingTable = 0;
assert(data < Buf->getBufferEnd()); assert(data < (const unsigned char*)Buf->getBufferEnd());
// Create the SpellingSearch object for this FileID. // Create the SpellingSearch object for this FileID.
PTHSpellingSearch* ss = new PTHSpellingSearch(*this, len, spellingTable); PTHSpellingSearch* ss = new PTHSpellingSearch(*this, len, spellingTable);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment