1212#include < clang/AST/AST.h>
1313#include < clang/Basic/TargetInfo.h>
1414#include < clang/Frontend/FrontendAction.h>
15+ #include < clang/Frontend/MultiplexConsumer.h>
1516#include < clang/Index/IndexDataConsumer.h>
1617#include < clang/Index/IndexingAction.h>
1718#include < clang/Index/USRGeneration.h>
@@ -1154,16 +1155,43 @@ class IndexPPCallbacks : public PPCallbacks {
11541155};
11551156
11561157class IndexFrontendAction : public ASTFrontendAction {
1158+ std::shared_ptr<IndexDataConsumer> dataConsumer;
1159+ const index::IndexingOptions &indexOpts;
11571160 IndexParam ¶m;
11581161
11591162public:
1160- IndexFrontendAction (IndexParam ¶m) : param(param) {}
1161- std::unique_ptr<ASTConsumer> CreateASTConsumer (CompilerInstance &CI ,
1162- StringRef InFile) override {
1163- Preprocessor &PP = CI .getPreprocessor ();
1164- PP .addPPCallbacks (
1165- std::make_unique<IndexPPCallbacks>(PP .getSourceManager (), param));
1166- return std::make_unique<ASTConsumer>();
1163+ IndexFrontendAction (std::shared_ptr<IndexDataConsumer> dataConsumer,
1164+ const index::IndexingOptions &indexOpts,
1165+ IndexParam ¶m)
1166+ : dataConsumer(std::move(dataConsumer)), indexOpts(indexOpts),
1167+ param (param) {}
1168+ std::unique_ptr<ASTConsumer> CreateASTConsumer (CompilerInstance &ci,
1169+ StringRef inFile) override {
1170+ class SkipProcessed : public ASTConsumer {
1171+ IndexParam ¶m;
1172+ const ASTContext *ctx = nullptr ;
1173+
1174+ public:
1175+ SkipProcessed (IndexParam ¶m) : param(param) {}
1176+ void Initialize (ASTContext &ctx) override { this ->ctx = &ctx; }
1177+ bool shouldSkipFunctionBody (Decl *d) override {
1178+ const SourceManager &sm = ctx->getSourceManager ();
1179+ FileID fid = sm.getFileID (sm.getExpansionLoc (d->getLocation ()));
1180+ return !(g_config->index .multiVersion && param.useMultiVersion (fid)) &&
1181+ !param.consumeFile (fid);
1182+ }
1183+ };
1184+
1185+ std::shared_ptr<Preprocessor> pp = ci.getPreprocessorPtr ();
1186+ pp->addPPCallbacks (
1187+ std::make_unique<IndexPPCallbacks>(pp->getSourceManager (), param));
1188+ std::vector<std::unique_ptr<ASTConsumer>> consumers;
1189+ consumers.push_back (std::make_unique<SkipProcessed>(param));
1190+ #if LLVM_VERSION_MAJOR >= 10 // rC370337
1191+ consumers.push_back (index::createIndexingASTConsumer (
1192+ dataConsumer, indexOpts, std::move (pp)));
1193+ #endif
1194+ return std::make_unique<MultiplexConsumer>(std::move (consumers));
11671195 }
11681196};
11691197} // namespace
@@ -1248,6 +1276,7 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
12481276 auto clang = std::make_unique<CompilerInstance>(pch);
12491277 clang->setInvocation (std::move (ci));
12501278 clang->createDiagnostics (&dc, false );
1279+ clang->getDiagnostics ().setIgnoreAllWarnings (true );
12511280 clang->setTarget (TargetInfo::CreateTargetInfo (
12521281 clang->getDiagnostics (), clang->getInvocation ().TargetOpts ));
12531282 if (!clang->hasTarget ())
@@ -1263,7 +1292,6 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
12631292 clang->getFileManager (), true ));
12641293
12651294 IndexParam param (*vfs, no_linkage);
1266- auto dataConsumer = std::make_shared<IndexDataConsumer>(param);
12671295
12681296 index::IndexingOptions indexOpts;
12691297 indexOpts.SystemSymbolFilter =
@@ -1279,8 +1307,16 @@ index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
12791307#endif
12801308 }
12811309
1282- std::unique_ptr<FrontendAction> action = createIndexingAction (
1283- dataConsumer, indexOpts, std::make_unique<IndexFrontendAction>(param));
1310+ #if LLVM_VERSION_MAJOR >= 10 // rC370337
1311+ auto action = std::make_unique<IndexFrontendAction>(
1312+ std::make_shared<IndexDataConsumer>(param), indexOpts, param);
1313+ #else
1314+ auto dataConsumer = std::make_shared<IndexDataConsumer>(param);
1315+ auto action = createIndexingAction (
1316+ dataConsumer, indexOpts,
1317+ std::make_unique<IndexFrontendAction>(dataConsumer, indexOpts, param));
1318+ #endif
1319+
12841320 std::string reason;
12851321 {
12861322 llvm::CrashRecoveryContext crc;
0 commit comments