mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Move raw_ostream's Error flag into raw_fd_ostream, as that's the only
class which is using it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111639 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
634d661965
commit
8df0e01046
@ -58,10 +58,6 @@ private:
|
||||
ExternalBuffer
|
||||
} BufferMode;
|
||||
|
||||
/// Error This flag is true if an error of any kind has been detected.
|
||||
///
|
||||
bool Error;
|
||||
|
||||
public:
|
||||
// color order matches ANSI escape sequence, don't change
|
||||
enum Colors {
|
||||
@ -77,7 +73,7 @@ public:
|
||||
};
|
||||
|
||||
explicit raw_ostream(bool unbuffered=false)
|
||||
: BufferMode(unbuffered ? Unbuffered : InternalBuffer), Error(false) {
|
||||
: BufferMode(unbuffered ? Unbuffered : InternalBuffer) {
|
||||
// Start out ready to flush.
|
||||
OutBufStart = OutBufEnd = OutBufCur = 0;
|
||||
}
|
||||
@ -87,21 +83,6 @@ public:
|
||||
/// tell - Return the current offset with the file.
|
||||
uint64_t tell() const { return current_pos() + GetNumBytesInBuffer(); }
|
||||
|
||||
/// has_error - Return the value of the flag in this raw_ostream indicating
|
||||
/// whether an output error has been encountered.
|
||||
/// This doesn't implicitly flush any pending output.
|
||||
bool has_error() const {
|
||||
return Error;
|
||||
}
|
||||
|
||||
/// clear_error - Set the flag read by has_error() to false. If the error
|
||||
/// flag is set at the time when this raw_ostream's destructor is called,
|
||||
/// report_fatal_error is called to report the error. Use clear_error()
|
||||
/// after handling the error to avoid this behavior.
|
||||
void clear_error() {
|
||||
Error = false;
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Configuration Interface
|
||||
//===--------------------------------------------------------------------===//
|
||||
@ -285,10 +266,6 @@ protected:
|
||||
/// underlying output mechanism.
|
||||
virtual size_t preferred_buffer_size() const;
|
||||
|
||||
/// error_detected - Set the flag indicating that an output error has
|
||||
/// been encountered.
|
||||
void error_detected() { Error = true; }
|
||||
|
||||
/// getBufferStart - Return the beginning of the current stream buffer, or 0
|
||||
/// if the stream is unbuffered.
|
||||
const char *getBufferStart() const { return OutBufStart; }
|
||||
@ -319,6 +296,11 @@ private:
|
||||
class raw_fd_ostream : public raw_ostream {
|
||||
int FD;
|
||||
bool ShouldClose;
|
||||
|
||||
/// Error This flag is true if an error of any kind has been detected.
|
||||
///
|
||||
bool Error;
|
||||
|
||||
uint64_t pos;
|
||||
|
||||
/// write_impl - See raw_ostream::write_impl.
|
||||
@ -331,6 +313,10 @@ class raw_fd_ostream : public raw_ostream {
|
||||
/// preferred_buffer_size - Determine an efficient buffer size.
|
||||
virtual size_t preferred_buffer_size() const;
|
||||
|
||||
/// error_detected - Set the flag indicating that an output error has
|
||||
/// been encountered.
|
||||
void error_detected() { Error = true; }
|
||||
|
||||
public:
|
||||
|
||||
enum {
|
||||
@ -365,7 +351,8 @@ public:
|
||||
/// ShouldClose is true, this closes the file when the stream is destroyed.
|
||||
raw_fd_ostream(int fd, bool shouldClose,
|
||||
bool unbuffered=false) : raw_ostream(unbuffered), FD(fd),
|
||||
ShouldClose(shouldClose) {}
|
||||
ShouldClose(shouldClose),
|
||||
Error(false) {}
|
||||
|
||||
~raw_fd_ostream();
|
||||
|
||||
@ -382,6 +369,21 @@ public:
|
||||
virtual raw_ostream &resetColor();
|
||||
|
||||
virtual bool is_displayed() const;
|
||||
|
||||
/// has_error - Return the value of the flag in this raw_fd_ostream indicating
|
||||
/// whether an output error has been encountered.
|
||||
/// This doesn't implicitly flush any pending output.
|
||||
bool has_error() const {
|
||||
return Error;
|
||||
}
|
||||
|
||||
/// clear_error - Set the flag read by has_error() to false. If the error
|
||||
/// flag is set at the time when this raw_ostream's destructor is called,
|
||||
/// report_fatal_error is called to report the error. Use clear_error()
|
||||
/// after handling the error to avoid this behavior.
|
||||
void clear_error() {
|
||||
Error = false;
|
||||
}
|
||||
};
|
||||
|
||||
/// raw_stdout_ostream - This is a stream that always prints to stdout.
|
||||
|
@ -57,13 +57,6 @@ raw_ostream::~raw_ostream() {
|
||||
|
||||
if (BufferMode == InternalBuffer)
|
||||
delete [] OutBufStart;
|
||||
|
||||
// If there are any pending errors, report them now. Clients wishing
|
||||
// to avoid report_fatal_error calls should check for errors with
|
||||
// has_error() and clear the error flag with clear_error() before
|
||||
// destructing raw_ostream objects which may have errors.
|
||||
if (Error)
|
||||
report_fatal_error("IO failure on output stream.");
|
||||
}
|
||||
|
||||
// An out of line virtual method to provide a home for the class vtable.
|
||||
@ -370,7 +363,7 @@ void format_object_base::home() {
|
||||
/// stream should be immediately destroyed; the string will be empty
|
||||
/// if no error occurred.
|
||||
raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
|
||||
unsigned Flags) : pos(0) {
|
||||
unsigned Flags) : Error(false), pos(0) {
|
||||
assert(Filename != 0 && "Filename is null");
|
||||
// Verify that we don't have both "append" and "excl".
|
||||
assert((!(Flags & F_Excl) || !(Flags & F_Append)) &&
|
||||
@ -418,14 +411,22 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
|
||||
}
|
||||
|
||||
raw_fd_ostream::~raw_fd_ostream() {
|
||||
if (FD < 0) return;
|
||||
flush();
|
||||
if (ShouldClose)
|
||||
while (::close(FD) != 0)
|
||||
if (errno != EINTR) {
|
||||
error_detected();
|
||||
break;
|
||||
}
|
||||
if (FD >= 0) {
|
||||
flush();
|
||||
if (ShouldClose)
|
||||
while (::close(FD) != 0)
|
||||
if (errno != EINTR) {
|
||||
error_detected();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are any pending errors, report them now. Clients wishing
|
||||
// to avoid report_fatal_error calls should check for errors with
|
||||
// has_error() and clear the error flag with clear_error() before
|
||||
// destructing raw_ostream objects which may have errors.
|
||||
if (has_error())
|
||||
report_fatal_error("IO failure on output stream.");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user