]> granicus.if.org Git - clang/commitdiff
Teach the search for modules to consider modules described by a module
authorDouglas Gregor <dgregor@apple.com>
Fri, 11 Nov 2011 23:20:24 +0000 (23:20 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 11 Nov 2011 23:20:24 +0000 (23:20 +0000)
map, so long as they have an umbrella header. This makes it possible
to introduce a module map + umbrella header for a given set of
headers, to turn it into a module.

There are two major deficiencies here: first, we don't go hunting for
module map files when we just see a module import (so we won't know
about the modules described therein). Second, we don't yet have a way
to build modules that don't have umbrella headers, or have incomplete
umbrella headers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144424 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/ModuleMap.h
lib/Lex/HeaderSearch.cpp
lib/Lex/ModuleMap.cpp
test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h [new file with mode: 0644]
test/Modules/Inputs/normal-module-map/Umbrella/module.map [new file with mode: 0644]
test/Modules/normal-module-map.cpp

index 291f2bbdec9a424ea5e364a3f99498243e5ae569..6ca37f1005fc8ee765db252c67291f1a13dfca58 100644 (file)
@@ -89,7 +89,7 @@ private:
   llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags;
   LangOptions LangOpts;
   
-  /// \brief The top-level modules that are known
+  /// \brief The top-level modules that are known.
   llvm::StringMap<Module *> Modules;
   
   /// \brief Mapping from each header to the module that owns the contents of the
@@ -121,6 +121,13 @@ public:
   /// that no module owns this header file.
   Module *findModuleForHeader(const FileEntry *File);
 
+  /// \brief Retrieve a module with the given name.
+  ///
+  /// \param The name of the module to look up.
+  ///
+  /// \returns The named module, if known; otherwise, returns null.
+  Module *findModule(StringRef Name);
+  
   /// \brief Parse the given module map file, and record any modules we 
   /// encounter.
   ///
index 4522de5cf3d662f8f28f41ac6b4950c7c9335c64..3f50285430eff883cb1d41703f128d37b88d25a9 100644 (file)
@@ -127,9 +127,19 @@ const FileEntry *HeaderSearch::lookupModule(StringRef ModuleName,
   if (!UmbrellaHeader)
     return 0;
   
+  // Look in the module map to determine if there is a module by this name
+  // that has 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;
+    }
+  }
+  
   // Look in each of the framework directories for an umbrella header with
   // the same name as the module.
-  // FIXME: We need a way for non-frameworks to provide umbrella headers.
   llvm::SmallString<128> UmbrellaHeaderName;
   UmbrellaHeaderName = ModuleName;
   UmbrellaHeaderName += '/';
index 7defe01a67fc04cdb5664b4f45411916757f6a0c..6695e4215038739ce4cb83473addd7688f33712e 100644 (file)
@@ -84,6 +84,14 @@ ModuleMap::Module *ModuleMap::findModuleForHeader(const FileEntry *File) {
   return 0;
 }
 
+ModuleMap::Module *ModuleMap::findModule(StringRef Name) {
+  llvm::StringMap<Module *>::iterator Known = Modules.find(Name);
+  if (Known != Modules.end())
+    return Known->getValue();
+  
+  return 0;
+}
+
 static void indent(llvm::raw_ostream &OS, unsigned Spaces) {
   OS << std::string(' ', Spaces);
 }
diff --git a/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h b/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h
new file mode 100644 (file)
index 0000000..5d201f5
--- /dev/null
@@ -0,0 +1 @@
+int umbrella;
diff --git a/test/Modules/Inputs/normal-module-map/Umbrella/module.map b/test/Modules/Inputs/normal-module-map/Umbrella/module.map
new file mode 100644 (file)
index 0000000..dd2e434
--- /dev/null
@@ -0,0 +1,3 @@
+module Umbrella {
+  umbrella "Umbrella.h"
+}
\ No newline at end of file
index b6f584d33cb56d7bfdc68fcf9029e7db7604350e..aeb569b87230e22163f5961dffe02d82d0a07809 100644 (file)
@@ -3,6 +3,12 @@
 
 // FIXME: The expected error here is temporary, since we don't yet have the
 // logic to build a module from a module map.
+#include "Umbrella/Umbrella.h"
+
+int getUmbrella() { 
+  return umbrella; 
+}
+
 #include "a1.h" // expected-error{{module 'libA' not found}}
 #include "b1.h"
 #include "nested/nested2.h"