aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2023-05-25 12:38:45 -0700
committerJan Svoboda <jan_svoboda@apple.com>2023-05-30 13:54:06 -0700
commit769d282d7292d14591a721ee967962736160095e (patch)
tree4fad903fe329c8e8443108aeff690171f0e677b6 /clang/lib
parent9e8a412cb37d2a1201bd33878fce0993587ef335 (diff)
downloadllvm-769d282d7292d14591a721ee967962736160095e.zip
llvm-769d282d7292d14591a721ee967962736160095e.tar.gz
llvm-769d282d7292d14591a721ee967962736160095e.tar.bz2
[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
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Frontend/FrontendAction.cpp9
-rw-r--r--clang/lib/Lex/HeaderSearch.cpp33
-rw-r--r--clang/lib/Lex/ModuleMap.cpp6
3 files changed, 23 insertions, 25 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index bd6d1b0..7ef480b 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -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
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index d09d3ae..7df1ca1 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -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
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 0db7ebf..adaad64 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -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);
}