[cfe-commits] r144877 - in /cfe/trunk: include/clang/Lex/HeaderSearch.h include/clang/Lex/ModuleMap.h lib/Lex/HeaderSearch.cpp lib/Lex/ModuleMap.cpp test/Modules/auto-module-import.c
Douglas Gregor
dgregor at apple.com
Wed Nov 16 17:41:17 PST 2011
Author: dgregor
Date: Wed Nov 16 19:41:17 2011
New Revision: 144877
URL: http://llvm.org/viewvc/llvm-project?rev=144877&view=rev
Log:
When we're loading a framework header, first try to turn the framework
into a module. This module can either be loaded from a module map in
the framework directory (which isn't quite working yet) or inferred
from an umbrella header (which does work, and replaces the existing
hack).
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/auto-module-import.c
Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=144877&r1=144876&r2=144877&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Nov 16 19:41:17 2011
@@ -389,6 +389,20 @@
///
/// \returns The module, if found; otherwise, null.
ModuleMap::Module *getModule(StringRef Name, bool AllowSearch = true);
+
+ /// \brief Retrieve a module with the given name, which may be part of the
+ /// given framework.
+ ///
+ /// \param Name The name of the module to retrieve.
+ ///
+ /// \param Dir The framework directory (e.g., ModuleName.framework).
+ ///
+ /// \returns The module, if found; otherwise, null.
+ ModuleMap::Module *getFrameworkModule(StringRef Name,
+ const DirectoryEntry *Dir);
+
+ /// \brief Retrieve the module map.
+ ModuleMap &getModuleMap() { return ModMap; }
unsigned header_file_size() const { return FileInfo.size(); }
Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=144877&r1=144876&r2=144877&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Wed Nov 16 19:41:17 2011
@@ -137,6 +137,11 @@
/// \returns The named module, if known; otherwise, returns null.
Module *findModule(StringRef Name);
+ /// \brief Infer the contents of a framework module map from the given
+ /// framework directory.
+ Module *inferFrameworkModule(StringRef ModuleName,
+ const DirectoryEntry *FrameworkDir);
+
/// \brief Parse the given module map file, and record any modules we
/// encounter.
///
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=144877&r1=144876&r2=144877&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Nov 16 19:41:17 2011
@@ -311,7 +311,8 @@
FrameworkName.push_back('/');
// FrameworkName = "/System/Library/Frameworks/Cocoa"
- FrameworkName.append(Filename.begin(), Filename.begin()+SlashPos);
+ StringRef ModuleName(Filename.begin(), SlashPos);
+ FrameworkName += ModuleName;
// FrameworkName = "/System/Library/Frameworks/Cocoa.framework/"
FrameworkName += ".framework/";
@@ -337,6 +338,18 @@
RelativePath->append(Filename.begin()+SlashPos+1, Filename.end());
}
+ // If we're allowed to look for modules, try to load or create the module
+ // corresponding to this framework.
+ ModuleMap::Module *Module = 0;
+ if (SuggestedModule) {
+ if (const DirectoryEntry *FrameworkDir
+ = FileMgr.getDirectory(FrameworkName)) {
+ if ((Module = HS.getFrameworkModule(ModuleName, FrameworkDir)) &&
+ Module->Name == BuildingModule)
+ Module = 0;
+ }
+ }
+
// Check "/System/Library/Frameworks/Cocoa.framework/Headers/file.h"
unsigned OrigSize = FrameworkName.size();
@@ -348,16 +361,16 @@
SearchPath->append(FrameworkName.begin(), FrameworkName.end()-1);
}
- /// Determine whether this is the module we're building or not.
- bool AutomaticImport = SuggestedModule &&
- (BuildingModule != StringRef(Filename.begin(), SlashPos)) &&
+ // Determine whether this is the module we're building or not.
+ // FIXME: Do we still need the ".." hack?
+ bool AutomaticImport = Module &&
!Filename.substr(SlashPos + 1).startswith("..");
FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end());
if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
/*openFile=*/!AutomaticImport)) {
if (AutomaticImport)
- *SuggestedModule = StringRef(Filename.begin(), SlashPos);
+ *SuggestedModule = Module->Name;
return FE;
}
@@ -372,7 +385,7 @@
const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
/*openFile=*/!AutomaticImport);
if (FE && AutomaticImport)
- *SuggestedModule = StringRef(Filename.begin(), SlashPos);
+ *SuggestedModule = Module->Name;
return FE;
}
@@ -839,6 +852,29 @@
return 0;
}
+
+ModuleMap::Module *HeaderSearch::getFrameworkModule(StringRef Name,
+ const DirectoryEntry *Dir) {
+ if (ModuleMap::Module *Module = ModMap.findModule(Name))
+ return Module;
+
+ // Try to load a module map file.
+ switch (loadModuleMapFile(Dir)) {
+ case LMM_InvalidModuleMap:
+ break;
+
+ case LMM_AlreadyLoaded:
+ case LMM_NoDirectory:
+ return 0;
+
+ case LMM_NewlyLoaded:
+ return ModMap.findModule(Name);
+ }
+
+ // Try to infer a module map.
+ return ModMap.inferFrameworkModule(Name, Dir);
+}
+
HeaderSearch::LoadModuleMapResult
HeaderSearch::loadModuleMapFile(StringRef DirName) {
Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=144877&r1=144876&r2=144877&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Wed Nov 16 19:41:17 2011
@@ -127,6 +127,34 @@
return 0;
}
+ModuleMap::Module *
+ModuleMap::inferFrameworkModule(StringRef ModuleName,
+ const DirectoryEntry *FrameworkDir) {
+ // Check whether we've already found this module.
+ if (Module *Module = findModule(ModuleName))
+ return Module;
+
+ // 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);
+
+ // 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
+ // idea.
+ if (!UmbrellaHeader)
+ return 0;
+
+ Module *Result = new Module(ModuleName, SourceLocation());
+ Result->UmbrellaHeader = UmbrellaHeader;
+ Headers[UmbrellaHeader] = Result;
+ UmbrellaDirs[FrameworkDir] = Result;
+ Modules[ModuleName] = Result;
+ return Result;
+}
+
static void indent(llvm::raw_ostream &OS, unsigned Spaces) {
OS << std::string(' ', Spaces);
}
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=144877&r1=144876&r2=144877&view=diff
==============================================================================
--- cfe/trunk/test/Modules/auto-module-import.c (original)
+++ cfe/trunk/test/Modules/auto-module-import.c Wed Nov 16 19:41:17 2011
@@ -1,6 +1,6 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -x objective-c -fmodule-cache-path %t -fauto-module-import -F %S/Inputs -verify %s
+// RUN: %clang_cc1 -x objective-c -fmodule-cache-path %t -fauto-module-import -F %S/Inputs %s -verify
#include <DependsOnModule/DependsOnModule.h>
More information about the cfe-commits
mailing list