r234597 - Use a std::unique_ptr to make it easier to see who owns the stream.
Rafael Espindola
rafael.espindola at gmail.com
Fri Apr 10 07:11:53 PDT 2015
Author: rafael
Date: Fri Apr 10 09:11:52 2015
New Revision: 234597
URL: http://llvm.org/viewvc/llvm-project?rev=234597&view=rev
Log:
Use a std::unique_ptr to make it easier to see who owns the stream.
Modified:
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=234597&r1=234596&r2=234597&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Fri Apr 10 09:11:52 2015
@@ -151,11 +151,11 @@ class CompilerInstance : public ModuleLo
struct OutputFile {
std::string Filename;
std::string TempFilename;
- raw_ostream *OS;
+ std::unique_ptr<raw_ostream> OS;
OutputFile(const std::string &filename, const std::string &tempFilename,
- raw_ostream *os)
- : Filename(filename), TempFilename(tempFilename), OS(os) { }
+ std::unique_ptr<raw_ostream> OS)
+ : Filename(filename), TempFilename(tempFilename), OS(std::move(OS)) {}
};
/// The list of active output files.
@@ -518,7 +518,7 @@ public:
/// addOutputFile - Add an output file onto the list of tracked output files.
///
/// \param OutFile - The output file info.
- void addOutputFile(const OutputFile &OutFile);
+ void addOutputFile(OutputFile &&OutFile);
/// clearOutputFiles - Clear the output file list, destroying the contained
/// output streams.
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=234597&r1=234596&r2=234597&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Fri Apr 10 09:11:52 2015
@@ -518,15 +518,14 @@ void CompilerInstance::createSema(Transl
// 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;
if (!it->TempFilename.empty()) {
if (EraseFiles) {
llvm::sys::fs::remove(it->TempFilename);
@@ -561,9 +560,10 @@ CompilerInstance::createDefaultOutputFil
}
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>();
+ llvm::raw_null_ostream *Ret = OS.get();
+ addOutputFile(OutputFile("", "", std::move(OS)));
+ return Ret;
}
llvm::raw_fd_ostream *
@@ -575,21 +575,22 @@ CompilerInstance::createOutputFile(Strin
bool CreateMissingDirectories) {
std::string OutputPathName, TempPathName;
std::error_code EC;
- llvm::raw_fd_ostream *OS = createOutputFile(
+ std::unique_ptr<llvm::raw_fd_ostream> OS(createOutputFile(
OutputPath, EC, Binary, RemoveFileOnSignal, InFile, Extension,
- UseTemporary, CreateMissingDirectories, &OutputPathName, &TempPathName);
+ UseTemporary, CreateMissingDirectories, &OutputPathName, &TempPathName));
if (!OS) {
getDiagnostics().Report(diag::err_fe_unable_to_open_output) << OutputPath
<< EC.message();
return nullptr;
}
+ llvm::raw_fd_ostream *Ret = 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 Ret;
}
llvm::raw_fd_ostream *CompilerInstance::createOutputFile(
More information about the cfe-commits
mailing list