diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-07-17 20:40:36 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-07-17 20:40:36 +0000 |
commit | a51666a4d624a745df90e1c84777fb7a644ff80b (patch) | |
tree | 27a6715358a552387f3e0fd041de88a3095d0a35 /clang/lib/Frontend/FrontendAction.cpp | |
parent | fa59e620126114e35477299dbb726c4e85195276 (diff) | |
download | bcm5719-llvm-a51666a4d624a745df90e1c84777fb7a644ff80b.tar.gz bcm5719-llvm-a51666a4d624a745df90e1c84777fb7a644ff80b.zip |
unique_ptr-ify ownership of ASTConsumers
(after fixing a bug in MultiplexConsumer I noticed the ownership of the
nested consumers was implemented with raw pointers - so this fixes
that... and follows the source back to its origin pushing unique_ptr
ownership up through there too)
llvm-svn: 213307
Diffstat (limited to 'clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 791017924d6..3535276e6e9 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -134,9 +134,10 @@ void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, CurrentASTUnit.reset(AST); } -ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, - StringRef InFile) { - ASTConsumer* Consumer = CreateASTConsumer(CI, InFile); +std::unique_ptr<ASTConsumer> +FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI, + StringRef InFile) { + std::unique_ptr<ASTConsumer> 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<ASTConsumer*> Consumers(1, Consumer); + std::vector<std::unique_ptr<ASTConsumer>> 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<PluginASTAction> 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<PluginASTAction> 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<MultiplexConsumer>(std::move(Consumers)); } bool FrontendAction::BeginSourceFile(CompilerInstance &CI, @@ -307,8 +308,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, if (!usesPreprocessorOnly()) { CI.createASTContext(); - std::unique_ptr<ASTConsumer> Consumer( - CreateWrappedASTConsumer(CI, InputFile)); + std::unique_ptr<ASTConsumer> Consumer = + CreateWrappedASTConsumer(CI, InputFile); if (!Consumer) goto failure; @@ -349,7 +350,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, goto failure; } - CI.setASTConsumer(Consumer.release()); + CI.setASTConsumer(std::move(Consumer)); if (!CI.hasASTConsumer()) goto failure; } @@ -444,7 +445,7 @@ void FrontendAction::EndSourceFile() { CI.resetAndLeakSema(); CI.resetAndLeakASTContext(); } - BuryPointer(CI.takeASTConsumer()); + BuryPointer(CI.takeASTConsumer().get()); } else { if (!isCurrentFileAST()) { CI.setSema(nullptr); @@ -516,14 +517,15 @@ void ASTFrontendAction::ExecuteAction() { void PluginASTAction::anchor() { } -ASTConsumer * +std::unique_ptr<ASTConsumer> PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!"); } -ASTConsumer *WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { +std::unique_ptr<ASTConsumer> +WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) { return WrappedAction->CreateASTConsumer(CI, InFile); } bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) { |