mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-24 08:35:08 +00:00
Add namespace alias clang::vfs = llvm::vfs to adapt D52783
vfs::x should be written as llvm::vfs::x to work around a [namepace.udir] bug before GCC 8 when namespace alias is used
This commit is contained in:
parent
c5ae521d36
commit
51081c3cd2
@ -84,20 +84,21 @@ lsTextEdit ToTextEdit(const clang::SourceManager &SM,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PreambleStatCache {
|
struct PreambleStatCache {
|
||||||
llvm::StringMap<ErrorOr<vfs::Status>> Cache;
|
llvm::StringMap<ErrorOr<llvm::vfs::Status>> Cache;
|
||||||
|
|
||||||
void Update(Twine Path, ErrorOr<vfs::Status> S) {
|
void Update(Twine Path, ErrorOr<llvm::vfs::Status> S) {
|
||||||
Cache.try_emplace(Path.str(), std::move(S));
|
Cache.try_emplace(Path.str(), std::move(S));
|
||||||
}
|
}
|
||||||
|
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem>
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem>
|
||||||
Producer(IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
Producer(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
|
||||||
struct VFS : vfs::ProxyFileSystem {
|
struct VFS : llvm::vfs::ProxyFileSystem {
|
||||||
PreambleStatCache &Cache;
|
PreambleStatCache &Cache;
|
||||||
|
|
||||||
VFS(IntrusiveRefCntPtr<vfs::FileSystem> FS, PreambleStatCache &Cache)
|
VFS(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
|
||||||
|
PreambleStatCache &Cache)
|
||||||
: ProxyFileSystem(std::move(FS)), Cache(Cache) {}
|
: ProxyFileSystem(std::move(FS)), Cache(Cache) {}
|
||||||
llvm::ErrorOr<std::unique_ptr<vfs::File>>
|
llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
|
||||||
openFileForRead(const Twine &Path) override {
|
openFileForRead(const Twine &Path) override {
|
||||||
auto File = getUnderlyingFS().openFileForRead(Path);
|
auto File = getUnderlyingFS().openFileForRead(Path);
|
||||||
if (!File || !*File)
|
if (!File || !*File)
|
||||||
@ -105,7 +106,7 @@ struct PreambleStatCache {
|
|||||||
Cache.Update(Path, File->get()->status());
|
Cache.Update(Path, File->get()->status());
|
||||||
return File;
|
return File;
|
||||||
}
|
}
|
||||||
llvm::ErrorOr<vfs::Status> status(const Twine &Path) override {
|
llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path) override {
|
||||||
auto S = getUnderlyingFS().status(Path);
|
auto S = getUnderlyingFS().status(Path);
|
||||||
Cache.Update(Path, S);
|
Cache.Update(Path, S);
|
||||||
return S;
|
return S;
|
||||||
@ -114,14 +115,14 @@ struct PreambleStatCache {
|
|||||||
return new VFS(std::move(FS), *this);
|
return new VFS(std::move(FS), *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem>
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem>
|
||||||
Consumer(IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
Consumer(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
|
||||||
struct VFS : vfs::ProxyFileSystem {
|
struct VFS : llvm::vfs::ProxyFileSystem {
|
||||||
const PreambleStatCache &Cache;
|
const PreambleStatCache &Cache;
|
||||||
VFS(IntrusiveRefCntPtr<vfs::FileSystem> FS,
|
VFS(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
|
||||||
const PreambleStatCache &Cache)
|
const PreambleStatCache &Cache)
|
||||||
: ProxyFileSystem(std::move(FS)), Cache(Cache) {}
|
: ProxyFileSystem(std::move(FS)), Cache(Cache) {}
|
||||||
llvm::ErrorOr<vfs::Status> status(const Twine &Path) override {
|
llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path) override {
|
||||||
auto I = Cache.Cache.find(Path.str());
|
auto I = Cache.Cache.find(Path.str());
|
||||||
if (I != Cache.Cache.end())
|
if (I != Cache.Cache.end())
|
||||||
return I->getValue();
|
return I->getValue();
|
||||||
@ -271,7 +272,7 @@ public:
|
|||||||
|
|
||||||
std::unique_ptr<CompilerInstance> BuildCompilerInstance(
|
std::unique_ptr<CompilerInstance> BuildCompilerInstance(
|
||||||
CompletionSession &session, std::unique_ptr<CompilerInvocation> CI,
|
CompletionSession &session, std::unique_ptr<CompilerInvocation> CI,
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS, DiagnosticConsumer &DC,
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS, DiagnosticConsumer &DC,
|
||||||
const PreambleData *preamble, const WorkingFiles::Snapshot &snapshot,
|
const PreambleData *preamble, const WorkingFiles::Snapshot &snapshot,
|
||||||
std::vector<std::unique_ptr<llvm::MemoryBuffer>> &Bufs) {
|
std::vector<std::unique_ptr<llvm::MemoryBuffer>> &Bufs) {
|
||||||
std::string main = ResolveIfRelative(
|
std::string main = ResolveIfRelative(
|
||||||
@ -319,7 +320,7 @@ bool Parse(CompilerInstance &Clang) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BuildPreamble(CompletionSession &session, CompilerInvocation &CI,
|
void BuildPreamble(CompletionSession &session, CompilerInvocation &CI,
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS,
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
|
||||||
const std::string &main,
|
const std::string &main,
|
||||||
std::unique_ptr<PreambleStatCache> stat_cache) {
|
std::unique_ptr<PreambleStatCache> stat_cache) {
|
||||||
std::shared_ptr<PreambleData> OldP = session.GetPreamble();
|
std::shared_ptr<PreambleData> OldP = session.GetPreamble();
|
||||||
@ -364,7 +365,8 @@ void *CompletionPreloadMain(void *manager_) {
|
|||||||
WorkingFiles::Snapshot snapshot =
|
WorkingFiles::Snapshot snapshot =
|
||||||
session->wfiles->AsSnapshot({StripFileType(session->file.filename)});
|
session->wfiles->AsSnapshot({StripFileType(session->file.filename)});
|
||||||
auto stat_cache = std::make_unique<PreambleStatCache>();
|
auto stat_cache = std::make_unique<PreambleStatCache>();
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS = stat_cache->Producer(session->FS);
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
|
||||||
|
stat_cache->Producer(session->FS);
|
||||||
if (std::unique_ptr<CompilerInvocation> CI =
|
if (std::unique_ptr<CompilerInvocation> CI =
|
||||||
BuildCompilerInvocation(args, FS))
|
BuildCompilerInvocation(args, FS))
|
||||||
BuildPreamble(*session, *CI, FS, request.path, std::move(stat_cache));
|
BuildPreamble(*session, *CI, FS, request.path, std::move(stat_cache));
|
||||||
@ -402,7 +404,7 @@ void *CompletionMain(void *manager_) {
|
|||||||
std::shared_ptr<CompletionSession> session =
|
std::shared_ptr<CompletionSession> session =
|
||||||
manager->TryGetSession(path, false);
|
manager->TryGetSession(path, false);
|
||||||
std::shared_ptr<PreambleData> preamble = session->GetPreamble();
|
std::shared_ptr<PreambleData> preamble = session->GetPreamble();
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS =
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
|
||||||
preamble ? preamble->stat_cache->Consumer(session->FS) : session->FS;
|
preamble ? preamble->stat_cache->Consumer(session->FS) : session->FS;
|
||||||
std::unique_ptr<CompilerInvocation> CI =
|
std::unique_ptr<CompilerInvocation> CI =
|
||||||
BuildCompilerInvocation(session->file.args, FS);
|
BuildCompilerInvocation(session->file.args, FS);
|
||||||
@ -482,7 +484,7 @@ void *DiagnosticMain(void *manager_) {
|
|||||||
std::shared_ptr<CompletionSession> session =
|
std::shared_ptr<CompletionSession> session =
|
||||||
manager->TryGetSession(path, false);
|
manager->TryGetSession(path, false);
|
||||||
std::shared_ptr<PreambleData> preamble = session->GetPreamble();
|
std::shared_ptr<PreambleData> preamble = session->GetPreamble();
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS =
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
|
||||||
preamble ? preamble->stat_cache->Consumer(session->FS) : session->FS;
|
preamble ? preamble->stat_cache->Consumer(session->FS) : session->FS;
|
||||||
std::unique_ptr<CompilerInvocation> CI =
|
std::unique_ptr<CompilerInvocation> CI =
|
||||||
BuildCompilerInvocation(session->file.args, FS);
|
BuildCompilerInvocation(session->file.args, FS);
|
||||||
|
@ -63,8 +63,8 @@ struct CompletionSession
|
|||||||
bool inferred = false;
|
bool inferred = false;
|
||||||
|
|
||||||
// TODO share
|
// TODO share
|
||||||
llvm::IntrusiveRefCntPtr<clang::vfs::FileSystem> FS =
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
|
||||||
clang::vfs::getRealFileSystem();
|
llvm::vfs::getRealFileSystem();
|
||||||
std::shared_ptr<clang::PCHContainerOperations> PCH;
|
std::shared_ptr<clang::PCHContainerOperations> PCH;
|
||||||
|
|
||||||
CompletionSession(const Project::Entry &file, WorkingFiles *wfiles,
|
CompletionSession(const Project::Entry &file, WorkingFiles *wfiles,
|
||||||
|
@ -83,7 +83,7 @@ Range FromTokenRange(const SourceManager &SM, const LangOptions &LangOpts,
|
|||||||
|
|
||||||
std::unique_ptr<CompilerInvocation>
|
std::unique_ptr<CompilerInvocation>
|
||||||
BuildCompilerInvocation(std::vector<const char *> args,
|
BuildCompilerInvocation(std::vector<const char *> args,
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
|
||||||
std::string save = "-resource-dir=" + g_config->clang.resourceDir;
|
std::string save = "-resource-dir=" + g_config->clang.resourceDir;
|
||||||
args.push_back(save.c_str());
|
args.push_back(save.c_str());
|
||||||
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
|
||||||
|
@ -22,6 +22,13 @@ limitations under the License.
|
|||||||
#include <clang/Basic/SourceManager.h>
|
#include <clang/Basic/SourceManager.h>
|
||||||
#include <clang/Frontend/CompilerInstance.h>
|
#include <clang/Frontend/CompilerInstance.h>
|
||||||
|
|
||||||
|
#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);
|
std::string PathFromFileEntry(const clang::FileEntry &file);
|
||||||
|
|
||||||
Range FromCharSourceRange(const clang::SourceManager &SM,
|
Range FromCharSourceRange(const clang::SourceManager &SM,
|
||||||
@ -39,6 +46,6 @@ Range FromTokenRange(const clang::SourceManager &SM,
|
|||||||
|
|
||||||
std::unique_ptr<clang::CompilerInvocation>
|
std::unique_ptr<clang::CompilerInvocation>
|
||||||
BuildCompilerInvocation(std::vector<const char *> args,
|
BuildCompilerInvocation(std::vector<const char *> args,
|
||||||
llvm::IntrusiveRefCntPtr<clang::vfs::FileSystem> VFS);
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS);
|
||||||
|
|
||||||
const char *ClangBuiltinTypeName(int);
|
const char *ClangBuiltinTypeName(int);
|
||||||
|
@ -1225,7 +1225,7 @@ Index(CompletionManager *completion, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
const std::vector<std::pair<std::string, std::string>> &remapped, bool &ok) {
|
const std::vector<std::pair<std::string, std::string>> &remapped, bool &ok) {
|
||||||
ok = true;
|
ok = true;
|
||||||
auto PCH = std::make_shared<PCHContainerOperations>();
|
auto PCH = std::make_shared<PCHContainerOperations>();
|
||||||
llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = llvm::vfs::getRealFileSystem();
|
||||||
std::shared_ptr<CompilerInvocation> CI = BuildCompilerInvocation(args, FS);
|
std::shared_ptr<CompilerInvocation> CI = BuildCompilerInvocation(args, FS);
|
||||||
// e.g. .s
|
// e.g. .s
|
||||||
if (!CI)
|
if (!CI)
|
||||||
|
Loading…
Reference in New Issue
Block a user