Skip to content

Commit c03d184

Browse files
committed
[clang] NFCI: Use FileEntryRef in PreamblePatch
1 parent be52db0 commit c03d184

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
390390
const auto &SM = AST.getSourceManager();
391391
include_cleaner::Includes ConvertedIncludes = convertIncludes(AST);
392392
const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID());
393-
auto *PreamblePatch = PreamblePatch::getPatchEntry(AST.tuPath(), SM);
393+
auto PreamblePatch = PreamblePatch::getPatchEntry(AST.tuPath(), SM);
394394

395395
std::vector<include_cleaner::SymbolReference> Macros =
396396
collectMacroReferences(AST);

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,12 +953,10 @@ const MainFileMacros &PreamblePatch::mainFileMacros() const {
953953
return PatchedMacros;
954954
}
955955

956-
const FileEntry *PreamblePatch::getPatchEntry(llvm::StringRef MainFilePath,
957-
const SourceManager &SM) {
956+
OptionalFileEntryRef PreamblePatch::getPatchEntry(llvm::StringRef MainFilePath,
957+
const SourceManager &SM) {
958958
auto PatchFilePath = getPatchName(MainFilePath);
959-
if (auto File = SM.getFileManager().getFile(PatchFilePath))
960-
return *File;
961-
return nullptr;
959+
return SM.getFileManager().getOptionalFileRef(PatchFilePath);
962960
}
963961
} // namespace clangd
964962
} // namespace clang

clang-tools-extra/clangd/Preamble.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ class PreamblePatch {
180180
const PreambleData &Baseline);
181181
/// Returns the FileEntry for the preamble patch of MainFilePath in SM, if
182182
/// any.
183-
static const FileEntry *getPatchEntry(llvm::StringRef MainFilePath,
184-
const SourceManager &SM);
183+
static OptionalFileEntryRef getPatchEntry(llvm::StringRef MainFilePath,
184+
const SourceManager &SM);
185185

186186
/// Adjusts CI (which compiles the modified inputs) to be used with the
187187
/// baseline preamble. This is done by inserting an artificial include to the

clang-tools-extra/clangd/unittests/PreambleTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,9 @@ TEST(PreamblePatch, PatchFileEntry) {
892892
}
893893
{
894894
auto AST = createPatchedAST(Code.code(), NewCode.code());
895-
auto *FE =
895+
auto FE =
896896
PreamblePatch::getPatchEntry(AST->tuPath(), AST->getSourceManager());
897-
ASSERT_NE(FE, nullptr);
897+
ASSERT_NE(FE, std::nullopt);
898898
EXPECT_THAT(FE->getName().str(),
899899
testing::EndsWith(PreamblePatch::HeaderName.str()));
900900
}

0 commit comments

Comments
 (0)