diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-12-22 21:40:42 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-12-22 21:40:42 +0000 |
commit | 464b0ca61a558d359795a3e4aa1ae5924ac571d5 (patch) | |
tree | e664a409d2686a5594f04b6172aba4aacad3d488 /clang/lib/Serialization/ASTWriter.cpp | |
parent | 6ca42c5be376d466d9f268dd2ada5a7438bc66d7 (diff) | |
download | bcm5719-llvm-464b0ca61a558d359795a3e4aa1ae5924ac571d5.tar.gz bcm5719-llvm-464b0ca61a558d359795a3e4aa1ae5924ac571d5.zip |
Serialize the AST reader's mapping from canonical declarations to the
set of (previously-canonical) declaration IDs to the module file, so
that future AST reader instances that load the module know which
declarations are merged. This is important in the fairly tricky case
where a declaration of an entity, e.g.,
@class X;
occurs before the import of a module that also declares that
entity. We merge the declarations, and record the fact that the
declaration of X loaded from the module was merged into the (now
canonical) declaration of X that we parsed.
llvm-svn: 147181
Diffstat (limited to 'clang/lib/Serialization/ASTWriter.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 97c31b07a37..feeb27f3389 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2903,6 +2903,25 @@ void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { Stream.EmitRecord(OPENCL_EXTENSIONS, Record); } +void ASTWriter::WriteMergedDecls() { + if (!Chain || Chain->MergedDecls.empty()) + return; + + RecordData Record; + for (ASTReader::MergedDeclsMap::iterator I = Chain->MergedDecls.begin(), + IEnd = Chain->MergedDecls.end(); + I != IEnd; ++I) { + DeclID CanonID = I->first->isFromASTFile()? Chain->DeclToID[I->first] + : getDeclID(I->first); + assert(CanonID && "Merged declaration not known?"); + + Record.push_back(CanonID); + Record.push_back(I->second.size()); + Record.append(I->second.begin(), I->second.end()); + } + Stream.EmitRecord(MERGED_DECLARATIONS, Record); +} + //===----------------------------------------------------------------------===// // General Serialization Routines //===----------------------------------------------------------------------===// @@ -3401,7 +3420,8 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, WriteDeclUpdatesBlocks(); WriteDeclReplacementsBlock(); WriteChainedObjCCategories(); - + WriteMergedDecls(); + if (!LocalRedeclarations.empty()) { // Sort the local redeclarations info by the first declaration ID, // since the reader will be perforing binary searches on this information. |