From f8d2778b659a12a94b60258f949373ad42f964a1 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 1 Feb 2024 23:58:38 -0800 Subject: [PATCH] Adapt llvm/llvm-project#74910: FileEntry::getName Based on a patch by @zsrkmyn --- src/clang_tu.cc | 8 ++++++++ src/clang_tu.hh | 4 ++++ src/indexer.cc | 19 ++++++++++++++++++- src/sema_manager.cc | 8 ++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 1800e2d2..2cf8f70f 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -23,13 +23,21 @@ using namespace clang; namespace ccls { +#if LLVM_VERSION_MAJOR < 19 std::string pathFromFileEntry(const FileEntry &file) { +#else +std::string pathFromFileEntry(FileEntryRef file) { +#endif std::string ret; if (file.getName().startswith("/../")) { // Resolve symlinks outside of working folders. This handles leading path // components, e.g. (/lib -> /usr/lib) in // /../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/utility +#if LLVM_VERSION_MAJOR < 19 ret = file.tryGetRealPathName(); +#else + ret = file.getFileEntry().tryGetRealPathName(); +#endif } else { // If getName() refers to a file within a workspace folder, we prefer it // (which may be a symlink). diff --git a/src/clang_tu.hh b/src/clang_tu.hh index 7dbfc4a8..cba38e56 100644 --- a/src/clang_tu.hh +++ b/src/clang_tu.hh @@ -22,7 +22,11 @@ namespace vfs = clang::vfs; #endif namespace ccls { +#if LLVM_VERSION_MAJOR < 19 std::string pathFromFileEntry(const clang::FileEntry &file); +#else +std::string pathFromFileEntry(clang::FileEntryRef file); +#endif bool isInsideMainFile(const clang::SourceManager &sm, clang::SourceLocation sl); diff --git a/src/indexer.cc b/src/indexer.cc index 68d3f810..f550f22a 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -68,7 +68,11 @@ struct IndexParam { // generating an index for it): auto [it, inserted] = uid2file.try_emplace(fid); if (inserted) { +#if LLVM_VERSION_MAJOR < 19 const FileEntry *fe = ctx->getSourceManager().getFileEntryForID(fid); +#else + OptionalFileEntryRef fe = ctx->getSourceManager().getFileEntryRefForID(fid); +#endif if (!fe) return; std::string path = pathFromFileEntry(*fe); @@ -94,9 +98,14 @@ struct IndexParam { bool useMultiVersion(FileID fid) { auto it = uid2multi.try_emplace(fid); - if (it.second) + if (it.second) { +#if LLVM_VERSION_MAJOR < 19 if (const FileEntry *fe = ctx->getSourceManager().getFileEntryForID(fid)) +#else + if (OptionalFileEntryRef fe = ctx->getSourceManager().getFileEntryRefForID(fid)) +#endif it.first->second = multiVersionMatcher->matches(pathFromFileEntry(*fe)); + } return it.first->second; } }; @@ -636,7 +645,11 @@ public: static int getFileLID(IndexFile *db, SourceManager &sm, FileID fid) { auto [it, inserted] = db->uid2lid_and_path.try_emplace(fid); if (inserted) { +#if LLVM_VERSION_MAJOR < 19 const FileEntry *fe = sm.getFileEntryForID(fid); +#else + OptionalFileEntryRef fe = sm.getFileEntryRefForID(fid); +#endif if (!fe) { it->second.first = -1; return -1; @@ -1124,7 +1137,11 @@ public: filenameRange, nullptr); FileID fid = sm.getFileID(filenameRange.getBegin()); if (IndexFile *db = param.consumeFile(fid)) { +#if LLVM_VERSION_MAJOR < 19 std::string path = pathFromFileEntry(*file); +#else + std::string path = pathFromFileEntry(*fileRef); +#endif if (path.size()) db->includes.push_back({spell.start.line, intern(path)}); } diff --git a/src/sema_manager.cc b/src/sema_manager.cc index 6be9e60d..5b09cf92 100644 --- a/src/sema_manager.cc +++ b/src/sema_manager.cc @@ -194,7 +194,11 @@ public: const FileEntry *file = fileRef ? &fileRef->getFileEntry() : nullptr; #endif if (file && seen.insert(file).second) +#if LLVM_VERSION_MAJOR < 19 out.emplace_back(pathFromFileEntry(*file), file->getModificationTime()); +#else + out.emplace_back(pathFromFileEntry(*fileRef), file->getModificationTime()); +#endif } }; @@ -236,7 +240,11 @@ public: FileID fid = sm.getFileID(l); auto it = fID2concerned.try_emplace(fid.getHashValue()); if (it.second) { +#if LLVM_VERSION_MAJOR < 19 const FileEntry *fe = sm.getFileEntryForID(fid); +#else + OptionalFileEntryRef fe = sm.getFileEntryRefForID(fid); +#endif it.first->second = fe && pathFromFileEntry(*fe) == path; } return it.first->second;