[clang] Use {File,Directory}EntryRef in modular header search (part 2/2)

This patch removes some deprecated uses of `{File,Directory}Entry::getName()`. No functional change intended.

Depends on D151854.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D151855
This commit is contained in:
Jan Svoboda
2023-06-15 10:47:27 +02:00
parent 253afd03f1
commit 7bca6f452f
5 changed files with 19 additions and 32 deletions

View File

@@ -638,7 +638,7 @@ public:
/// Try to find a module map file in the given directory, returning
/// \c nullopt if none is found.
OptionalFileEntryRef lookupModuleMapFile(const DirectoryEntry *Dir,
OptionalFileEntryRef lookupModuleMapFile(DirectoryEntryRef Dir,
bool IsFramework);
/// Determine whether there is a module map that may map the header

View File

@@ -487,11 +487,11 @@ public:
/// Determine whether the given header is part of a module
/// marked 'unavailable'.
bool isHeaderInUnavailableModule(const FileEntry *Header) const;
bool isHeaderInUnavailableModule(FileEntryRef Header) const;
/// Determine whether the given header is unavailable as part
/// of the specified module.
bool isHeaderUnavailableInModule(const FileEntry *Header,
bool isHeaderUnavailableInModule(FileEntryRef Header,
const Module *RequestingModule) const;
/// Retrieve a module with the given name.

View File

@@ -1751,12 +1751,12 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
}
OptionalFileEntryRef
HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
HeaderSearch::lookupModuleMapFile(DirectoryEntryRef Dir, bool IsFramework) {
if (!HSOpts->ImplicitModuleMaps)
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());
SmallString<128> ModuleMapFileName(Dir.getName());
if (IsFramework)
llvm::sys::path::append(ModuleMapFileName, "Modules");
llvm::sys::path::append(ModuleMapFileName, "module.modulemap");
@@ -1764,7 +1764,7 @@ HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
return *F;
// Continue to allow module.map
ModuleMapFileName = Dir->getName();
ModuleMapFileName = Dir.getName();
llvm::sys::path::append(ModuleMapFileName, "module.map");
if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))
return *F;
@@ -1772,7 +1772,7 @@ HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
// For frameworks, allow to have a private module map with a preferred
// spelling when a public module map is absent.
if (IsFramework) {
ModuleMapFileName = Dir->getName();
ModuleMapFileName = Dir.getName();
llvm::sys::path::append(ModuleMapFileName, "Modules",
"module.private.modulemap");
if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName))

View File

@@ -700,13 +700,12 @@ ModuleMap::findResolvedModulesForHeader(const FileEntry *File) const {
return It->second;
}
bool ModuleMap::isHeaderInUnavailableModule(const FileEntry *Header) const {
bool ModuleMap::isHeaderInUnavailableModule(FileEntryRef Header) const {
return isHeaderUnavailableInModule(Header, nullptr);
}
bool
ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
const Module *RequestingModule) const {
bool ModuleMap::isHeaderUnavailableInModule(
FileEntryRef Header, const Module *RequestingModule) const {
resolveHeaderDirectives(Header);
HeadersMap::const_iterator Known = Headers.find(Header);
if (Known != Headers.end()) {
@@ -734,8 +733,8 @@ ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
return true;
}
const DirectoryEntry *Dir = Header->getDir();
SmallVector<const DirectoryEntry *, 2> SkippedDirs;
OptionalDirectoryEntryRef Dir = Header.getDir();
SmallVector<DirectoryEntryRef, 2> SkippedDirs;
StringRef DirName = Dir->getName();
auto IsUnavailable = [&](const Module *M) {
@@ -746,8 +745,7 @@ ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
// Keep walking up the directory hierarchy, looking for a directory with
// an umbrella header.
do {
llvm::DenseMap<const DirectoryEntry *, Module *>::const_iterator KnownDir
= UmbrellaDirs.find(Dir);
auto KnownDir = UmbrellaDirs.find(*Dir);
if (KnownDir != UmbrellaDirs.end()) {
Module *Found = KnownDir->second;
if (IsUnavailable(Found))
@@ -761,11 +759,11 @@ ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
UmbrellaModule = UmbrellaModule->Parent;
if (UmbrellaModule->InferSubmodules) {
for (const DirectoryEntry *SkippedDir : llvm::reverse(SkippedDirs)) {
for (DirectoryEntryRef SkippedDir : llvm::reverse(SkippedDirs)) {
// Find or create the module that corresponds to this directory name.
SmallString<32> NameBuf;
StringRef Name = sanitizeFilenameAsIdentifier(
llvm::sys::path::stem(SkippedDir->getName()), NameBuf);
llvm::sys::path::stem(SkippedDir.getName()), NameBuf);
Found = lookupModuleQualified(Name, Found);
if (!Found)
return false;
@@ -776,7 +774,7 @@ ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
// Infer a submodule with the same name as this header file.
SmallString<32> NameBuf;
StringRef Name = sanitizeFilenameAsIdentifier(
llvm::sys::path::stem(Header->getName()),
llvm::sys::path::stem(Header.getName()),
NameBuf);
Found = lookupModuleQualified(Name, Found);
if (!Found)
@@ -786,7 +784,7 @@ ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
return IsUnavailable(Found);
}
SkippedDirs.push_back(Dir);
SkippedDirs.push_back(*Dir);
// Retrieve our parent path.
DirName = llvm::sys::path::parent_path(DirName);
@@ -794,10 +792,7 @@ ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
break;
// Resolve the parent path to a directory entry.
if (auto DirEntry = SourceMgr.getFileManager().getDirectory(DirName))
Dir = *DirEntry;
else
Dir = nullptr;
Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
} while (Dir);
return false;

View File

@@ -24,15 +24,7 @@
// CHECK-NEXT: note: diagnostic msg: {{.*}}.cache
// CHECKYAML: 'type': 'directory',
// CHECKYAML: 'name': "/[[PATH:.*]]/i/Frameworks/A.framework/Frameworks/B.framework/Headers",
// CHECKYAML-NEXT: 'contents': [
// CHECKYAML-NEXT: {
// CHECKYAML-NEXT: 'type': 'file',
// CHECKYAML-NEXT: 'name': "B.h",
// CHECKYAML-NEXT: 'external-contents': "/[[PATH]]/i/Frameworks/B.framework/Headers/B.h"
// CHECKYAML: 'type': 'directory',
// CHECKYAML: 'name': "/[[PATH]]/i/Frameworks/B.framework/Headers",
// CHECKYAML: 'name': "/[[PATH:.*]]/i/Frameworks/B.framework/Headers",
// CHECKYAML-NEXT: 'contents': [
// CHECKYAML-NEXT: {
// CHECKYAML-NEXT: 'type': 'file',