[cfe-commits] r145957 - in /cfe/trunk: include/clang/Lex/ModuleMap.h lib/Lex/HeaderSearch.cpp lib/Lex/ModuleMap.cpp test/Modules/Inputs/Module.framework/Frameworks/ test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/ test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/Headers/ test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/Headers/SubFramework.h test/Modules/auto-module-import.c test/Modules/on-demand-build.m

Douglas Gregor dgregor at apple.com
Tue Dec 6 11:39:30 PST 2011


Author: dgregor
Date: Tue Dec  6 13:39:29 2011
New Revision: 145957

URL: http://llvm.org/viewvc/llvm-project?rev=145957&view=rev
Log:
When inferring a module map for a framework, infer subframework
modules for each of its subframeworks.

Added:
    cfe/trunk/test/Modules/Inputs/Module.framework/Frameworks/
    cfe/trunk/test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/
    cfe/trunk/test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/Headers/
    cfe/trunk/test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/Headers/SubFramework.h
Modified:
    cfe/trunk/include/clang/Lex/ModuleMap.h
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/lib/Lex/ModuleMap.cpp
    cfe/trunk/test/Modules/auto-module-import.c
    cfe/trunk/test/Modules/on-demand-build.m

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=145957&r1=145956&r2=145957&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Tue Dec  6 13:39:29 2011
@@ -146,7 +146,8 @@
   /// \brief Infer the contents of a framework module map from the given
   /// framework directory.
   Module *inferFrameworkModule(StringRef ModuleName, 
-                               const DirectoryEntry *FrameworkDir);
+                               const DirectoryEntry *FrameworkDir,
+                               Module *Parent);
   
   /// \brief Retrieve the module map file containing the definition of the given
   /// module.

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=145957&r1=145956&r2=145957&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Tue Dec  6 13:39:29 2011
@@ -849,7 +849,7 @@
   }
   
   // Try to infer a module map.
-  return ModMap.inferFrameworkModule(Name, Dir);
+  return ModMap.inferFrameworkModule(Name, Dir, /*Parent=*/0);
 }
 
 

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=145957&r1=145956&r2=145957&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Tue Dec  6 13:39:29 2011
@@ -20,6 +20,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/PathV2.h"
 #include "llvm/Support/raw_ostream.h"
@@ -219,17 +220,19 @@
 
 Module *
 ModuleMap::inferFrameworkModule(StringRef ModuleName, 
-                                const DirectoryEntry *FrameworkDir) {
+                                const DirectoryEntry *FrameworkDir,
+                                Module *Parent) {
   // Check whether we've already found this module.
-  if (Module *Module = findModule(ModuleName))
-    return Module;
+  if (Module *Mod = lookupModuleQualified(ModuleName, Parent))
+    return Mod;
+  
+  FileManager &FileMgr = SourceMgr->getFileManager();
   
   // Look for an umbrella header.
   llvm::SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
   llvm::sys::path::append(UmbrellaName, "Headers");
   llvm::sys::path::append(UmbrellaName, ModuleName + ".h");
-  const FileEntry *UmbrellaHeader
-    = SourceMgr->getFileManager().getFile(UmbrellaName);
+  const FileEntry *UmbrellaHeader = FileMgr.getFile(UmbrellaName);
   
   // FIXME: If there's no umbrella header, we could probably scan the
   // framework to load *everything*. But, it's not clear that this is a good
@@ -237,8 +240,14 @@
   if (!UmbrellaHeader)
     return 0;
   
-  Module *Result = new Module(ModuleName, SourceLocation(), 
-                              /*IsFramework=*/true);
+  Module *Result = new Module(ModuleName, SourceLocation(), Parent,
+                              /*IsFramework=*/true, /*IsExplicit=*/false);
+  
+  if (Parent)
+    Parent->SubModules[ModuleName] = Result;
+  else
+    Modules[ModuleName] = Result;
+
   // umbrella "umbrella-header-name"
   Result->UmbrellaHeader = UmbrellaHeader;
   Headers[UmbrellaHeader] = Result;
@@ -251,9 +260,24 @@
   Result->InferSubmodules = true;
   Result->InferExportWildcard = true;
   
-  // FIXME: Look for subframeworks.
+  // Look for subframeworks.
+  llvm::error_code EC;
+  llvm::SmallString<128> SubframeworksDirName = StringRef(FrameworkDir->getName());
+  llvm::sys::path::append(SubframeworksDirName, "Frameworks");
+  for (llvm::sys::fs::directory_iterator Dir(SubframeworksDirName.str(), EC),
+                                         DirEnd;
+       Dir != DirEnd && !EC; Dir.increment(EC)) {
+    if (!StringRef(Dir->path()).endswith(".framework"))
+      continue;
+    
+    if (const DirectoryEntry *SubframeworkDir
+          = FileMgr.getDirectory(Dir->path())) {
+      // FIXME: Do we want to warn about subframeworks without umbrella headers?
+      inferFrameworkModule(llvm::sys::path::stem(Dir->path()), SubframeworkDir,
+                           Result);
+    }
+  }
   
-  Modules[ModuleName] = Result;
   return Result;
 }
 

Added: cfe/trunk/test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/Headers/SubFramework.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/Headers/SubFramework.h?rev=145957&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/Headers/SubFramework.h (added)
+++ cfe/trunk/test/Modules/Inputs/Module.framework/Frameworks/SubFramework.framework/Headers/SubFramework.h Tue Dec  6 13:39:29 2011
@@ -0,0 +1,4 @@
+#ifndef MODULE_SUBFRAMEWORK_H
+#define MODULE_SUBFRAMEWORK_H
+char *module_subframework;
+#endif

Modified: cfe/trunk/test/Modules/auto-module-import.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/auto-module-import.c?rev=145957&r1=145956&r2=145957&view=diff
==============================================================================
--- cfe/trunk/test/Modules/auto-module-import.c (original)
+++ cfe/trunk/test/Modules/auto-module-import.c Tue Dec  6 13:39:29 2011
@@ -29,3 +29,13 @@
 void testSubframeworkOtherAgain() {
   double *sfo1 = sub_framework_other;
 }
+
+void testModuleSubFramework() {
+  char *msf = module_subframework;
+}
+
+#include <Module/../Frameworks/SubFramework.framework/Headers/SubFramework.h> // expected-warning{{treating #include as an import of module 'Module.SubFramework'}}
+
+void testModuleSubFrameworkAgain() {
+  char *msf = module_subframework;
+}

Modified: cfe/trunk/test/Modules/on-demand-build.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/on-demand-build.m?rev=145957&r1=145956&r2=145957&view=diff
==============================================================================
--- cfe/trunk/test/Modules/on-demand-build.m (original)
+++ cfe/trunk/test/Modules/on-demand-build.m Tue Dec  6 13:39:29 2011
@@ -16,7 +16,7 @@
   OtherClass *other = [Module alloc]; // expected-error{{init}}
 }
 
-#ifdef MODULE_H
-#  error MODULE_H should not be hidden
+#ifdef MODULE_SUBFRAMEWORK_H
+#  error MODULE_SUBFRAMEWORK_H should be hidden
 #endif
 





More information about the cfe-commits mailing list