[cfe-commits] r144424 - in /cfe/trunk: include/clang/Lex/ModuleMap.h lib/Lex/HeaderSearch.cpp lib/Lex/ModuleMap.cpp test/Modules/Inputs/normal-module-map/Umbrella/ test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h test/Modules/Inputs/normal-module-map/Umbrella/module.map test/Modules/normal-module-map.cpp
Douglas Gregor
dgregor at apple.com
Fri Nov 11 15:20:24 PST 2011
Author: dgregor
Date: Fri Nov 11 17:20:24 2011
New Revision: 144424
URL: http://llvm.org/viewvc/llvm-project?rev=144424&view=rev
Log:
Teach the search for modules to consider modules described by a module
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.
Added:
cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/
cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h (with props)
cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/module.map
Modified:
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/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=144424&r1=144423&r2=144424&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Fri Nov 11 17:20:24 2011
@@ -89,7 +89,7 @@
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 @@
/// 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.
///
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=144424&r1=144423&r2=144424&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Nov 11 17:20:24 2011
@@ -127,9 +127,19 @@
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 += '/';
Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=144424&r1=144423&r2=144424&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Nov 11 17:20:24 2011
@@ -84,6 +84,14 @@
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);
}
Added: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h?rev=144424&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h (added)
+++ cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h Fri Nov 11 17:20:24 2011
@@ -0,0 +1 @@
+int umbrella;
Propchange: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/Umbrella.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/module.map?rev=144424&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/module.map (added)
+++ cfe/trunk/test/Modules/Inputs/normal-module-map/Umbrella/module.map Fri Nov 11 17:20:24 2011
@@ -0,0 +1,3 @@
+module Umbrella {
+ umbrella "Umbrella.h"
+}
\ No newline at end of file
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=144424&r1=144423&r2=144424&view=diff
==============================================================================
--- cfe/trunk/test/Modules/normal-module-map.cpp (original)
+++ cfe/trunk/test/Modules/normal-module-map.cpp Fri Nov 11 17:20:24 2011
@@ -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"
More information about the cfe-commits
mailing list