summaryrefslogtreecommitdiffstats
path: root/lib/Serialization/ASTWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-12-22 21:40:42 +0000
committerDouglas Gregor <dgregor@apple.com>2011-12-22 21:40:42 +0000
commitc3cfd2ab3338d47861ece597212f21b972ebe727 (patch)
tree836c68f3c7a01079a4e278b86a9a8c1d6421dbb0 /lib/Serialization/ASTWriter.cpp
parente89fd1b30ae0c9f396b183f338d563757c26d3a8 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147181 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTWriter.cpp')
-rw-r--r--lib/Serialization/ASTWriter.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 97c31b07a3..feeb27f338 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/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.