[cfe-commits] r144433 - in /cfe/trunk: include/clang/Lex/HeaderSearch.h lib/Lex/HeaderSearch.cpp test/Modules/Inputs/normal-module-map/Umbrella2/ test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h test/Modules/Inputs/normal-module-map/Umbrella2/module.map test/Modules/normal-module-map.cpp

Douglas Gregor dgregor at apple.com
Fri Nov 11 16:05:07 PST 2011


Author: dgregor
Date: Fri Nov 11 18:05:07 2011
New Revision: 144433

URL: http://llvm.org/viewvc/llvm-project?rev=144433&view=rev
Log:
When searching for a module, speculatively load module maps to see if
the module is described in one of the module maps in a search path or
in a subdirectory off the search path that has the same name as the
module we're looking for.

Added:
    cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/
    cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h   (with props)
    cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/module.map
Modified:
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/test/Modules/normal-module-map.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=144433&r1=144432&r2=144433&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Fri Nov 11 18:05:07 2011
@@ -408,6 +408,15 @@
   size_t getTotalMemory() const;
 
 private:
+  /// \brief Try to load the module map file in the given directory.
+  ///
+  /// \returns false if the module map was loaded successfully, true otherwise.
+  bool loadModuleMapFile(StringRef DirName);
+
+  /// \brief Try to load the module map file in the given directory.
+  ///
+  /// \returns false if the module map was loaded successfully, true otherwise.
+  bool loadModuleMapFile(const DirectoryEntry *Dir);
 
   /// getFileInfo - Return the HeaderFileInfo structure for the specified
   /// FileEntry.

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=144433&r1=144432&r2=144433&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Nov 11 18:05:07 2011
@@ -127,15 +127,45 @@
   if (!UmbrellaHeader)
     return 0;
   
-  // Look in the module map to determine if there is a module by this name
-  // that has an umbrella header.
+  // Look in the module map to determine if there is a module by this name.
+  ModuleMap::Module *Module = ModMap.findModule(ModuleName);
+  if (!Module) {
+    // Look through the various header search paths to load any avaiable module 
+    // maps, searching for a module map that describes this module.
+    for (unsigned Idx = 0, N = SearchDirs.size(); Idx != N; ++Idx) {
+      // Skip non-normal include paths
+      if (!SearchDirs[Idx].isNormalDir())
+        continue;
+      
+      // Search for a module map in this directory, if we haven't already
+      // looked there.
+      if (!loadModuleMapFile(SearchDirs[Idx].getDir())) {
+        // If we found a module map, look for the module again.
+        Module = ModMap.findModule(ModuleName);
+        if (Module)
+          break;
+      }
+      
+      // Search for a module map in a subdirectory with the same name as the
+      // module.
+      llvm::SmallString<128> NestedModuleMapDirName;
+      NestedModuleMapDirName = SearchDirs[Idx].getDir()->getName();
+      llvm::sys::path::append(NestedModuleMapDirName, ModuleName);
+      if (!loadModuleMapFile(NestedModuleMapDirName)) {
+        // If we found a module map, look for the module again.
+        Module = ModMap.findModule(ModuleName);
+        if (Module)
+          break;        
+      }
+    }
+  }
+
+  // If we have a module with an umbrella header 
   // FIXME: Even if it doesn't have an umbrella header, we should be able to
   // handle the module. However, the caller isn't ready for that yet.
