diff options
Diffstat (limited to 'include/llvm/Support/raw_ostream.h')
| -rw-r--r-- | include/llvm/Support/raw_ostream.h | 60 |
1 files changed, 19 insertions, 41 deletions
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index 28e512c86941b..d1e96f892a4b4 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -218,14 +218,13 @@ public: // Formatted output, see the leftJustify() function in Support/Format.h. raw_ostream &operator<<(const FormattedString &); - + // Formatted output, see the formatHex() function in Support/Format.h. raw_ostream &operator<<(const FormattedNumber &); - + /// indent - Insert 'NumSpaces' spaces. raw_ostream &indent(unsigned NumSpaces); - /// Changes the foreground color of text that will be output from this point /// forward. /// @param Color ANSI color to use, the special SAVEDCOLOR can be used to @@ -246,7 +245,7 @@ public: /// outputting colored text, or before program exit. virtual raw_ostream &resetColor() { return *this; } - /// Reverses the forground and background colors. + /// Reverses the foreground and background colors. virtual raw_ostream &reverseColor() { return *this; } /// This function determines if this stream is connected to a "tty" or @@ -316,7 +315,7 @@ private: }; /// An abstract base class for streams implementations that also support a -/// pwrite operation. This is usefull for code that can mostly stream out data, +/// pwrite operation. This is useful for code that can mostly stream out data, /// but needs to patch in a header that needs to know the output size. class raw_pwrite_stream : public raw_ostream { virtual void pwrite_impl(const char *Ptr, size_t Size, uint64_t Offset) = 0; @@ -350,10 +349,6 @@ class raw_fd_ostream : public raw_pwrite_stream { /// bool Error; - /// Controls whether the stream should attempt to use atomic writes, when - /// possible. - bool UseAtomicWrites; - uint64_t pos; bool SupportsSeeking; @@ -403,16 +398,6 @@ public: /// to the offset specified from the beginning of the file. uint64_t seek(uint64_t off); - /// Set the stream to attempt to use atomic writes for individual output - /// routines where possible. - /// - /// Note that because raw_ostream's are typically buffered, this flag is only - /// sensible when used on unbuffered streams which will flush their output - /// immediately. - void SetUseAtomicWrites(bool Value) { - UseAtomicWrites = Value; - } - raw_ostream &changeColor(enum Colors colors, bool bold=false, bool bg=false) override; raw_ostream &resetColor() override; @@ -471,6 +456,7 @@ class raw_string_ostream : public raw_ostream { /// Return the current position within the stream, not counting the bytes /// currently in the buffer. uint64_t current_pos() const override { return OS.size(); } + public: explicit raw_string_ostream(std::string &O) : OS(O) {} ~raw_string_ostream() override; @@ -485,6 +471,9 @@ public: /// A raw_ostream that writes to an SmallVector or SmallString. This is a /// simple adaptor class. This class does not encounter output errors. +/// raw_svector_ostream operates without a buffer, delegating all memory +/// management to the SmallString. Thus the SmallString is always up-to-date, +/// may be used directly and there is no need to call flush(). class raw_svector_ostream : public raw_pwrite_stream { SmallVectorImpl<char> &OS; @@ -493,32 +482,23 @@ class raw_svector_ostream : public raw_pwrite_stream { void pwrite_impl(const char *Ptr, size_t Size, uint64_t Offset) override; - /// Return the current position within the stream, not counting the bytes - /// currently in the buffer. + /// Return the current position within the stream. uint64_t current_pos() const override; -protected: - // Like the regular constructor, but doesn't call init. - explicit raw_svector_ostream(SmallVectorImpl<char> &O, unsigned); - void init(); - public: /// Construct a new raw_svector_ostream. /// /// \param O The vector to write to; this should generally have at least 128 /// bytes free to avoid any extraneous memory overhead. - explicit raw_svector_ostream(SmallVectorImpl<char> &O); - ~raw_svector_ostream() override; - + explicit raw_svector_ostream(SmallVectorImpl<char> &O) : OS(O) { + SetUnbuffered(); + } + ~raw_svector_ostream() override {} - /// This is called when the SmallVector we're appending to is changed outside - /// of the raw_svector_ostream's control. It is only safe to do this if the - /// raw_svector_ostream has previously been flushed. - void resync(); + void flush() = delete; - /// Flushes the stream contents to the target vector and return a StringRef - /// for the vector contents. - StringRef str(); + /// Return a StringRef for the vector contents. + StringRef str() { return StringRef(OS.data(), OS.size()); } }; /// A raw_ostream that discards all output. @@ -541,12 +521,10 @@ class buffer_ostream : public raw_svector_ostream { SmallVector<char, 0> Buffer; public: - buffer_ostream(raw_ostream &OS) : raw_svector_ostream(Buffer, 0), OS(OS) { - init(); - } - ~buffer_ostream() { OS << str(); } + buffer_ostream(raw_ostream &OS) : raw_svector_ostream(Buffer), OS(OS) {} + ~buffer_ostream() override { OS << str(); } }; } // end llvm namespace -#endif +#endif // LLVM_SUPPORT_RAW_OSTREAM_H |
