Author: Jan Svoboda Date: 2023-09-20T16:10:18-07:00 New Revision: c03d18441c94a69c0b32a7882a66c8cc95c6e928
URL: https://github.com/llvm/llvm-project/commit/c03d18441c94a69c0b32a7882a66c8cc95c6e928 DIFF: https://github.com/llvm/llvm-project/commit/c03d18441c94a69c0b32a7882a66c8cc95c6e928.diff LOG: [clang] NFCI: Use `FileEntryRef` in `PreamblePatch` Added: Modified: clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/Preamble.h clang-tools-extra/clangd/unittests/PreambleTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp index d3ee7591edf09d8..a299347e8c0c3e6 100644 --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -390,7 +390,7 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) { const auto &SM = AST.getSourceManager(); include_cleaner::Includes ConvertedIncludes = convertIncludes(AST); const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID()); - auto *PreamblePatch = PreamblePatch::getPatchEntry(AST.tuPath(), SM); + auto PreamblePatch = PreamblePatch::getPatchEntry(AST.tuPath(), SM); std::vector<include_cleaner::SymbolReference> Macros = collectMacroReferences(AST); diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp index 60c0f936d6f3810..8084e9644b426fc 100644 --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -953,12 +953,10 @@ const MainFileMacros &PreamblePatch::mainFileMacros() const { return PatchedMacros; } -const FileEntry *PreamblePatch::getPatchEntry(llvm::StringRef MainFilePath, - const SourceManager &SM) { +OptionalFileEntryRef PreamblePatch::getPatchEntry(llvm::StringRef MainFilePath, + const SourceManager &SM) { auto PatchFilePath = getPatchName(MainFilePath); - if (auto File = SM.getFileManager().getFile(PatchFilePath)) - return *File; - return nullptr; + return SM.getFileManager().getOptionalFileRef(PatchFilePath); } } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/clangd/Preamble.h b/clang-tools-extra/clangd/Preamble.h index 21a281aac0cce95..37da3833748a9c6 100644 --- a/clang-tools-extra/clangd/Preamble.h +++ b/clang-tools-extra/clangd/Preamble.h @@ -180,8 +180,8 @@ class PreamblePatch { const PreambleData &Baseline); /// Returns the FileEntry for the preamble patch of MainFilePath in SM, if /// any. - static const FileEntry *getPatchEntry(llvm::StringRef MainFilePath, - const SourceManager &SM); + static OptionalFileEntryRef getPatchEntry(llvm::StringRef MainFilePath, + const SourceManager &SM); /// Adjusts CI (which compiles the modified inputs) to be used with the /// baseline preamble. This is done by inserting an artificial include to the diff --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp b/clang-tools-extra/clangd/unittests/PreambleTests.cpp index 6da98c55e392706..3e9ed5304376452 100644 --- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp +++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp @@ -892,9 +892,9 @@ TEST(PreamblePatch, PatchFileEntry) { } { auto AST = createPatchedAST(Code.code(), NewCode.code()); - auto *FE = + auto FE = PreamblePatch::getPatchEntry(AST->tuPath(), AST->getSourceManager()); - ASSERT_NE(FE, nullptr); + ASSERT_NE(FE, std::nullopt); EXPECT_THAT(FE->getName().str(), testing::EndsWith(PreamblePatch::HeaderName.str())); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits