Make tool_output_file's raw_ostream instance a member variable instead

of a base class.

This makes it possible to unregister the file from FilesToRemove when
the file is done. Also, this eliminates the need for
formatted_tool_output_file.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112706 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2010-09-01 14:20:41 +00:00
parent 41154114f6
commit d4c454317a
19 changed files with 198 additions and 208 deletions
+18 -14
View File
@@ -670,25 +670,29 @@ uint64_t raw_null_ostream::current_pos() const {
// tool_output_file
//===----------------------------------------------------------------------===//
/// SetupRemoveOnSignal - This is a helper for tool_output_file's constructor
/// to allow the signal handlers to be installed before constructing the
/// base class raw_fd_ostream.
static const char *SetupRemoveOnSignal(const char *Filename) {
tool_output_file::CleanupInstaller::CleanupInstaller(const char *filename)
: Filename(filename), Keep(false) {
// Arrange for the file to be deleted if the process is killed.
if (strcmp(Filename, "-") != 0)
if (Filename != "-")
sys::RemoveFileOnSignal(sys::Path(Filename));
return Filename;
}
tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
unsigned Flags)
: raw_fd_ostream(SetupRemoveOnSignal(filename), ErrorInfo, Flags),
Filename(filename),
Keep(!ErrorInfo.empty() /* If open fails, no cleanup is needed. */) {
}
tool_output_file::~tool_output_file() {
tool_output_file::CleanupInstaller::~CleanupInstaller() {
// Delete the file if the client hasn't told us not to.
if (!Keep && Filename != "-")
sys::Path(Filename).eraseFromDisk();
// Ok, the file is successfully written and closed, or deleted. There's no
// further need to clean it up on signals.
if (Filename != "-")
sys::DontRemoveFileOnSignal(sys::Path(Filename));
}
tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
unsigned Flags)
: Installer(filename),
OS(filename, ErrorInfo, Flags) {
// If open fails, no cleanup is needed.
if (!ErrorInfo.empty())
Installer.Keep = true;
}