From b53da8604800249ab936b1316b1d81a81841a3d8 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sun, 10 Aug 2014 19:56:51 +0000 Subject: [PATCH] Recommit 213307: unique_ptr-ify ownership of ASTConsumers (reverted in r213325) After post-commit review and community discussion, this seems like a reasonable direction to continue, making ownership semantics explicit in the source using the type system. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215323 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../PrintFunctionNames/PrintFunctionNames.cpp | 5 +- include/clang/ARCMigrate/ARCMTActions.h | 8 +- include/clang/ASTMatchers/ASTMatchFinder.h | 2 +- include/clang/CodeGen/CodeGenAction.h | 4 +- include/clang/Frontend/ASTConsumers.h | 14 ++- include/clang/Frontend/CompilerInstance.h | 5 +- include/clang/Frontend/FrontendAction.h | 23 ++-- include/clang/Frontend/FrontendActions.h | 51 ++++---- include/clang/Frontend/MultiplexConsumer.h | 4 +- include/clang/Rewrite/Frontend/ASTConsumers.h | 28 ++--- .../clang/Rewrite/Frontend/FrontendActions.h | 12 +- .../Frontend/AnalysisConsumer.h | 7 +- .../StaticAnalyzer/Frontend/FrontendActions.h | 4 +- include/clang/Tooling/Tooling.h | 5 +- lib/ARCMigrate/ARCMT.cpp | 6 +- lib/ARCMigrate/ObjCMT.cpp | 38 +++--- lib/ASTMatchers/ASTMatchFinder.cpp | 4 +- lib/CodeGen/CodeGenAction.cpp | 16 +-- lib/Frontend/ASTConsumers.cpp | 25 ++-- lib/Frontend/ASTMerge.cpp | 4 +- lib/Frontend/ASTUnit.cpp | 32 ++--- lib/Frontend/ChainedIncludesSource.cpp | 8 +- lib/Frontend/CompilerInstance.cpp | 4 +- lib/Frontend/FrontendAction.cpp | 38 +++--- lib/Frontend/FrontendActions.cpp | 63 +++++----- lib/Frontend/MultiplexConsumer.cpp | 111 +++++++++--------- lib/Frontend/Rewrite/FrontendActions.cpp | 14 +-- lib/Frontend/Rewrite/HTMLPrint.cpp | 11 +- lib/Frontend/Rewrite/RewriteModernObjC.cpp | 13 +- lib/Frontend/Rewrite/RewriteObjC.cpp | 12 +- .../Frontend/AnalysisConsumer.cpp | 4 +- .../Frontend/FrontendActions.cpp | 4 +- tools/clang-check/ClangCheck.cpp | 5 +- tools/libclang/Indexing.cpp | 11 +- unittests/AST/EvaluateAsRValueTest.cpp | 7 +- unittests/AST/ExternalASTSourceTest.cpp | 6 +- unittests/AST/NamedDeclPrinterTest.cpp | 4 +- unittests/Frontend/FrontendActionTest.cpp | 6 +- unittests/Sema/ExternalSemaSourceTest.cpp | 4 +- unittests/Tooling/RefactoringTest.cpp | 7 +- unittests/Tooling/TestVisitor.h | 6 +- unittests/Tooling/ToolingTest.cpp | 50 ++++---- 42 files changed, 346 insertions(+), 339 deletions(-) diff --git a/examples/PrintFunctionNames/PrintFunctionNames.cpp b/examples/PrintFunctionNames/PrintFunctionNames.cpp index 3f18cd45e5..e8a361dbee 100644 --- a/examples/PrintFunctionNames/PrintFunctionNames.cpp +++ b/examples/PrintFunctionNames/PrintFunctionNames.cpp @@ -36,8 +36,9 @@ public: class PrintFunctionNamesAction : public PluginASTAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, llvm::StringRef) { - return new PrintFunctionsConsumer(); + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + llvm::StringRef) { + return llvm::make_unique(); } bool ParseArgs(const CompilerInstance &CI, diff --git a/include/clang/ARCMigrate/ARCMTActions.h b/include/clang/ARCMigrate/ARCMTActions.h index b3e74b9966..0f45ccc0f4 100644 --- a/include/clang/ARCMigrate/ARCMTActions.h +++ b/include/clang/ARCMigrate/ARCMTActions.h @@ -37,8 +37,8 @@ class MigrateSourceAction : public ASTFrontendAction { FileRemapper Remapper; protected: bool BeginInvocation(CompilerInstance &CI) override; - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; class MigrateAction : public WrapperFrontendAction { @@ -65,8 +65,8 @@ public: unsigned migrateAction); protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; bool BeginInvocation(CompilerInstance &CI) override; }; diff --git a/include/clang/ASTMatchers/ASTMatchFinder.h b/include/clang/ASTMatchers/ASTMatchFinder.h index 9e90270dcf..5a8aff13bc 100644 --- a/include/clang/ASTMatchers/ASTMatchFinder.h +++ b/include/clang/ASTMatchers/ASTMatchFinder.h @@ -148,7 +148,7 @@ public: MatchCallback *Action); /// \brief Creates a clang ASTConsumer that finds all matches. - clang::ASTConsumer *newASTConsumer(); + std::unique_ptr newASTConsumer(); /// \brief Calls the registered callbacks on all matches on the given \p Node. /// diff --git a/include/clang/CodeGen/CodeGenAction.h b/include/clang/CodeGen/CodeGenAction.h index 37819c780d..4619b48378 100644 --- a/include/clang/CodeGen/CodeGenAction.h +++ b/include/clang/CodeGen/CodeGenAction.h @@ -37,8 +37,8 @@ protected: bool hasIRSupport() const override; - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; void ExecuteAction() override; diff --git a/include/clang/Frontend/ASTConsumers.h b/include/clang/Frontend/ASTConsumers.h index 366c499b67..4afcb0c28a 100644 --- a/include/clang/Frontend/ASTConsumers.h +++ b/include/clang/Frontend/ASTConsumers.h @@ -16,6 +16,8 @@ #include "clang/Basic/LLVM.h" +#include + namespace clang { class ASTConsumer; @@ -30,24 +32,26 @@ class TargetOptions; // original C code. The output is intended to be in a format such that // clang could re-parse the output back into the same AST, but the // implementation is still incomplete. -ASTConsumer *CreateASTPrinter(raw_ostream *OS, StringRef FilterString); +std::unique_ptr CreateASTPrinter(raw_ostream *OS, + StringRef FilterString); // AST dumper: dumps the raw AST in human-readable form to stderr; this is // intended for debugging. -ASTConsumer *CreateASTDumper(StringRef FilterString, bool DumpLookups = false); +std::unique_ptr CreateASTDumper(StringRef FilterString, + bool DumpLookups = false); // AST Decl node lister: prints qualified names of all filterable AST Decl // nodes. -ASTConsumer *CreateASTDeclNodeLister(); +std::unique_ptr CreateASTDeclNodeLister(); // Graphical AST viewer: for each function definition, creates a graph of // the AST and displays it with the graph viewer "dotty". Also outputs // function declarations to stderr. -ASTConsumer *CreateASTViewer(); +std::unique_ptr CreateASTViewer(); // DeclContext printer: prints out the DeclContext tree in human-readable form // to stderr; this is intended for debugging. -ASTConsumer *CreateDeclContextPrinter(); +std::unique_ptr CreateDeclContextPrinter(); } // end clang namespace diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index a9fc371178..7194057462 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -14,6 +14,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/Utils.h" +#include "clang/AST/ASTConsumer.h" #include "clang/Lex/ModuleLoader.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" @@ -443,11 +444,11 @@ public: /// takeASTConsumer - Remove the current AST consumer and give ownership to /// the caller. - ASTConsumer *takeASTConsumer() { return Consumer.release(); } + std::unique_ptr takeASTConsumer() { return std::move(Consumer); } /// setASTConsumer - Replace the current AST consumer; the compiler instance /// takes ownership of \p Value. - void setASTConsumer(ASTConsumer *Value); + void setASTConsumer(std::unique_ptr Value); /// } /// @name Semantic analysis diff --git a/include/clang/Frontend/FrontendAction.h b/include/clang/Frontend/FrontendAction.h index 95e1c09c0c..3eb9d7930a 100644 --- a/include/clang/Frontend/FrontendAction.h +++ b/include/clang/Frontend/FrontendAction.h @@ -41,8 +41,8 @@ class FrontendAction { friend class WrapperFrontendAction; private: - ASTConsumer* CreateWrappedASTConsumer(CompilerInstance &CI, - StringRef InFile); + std::unique_ptr CreateWrappedASTConsumer(CompilerInstance &CI, + StringRef InFile); protected: /// @name Implementation Action Interface @@ -61,8 +61,8 @@ protected: /// getCurrentFile(). /// /// \return The new AST consumer, or null on failure. - virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) = 0; + virtual std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) = 0; /// \brief Callback before starting processing a single input, giving the /// opportunity to modify the CompilerInvocation or do some other action @@ -229,11 +229,10 @@ public: class PluginASTAction : public ASTFrontendAction { virtual void anchor(); -protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override = 0; - public: + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override = 0; + /// \brief Parse the given plugin command line arguments. /// /// \param CI - The compiler instance, for use in reporting diagnostics. @@ -249,8 +248,8 @@ class PreprocessorFrontendAction : public FrontendAction { protected: /// \brief Provide a default implementation which returns aborts; /// this method should never be called by FrontendAction clients. - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; public: bool usesPreprocessorOnly() const override { return true; } @@ -266,8 +265,8 @@ class WrapperFrontendAction : public FrontendAction { std::unique_ptr WrappedAction; protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; bool BeginInvocation(CompilerInstance &CI) override; bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override; void ExecuteAction() override; diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h index 84cc82cfbe..850f87c073 100644 --- a/include/clang/Frontend/FrontendActions.h +++ b/include/clang/Frontend/FrontendActions.h @@ -26,8 +26,8 @@ class FileEntry; class InitOnlyAction : public FrontendAction { void ExecuteAction() override; - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; public: // Don't claim to only use the preprocessor, we want to follow the AST path, @@ -41,38 +41,38 @@ public: class ASTPrintAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; class ASTDumpAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; class ASTDeclListAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; class ASTViewAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; class DeclContextPrintAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; class GeneratePCHAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; TranslationUnitKind getTranslationUnitKind() override { return TU_Prefix; @@ -98,8 +98,8 @@ class GenerateModuleAction : public ASTFrontendAction { bool IsSystem; protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; TranslationUnitKind getTranslationUnitKind() override { return TU_Module; @@ -128,8 +128,8 @@ public: class SyntaxOnlyAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; public: bool hasCodeCompletionSupport() const override { return true; } @@ -139,8 +139,8 @@ public: /// basic debugging and discovery. class DumpModuleInfoAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; void ExecuteAction() override; public: @@ -152,8 +152,8 @@ public: class VerifyPCHAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; void ExecuteAction() override; @@ -177,8 +177,8 @@ class ASTMergeAction : public FrontendAction { std::vector ASTFiles; protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override; @@ -200,7 +200,8 @@ public: class PrintPreambleAction : public FrontendAction { protected: void ExecuteAction() override; - ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) override { + std::unique_ptr CreateASTConsumer(CompilerInstance &, + StringRef) override { return nullptr; } diff --git a/include/clang/Frontend/MultiplexConsumer.h b/include/clang/Frontend/MultiplexConsumer.h index 4d31104cce..8c414e7d46 100644 --- a/include/clang/Frontend/MultiplexConsumer.h +++ b/include/clang/Frontend/MultiplexConsumer.h @@ -29,7 +29,7 @@ class MultiplexASTDeserializationListener; class MultiplexConsumer : public SemaConsumer { public: // Takes ownership of the pointers in C. - MultiplexConsumer(ArrayRef C); + MultiplexConsumer(std::vector> C); ~MultiplexConsumer(); // ASTConsumer @@ -59,7 +59,7 @@ public: void ForgetSema() override; private: - std::vector Consumers; // Owns these. + std::vector> Consumers; // Owns these. std::unique_ptr MutationListener; std::unique_ptr DeserializationListener; }; diff --git a/include/clang/Rewrite/Frontend/ASTConsumers.h b/include/clang/Rewrite/Frontend/ASTConsumers.h index 584af3fa18..9ea96cd423 100644 --- a/include/clang/Rewrite/Frontend/ASTConsumers.h +++ b/include/clang/Rewrite/Frontend/ASTConsumers.h @@ -15,6 +15,8 @@ #define REWRITE_ASTCONSUMERS_H #include "clang/Basic/LLVM.h" + +#include #include namespace clang { @@ -26,23 +28,21 @@ class Preprocessor; // ObjC rewriter: attempts to rewrite ObjC constructs into pure C code. // This is considered experimental, and only works with Apple's ObjC runtime. -ASTConsumer *CreateObjCRewriter(const std::string &InFile, - raw_ostream *OS, - DiagnosticsEngine &Diags, - const LangOptions &LOpts, - bool SilenceRewriteMacroWarning); -ASTConsumer *CreateModernObjCRewriter(const std::string &InFile, - raw_ostream *OS, - DiagnosticsEngine &Diags, - const LangOptions &LOpts, - bool SilenceRewriteMacroWarning, - bool LineInfo); +std::unique_ptr +CreateObjCRewriter(const std::string &InFile, raw_ostream *OS, + DiagnosticsEngine &Diags, const LangOptions &LOpts, + bool SilenceRewriteMacroWarning); +std::unique_ptr +CreateModernObjCRewriter(const std::string &InFile, raw_ostream *OS, + DiagnosticsEngine &Diags, const LangOptions &LOpts, + bool SilenceRewriteMacroWarning, bool LineInfo); /// CreateHTMLPrinter - Create an AST consumer which rewrites source code to /// HTML with syntax highlighting suitable for viewing in a web-browser. -ASTConsumer *CreateHTMLPrinter(raw_ostream *OS, Preprocessor &PP, - bool SyntaxHighlight = true, - bool HighlightMacros = true); +std::unique_ptr CreateHTMLPrinter(raw_ostream *OS, + Preprocessor &PP, + bool SyntaxHighlight = true, + bool HighlightMacros = true); } // end clang namespace diff --git a/include/clang/Rewrite/Frontend/FrontendActions.h b/include/clang/Rewrite/Frontend/FrontendActions.h index fc79270748..eca3650d8f 100644 --- a/include/clang/Rewrite/Frontend/FrontendActions.h +++ b/include/clang/Rewrite/Frontend/FrontendActions.h @@ -22,8 +22,8 @@ class FixItOptions; class HTMLPrintAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; class FixItAction : public ASTFrontendAction { @@ -31,8 +31,8 @@ protected: std::unique_ptr Rewriter; std::unique_ptr FixItOpts; - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) override; @@ -59,8 +59,8 @@ protected: class RewriteObjCAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; class RewriteMacrosAction : public PreprocessorFrontendAction { diff --git a/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h b/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h index 30e5d3dd9a..6067dfdb6a 100644 --- a/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h +++ b/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h @@ -37,10 +37,9 @@ public: /// CreateAnalysisConsumer - Creates an ASTConsumer to run various code /// analysis passes. (The set of analyses run is controlled by command-line /// options.) -AnalysisASTConsumer *CreateAnalysisConsumer(const Preprocessor &pp, - const std::string &output, - AnalyzerOptionsRef opts, - ArrayRef plugins); +std::unique_ptr +CreateAnalysisConsumer(const Preprocessor &pp, const std::string &output, + AnalyzerOptionsRef opts, ArrayRef plugins); } // end GR namespace diff --git a/include/clang/StaticAnalyzer/Frontend/FrontendActions.h b/include/clang/StaticAnalyzer/Frontend/FrontendActions.h index 21ecfc234f..921d67e085 100644 --- a/include/clang/StaticAnalyzer/Frontend/FrontendActions.h +++ b/include/clang/StaticAnalyzer/Frontend/FrontendActions.h @@ -22,8 +22,8 @@ namespace ento { class AnalysisAction : public ASTFrontendAction { protected: - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; }; void printCheckerHelp(raw_ostream &OS, ArrayRef plugins); diff --git a/include/clang/Tooling/Tooling.h b/include/clang/Tooling/Tooling.h index 769acd3253..fb9178abcc 100644 --- a/include/clang/Tooling/Tooling.h +++ b/include/clang/Tooling/Tooling.h @@ -30,6 +30,7 @@ #ifndef LLVM_CLANG_TOOLING_TOOLING_H #define LLVM_CLANG_TOOLING_TOOLING_H +#include "clang/AST/ASTConsumer.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/LLVM.h" @@ -335,8 +336,8 @@ inline std::unique_ptr newFrontendActionFactory( SourceFileCallbacks *Callbacks) : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {} - clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &, - StringRef) override { + std::unique_ptr + CreateASTConsumer(clang::CompilerInstance &, StringRef) override { return ConsumerFactory->newASTConsumer(); } diff --git a/lib/ARCMigrate/ARCMT.cpp b/lib/ARCMigrate/ARCMT.cpp index 8a13b2ee4f..524c8d9cae 100644 --- a/lib/ARCMigrate/ARCMT.cpp +++ b/lib/ARCMigrate/ARCMT.cpp @@ -446,11 +446,11 @@ public: ARCMTMacroTrackerAction(std::vector &ARCMTMacroLocs) : ARCMTMacroLocs(ARCMTMacroLocs) { } - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override { + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override { CI.getPreprocessor().addPPCallbacks( new ARCMTMacroTrackerPPCallbacks(ARCMTMacroLocs)); - return new ASTConsumer(); + return llvm::make_unique(); } }; diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 1a2055e9c4..565381c446 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -185,23 +185,17 @@ ObjCMigrateAction::ObjCMigrateAction(FrontendAction *WrappedAction, MigrateDir = "."; // user current directory if none is given. } -ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { PPConditionalDirectiveRecord * PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager()); CompInst->getPreprocessor().addPPCallbacks(PPRec); - ASTConsumer * - WrappedConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile); - ASTConsumer *MTConsumer = new ObjCMigrateASTConsumer(MigrateDir, - ObjCMigAction, - Remapper, - CompInst->getFileManager(), - PPRec, - CompInst->getPreprocessor(), - false, - ArrayRef()); - ASTConsumer *Consumers[] = { MTConsumer, WrappedConsumer }; - return new MultiplexConsumer(Consumers); + std::vector> Consumers; + Consumers.push_back(WrapperFrontendAction::CreateASTConsumer(CI, InFile)); + Consumers.push_back(llvm::make_unique( + MigrateDir, ObjCMigAction, Remapper, CompInst->getFileManager(), PPRec, + CompInst->getPreprocessor(), false, ArrayRef())); + return llvm::make_unique(std::move(Consumers)); } bool ObjCMigrateAction::BeginInvocation(CompilerInstance &CI) { @@ -1865,8 +1859,8 @@ static std::vector getWhiteListFilenames(StringRef DirPath) { return Filenames; } -ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { PPConditionalDirectiveRecord * PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager()); unsigned ObjCMTAction = CI.getFrontendOpts().ObjCMTAction; @@ -1883,14 +1877,10 @@ ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, CI.getPreprocessor().addPPCallbacks(PPRec); std::vector WhiteList = getWhiteListFilenames(CI.getFrontendOpts().ObjCMTWhiteListPath); - return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile, - ObjCMTAction, - Remapper, - CI.getFileManager(), - PPRec, - CI.getPreprocessor(), - /*isOutputFile=*/true, - WhiteList); + return llvm::make_unique( + CI.getFrontendOpts().OutputFile, ObjCMTAction, Remapper, + CI.getFileManager(), PPRec, CI.getPreprocessor(), + /*isOutputFile=*/true, WhiteList); } namespace { diff --git a/lib/ASTMatchers/ASTMatchFinder.cpp b/lib/ASTMatchers/ASTMatchFinder.cpp index b8ac68aad7..050630fd4b 100644 --- a/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/lib/ASTMatchers/ASTMatchFinder.cpp @@ -823,8 +823,8 @@ bool MatchFinder::addDynamicMatcher(const internal::DynTypedMatcher &NodeMatch, return false; } -ASTConsumer *MatchFinder::newASTConsumer() { - return new internal::MatchASTConsumer(this, ParsingDone); +std::unique_ptr MatchFinder::newASTConsumer() { + return llvm::make_unique(this, ParsingDone); } void MatchFinder::match(const clang::ast_type_traits::DynTypedNode &Node, diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index d319d220dc..a7dbd4ae15 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -607,8 +607,8 @@ static raw_ostream *GetOutputStream(CompilerInstance &CI, llvm_unreachable("Invalid action!"); } -ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { BackendAction BA = static_cast(Act); std::unique_ptr OS(GetOutputStream(CI, InFile, BA)); if (BA != Backend_EmitNothing && !OS) @@ -646,12 +646,12 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI, CoverageInfo = new CoverageSourceInfo; CI.getPreprocessor().addPPCallbacks(CoverageInfo); } - BEConsumer = new BackendConsumer(BA, CI.getDiagnostics(), CI.getCodeGenOpts(), - CI.getTargetOpts(), CI.getLangOpts(), - CI.getFrontendOpts().ShowTimers, InFile, - LinkModuleToUse, OS.release(), *VMContext, - CoverageInfo); - return BEConsumer; + auto Result = llvm::make_unique( + BA, CI.getDiagnostics(), CI.getCodeGenOpts(), CI.getTargetOpts(), + CI.getLangOpts(), (bool)CI.getFrontendOpts().ShowTimers, InFile, + LinkModuleToUse, OS.release(), *VMContext, CoverageInfo); + BEConsumer = Result.get(); + return std::move(Result); } void CodeGenAction::ExecuteAction() { diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp index 54a6d474c1..d836ed42d6 100644 --- a/lib/Frontend/ASTConsumers.cpp +++ b/lib/Frontend/ASTConsumers.cpp @@ -118,17 +118,19 @@ namespace { }; } // end anonymous namespace -ASTConsumer *clang::CreateASTPrinter(raw_ostream *Out, - StringRef FilterString) { - return new ASTPrinter(Out, /*Dump=*/ false, FilterString); +std::unique_ptr clang::CreateASTPrinter(raw_ostream *Out, + StringRef FilterString) { + return llvm::make_unique(Out, /*Dump=*/false, FilterString); } -ASTConsumer *clang::CreateASTDumper(StringRef FilterString, bool DumpLookups) { - return new ASTPrinter(nullptr, /*Dump=*/true, FilterString, DumpLookups); +std::unique_ptr clang::CreateASTDumper(StringRef FilterString, + bool DumpLookups) { + return llvm::make_unique(nullptr, /*Dump=*/true, FilterString, + DumpLookups); } -ASTConsumer *clang::CreateASTDeclNodeLister() { - return new ASTDeclNodeLister(nullptr); +std::unique_ptr clang::CreateASTDeclNodeLister() { + return llvm::make_unique(nullptr); } //===----------------------------------------------------------------------===// @@ -164,8 +166,9 @@ void ASTViewer::HandleTopLevelSingleDecl(Decl *D) { } } - -ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); } +std::unique_ptr clang::CreateASTViewer() { + return llvm::make_unique(); +} //===----------------------------------------------------------------------===// /// DeclContextPrinter - Decl and DeclContext Visualization @@ -475,6 +478,6 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, } } } -ASTConsumer *clang::CreateDeclContextPrinter() { - return new DeclContextPrinter(); +std::unique_ptr clang::CreateDeclContextPrinter() { + return llvm::make_unique(); } diff --git a/lib/Frontend/ASTMerge.cpp b/lib/Frontend/ASTMerge.cpp index 95cfe24800..216ac6a169 100644 --- a/lib/Frontend/ASTMerge.cpp +++ b/lib/Frontend/ASTMerge.cpp @@ -16,8 +16,8 @@ using namespace clang; -ASTConsumer *ASTMergeAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +ASTMergeAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return AdaptedAction->CreateASTConsumer(CI, InFile); } diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 78d86d4b65..0b740e7a11 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -887,12 +887,12 @@ class TopLevelDeclTrackerAction : public ASTFrontendAction { public: ASTUnit &Unit; - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override { + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override { CI.getPreprocessor().addPPCallbacks( new MacroDefinitionTrackerPPCallbacks(Unit.getCurrentTopLevelHashValue())); - return new TopLevelDeclTrackerConsumer(Unit, - Unit.getCurrentTopLevelHashValue()); + return llvm::make_unique( + Unit, Unit.getCurrentTopLevelHashValue()); } public: @@ -912,8 +912,8 @@ public: explicit PrecompilePreambleAction(ASTUnit &Unit) : Unit(Unit), HasEmittedPreamblePCH(false) {} - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override; + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override; bool hasEmittedPreamblePCH() const { return HasEmittedPreamblePCH; } void setHasEmittedPreamblePCH() { HasEmittedPreamblePCH = true; } bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); } @@ -975,8 +975,9 @@ public: } -ASTConsumer *PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { std::string Sysroot; std::string OutputFile; raw_ostream *OS = nullptr; @@ -989,8 +990,8 @@ ASTConsumer *PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI, CI.getPreprocessor().addPPCallbacks(new MacroDefinitionTrackerPPCallbacks( Unit.getCurrentTopLevelHashValue())); - return new PrecompilePreambleConsumer(Unit, this, CI.getPreprocessor(), - Sysroot, OS); + return llvm::make_unique( + Unit, this, CI.getPreprocessor(), Sysroot, OS); } static bool isNonDriverDiag(const StoredDiagnostic &StoredDiag) { @@ -1685,7 +1686,7 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) { assert(CI.hasInvocation() && "missing invocation"); LangOpts = CI.getInvocation().LangOpts; TheSema = CI.takeSema(); - Consumer.reset(CI.takeASTConsumer()); + Consumer = CI.takeASTConsumer(); if (CI.hasASTContext()) Ctx = &CI.getASTContext(); if (CI.hasPreprocessor()) @@ -1859,12 +1860,13 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction( if (Persistent && !TrackerAct) { Clang->getPreprocessor().addPPCallbacks( new MacroDefinitionTrackerPPCallbacks(AST->getCurrentTopLevelHashValue())); - std::vector Consumers; + std::vector> Consumers; if (Clang->hasASTConsumer()) Consumers.push_back(Clang->takeASTConsumer()); - Consumers.push_back(new TopLevelDeclTrackerConsumer(*AST, - AST->getCurrentTopLevelHashValue())); - Clang->setASTConsumer(new MultiplexConsumer(Consumers)); + Consumers.push_back(llvm::make_unique( + *AST, AST->getCurrentTopLevelHashValue())); + Clang->setASTConsumer( + llvm::make_unique(std::move(Consumers))); } if (!Act->Execute()) { AST->transferASTDataFromCompilerInstance(*Clang); diff --git a/lib/Frontend/ChainedIncludesSource.cpp b/lib/Frontend/ChainedIncludesSource.cpp index e6e73ac963..6b14e2505f 100644 --- a/lib/Frontend/ChainedIncludesSource.cpp +++ b/lib/Frontend/ChainedIncludesSource.cpp @@ -158,12 +158,12 @@ IntrusiveRefCntPtr clang::createChainedIncludesSource( SmallVector serialAST; llvm::raw_svector_ostream OS(serialAST); - std::unique_ptr consumer; - consumer.reset(new PCHGenerator(Clang->getPreprocessor(), "-", nullptr, - /*isysroot=*/"", &OS)); + auto consumer = + llvm::make_unique(Clang->getPreprocessor(), "-", nullptr, + /*isysroot=*/"", &OS); Clang->getASTContext().setASTMutationListener( consumer->GetASTMutationListener()); - Clang->setASTConsumer(consumer.release()); + Clang->setASTConsumer(std::move(consumer)); Clang->createSema(TU_Prefix, nullptr); if (firstInclude) { diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 22788aa5fb..6b8669e9a1 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -101,8 +101,8 @@ void CompilerInstance::setSema(Sema *S) { TheSema.reset(S); } -void CompilerInstance::setASTConsumer(ASTConsumer *Value) { - Consumer.reset(Value); +void CompilerInstance::setASTConsumer(std::unique_ptr Value) { + Consumer = std::move(Value); } void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) { diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index cd3dd1f17d..d04169fb2f 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -134,9 +134,10 @@ void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, CurrentASTUnit = std::move(AST); } -ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, - StringRef InFile) { - ASTConsumer* Consumer = CreateASTConsumer(CI, InFile); +std::unique_ptr +FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, + StringRef InFile) { + std::unique_ptr Consumer = CreateASTConsumer(CI, InFile); if (!Consumer) return nullptr; @@ -145,7 +146,8 @@ ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, // Make sure the non-plugin consumer is first, so that plugins can't // modifiy the AST. - std::vector Consumers(1, Consumer); + std::vector> Consumers; + Consumers.push_back(std::move(Consumer)); for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size(); i != e; ++i) { @@ -155,16 +157,15 @@ ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, it = FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end(); it != ie; ++it) { - if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) { - std::unique_ptr P(it->instantiate()); - FrontendAction* c = P.get(); - if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i])) - Consumers.push_back(c->CreateASTConsumer(CI, InFile)); - } + if (it->getName() != CI.getFrontendOpts().AddPluginActions[i]) + continue; + std::unique_ptr P = it->instantiate(); + if (P->ParseArgs(CI, CI.getFrontendOpts().AddPluginArgs[i])) + Consumers.push_back(P->CreateASTConsumer(CI, InFile)); } } - return new MultiplexConsumer(Consumers); + return llvm::make_unique(std::move(Consumers)); } bool FrontendAction::BeginSourceFile(CompilerInstance &CI, @@ -308,8 +309,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, if (!usesPreprocessorOnly()) { CI.createASTContext(); - std::unique_ptr Consumer( - CreateWrappedASTConsumer(CI, InputFile)); + std::unique_ptr Consumer = + CreateWrappedASTConsumer(CI, InputFile); if (!Consumer) goto failure; @@ -350,7 +351,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, goto failure; } - CI.setASTConsumer(Consumer.release()); + CI.setASTConsumer(std::move(Consumer)); if (!CI.hasASTConsumer()) goto failure; } @@ -449,7 +450,7 @@ void FrontendAction::EndSourceFile() { CI.resetAndLeakSema(); CI.resetAndLeakASTContext(); } - BuryPointer(CI.takeASTConsumer()); + BuryPointer(CI.takeASTConsumer().get()); } else { if (!isCurrentFileAST()) { CI.setSema(nullptr); @@ -517,14 +518,15 @@ void ASTFrontendAction::ExecuteAction() { void PluginASTAction::anchor() { } -ASTConsumer * +std::unique_ptr PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!"); } -ASTConsumer *WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { return WrappedAction->CreateASTConsumer(CI, InFile); } bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) { diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 3c24707150..903abe2d61 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -33,9 +33,9 @@ using namespace clang; // Custom Actions //===----------------------------------------------------------------------===// -ASTConsumer *InitOnlyAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { - return new ASTConsumer(); +std::unique_ptr +InitOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { + return llvm::make_unique(); } void InitOnlyAction::ExecuteAction() { @@ -45,36 +45,37 @@ void InitOnlyAction::ExecuteAction() { // AST Consumer Actions //===----------------------------------------------------------------------===// -ASTConsumer *ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile)) return CreateASTPrinter(OS, CI.getFrontendOpts().ASTDumpFilter); return nullptr; } -ASTConsumer *ASTDumpAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +ASTDumpAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return CreateASTDumper(CI.getFrontendOpts().ASTDumpFilter, CI.getFrontendOpts().ASTDumpLookups); } -ASTConsumer *ASTDeclListAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +ASTDeclListAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return CreateASTDeclNodeLister(); } -ASTConsumer *ASTViewAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +ASTViewAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return CreateASTViewer(); } -ASTConsumer *DeclContextPrintAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +DeclContextPrintAction::CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { return CreateDeclContextPrinter(); } -ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::string Sysroot; std::string OutputFile; raw_ostream *OS = nullptr; @@ -83,8 +84,8 @@ ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, if (!CI.getFrontendOpts().RelocatablePCH) Sysroot.clear(); - return new PCHGenerator(CI.getPreprocessor(), OutputFile, nullptr, Sysroot, - OS); + return llvm::make_unique(CI.getPreprocessor(), OutputFile, + nullptr, Sysroot, OS); } bool GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI, @@ -111,16 +112,17 @@ bool GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI, return false; } -ASTConsumer *GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { std::string Sysroot; std::string OutputFile; raw_ostream *OS = nullptr; if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS)) return nullptr; - return new PCHGenerator(CI.getPreprocessor(), OutputFile, Module, - Sysroot, OS); + return llvm::make_unique(CI.getPreprocessor(), OutputFile, + Module, Sysroot, OS); } static SmallVectorImpl & @@ -365,19 +367,20 @@ bool GenerateModuleAction::ComputeASTConsumerArguments(CompilerInstance &CI, return false; } -ASTConsumer *SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { - return new ASTConsumer(); +std::unique_ptr +SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { + return llvm::make_unique(); } -ASTConsumer *DumpModuleInfoAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { - return new ASTConsumer(); +std::unique_ptr +DumpModuleInfoAction::CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { + return llvm::make_unique(); } -ASTConsumer *VerifyPCHAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { - return new ASTConsumer(); +std::unique_ptr +VerifyPCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { + return llvm::make_unique(); } void VerifyPCHAction::ExecuteAction() { diff --git a/lib/Frontend/MultiplexConsumer.cpp b/lib/Frontend/MultiplexConsumer.cpp index 0e933a3f16..2930cb3952 100644 --- a/lib/Frontend/MultiplexConsumer.cpp +++ b/lib/Frontend/MultiplexConsumer.cpp @@ -183,118 +183,113 @@ void MultiplexASTMutationListener::DeclarationMarkedUsed(const Decl *D) { } // end namespace clang -MultiplexConsumer::MultiplexConsumer(ArrayRef C) - : Consumers(C.begin(), C.end()), MutationListener(), - DeserializationListener() { +MultiplexConsumer::MultiplexConsumer( + std::vector> C) + : Consumers(std::move(C)), MutationListener(), DeserializationListener() { // Collect the mutation listeners and deserialization listeners of all // children, and create a multiplex listener each if so. std::vector mutationListeners; std::vector serializationListeners; - for (size_t i = 0, e = Consumers.size(); i != e; ++i) { - ASTMutationListener* mutationListener = - Consumers[i]->GetASTMutationListener(); - if (mutationListener) + for (auto &Consumer : Consumers) { + if (auto *mutationListener = Consumer->GetASTMutationListener()) mutationListeners.push_back(mutationListener); - ASTDeserializationListener* serializationListener = - Consumers[i]->GetASTDeserializationListener(); - if (serializationListener) + if (auto *serializationListener = Consumer->GetASTDeserializationListener()) serializationListeners.push_back(serializationListener); } - if (mutationListeners.size()) { - MutationListener.reset(new MultiplexASTMutationListener(mutationListeners)); + if (!mutationListeners.empty()) { + MutationListener = + llvm::make_unique(mutationListeners); } - if (serializationListeners.size()) { - DeserializationListener.reset( - new MultiplexASTDeserializationListener(serializationListeners)); + if (!serializationListeners.empty()) { + DeserializationListener = + llvm::make_unique( + serializationListeners); } } -MultiplexConsumer::~MultiplexConsumer() { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - delete Consumers[i]; -} +MultiplexConsumer::~MultiplexConsumer() {} void MultiplexConsumer::Initialize(ASTContext &Context) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->Initialize(Context); + for (auto &Consumer : Consumers) + Consumer->Initialize(Context); } bool MultiplexConsumer::HandleTopLevelDecl(DeclGroupRef D) { bool Continue = true; - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Continue = Continue && Consumers[i]->HandleTopLevelDecl(D); + for (auto &Consumer : Consumers) + Continue = Continue && Consumer->HandleTopLevelDecl(D); return Continue; } void MultiplexConsumer::HandleInlineMethodDefinition(CXXMethodDecl *D) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleInlineMethodDefinition(D); + for (auto &Consumer : Consumers) + Consumer->HandleInlineMethodDefinition(D); } -void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleCXXStaticMemberVarInstantiation(VD); +void MultiplexConsumer::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) { + for (auto &Consumer : Consumers) + Consumer->HandleCXXStaticMemberVarInstantiation(VD); } void MultiplexConsumer::HandleInterestingDecl(DeclGroupRef D) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleInterestingDecl(D); + for (auto &Consumer : Consumers) + Consumer->HandleInterestingDecl(D); } void MultiplexConsumer::HandleTranslationUnit(ASTContext &Ctx) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleTranslationUnit(Ctx); + for (auto &Consumer : Consumers) + Consumer->HandleTranslationUnit(Ctx); } void MultiplexConsumer::HandleTagDeclDefinition(TagDecl *D) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleTagDeclDefinition(D); + for (auto &Consumer : Consumers) + Consumer->HandleTagDeclDefinition(D); } void MultiplexConsumer::HandleTagDeclRequiredDefinition(const TagDecl *D) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleTagDeclRequiredDefinition(D); + for (auto &Consumer : Consumers) + Consumer->HandleTagDeclRequiredDefinition(D); } void MultiplexConsumer::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D){ - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleCXXImplicitFunctionInstantiation(D); + for (auto &Consumer : Consumers) + Consumer->HandleCXXImplicitFunctionInstantiation(D); } void MultiplexConsumer::HandleTopLevelDeclInObjCContainer(DeclGroupRef D) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleTopLevelDeclInObjCContainer(D); + for (auto &Consumer : Consumers) + Consumer->HandleTopLevelDeclInObjCContainer(D); } void MultiplexConsumer::HandleImplicitImportDecl(ImportDecl *D) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleImplicitImportDecl(D); + for (auto &Consumer : Consumers) + Consumer->HandleImplicitImportDecl(D); } void MultiplexConsumer::HandleLinkerOptionPragma(llvm::StringRef Opts) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleLinkerOptionPragma(Opts); + for (auto &Consumer : Consumers) + Consumer->HandleLinkerOptionPragma(Opts); } void MultiplexConsumer::HandleDetectMismatch(llvm::StringRef Name, llvm::StringRef Value) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleDetectMismatch(Name, Value); + for (auto &Consumer : Consumers) + Consumer->HandleDetectMismatch(Name, Value); } void MultiplexConsumer::HandleDependentLibrary(llvm::StringRef Lib) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleDependentLibrary(Lib); + for (auto &Consumer : Consumers) + Consumer->HandleDependentLibrary(Lib); } void MultiplexConsumer::CompleteTentativeDefinition(VarDecl *D) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->CompleteTentativeDefinition(D); + for (auto &Consumer : Consumers) + Consumer->CompleteTentativeDefinition(D); } void MultiplexConsumer::HandleVTable( CXXRecordDecl *RD, bool DefinitionRequired) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->HandleVTable(RD, DefinitionRequired); + for (auto &Consumer : Consumers) + Consumer->HandleVTable(RD, DefinitionRequired); } ASTMutationListener *MultiplexConsumer::GetASTMutationListener() { @@ -306,18 +301,18 @@ ASTDeserializationListener *MultiplexConsumer::GetASTDeserializationListener() { } void MultiplexConsumer::PrintStats() { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - Consumers[i]->PrintStats(); + for (auto &Consumer : Consumers) + Consumer->PrintStats(); } void MultiplexConsumer::InitializeSema(Sema &S) { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - if (SemaConsumer *SC = dyn_cast(Consumers[i])) + for (auto &Consumer : Consumers) + if (SemaConsumer *SC = dyn_cast(Consumer.get())) SC->InitializeSema(S); } void MultiplexConsumer::ForgetSema() { - for (size_t i = 0, e = Consumers.size(); i != e; ++i) - if (SemaConsumer *SC = dyn_cast(Consumers[i])) + for (auto &Consumer : Consumers) + if (SemaConsumer *SC = dyn_cast(Consumer.get())) SC->ForgetSema(); } diff --git a/lib/Frontend/Rewrite/FrontendActions.cpp b/lib/Frontend/Rewrite/FrontendActions.cpp index 59fef736f1..1b5eb2855b 100644 --- a/lib/Frontend/Rewrite/FrontendActions.cpp +++ b/lib/Frontend/Rewrite/FrontendActions.cpp @@ -30,8 +30,8 @@ using namespace clang; // AST Consumer Actions //===----------------------------------------------------------------------===// -ASTConsumer *HTMLPrintAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +HTMLPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile)) return CreateHTMLPrinter(OS, CI.getPreprocessor()); return nullptr; @@ -40,9 +40,9 @@ ASTConsumer *HTMLPrintAction::CreateASTConsumer(CompilerInstance &CI, FixItAction::FixItAction() {} FixItAction::~FixItAction() {} -ASTConsumer *FixItAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { - return new ASTConsumer(); +std::unique_ptr +FixItAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { + return llvm::make_unique(); } namespace { @@ -148,8 +148,8 @@ bool FixItRecompile::BeginInvocation(CompilerInstance &CI) { #ifdef CLANG_ENABLE_OBJC_REWRITER -ASTConsumer *RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "cpp")) { if (CI.getLangOpts().ObjCRuntime.isNonFragile()) return CreateModernObjCRewriter(InFile, OS, diff --git a/lib/Frontend/Rewrite/HTMLPrint.cpp b/lib/Frontend/Rewrite/HTMLPrint.cpp index 64da05fdde..22ccfe6936 100644 --- a/lib/Frontend/Rewrite/HTMLPrint.cpp +++ b/lib/Frontend/Rewrite/HTMLPrint.cpp @@ -47,11 +47,12 @@ namespace { }; } -ASTConsumer* clang::CreateHTMLPrinter(raw_ostream *OS, - Preprocessor &PP, - bool SyntaxHighlight, - bool HighlightMacros) { - return new HTMLPrinter(OS, PP, SyntaxHighlight, HighlightMacros); +std::unique_ptr clang::CreateHTMLPrinter(raw_ostream *OS, + Preprocessor &PP, + bool SyntaxHighlight, + bool HighlightMacros) { + return llvm::make_unique(OS, PP, SyntaxHighlight, + HighlightMacros); } void HTMLPrinter::Initialize(ASTContext &context) { diff --git a/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 3e18a8b415..c97fa979f6 100644 --- a/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -675,14 +675,11 @@ RewriteModernObjC::RewriteModernObjC(std::string inFile, raw_ostream* OS, "for @try/@finally (code may not execute properly)"); } -ASTConsumer *clang::CreateModernObjCRewriter(const std::string& InFile, - raw_ostream* OS, - DiagnosticsEngine &Diags, - const LangOptions &LOpts, - bool SilenceRewriteMacroWarning, - bool LineInfo) { - return new RewriteModernObjC(InFile, OS, Diags, LOpts, - SilenceRewriteMacroWarning, LineInfo); +std::unique_ptr clang::CreateModernObjCRewriter( + const std::string &InFile, raw_ostream *OS, DiagnosticsEngine &Diags, + const LangOptions &LOpts, bool SilenceRewriteMacroWarning, bool LineInfo) { + return llvm::make_unique( + InFile, OS, Diags, LOpts, SilenceRewriteMacroWarning, LineInfo); } void RewriteModernObjC::InitializeCommon(ASTContext &context) { diff --git a/lib/Frontend/Rewrite/RewriteObjC.cpp b/lib/Frontend/Rewrite/RewriteObjC.cpp index 7a72177175..8d48d9e7b6 100644 --- a/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -600,12 +600,12 @@ RewriteObjC::RewriteObjC(std::string inFile, raw_ostream* OS, "for @try/@finally (code may not execute properly)"); } -ASTConsumer *clang::CreateObjCRewriter(const std::string& InFile, - raw_ostream* OS, - DiagnosticsEngine &Diags, - const LangOptions &LOpts, - bool SilenceRewriteMacroWarning) { - return new RewriteObjCFragileABI(InFile, OS, Diags, LOpts, SilenceRewriteMacroWarning); +std::unique_ptr +clang::CreateObjCRewriter(const std::string &InFile, raw_ostream *OS, + DiagnosticsEngine &Diags, const LangOptions &LOpts, + bool SilenceRewriteMacroWarning) { + return llvm::make_unique(InFile, OS, Diags, LOpts, + SilenceRewriteMacroWarning); } void RewriteObjC::InitializeCommon(ASTContext &context) { diff --git a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index f0dd274235..c390e9dbfa 100644 --- a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -687,14 +687,14 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D, // AnalysisConsumer creation. //===----------------------------------------------------------------------===// -AnalysisASTConsumer * +std::unique_ptr ento::CreateAnalysisConsumer(const Preprocessor &pp, const std::string &outDir, AnalyzerOptionsRef opts, ArrayRef plugins) { // Disable the effects of '-Werror' when using the AnalysisConsumer. pp.getDiagnostics().setWarningsAsErrors(false); - return new AnalysisConsumer(pp, outDir, opts, plugins); + return llvm::make_unique(pp, outDir, opts, plugins); } //===----------------------------------------------------------------------===// diff --git a/lib/StaticAnalyzer/Frontend/FrontendActions.cpp b/lib/StaticAnalyzer/Frontend/FrontendActions.cpp index aa38077326..567102b765 100644 --- a/lib/StaticAnalyzer/Frontend/FrontendActions.cpp +++ b/lib/StaticAnalyzer/Frontend/FrontendActions.cpp @@ -13,8 +13,8 @@ using namespace clang; using namespace ento; -ASTConsumer *AnalysisAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr +AnalysisAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { return CreateAnalysisConsumer(CI.getPreprocessor(), CI.getFrontendOpts().OutputFile, CI.getAnalyzerOpts(), diff --git a/tools/clang-check/ClangCheck.cpp b/tools/clang-check/ClangCheck.cpp index cc8d43cec2..df3b4e0d95 100644 --- a/tools/clang-check/ClangCheck.cpp +++ b/tools/clang-check/ClangCheck.cpp @@ -28,6 +28,7 @@ #include "llvm/Option/OptTable.h" #include "llvm/Support/Path.h" #include "llvm/Support/Signals.h" +#include "llvm/ADT/STLExtras.h" using namespace clang::driver; using namespace clang::tooling; @@ -179,14 +180,14 @@ private: namespace clang_check { class ClangCheckActionFactory { public: - clang::ASTConsumer *newASTConsumer() { + std::unique_ptr newASTConsumer() { if (ASTList) return clang::CreateASTDeclNodeLister(); if (ASTDump) return clang::CreateASTDumper(ASTDumpFilter); if (ASTPrint) return clang::CreateASTPrinter(&llvm::outs(), ASTDumpFilter); - return new clang::ASTConsumer(); + return llvm::make_unique(); } }; } diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp index 58af61811b..f347f9f345 100644 --- a/tools/libclang/Indexing.cpp +++ b/tools/libclang/Indexing.cpp @@ -414,8 +414,8 @@ public: : IndexCtx(clientData, indexCallbacks, indexOptions, cxTU), CXTU(cxTU), SKData(skData) { } - ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) override { + std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override { PreprocessorOptions &PPOpts = CI.getPreprocessorOpts(); if (!PPOpts.ImplicitPCHInclude.empty()) { @@ -429,13 +429,12 @@ public: IndexCtx.setPreprocessor(PP); if (SKData) { - PPConditionalDirectiveRecord * - PPRec = new PPConditionalDirectiveRecord(PP.getSourceManager()); + auto *PPRec = new PPConditionalDirectiveRecord(PP.getSourceManager()); PP.addPPCallbacks(PPRec); - SKCtrl.reset(new TUSkipBodyControl(*SKData, *PPRec, PP)); + SKCtrl = llvm::make_unique(*SKData, *PPRec, PP); } - return new IndexingConsumer(IndexCtx, SKCtrl.get()); + return llvm::make_unique(IndexCtx, SKCtrl.get()); } void EndSourceFileAction() override { diff --git a/unittests/AST/EvaluateAsRValueTest.cpp b/unittests/AST/EvaluateAsRValueTest.cpp index 9120c936ed..b5f9b32740 100644 --- a/unittests/AST/EvaluateAsRValueTest.cpp +++ b/unittests/AST/EvaluateAsRValueTest.cpp @@ -59,9 +59,10 @@ class EvaluateConstantInitializersVisitor class EvaluateConstantInitializersAction : public clang::ASTFrontendAction { public: - clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &Compiler, - llvm::StringRef FilePath) override { - return new Consumer; + std::unique_ptr + CreateASTConsumer(clang::CompilerInstance &Compiler, + llvm::StringRef FilePath) override { + return llvm::make_unique(); } private: diff --git a/unittests/AST/ExternalASTSourceTest.cpp b/unittests/AST/ExternalASTSourceTest.cpp index 5cc2defe20..6a5db6c1dd 100644 --- a/unittests/AST/ExternalASTSourceTest.cpp +++ b/unittests/AST/ExternalASTSourceTest.cpp @@ -35,9 +35,9 @@ private: return ASTFrontendAction::ExecuteAction(); } - virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { - return new ASTConsumer; + virtual std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { + return llvm::make_unique(); } IntrusiveRefCntPtr Source; diff --git a/unittests/AST/NamedDeclPrinterTest.cpp b/unittests/AST/NamedDeclPrinterTest.cpp index 4823b44862..f8fb98454b 100644 --- a/unittests/AST/NamedDeclPrinterTest.cpp +++ b/unittests/AST/NamedDeclPrinterTest.cpp @@ -68,8 +68,8 @@ PrintedNamedDeclMatches(StringRef Code, const std::vector &Args, PrintMatch Printer(SuppressUnwrittenScope); MatchFinder Finder; Finder.addMatcher(NodeMatch, &Printer); - std::unique_ptr Factory( - newFrontendActionFactory(&Finder)); + std::unique_ptr Factory = + newFrontendActionFactory(&Finder); if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName)) return testing::AssertionFailure() diff --git a/unittests/Frontend/FrontendActionTest.cpp b/unittests/Frontend/FrontendActionTest.cpp index 44843eed13..cb9cc52725 100644 --- a/unittests/Frontend/FrontendActionTest.cpp +++ b/unittests/Frontend/FrontendActionTest.cpp @@ -38,9 +38,9 @@ public: return ASTFrontendAction::BeginSourceFileAction(ci, filename); } - virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { - return new Visitor(decl_names); + virtual std::unique_ptr CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { + return llvm::make_unique(decl_names); } private: diff --git a/unittests/Sema/ExternalSemaSourceTest.cpp b/unittests/Sema/ExternalSemaSourceTest.cpp index bc0d632cfd..4291b76e7d 100644 --- a/unittests/Sema/ExternalSemaSourceTest.cpp +++ b/unittests/Sema/ExternalSemaSourceTest.cpp @@ -140,10 +140,10 @@ class ExternalSemaSourceInstaller : public clang::ASTFrontendAction { std::unique_ptr OwnedClient; protected: - virtual clang::ASTConsumer * + virtual std::unique_ptr CreateASTConsumer(clang::CompilerInstance &Compiler, llvm::StringRef /* dummy */) { - return new clang::ASTConsumer(); + return llvm::make_unique(); } virtual void ExecuteAction() { diff --git a/unittests/Tooling/RefactoringTest.cpp b/unittests/Tooling/RefactoringTest.cpp index ddb974ac9f..3e067dd3f9 100644 --- a/unittests/Tooling/RefactoringTest.cpp +++ b/unittests/Tooling/RefactoringTest.cpp @@ -299,11 +299,12 @@ private: public: TestAction(TestVisitor *Visitor) : Visitor(Visitor) {} - virtual clang::ASTConsumer* CreateASTConsumer( - clang::CompilerInstance& compiler, llvm::StringRef dummy) { + virtual std::unique_ptr + CreateASTConsumer(clang::CompilerInstance &compiler, + llvm::StringRef dummy) { Visitor->SM = &compiler.getSourceManager(); /// TestConsumer will be deleted by the framework calling us. - return new FindConsumer(Visitor); + return llvm::make_unique(Visitor); } private: diff --git a/unittests/Tooling/TestVisitor.h b/unittests/Tooling/TestVisitor.h index 205a0aa16e..23ea754d39 100644 --- a/unittests/Tooling/TestVisitor.h +++ b/unittests/Tooling/TestVisitor.h @@ -95,10 +95,10 @@ protected: public: TestAction(TestVisitor *Visitor) : Visitor(Visitor) {} - virtual clang::ASTConsumer* CreateASTConsumer( - CompilerInstance&, llvm::StringRef dummy) { + virtual std::unique_ptr + CreateASTConsumer(CompilerInstance &, llvm::StringRef dummy) { /// TestConsumer will be deleted by the framework calling us. - return new FindConsumer(Visitor); + return llvm::make_unique(Visitor); } protected: diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp index 9aede044f6..85ab942387 100644 --- a/unittests/Tooling/ToolingTest.cpp +++ b/unittests/Tooling/ToolingTest.cpp @@ -28,20 +28,20 @@ namespace { /// Takes an ast consumer and returns it from CreateASTConsumer. This only /// works with single translation unit compilations. class TestAction : public clang::ASTFrontendAction { - public: +public: /// Takes ownership of TestConsumer. - explicit TestAction(clang::ASTConsumer *TestConsumer) - : TestConsumer(TestConsumer) {} + explicit TestAction(std::unique_ptr TestConsumer) + : TestConsumer(std::move(TestConsumer)) {} - protected: - virtual clang::ASTConsumer* CreateASTConsumer( - clang::CompilerInstance& compiler, StringRef dummy) { +protected: + virtual std::unique_ptr + CreateASTConsumer(clang::CompilerInstance &compiler, StringRef dummy) { /// TestConsumer will be deleted by the framework calling us. - return TestConsumer; + return std::move(TestConsumer); } - private: - clang::ASTConsumer * const TestConsumer; +private: + std::unique_ptr TestConsumer; }; class FindTopLevelDeclConsumer : public clang::ASTConsumer { @@ -59,8 +59,10 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer { TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) { bool FoundTopLevelDecl = false; - EXPECT_TRUE(runToolOnCode( - new TestAction(new FindTopLevelDeclConsumer(&FoundTopLevelDecl)), "")); + EXPECT_TRUE( + runToolOnCode(new TestAction(llvm::make_unique( + &FoundTopLevelDecl)), + "")); EXPECT_FALSE(FoundTopLevelDecl); } @@ -97,13 +99,17 @@ bool FindClassDeclX(ASTUnit *AST) { TEST(runToolOnCode, FindsClassDecl) { bool FoundClassDeclX = false; - EXPECT_TRUE(runToolOnCode(new TestAction( - new FindClassDeclXConsumer(&FoundClassDeclX)), "class X;")); + EXPECT_TRUE( + runToolOnCode(new TestAction(llvm::make_unique( + &FoundClassDeclX)), + "class X;")); EXPECT_TRUE(FoundClassDeclX); FoundClassDeclX = false; - EXPECT_TRUE(runToolOnCode(new TestAction( - new FindClassDeclXConsumer(&FoundClassDeclX)), "class Y;")); + EXPECT_TRUE( + runToolOnCode(new TestAction(llvm::make_unique( + &FoundClassDeclX)), + "class Y;")); EXPECT_FALSE(FoundClassDeclX); } @@ -125,8 +131,8 @@ TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromType) { } struct IndependentFrontendActionCreator { - ASTConsumer *newASTConsumer() { - return new FindTopLevelDeclConsumer(nullptr); + std::unique_ptr newASTConsumer() { + return llvm::make_unique(nullptr); } }; @@ -185,8 +191,8 @@ struct VerifyEndCallback : public SourceFileCallbacks { virtual void handleEndSource() { ++EndCalled; } - ASTConsumer *newASTConsumer() { - return new FindTopLevelDeclConsumer(&Matched); + std::unique_ptr newASTConsumer() { + return llvm::make_unique(&Matched); } unsigned BeginCalled; unsigned EndCalled; @@ -225,10 +231,10 @@ struct SkipBodyConsumer : public clang::ASTConsumer { }; struct SkipBodyAction : public clang::ASTFrontendAction { - virtual ASTConsumer *CreateASTConsumer(CompilerInstance &Compiler, - StringRef) { + virtual std::unique_ptr + CreateASTConsumer(CompilerInstance &Compiler, StringRef) { Compiler.getFrontendOpts().SkipFunctionBodies = true; - return new SkipBodyConsumer; + return llvm::make_unique(); } }; -- 2.40.0