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. llvm-svn: 144410
This commit is contained in:
parent
28c1d18434
commit
ab0c8a849a
|
@ -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(); }
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue