[cfe-commits] r137971 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp test/Modules/

Chad Rosier mcrosier at apple.com
Thu Aug 18 12:06:24 PDT 2011


Author: mcrosier
Date: Thu Aug 18 14:06:24 2011
New Revision: 137971

URL: http://llvm.org/viewvc/llvm-project?rev=137971&view=rev
Log:
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.

Removed:
    cfe/trunk/test/Modules/
Modified:
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=137971&r1=137970&r2=137971&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Aug 18 14:06:24 2011
@@ -507,11 +507,8 @@
   ///
   /// \param ImportedBy The module that is importing this module, or NULL if
   /// this module is imported directly by the user.
-  ///
-  /// \return A pointer to the module that corresponds to this file name,
-  /// and a boolean indicating whether the module was newly added.
-  std::pair<Module *, bool> 
-  addModule(StringRef FileName, ModuleKind Type, Module *ImportedBy);
+  Module &addModule(StringRef FileName, ModuleKind Type,
+                    Module *ImportedBy);
   
   /// \brief Add an in-memory buffer the list of known buffers
   void addInMemoryBuffer(StringRef FileName, llvm::MemoryBuffer *Buffer);

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=137971&r1=137970&r2=137971&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Aug 18 14:06:24 2011
@@ -2831,23 +2831,7 @@
 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 @@
   return InMemoryBuffers[Entry];
 }
 
-std::pair<Module *, bool>
-ModuleManager::addModule(StringRef FileName, ModuleKind Type, 
-                         Module *ImportedBy) {
-  const FileEntry *Entry = FileMgr.getFile(FileName);
-  if (!Entry)
-    return std::make_pair(static_cast<Module*>(0), false);
+/// \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);
 
-  // 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;
-  }
+  const FileEntry *Entry = FileMgr.getFile(FileName);
+  // 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, 





More information about the cfe-commits mailing list