[clang] 7bca6f4 - [clang] Use `{File,Directory}EntryRef` in modular header search (part 2/2)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 15 02:22:37 PDT 2023
Author: Jan Svoboda
Date: 2023-06-15T11:22:31+02:00
New Revision: 7bca6f452f53a4a8d31a56b480e5b9fbaabad4fb
URL: https://github.com/llvm/llvm-project/commit/7bca6f452f53a4a8d31a56b480e5b9fbaabad4fb
DIFF: https://github.com/llvm/llvm-project/commit/7bca6f452f53a4a8d31a56b480e5b9fbaabad4fb.diff
LOG: [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
Added:
Modified:
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/ModuleMap.cpp
clang/test/Modules/crash-vfs-umbrella-frameworks.m
Removed:
################################################################################
diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h
index 131dbdcc20007..4906fa94e8ab6 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -638,7 +638,7 @@ class HeaderSearch {
/// 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
diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 83c227b38e1bb..8f3f234036d26 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -487,11 +487,11 @@ class ModuleMap {
/// 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.
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index d94fe09274ed6..723479ca4fbbc 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -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))
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index c620eb7769742..56329410c87da 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -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;
diff --git a/clang/test/Modules/crash-vfs-umbrella-frameworks.m b/clang/test/Modules/crash-vfs-umbrella-frameworks.m
index d097ffb81a03f..3861dfb36819b 100644
--- a/clang/test/Modules/crash-vfs-umbrella-frameworks.m
+++ b/clang/test/Modules/crash-vfs-umbrella-frameworks.m
@@ -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',
More information about the cfe-commits
mailing list