Author: gribozavr Date: Thu Aug 29 04:47:34 2019 New Revision: 370338 URL: http://llvm.org/viewvc/llvm-project?rev=370338&view=rev Log: [Index] Added a ShouldSkipFunctionBody callback to libIndex, and refactored clients to use it instead of inventing their own solution
Subscribers: jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66879 Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=370338&r1=370337&r2=370338&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original) +++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Thu Aug 29 04:47:34 2019 @@ -121,30 +121,6 @@ private: IncludeGraph &IG; }; -/// An ASTConsumer that instructs the parser to skip bodies of functions in the -/// files that should not be processed. -class SkipProcessedFunctions : public ASTConsumer { -public: - SkipProcessedFunctions(std::function<bool(FileID)> FileFilter) - : ShouldIndexFile(std::move(FileFilter)), Context(nullptr) { - assert(this->ShouldIndexFile); - } - - void Initialize(ASTContext &Context) override { this->Context = &Context; } - bool shouldSkipFunctionBody(Decl *D) override { - assert(Context && "Initialize() was never called."); - auto &SM = Context->getSourceManager(); - auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation())); - if (!FID.isValid()) - return false; - return !ShouldIndexFile(FID); - } - -private: - std::function<bool(FileID)> ShouldIndexFile; - const ASTContext *Context; -}; - // Wraps the index action and reports index data after each translation unit. class IndexAction : public ASTFrontendAction { public: @@ -169,12 +145,15 @@ public: CI.getPreprocessor().addPPCallbacks( std::make_unique<IncludeGraphCollector>(CI.getSourceManager(), IG)); - std::vector<std::unique_ptr<ASTConsumer>> Consumers; - Consumers.push_back(std::make_unique<SkipProcessedFunctions>( - [this](FileID FID) { return Collector->shouldIndexFile(FID); })); - Consumers.push_back(index::createIndexingASTConsumer( - Collector, Opts, CI.getPreprocessorPtr())); - return std::make_unique<MultiplexConsumer>(std::move(Consumers)); + return index::createIndexingASTConsumer( + Collector, Opts, CI.getPreprocessorPtr(), + /*ShouldSkipFunctionBody=*/[this](const Decl *D) { + auto &SM = D->getASTContext().getSourceManager(); + auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation())); + if (!FID.isValid()) + return false; + return !Collector->shouldIndexFile(FID); + }); } bool BeginInvocation(CompilerInstance &CI) override { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits