Rearrange serialization block order to put decl update emission into the same

block as decl and type emission. This allows decl updates include statements
and expressions. No functionality change (but the generated PCM files are
incompatible with earlier versions of Clang).

llvm-svn: 204385
This commit is contained in:
Richard Smith 2014-03-20 19:44:17 +00:00
parent c962cda1db
commit b9eab6d1c8
4 changed files with 53 additions and 52 deletions

View File

@ -213,9 +213,6 @@ namespace clang {
/// types and decls used within the AST file.
DECLTYPES_BLOCK_ID,
/// \brief The block containing DECL_UPDATES records.
DECL_UPDATES_BLOCK_ID,
/// \brief The block containing the detailed preprocessing record.
PREPROCESSOR_DETAIL_BLOCK_ID,

View File

@ -448,7 +448,7 @@ private:
bool IsModule);
void WriteAttributes(ArrayRef<const Attr*> Attrs, RecordDataImpl &Record);
void ResolveDeclUpdatesBlocks();
void WriteDeclUpdatesBlocks();
void WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord);
void WriteDeclReplacementsBlock();
void WriteDeclContextVisibleUpdate(const DeclContext *DC);
void WriteFPPragmaOptions(const FPOptions &Opts);

View File

@ -2352,14 +2352,7 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) {
return true;
}
break;
case DECL_UPDATES_BLOCK_ID:
if (Stream.SkipBlock()) {
Error("malformed block record in AST file");
return true;
}
break;
case PREPROCESSOR_BLOCK_ID:
F.MacroCursor = Stream;
if (!PP.getExternalSource())
@ -2707,9 +2700,9 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) {
// Initialize the remapping table.
// Invalid stays invalid.
F.SLocRemap.insert(std::make_pair(0U, 0));
F.SLocRemap.insertOrReplace(std::make_pair(0U, 0));
// This module. Base was 2 when being compiled.
F.SLocRemap.insert(std::make_pair(2U,
F.SLocRemap.insertOrReplace(std::make_pair(2U,
static_cast<int>(F.SLocEntryBaseOffset - 2)));
TotalNumSLocEntries += F.LocalNumSLocEntries;
@ -2720,7 +2713,13 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) {
// Additional remapping information.
const unsigned char *Data = (const unsigned char*)Blob.data();
const unsigned char *DataEnd = Data + Blob.size();
// If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders.
if (F.SLocRemap.find(0) == F.SLocRemap.end()) {
F.SLocRemap.insert(std::make_pair(0U, 0));
F.SLocRemap.insert(std::make_pair(2U, 1));
}
// Continuous range maps we may be updating in our module.
ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap);
ContinuousRangeMap<uint32_t, int, 2>::Builder

View File

@ -4104,9 +4104,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef,
}
}
// Resolve any declaration pointers within the declaration updates block.
ResolveDeclUpdatesBlocks();
// Form the record of special types.
RecordData SpecialTypes;
AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
@ -4118,30 +4115,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef,
AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
AddTypeRef(Context.getucontext_tType(), SpecialTypes);
// Keep writing types and declarations until all types and
// declarations have been written.
Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE);
WriteDeclsBlockAbbrevs();
for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(),
E = DeclsToRewrite.end();
I != E; ++I)
DeclTypesToEmit.push(const_cast<Decl*>(*I));
while (!DeclTypesToEmit.empty()) {
DeclOrType DOT = DeclTypesToEmit.front();
DeclTypesToEmit.pop();
if (DOT.isType())
WriteType(DOT.getType());
else
WriteDecl(Context, DOT.getDecl());
}
Stream.ExitBlock();
DoneWritingDeclsAndTypes = true;
WriteFileDeclIDsMap();
WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot);
WriteComments();
if (Chain) {
// Write the mapping information describing our module dependencies and how
// each of those modules were mapped into our own offset/ID space, so that
@ -4186,6 +4159,44 @@ void ASTWriter::WriteASTCore(Sema &SemaRef,
Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record,
Buffer.data(), Buffer.size());
}
// Resolve any declaration pointers within the declaration updates block.
// FIXME: Fold this into WriteDeclUpdatesBlocks.
ResolveDeclUpdatesBlocks();
RecordData DeclUpdatesOffsetsRecord;
// Keep writing types and declarations until all types and
// declarations have been written.
Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE);
WriteDeclsBlockAbbrevs();
for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(),
E = DeclsToRewrite.end();
I != E; ++I)
DeclTypesToEmit.push(const_cast<Decl*>(*I));
while (!DeclTypesToEmit.empty()) {
DeclOrType DOT = DeclTypesToEmit.front();
DeclTypesToEmit.pop();
if (DOT.isType())
WriteType(DOT.getType());
else
WriteDecl(Context, DOT.getDecl());
}
WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord);
Stream.ExitBlock();
if (!DeclUpdatesOffsetsRecord.empty())
Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord);
DoneWritingDeclsAndTypes = true;
// These things can only be done once we've written out decls and types.
WriteTypeDeclOffsets();
WriteCXXBaseSpecifiersOffsets();
WriteFileDeclIDsMap();
WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot);
WriteComments();
WritePreprocessor(PP, isModule);
WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot);
WriteSelectors(SemaRef);
@ -4193,12 +4204,8 @@ void ASTWriter::WriteASTCore(Sema &SemaRef,
WriteIdentifierTable(PP, SemaRef.IdResolver, isModule);
WriteFPPragmaOptions(SemaRef.getFPOptions());
WriteOpenCLExtensions(SemaRef);
WriteTypeDeclOffsets();
WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule);
WriteCXXBaseSpecifiersOffsets();
// If we're emitting a module, write out the submodule information.
if (WritingModule)
WriteSubmodules(WritingModule);
@ -4290,7 +4297,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef,
}
}
WriteDeclUpdatesBlocks();
WriteDeclReplacementsBlock();
WriteRedeclarations();
WriteMergedDecls();
@ -4343,12 +4349,10 @@ void ASTWriter::ResolveDeclUpdatesBlocks() {
}
}
void ASTWriter::WriteDeclUpdatesBlocks() {
void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) {
if (DeclUpdates.empty())
return;
RecordData OffsetsRecord;
Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE);
for (DeclUpdateMap::iterator
I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) {
const Decl *D = I->first;
@ -4360,11 +4364,12 @@ void ASTWriter::WriteDeclUpdatesBlocks() {
uint64_t Offset = Stream.GetCurrentBitNo();
Stream.EmitRecord(DECL_UPDATES, URec);
// Flush any statements that were written as part of this update record.
FlushStmts();
OffsetsRecord.push_back(GetDeclRef(D));
OffsetsRecord.push_back(Offset);
}
Stream.ExitBlock();
Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord);
}
void ASTWriter::WriteDeclReplacementsBlock() {