summaryrefslogtreecommitdiff
path: root/include/llvm/Support/raw_ostream.h
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-16 22:55:06 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-16 22:55:06 +0000
commitcf2a2c6a26427733f31dd539c6ee6486ea191da2 (patch)
treefb38cd0aa092459d67a629f2ae107cae8f271320 /include/llvm/Support/raw_ostream.h
parent4752bd3b40f4c4a15ca9eeb5122e405b17c87b3d (diff)
downloadllvm-cf2a2c6a26427733f31dd539c6ee6486ea191da2.tar.gz
llvm-cf2a2c6a26427733f31dd539c6ee6486ea191da2.tar.bz2
llvm-cf2a2c6a26427733f31dd539c6ee6486ea191da2.tar.xz
raw_ostream: Lift out flush_nonempty.
- Flush a known non-empty buffers; enforces the interface to flush_impl and kills off HandleFlush (which I saw no reason to be an inline method, Chris?). - Clarify invariant that flush_impl is only called with OutBufCur > OutBufStart. - This also cleary collects all places where we have to deal with the buffer possibly not existing. - A few more comments and fixing the unbuffered behavior remain in this commit sequence. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67057 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/raw_ostream.h')
-rw-r--r--include/llvm/Support/raw_ostream.h62
1 files changed, 38 insertions, 24 deletions
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h
index 8574659900..7ea182b0d7 100644
--- a/include/llvm/Support/raw_ostream.h
+++ b/include/llvm/Support/raw_ostream.h
@@ -31,6 +31,10 @@ namespace llvm {
/// a chunk at a time.
class raw_ostream {
protected:
+ /// \invariant { The buffer is uninitialized (OutBufStart,
+ /// OutBufEnd, and OutBufCur are non-zero), or none of them are zero
+ /// and there are at least 64 total bytes in the buffer. }
+
char *OutBufStart, *OutBufEnd, *OutBufCur;
bool Unbuffered;
@@ -77,7 +81,7 @@ public:
void flush() {
if (OutBufCur != OutBufStart)
- flush_impl();
+ flush_nonempty();
}
raw_ostream &operator<<(char C) {
@@ -85,7 +89,7 @@ public:
return write(C);
*OutBufCur++ = C;
if (Unbuffered)
- flush_impl();
+ flush_nonempty();
return *this;
}
@@ -94,7 +98,7 @@ public:
return write(C);
*OutBufCur++ = C;
if (Unbuffered)
- flush_impl();
+ flush_nonempty();
return *this;
}
@@ -103,7 +107,7 @@ public:
return write(C);
*OutBufCur++ = C;
if (Unbuffered)
- flush_impl();
+ flush_nonempty();
return *this;
}
@@ -142,23 +146,25 @@ public:
// Subclass Interface
//===--------------------------------------------------------------------===//
-protected:
-
+private:
/// flush_impl - The is the piece of the class that is implemented by
- /// subclasses. This outputs the currently buffered data and resets the
- /// buffer to empty.
+ /// subclasses. This only outputs the currently buffered data.
+ ///
+ /// raw_ostream guarantees to only call this routine when there is
+ /// buffered data, i.e. OutBufStart != OutBufCur.
virtual void flush_impl() = 0;
- /// HandleFlush - A stream's implementation of flush should call this after
- /// emitting the bytes to the data sink.
- void HandleFlush() {
- if (OutBufStart == 0)
- SetBufferSize(4096);
- OutBufCur = OutBufStart;
- }
-private:
// An out of line virtual method to provide a home for the class vtable.
virtual void handle();
+
+ //===--------------------------------------------------------------------===//
+ // Private Interface
+ //===--------------------------------------------------------------------===//
+private:
+ /// flush_nonempty - Flush the current buffer, which is known to be
+ /// non-empty. This outputs the currently buffered data and resets
+ /// the buffer to empty.
+ void flush_nonempty();
};
//===----------------------------------------------------------------------===//
@@ -192,8 +198,10 @@ public:
~raw_fd_ostream();
/// flush_impl - The is the piece of the class that is implemented by
- /// subclasses. This outputs the currently buffered data and resets the
- /// buffer to empty.
+ /// subclasses. This only outputs the currently buffered data.
+ ///
+ /// raw_ostream guarantees to only call this routine when there is
+ /// buffered data, i.e. OutBufStart != OutBufCur.
virtual void flush_impl();
/// close - Manually flush the stream and close the file.
@@ -249,8 +257,10 @@ public:
~raw_os_ostream();
/// flush_impl - The is the piece of the class that is implemented by
- /// subclasses. This outputs the currently buffered data and resets the
- /// buffer to empty.
+ /// subclasses. This only outputs the currently buffered data.
+ ///
+ /// raw_ostream guarantees to only call this routine when there is
+ /// buffered data, i.e. OutBufStart != OutBufCur.
virtual void flush_impl();
};
@@ -270,8 +280,10 @@ public:
}
/// flush_impl - The is the piece of the class that is implemented by
- /// subclasses. This outputs the currently buffered data and resets the
- /// buffer to empty.
+ /// subclasses. This only outputs the currently buffered data.
+ ///
+ /// raw_ostream guarantees to only call this routine when there is
+ /// buffered data, i.e. OutBufStart != OutBufCur.
virtual void flush_impl();
};
@@ -284,8 +296,10 @@ public:
~raw_svector_ostream();
/// flush_impl - The is the piece of the class that is implemented by
- /// subclasses. This outputs the currently buffered data and resets the
- /// buffer to empty.
+ /// subclasses. This only outputs the currently buffered data.
+ ///
+ /// raw_ostream guarantees to only call this routine when there is
+ /// buffered data, i.e. OutBufStart != OutBufCur.
virtual void flush_impl();
};