[Tooling] [1/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 27 Feb 2018 15:19:28 +0000 (15:19 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 27 Feb 2018 15:19:28 +0000 (15:19 +0000)
Summary:
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-tools-extra part.
Clang part is D43779.

Reviewers: klimek, bkramer, alexfh, pcc

Reviewed By: alexfh

Subscribers: ioeric, jkorous-apple, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D43780

llvm-svn: 326202

clang-tools-extra/clang-move/ClangMove.h
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
clang-tools-extra/include-fixer/find-all-symbols/FindAllSymbolsAction.h
clang-tools-extra/modularize/CoverageChecker.cpp
clang-tools-extra/modularize/Modularize.cpp
clang-tools-extra/pp-trace/PPTrace.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp

index 945c6db..ddcb92a 100644 (file)
@@ -217,8 +217,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 llvm::make_unique<ClangMoveAction>(Context, Reporter);
   }
 
 private:
index a68111b..e217552 100644 (file)
@@ -527,7 +527,9 @@ void runClangTidy(clang::tidy::ClangTidyContext &Context,
   class ActionFactory : public FrontendActionFactory {
   public:
     ActionFactory(ClangTidyContext &Context) : ConsumerFactory(Context) {}
-    FrontendAction *create() override { return new Action(&ConsumerFactory); }
+    std::unique_ptr<clang::FrontendAction> create() override {
+      return llvm::make_unique<Action>(&ConsumerFactory);
+    }
 
   private:
     class Action : public ASTFrontendAction {
index b4f7f0b..bc6241d 100644 (file)
@@ -53,7 +53,7 @@ class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
 public:
   SymbolIndexActionFactory(tooling::ExecutionContext *Ctx) : Ctx(Ctx) {}
 
-  clang::FrontendAction *create() override {
+  std::unique_ptr<clang::FrontendAction> create() override {
     // Wraps the index action and reports collected symbols to the execution
     // context at the end of each translation unit.
     class WrappedIndexAction : public WrapperFrontendAction {
@@ -102,7 +102,8 @@ public:
     auto Includes = llvm::make_unique<CanonicalIncludes>();
     addSystemHeadersMapping(Includes.get());
     CollectorOpts.Includes = Includes.get();
-    return new WrappedIndexAction(
+
+    return llvm::make_unique<WrappedIndexAction>(
         std::make_shared<SymbolCollector>(std::move(CollectorOpts)),
         std::move(Includes), IndexOpts, Ctx);
   }
index 7be9fe2..0e109d5 100644 (file)
@@ -48,8 +48,8 @@ public:
       const HeaderMapCollector::RegexHeaderMap *RegexHeaderMap = nullptr)
       : Reporter(Reporter), RegexHeaderMap(RegexHeaderMap) {}
 
-  clang::FrontendAction *create() override {
-    return new FindAllSymbolsAction(Reporter, RegexHeaderMap);
+  std::unique_ptr<clang::FrontendAction> create() override {
+    return llvm::make_unique<FindAllSymbolsAction>(Reporter, RegexHeaderMap);
   }
 
 private:
index 3687872..3c40688 100644 (file)
@@ -129,8 +129,8 @@ public:
   CoverageCheckerFrontendActionFactory(CoverageChecker &Checker)
     : Checker(Checker) {}
 
-  CoverageCheckerAction *create() override {
-    return new CoverageCheckerAction(Checker);
+  std::unique_ptr<clang::FrontendAction> create() override {
+    return llvm::make_unique<CoverageCheckerAction>(Checker);
   }
 
 private:
index e5f19de..5512f92 100644 (file)
@@ -722,8 +722,9 @@ public:
       : Entities(Entities), PPTracker(preprocessorTracker),
         HadErrors(HadErrors) {}
 
-  CollectEntitiesAction *create() override {
-    return new CollectEntitiesAction(Entities, PPTracker, HadErrors);
+  std::unique_ptr<clang::FrontendAction> create() override {
+    return llvm::make_unique<CollectEntitiesAction>(Entities, PPTracker,
+                                                    HadErrors);
   }
 
 private:
@@ -802,8 +803,8 @@ class CompileCheckFrontendActionFactory : public FrontendActionFactory {
 public:
   CompileCheckFrontendActionFactory() {}
 
-  CompileCheckAction *create() override {
-    return new CompileCheckAction();
+  std::unique_ptr<clang::FrontendAction> create() override {
+    return llvm::make_unique<CompileCheckAction>();
   }
 };
 
index d49bc20..fdc121a 100644 (file)
@@ -139,8 +139,8 @@ public:
                                std::vector<CallbackCall> &CallbackCalls)
       : Ignore(Ignore), CallbackCalls(CallbackCalls) {}
 
-  PPTraceAction *create() override {
-    return new PPTraceAction(Ignore, CallbackCalls);
+  std::unique_ptr<clang::FrontendAction> create() override {
+    return llvm::make_unique<PPTraceAction>(Ignore, CallbackCalls);
   }
 
 private:
index 197c137..fc73022 100644 (file)
@@ -107,7 +107,8 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
   SmallVector<std::unique_ptr<ClangTidyCheck>, 1> Checks;
   CheckFactory<CheckList...>::createChecks(&Context, Checks);
   tooling::ToolInvocation Invocation(
-      Args, new TestClangTidyAction(Checks, Finder, Context), Files.get());
+      Args, llvm::make_unique<TestClangTidyAction>(Checks, Finder, Context),
+      Files.get());
   InMemoryFileSystem->addFile(Filename, 0,
                               llvm::MemoryBuffer::getMemBuffer(Code));
   for (const auto &FileContent : PathsToContent) {
index 27cf630..a014c1e 100644 (file)
@@ -69,7 +69,7 @@ public:
                            CommentHandler *PragmaHandler)
       : COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}
 
-  clang::FrontendAction *create() override {
+  std::unique_ptr<clang::FrontendAction> create() override {
     class WrappedIndexAction : public WrapperFrontendAction {
     public:
       WrappedIndexAction(std::shared_ptr<SymbolCollector> C,
@@ -95,8 +95,9 @@ public:
         index::IndexingOptions::SystemSymbolFilterKind::All;
     IndexOpts.IndexFunctionLocals = false;
     Collector = std::make_shared<SymbolCollector>(COpts);
-    return new WrappedIndexAction(Collector, std::move(IndexOpts),
-                                  PragmaHandler);
+
+    return llvm::make_unique<WrappedIndexAction>(
+        Collector, std::move(IndexOpts), PragmaHandler);
   }
 
   std::shared_ptr<SymbolCollector> Collector;