diff --git a/README.md b/README.md index 7075260d..289e80ff 100644 --- a/README.md +++ b/README.md @@ -16,18 +16,18 @@ a C/C++/Objective-C language server. It makes use of C++17 features, has less third-party dependencies and slimmed-down code base. Cross reference features are strenghened, (see [wiki/FAQ](../../wiki/FAQ). It currently uses libclang to index C++ code but will switch to Clang C++ API. Refactoring and formatting are non-goals as they can be provided by clang-format, clang-include-fixer and other Clang based tools. -The comparison with cquery as noted on 2018-07-09: +The comparison with cquery as noted on 2018-07-15: | | cquery | ccls | |------------ |--------------------------------|------------------------------| | third_party | more | fewer | | C++ | C++14 | C++17 | -| clang API | libclang (C) | libclang + clang/llvm C++ | +| clang API | libclang (C) | clang/llvm C++ | | Filesystem | AbsolutePath + custom routines | llvm/Support | | index | libclang | clangIndex, some enhancement | | pipeline | index merge+id remapping | simpler and more robust | -cquery has system include path detection (through running the compiler driver) while ccls does not. +cquery has system include path detection (through running the compiler driver) while ccls uses clangDriver. # >>> [Getting started](../../wiki/Getting-started) (CLICK HERE) <<< diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 42813cc8..af7e936c 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -9,6 +9,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include #include +#include #include using namespace clang; using namespace llvm; @@ -444,8 +445,10 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { CodeCompleteOptions Opts; LangOptions LangOpts; Opts.IncludeBriefComments = true; - Opts.LoadExternal = false; +#if LLVM_VERSION_MAJOR >= 7 + Opts.LoadExternal = true; Opts.IncludeFixIts = true; +#endif CaptureCompletionResults capture(Opts); tu->Unit->CodeComplete(session->file.filename, request->position.line + 1, request->position.character + 1, Remapped, diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 5411c923..092caab4 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -89,7 +89,12 @@ ClangTranslationUnit::Create(const std::string &filepath, /*CaptureDiagnostics=*/true, Remapped, /*RemappedFilesKeepOriginalName=*/true, 1, TU_Prefix, /*CacheCodeCompletionResults=*/true, true, - /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodiesScope::None, + /*AllowPCHWithCompilerErrors=*/true, +#if LLVM_VERSION_MAJOR >= 7 + SkipFunctionBodiesScope::None, +#else + false, +#endif /*SingleFileParse=*/false, /*UserFilesAreVolatile=*/true, false, ret->PCHCO->getRawReader().getFormat(), &ErrUnit)); diff --git a/src/clang_utils.cc b/src/clang_utils.cc index 8e0b1125..8ed4c201 100644 --- a/src/clang_utils.cc +++ b/src/clang_utils.cc @@ -6,6 +6,7 @@ #include "utils.h" #include +#include using namespace clang; using namespace llvm; @@ -66,6 +67,7 @@ const char* ClangBuiltinTypeName(int kind) { return "double"; case BuiltinType::LongDouble: return "long double"; +#if LLVM_VERSION_MAJOR >= 7 case BuiltinType::ShortAccum: return "short _Accum"; case BuiltinType::Accum: @@ -114,6 +116,7 @@ const char* ClangBuiltinTypeName(int kind) { return "_Sat unsigned _Fract"; case BuiltinType::BuiltinType::SatULongFract: return "_Sat unsigned long _Fract"; +#endif case BuiltinType::Float16: return "_Float16"; case BuiltinType::Float128: @@ -121,8 +124,10 @@ const char* ClangBuiltinTypeName(int kind) { case BuiltinType::WChar_S: case BuiltinType::WChar_U: return "wchar_t"; +#if LLVM_VERSION_MAJOR >= 7 case BuiltinType::Char8: return "char8_t"; +#endif case BuiltinType::Char16: return "char16_t"; case BuiltinType::Char32: diff --git a/src/project.cc b/src/project.cc index c74ef410..7140e082 100644 --- a/src/project.cc +++ b/src/project.cc @@ -14,12 +14,9 @@ using namespace ccls; #include #include -#include #include #include #include -#include -#include #include #include using namespace clang; @@ -99,22 +96,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( args.insert(args.end(), config->extra_flags.begin(), config->extra_flags.end()); -#if 1 - std::unique_ptr Opts = driver::createDriverOptTable(); - unsigned MissingArgIndex, MissingArgCount; - std::vector cargs; - for (auto& arg : args) - cargs.push_back(arg.c_str()); - InputArgList Args = - Opts->ParseArgs(makeArrayRef(cargs), MissingArgIndex, MissingArgCount, - driver::options::CC1Option); - using namespace clang::driver::options; - for (const auto* A : Args.filtered(OPT_I, OPT_c_isystem, OPT_cxx_isystem, - OPT_isystem, OPT_idirafter)) - config->angle_dirs.insert(entry.ResolveIfRelative(A->getValue())); - for (const auto* A : Args.filtered(OPT_I, OPT_iquote)) - config->quote_dirs.insert(entry.ResolveIfRelative(A->getValue())); -#else // a weird C++ deduction guide heap-use-after-free causes libclang to crash. IgnoringDiagConsumer DiagC; IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions()); @@ -164,7 +145,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( break; } } -#endif for (size_t i = 1; i < args.size(); i++) // This is most likely the file path we will be passing to clang. The @@ -176,9 +156,9 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( continue; } - // if (HeaderOpts.ResourceDir.empty() && HeaderOpts.UseBuiltinIncludes) + if (HeaderOpts.ResourceDir.empty() && HeaderOpts.UseBuiltinIncludes) args.push_back("-resource-dir=" + g_config->clang.resourceDir); - // if (CI->getFileSystemOpts().WorkingDir.empty()) + if (CI->getFileSystemOpts().WorkingDir.empty()) args.push_back("-working-directory=" + entry.directory); // There could be a clang version mismatch between what the project uses and