summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/Rewrite/FrontendActions.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-07-15 00:55:40 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-07-15 00:55:40 +0000
commit03f8907f65c5581a3d2653210dcab07e116ebe2f (patch)
treeea4db0f5bd3b2d034aea3560a15d2c70d25fafb8 /clang/lib/Frontend/Rewrite/FrontendActions.cpp
parent38c5318662c51ea02415e81ff4a5fc52df1c9d35 (diff)
downloadbcm5719-llvm-03f8907f65c5581a3d2653210dcab07e116ebe2f.tar.gz
bcm5719-llvm-03f8907f65c5581a3d2653210dcab07e116ebe2f.zip
Frontend: Simplify ownership model for clang's output streams.
This changes the CompilerInstance::createOutputFile function to return a std::unique_ptr<llvm::raw_ostream>, rather than an llvm::raw_ostream implicitly owned by the CompilerInstance. This in most cases required that I move ownership of the output stream to the relevant ASTConsumer. The motivation for this change is to allow BackendConsumer to be a client of interfaces such as D20268 which take ownership of the output stream. Differential Revision: http://reviews.llvm.org/D21537 llvm-svn: 275507
Diffstat (limited to 'clang/lib/Frontend/Rewrite/FrontendActions.cpp')
-rw-r--r--clang/lib/Frontend/Rewrite/FrontendActions.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/clang/lib/Frontend/Rewrite/FrontendActions.cpp b/clang/lib/Frontend/Rewrite/FrontendActions.cpp
index 24aa98c2110..13d410e2138 100644
--- a/clang/lib/Frontend/Rewrite/FrontendActions.cpp
+++ b/clang/lib/Frontend/Rewrite/FrontendActions.cpp
@@ -33,8 +33,9 @@ using namespace clang;
std::unique_ptr<ASTConsumer>
HTMLPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
- if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile))
- return CreateHTMLPrinter(OS, CI.getPreprocessor());
+ if (std::unique_ptr<raw_ostream> OS =
+ CI.createDefaultOutputFile(false, InFile))
+ return CreateHTMLPrinter(std::move(OS), CI.getPreprocessor());
return nullptr;
}
@@ -152,14 +153,15 @@ bool FixItRecompile::BeginInvocation(CompilerInstance &CI) {
std::unique_ptr<ASTConsumer>
RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
- if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "cpp")) {
+ if (std::unique_ptr<raw_ostream> OS =
+ CI.createDefaultOutputFile(false, InFile, "cpp")) {
if (CI.getLangOpts().ObjCRuntime.isNonFragile())
return CreateModernObjCRewriter(
- InFile, OS, CI.getDiagnostics(), CI.getLangOpts(),
+ InFile, std::move(OS), CI.getDiagnostics(), CI.getLangOpts(),
CI.getDiagnosticOpts().NoRewriteMacros,
(CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo));
- return CreateObjCRewriter(InFile, OS,
- CI.getDiagnostics(), CI.getLangOpts(),
+ return CreateObjCRewriter(InFile, std::move(OS), CI.getDiagnostics(),
+ CI.getLangOpts(),
CI.getDiagnosticOpts().NoRewriteMacros);
}
return nullptr;
@@ -173,25 +175,28 @@ RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
void RewriteMacrosAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
- raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile());
+ std::unique_ptr<raw_ostream> OS =
+ CI.createDefaultOutputFile(true, getCurrentFile());
if (!OS) return;
- RewriteMacrosInInput(CI.getPreprocessor(), OS);
+ RewriteMacrosInInput(CI.getPreprocessor(), OS.get());
}
void RewriteTestAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
- raw_ostream *OS = CI.createDefaultOutputFile(false, getCurrentFile());
+ std::unique_ptr<raw_ostream> OS =
+ CI.createDefaultOutputFile(false, getCurrentFile());
if (!OS) return;
- DoRewriteTest(CI.getPreprocessor(), OS);
+ DoRewriteTest(CI.getPreprocessor(), OS.get());
}
void RewriteIncludesAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
- raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile());
+ std::unique_ptr<raw_ostream> OS =
+ CI.createDefaultOutputFile(true, getCurrentFile());
if (!OS) return;
- RewriteIncludesInInput(CI.getPreprocessor(), OS,
+ RewriteIncludesInInput(CI.getPreprocessor(), OS.get(),
CI.getPreprocessorOutputOpts());
}
OpenPOWER on IntegriCloud