diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-08-18 04:12:04 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-08-18 04:12:04 +0000 |
commit | 10bc00fd45824f9b5cd139d63af8b0f6d28aadda (patch) | |
tree | feebae845b9bbbe1782000ac5f70535b2c733b6f /lib/Serialization/ASTWriter.cpp | |
parent | 1cb4f664fd4f72a65a145e9ff8a7e2540ab09156 (diff) |
Keep track of which modules have been loaded directly (e.g., via
-import-module) vs. loaded because some other module depends on
them. As part of doing this, pass down the module that caused a module
to be loaded directly, rather than assuming that we're loading a
chain. Finally, write out all of the directly-loaded modules when
serializing an AST file (using the new IMPORTS record), so that an AST
file can depend on more than one other AST file, all of which will be
loaded when that AST file is loaded. This allows us to form and load a
tree of modules, but we can't yet load a DAG of modules.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137923 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTWriter.cpp')
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 91c68df477..15a7cbc628 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -972,18 +972,23 @@ void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot, Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, Triple); if (Chain) { - // FIXME: Add all of the "directly imported" modules, not just - // "the one we're chaining to". serialization::ModuleManager &Mgr = Chain->getModuleManager(); llvm::SmallVector<char, 128> ModulePaths; Record.clear(); - Module &PrimaryModule = Mgr.getPrimaryModule(); - Record.push_back((unsigned)PrimaryModule.Kind); // FIXME: Stable encoding - // FIXME: Write import location, once it matters. - // FIXME: This writes the absolute path for AST files we depend on. - const std::string &MainFileName = PrimaryModule.FileName; - Record.push_back(MainFileName.size()); - Record.append(MainFileName.begin(), MainFileName.end()); + + for (ModuleManager::ModuleIterator M = Mgr.begin(), MEnd = Mgr.end(); + M != MEnd; ++M) { + // Skip modules that weren't directly imported. + if (!(*M)->isDirectlyImported()) + continue; + + Record.push_back((unsigned)(*M)->Kind); // FIXME: Stable encoding + // FIXME: Write import location, once it matters. + // FIXME: This writes the absolute path for AST files we depend on. + const std::string &FileName = (*M)->FileName; + Record.push_back(FileName.size()); + Record.append(FileName.begin(), FileName.end()); + } Stream.EmitRecord(IMPORTS, Record); } @@ -3855,7 +3860,7 @@ void ASTWriter::AddCXXDefinitionData(const CXXRecordDecl *D, RecordDataImpl &Rec void ASTWriter::ReaderInitialized(ASTReader *Reader) { assert(Reader && "Cannot remove chain"); - assert(!Chain && "Cannot replace chain"); + assert((!Chain || Chain == Reader) && "Cannot replace chain"); assert(FirstDeclID == NextDeclID && FirstTypeID == NextTypeID && FirstIdentID == NextIdentID && @@ -3865,11 +3870,11 @@ void ASTWriter::ReaderInitialized(ASTReader *Reader) { Chain = Reader; - FirstDeclID += Chain->getTotalNumDecls(); - FirstTypeID += Chain->getTotalNumTypes(); - FirstIdentID += Chain->getTotalNumIdentifiers(); - FirstSelectorID += Chain->getTotalNumSelectors(); - FirstMacroID += Chain->getTotalNumMacroDefinitions(); + FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); + FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); + FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); + FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); + FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacroDefinitions(); NextDeclID = FirstDeclID; NextTypeID = FirstTypeID; NextIdentID = FirstIdentID; |