summaryrefslogtreecommitdiff
path: root/lib/Index
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2019-08-29 11:47:34 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2019-08-29 11:47:34 +0000
commitf2dd7c98997c776fe1ce7ae651cb437379e405fd (patch)
tree364f79720d30ac95703f4109fc8666af7e1cc12e /lib/Index
parentca7487190698eb46511a983fb2f469db2bdb8836 (diff)
downloadclang-f2dd7c98997c776fe1ce7ae651cb437379e405fd.tar.gz
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370338 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Index')
-rw-r--r--lib/Index/IndexingAction.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/Index/IndexingAction.cpp b/lib/Index/IndexingAction.cpp
index e707972014..6d6133e89d 100644
--- a/lib/Index/IndexingAction.cpp
+++ b/lib/Index/IndexingAction.cpp
@@ -57,14 +57,17 @@ class IndexASTConsumer final : public ASTConsumer {
std::shared_ptr<IndexDataConsumer> DataConsumer;
std::shared_ptr<IndexingContext> IndexCtx;
std::shared_ptr<Preprocessor> PP;
+ std::function<bool(const Decl *)> ShouldSkipFunctionBody;
public:
IndexASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
const IndexingOptions &Opts,
- std::shared_ptr<Preprocessor> PP)
+ std::shared_ptr<Preprocessor> PP,
+ std::function<bool(const Decl *)> ShouldSkipFunctionBody)
: DataConsumer(std::move(DataConsumer)),
IndexCtx(new IndexingContext(Opts, *this->DataConsumer)),
- PP(std::move(PP)) {
+ PP(std::move(PP)),
+ ShouldSkipFunctionBody(std::move(ShouldSkipFunctionBody)) {
assert(this->DataConsumer != nullptr);
assert(this->PP != nullptr);
}
@@ -92,6 +95,10 @@ protected:
void HandleTranslationUnit(ASTContext &Ctx) override {
DataConsumer->finish();
}
+
+ bool shouldSkipFunctionBody(Decl *D) override {
+ return ShouldSkipFunctionBody(D);
+ }
};
class IndexAction final : public ASTFrontendAction {
@@ -108,18 +115,20 @@ public:
protected:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
- return std::make_unique<IndexASTConsumer>(DataConsumer, Opts,
- CI.getPreprocessorPtr());
+ return std::make_unique<IndexASTConsumer>(
+ DataConsumer, Opts, CI.getPreprocessorPtr(),
+ /*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
}
};
} // anonymous namespace
-std::unique_ptr<ASTConsumer>
-index::createIndexingASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
- const IndexingOptions &Opts,
- std::shared_ptr<Preprocessor> PP) {
- return std::make_unique<IndexASTConsumer>(DataConsumer, Opts, PP);
+std::unique_ptr<ASTConsumer> index::createIndexingASTConsumer(
+ std::shared_ptr<IndexDataConsumer> DataConsumer,
+ const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP,
+ std::function<bool(const Decl *)> ShouldSkipFunctionBody) {
+ return std::make_unique<IndexASTConsumer>(DataConsumer, Opts, PP,
+ ShouldSkipFunctionBody);
}
std::unique_ptr<FrontendAction>