[clang][lex] NFCI: Use FileEntryRef in ModuleMap::{load,lookup}ModuleMap()
This patch changes the return/argument types of `ModuleMap::{load,lookup}ModuleMap()` from `const FileEntry *` to `FileEntryRef` in order to remove uses of the deprecated `DirectoryEntry::getName()`.
Reviewed By: bnbarham
Differential Revision: https://reviews.llvm.org/D127647
This commit is contained in:
@@ -637,9 +637,9 @@ public:
|
||||
bool AllowExtraModuleMapSearch = false);
|
||||
|
||||
/// Try to find a module map file in the given directory, returning
|
||||
/// \c nullptr if none is found.
|
||||
const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir,
|
||||
bool IsFramework);
|
||||
/// \c nullopt if none is found.
|
||||
OptionalFileEntryRef lookupModuleMapFile(const DirectoryEntry *Dir,
|
||||
bool IsFramework);
|
||||
|
||||
/// Determine whether there is a module map that may map the header
|
||||
/// with the given file name to a (sub)module.
|
||||
@@ -686,8 +686,8 @@ public:
|
||||
/// used to resolve paths within the module (this is required when
|
||||
/// building the module from preprocessed source).
|
||||
/// \returns true if an error occurred, false otherwise.
|
||||
bool loadModuleMapFile(const FileEntry *File, bool IsSystem,
|
||||
FileID ID = FileID(), unsigned *Offset = nullptr,
|
||||
bool loadModuleMapFile(FileEntryRef File, bool IsSystem, FileID ID = FileID(),
|
||||
unsigned *Offset = nullptr,
|
||||
StringRef OriginalModuleMapFile = StringRef());
|
||||
|
||||
/// Collect the set of all known, top-level modules.
|
||||
@@ -904,8 +904,7 @@ private:
|
||||
LMM_InvalidModuleMap
|
||||
};
|
||||
|
||||
LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File,
|
||||
bool IsSystem,
|
||||
LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
|
||||
DirectoryEntryRef Dir,
|
||||
FileID ID = FileID(),
|
||||
unsigned *Offset = nullptr);
|
||||
|
||||
@@ -447,7 +447,8 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
|
||||
|
||||
// Map the current input to a file.
|
||||
FileID ModuleMapID = SrcMgr.getMainFileID();
|
||||
const FileEntry *ModuleMap = SrcMgr.getFileEntryForID(ModuleMapID);
|
||||
OptionalFileEntryRef ModuleMap = SrcMgr.getFileEntryRefForID(ModuleMapID);
|
||||
assert(ModuleMap && "MainFileID without FileEntry");
|
||||
|
||||
// If the module map is preprocessed, handle the initial line marker;
|
||||
// line directives are not part of the module map syntax in general.
|
||||
@@ -460,7 +461,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
|
||||
}
|
||||
|
||||
// Load the module map file.
|
||||
if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset,
|
||||
if (HS.loadModuleMapFile(*ModuleMap, IsSystem, ModuleMapID, &Offset,
|
||||
PresumedModuleMapFile))
|
||||
return true;
|
||||
|
||||
@@ -469,7 +470,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
|
||||
|
||||
// Infer framework module if possible.
|
||||
if (HS.getModuleMap().canInferFrameworkModule(ModuleMap->getDir())) {
|
||||
SmallString<128> InferredFrameworkPath = ModuleMap->getDir()->getName();
|
||||
SmallString<128> InferredFrameworkPath = ModuleMap->getDir().getName();
|
||||
llvm::sys::path::append(InferredFrameworkPath,
|
||||
CI.getLangOpts().ModuleName + ".framework");
|
||||
if (auto Dir = CI.getFileManager().getDirectory(InferredFrameworkPath))
|
||||
@@ -910,7 +911,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
|
||||
|
||||
// If we were asked to load any module map files, do so now.
|
||||
for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
|
||||
if (auto File = CI.getFileManager().getFile(Filename))
|
||||
if (auto File = CI.getFileManager().getOptionalFileRef(Filename))
|
||||
CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile(
|
||||
*File, /*IsSystem*/false);
|
||||
else
|
||||
|
||||
@@ -1654,10 +1654,10 @@ bool HeaderSearch::findUsableModuleForFrameworkHeader(
|
||||
return true;
|
||||
}
|
||||
|
||||
static const FileEntry *getPrivateModuleMap(const FileEntry *File,
|
||||
static const FileEntry *getPrivateModuleMap(FileEntryRef File,
|
||||
FileManager &FileMgr) {
|
||||
StringRef Filename = llvm::sys::path::filename(File->getName());
|
||||
SmallString<128> PrivateFilename(File->getDir()->getName());
|
||||
StringRef Filename = llvm::sys::path::filename(File.getName());
|
||||
SmallString<128> PrivateFilename(File.getDir().getName());
|
||||
if (Filename == "module.map")
|
||||
llvm::sys::path::append(PrivateFilename, "module_private.map");
|
||||
else if (Filename == "module.modulemap")
|
||||
@@ -1669,7 +1669,7 @@ static const FileEntry *getPrivateModuleMap(const FileEntry *File,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,
|
||||
bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem,
|
||||
FileID ID, unsigned *Offset,
|
||||
StringRef OriginalModuleMapFile) {
|
||||
// Find the directory for the module. For frameworks, that may require going
|
||||
@@ -1688,9 +1688,7 @@ bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,
|
||||
Dir = FakeFile.getDir();
|
||||
}
|
||||
} else {
|
||||
// TODO: Replace with `Dir = File.getDir()` when `File` is switched to
|
||||
// `FileEntryRef`.
|
||||
Dir = FileMgr.getOptionalDirectoryRef(File->getDir()->getName());
|
||||
Dir = File.getDir();
|
||||
}
|
||||
|
||||
assert(Dir && "parent must exist");
|
||||
@@ -1719,11 +1717,9 @@ bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,
|
||||
}
|
||||
|
||||
HeaderSearch::LoadModuleMapResult
|
||||
HeaderSearch::loadModuleMapFileImpl(const FileEntry *File, bool IsSystem,
|
||||
HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
|
||||
DirectoryEntryRef Dir, FileID ID,
|
||||
unsigned *Offset) {
|
||||
assert(File && "expected FileEntry");
|
||||
|
||||
// Check whether we've already loaded this module map, and mark it as being
|
||||
// loaded in case we recursively try to load it from itself.
|
||||
auto AddResult = LoadedModuleMaps.insert(std::make_pair(File, true));
|
||||
@@ -1747,23 +1743,23 @@ HeaderSearch::loadModuleMapFileImpl(const FileEntry *File, bool IsSystem,
|
||||
return LMM_NewlyLoaded;
|
||||
}
|
||||
|
||||
const FileEntry *
|
||||
OptionalFileEntryRef
|
||||
HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
|
||||
if (!HSOpts->ImplicitModuleMaps)
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
// For frameworks, the preferred spelling is Modules/module.modulemap, but
|
||||
// module.map at the framework root is also accepted.
|
||||
SmallString<128> ModuleMapFileName(Dir->getName());
|
||||
if (IsFramework)
|
||||
llvm::sys::path::append(ModuleMapFileName, "Modules");
|
||||
llvm::sys::path::append(ModuleMapFileName, "module.modulemap");
|
||||
if (auto F = FileMgr.getFile(ModuleMapFileName))
|
||||
if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
|
||||
return *F;
|
||||
|
||||
// Continue to allow module.map
|
||||
ModuleMapFileName = Dir->getName();
|
||||
llvm::sys::path::append(ModuleMapFileName, "module.map");
|
||||
if (auto F = FileMgr.getFile(ModuleMapFileName))
|
||||
if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
|
||||
return *F;
|
||||
|
||||
// For frameworks, allow to have a private module map with a preferred
|
||||
@@ -1772,10 +1768,10 @@ HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
|
||||
ModuleMapFileName = Dir->getName();
|
||||
llvm::sys::path::append(ModuleMapFileName, "Modules",
|
||||
"module.private.modulemap");
|
||||
if (auto F = FileMgr.getFile(ModuleMapFileName))
|
||||
if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
|
||||
return *F;
|
||||
}
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Module *HeaderSearch::loadFrameworkModule(StringRef Name, DirectoryEntryRef Dir,
|
||||
@@ -1818,9 +1814,10 @@ HeaderSearch::loadModuleMapFile(DirectoryEntryRef Dir, bool IsSystem,
|
||||
if (KnownDir != DirectoryHasModuleMap.end())
|
||||
return KnownDir->second ? LMM_AlreadyLoaded : LMM_InvalidModuleMap;
|
||||
|
||||
if (const FileEntry *ModuleMapFile = lookupModuleMapFile(Dir, IsFramework)) {
|
||||
if (OptionalFileEntryRef ModuleMapFile =
|
||||
lookupModuleMapFile(Dir, IsFramework)) {
|
||||
LoadModuleMapResult Result =
|
||||
loadModuleMapFileImpl(ModuleMapFile, IsSystem, Dir);
|
||||
loadModuleMapFileImpl(*ModuleMapFile, IsSystem, Dir);
|
||||
// Add Dir explicitly in case ModuleMapFile is in a subdirectory.
|
||||
// E.g. Foo.framework/Modules/module.modulemap
|
||||
// ^Dir ^ModuleMapFile
|
||||
|
||||
@@ -1019,9 +1019,9 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
|
||||
// We haven't looked here before. Load a module map, if there is
|
||||
// one.
|
||||
bool IsFrameworkDir = Parent.endswith(".framework");
|
||||
if (const FileEntry *ModMapFile =
|
||||
HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
|
||||
parseModuleMapFile(ModMapFile, Attrs.IsSystem, *ParentDir);
|
||||
if (OptionalFileEntryRef ModMapFile =
|
||||
HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
|
||||
parseModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir);
|
||||
inferred = InferredDirectories.find(*ParentDir);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user