diff --git a/src/indexer.cc b/src/indexer.cc index 5e3e2bd6..fc193ff2 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -23,6 +23,7 @@ limitations under the License. #include #include +#include #include #include #include @@ -1153,16 +1154,43 @@ public: }; class IndexFrontendAction : public ASTFrontendAction { + std::shared_ptr dataConsumer; + const index::IndexingOptions &indexOpts; IndexParam ¶m; public: - IndexFrontendAction(IndexParam ¶m) : param(param) {} - std::unique_ptr CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override { - Preprocessor &PP = CI.getPreprocessor(); - PP.addPPCallbacks( - std::make_unique(PP.getSourceManager(), param)); - return std::make_unique(); + IndexFrontendAction(std::shared_ptr dataConsumer, + const index::IndexingOptions &indexOpts, + IndexParam ¶m) + : dataConsumer(std::move(dataConsumer)), indexOpts(indexOpts), + param(param) {} + std::unique_ptr CreateASTConsumer(CompilerInstance &ci, + 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 pp = ci.getPreprocessorPtr(); + pp->addPPCallbacks( + std::make_unique(pp->getSourceManager(), param)); + std::vector> consumers; + consumers.push_back(std::make_unique(param)); +#if LLVM_VERSION_MAJOR >= 10 // rC370337 + consumers.push_back(index::createIndexingASTConsumer( + dataConsumer, indexOpts, std::move(pp))); +#endif + return std::make_unique(std::move(consumers)); } }; } // namespace @@ -1229,6 +1257,10 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs, if (!CI) return {}; 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 // code completion. 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(PCH); Clang->setInvocation(std::move(CI)); Clang->createDiagnostics(&DC, false); + Clang->getDiagnostics().setIgnoreAllWarnings(true); Clang->setTarget(TargetInfo::CreateTargetInfo( Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); if (!Clang->hasTarget()) @@ -1260,40 +1293,47 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs, Clang->getFileManager(), true)); IndexParam param(*vfs, no_linkage); - auto DataConsumer = std::make_shared(param); - index::IndexingOptions IndexOpts; - IndexOpts.SystemSymbolFilter = + index::IndexingOptions indexOpts; + indexOpts.SystemSymbolFilter = index::IndexingOptions::SystemSymbolFilterKind::All; if (no_linkage) { - IndexOpts.IndexFunctionLocals = true; - IndexOpts.IndexImplicitInstantiation = true; + indexOpts.IndexFunctionLocals = true; + indexOpts.IndexImplicitInstantiation = true; #if LLVM_VERSION_MAJOR >= 9 - IndexOpts.IndexParametersInDeclarations = + indexOpts.IndexParametersInDeclarations = g_config->index.parametersInDeclarations; - IndexOpts.IndexTemplateParameters = true; + indexOpts.IndexTemplateParameters = true; #endif } - std::unique_ptr Action = createIndexingAction( - DataConsumer, IndexOpts, std::make_unique(param)); +#if LLVM_VERSION_MAJOR >= 10 // rC370337 + auto action = std::make_unique( + std::make_shared(param), indexOpts, param); +#else + auto dataConsumer = std::make_shared(param); + auto action = createIndexingAction( + dataConsumer, indexOpts, + std::make_unique(dataConsumer, indexOpts, param)); +#endif + std::string reason; { llvm::CrashRecoveryContext CRC; auto parse = [&]() { - if (!Action->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) + if (!action->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) return; #if LLVM_VERSION_MAJOR >= 9 // rL364464 - if (llvm::Error E = Action->Execute()) { + if (llvm::Error E = action->Execute()) { reason = llvm::toString(std::move(E)); return; } #else - if (!Action->Execute()) + if (!action->Execute()) return; #endif - Action->EndSourceFile(); + action->EndSourceFile(); ok = true; }; if (!CRC.RunSafely(parse)) {