]> granicus.if.org Git - clang/commitdiff
Wire up the mapping from header files mentioned in module maps over to
authorDouglas Gregor <dgregor@apple.com>
Fri, 11 Nov 2011 22:18:48 +0000 (22:18 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 11 Nov 2011 22:18:48 +0000 (22:18 +0000)
the corresponding (top-level) modules. This isn't actually useful yet,
because we don't yet have a way to build modules out of module maps.

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

include/clang/Lex/HeaderSearch.h
include/clang/Lex/ModuleMap.h
lib/Lex/HeaderSearch.cpp
lib/Lex/ModuleMap.cpp
test/Modules/normal-module-map.cpp

index 995deab9dc73a7c812c78f2af75c40b798d8b5b3..87242c4372dbde6a31c173eb134b78a829a0107e 100644 (file)
@@ -365,7 +365,7 @@ public:
   /// \brief Retrieve the module that corresponds to the given file, if any.
   ///
   /// FIXME: This will need to be generalized for submodules.
-  StringRef getModuleForHeader(const FileEntry *File);
+  StringRef findModuleForHeader(const FileEntry *File);
   
   typedef std::vector<HeaderFileInfo>::const_iterator header_file_iterator;
   header_file_iterator header_file_begin() const { return FileInfo.begin(); }
index 2834f6a11bc58fe225c931bcd802e41f08405688..291f2bbdec9a424ea5e364a3f99498243e5ae569 100644 (file)
@@ -79,6 +79,9 @@ public:
     /// \brief Retrieve the full name of this module, including the path from
     /// its top-level module.
     std::string getFullModuleName() const;
+    
+    /// \brief Retrieve the name of the top-level module.
+    StringRef getTopLevelModuleName() const;
   };
   
 private:
@@ -105,9 +108,19 @@ public:
   /// \param DC A diagnostic consumer that will be cloned for use in generating
   /// diagnostics.
   ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC);
-  
+
+  /// \brief Destroy the module map.
+  ///
   ~ModuleMap();
   
+  /// \brief Retrieve the module that owns the given header file, if any.
+  ///
+  /// \param File The header file that is likely to be included.
+  ///
+  /// \returns The module that owns the given header file, or null to indicate
+  /// that no module owns this header file.
+  Module *findModuleForHeader(const FileEntry *File);
+
   /// \brief Parse the given module map file, and record any modules we 
   /// encounter.
   ///
@@ -115,7 +128,7 @@ public:
   ///
   /// \returns true if an error occurred, false otherwise.
   bool parseModuleMapFile(const FileEntry *File);
-  
+    
   /// \brief Dump the contents of the module map, for debugging purposes.
   void dump();
 };
index 6403cfb8683bc66543a0423c7ab3449b0d193653..4522de5cf3d662f8f28f41ac6b4950c7c9335c64 100644 (file)
@@ -205,7 +205,7 @@ const FileEntry *DirectoryLookup::LookupFile(
       
       // If there is a module that corresponds to this header, 
       // suggest it.
-      StringRef Module = HS.getModuleForHeader(File);
+      StringRef Module = HS.findModuleForHeader(File);
       if (!Module.empty() && Module != BuildingModule)
         *SuggestedModule = Module;
       
@@ -772,8 +772,10 @@ bool HeaderSearch::hasModuleMap(StringRef FileName,
   return false;
 }
 
-StringRef HeaderSearch::getModuleForHeader(const FileEntry *File) {
-  // FIXME: Actually look for the corresponding module for this header.
+StringRef HeaderSearch::findModuleForHeader(const FileEntry *File) {
+  if (ModuleMap::Module *Module = ModMap.findModuleForHeader(File))
+    return Module->getTopLevelModuleName();
+  
   return StringRef();
 }
 
index 8adb22014b7ceb4e943c5b2bf74491b2bd1f170d..7defe01a67fc04cdb5664b4f45411916757f6a0c 100644 (file)
@@ -51,6 +51,14 @@ std::string ModuleMap::Module::getFullModuleName() const {
   return Result;
 }
 
+StringRef ModuleMap::Module::getTopLevelModuleName() const {
+  const Module *Top = this;
+  while (Top->Parent)
+    Top = Top->Parent;
+  
+  return Top->Name;
+}
+
 //----------------------------------------------------------------------------//
 // Module map
 //----------------------------------------------------------------------------//
@@ -67,6 +75,15 @@ ModuleMap::~ModuleMap() {
   delete SourceMgr;
 }
 
+ModuleMap::Module *ModuleMap::findModuleForHeader(const FileEntry *File) {
+  llvm::DenseMap<const FileEntry *, Module *>::iterator Known
+    = Headers.find(File);
+  if (Known != Headers.end())
+    return Known->second;
+  
+  return 0;
+}
+
 static void indent(llvm::raw_ostream &OS, unsigned Spaces) {
   OS << std::string(' ', Spaces);
 }
index 2935c8baa9fcd36d524e2ba5507e3dcafd95874b..b6f584d33cb56d7bfdc68fcf9029e7db7604350e 100644 (file)
@@ -1,7 +1,9 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -x objective-c -fmodule-cache-path %t -fauto-module-import -I %S/Inputs/normal-module-map -verify %s 
+// RUN: %clang_cc1 -x objective-c -fmodule-cache-path %t -fauto-module-import -I %S/Inputs/normal-module-map %s -verify
 
-#include "a1.h"
+// FIXME: The expected error here is temporary, since we don't yet have the
+// logic to build a module from a module map.
+#include "a1.h" // expected-error{{module 'libA' not found}}
 #include "b1.h"
 #include "nested/nested2.h"