r370336 - [Index] Moved the IndexDataConsumer::finish call into the IndexASTConsumer from IndexAction
Dmitri Gribenko via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 04:38:43 PDT 2019
Author: gribozavr
Date: Thu Aug 29 04:38:43 2019
New Revision: 370336
URL: http://llvm.org/viewvc/llvm-project?rev=370336&view=rev
Log:
[Index] Moved the IndexDataConsumer::finish call into the IndexASTConsumer from IndexAction
Doing so removes the last reason to expose a FrontendAction from
libIndex.
Modified:
cfe/trunk/lib/Index/IndexingAction.cpp
Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=370336&r1=370335&r2=370336&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Aug 29 04:38:43 2019
@@ -54,13 +54,20 @@ public:
};
class IndexASTConsumer final : public ASTConsumer {
- std::shared_ptr<Preprocessor> PP;
+ std::shared_ptr<IndexDataConsumer> DataConsumer;
std::shared_ptr<IndexingContext> IndexCtx;
+ std::shared_ptr<Preprocessor> PP;
public:
- IndexASTConsumer(std::shared_ptr<Preprocessor> PP,
- std::shared_ptr<IndexingContext> IndexCtx)
- : PP(std::move(PP)), IndexCtx(std::move(IndexCtx)) {}
+ IndexASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
+ const IndexingOptions &Opts,
+ std::shared_ptr<Preprocessor> PP)
+ : DataConsumer(std::move(DataConsumer)),
+ IndexCtx(new IndexingContext(Opts, *this->DataConsumer)),
+ PP(std::move(PP)) {
+ assert(this->DataConsumer != nullptr);
+ assert(this->PP != nullptr);
+ }
protected:
void Initialize(ASTContext &Context) override {
@@ -83,27 +90,25 @@ protected:
}
void HandleTranslationUnit(ASTContext &Ctx) override {
+ DataConsumer->finish();
}
};
class IndexActionBase {
protected:
std::shared_ptr<IndexDataConsumer> DataConsumer;
- std::shared_ptr<IndexingContext> IndexCtx;
+ IndexingOptions Opts;
- IndexActionBase(std::shared_ptr<IndexDataConsumer> dataConsumer,
+ IndexActionBase(std::shared_ptr<IndexDataConsumer> DataConsumer,
IndexingOptions Opts)
- : DataConsumer(std::move(dataConsumer)),
- IndexCtx(new IndexingContext(Opts, *DataConsumer)) {}
+ : DataConsumer(std::move(DataConsumer)), Opts(Opts) {
+ assert(this->DataConsumer != nullptr);
+ }
std::unique_ptr<IndexASTConsumer>
createIndexASTConsumer(CompilerInstance &CI) {
- return std::make_unique<IndexASTConsumer>(CI.getPreprocessorPtr(),
- IndexCtx);
- }
-
- void finish() {
- DataConsumer->finish();
+ return std::make_unique<IndexASTConsumer>(DataConsumer, Opts,
+ CI.getPreprocessorPtr());
}
};
@@ -118,16 +123,10 @@ protected:
StringRef InFile) override {
return createIndexASTConsumer(CI);
}
-
- void EndSourceFileAction() override {
- FrontendAction::EndSourceFileAction();
- finish();
- }
};
-class WrappingIndexAction final : public WrapperFrontendAction, IndexActionBase {
- bool IndexActionFailed = false;
-
+class WrappingIndexAction final : public WrapperFrontendAction,
+ IndexActionBase {
public:
WrappingIndexAction(std::unique_ptr<FrontendAction> WrappedAction,
std::shared_ptr<IndexDataConsumer> DataConsumer,
@@ -140,7 +139,6 @@ protected:
StringRef InFile) override {
auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
if (!OtherConsumer) {
- IndexActionFailed = true;
return nullptr;
}
@@ -149,13 +147,6 @@ protected:
Consumers.push_back(createIndexASTConsumer(CI));
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
}
-
- void EndSourceFileAction() override {
- // Invoke wrapped action's method.
- WrapperFrontendAction::EndSourceFileAction();
- if (!IndexActionFailed)
- finish();
- }
};
} // anonymous namespace
@@ -164,10 +155,11 @@ std::unique_ptr<FrontendAction>
index::createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
IndexingOptions Opts,
std::unique_ptr<FrontendAction> WrappedAction) {
+ assert(DataConsumer != nullptr);
+
if (WrappedAction)
return std::make_unique<WrappingIndexAction>(std::move(WrappedAction),
- std::move(DataConsumer),
- Opts);
+ std::move(DataConsumer), Opts);
return std::make_unique<IndexAction>(std::move(DataConsumer), Opts);
}
More information about the cfe-commits
mailing list