[clang-tools-extra] r213308 - unique_ptr-ify ownership of ASTConsumers

David Blaikie dblaikie at gmail.com
Thu Jul 17 13:40:47 PDT 2014


Author: dblaikie
Date: Thu Jul 17 15:40:47 2014
New Revision: 213308

URL: http://llvm.org/viewvc/llvm-project?rev=213308&view=rev
Log:
unique_ptr-ify ownership of ASTConsumers

Modified:
    clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp
    clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
    clang-tools-extra/trunk/clang-tidy/ClangTidy.h
    clang-tools-extra/trunk/modularize/Modularize.cpp
    clang-tools-extra/trunk/module-map-checker/ModuleMapChecker.cpp
    clang-tools-extra/trunk/pp-trace/PPTrace.cpp
    clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp

Modified: clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp?rev=213308&r1=213307&r2=213308&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/Core/Transform.cpp Thu Jul 17 15:40:47 2014
@@ -49,7 +49,8 @@ private:
     FactoryAdaptor(MatchFinder &Finder, Transform &Owner)
         : Finder(Finder), Owner(Owner) {}
 
-    ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) {
+    std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &,
+                                                   StringRef) {
       return Finder.newASTConsumer();
     }
 

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=213308&r1=213307&r2=213308&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu Jul 17 15:40:47 2014
@@ -179,10 +179,10 @@ private:
 
 class ClangTidyASTConsumer : public MultiplexConsumer {
 public:
-  ClangTidyASTConsumer(const SmallVectorImpl<ASTConsumer *> &Consumers,
+  ClangTidyASTConsumer(std::vector<std::unique_ptr<ASTConsumer>> Consumers,
                        std::unique_ptr<ast_matchers::MatchFinder> Finder,
                        std::vector<std::unique_ptr<ClangTidyCheck>> Checks)
-      : MultiplexConsumer(Consumers), Finder(std::move(Finder)),
+      : MultiplexConsumer(std::move(Consumers)), Finder(std::move(Finder)),
         Checks(std::move(Checks)) {}
 
 private:
@@ -203,8 +203,8 @@ ClangTidyASTConsumerFactory::ClangTidyAS
   }
 }
 
-
-clang::ASTConsumer *ClangTidyASTConsumerFactory::CreateASTConsumer(
+std::unique_ptr<clang::ASTConsumer>
+ClangTidyASTConsumerFactory::CreateASTConsumer(
     clang::CompilerInstance &Compiler, StringRef File) {
   // FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
   // modify Compiler.
@@ -224,7 +224,7 @@ clang::ASTConsumer *ClangTidyASTConsumer
     Check->registerPPCallbacks(Compiler);
   }
 
-  SmallVector<ASTConsumer *, 2> Consumers;
+  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
   if (!Checks.empty())
     Consumers.push_back(Finder->newASTConsumer());
 
@@ -240,15 +240,16 @@ clang::ASTConsumer *ClangTidyASTConsumer
     AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
     AnalyzerOptions->AnalyzeNestedBlocks = true;
     AnalyzerOptions->eagerlyAssumeBinOpBifurcation = true;
-    ento::AnalysisASTConsumer *AnalysisConsumer = ento::CreateAnalysisConsumer(
-        Compiler.getPreprocessor(), Compiler.getFrontendOpts().OutputFile,
-        AnalyzerOptions, Compiler.getFrontendOpts().Plugins);
+    std::unique_ptr<ento::AnalysisASTConsumer> AnalysisConsumer =
+        ento::CreateAnalysisConsumer(
+            Compiler.getPreprocessor(), Compiler.getFrontendOpts().OutputFile,
+            AnalyzerOptions, Compiler.getFrontendOpts().Plugins);
     AnalysisConsumer->AddDiagnosticConsumer(
         new AnalyzerDiagnosticConsumer(Context));
-    Consumers.push_back(AnalysisConsumer);
+    Consumers.push_back(std::move(AnalysisConsumer));
   }
-  return new ClangTidyASTConsumer(Consumers, std::move(Finder),
-                                  std::move(Checks));
+  return llvm::make_unique<ClangTidyASTConsumer>(
+      std::move(Consumers), std::move(Finder), std::move(Checks));
 }
 
 std::vector<std::string>
