Skip to content

Commit f8d2778

Browse files
committed
Adapt llvm/llvm-project#74910: FileEntry::getName
Based on a patch by @zsrkmyn
1 parent f36ecb0 commit f8d2778

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/clang_tu.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@
2323
using namespace clang;
2424

2525
namespace ccls {
26+
#if LLVM_VERSION_MAJOR < 19
2627
std::string pathFromFileEntry(const FileEntry &file) {
28+
#else
29+
std::string pathFromFileEntry(FileEntryRef file) {
30+
#endif
2731
std::string ret;
2832
if (file.getName().startswith("/../")) {
2933
// Resolve symlinks outside of working folders. This handles leading path
3034
// components, e.g. (/lib -> /usr/lib) in
3135
// /../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/utility
36+
#if LLVM_VERSION_MAJOR < 19
3237
ret = file.tryGetRealPathName();
38+
#else
39+
ret = file.getFileEntry().tryGetRealPathName();
40+
#endif
3341
} else {
3442
// If getName() refers to a file within a workspace folder, we prefer it
3543
// (which may be a symlink).

src/clang_tu.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ namespace vfs = clang::vfs;
2222
#endif
2323

2424
namespace ccls {
25+
#if LLVM_VERSION_MAJOR < 19
2526
std::string pathFromFileEntry(const clang::FileEntry &file);
27+
#else
28+
std::string pathFromFileEntry(clang::FileEntryRef file);
29+
#endif
2630

2731
bool isInsideMainFile(const clang::SourceManager &sm, clang::SourceLocation sl);
2832

src/indexer.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ struct IndexParam {
6868
// generating an index for it):
6969
auto [it, inserted] = uid2file.try_emplace(fid);
7070
if (inserted) {
71+
#if LLVM_VERSION_MAJOR < 19
7172
const FileEntry *fe = ctx->getSourceManager().getFileEntryForID(fid);
73+
#else
74+
OptionalFileEntryRef fe = ctx->getSourceManager().getFileEntryRefForID(fid);
75+
#endif
7276
if (!fe)
7377
return;
7478
std::string path = pathFromFileEntry(*fe);
@@ -94,9 +98,14 @@ struct IndexParam {
9498

9599
bool useMultiVersion(FileID fid) {
96100
auto it = uid2multi.try_emplace(fid);
97-
if (it.second)
101+
if (it.second) {
102+
#if LLVM_VERSION_MAJOR < 19
98103
if (const FileEntry *fe = ctx->getSourceManager().getFileEntryForID(fid))
104+
#else
105+
if (OptionalFileEntryRef fe = ctx->getSourceManager().getFileEntryRefForID(fid))
106+
#endif
99107
it.first->second = multiVersionMatcher->matches(pathFromFileEntry(*fe));
108+
}
100109
return it.first->second;
101110
}
102111
};
@@ -636,7 +645,11 @@ class IndexDataConsumer : public index::IndexDataConsumer {
636645
static int getFileLID(IndexFile *db, SourceManager &sm, FileID fid) {
637646
auto [it, inserted] = db->uid2lid_and_path.try_emplace(fid);
638647
if (inserted) {
648+
#if LLVM_VERSION_MAJOR < 19
639649
const FileEntry *fe = sm.getFileEntryForID(fid);
650+
#else
651+
OptionalFileEntryRef fe = sm.getFileEntryRefForID(fid);
652+
#endif
640653
if (!fe) {
641654
it->second.first = -1;
642655
return -1;
@@ -1124,7 +1137,11 @@ class IndexPPCallbacks : public PPCallbacks {
11241137
filenameRange, nullptr);
11251138
FileID fid = sm.getFileID(filenameRange.getBegin());
11261139
if (IndexFile *db = param.consumeFile(fid)) {
1140+
#if LLVM_VERSION_MAJOR < 19
11271141
std::string path = pathFromFileEntry(*file);
1142+
#else
1143+
std::string path = pathFromFileEntry(*fileRef);
1144+
#endif
11281145
if (path.size())
11291146
db->includes.push_back({spell.start.line, intern(path)});
11301147
}

src/sema_manager.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ class StoreInclude : public PPCallbacks {
194194
const FileEntry *file = fileRef ? &fileRef->getFileEntry() : nullptr;
195195
#endif
196196
if (file && seen.insert(file).second)
197+
#if LLVM_VERSION_MAJOR < 19
197198
out.emplace_back(pathFromFileEntry(*file), file->getModificationTime());
199+
#else
200+
out.emplace_back(pathFromFileEntry(*fileRef), file->getModificationTime());
201+
#endif
198202
}
199203
};
200204

@@ -236,7 +240,11 @@ class StoreDiags : public DiagnosticConsumer {
236240
FileID fid = sm.getFileID(l);
237241
auto it = fID2concerned.try_emplace(fid.getHashValue());
238242
if (it.second) {
243+
#if LLVM_VERSION_MAJOR < 19
239244
const FileEntry *fe = sm.getFileEntryForID(fid);
245+
#else
246+
OptionalFileEntryRef fe = sm.getFileEntryRefForID(fid);
247+
#endif
240248
it.first->second = fe && pathFromFileEntry(*fe) == path;
241249
}
242250
return it.first->second;

0 commit comments

Comments
 (0)