diff options
author | Chad Rosier <mcrosier@apple.com> | 2011-08-18 19:06:24 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2011-08-18 19:06:24 +0000 |
commit | 870d1fee3c5027efe7fd23d6935952bc1f419f99 (patch) | |
tree | 43a5d2be5924494607d0ac3c678a7e89250493d6 /lib | |
parent | 647a75160df6d53d26724038b3bfe0d836513f58 (diff) |
Temporarily revert r137925 to appease buildbots. Original commit message:
Teach ModuleManager::addModule() to check whether a particular module
has already been loaded before allocating a new Module structure. If
the module has already been loaded (uniquing based on file name), then
just return the existing module rather than trying to load it again.
This allows us to load a DAG of modules. Introduce a simple test case
that forms a diamond-shaped module graph, and illustrates that a
source file importing the bottom of the diamond can see declarations
in all four of the modules that make up the diamond.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137971 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 53 |
1 files changed, 14 insertions, 39 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index b635b38c10..d81e9d8a36 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2831,23 +2831,7 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, ModuleKind Type, Module *ImportedBy) { - Module *M; - bool NewModule; - llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy); - - if (!M) { - // We couldn't load the module. - std::string Msg = "Unable to load module \"" + FileName.str() + "\""; - Error(Msg); - return Failure; - } - - if (!NewModule) { - // We've already loaded this module. - return Success; - } - - Module &F = *M; + Module &F = ModuleMgr.addModule(FileName, Type, ImportedBy); if (FileName != "-") { CurrentDir = llvm::sys::path::parent_path(FileName); @@ -5725,34 +5709,25 @@ llvm::MemoryBuffer *ModuleManager::lookupBuffer(StringRef Name) { return InMemoryBuffers[Entry]; } -std::pair<Module *, bool> -ModuleManager::addModule(StringRef FileName, ModuleKind Type, - Module *ImportedBy) { +/// \brief Creates a new module and adds it to the list of known modules +Module &ModuleManager::addModule(StringRef FileName, ModuleKind Type, + Module *ImportedBy) { + Module *Current = new Module(Type); + Current->FileName = FileName.str(); + Chain.push_back(Current); + const FileEntry *Entry = FileMgr.getFile(FileName); - if (!Entry) - return std::make_pair(static_cast<Module*>(0), false); - - // Check whether we already loaded this module, before - Module *&ModuleEntry = Modules[Entry]; - bool NewModule = false; - if (!ModuleEntry) { - // Allocate a new module. - Module *New = new Module(Type); - New->FileName = FileName.str(); - Chain.push_back(New); - - NewModule = true; - ModuleEntry = New; - } + // FIXME: Check whether we already loaded this module, before + Modules[Entry] = Current; if (ImportedBy) { - ModuleEntry->ImportedBy.insert(ImportedBy); - ImportedBy->Imports.insert(ModuleEntry); + Current->ImportedBy.insert(ImportedBy); + ImportedBy->Imports.insert(Current); } else { - ModuleEntry->DirectlyImported = true; + Current->DirectlyImported = true; } - return std::make_pair(ModuleEntry, NewModule); + return *Current; } void ModuleManager::addInMemoryBuffer(StringRef FileName, |