mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-28 02:21:57 +00:00
indexer: disable warnings and skip processed function bodies
Adapt clang rC370337: removal of createIndexingAction and WrappingIndexAction
This commit is contained in:
parent
edc73ceb10
commit
3865a09447
@ -96,6 +96,8 @@ buildCompilerInvocation(const std::string &main, std::vector<const char *> args,
|
|||||||
if (ci) {
|
if (ci) {
|
||||||
ci->getDiagnosticOpts().IgnoreWarnings = true;
|
ci->getDiagnosticOpts().IgnoreWarnings = true;
|
||||||
ci->getFrontendOpts().DisableFree = false;
|
ci->getFrontendOpts().DisableFree = false;
|
||||||
|
// Enable IndexFrontendAction::shouldSkipFunctionBody.
|
||||||
|
ci->getFrontendOpts().SkipFunctionBodies = true;
|
||||||
ci->getLangOpts()->SpellChecking = false;
|
ci->getLangOpts()->SpellChecking = false;
|
||||||
auto &isec = ci->getFrontendOpts().Inputs;
|
auto &isec = ci->getFrontendOpts().Inputs;
|
||||||
if (isec.size())
|
if (isec.size())
|
||||||
|
@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <clang/AST/AST.h>
|
#include <clang/AST/AST.h>
|
||||||
#include <clang/Frontend/FrontendAction.h>
|
#include <clang/Frontend/FrontendAction.h>
|
||||||
|
#include <clang/Frontend/MultiplexConsumer.h>
|
||||||
#include <clang/Index/IndexDataConsumer.h>
|
#include <clang/Index/IndexDataConsumer.h>
|
||||||
#include <clang/Index/IndexingAction.h>
|
#include <clang/Index/IndexingAction.h>
|
||||||
#include <clang/Index/USRGeneration.h>
|
#include <clang/Index/USRGeneration.h>
|
||||||
@ -1163,16 +1164,43 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class IndexFrontendAction : public ASTFrontendAction {
|
class IndexFrontendAction : public ASTFrontendAction {
|
||||||
|
std::shared_ptr<IndexDataConsumer> dataConsumer;
|
||||||
|
const index::IndexingOptions &indexOpts;
|
||||||
IndexParam ¶m;
|
IndexParam ¶m;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IndexFrontendAction(IndexParam ¶m) : param(param) {}
|
IndexFrontendAction(std::shared_ptr<IndexDataConsumer> dataConsumer,
|
||||||
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
const index::IndexingOptions &indexOpts,
|
||||||
StringRef InFile) override {
|
IndexParam ¶m)
|
||||||
Preprocessor &PP = CI.getPreprocessor();
|
: dataConsumer(std::move(dataConsumer)), indexOpts(indexOpts),
|
||||||
PP.addPPCallbacks(
|
param(param) {}
|
||||||
std::make_unique<IndexPPCallbacks>(PP.getSourceManager(), param));
|
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &ci,
|
||||||
return std::make_unique<ASTConsumer>();
|
StringRef inFile) override {
|
||||||
|
class SkipProcessed : public ASTConsumer {
|
||||||
|
IndexParam ¶m;
|
||||||
|
const ASTContext *ctx = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SkipProcessed(IndexParam ¶m) : param(param) {}
|
||||||
|
void Initialize(ASTContext &ctx) override { this->ctx = &ctx; }
|
||||||
|
bool shouldSkipFunctionBody(Decl *d) override {
|
||||||
|
const SourceManager &sm = ctx->getSourceManager();
|
||||||
|
FileID fid = sm.getFileID(sm.getExpansionLoc(d->getLocation()));
|
||||||
|
return !(g_config->index.multiVersion && param.useMultiVersion(fid)) &&
|
||||||
|
!param.consumeFile(fid);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::shared_ptr<Preprocessor> pp = ci.getPreprocessorPtr();
|
||||||
|
pp->addPPCallbacks(
|
||||||
|
std::make_unique<IndexPPCallbacks>(pp->getSourceManager(), param));
|
||||||
|
std::vector<std::unique_ptr<ASTConsumer>> consumers;
|
||||||
|
consumers.push_back(std::make_unique<SkipProcessed>(param));
|
||||||
|
#if LLVM_VERSION_MAJOR >= 10 // rC370337
|
||||||
|
consumers.push_back(index::createIndexingASTConsumer(
|
||||||
|
dataConsumer, indexOpts, std::move(pp)));
|
||||||
|
#endif
|
||||||
|
return std::make_unique<MultiplexConsumer>(std::move(consumers));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -1257,6 +1285,7 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
auto clang = std::make_unique<CompilerInstance>(pch);
|
auto clang = std::make_unique<CompilerInstance>(pch);
|
||||||
clang->setInvocation(std::move(ci));
|
clang->setInvocation(std::move(ci));
|
||||||
clang->createDiagnostics(&dc, false);
|
clang->createDiagnostics(&dc, false);
|
||||||
|
clang->getDiagnostics().setIgnoreAllWarnings(true);
|
||||||
clang->setTarget(TargetInfo::CreateTargetInfo(
|
clang->setTarget(TargetInfo::CreateTargetInfo(
|
||||||
clang->getDiagnostics(), clang->getInvocation().TargetOpts));
|
clang->getDiagnostics(), clang->getInvocation().TargetOpts));
|
||||||
if (!clang->hasTarget())
|
if (!clang->hasTarget())
|
||||||
@ -1272,7 +1301,6 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
clang->getFileManager(), true));
|
clang->getFileManager(), true));
|
||||||
|
|
||||||
IndexParam param(*vfs, no_linkage);
|
IndexParam param(*vfs, no_linkage);
|
||||||
auto dataConsumer = std::make_shared<IndexDataConsumer>(param);
|
|
||||||
|
|
||||||
index::IndexingOptions indexOpts;
|
index::IndexingOptions indexOpts;
|
||||||
indexOpts.SystemSymbolFilter =
|
indexOpts.SystemSymbolFilter =
|
||||||
@ -1288,8 +1316,16 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<FrontendAction> action = createIndexingAction(
|
#if LLVM_VERSION_MAJOR >= 10 // rC370337
|
||||||
dataConsumer, indexOpts, std::make_unique<IndexFrontendAction>(param));
|
auto action = std::make_unique<IndexFrontendAction>(
|
||||||
|
std::make_shared<IndexDataConsumer>(param), indexOpts, param);
|
||||||
|
#else
|
||||||
|
auto dataConsumer = std::make_shared<IndexDataConsumer>(param);
|
||||||
|
auto action = createIndexingAction(
|
||||||
|
dataConsumer, indexOpts,
|
||||||
|
std::make_unique<IndexFrontendAction>(dataConsumer, indexOpts, param));
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string reason;
|
std::string reason;
|
||||||
{
|
{
|
||||||
llvm::CrashRecoveryContext crc;
|
llvm::CrashRecoveryContext crc;
|
||||||
|
@ -478,7 +478,6 @@ void *completionMain(void *manager_) {
|
|||||||
fOpts.CodeCompletionAt.FileName = task->path;
|
fOpts.CodeCompletionAt.FileName = task->path;
|
||||||
fOpts.CodeCompletionAt.Line = task->position.line + 1;
|
fOpts.CodeCompletionAt.Line = task->position.line + 1;
|
||||||
fOpts.CodeCompletionAt.Column = task->position.character + 1;
|
fOpts.CodeCompletionAt.Column = task->position.character + 1;
|
||||||
fOpts.SkipFunctionBodies = true;
|
|
||||||
ci->getLangOpts()->CommentOpts.ParseAllComments = true;
|
ci->getLangOpts()->CommentOpts.ParseAllComments = true;
|
||||||
|
|
||||||
DiagnosticConsumer dc;
|
DiagnosticConsumer dc;
|
||||||
@ -584,6 +583,7 @@ void *diagnosticMain(void *manager_) {
|
|||||||
if (lookupExtension(session->file.filename).second)
|
if (lookupExtension(session->file.filename).second)
|
||||||
ci->getDiagnosticOpts().Warnings.push_back("no-unused-function");
|
ci->getDiagnosticOpts().Warnings.push_back("no-unused-function");
|
||||||
ci->getDiagnosticOpts().IgnoreWarnings = false;
|
ci->getDiagnosticOpts().IgnoreWarnings = false;
|
||||||
|
ci->getFrontendOpts().SkipFunctionBodies = false;
|
||||||
ci->getLangOpts()->SpellChecking = g_config->diagnostics.spellChecking;
|
ci->getLangOpts()->SpellChecking = g_config->diagnostics.spellChecking;
|
||||||
StoreDiags dc(task.path);
|
StoreDiags dc(task.path);
|
||||||
std::string content = manager->wfiles->getContent(task.path);
|
std::string content = manager->wfiles->getContent(task.path);
|
||||||
|
Loading…
Reference in New Issue
Block a user