mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 11:01: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
646aca5b7f
commit
e4c105d78d
@ -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>
|
||||||
@ -1153,16 +1154,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
|
||||||
@ -1229,6 +1257,10 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
|
|||||||
if (!CI)
|
if (!CI)
|
||||||
return {};
|
return {};
|
||||||
ok = false;
|
ok = false;
|
||||||
|
// Disable computing warnings which will be discarded anyway.
|
||||||
|
CI->getDiagnosticOpts().IgnoreWarnings = true;
|
||||||
|
// Enable IndexFrontendAction::shouldSkipFunctionBody.
|
||||||
|
CI->getFrontendOpts().SkipFunctionBodies = true;
|
||||||
// -fparse-all-comments enables documentation in the indexer and in
|
// -fparse-all-comments enables documentation in the indexer and in
|
||||||
// code completion.
|
// code completion.
|
||||||
CI->getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1;
|
CI->getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1;
|
||||||
@ -1245,6 +1277,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())
|
||||||
@ -1260,40 +1293,47 @@ 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 =
|
||||||
index::IndexingOptions::SystemSymbolFilterKind::All;
|
index::IndexingOptions::SystemSymbolFilterKind::All;
|
||||||
if (no_linkage) {
|
if (no_linkage) {
|
||||||
IndexOpts.IndexFunctionLocals = true;
|
indexOpts.IndexFunctionLocals = true;
|
||||||
IndexOpts.IndexImplicitInstantiation = true;
|
indexOpts.IndexImplicitInstantiation = true;
|
||||||
#if LLVM_VERSION_MAJOR >= 9
|
#if LLVM_VERSION_MAJOR >= 9
|
||||||
|
|
||||||
IndexOpts.IndexParametersInDeclarations =
|
indexOpts.IndexParametersInDeclarations =
|
||||||
g_config->index.parametersInDeclarations;
|
g_config->index.parametersInDeclarations;
|
||||||
IndexOpts.IndexTemplateParameters = true;
|
indexOpts.IndexTemplateParameters = true;
|
||||||
#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;
|
||||||
auto parse = [&]() {
|
auto parse = [&]() {
|
||||||
if (!Action->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]))
|
if (!action->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]))
|
||||||
return;
|
return;
|
||||||
#if LLVM_VERSION_MAJOR >= 9 // rL364464
|
#if LLVM_VERSION_MAJOR >= 9 // rL364464
|
||||||
if (llvm::Error E = Action->Execute()) {
|
if (llvm::Error E = action->Execute()) {
|
||||||
reason = llvm::toString(std::move(E));
|
reason = llvm::toString(std::move(E));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!Action->Execute())
|
if (!action->Execute())
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
Action->EndSourceFile();
|
action->EndSourceFile();
|
||||||
ok = true;
|
ok = true;
|
||||||
};
|
};
|
||||||
if (!CRC.RunSafely(parse)) {
|
if (!CRC.RunSafely(parse)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user