diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-11-11 22:18:48 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-11-11 22:18:48 +0000 |
commit | 65f3b5e99009f49d51eb00a859dbd2c2ee660718 (patch) | |
tree | bfe0e47aa7bbb690bd96e44adb23a058e196fd07 | |
parent | 8b6d3deb5af464e1afbbeccdec369c5d4252b1a0 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144410 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Lex/HeaderSearch.h | 2 | ||||
-rw-r--r-- | include/clang/Lex/ModuleMap.h | 17 | ||||
-rw-r--r-- | lib/Lex/HeaderSearch.cpp | 8 | ||||
-rw-r--r-- | lib/Lex/ModuleMap.cpp | 17 | ||||
-rw-r--r-- | test/Modules/normal-module-map.cpp | 6 |
5 files changed, 42 insertions, 8 deletions
diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h index 995deab9dc..87242c4372 100644 --- a/include/clang/Lex/HeaderSearch.h +++ b/include/clang/Lex/HeaderSearch.h @@ -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(); } diff --git a/include/clang/Lex/ModuleMap.h b/include/clang/Lex/ModuleMap.h index 2834f6a11b..291f2bbdec 100644 --- a/include/clang/Lex/ModuleMap.h +++ b/include/clang/Lex/ModuleMap.h @@ -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(); }; diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 6403cfb868..4522de5cf3 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -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(); } diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index 8adb22014b..7defe01a67 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -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); } diff --git a/test/Modules/normal-module-map.cpp b/test/Modules/normal-module-map.cpp index 2935c8baa9..b6f584d33c 100644 --- a/test/Modules/normal-module-map.cpp +++ b/test/Modules/normal-module-map.cpp @@ -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" |