@@ -339,8 +340,8 @@ ClangTidyStats runClangTidy(ClangTidyOpt
     class Action : public ASTFrontendAction {
     public:
       Action(ClangTidyASTConsumerFactory *Factory) : Factory(Factory) {}
-      ASTConsumer *CreateASTConsumer(CompilerInstance &Compiler,
-                                     StringRef File) override {
+      std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,
+                                                     StringRef File) override {
         return Factory->CreateASTConsumer(Compiler, File);
       }
 

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.h?rev=213308&r1=213307&r2=213308&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.h Thu Jul 17 15:40:47 2014
@@ -99,8 +99,8 @@ public:
   ClangTidyASTConsumerFactory(ClangTidyContext &Context);
 
   /// \brief Returns an ASTConsumer that runs the specified clang-tidy checks.
-  clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &Compiler,
-                                        StringRef File);
+  std::unique_ptr<clang::ASTConsumer>
+  CreateASTConsumer(clang::CompilerInstance &Compiler, StringRef File);
 
   /// \brief Get the list of enabled checks.
   std::vector<std::string> getCheckNames(ChecksFilter &Filter);

Modified: clang-tools-extra/trunk/modularize/Modularize.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Modularize.cpp?rev=213308&r1=213307&r2=213308&view=diff
==============================================================================
--- clang-tools-extra/trunk/modularize/Modularize.cpp (original)
+++ clang-tools-extra/trunk/modularize/Modularize.cpp Thu Jul 17 15:40:47 2014
@@ -652,10 +652,10 @@ public:
         HadErrors(HadErrors) {}
 
 protected:
-  virtual clang::ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
-                                                StringRef InFile) {
-    return new CollectEntitiesConsumer(Entities, PPTracker,
-                                       CI.getPreprocessor(), InFile, HadErrors);
+  std::unique_ptr<clang::ASTConsumer>
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+    return llvm::make_unique<CollectEntitiesConsumer>(
+        Entities, PPTracker, CI.getPreprocessor(), InFile, HadErrors);
   }
 
 private:

Modified: clang-tools-extra/trunk/module-map-checker/ModuleMapChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/module-map-checker/ModuleMapChecker.cpp?rev=213308&r1=213307&r2=213308&view=diff
==============================================================================
--- clang-tools-extra/trunk/module-map-checker/ModuleMapChecker.cpp (original)
+++ clang-tools-extra/trunk/module-map-checker/ModuleMapChecker.cpp Thu Jul 17 15:40:47 2014
@@ -178,9 +178,10 @@ public:
   ModuleMapCheckerAction(ModuleMapChecker &Checker) : Checker(Checker) {}
 
 protected:
-  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
-                                         StringRef InFile) {
-    return new ModuleMapCheckerConsumer(Checker, CI.getPreprocessor());
+  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
+                                                 StringRef InFile) override {
+    return llvm::make_unique<ModuleMapCheckerConsumer>(Checker,
+                                                       CI.getPreprocessor());
   }
 
 private:

Modified: clang-tools-extra/trunk/pp-trace/PPTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/pp-trace/PPTrace.cpp?rev=213308&r1=213307&r2=213308&view=diff
==============================================================================
--- clang-tools-extra/trunk/pp-trace/PPTrace.cpp (original)
+++ clang-tools-extra/trunk/pp-trace/PPTrace.cpp Thu Jul 17 15:40:47 2014
@@ -120,9 +120,10 @@ public:
       : Ignore(Ignore), CallbackCalls(CallbackCalls) {}
 
 protected:
-  virtual clang::ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
-                                                StringRef InFile) {
-    return new PPTraceConsumer(Ignore, CallbackCalls, CI.getPreprocessor());
+  std::unique_ptr<clang::ASTConsumer>
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+    return llvm::make_unique<PPTraceConsumer>(Ignore, CallbackCalls,
+                                              CI.getPreprocessor());
   }
 
 private:

Modified: clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp?rev=213308&r1=213307&r2=213308&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-modernize/TransformTest.cpp Thu Jul 17 15:40:47 2014
@@ -93,8 +93,8 @@ public:
 };
 
 struct ConsumerFactory {
-  ASTConsumer *newASTConsumer() {
-    return new TimePassingASTConsumer(&Called);
+  std::unique_ptr<ASTConsumer> newASTConsumer() {
+    return llvm::make_unique<TimePassingASTConsumer>(&Called);
   }
   bool Called;
 };





More information about the cfe-commits mailing list