Skip to content

Commit 797cad9

Browse files
committed
[clang] NFCI: Use FileEntryRef in 'clang-tools-extra'
1 parent b19fe81 commit 797cad9

File tree

14 files changed

+42
-45
lines changed

14 files changed

+42
-45
lines changed

clang-tools-extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ typedef std::vector<std::string> TUReplacementFiles;
4040
typedef std::vector<clang::tooling::TranslationUnitDiagnostics> TUDiagnostics;
4141

4242
/// Map mapping file name to a set of AtomicChange targeting that file.
43-
typedef llvm::DenseMap<const clang::FileEntry *,
44-
std::vector<tooling::AtomicChange>>
45-
FileToChangesMap;
43+
using FileToChangesMap =
44+
llvm::DenseMap<clang::FileEntryRef, std::vector<tooling::AtomicChange>>;
4645

4746
/// Recursively descends through a directory structure rooted at \p
4847
/// Directory and attempts to deserialize *.yaml files as

clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ std::error_code collectReplacementsFromDirectory(
138138
///
139139
/// \returns A map mapping FileEntry to a set of Replacement targeting that
140140
/// file.
141-
static llvm::DenseMap<const FileEntry *, std::vector<tooling::Replacement>>
141+
static llvm::DenseMap<FileEntryRef, std::vector<tooling::Replacement>>
142142
groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
143143
const clang::SourceManager &SM) {
144144
llvm::StringSet<> Warned;
145-
llvm::DenseMap<const FileEntry *, std::vector<tooling::Replacement>>
145+
llvm::DenseMap<FileEntryRef, std::vector<tooling::Replacement>>
146146
GroupedReplacements;
147147

148148
// Deduplicate identical replacements in diagnostics unless they are from the
@@ -165,7 +165,7 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
165165
else
166166
SM.getFileManager().makeAbsolutePath(Path);
167167

168-
if (auto Entry = SM.getFileManager().getFile(Path)) {
168+
if (auto Entry = SM.getFileManager().getOptionalFileRef(Path)) {
169169
if (SourceTU) {
170170
auto &Replaces = DiagReplacements[*Entry];
171171
auto It = Replaces.find(R);
@@ -212,10 +212,10 @@ bool mergeAndDeduplicate(const TUReplacements &TUs, const TUDiagnostics &TUDs,
212212
// To report conflicting replacements on corresponding file, all replacements
213213
// are stored into 1 big AtomicChange.
214214
for (const auto &FileAndReplacements : GroupedReplacements) {
215-
const FileEntry *Entry = FileAndReplacements.first;
215+
FileEntryRef Entry = FileAndReplacements.first;
216216
const SourceLocation BeginLoc =
217217
SM.getLocForStartOfFile(SM.getOrCreateFileID(Entry, SrcMgr::C_User));
218-
tooling::AtomicChange FileChange(Entry->getName(), Entry->getName());
218+
tooling::AtomicChange FileChange(Entry.getName(), Entry.getName());
219219
for (const auto &R : FileAndReplacements.second) {
220220
llvm::Error Err =
221221
FileChange.replace(SM, BeginLoc.getLocWithOffset(R.getOffset()),

clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ int main(int argc, char **argv) {
146146
: tooling::ApplyChangesSpec::kNone;
147147

148148
for (const auto &FileChange : Changes) {
149-
const FileEntry *Entry = FileChange.first;
150-
StringRef FileName = Entry->getName();
149+
FileEntryRef Entry = FileChange.first;
150+
StringRef FileName = Entry.getName();
151151
llvm::Expected<std::string> NewFileData =
152152
applyChanges(FileName, FileChange.second, Spec, Diagnostics);
153153
if (!NewFileData) {

clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllMacros.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void FindAllMacros::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
6262
}
6363

6464
void FindAllMacros::EndOfMainFile() {
65-
Reporter->reportSymbols(SM->getFileEntryForID(SM->getMainFileID())->getName(),
66-
FileSymbols);
65+
Reporter->reportSymbols(
66+
SM->getFileEntryRefForID(SM->getMainFileID())->getName(), FileSymbols);
6767
FileSymbols.clear();
6868
}
6969

clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void FindAllSymbols::run(const MatchFinder::MatchResult &Result) {
254254
const SourceManager *SM = Result.SourceManager;
255255
if (auto Symbol = CreateSymbolInfo(ND, *SM, Collector)) {
256256
Filename =
257-
std::string(SM->getFileEntryForID(SM->getMainFileID())->getName());
257+
std::string(SM->getFileEntryRefForID(SM->getMainFileID())->getName());
258258
FileSymbols[*Symbol] += Signals;
259259
}
260260
}

clang-tools-extra/clang-move/Move.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ AST_POLYMORPHIC_MATCHER_P(isExpansionInFile,
115115
auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc());
116116
if (ExpansionLoc.isInvalid())
117117
return false;
118-
auto *FileEntry =
119-
SourceManager.getFileEntryForID(SourceManager.getFileID(ExpansionLoc));
118+
auto FileEntry =
119+
SourceManager.getFileEntryRefForID(SourceManager.getFileID(ExpansionLoc));
120120
if (!FileEntry)
121121
return false;
122122
return MakeAbsolutePath(SourceManager, FileEntry->getName()) ==
@@ -135,7 +135,7 @@ class FindAllIncludes : public PPCallbacks {
135135
StringRef /*RelativePath*/,
136136
const Module * /*Imported*/,
137137
SrcMgr::CharacteristicKind /*FileType*/) override {
138-
if (const auto *FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc)))
138+
if (auto FileEntry = SM.getFileEntryRefForID(SM.getFileID(HashLoc)))
139139
MoveTool->addIncludes(FileName, IsAngled, SearchPath,
140140
FileEntry->getName(), FilenameRange, SM);
141141
}
@@ -341,7 +341,7 @@ bool isInHeaderFile(const Decl *D, llvm::StringRef OriginalRunningDirectory,
341341
if (ExpansionLoc.isInvalid())
342342
return false;
343343

344-
if (const auto *FE = SM.getFileEntryForID(SM.getFileID(ExpansionLoc))) {
344+
if (auto FE = SM.getFileEntryRefForID(SM.getFileID(ExpansionLoc))) {
345345
return MakeAbsolutePath(SM, FE->getName()) ==
346346
MakeAbsolutePath(OriginalRunningDirectory, OldHeader);
347347
}

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
552552
// location needed depends on the check (in particular, where this check wants
553553
// to apply fixes).
554554
FileID FID = Sources.getDecomposedExpansionLoc(Location).first;
555-
const FileEntry *File = Sources.getFileEntryForID(FID);
555+
OptionalFileEntryRef File = Sources.getFileEntryRefForID(FID);
556556

557557
// -DMACRO definitions on the command line have locations in a virtual buffer
558558
// that doesn't have a FileEntry. Don't skip these as well.

clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ AST_POLYMORPHIC_MATCHER(
3434
SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc());
3535
if (Loc.isInvalid())
3636
return false;
37-
const FileEntry *FileEntry =
38-
SourceManager.getFileEntryForID(SourceManager.getFileID(Loc));
37+
OptionalFileEntryRef FileEntry =
38+
SourceManager.getFileEntryRefForID(SourceManager.getFileID(Loc));
3939
if (!FileEntry)
4040
return false;
4141
// Determine whether filepath contains "absl/[absl-library]" substring, where

clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool KernelNameRestrictionPPCallbacks::fileNameIsRestricted(
7676
void KernelNameRestrictionPPCallbacks::EndOfMainFile() {
7777

7878
// Check main file for restricted names.
79-
const FileEntry *Entry = SM.getFileEntryForID(SM.getMainFileID());
79+
OptionalFileEntryRef Entry = SM.getFileEntryRefForID(SM.getMainFileID());
8080
StringRef FileName = llvm::sys::path::filename(Entry->getName());
8181
if (fileNameIsRestricted(FileName))
8282
Check.diag(SM.getLocForStartOfFile(SM.getMainFileID()),

clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
8484
return;
8585
// We don't emit warnings on unused-using-decls from headers, so bail out if
8686
// the main file is a header.
87-
if (const auto *MainFile = Result.SourceManager->getFileEntryForID(
87+
if (auto MainFile = Result.SourceManager->getFileEntryRefForID(
8888
Result.SourceManager->getMainFileID());
8989
utils::isFileExtension(MainFile->getName(), HeaderFileExtensions))
9090
return;

0 commit comments

Comments
 (0)