-  if (ModuleMap::Module *Module = ModMap.findModule(ModuleName)) {
-    if (Module->UmbrellaHeader) {
-      *UmbrellaHeader = Module->UmbrellaHeader->getName();
-      return 0;
-    }
+  if (Module && Module->UmbrellaHeader) {
+    *UmbrellaHeader = Module->UmbrellaHeader->getName();
+    return 0;
   }
   
   // Look in each of the framework directories for an umbrella header with
@@ -735,45 +765,20 @@
     if (!Dir)
       return false;
     
-    llvm::DenseMap<const DirectoryEntry *, bool>::iterator
-      KnownDir = DirectoryHasModuleMap.find(Dir);
-    if (KnownDir != DirectoryHasModuleMap.end()) {
-      // We have seen this directory before. If it has no module map file,
-      // we're done.
-      if (!KnownDir->second)
-        return false;
-      
-      // All of the directories we stepped through inherit this module map
-      // file.
+    // Try to load the module map file in this directory.
+    if (!loadModuleMapFile(Dir)) {      
+      // Success. All of the directories we stepped through inherit this module
+      // map file.
       for (unsigned I = 0, N = FixUpDirectories.size(); I != N; ++I)
         DirectoryHasModuleMap[FixUpDirectories[I]] = true;
       
       return true;
     }
-    
-    // We have not checked for a module map file in this directory yet;
-    // do so now.
-    llvm::SmallString<128> ModuleMapFileName;
-    ModuleMapFileName += Dir->getName();
-    llvm::sys::path::append(ModuleMapFileName, "module.map");
-    if (const FileEntry *ModuleMapFile = FileMgr.getFile(ModuleMapFileName)) {
-      // We have found a module map file. Try to parse it.
-      if (!ModMap.parseModuleMapFile(ModuleMapFile)) {
-        // This directory has a module map.
-        DirectoryHasModuleMap[Dir] = true;
-        
-        // All of the directories we stepped through inherit this module map
-        // file.
-        for (unsigned I = 0, N = FixUpDirectories.size(); I != N; ++I)
-          DirectoryHasModuleMap[FixUpDirectories[I]] = true;
-        
-        return true;
-      }
-    }
 
-    // This directory did not have a module map file.
-    DirectoryHasModuleMap[Dir] = false;
-    
+    // If we hit the top of our search, we're done.
+    if (Dir == Root)
+      return false;
+        
     // Keep track of all of the directories we checked, so we can mark them as
     // having module maps if we eventually do find a module map.
     FixUpDirectories.push_back(Dir);
@@ -789,4 +794,34 @@
   return StringRef();
 }
 
+bool HeaderSearch::loadModuleMapFile(StringRef DirName) {
+  if (const DirectoryEntry *Dir = FileMgr.getDirectory(DirName))
+    return loadModuleMapFile(Dir);
+  
+  return true;
+}
+
+bool HeaderSearch::loadModuleMapFile(const DirectoryEntry *Dir) {
+  llvm::DenseMap<const DirectoryEntry *, bool>::iterator KnownDir
+    = DirectoryHasModuleMap.find(Dir);
+  if (KnownDir != DirectoryHasModuleMap.end())
+    return !KnownDir->second;
+  
+  llvm::SmallString<128> ModuleMapFileName;
+  ModuleMapFileName += Dir->getName();
+  llvm::sys::path::append(ModuleMapFileName, "module.map");
+  if (const FileEntry *ModuleMapFile = FileMgr.getFile(ModuleMapFileName)) {
+    // We have found a module map file. Try to parse it.
+    if (!ModMap.parseModuleMapFile(ModuleMapFile)) {
+      // This directory has a module map.
+      DirectoryHasModuleMap[Dir] = true;
+      
+      return false;
+    }
+  }
+  
+  // No suitable module map.
+  DirectoryHasModuleMap[Dir] = false;
+  return true;
+}
 

Added: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h?rev=144433&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h (added)
+++ cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h Fri Nov 11 18:05:07 2011
@@ -0,0 +1 @@
+int umbrella2;

Propchange: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/Umbrella2.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/module.map?rev=144433&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/module.map (added)
+++ cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella2/module.map Fri Nov 11 18:05:07 2011
@@ -0,0 +1,3 @@
+module Umbrella2 {
+  umbrella "Umbrella2.h"
+}
\ No newline at end of file

Modified: cfe/trunk/test/Modules/normal-module-map.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/normal-module-map.cpp?rev=144433&r1=144432&r2=144433&view=diff
==============================================================================
--- cfe/trunk/test/Modules/normal-module-map.cpp (original)
+++ cfe/trunk/test/Modules/normal-module-map.cpp Fri Nov 11 18:05:07 2011
@@ -9,6 +9,8 @@
   return umbrella; 
 }
 
+__import_module__ Umbrella2;
+
 #include "a1.h" // expected-error{{module 'libA' not found}}
 #include "b1.h"
 #include "nested/nested2.h"





More information about the cfe-commits mailing list