r370337 - [Index] Stopped wrapping FrontendActions in libIndex and its users
Dmitri Gribenko via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 04:43:05 PDT 2019
Author: gribozavr
Date: Thu Aug 29 04:43:05 2019
New Revision: 370337
URL: http://llvm.org/viewvc/llvm-project?rev=370337&view=rev
Log:
[Index] Stopped wrapping FrontendActions in libIndex and its users
Exposed a new function, createIndexingASTConsumer, that creates an
ASTConsumer. ASTConsumers compose well.
Removed wrapping functionality from createIndexingAction.
Modified:
cfe/trunk/include/clang/Index/IndexingAction.h
cfe/trunk/lib/Index/IndexingAction.cpp
cfe/trunk/tools/c-index-test/core_main.cpp
cfe/trunk/tools/libclang/Indexing.cpp
Modified: cfe/trunk/include/clang/Index/IndexingAction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=370337&r1=370336&r2=370337&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/IndexingAction.h (original)
+++ cfe/trunk/include/clang/Index/IndexingAction.h Thu Aug 29 04:43:05 2019
@@ -17,6 +17,7 @@
namespace clang {
class ASTContext;
+ class ASTConsumer;
class ASTReader;
class ASTUnit;
class Decl;
@@ -49,12 +50,16 @@ struct IndexingOptions {
bool IndexTemplateParameters = false;
};
+/// Creates an ASTConsumer that indexes all symbols (macros and AST decls).
+std::unique_ptr<ASTConsumer>
+createIndexingASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
+ const IndexingOptions &Opts,
+ std::shared_ptr<Preprocessor> PP);
+
/// Creates a frontend action that indexes all symbols (macros and AST decls).
-/// \param WrappedAction another frontend action to wrap over or null.
std::unique_ptr<FrontendAction>
createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
- IndexingOptions Opts,
- std::unique_ptr<FrontendAction> WrappedAction);
+ const IndexingOptions &Opts);
/// Recursively indexes all decls in the AST.
void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,
Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=370337&r1=370336&r2=370337&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Aug 29 04:43:05 2019
@@ -94,72 +94,38 @@ protected:
}
};
-class IndexActionBase {
-protected:
+class IndexAction final : public ASTFrontendAction {
std::shared_ptr<IndexDataConsumer> DataConsumer;
IndexingOptions Opts;
- IndexActionBase(std::shared_ptr<IndexDataConsumer> DataConsumer,
- IndexingOptions Opts)
- : DataConsumer(std::move(DataConsumer)), Opts(Opts) {
- assert(this->DataConsumer != nullptr);
- }
-
- std::unique_ptr<IndexASTConsumer>
- createIndexASTConsumer(CompilerInstance &CI) {
- return std::make_unique<IndexASTConsumer>(DataConsumer, Opts,
- CI.getPreprocessorPtr());
- }
-};
-
-class IndexAction final : 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(CI);
+ const IndexingOptions &Opts)
+ : DataConsumer(std::move(DataConsumer)), Opts(Opts) {
+ assert(this->DataConsumer != nullptr);
}
-};
-
-class WrappingIndexAction final : public WrapperFrontendAction,
- IndexActionBase {
-public:
- WrappingIndexAction(std::unique_ptr<FrontendAction> WrappedAction,
- std::shared_ptr<IndexDataConsumer> DataConsumer,
- IndexingOptions Opts)
- : WrapperFrontendAction(std::move(WrappedAction)),
- IndexActionBase(std::move(DataConsumer), Opts) {}
protected:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
- auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
- if (!OtherConsumer) {
- return nullptr;
- }
-
- std::vector<std::unique_ptr<ASTConsumer>> Consumers;
- Consumers.push_back(std::move(OtherConsumer));
- Consumers.push_back(createIndexASTConsumer(CI));
- return std::make_unique<MultiplexConsumer>(std::move(Consumers));
+ return std::make_unique<IndexASTConsumer>(DataConsumer, Opts,
+ CI.getPreprocessorPtr());
}
};
} // 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<FrontendAction>
index::createIndexingAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
- IndexingOptions Opts,
- std::unique_ptr<FrontendAction> WrappedAction) {
+ const IndexingOptions &Opts) {
assert(DataConsumer != nullptr);
-
- if (WrappedAction)
- return std::make_unique<WrappingIndexAction>(std::move(WrappedAction),
- std::move(DataConsumer), Opts);
return std::make_unique<IndexAction>(std::move(DataConsumer), Opts);
}
Modified: cfe/trunk/tools/c-index-test/core_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/core_main.cpp?rev=370337&r1=370336&r2=370337&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/core_main.cpp (original)
+++ cfe/trunk/tools/c-index-test/core_main.cpp Thu Aug 29 04:43:05 2019
@@ -221,9 +221,8 @@ static bool printSourceSymbols(const cha
auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(OS);
IndexingOptions IndexOpts;
IndexOpts.IndexFunctionLocals = indexLocals;
- std::unique_ptr<FrontendAction> IndexAction;
- IndexAction = createIndexingAction(DataConsumer, IndexOpts,
- /*WrappedAction=*/nullptr);
+ std::unique_ptr<FrontendAction> IndexAction =
+ createIndexingAction(DataConsumer, IndexOpts);
auto PCHContainerOps = std::make_shared<PCHContainerOperations>();
std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=370337&r1=370336&r2=370337&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Thu Aug 29 04:43:05 2019
@@ -19,6 +19,7 @@
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Frontend/Utils.h"
#include "clang/Index/IndexingAction.h"
#include "clang/Lex/HeaderSearch.h"
@@ -367,14 +368,16 @@ public:
class IndexingFrontendAction : public ASTFrontendAction {
std::shared_ptr<CXIndexDataConsumer> DataConsumer;
+ IndexingOptions Opts;
SharedParsedRegionsStorage *SKData;
std::unique_ptr<ParsedSrcLocationsTracker> ParsedLocsTracker;
public:
IndexingFrontendAction(std::shared_ptr<CXIndexDataConsumer> dataConsumer,
+ const IndexingOptions &Opts,
SharedParsedRegionsStorage *skData)
- : DataConsumer(std::move(dataConsumer)), SKData(skData) {}
+ : DataConsumer(std::move(dataConsumer)), Opts(Opts), SKData(skData) {}
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
@@ -398,8 +401,12 @@ public:
std::make_unique<ParsedSrcLocationsTracker>(*SKData, *PPRec, PP);
}
- return std::make_unique<IndexingConsumer>(*DataConsumer,
- ParsedLocsTracker.get());
+ std::vector<std::unique_ptr<ASTConsumer>> Consumers;
+ Consumers.push_back(std::make_unique<IndexingConsumer>(
+ *DataConsumer, ParsedLocsTracker.get()));
+ Consumers.push_back(
+ createIndexingASTConsumer(DataConsumer, Opts, CI.getPreprocessorPtr()));
+ return std::make_unique<MultiplexConsumer>(std::move(Consumers));
}
TranslationUnitKind getTranslationUnitKind() override {
@@ -569,12 +576,9 @@ static CXErrorCode clang_indexSourceFile
auto DataConsumer =
std::make_shared<CXIndexDataConsumer>(client_data, CB, index_options,
CXTU->getTU());
- auto InterAction = std::make_unique<IndexingFrontendAction>(DataConsumer,
- SkipBodies ? IdxSession->SkipBodyData.get() : nullptr);
- std::unique_ptr<FrontendAction> IndexAction;
- IndexAction = createIndexingAction(DataConsumer,
- getIndexingOptionsFromCXOptions(index_options),
- std::move(InterAction));
+ auto IndexAction = std::make_unique<IndexingFrontendAction>(
+ DataConsumer, getIndexingOptionsFromCXOptions(index_options),
+ SkipBodies ? IdxSession->SkipBodyData.get() : nullptr);
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<FrontendAction>
@@ -995,4 +999,3 @@ CXSourceLocation clang_indexLoc_getCXSou
*static_cast<CXIndexDataConsumer*>(location.ptr_data[0]);
return cxloc::translateSourceLocation(DataConsumer.getASTContext(), Loc);
}
-
More information about the cfe-commits
mailing list