[clang-tools-extra] 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:
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.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=370337&r1=370336&r2=370337&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Thu Aug 29 04:43:05 2019
@@ -121,42 +121,32 @@ private:
IncludeGraph &IG;
};
-/// Returns an ASTConsumer that wraps \p Inner and additionally instructs the
-/// parser to skip bodies of functions in the files that should not be
-/// processed.
-static std::unique_ptr<ASTConsumer>
-skipProcessedFunctions(std::unique_ptr<ASTConsumer> Inner,
- std::function<bool(FileID)> ShouldIndexFile) {
- class SkipProcessedFunctions : public ASTConsumer {
- public:
- SkipProcessedFunctions(std::function<bool(FileID)> FileFilter)
- : ShouldIndexFile(std::move(FileFilter)), Context(nullptr) {
- assert(this->ShouldIndexFile);
- }
+/// 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);
- }
+ 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;
- };
- std::vector<std::unique_ptr<ASTConsumer>> Consumers;
- Consumers.push_back(
- std::make_unique<SkipProcessedFunctions>(ShouldIndexFile));
- Consumers.push_back(std::move(Inner));
- return std::make_unique<MultiplexConsumer>(std::move(Consumers));
-}
+private:
+ std::function<bool(FileID)> ShouldIndexFile;
+ const ASTContext *Context;
+};
// Wraps the index action and reports index data after each translation unit.
-class IndexAction : public WrapperFrontendAction {
+class IndexAction : public ASTFrontendAction {
public:
IndexAction(std::shared_ptr<SymbolCollector> C,
std::unique_ptr<CanonicalIncludes> Includes,
@@ -165,11 +155,10 @@ public:
std::function<void(RefSlab)> RefsCallback,
std::function<void(RelationSlab)> RelationsCallback,
std::function<void(IncludeGraph)> IncludeGraphCallback)
- : WrapperFrontendAction(index::createIndexingAction(C, Opts, nullptr)),
- SymbolsCallback(SymbolsCallback), RefsCallback(RefsCallback),
- RelationsCallback(RelationsCallback),
+ : SymbolsCallback(SymbolsCallback),
+ RefsCallback(RefsCallback), RelationsCallback(RelationsCallback),
IncludeGraphCallback(IncludeGraphCallback), Collector(C),
- Includes(std::move(Includes)),
+ Includes(std::move(Includes)), Opts(Opts),
PragmaHandler(collectIWYUHeaderMaps(this->Includes.get())) {}
std::unique_ptr<ASTConsumer>
@@ -179,9 +168,13 @@ public:
if (IncludeGraphCallback != nullptr)
CI.getPreprocessor().addPPCallbacks(
std::make_unique<IncludeGraphCollector>(CI.getSourceManager(), IG));
- return skipProcessedFunctions(
- WrapperFrontendAction::CreateASTConsumer(CI, InFile),
- [this](FileID FID) { return Collector->shouldIndexFile(FID); });
+
+ 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));
}
bool BeginInvocation(CompilerInstance &CI) override {
@@ -195,13 +188,10 @@ public:
// bodies. The ASTConsumer will take care of skipping only functions inside
// the files that we have already processed.
CI.getFrontendOpts().SkipFunctionBodies = true;
-
- return WrapperFrontendAction::BeginInvocation(CI);
+ return true;
}
void EndSourceFileAction() override {
- WrapperFrontendAction::EndSourceFileAction();
-
SymbolsCallback(Collector->takeSymbols());
if (RefsCallback != nullptr)
RefsCallback(Collector->takeRefs());
@@ -224,6 +214,7 @@ private:
std::function<void(IncludeGraph)> IncludeGraphCallback;
std::shared_ptr<SymbolCollector> Collector;
std::unique_ptr<CanonicalIncludes> Includes;
+ index::IndexingOptions Opts;
std::unique_ptr<CommentHandler> PragmaHandler;
IncludeGraph IG;
};
Modified: clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp?rev=370337&r1=370336&r2=370337&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp Thu Aug 29 04:43:05 2019
@@ -201,30 +201,30 @@ public:
: COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}
clang::FrontendAction *create() override {
- class WrappedIndexAction : public WrapperFrontendAction {
+ class IndexAction : public ASTFrontendAction {
public:
- WrappedIndexAction(std::shared_ptr<SymbolCollector> C,
- const index::IndexingOptions &Opts,
- CommentHandler *PragmaHandler)
- : WrapperFrontendAction(
- index::createIndexingAction(C, Opts, nullptr)),
+ IndexAction(std::shared_ptr<index::IndexDataConsumer> DataConsumer,
+ const index::IndexingOptions &Opts,
+ CommentHandler *PragmaHandler)
+ : DataConsumer(std::move(DataConsumer)), Opts(Opts),
PragmaHandler(PragmaHandler) {}
std::unique_ptr<ASTConsumer>
CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) override {
if (PragmaHandler)
CI.getPreprocessor().addCommentHandler(PragmaHandler);
- return WrapperFrontendAction::CreateASTConsumer(CI, InFile);
+ return createIndexingASTConsumer(DataConsumer, Opts, CI.getPreprocessorPtr());
}
bool BeginInvocation(CompilerInstance &CI) override {
// Make the compiler parse all comments.
CI.getLangOpts().CommentOpts.ParseAllComments = true;
- return WrapperFrontendAction::BeginInvocation(CI);
+ return true;
}
private:
- index::IndexingOptions IndexOpts;
+ std::shared_ptr<index::IndexDataConsumer> DataConsumer;
+ index::IndexingOptions Opts;
CommentHandler *PragmaHandler;
};
index::IndexingOptions IndexOpts;
@@ -232,8 +232,7 @@ public:
index::IndexingOptions::SystemSymbolFilterKind::All;
IndexOpts.IndexFunctionLocals = false;
Collector = std::make_shared<SymbolCollector>(COpts);
- return new WrappedIndexAction(Collector, std::move(IndexOpts),
- PragmaHandler);
+ return new IndexAction(Collector, std::move(IndexOpts), PragmaHandler);
}
std::shared_ptr<SymbolCollector> Collector;
More information about the cfe-commits
mailing list