forked from OSchip/llvm-project
[index] Allow calling createIndexingAction() without passing another action to wrap over.
llvm-svn: 260841
This commit is contained in:
parent
094bbcaf63
commit
469c1367f1
|
@ -32,10 +32,11 @@ struct IndexingOptions {
|
|||
bool IndexFunctionLocals = false;
|
||||
};
|
||||
|
||||
/// \param WrappedAction another frontend action to wrap over or null.
|
||||
std::unique_ptr<FrontendAction>
|
||||
createIndexingAction(std::unique_ptr<FrontendAction> WrappedAction,
|
||||
std::shared_ptr<IndexDataConsumer> DataConsumer,
|
||||
IndexingOptions Opts);
|
||||
createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
|
||||
IndexingOptions Opts,
|
||||
std::unique_ptr<FrontendAction> WrappedAction = nullptr);
|
||||
|
||||
void indexASTUnit(ASTUnit &Unit,
|
||||
std::shared_ptr<IndexDataConsumer> DataConsumer,
|
||||
|
|
|
@ -68,18 +68,52 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
class IndexAction : public WrapperFrontendAction {
|
||||
IndexingOptions IndexOpts;
|
||||
class IndexActionBase {
|
||||
protected:
|
||||
std::shared_ptr<IndexDataConsumer> DataConsumer;
|
||||
std::unique_ptr<IndexingContext> IndexCtx;
|
||||
IndexingContext IndexCtx;
|
||||
|
||||
IndexActionBase(std::shared_ptr<IndexDataConsumer> dataConsumer,
|
||||
IndexingOptions Opts)
|
||||
: DataConsumer(std::move(dataConsumer)),
|
||||
IndexCtx(Opts, *DataConsumer) {}
|
||||
|
||||
std::unique_ptr<IndexASTConsumer> createIndexASTConsumer() {
|
||||
return llvm::make_unique<IndexASTConsumer>(IndexCtx);
|
||||
}
|
||||
|
||||
void finish() {
|
||||
DataConsumer->finish();
|
||||
}
|
||||
};
|
||||
|
||||
class IndexAction : public ASTFrontendAction, IndexActionBase {
|
||||
public:
|
||||
IndexAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
|
||||
IndexingOptions Opts)
|
||||
: IndexActionBase(std::move(DataConsumer), Opts) {}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
||||
StringRef InFile) override {
|
||||
return createIndexASTConsumer();
|
||||
}
|
||||
|
||||
void EndSourceFileAction() override {
|
||||
FrontendAction::EndSourceFileAction();
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
class WrappingIndexAction : public WrapperFrontendAction, IndexActionBase {
|
||||
bool IndexActionFailed = false;
|
||||
|
||||
public:
|
||||
IndexAction(std::unique_ptr<FrontendAction> WrappedAction,
|
||||
std::shared_ptr<IndexDataConsumer> DataConsumer,
|
||||
IndexingOptions Opts)
|
||||
WrappingIndexAction(std::unique_ptr<FrontendAction> WrappedAction,
|
||||
std::shared_ptr<IndexDataConsumer> DataConsumer,
|
||||
IndexingOptions Opts)
|
||||
: WrapperFrontendAction(std::move(WrappedAction)),
|
||||
IndexOpts(Opts),
|
||||
DataConsumer(std::move(DataConsumer)) {}
|
||||
IndexActionBase(std::move(DataConsumer), Opts) {}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
|
||||
|
@ -89,36 +123,36 @@ protected:
|
|||
|
||||
} // anonymous namespace
|
||||
|
||||
void IndexAction::EndSourceFileAction() {
|
||||
void WrappingIndexAction::EndSourceFileAction() {
|
||||
// Invoke wrapped action's method.
|
||||
WrapperFrontendAction::EndSourceFileAction();
|
||||
|
||||
bool IndexActionFailed = !IndexCtx;
|
||||
if (!IndexActionFailed)
|
||||
DataConsumer->finish();
|
||||
finish();
|
||||
}
|
||||
|
||||
std::unique_ptr<ASTConsumer>
|
||||
IndexAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
||||
WrappingIndexAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
||||
auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
|
||||
if (!OtherConsumer)
|
||||
if (!OtherConsumer) {
|
||||
IndexActionFailed = true;
|
||||
return nullptr;
|
||||
|
||||
IndexCtx.reset(new IndexingContext(IndexOpts, *DataConsumer));
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
|
||||
Consumers.push_back(std::move(OtherConsumer));
|
||||
Consumers.push_back(llvm::make_unique<IndexASTConsumer>(*IndexCtx));
|
||||
Consumers.push_back(createIndexASTConsumer());
|
||||
return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
|
||||
}
|
||||
|
||||
std::unique_ptr<FrontendAction>
|
||||
index::createIndexingAction(std::unique_ptr<FrontendAction> WrappedAction,
|
||||
std::shared_ptr<IndexDataConsumer> DataConsumer,
|
||||
IndexingOptions Opts) {
|
||||
return llvm::make_unique<IndexAction>(std::move(WrappedAction),
|
||||
std::move(DataConsumer),
|
||||
Opts);
|
||||
index::createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
|
||||
IndexingOptions Opts,
|
||||
std::unique_ptr<FrontendAction> WrappedAction) {
|
||||
if (WrappedAction)
|
||||
return llvm::make_unique<WrappingIndexAction>(std::move(WrappedAction),
|
||||
std::move(DataConsumer),
|
||||
Opts);
|
||||
return llvm::make_unique<IndexAction>(std::move(DataConsumer), Opts);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -542,8 +542,9 @@ static CXErrorCode clang_indexSourceFile_Impl(
|
|||
auto InterAction = llvm::make_unique<IndexingFrontendAction>(DataConsumer,
|
||||
SkipBodies ? IdxSession->SkipBodyData.get() : nullptr);
|
||||
std::unique_ptr<FrontendAction> IndexAction;
|
||||
IndexAction = createIndexingAction(std::move(InterAction), DataConsumer,
|
||||
getIndexingOptionsFromCXOptions(index_options));
|
||||
IndexAction = createIndexingAction(DataConsumer,
|
||||
getIndexingOptionsFromCXOptions(index_options),
|
||||
std::move(InterAction));
|
||||
|
||||
// Recover resources if we crash before exiting this method.
|
||||
llvm::CrashRecoveryContextCleanupRegistrar<FrontendAction>
|
||||
|
|
Loading…
Reference in New Issue