diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-29 17:08:11 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-29 17:08:11 +0000 |
commit | e434ec71fccfe078906403affd641f709702d598 (patch) | |
tree | e67ed7e1afafc803a337dee6d90b7824223bf763 /lib/Lex/HeaderSearch.cpp | |
parent | 8f95cb328a5f4b5bf6d903b36861b1acc94b0505 (diff) |
Rework HeaderSearch's interface for getting a module from a name and
for getting the name of the module file, unifying the code for
searching for a module with a given name (into lookupModule()) and
separating out the mapping to a module file (into
getModuleFileName()). No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149197 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/HeaderSearch.cpp')
-rw-r--r-- | lib/Lex/HeaderSearch.cpp | 167 |
1 files changed, 71 insertions, 96 deletions
diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index ff63bdb31b..7c981f852b 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -103,79 +103,81 @@ const HeaderMap *HeaderSearch::CreateHeaderMap(const FileEntry *FE) { return 0; } -const FileEntry *HeaderSearch::lookupModule(StringRef ModuleName, - Module *&Module, - std::string *ModuleFileName) { - Module = 0; - +std::string HeaderSearch::getModuleFileName(Module *Module) { // If we don't have a module cache path, we can't do anything. - if (ModuleCachePath.empty()) { - if (ModuleFileName) - ModuleFileName->clear(); - return 0; - } + if (ModuleCachePath.empty()) + return std::string(); + + + llvm::SmallString<256> Result(ModuleCachePath); + llvm::sys::path::append(Result, Module->getTopLevelModule()->Name + ".pcm"); + return Result.str().str(); +} + +std::string HeaderSearch::getModuleFileName(StringRef ModuleName) { + // If we don't have a module cache path, we can't do anything. + if (ModuleCachePath.empty()) + return std::string(); - // Try to find the module path. - llvm::SmallString<256> FileName(ModuleCachePath); - llvm::sys::path::append(FileName, ModuleName + ".pcm"); - if (ModuleFileName) - *ModuleFileName = FileName.str(); - + + llvm::SmallString<256> Result(ModuleCachePath); + llvm::sys::path::append(Result, ModuleName + ".pcm"); + return Result.str().str(); +} + +Module *HeaderSearch::lookupModule(StringRef ModuleName, bool AllowSearch) { // Look in the module map to determine if there is a module by this name. - Module = ModMap.findModule(ModuleName); - if (!Module) { - // Look through the various header search paths to load any avaiable module - // maps, searching for a module map that describes this module. - for (unsigned Idx = 0, N = SearchDirs.size(); Idx != N; ++Idx) { - if (SearchDirs[Idx].isFramework()) { - // Search for or infer a module map for a framework. - llvm::SmallString<128> FrameworkDirName; - FrameworkDirName += SearchDirs[Idx].getFrameworkDir()->getName(); - llvm::sys::path::append(FrameworkDirName, ModuleName + ".framework"); - if (const DirectoryEntry *FrameworkDir - = FileMgr.getDirectory(FrameworkDirName)) { - bool IsSystem - = SearchDirs[Idx].getDirCharacteristic() != SrcMgr::C_User; - Module = getFrameworkModule(ModuleName, FrameworkDir, IsSystem); - if (Module) - break; - } - } - - // FIXME: Figure out how header maps and module maps will work together. - - // Only deal with normal search directories. - if (!SearchDirs[Idx].isNormalDir()) - continue; - - // Search for a module map file in this directory. - if (loadModuleMapFile(SearchDirs[Idx].getDir()) == LMM_NewlyLoaded) { - // We just loaded a module map file; check whether the module is - // available now. - Module = ModMap.findModule(ModuleName); + Module *Module = ModMap.findModule(ModuleName); + if (Module || !AllowSearch) + return Module; + + // Look through the various header search paths to load any avai;able module + // maps, searching for a module map that describes this module. + for (unsigned Idx = 0, N = SearchDirs.size(); Idx != N; ++Idx) { + if (SearchDirs[Idx].isFramework()) { + // Search for or infer a module map for a framework. + llvm::SmallString<128> FrameworkDirName; + FrameworkDirName += SearchDirs[Idx].getFrameworkDir()->getName(); + llvm::sys::path::append(FrameworkDirName, ModuleName + ".framework"); + if (const DirectoryEntry *FrameworkDir + = FileMgr.getDirectory(FrameworkDirName)) { + bool IsSystem + = SearchDirs[Idx].getDirCharacteristic() != SrcMgr::C_User; + Module = loadFrameworkModule(ModuleName, FrameworkDir, IsSystem); if (Module) break; } - - // Search for a module map in a subdirectory with the same name as the - // module. - llvm::SmallString<128> NestedModuleMapDirName; - NestedModuleMapDirName = SearchDirs[Idx].getDir()->getName(); - llvm::sys::path::append(NestedModuleMapDirName, ModuleName); - if (loadModuleMapFile(NestedModuleMapDirName) == LMM_NewlyLoaded) { - // If we just loaded a module map file, look for the module again. - Module = ModMap.findModule(ModuleName); - if (Module) - break; - } + } + + // FIXME: Figure out how header maps and module maps will work together. + + // Only deal with normal search directories. + if (!SearchDirs[Idx].isNormalDir()) + continue; + + // Search for a module map file in this directory. + if (loadModuleMapFile(SearchDirs[Idx].getDir()) == LMM_NewlyLoaded) { + // We just loaded a module map file; check whether the module is + // available now. + Module = ModMap.findModule(ModuleName); + if (Module) + break; + } + + // Search for a module map in a subdirectory with the same name as the + // module. + llvm::SmallString<128> NestedModuleMapDirName; + NestedModuleMapDirName = SearchDirs[Idx].getDir()->getName(); + llvm::sys::path::append(NestedModuleMapDirName, ModuleName); + if (loadModuleMapFile(NestedModuleMapDirName) == LMM_NewlyLoaded) { + // If we just loaded a module map file, look for the module again. + Module = ModMap.findModule(ModuleName); + if (Module) + break; } } - - // Look for the module file in the module cache. - // FIXME: If we didn't find a description of the module itself, should we - // even try to find the module in the cache? - return getFileMgr().getFile(FileName, /*OpenFile=*/false, - /*CacheFailure=*/false); + + return Module; } //===----------------------------------------------------------------------===// @@ -323,7 +325,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup( if (const DirectoryEntry *FrameworkDir = FileMgr.getDirectory(FrameworkName)) { bool IsSystem = getDirCharacteristic() != SrcMgr::C_User; - Module = HS.getFrameworkModule(ModuleName, FrameworkDir, IsSystem); + Module = HS.loadFrameworkModule(ModuleName, FrameworkDir, IsSystem); } } @@ -834,36 +836,9 @@ bool HeaderSearch::loadModuleMapFile(const FileEntry *File) { return Result; } -Module *HeaderSearch::getModule(StringRef Name, bool AllowSearch) { - if (Module *Module = ModMap.findModule(Name)) - return Module; - - if (!AllowSearch) - return 0; - - for (unsigned I = 0, N = SearchDirs.size(); I != N; ++I) { - if (!SearchDirs[I].isNormalDir()) - continue; - - switch (loadModuleMapFile(SearchDirs[I].getDir())) { - case LMM_AlreadyLoaded: - case LMM_InvalidModuleMap: - case LMM_NoDirectory: - break; - - case LMM_NewlyLoaded: - if (Module *Module = ModMap.findModule(Name)) - return Module; - break; - } - } - - return 0; -} - -Module *HeaderSearch::getFrameworkModule(StringRef Name, - const DirectoryEntry *Dir, - bool IsSystem) { +Module *HeaderSearch::loadFrameworkModule(StringRef Name, + const DirectoryEntry *Dir, + bool IsSystem) { if (Module *Module = ModMap.findModule(Name)) return Module; |