summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2019-08-29 16:38:36 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2019-08-29 16:38:36 +0000
commit907452107dfb1e7ffdc2e8e70eecdeb95ca7ef2f (patch)
tree5e7ac2f87be2d204fde9762ebf7282171d9fb0c9
parent87720ac8c8d3263b9ff97d9f46e2b83ed66a9750 (diff)
downloadbcm5719-llvm-907452107dfb1e7ffdc2e8e70eecdeb95ca7ef2f.tar.gz
bcm5719-llvm-907452107dfb1e7ffdc2e8e70eecdeb95ca7ef2f.zip
Changed FrontendActionFactory::create to return a std::unique_ptr
Subscribers: jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66947 llvm-svn: 370379
-rw-r--r--clang-tools-extra/clang-doc/ClangDoc.cpp6
-rw-r--r--clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h4
-rw-r--r--clang-tools-extra/clang-move/Move.h4
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidy.cpp4
-rw-r--r--clang-tools-extra/clangd/indexer/IndexerMain.cpp55
-rw-r--r--clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp5
-rw-r--r--clang-tools-extra/modularize/CoverageChecker.cpp5
-rw-r--r--clang-tools-extra/modularize/Modularize.cpp11
-rw-r--r--clang-tools-extra/pp-trace/PPTrace.cpp5
-rw-r--r--clang/include/clang/Tooling/Tooling.h50
-rw-r--r--clang/lib/Tooling/Tooling.cpp15
-rw-r--r--clang/tools/clang-refactor/ClangRefactor.cpp4
-rw-r--r--clang/unittests/Tooling/ExecutionTest.cpp4
13 files changed, 114 insertions, 58 deletions
diff --git a/clang-tools-extra/clang-doc/ClangDoc.cpp b/clang-tools-extra/clang-doc/ClangDoc.cpp
index 261139bc375..da4165a18d0 100644
--- a/clang-tools-extra/clang-doc/ClangDoc.cpp
+++ b/clang-tools-extra/clang-doc/ClangDoc.cpp
@@ -29,13 +29,13 @@ namespace doc {
class MapperActionFactory : public tooling::FrontendActionFactory {
public:
MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
- clang::FrontendAction *create() override;
+ std::unique_ptr<FrontendAction> create() override;
private:
ClangDocContext CDCtx;
};
-clang::FrontendAction *MapperActionFactory::create() {
+std::unique_ptr<FrontendAction> MapperActionFactory::create() {
class ClangDocAction : public clang::ASTFrontendAction {
public:
ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
@@ -49,7 +49,7 @@ clang::FrontendAction *MapperActionFactory::create() {
private:
ClangDocContext CDCtx;
};
- return new ClangDocAction(CDCtx);
+ return std::make_unique<ClangDocAction>(CDCtx);
}
std::unique_ptr<tooling::FrontendActionFactory>
diff --git a/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h b/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
index ccffa4b3c9d..1a8b99a35ae 100644
--- a/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
+++ b/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
@@ -47,8 +47,8 @@ public:
const HeaderMapCollector::RegexHeaderMap *RegexHeaderMap = nullptr)
: Reporter(Reporter), RegexHeaderMap(RegexHeaderMap) {}
- clang::FrontendAction *create() override {
- return new FindAllSymbolsAction(Reporter, RegexHeaderMap);
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<FindAllSymbolsAction>(Reporter, RegexHeaderMap);
}
private:
diff --git a/clang-tools-extra/clang-move/Move.h b/clang-tools-extra/clang-move/Move.h
index da4bc444b4a..ea241bbbc4f 100644
--- a/clang-tools-extra/clang-move/Move.h
+++ b/clang-tools-extra/clang-move/Move.h
@@ -224,8 +224,8 @@ public:
DeclarationReporter *const Reporter = nullptr)
: Context(Context), Reporter(Reporter) {}
- clang::FrontendAction *create() override {
- return new ClangMoveAction(Context, Reporter);
+ std::unique_ptr<clang::FrontendAction> create() override {
+ return std::make_unique<ClangMoveAction>(Context, Reporter);
}
private:
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index dd5c35e7633..73933e3f250 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -530,7 +530,9 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
ActionFactory(ClangTidyContext &Context,
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS)
: ConsumerFactory(Context, BaseFS) {}
- FrontendAction *create() override { return new Action(&ConsumerFactory); }
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<Action>(&ConsumerFactory);
+ }
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
FileManager *Files,
diff --git a/clang-tools-extra/clangd/indexer/IndexerMain.cpp b/clang-tools-extra/clangd/indexer/IndexerMain.cpp
index 97d8d1283b6..dac038308d9 100644
--- a/clang-tools-extra/clangd/indexer/IndexerMain.cpp
+++ b/clang-tools-extra/clangd/indexer/IndexerMain.cpp
@@ -39,37 +39,36 @@ class IndexActionFactory : public tooling::FrontendActionFactory {
public:
IndexActionFactory(IndexFileIn &Result) : Result(Result) {}
- clang::FrontendAction *create() override {
+ std::unique_ptr<FrontendAction> create() override {
SymbolCollector::Options Opts;
Opts.CountReferences = true;
return createStaticIndexingAction(
- Opts,
- [&](SymbolSlab S) {
- // Merge as we go.
- std::lock_guard<std::mutex> Lock(SymbolsMu);
- for (const auto &Sym : S) {
- if (const auto *Existing = Symbols.find(Sym.ID))
- Symbols.insert(mergeSymbol(*Existing, Sym));
- else
- Symbols.insert(Sym);
- }
- },
- [&](RefSlab S) {
- std::lock_guard<std::mutex> Lock(SymbolsMu);
- for (const auto &Sym : S) {
- // Deduplication happens during insertion.
- for (const auto &Ref : Sym.second)
- Refs.insert(Sym.first, Ref);
- }
- },
- [&](RelationSlab S) {
- std::lock_guard<std::mutex> Lock(SymbolsMu);
- for (const auto &R : S) {
- Relations.insert(R);
- }
- },
- /*IncludeGraphCallback=*/nullptr)
- .release();
+ Opts,
+ [&](SymbolSlab S) {
+ // Merge as we go.
+ std::lock_guard<std::mutex> Lock(SymbolsMu);
+ for (const auto &Sym : S) {
+ if (const auto *Existing = Symbols.find(Sym.ID))
+ Symbols.insert(mergeSymbol(*Existing, Sym));
+ else
+ Symbols.insert(Sym);
+ }
+ },
+ [&](RefSlab S) {
+ std::lock_guard<std::mutex> Lock(SymbolsMu);
+ for (const auto &Sym : S) {
+ // Deduplication happens during insertion.
+ for (const auto &Ref : Sym.second)
+ Refs.insert(Sym.first, Ref);
+ }
+ },
+ [&](RelationSlab S) {
+ std::lock_guard<std::mutex> Lock(SymbolsMu);
+ for (const auto &R : S) {
+ Relations.insert(R);
+ }
+ },
+ /*IncludeGraphCallback=*/nullptr);
}
// Awkward: we write the result in the destructor, because the executor
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index a9248e1cfc0..aa5bc77b5f1 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -200,7 +200,7 @@ public:
CommentHandler *PragmaHandler)
: COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}
- clang::FrontendAction *create() override {
+ std::unique_ptr<FrontendAction> create() override {
class IndexAction : public ASTFrontendAction {
public:
IndexAction(std::shared_ptr<index::IndexDataConsumer> DataConsumer,
@@ -232,7 +232,8 @@ public:
index::IndexingOptions::SystemSymbolFilterKind::All;
IndexOpts.IndexFunctionLocals = false;
Collector = std::make_shared<SymbolCollector>(COpts);
- return new IndexAction(Collector, std::move(IndexOpts), PragmaHandler);
+ return std::make_unique<IndexAction>(Collector, std::move(IndexOpts),
+ PragmaHandler);
}
std::shared_ptr<SymbolCollector> Collector;
diff --git a/clang-tools-extra/modularize/CoverageChecker.cpp b/clang-tools-extra/modularize/CoverageChecker.cpp
index af257abb523..6cfeb0e2dab 100644
--- a/clang-tools-extra/modularize/CoverageChecker.cpp
+++ b/clang-tools-extra/modularize/CoverageChecker.cpp
@@ -58,6 +58,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
@@ -129,8 +130,8 @@ public:
CoverageCheckerFrontendActionFactory(CoverageChecker &Checker)
: Checker(Checker) {}
- CoverageCheckerAction *create() override {
- return new CoverageCheckerAction(Checker);
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<CoverageCheckerAction>(Checker);
}
private:
diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp
index 8d333103da3..e4bbb04d358 100644
--- a/clang-tools-extra/modularize/Modularize.cpp
+++ b/clang-tools-extra/modularize/Modularize.cpp
@@ -233,6 +233,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Tooling/CompilationDatabase.h"
@@ -721,8 +722,9 @@ public:
: Entities(Entities), PPTracker(preprocessorTracker),
HadErrors(HadErrors) {}
- CollectEntitiesAction *create() override {
- return new CollectEntitiesAction(Entities, PPTracker, HadErrors);
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<CollectEntitiesAction>(Entities, PPTracker,
+ HadErrors);
}
private:
@@ -801,8 +803,8 @@ class CompileCheckFrontendActionFactory : public FrontendActionFactory {
public:
CompileCheckFrontendActionFactory() {}
- CompileCheckAction *create() override {
- return new CompileCheckAction();
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<CompileCheckAction>();
}
};
@@ -886,6 +888,7 @@ int main(int Argc, const char **Argv) {
CompileCheckTool.appendArgumentsAdjuster(
getModularizeArgumentsAdjuster(ModUtil->Dependencies));
int CompileCheckFileErrors = 0;
+ // FIXME: use newFrontendActionFactory.
CompileCheckFrontendActionFactory CompileCheckFactory;
CompileCheckFileErrors |= CompileCheckTool.run(&CompileCheckFactory);
if (CompileCheckFileErrors != 0) {
diff --git a/clang-tools-extra/pp-trace/PPTrace.cpp b/clang-tools-extra/pp-trace/PPTrace.cpp
index fcc811c53f3..f91b01969a7 100644
--- a/clang-tools-extra/pp-trace/PPTrace.cpp
+++ b/clang-tools-extra/pp-trace/PPTrace.cpp
@@ -30,6 +30,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Driver/Options.h"
#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Tooling/Execution.h"
@@ -112,7 +113,9 @@ public:
PPTraceFrontendActionFactory(const FilterType &Filters, raw_ostream &OS)
: Filters(Filters), OS(OS) {}
- PPTraceAction *create() override { return new PPTraceAction(Filters, OS); }
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<PPTraceAction>(Filters, OS);
+ }
private:
const FilterType &Filters;
diff --git a/clang/include/clang/Tooling/Tooling.h b/clang/include/clang/Tooling/Tooling.h
index 83fe43ac59e..5df816e6715 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -99,9 +99,7 @@ public:
DiagnosticConsumer *DiagConsumer) override;
/// Returns a new clang::FrontendAction.
- ///
- /// The caller takes ownership of the returned action.
- virtual FrontendAction *create() = 0;
+ virtual std::unique_ptr<FrontendAction> create() = 0;
};
/// Returns a new FrontendActionFactory for a given type.
@@ -161,6 +159,14 @@ bool runToolOnCode(FrontendAction *ToolAction, const Twine &Code,
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<PCHContainerOperations>());
+inline bool
+runToolOnCode(std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
+ const Twine &FileName = "input.cc",
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps =
+ std::make_shared<PCHContainerOperations>()) {
+ return runToolOnCode(ToolAction.release(), Code, FileName, PCHContainerOps);
+}
+
/// The first part of the pair is the filename, the second part the
/// file-content.
using FileContentMappings = std::vector<std::pair<std::string, std::string>>;
@@ -186,6 +192,17 @@ bool runToolOnCodeWithArgs(
std::make_shared<PCHContainerOperations>(),
const FileContentMappings &VirtualMappedFiles = FileContentMappings());
+inline bool runToolOnCodeWithArgs(
+ std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
+ const std::vector<std::string> &Args, const Twine &FileName = "input.cc",
+ const Twine &ToolName = "clang-tool",
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps =
+ std::make_shared<PCHContainerOperations>(),
+ const FileContentMappings &VirtualMappedFiles = FileContentMappings()) {
+ return runToolOnCodeWithArgs(ToolAction.release(), Code, Args, FileName,
+ ToolName, PCHContainerOps, VirtualMappedFiles);
+}
+
// Similar to the overload except this takes a VFS.
bool runToolOnCodeWithArgs(
FrontendAction *ToolAction, const Twine &Code,
@@ -195,6 +212,17 @@ bool runToolOnCodeWithArgs(
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<PCHContainerOperations>());
+inline bool runToolOnCodeWithArgs(
+ std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
+ const std::vector<std::string> &Args, const Twine &FileName = "input.cc",
+ const Twine &ToolName = "clang-tool",
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps =
+ std::make_shared<PCHContainerOperations>()) {
+ return runToolOnCodeWithArgs(ToolAction.release(), Code, VFS, Args, FileName,
+ ToolName, PCHContainerOps);
+}
+
/// Builds an AST for 'Code'.
///
/// \param Code C++ code.
@@ -247,6 +275,13 @@ public:
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<PCHContainerOperations>());
+ ToolInvocation(std::vector<std::string> CommandLine,
+ std::unique_ptr<FrontendAction> FAction, FileManager *Files,
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps =
+ std::make_shared<PCHContainerOperations>())
+ : ToolInvocation(std::move(CommandLine), FAction.release(), Files,
+ PCHContainerOps) {}
+
/// Create a tool invocation.
///
/// \param CommandLine The command line arguments to clang.
@@ -397,7 +432,9 @@ template <typename T>
std::unique_ptr<FrontendActionFactory> newFrontendActionFactory() {
class SimpleFrontendActionFactory : public FrontendActionFactory {
public:
- FrontendAction *create() override { return new T; }
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<T>();
+ }
};
return std::unique_ptr<FrontendActionFactory>(
@@ -413,8 +450,9 @@ inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(
SourceFileCallbacks *Callbacks)
: ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
- FrontendAction *create() override {
- return new ConsumerFactoryAdaptor(ConsumerFactory, Callbacks);
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<ConsumerFactoryAdaptor>(ConsumerFactory,
+ Callbacks);
}
private:
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index b21fc33ac39..8c0d13d243d 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -247,12 +247,15 @@ void addTargetAndModeForProgramName(std::vector<std::string> &CommandLine,
namespace {
class SingleFrontendActionFactory : public FrontendActionFactory {
- FrontendAction *Action;
+ std::unique_ptr<FrontendAction> Action;
public:
- SingleFrontendActionFactory(FrontendAction *Action) : Action(Action) {}
+ SingleFrontendActionFactory(std::unique_ptr<FrontendAction> Action)
+ : Action(std::move(Action)) {}
- FrontendAction *create() override { return Action; }
+ std::unique_ptr<FrontendAction> create() override {
+ return std::move(Action);
+ }
};
} // namespace
@@ -267,8 +270,10 @@ ToolInvocation::ToolInvocation(
std::vector<std::string> CommandLine, FrontendAction *FAction,
FileManager *Files, std::shared_ptr<PCHContainerOperations> PCHContainerOps)
: CommandLine(std::move(CommandLine)),
- Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true),
- Files(Files), PCHContainerOps(std::move(PCHContainerOps)) {}
+ Action(new SingleFrontendActionFactory(
+ std::unique_ptr<FrontendAction>(FAction))),
+ OwnsAction(true), Files(Files),
+ PCHContainerOps(std::move(PCHContainerOps)) {}
ToolInvocation::~ToolInvocation() {
if (OwnsAction)
diff --git a/clang/tools/clang-refactor/ClangRefactor.cpp b/clang/tools/clang-refactor/ClangRefactor.cpp
index 2a9d6ffefb7..8b44c7fa6ed 100644
--- a/clang/tools/clang-refactor/ClangRefactor.cpp
+++ b/clang/tools/clang-refactor/ClangRefactor.cpp
@@ -461,7 +461,9 @@ public:
ToolActionFactory(TUCallbackType Callback)
: Callback(std::move(Callback)) {}
- FrontendAction *create() override { return new ToolASTAction(Callback); }
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<ToolASTAction>(Callback);
+ }
private:
TUCallbackType Callback;
diff --git a/clang/unittests/Tooling/ExecutionTest.cpp b/clang/unittests/Tooling/ExecutionTest.cpp
index 3e1e51e98fe..16455fb2fd7 100644
--- a/clang/unittests/Tooling/ExecutionTest.cpp
+++ b/clang/unittests/Tooling/ExecutionTest.cpp
@@ -78,7 +78,9 @@ private:
class ReportResultActionFactory : public FrontendActionFactory {
public:
ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
- FrontendAction *create() override { return new ReportResultAction(Context); }
+ std::unique_ptr<FrontendAction> create() override {
+ return std::make_unique<ReportResultAction>(Context);
+ }
private:
ExecutionContext *const Context;
OpenPOWER on IntegriCloud