Skip to content

Commit 5a3130e

Browse files
committed
[clang] NFCI: Use FileEntryRef in FileManager::getCanonicalName()
1 parent f5592f3 commit 5a3130e

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

clang/include/clang/Basic/FileManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class FileManager : public RefCountedBase<FileManager> {
327327
/// This is a very expensive operation, despite its results being cached,
328328
/// and should only be used when the physical layout of the file system is
329329
/// required, which is (almost) never.
330-
StringRef getCanonicalName(const FileEntry *File);
330+
StringRef getCanonicalName(FileEntryRef File);
331331

332332
private:
333333
/// Retrieve the canonical name for a given file or directory.

clang/lib/Basic/FileManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ StringRef FileManager::getCanonicalName(DirectoryEntryRef Dir) {
636636
return getCanonicalName(Dir, Dir.getName());
637637
}
638638

639-
StringRef FileManager::getCanonicalName(const FileEntry *File) {
640-
return getCanonicalName(File, File->getName());
639+
StringRef FileManager::getCanonicalName(FileEntryRef File) {
640+
return getCanonicalName(File, File.getName());
641641
}
642642

643643
StringRef FileManager::getCanonicalName(const void *Entry, StringRef Name) {

clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,17 @@ struct LocationFileChecker {
177177
if (FID.isInvalid())
178178
return false;
179179

180-
const auto *File = SM.getFileEntryForID(FID);
180+
OptionalFileEntryRef File = SM.getFileEntryRefForID(FID);
181181
if (!File)
182182
return false;
183183

184-
if (KnownFileEntries.count(File))
184+
if (KnownFileEntries.count(*File))
185185
return true;
186186

187-
if (ExternalFileEntries.count(File))
187+
if (ExternalFileEntries.count(*File))
188188
return false;
189189

190-
StringRef FileName = SM.getFileManager().getCanonicalName(File);
190+
StringRef FileName = SM.getFileManager().getCanonicalName(*File);
191191

192192
// Try to reduce the include name the same way we tried to include it.
193193
bool IsQuoted = false;
@@ -197,13 +197,13 @@ struct LocationFileChecker {
197197
return KnownFile.first.equals(*IncludeName) &&
198198
KnownFile.second == IsQuoted;
199199
})) {
200-
KnownFileEntries.insert(File);
200+
KnownFileEntries.insert(*File);
201201
return true;
202202
}
203203

204204
// Record that the file was not found to avoid future reverse lookup for
205205
// the same file.
206-
ExternalFileEntries.insert(File);
206+
ExternalFileEntries.insert(*File);
207207
return false;
208208
}
209209

clang/lib/Frontend/DependencyFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void DependencyCollector::maybeAddDependency(StringRef Filename,
159159
bool IsMissing) {
160160
if (sawDependency(Filename, FromModule, IsSystem, IsModuleFile, IsMissing)) {
161161
if (IsSystem && FileMgr && shouldCanonicalizeSystemDependencies()) {
162-
if (auto F = FileMgr->getFile(Filename))
162+
if (auto F = FileMgr->getOptionalFileRef(Filename))
163163
Filename = FileMgr->getCanonicalName(*F);
164164
}
165165
addDependency(Filename);

clang/lib/Frontend/SARIFDiagnostic.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ SARIFDiagnostic::addDiagnosticLevelToRule(SarifRule Rule,
164164
llvm::StringRef SARIFDiagnostic::emitFilename(StringRef Filename,
165165
const SourceManager &SM) {
166166
if (DiagOpts->AbsolutePath) {
167-
llvm::ErrorOr<const FileEntry *> File =
168-
SM.getFileManager().getFile(Filename);
167+
auto File = SM.getFileManager().getOptionalFileRef(Filename);
169168
if (File) {
170169
// We want to print a simplified absolute path, i. e. without "dots".
171170
//
@@ -182,7 +181,7 @@ llvm::StringRef SARIFDiagnostic::emitFilename(StringRef Filename,
182181
// on Windows we can just use llvm::sys::path::remove_dots(), because,
183182
// on that system, both aforementioned paths point to the same place.
184183
#ifdef _WIN32
185-
SmallString<256> TmpFilename = (*File)->getName();
184+
SmallString<256> TmpFilename = File->getName();
186185
llvm::sys::fs::make_absolute(TmpFilename);
187186
llvm::sys::path::native(TmpFilename);
188187
llvm::sys::path::remove_dots(TmpFilename, /* remove_dot_dot */ true);

clang/lib/Frontend/TextDiagnostic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ void TextDiagnostic::emitFilename(StringRef Filename, const SourceManager &SM) {
736736
SmallString<4096> TmpFilename;
737737
#endif
738738
if (DiagOpts->AbsolutePath) {
739-
auto File = SM.getFileManager().getFile(Filename);
739+
auto File = SM.getFileManager().getOptionalFileRef(Filename);
740740
if (File) {
741741
// We want to print a simplified absolute path, i. e. without "dots".
742742
//
@@ -753,7 +753,7 @@ void TextDiagnostic::emitFilename(StringRef Filename, const SourceManager &SM) {
753753
// on Windows we can just use llvm::sys::path::remove_dots(), because,
754754
// on that system, both aforementioned paths point to the same place.
755755
#ifdef _WIN32
756-
TmpFilename = (*File)->getName();
756+
TmpFilename = File->getName();
757757
llvm::sys::fs::make_absolute(TmpFilename);
758758
llvm::sys::path::native(TmpFilename);
759759
llvm::sys::path::remove_dots(TmpFilename, /* remove_dot_dot */ true);

0 commit comments

Comments
 (0)