diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-12-05 16:33:54 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-12-05 16:33:54 +0000 |
commit | 55988680ece66b8e505ee136b35e74fcb1173aee (patch) | |
tree | 98b942dc721f88d21eeda306df4a7af70a04db12 /lib/Serialization/ASTWriter.cpp | |
parent | 5460ff35ab748860f05aeea4685cd195153dca66 (diff) |
When writing a module file, keep track of the set of (sub)modules that
it imports, establishing dependencies at the (sub)module
granularity. This is not a user-visible change (yet).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145808 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTWriter.cpp')
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index b6198184cc..f2c2f4330a 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1858,6 +1858,22 @@ static unsigned getNumberOfModules(Module *Mod) { } void ASTWriter::WriteSubmodules(Module *WritingModule) { + // + // FIXME: This feels like it belongs somewhere else, but there are no + // other consumers of this information. + SourceManager &SrcMgr = PP->getSourceManager(); + ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); + for (ASTContext::import_iterator I = Context->local_import_begin(), + IEnd = Context->local_import_end(); + I != IEnd; ++I) { + assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); + if (Module *ImportedFrom + = ModMap.inferModuleFromLocation(FullSourceLoc(I->getLocation(), + SrcMgr))) { + ImportedFrom->Imports.push_back(I->getImportedModule()); + } + } + // Enter the submodule description block. Stream.EnterSubblock(SUBMODULE_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); @@ -1924,7 +1940,18 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) { Stream.EmitRecordWithBlob(HeaderAbbrev, Record, Mod->Headers[I]->getName()); } - + + // Emit the imports. + if (!Mod->Imports.empty()) { + Record.clear(); + for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { + unsigned ImportedID = SubmoduleIDs[Mod->Imports[I]]; + assert(ImportedID && "Unknown submodule!"); + Record.push_back(ImportedID); + } + Stream.EmitRecord(SUBMODULE_IMPORTS, Record); + } + // Emit the exports. if (!Mod->Exports.empty()) { Record.clear(); @@ -1960,22 +1987,11 @@ serialization::SubmoduleID ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) { if (Loc.isInvalid() || SubmoduleIDs.empty()) return 0; // No submodule - - // Use the expansion location to determine which module we're in. - SourceManager &SrcMgr = PP->getSourceManager(); - SourceLocation ExpansionLoc = SrcMgr.getExpansionLoc(Loc); - if (!ExpansionLoc.isFileID()) - return 0; - - - FileID ExpansionFileID = SrcMgr.getFileID(ExpansionLoc); - const FileEntry *ExpansionFile = SrcMgr.getFileEntryForID(ExpansionFileID); - if (!ExpansionFile) - return 0; - - // Find the module that owns this header. + + // Find the module that owns this location. ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); - Module *OwningMod = ModMap.findModuleForHeader(ExpansionFile); + Module *OwningMod + = ModMap.inferModuleFromLocation(FullSourceLoc(Loc,PP->getSourceManager())); if (!OwningMod) return 0; |