forked from OSchip/llvm-project
finish converting the normal cases in ASTReader to use the new BitstreamCursor APIs.
llvm-svn: 172937
This commit is contained in:
parent
9976974cc6
commit
7fb3bef13e
|
@ -51,12 +51,12 @@
|
||||||
#include "llvm/Support/SaveAndRestore.h"
|
#include "llvm/Support/SaveAndRestore.h"
|
||||||
#include "llvm/Support/system_error.h"
|
#include "llvm/Support/system_error.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
using namespace clang::serialization;
|
using namespace clang::serialization;
|
||||||
using namespace clang::serialization::reader;
|
using namespace clang::serialization::reader;
|
||||||
|
using llvm::BitstreamCursor;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// PCH validator implementation
|
// PCH validator implementation
|
||||||
|
@ -661,7 +661,7 @@ ASTDeclContextNameLookupTrait::ReadData(internal_key_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ASTReader::ReadDeclContextStorage(ModuleFile &M,
|
bool ASTReader::ReadDeclContextStorage(ModuleFile &M,
|
||||||
llvm::BitstreamCursor &Cursor,
|
BitstreamCursor &Cursor,
|
||||||
const std::pair<uint64_t, uint64_t> &Offsets,
|
const std::pair<uint64_t, uint64_t> &Offsets,
|
||||||
DeclContextInfo &Info) {
|
DeclContextInfo &Info) {
|
||||||
SavedStreamPosition SavedPosition(Cursor);
|
SavedStreamPosition SavedPosition(Cursor);
|
||||||
|
@ -773,7 +773,7 @@ bool ASTReader::ParseLineTable(ModuleFile &F,
|
||||||
bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) {
|
bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) {
|
||||||
using namespace SrcMgr;
|
using namespace SrcMgr;
|
||||||
|
|
||||||
llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor;
|
BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor;
|
||||||
|
|
||||||
// Set the source-location entry cursor to the current position in
|
// Set the source-location entry cursor to the current position in
|
||||||
// the stream. This cursor will be used to read the contents of the
|
// the stream. This cursor will be used to read the contents of the
|
||||||
|
@ -870,7 +870,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
|
||||||
|
|
||||||
ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second;
|
ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second;
|
||||||
F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]);
|
F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]);
|
||||||
llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
|
BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
|
||||||
unsigned BaseOffset = F->SLocEntryBaseOffset;
|
unsigned BaseOffset = F->SLocEntryBaseOffset;
|
||||||
|
|
||||||
++NumSLocEntriesRead;
|
++NumSLocEntriesRead;
|
||||||
|
@ -1029,8 +1029,7 @@ SourceLocation ASTReader::getImportLocation(ModuleFile *F) {
|
||||||
/// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
|
/// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
|
||||||
/// specified cursor. Read the abbreviations that are at the top of the block
|
/// specified cursor. Read the abbreviations that are at the top of the block
|
||||||
/// and then leave the cursor pointing into the block.
|
/// and then leave the cursor pointing into the block.
|
||||||
bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor,
|
bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) {
|
||||||
unsigned BlockID) {
|
|
||||||
if (Cursor.EnterSubBlock(BlockID)) {
|
if (Cursor.EnterSubBlock(BlockID)) {
|
||||||
Error("malformed block record in AST file");
|
Error("malformed block record in AST file");
|
||||||
return Failure;
|
return Failure;
|
||||||
|
@ -1051,7 +1050,7 @@ bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor,
|
||||||
|
|
||||||
void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset,
|
void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset,
|
||||||
MacroInfo *Hint) {
|
MacroInfo *Hint) {
|
||||||
llvm::BitstreamCursor &Stream = F.MacroCursor;
|
BitstreamCursor &Stream = F.MacroCursor;
|
||||||
|
|
||||||
// Keep track of where we are in the stream, then jump back there
|
// Keep track of where we are in the stream, then jump back there
|
||||||
// after reading this macro.
|
// after reading this macro.
|
||||||
|
@ -1084,7 +1083,7 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset,
|
||||||
// Advance to the next record, but if we get to the end of the block, don't
|
// Advance to the next record, but if we get to the end of the block, don't
|
||||||
// pop it (removing all the abbreviations from the cursor) since we want to
|
// pop it (removing all the abbreviations from the cursor) since we want to
|
||||||
// be able to reseek within the block and read entries.
|
// be able to reseek within the block and read entries.
|
||||||
unsigned Flags = llvm::BitstreamCursor::AF_DontPopBlockAtEnd;
|
unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd;
|
||||||
llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags);
|
llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags);
|
||||||
|
|
||||||
switch (Entry.Kind) {
|
switch (Entry.Kind) {
|
||||||
|
@ -1339,13 +1338,13 @@ void ASTReader::ReadDefinedMacros() {
|
||||||
|
|
||||||
for (ModuleReverseIterator I = ModuleMgr.rbegin(),
|
for (ModuleReverseIterator I = ModuleMgr.rbegin(),
|
||||||
E = ModuleMgr.rend(); I != E; ++I) {
|
E = ModuleMgr.rend(); I != E; ++I) {
|
||||||
llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor;
|
BitstreamCursor &MacroCursor = (*I)->MacroCursor;
|
||||||
|
|
||||||
// If there was no preprocessor block, skip this file.
|
// If there was no preprocessor block, skip this file.
|
||||||
if (!MacroCursor.getBitStreamReader())
|
if (!MacroCursor.getBitStreamReader())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
llvm::BitstreamCursor Cursor = MacroCursor;
|
BitstreamCursor Cursor = MacroCursor;
|
||||||
Cursor.JumpToBit((*I)->MacroStartOffset);
|
Cursor.JumpToBit((*I)->MacroStartOffset);
|
||||||
|
|
||||||
RecordData Record;
|
RecordData Record;
|
||||||
|
@ -1464,7 +1463,7 @@ ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
|
||||||
return F.InputFilesLoaded[ID-1];
|
return F.InputFilesLoaded[ID-1];
|
||||||
|
|
||||||
// Go find this input file.
|
// Go find this input file.
|
||||||
llvm::BitstreamCursor &Cursor = F.InputFilesCursor;
|
BitstreamCursor &Cursor = F.InputFilesCursor;
|
||||||
SavedStreamPosition SavedPosition(Cursor);
|
SavedStreamPosition SavedPosition(Cursor);
|
||||||
Cursor.JumpToBit(F.InputFileOffsets[ID-1]);
|
Cursor.JumpToBit(F.InputFileOffsets[ID-1]);
|
||||||
|
|
||||||
|
@ -1608,7 +1607,7 @@ ASTReader::ASTReadResult
|
||||||
ASTReader::ReadControlBlock(ModuleFile &F,
|
ASTReader::ReadControlBlock(ModuleFile &F,
|
||||||
SmallVectorImpl<ImportedModule> &Loaded,
|
SmallVectorImpl<ImportedModule> &Loaded,
|
||||||
unsigned ClientLoadCapabilities) {
|
unsigned ClientLoadCapabilities) {
|
||||||
llvm::BitstreamCursor &Stream = F.Stream;
|
BitstreamCursor &Stream = F.Stream;
|
||||||
|
|
||||||
if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
||||||
Error("malformed block record in AST file");
|
Error("malformed block record in AST file");
|
||||||
|
@ -1801,7 +1800,7 @@ ASTReader::ReadControlBlock(ModuleFile &F,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ASTReader::ReadASTBlock(ModuleFile &F) {
|
bool ASTReader::ReadASTBlock(ModuleFile &F) {
|
||||||
llvm::BitstreamCursor &Stream = F.Stream;
|
BitstreamCursor &Stream = F.Stream;
|
||||||
|
|
||||||
if (Stream.EnterSubBlock(AST_BLOCK_ID)) {
|
if (Stream.EnterSubBlock(AST_BLOCK_ID)) {
|
||||||
Error("malformed block record in AST file");
|
Error("malformed block record in AST file");
|
||||||
|
@ -1888,7 +1887,7 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COMMENTS_BLOCK_ID: {
|
case COMMENTS_BLOCK_ID: {
|
||||||
llvm::BitstreamCursor C = Stream;
|
BitstreamCursor C = Stream;
|
||||||
if (Stream.SkipBlock() ||
|
if (Stream.SkipBlock() ||
|
||||||
ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) {
|
ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) {
|
||||||
Error("malformed comments block in AST file");
|
Error("malformed comments block in AST file");
|
||||||
|
@ -2825,7 +2824,7 @@ ASTReader::ReadASTCore(StringRef FileName,
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleFile &F = *M;
|
ModuleFile &F = *M;
|
||||||
llvm::BitstreamCursor &Stream = F.Stream;
|
BitstreamCursor &Stream = F.Stream;
|
||||||
Stream.init(F.StreamFile);
|
Stream.init(F.StreamFile);
|
||||||
F.SizeInBits = F.Buffer->getBufferSize() * 8;
|
F.SizeInBits = F.Buffer->getBufferSize() * 8;
|
||||||
|
|
||||||
|
@ -3043,6 +3042,36 @@ void ASTReader::finalizeForWriting() {
|
||||||
HiddenNamesMap.clear();
|
HiddenNamesMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// SkipCursorToControlBlock - Given a cursor at the start of an AST file, scan
|
||||||
|
/// ahead and drop the cursor into the start of the CONTROL_BLOCK, returning
|
||||||
|
/// false on success and true on failure.
|
||||||
|
static bool SkipCursorToControlBlock(BitstreamCursor &Cursor) {
|
||||||
|
while (1) {
|
||||||
|
llvm::BitstreamEntry Entry = Cursor.advance();
|
||||||
|
switch (Entry.Kind) {
|
||||||
|
case llvm::BitstreamEntry::Error:
|
||||||
|
case llvm::BitstreamEntry::EndBlock:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case llvm::BitstreamEntry::Record:
|
||||||
|
// Ignore top-level records.
|
||||||
|
Cursor.skipRecord(Entry.ID);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case llvm::BitstreamEntry::SubBlock:
|
||||||
|
if (Entry.ID == CONTROL_BLOCK_ID) {
|
||||||
|
if (Cursor.EnterSubBlock(CONTROL_BLOCK_ID))
|
||||||
|
return true;
|
||||||
|
// Found it!
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Cursor.SkipBlock())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Retrieve the name of the original source file name
|
/// \brief Retrieve the name of the original source file name
|
||||||
/// directly from the AST file, without actually loading the AST
|
/// directly from the AST file, without actually loading the AST
|
||||||
/// file.
|
/// file.
|
||||||
|
@ -3060,7 +3089,7 @@ std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName,
|
||||||
|
|
||||||
// Initialize the stream
|
// Initialize the stream
|
||||||
llvm::BitstreamReader StreamFile;
|
llvm::BitstreamReader StreamFile;
|
||||||
llvm::BitstreamCursor Stream;
|
BitstreamCursor Stream;
|
||||||
StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
|
StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
|
||||||
(const unsigned char *)Buffer->getBufferEnd());
|
(const unsigned char *)Buffer->getBufferEnd());
|
||||||
Stream.init(StreamFile);
|
Stream.init(StreamFile);
|
||||||
|
@ -3073,45 +3102,17 @@ std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName,
|
||||||
Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName;
|
Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName;
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan for the CONTROL_BLOCK_ID block.
|
// Scan for the CONTROL_BLOCK_ID block.
|
||||||
llvm::BitstreamEntry Entry;
|
if (SkipCursorToControlBlock(Stream)) {
|
||||||
RecordData Record;
|
Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
|
||||||
|
return std::string();
|
||||||
bool FoundControlBlock = false;
|
|
||||||
while (!FoundControlBlock) {
|
|
||||||
Entry = Stream.advance();
|
|
||||||
switch (Entry.Kind) {
|
|
||||||
case llvm::BitstreamEntry::Error:
|
|
||||||
case llvm::BitstreamEntry::EndBlock:
|
|
||||||
Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName;
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
case llvm::BitstreamEntry::Record:
|
|
||||||
// Ignore top-level records.
|
|
||||||
Stream.skipRecord(Entry.ID);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case llvm::BitstreamEntry::SubBlock:
|
|
||||||
if (Entry.ID == CONTROL_BLOCK_ID) {
|
|
||||||
if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
|
||||||
Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
FoundControlBlock = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Stream.SkipBlock()) {
|
|
||||||
Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName;
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan for ORIGINAL_FILE.
|
// Scan for ORIGINAL_FILE inside the control block.
|
||||||
|
RecordData Record;
|
||||||
while (1) {
|
while (1) {
|
||||||
Entry = Stream.advanceSkippingSubblocks();
|
llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
|
||||||
if (Entry.Kind == llvm::BitstreamEntry::EndBlock)
|
if (Entry.Kind == llvm::BitstreamEntry::EndBlock)
|
||||||
return std::string();
|
return std::string();
|
||||||
|
|
||||||
|
@ -3178,7 +3179,7 @@ bool ASTReader::readASTFileControlBlock(StringRef Filename,
|
||||||
|
|
||||||
// Initialize the stream
|
// Initialize the stream
|
||||||
llvm::BitstreamReader StreamFile;
|
llvm::BitstreamReader StreamFile;
|
||||||
llvm::BitstreamCursor Stream;
|
BitstreamCursor Stream;
|
||||||
StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
|
StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
|
||||||
(const unsigned char *)Buffer->getBufferEnd());
|
(const unsigned char *)Buffer->getBufferEnd());
|
||||||
Stream.init(StreamFile);
|
Stream.init(StreamFile);
|
||||||
|
@ -3191,105 +3192,74 @@ bool ASTReader::readASTFileControlBlock(StringRef Filename,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan for the CONTROL_BLOCK_ID block.
|
||||||
|
if (SkipCursorToControlBlock(Stream))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Scan for ORIGINAL_FILE inside the control block.
|
||||||
RecordData Record;
|
RecordData Record;
|
||||||
bool InControlBlock = false;
|
while (1) {
|
||||||
while (!Stream.AtEndOfStream()) {
|
llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
|
||||||
unsigned Code = Stream.ReadCode();
|
if (Entry.Kind == llvm::BitstreamEntry::EndBlock)
|
||||||
|
return false;
|
||||||
if (Code == llvm::bitc::ENTER_SUBBLOCK) {
|
|
||||||
unsigned BlockID = Stream.ReadSubBlockID();
|
if (Entry.Kind != llvm::BitstreamEntry::Record)
|
||||||
|
return true;
|
||||||
// We only know the control subblock ID.
|
|
||||||
switch (BlockID) {
|
|
||||||
case CONTROL_BLOCK_ID:
|
|
||||||
if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
InControlBlock = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (Stream.SkipBlock())
|
|
||||||
return true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Code == llvm::bitc::END_BLOCK) {
|
|
||||||
if (Stream.ReadBlockEnd()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
InControlBlock = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Code == llvm::bitc::DEFINE_ABBREV) {
|
|
||||||
Stream.ReadAbbrevRecord();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Record.clear();
|
Record.clear();
|
||||||
const char *BlobStart = 0;
|
const char *BlobStart = 0;
|
||||||
unsigned BlobLen = 0;
|
unsigned BlobLen = 0;
|
||||||
unsigned RecCode = Stream.ReadRecord(Code, Record, BlobStart, BlobLen);
|
unsigned RecCode = Stream.ReadRecord(Entry.ID, Record, BlobStart, BlobLen);
|
||||||
if (InControlBlock) {
|
switch ((ControlRecordTypes)RecCode) {
|
||||||
switch ((ControlRecordTypes)RecCode) {
|
case METADATA: {
|
||||||
case METADATA: {
|
if (Record[0] != VERSION_MAJOR)
|
||||||
if (Record[0] != VERSION_MAJOR) {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string &CurBranch = getClangFullRepositoryVersion();
|
const std::string &CurBranch = getClangFullRepositoryVersion();
|
||||||
StringRef ASTBranch(BlobStart, BlobLen);
|
StringRef ASTBranch(BlobStart, BlobLen);
|
||||||
if (StringRef(CurBranch) != ASTBranch)
|
if (StringRef(CurBranch) != ASTBranch)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LANGUAGE_OPTIONS:
|
case LANGUAGE_OPTIONS:
|
||||||
if (ParseLanguageOptions(Record, false, Listener))
|
if (ParseLanguageOptions(Record, false, Listener))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_OPTIONS:
|
case TARGET_OPTIONS:
|
||||||
if (ParseTargetOptions(Record, false, Listener))
|
if (ParseTargetOptions(Record, false, Listener))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIAGNOSTIC_OPTIONS:
|
case DIAGNOSTIC_OPTIONS:
|
||||||
if (ParseDiagnosticOptions(Record, false, Listener))
|
if (ParseDiagnosticOptions(Record, false, Listener))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FILE_SYSTEM_OPTIONS:
|
case FILE_SYSTEM_OPTIONS:
|
||||||
if (ParseFileSystemOptions(Record, false, Listener))
|
if (ParseFileSystemOptions(Record, false, Listener))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HEADER_SEARCH_OPTIONS:
|
case HEADER_SEARCH_OPTIONS:
|
||||||
if (ParseHeaderSearchOptions(Record, false, Listener))
|
if (ParseHeaderSearchOptions(Record, false, Listener))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PREPROCESSOR_OPTIONS: {
|
case PREPROCESSOR_OPTIONS: {
|
||||||
std::string IgnoredSuggestedPredefines;
|
std::string IgnoredSuggestedPredefines;
|
||||||
if (ParsePreprocessorOptions(Record, false, Listener,
|
if (ParsePreprocessorOptions(Record, false, Listener,
|
||||||
IgnoredSuggestedPredefines))
|
IgnoredSuggestedPredefines))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// No other validation to perform.
|
// No other validation to perform.
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3314,35 +3284,25 @@ bool ASTReader::ReadSubmoduleBlock(ModuleFile &F) {
|
||||||
Module *CurrentModule = 0;
|
Module *CurrentModule = 0;
|
||||||
RecordData Record;
|
RecordData Record;
|
||||||
while (true) {
|
while (true) {
|
||||||
unsigned Code = F.Stream.ReadCode();
|
llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks();
|
||||||
if (Code == llvm::bitc::END_BLOCK) {
|
|
||||||
if (F.Stream.ReadBlockEnd()) {
|
switch (Entry.Kind) {
|
||||||
Error("error at end of submodule block in AST file");
|
case llvm::BitstreamEntry::SubBlock: // Handled for us already.
|
||||||
return true;
|
case llvm::BitstreamEntry::Error:
|
||||||
}
|
Error("malformed block record in AST file");
|
||||||
|
return true;
|
||||||
|
case llvm::BitstreamEntry::EndBlock:
|
||||||
return false;
|
return false;
|
||||||
|
case llvm::BitstreamEntry::Record:
|
||||||
|
// The interesting case.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Code == llvm::bitc::ENTER_SUBBLOCK) {
|
|
||||||
// No known subblocks, always skip them.
|
|
||||||
F.Stream.ReadSubBlockID();
|
|
||||||
if (F.Stream.SkipBlock()) {
|
|
||||||
Error("malformed block record in AST file");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Code == llvm::bitc::DEFINE_ABBREV) {
|
|
||||||
F.Stream.ReadAbbrevRecord();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read a record.
|
// Read a record.
|
||||||
const char *BlobStart;
|
const char *BlobStart;
|
||||||
unsigned BlobLen;
|
unsigned BlobLen;
|
||||||
Record.clear();
|
Record.clear();
|
||||||
switch (F.Stream.ReadRecord(Code, Record, BlobStart, BlobLen)) {
|
switch (F.Stream.ReadRecord(Entry.ID, Record, BlobStart, BlobLen)) {
|
||||||
default: // Default behavior: ignore.
|
default: // Default behavior: ignore.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -3785,31 +3745,19 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
|
||||||
unsigned LocalIndex = PPInfo.second;
|
unsigned LocalIndex = PPInfo.second;
|
||||||
const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
|
const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex];
|
||||||
|
|
||||||
SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor);
|
|
||||||
M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset);
|
|
||||||
|
|
||||||
unsigned Code = M.PreprocessorDetailCursor.ReadCode();
|
|
||||||
switch (Code) {
|
|
||||||
case llvm::bitc::END_BLOCK:
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case llvm::bitc::ENTER_SUBBLOCK:
|
|
||||||
Error("unexpected subblock record in preprocessor detail block");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case llvm::bitc::DEFINE_ABBREV:
|
|
||||||
Error("unexpected abbrevation record in preprocessor detail block");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PP.getPreprocessingRecord()) {
|
if (!PP.getPreprocessingRecord()) {
|
||||||
Error("no preprocessing record");
|
Error("no preprocessing record");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor);
|
||||||
|
M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset);
|
||||||
|
|
||||||
|
llvm::BitstreamEntry Entry =
|
||||||
|
M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd);
|
||||||
|
if (Entry.Kind != llvm::BitstreamEntry::Record)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Read the record.
|
// Read the record.
|
||||||
SourceRange Range(ReadSourceLocation(M, PPOffs.Begin),
|
SourceRange Range(ReadSourceLocation(M, PPOffs.Begin),
|
||||||
ReadSourceLocation(M, PPOffs.End));
|
ReadSourceLocation(M, PPOffs.End));
|
||||||
|
@ -3819,7 +3767,7 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
|
||||||
RecordData Record;
|
RecordData Record;
|
||||||
PreprocessorDetailRecordTypes RecType =
|
PreprocessorDetailRecordTypes RecType =
|
||||||
(PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord(
|
(PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord(
|
||||||
Code, Record, BlobStart, BlobLen);
|
Entry.ID, Record, BlobStart, BlobLen);
|
||||||
switch (RecType) {
|
switch (RecType) {
|
||||||
case PPD_MACRO_EXPANSION: {
|
case PPD_MACRO_EXPANSION: {
|
||||||
bool isBuiltin = Record[0];
|
bool isBuiltin = Record[0];
|
||||||
|
@ -4153,7 +4101,7 @@ ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) {
|
||||||
/// IDs.
|
/// IDs.
|
||||||
QualType ASTReader::readTypeRecord(unsigned Index) {
|
QualType ASTReader::readTypeRecord(unsigned Index) {
|
||||||
RecordLocation Loc = TypeCursorForIndex(Index);
|
RecordLocation Loc = TypeCursorForIndex(Index);
|
||||||
llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
|
BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
|
||||||
|
|
||||||
// Keep track of where we are in the stream, then jump back there
|
// Keep track of where we are in the stream, then jump back there
|
||||||
// after reading this type.
|
// after reading this type.
|
||||||
|
@ -5013,7 +4961,7 @@ uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Recor
|
||||||
|
|
||||||
CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
|
CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
|
||||||
RecordLocation Loc = getLocalBitOffset(Offset);
|
RecordLocation Loc = getLocalBitOffset(Offset);
|
||||||
llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor;
|
BitstreamCursor &Cursor = Loc.F->DeclsCursor;
|
||||||
SavedStreamPosition SavedPosition(Cursor);
|
SavedStreamPosition SavedPosition(Cursor);
|
||||||
Cursor.JumpToBit(Loc.Offset);
|
Cursor.JumpToBit(Loc.Offset);
|
||||||
ReadingKindTracker ReadingKind(Read_Decl, *this);
|
ReadingKindTracker ReadingKind(Read_Decl, *this);
|
||||||
|
@ -6785,39 +6733,35 @@ void ASTReader::ClearSwitchCaseIDs() {
|
||||||
|
|
||||||
void ASTReader::ReadComments() {
|
void ASTReader::ReadComments() {
|
||||||
std::vector<RawComment *> Comments;
|
std::vector<RawComment *> Comments;
|
||||||
for (SmallVectorImpl<std::pair<llvm::BitstreamCursor,
|
for (SmallVectorImpl<std::pair<BitstreamCursor,
|
||||||
serialization::ModuleFile *> >::iterator
|
serialization::ModuleFile *> >::iterator
|
||||||
I = CommentsCursors.begin(),
|
I = CommentsCursors.begin(),
|
||||||
E = CommentsCursors.end();
|
E = CommentsCursors.end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
llvm::BitstreamCursor &Cursor = I->first;
|
BitstreamCursor &Cursor = I->first;
|
||||||
serialization::ModuleFile &F = *I->second;
|
serialization::ModuleFile &F = *I->second;
|
||||||
SavedStreamPosition SavedPosition(Cursor);
|
SavedStreamPosition SavedPosition(Cursor);
|
||||||
|
|
||||||
RecordData Record;
|
RecordData Record;
|
||||||
while (true) {
|
while (true) {
|
||||||
unsigned Code = Cursor.ReadCode();
|
llvm::BitstreamEntry Entry =
|
||||||
if (Code == llvm::bitc::END_BLOCK)
|
Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd);
|
||||||
|
|
||||||
|
switch (Entry.Kind) {
|
||||||
|
case llvm::BitstreamEntry::SubBlock: // Handled for us already.
|
||||||
|
case llvm::BitstreamEntry::Error:
|
||||||
|
Error("malformed block record in AST file");
|
||||||
|
return;
|
||||||
|
case llvm::BitstreamEntry::EndBlock:
|
||||||
|
goto NextCursor;
|
||||||
|
case llvm::BitstreamEntry::Record:
|
||||||
|
// The interesting case.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (Code == llvm::bitc::ENTER_SUBBLOCK) {
|
|
||||||
// No known subblocks, always skip them.
|
|
||||||
Cursor.ReadSubBlockID();
|
|
||||||
if (Cursor.SkipBlock()) {
|
|
||||||
Error("malformed block record in AST file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Code == llvm::bitc::DEFINE_ABBREV) {
|
|
||||||
Cursor.ReadAbbrevRecord();
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a record.
|
// Read a record.
|
||||||
Record.clear();
|
Record.clear();
|
||||||
switch ((CommentRecordTypes) Cursor.ReadRecord(Code, Record)) {
|
switch ((CommentRecordTypes)Cursor.ReadRecord(Entry.ID, Record)) {
|
||||||
case COMMENTS_RAW_COMMENT: {
|
case COMMENTS_RAW_COMMENT: {
|
||||||
unsigned Idx = 0;
|
unsigned Idx = 0;
|
||||||
SourceRange SR = ReadSourceRange(F, Record, Idx);
|
SourceRange SR = ReadSourceRange(F, Record, Idx);
|
||||||
|
@ -6832,6 +6776,7 @@ void ASTReader::ReadComments() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NextCursor:;
|
||||||
}
|
}
|
||||||
Context.Comments.addCommentsToFront(Comments);
|
Context.Comments.addCommentsToFront(Comments);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue