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

Douglas Gregor dgregor at apple.com
Fri Nov 11 14:18:49 PST 2011


Author: dgregor
Date: Fri Nov 11 16:18:48 2011
New Revision: 144410

URL: http://llvm.org/viewvc/llvm-project?rev=144410&view=rev
Log:
Wire up the mapping from header files mentioned in module maps over to
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.

Modified:
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/include/clang/Lex/ModuleMap.h
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/lib/Lex/ModuleMap.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=144410&r1=144409&r2=144410&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Fri Nov 11 16:18:48 2011
@@ -365,7 +365,7 @@
   /// \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(); }

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=144410&r1=144409&r2=144410&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Fri Nov 11 16:18:48 2011
@@ -79,6 +79,9 @@
     /// \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 @@
   /// \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 @@
   ///
   /// \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();
 };

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=144410&r1=144409&r2=144410&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Nov 11 16:18:48 2011
@@ -205,7 +205,7 @@
       
       // 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 @@
   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();
 }
 

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=144410&r1=144409&r2=144410&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Nov 11 16:18:48 2011
@@ -51,6 +51,14 @@
   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 @@
   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);
 }

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=144410&r1=144409&r2=144410&view=diff
==============================================================================
--- cfe/trunk/test/Modules/normal-module-map.cpp (original)
+++ cfe/trunk/test/Modules/normal-module-map.cpp Fri Nov 11 16:18:48 2011
@@ -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"
 





More information about the cfe-commits mailing list