/// \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(); }
/// \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:
/// \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.
///
///
/// \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();
};
// 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;
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();
}
return Result;
}
+StringRef ModuleMap::Module::getTopLevelModuleName() const {
+ const Module *Top = this;
+ while (Top->Parent)
+ Top = Top->Parent;
+
+ return Top->Name;
+}
+
//----------------------------------------------------------------------------//
// Module map
//----------------------------------------------------------------------------//
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);
}
// 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"