Skip to content

Commit

Permalink
[clang] NFC: Use DirectoryEntryRef in `FileManager::getCanonicalNam…
Browse files Browse the repository at this point in the history
…e()`

This patch removes the last use of deprecated `DirectoryEntry::getName()`.

Depends on D151855.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D151922
  • Loading branch information
jansvoboda11 committed Jun 15, 2023
1 parent 7bca6f4 commit 1dee56a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-move/Move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::string MakeAbsolutePath(const SourceManager &SM, StringRef Path) {
<< '\n';
// Handle symbolic link path cases.
// We are trying to get the real file path of the symlink.
auto Dir = SM.getFileManager().getDirectory(
auto Dir = SM.getFileManager().getOptionalDirectoryRef(
llvm::sys::path::parent_path(AbsolutePath.str()));
if (Dir) {
StringRef DirName = SM.getFileManager().getCanonicalName(*Dir);
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/SourceCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ std::optional<std::string> getCanonicalPath(const FileEntryRef F,
//
// The file path of Symbol is "/project/src/foo.h" instead of
// "/tmp/build/foo.h"
if (auto Dir = FileMgr.getDirectory(
if (auto Dir = FileMgr.getOptionalDirectoryRef(
llvm::sys::path::parent_path(FilePath))) {
llvm::SmallString<128> RealPath;
llvm::StringRef DirName = FileMgr.getCanonicalName(*Dir);
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/FileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class FileManager : public RefCountedBase<FileManager> {
/// This is a very expensive operation, despite its results being cached,
/// and should only be used when the physical layout of the file system is
/// required, which is (almost) never.
StringRef getCanonicalName(const DirectoryEntry *Dir);
StringRef getCanonicalName(DirectoryEntryRef Dir);

/// Retrieve the canonical name for a given file.
///
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/Basic/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,16 +631,15 @@ void FileManager::GetUniqueIDMapping(
UIDToFiles[VFE->getUID()] = VFE;
}

StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
llvm::DenseMap<const void *, llvm::StringRef>::iterator Known
= CanonicalNames.find(Dir);
StringRef FileManager::getCanonicalName(DirectoryEntryRef Dir) {
auto Known = CanonicalNames.find(Dir);
if (Known != CanonicalNames.end())
return Known->second;

StringRef CanonicalName(Dir->getName());
StringRef CanonicalName(Dir.getName());

SmallString<4096> CanonicalNameBuf;
if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf))
if (!FS->getRealPath(Dir.getName(), CanonicalNameBuf))
CanonicalName = CanonicalNameBuf.str().copy(CanonicalNameStorage);

CanonicalNames.insert({Dir, CanonicalName});
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,9 +1319,9 @@ ModuleMap::canonicalizeModuleMapPath(SmallVectorImpl<char> &Path) {
}

FileManager &FM = SourceMgr.getFileManager();
auto DirEntry = FM.getDirectory(Dir.empty() ? "." : Dir);
auto DirEntry = FM.getDirectoryRef(Dir.empty() ? "." : Dir);
if (!DirEntry)
return DirEntry.getError();
return llvm::errorToErrorCode(DirEntry.takeError());

// Canonicalize the directory.
StringRef CanonicalDir = FM.getCanonicalName(*DirEntry);
Expand Down

0 comments on commit 1dee56a

Please sign in to comment.