diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-08-10 23:35:58 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-08-10 23:35:58 +0000 |
commit | 3b0e32bf61e45ef2bcfcaa962cad13a081b88b45 (patch) | |
tree | 48184a3db20df54681722f9d97f591b2492c8874 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 3a908a0bfc00605e6d7cd51406fcfe03251f624f (diff) | |
download | bcm5719-llvm-3b0e32bf61e45ef2bcfcaa962cad13a081b88b45.tar.gz bcm5719-llvm-3b0e32bf61e45ef2bcfcaa962cad13a081b88b45.zip |
unique_ptrify CompilerInstance::OutputFile(s) and remove a unique_ptr around a non-owning raw_ostream in CodeGenAction::CreateASTConsumer
llvm-svn: 215331
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index d8f4400f447..2de221d13a5 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -518,15 +518,15 @@ void CompilerInstance::createSema(TranslationUnitKind TUKind, // Output Files -void CompilerInstance::addOutputFile(const OutputFile &OutFile) { +void CompilerInstance::addOutputFile(OutputFile OutFile) { assert(OutFile.OS && "Attempt to add empty stream to output list!"); - OutputFiles.push_back(OutFile); + OutputFiles.push_back(std::move(OutFile)); } void CompilerInstance::clearOutputFiles(bool EraseFiles) { for (std::list<OutputFile>::iterator it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) { - delete it->OS; + it->OS.reset(); if (!it->TempFilename.empty()) { if (EraseFiles) { llvm::sys::fs::remove(it->TempFilename); @@ -561,9 +561,10 @@ CompilerInstance::createDefaultOutputFile(bool Binary, } llvm::raw_null_ostream *CompilerInstance::createNullOutputFile() { - llvm::raw_null_ostream *OS = new llvm::raw_null_ostream(); - addOutputFile(OutputFile("", "", OS)); - return OS; + auto OS = llvm::make_unique<llvm::raw_null_ostream>(); + auto *Res = OS.get(); + addOutputFile(OutputFile("", "", std::move(OS))); + return Res; } llvm::raw_fd_ostream * @@ -574,7 +575,7 @@ CompilerInstance::createOutputFile(StringRef OutputPath, bool UseTemporary, bool CreateMissingDirectories) { std::string Error, OutputPathName, TempPathName; - llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary, + auto OS = createOutputFile(OutputPath, Error, Binary, RemoveFileOnSignal, InFile, Extension, UseTemporary, @@ -587,15 +588,16 @@ CompilerInstance::createOutputFile(StringRef OutputPath, return nullptr; } + auto *Res = OS.get(); // Add the output file -- but don't try to remove "-", since this means we are // using stdin. addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "", - TempPathName, OS)); + TempPathName, std::move(OS))); - return OS; + return Res; } -llvm::raw_fd_ostream * +std::unique_ptr<llvm::raw_fd_ostream> CompilerInstance::createOutputFile(StringRef OutputPath, std::string &Error, bool Binary, @@ -663,7 +665,7 @@ CompilerInstance::createOutputFile(StringRef OutputPath, } if (!EC) { - OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true)); + OS = llvm::make_unique<llvm::raw_fd_ostream>(fd, /*shouldClose=*/true); OSFile = TempFile = TempPath.str(); } // If we failed to create the temporary, fallback to writing to the file @@ -673,9 +675,9 @@ CompilerInstance::createOutputFile(StringRef OutputPath, if (!OS) { OSFile = OutFile; - OS.reset(new llvm::raw_fd_ostream( + OS = llvm::make_unique<llvm::raw_fd_ostream>( OSFile.c_str(), Error, - (Binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text))); + (Binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text)); if (!Error.empty()) return nullptr; } @@ -689,7 +691,7 @@ CompilerInstance::createOutputFile(StringRef OutputPath, if (TempPathName) *TempPathName = TempFile; - return OS.release(); + return OS; } // Initialization Utilities |