diff --git a/src/clang_complete.cc b/src/clang_complete.cc index b55e53d4..25857e7a 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -72,20 +72,21 @@ lsTextEdit ToTextEdit(const clang::SourceManager &SM, } struct PreambleStatCache { - llvm::StringMap> Cache; + llvm::StringMap> Cache; - void Update(Twine Path, ErrorOr S) { + void Update(Twine Path, ErrorOr S) { Cache.try_emplace(Path.str(), std::move(S)); } - IntrusiveRefCntPtr - Producer(IntrusiveRefCntPtr FS) { - struct VFS : vfs::ProxyFileSystem { + IntrusiveRefCntPtr + Producer(IntrusiveRefCntPtr FS) { + struct VFS : llvm::vfs::ProxyFileSystem { PreambleStatCache &Cache; - VFS(IntrusiveRefCntPtr FS, PreambleStatCache &Cache) + VFS(IntrusiveRefCntPtr FS, + PreambleStatCache &Cache) : ProxyFileSystem(std::move(FS)), Cache(Cache) {} - llvm::ErrorOr> + llvm::ErrorOr> openFileForRead(const Twine &Path) override { auto File = getUnderlyingFS().openFileForRead(Path); if (!File || !*File) @@ -93,7 +94,7 @@ struct PreambleStatCache { Cache.Update(Path, File->get()->status()); return File; } - llvm::ErrorOr status(const Twine &Path) override { + llvm::ErrorOr status(const Twine &Path) override { auto S = getUnderlyingFS().status(Path); Cache.Update(Path, S); return S; @@ -102,14 +103,14 @@ struct PreambleStatCache { return new VFS(std::move(FS), *this); } - IntrusiveRefCntPtr - Consumer(IntrusiveRefCntPtr FS) { - struct VFS : vfs::ProxyFileSystem { + IntrusiveRefCntPtr + Consumer(IntrusiveRefCntPtr FS) { + struct VFS : llvm::vfs::ProxyFileSystem { const PreambleStatCache &Cache; - VFS(IntrusiveRefCntPtr FS, + VFS(IntrusiveRefCntPtr FS, const PreambleStatCache &Cache) : ProxyFileSystem(std::move(FS)), Cache(Cache) {} - llvm::ErrorOr status(const Twine &Path) override { + llvm::ErrorOr status(const Twine &Path) override { auto I = Cache.Cache.find(Path.str()); if (I != Cache.Cache.end()) return I->getValue(); @@ -259,7 +260,7 @@ public: std::unique_ptr BuildCompilerInstance( CompletionSession &session, std::unique_ptr CI, - IntrusiveRefCntPtr FS, DiagnosticConsumer &DC, + IntrusiveRefCntPtr FS, DiagnosticConsumer &DC, const PreambleData *preamble, const WorkingFiles::Snapshot &snapshot, std::vector> &Bufs) { std::string main = ResolveIfRelative( @@ -307,7 +308,7 @@ bool Parse(CompilerInstance &Clang) { } void BuildPreamble(CompletionSession &session, CompilerInvocation &CI, - IntrusiveRefCntPtr FS, + IntrusiveRefCntPtr FS, const std::string &main, std::unique_ptr stat_cache) { std::shared_ptr OldP = session.GetPreamble(); @@ -353,7 +354,8 @@ void *CompletionPreloadMain(void *manager_) { WorkingFiles::Snapshot snapshot = session->wfiles->AsSnapshot({StripFileType(session->file.filename)}); auto stat_cache = std::make_unique(); - IntrusiveRefCntPtr FS = stat_cache->Producer(session->FS); + IntrusiveRefCntPtr FS = + stat_cache->Producer(session->FS); if (std::unique_ptr CI = BuildCompilerInvocation(args, FS)) BuildPreamble(*session, *CI, FS, request.path, std::move(stat_cache)); @@ -391,7 +393,7 @@ void *CompletionMain(void *manager_) { std::shared_ptr session = manager->TryGetSession(path, false); std::shared_ptr preamble = session->GetPreamble(); - IntrusiveRefCntPtr FS = + IntrusiveRefCntPtr FS = preamble ? preamble->stat_cache->Consumer(session->FS) : session->FS; std::unique_ptr CI = BuildCompilerInvocation(session->file.args, FS); @@ -471,7 +473,7 @@ void *DiagnosticMain(void *manager_) { std::shared_ptr session = manager->TryGetSession(path, false); std::shared_ptr preamble = session->GetPreamble(); - IntrusiveRefCntPtr FS = + IntrusiveRefCntPtr FS = preamble ? preamble->stat_cache->Consumer(session->FS) : session->FS; std::unique_ptr CI = BuildCompilerInvocation(session->file.args, FS); diff --git a/src/clang_complete.hh b/src/clang_complete.hh index ba357224..eae3897a 100644 --- a/src/clang_complete.hh +++ b/src/clang_complete.hh @@ -51,8 +51,8 @@ struct CompletionSession bool inferred = false; // TODO share - llvm::IntrusiveRefCntPtr FS = - clang::vfs::getRealFileSystem(); + llvm::IntrusiveRefCntPtr FS = + llvm::vfs::getRealFileSystem(); std::shared_ptr PCH; CompletionSession(const Project::Entry &file, WorkingFiles *wfiles, diff --git a/src/clang_tu.cc b/src/clang_tu.cc index fd82f402..46015bdf 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -71,7 +71,7 @@ Range FromTokenRange(const SourceManager &SM, const LangOptions &LangOpts, std::unique_ptr BuildCompilerInvocation(std::vector args, - IntrusiveRefCntPtr VFS) { + IntrusiveRefCntPtr VFS) { std::string save = "-resource-dir=" + g_config->clang.resourceDir; args.push_back(save.c_str()); IntrusiveRefCntPtr Diags( diff --git a/src/clang_tu.hh b/src/clang_tu.hh index c790aa69..5db41d17 100644 --- a/src/clang_tu.hh +++ b/src/clang_tu.hh @@ -10,6 +10,13 @@ #include #include +#if LLVM_VERSION_MAJOR < 8 +// D52783 Lift VFS from clang to llvm +namespace llvm { +namespace vfs = clang::vfs; +} +#endif + std::string PathFromFileEntry(const clang::FileEntry &file); Range FromCharSourceRange(const clang::SourceManager &SM, @@ -27,6 +34,6 @@ Range FromTokenRange(const clang::SourceManager &SM, std::unique_ptr BuildCompilerInvocation(std::vector args, - llvm::IntrusiveRefCntPtr VFS); + llvm::IntrusiveRefCntPtr VFS); const char *ClangBuiltinTypeName(int); diff --git a/src/indexer.cc b/src/indexer.cc index 59c2fa43..30f14eaf 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1211,7 +1211,7 @@ Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs, const std::vector> &remapped, bool &ok) { ok = true; auto PCH = std::make_shared(); - llvm::IntrusiveRefCntPtr FS = vfs::getRealFileSystem(); + llvm::IntrusiveRefCntPtr FS = llvm::vfs::getRealFileSystem(); std::shared_ptr CI = BuildCompilerInvocation(args, FS); // e.g. .s if (!CI)