llvm.org GIT mirror llvm / cd0129f
Make some methods const. The only interesting change here is that it changes raw_fd_ostream::preferred_buffer_size to return zero on a scary stat failure instead of setting the stream to an error state. This method really should not mutate the stream. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91740 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
5 changed file(s) with 28 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
5858
5959 /// current_pos - Return the current position within the stream,
6060 /// not counting the bytes currently in the buffer.
61 virtual uint64_t current_pos() {
61 virtual uint64_t current_pos() const {
6262 // This has the same effect as calling TheStream.current_pos(),
6363 // but that interface is private.
6464 return TheStream->tell() - TheStream->GetNumBytesInBuffer();
2929
3030 /// current_pos - Return the current position within the stream, not
3131 /// counting the bytes currently in the buffer.
32 virtual uint64_t current_pos();
32 virtual uint64_t current_pos() const;
3333
3434 public:
3535 raw_os_ostream(std::ostream &O) : OS(O) {}
8484 virtual ~raw_ostream();
8585
8686 /// tell - Return the current offset with the file.
87 uint64_t tell() { return current_pos() + GetNumBytesInBuffer(); }
87 uint64_t tell() const { return current_pos() + GetNumBytesInBuffer(); }
8888
8989 /// has_error - Return the value of the flag in this raw_ostream indicating
9090 /// whether an output error has been encountered.
115115 SetBufferAndMode(new char[Size], Size, InternalBuffer);
116116 }
117117
118 size_t GetBufferSize() {
118 size_t GetBufferSize() const {
119119 // If we're supposed to be buffered but haven't actually gotten around
120120 // to allocating the buffer yet, return the value that would be used.
121121 if (BufferMode != Unbuffered && OutBufStart == 0)
268268
269269 /// current_pos - Return the current position within the stream, not
270270 /// counting the bytes currently in the buffer.
271 virtual uint64_t current_pos() = 0;
271 virtual uint64_t current_pos() const = 0;
272272
273273 protected:
274274 /// SetBuffer - Use the provided buffer as the raw_ostream buffer. This is
281281
282282 /// preferred_buffer_size - Return an efficient buffer size for the
283283 /// underlying output mechanism.
284 virtual size_t preferred_buffer_size();
284 virtual size_t preferred_buffer_size() const;
285285
286286 /// error_detected - Set the flag indicating that an output error has
287287 /// been encountered.
324324
325325 /// current_pos - Return the current position within the stream, not
326326 /// counting the bytes currently in the buffer.
327 virtual uint64_t current_pos() { return pos; }
327 virtual uint64_t current_pos() const { return pos; }
328328
329329 /// preferred_buffer_size - Determine an efficient buffer size.
330 virtual size_t preferred_buffer_size();
330 virtual size_t preferred_buffer_size() const;
331331
332332 public:
333333
422422
423423 /// current_pos - Return the current position within the stream, not
424424 /// counting the bytes currently in the buffer.
425 virtual uint64_t current_pos() { return OS.size(); }
425 virtual uint64_t current_pos() const { return OS.size(); }
426426 public:
427427 explicit raw_string_ostream(std::string &O) : OS(O) {}
428428 ~raw_string_ostream();
446446
447447 /// current_pos - Return the current position within the stream, not
448448 /// counting the bytes currently in the buffer.
449 virtual uint64_t current_pos();
449 virtual uint64_t current_pos() const;
450450 public:
451451 /// Construct a new raw_svector_ostream.
452452 ///
467467
468468 /// current_pos - Return the current position within the stream, not
469469 /// counting the bytes currently in the buffer.
470 virtual uint64_t current_pos();
470 virtual uint64_t current_pos() const;
471471
472472 public:
473473 explicit raw_null_ostream() {}
2626 OS.write(Ptr, Size);
2727 }
2828
29 uint64_t raw_os_ostream::current_pos() { return OS.tellp(); }
29 uint64_t raw_os_ostream::current_pos() const { return OS.tellp(); }
6666 // An out of line virtual method to provide a home for the class vtable.
6767 void raw_ostream::handle() {}
6868
69 size_t raw_ostream::preferred_buffer_size() {
69 size_t raw_ostream::preferred_buffer_size() const {
7070 // BUFSIZ is intended to be a reasonable default.
7171 return BUFSIZ;
7272 }
439439 return pos;
440440 }
441441
442 size_t raw_fd_ostream::preferred_buffer_size() {
442 size_t raw_fd_ostream::preferred_buffer_size() const {
443443 #if !defined(_MSC_VER) && !defined(__MINGW32__) // Windows has no st_blksize.
444444 assert(FD >= 0 && "File not yet open!");
445445 struct stat statbuf;
446 if (fstat(FD, &statbuf) == 0) {
447 // If this is a terminal, don't use buffering. Line buffering
448 // would be a more traditional thing to do, but it's not worth
449 // the complexity.
450 if (S_ISCHR(statbuf.st_mode) && isatty(FD))
451 return 0;
452 // Return the preferred block size.
453 return statbuf.st_blksize;
454 }
455 error_detected();
446 if (fstat(FD, &statbuf) != 0)
447 return 0;
448
449 // If this is a terminal, don't use buffering. Line buffering
450 // would be a more traditional thing to do, but it's not worth
451 // the complexity.
452 if (S_ISCHR(statbuf.st_mode) && isatty(FD))
453 return 0;
454 // Return the preferred block size.
455 return statbuf.st_blksize;
456456 #endif
457457 return raw_ostream::preferred_buffer_size();
458458 }
577577 SetBuffer(OS.end(), OS.capacity() - OS.size());
578578 }
579579
580 uint64_t raw_svector_ostream::current_pos() { return OS.size(); }
580 uint64_t raw_svector_ostream::current_pos() const {
581 return OS.size();
582 }
581583
582584 StringRef raw_svector_ostream::str() {
583585 flush();
600602 void raw_null_ostream::write_impl(const char *Ptr, size_t Size) {
601603 }
602604
603 uint64_t raw_null_ostream::current_pos() {
605 uint64_t raw_null_ostream::current_pos() const {
604606 return 0;
605607 }