llvm.org GIT mirror llvm / 080e3c5
unindent the file to follow coding standards, change class doc comment to be correct. No functionality or behavior change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178511 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 7 years ago
1 changed file(s) with 104 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
1616
1717 #include "llvm/Support/raw_ostream.h"
1818
19 namespace llvm
20 {
21 /// formatted_raw_ostream - Formatted raw_fd_ostream to handle
22 /// asm-specific constructs.
19 namespace llvm {
20
21 /// formatted_raw_ostream - A raw_ostream that wraps another one and keeps track
22 /// of column position, allowing padding out to specific column boundaries.
23 ///
24 class formatted_raw_ostream : public raw_ostream {
25 public:
26 /// DELETE_STREAM - Tell the destructor to delete the held stream.
2327 ///
24 class formatted_raw_ostream : public raw_ostream {
25 public:
26 /// DELETE_STREAM - Tell the destructor to delete the held stream.
27 ///
28 static const bool DELETE_STREAM = true;
28 static const bool DELETE_STREAM = true;
2929
30 /// PRESERVE_STREAM - Tell the destructor to not delete the held
31 /// stream.
32 ///
33 static const bool PRESERVE_STREAM = false;
30 /// PRESERVE_STREAM - Tell the destructor to not delete the held
31 /// stream.
32 ///
33 static const bool PRESERVE_STREAM = false;
3434
35 private:
36 /// TheStream - The real stream we output to. We set it to be
37 /// unbuffered, since we're already doing our own buffering.
38 ///
39 raw_ostream *TheStream;
35 private:
36 /// TheStream - The real stream we output to. We set it to be
37 /// unbuffered, since we're already doing our own buffering.
38 ///
39 raw_ostream *TheStream;
4040
41 /// DeleteStream - Do we need to delete TheStream in the
42 /// destructor?
43 ///
44 bool DeleteStream;
41 /// DeleteStream - Do we need to delete TheStream in the
42 /// destructor?
43 ///
44 bool DeleteStream;
4545
46 /// ColumnScanned - The current output column of the data that's
47 /// been flushed and the portion of the buffer that's been
48 /// scanned. The column scheme is zero-based.
49 ///
50 unsigned ColumnScanned;
46 /// ColumnScanned - The current output column of the data that's
47 /// been flushed and the portion of the buffer that's been
48 /// scanned. The column scheme is zero-based.
49 ///
50 unsigned ColumnScanned;
5151
52 /// Scanned - This points to one past the last character in the
53 /// buffer we've scanned.
54 ///
55 const char *Scanned;
52 /// Scanned - This points to one past the last character in the
53 /// buffer we've scanned.
54 ///
55 const char *Scanned;
5656
57 virtual void write_impl(const char *Ptr, size_t Size) LLVM_OVERRIDE;
57 virtual void write_impl(const char *Ptr, size_t Size) LLVM_OVERRIDE;
5858
59 /// current_pos - Return the current position within the stream,
60 /// not counting the bytes currently in the buffer.
61 virtual uint64_t current_pos() const LLVM_OVERRIDE {
62 // Our current position in the stream is all the contents which have been
63 // written to the underlying stream (*not* the current position of the
64 // underlying stream).
65 return TheStream->tell();
66 }
59 /// current_pos - Return the current position within the stream,
60 /// not counting the bytes currently in the buffer.
61 virtual uint64_t current_pos() const LLVM_OVERRIDE {
62 // Our current position in the stream is all the contents which have been
63 // written to the underlying stream (*not* the current position of the
64 // underlying stream).
65 return TheStream->tell();
66 }
6767
68 /// ComputeColumn - Examine the given output buffer and figure out which
69 /// column we end up in after output.
70 ///
71 void ComputeColumn(const char *Ptr, size_t size);
68 /// ComputeColumn - Examine the given output buffer and figure out which
69 /// column we end up in after output.
70 ///
71 void ComputeColumn(const char *Ptr, size_t size);
7272
73 public:
74 /// formatted_raw_ostream - Open the specified file for
75 /// writing. If an error occurs, information about the error is
76 /// put into ErrorInfo, and the stream should be immediately
77 /// destroyed; the string will be empty if no error occurred.
78 ///
79 /// As a side effect, the given Stream is set to be Unbuffered.
80 /// This is because formatted_raw_ostream does its own buffering,
81 /// so it doesn't want another layer of buffering to be happening
82 /// underneath it.
83 ///
84 formatted_raw_ostream(raw_ostream &Stream, bool Delete = false)
85 : raw_ostream(), TheStream(0), DeleteStream(false), ColumnScanned(0) {
86 setStream(Stream, Delete);
87 }
88 explicit formatted_raw_ostream()
89 : raw_ostream(), TheStream(0), DeleteStream(false), ColumnScanned(0) {
90 Scanned = 0;
91 }
73 public:
74 /// formatted_raw_ostream - Open the specified file for
75 /// writing. If an error occurs, information about the error is
76 /// put into ErrorInfo, and the stream should be immediately
77 /// destroyed; the string will be empty if no error occurred.
78 ///
79 /// As a side effect, the given Stream is set to be Unbuffered.
80 /// This is because formatted_raw_ostream does its own buffering,
81 /// so it doesn't want another layer of buffering to be happening
82 /// underneath it.
83 ///
84 formatted_raw_ostream(raw_ostream &Stream, bool Delete = false)
85 : raw_ostream(), TheStream(0), DeleteStream(false), ColumnScanned(0) {
86 setStream(Stream, Delete);
87 }
88 explicit formatted_raw_ostream()
89 : raw_ostream(), TheStream(0), DeleteStream(false), ColumnScanned(0) {
90 Scanned = 0;
91 }
9292
93 ~formatted_raw_ostream() {
94 flush();
95 releaseStream();
96 }
93 ~formatted_raw_ostream() {
94 flush();
95 releaseStream();
96 }
9797
98 void setStream(raw_ostream &Stream, bool Delete = false) {
99 releaseStream();
98 void setStream(raw_ostream &Stream, bool Delete = false) {
99 releaseStream();
100100
101 TheStream = &Stream;
102 DeleteStream = Delete;
101 TheStream = &Stream;
102 DeleteStream = Delete;
103103
104 // This formatted_raw_ostream inherits from raw_ostream, so it'll do its
105 // own buffering, and it doesn't need or want TheStream to do another
106 // layer of buffering underneath. Resize the buffer to what TheStream
107 // had been using, and tell TheStream not to do its own buffering.
108 if (size_t BufferSize = TheStream->GetBufferSize())
109 SetBufferSize(BufferSize);
110 else
111 SetUnbuffered();
104 // This formatted_raw_ostream inherits from raw_ostream, so it'll do its
105 // own buffering, and it doesn't need or want TheStream to do another
106 // layer of buffering underneath. Resize the buffer to what TheStream
107 // had been using, and tell TheStream not to do its own buffering.
108 if (size_t BufferSize = TheStream->GetBufferSize())
109 SetBufferSize(BufferSize);
110 else
111 SetUnbuffered();
112 TheStream->SetUnbuffered();
113
114 Scanned = 0;
115 }
116
117 /// PadToColumn - Align the output to some column number. If the current
118 /// column is already equal to or more than NewCol, PadToColumn inserts one
119 /// space.
120 ///
121 /// \param NewCol - The column to move to.
122 formatted_raw_ostream &PadToColumn(unsigned NewCol);
123
124 private:
125 void releaseStream() {
126 // Delete the stream if needed. Otherwise, transfer the buffer
127 // settings from this raw_ostream back to the underlying stream.
128 if (!TheStream)
129 return;
130 if (DeleteStream)
131 delete TheStream;
132 else if (size_t BufferSize = GetBufferSize())
133 TheStream->SetBufferSize(BufferSize);
134 else
112135 TheStream->SetUnbuffered();
113
114 Scanned = 0;
115 }
116
117 /// PadToColumn - Align the output to some column number. If the current
118 /// column is already equal to or more than NewCol, PadToColumn inserts one
119 /// space.
120 ///
121 /// \param NewCol - The column to move to.
122 formatted_raw_ostream &PadToColumn(unsigned NewCol);
123
124 private:
125 void releaseStream() {
126 // Delete the stream if needed. Otherwise, transfer the buffer
127 // settings from this raw_ostream back to the underlying stream.
128 if (!TheStream)
129 return;
130 if (DeleteStream)
131 delete TheStream;
132 else if (size_t BufferSize = GetBufferSize())
133 TheStream->SetBufferSize(BufferSize);
134 else
135 TheStream->SetUnbuffered();
136 }
137 };
136 }
137 };
138138
139139 /// fouts() - This returns a reference to a formatted_raw_ostream for
140140 /// standard output. Use it like: fouts() << "foo" << "bar";