From 9438256f7d6890d53e575269287b428086f48e70 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 27 Feb 2018 15:19:20 +0000 Subject: [Tooling] [0/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<> Summary: Noticed during review of D41102. I'm not sure whether there are any principal reasons why it returns raw owning pointer, or it is just a old code that was not updated post-C++11. I'm not too sure what testing i should do, because `check-all` is not error clean here for some reason, but it does not //appear// asif those failures are related to these changes. This is clang part. Clang-tools-extra part is D43780. Reviewers: klimek, bkramer, alexfh, pcc Reviewed By: alexfh Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D43779 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326201 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Tooling/Tooling.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'lib/Tooling/Tooling.cpp') diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 7ae2950037..82abede803 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -104,12 +104,12 @@ clang::CompilerInvocation *newInvocation( return Invocation; } -bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, - const Twine &FileName, +bool runToolOnCode(std::unique_ptr ToolAction, + const Twine &Code, const Twine &FileName, std::shared_ptr PCHContainerOps) { - return runToolOnCodeWithArgs(ToolAction, Code, std::vector(), - FileName, "clang-tool", - std::move(PCHContainerOps)); + return runToolOnCodeWithArgs(std::move(ToolAction), Code, + std::vector(), FileName, + "clang-tool", std::move(PCHContainerOps)); } static std::vector @@ -125,7 +125,7 @@ getSyntaxOnlyToolArgs(const Twine &ToolName, } bool runToolOnCodeWithArgs( - clang::FrontendAction *ToolAction, const Twine &Code, + std::unique_ptr ToolAction, const Twine &Code, const std::vector &Args, const Twine &FileName, const Twine &ToolName, std::shared_ptr PCHContainerOps, @@ -143,8 +143,7 @@ bool runToolOnCodeWithArgs( ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(); ToolInvocation Invocation( getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef), - ToolAction, Files.get(), - std::move(PCHContainerOps)); + std::move(ToolAction), Files.get(), std::move(PCHContainerOps)); SmallString<1024> CodeStorage; InMemoryFileSystem->addFile(FileNameRef, 0, @@ -204,15 +203,18 @@ void addTargetAndModeForProgramName(std::vector &CommandLine, namespace { class SingleFrontendActionFactory : public FrontendActionFactory { - FrontendAction *Action; + std::unique_ptr Action; public: - SingleFrontendActionFactory(FrontendAction *Action) : Action(Action) {} + SingleFrontendActionFactory(std::unique_ptr Action) + : Action(std::move(Action)) {} - FrontendAction *create() override { return Action; } + std::unique_ptr create() override { + return std::move(Action); + } }; -} +} // namespace ToolInvocation::ToolInvocation( std::vector CommandLine, ToolAction *Action, @@ -222,12 +224,13 @@ ToolInvocation::ToolInvocation( DiagConsumer(nullptr) {} ToolInvocation::ToolInvocation( - std::vector CommandLine, FrontendAction *FAction, - FileManager *Files, std::shared_ptr PCHContainerOps) + std::vector CommandLine, + std::unique_ptr FAction, FileManager *Files, + std::shared_ptr PCHContainerOps) : CommandLine(std::move(CommandLine)), - Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true), - Files(Files), PCHContainerOps(std::move(PCHContainerOps)), - DiagConsumer(nullptr) {} + Action(new SingleFrontendActionFactory(std::move(FAction))), + OwnsAction(true), Files(Files), + PCHContainerOps(std::move(PCHContainerOps)), DiagConsumer(nullptr) {} ToolInvocation::~ToolInvocation() { if (OwnsAction) -- cgit v1.2.1