diff options
| author | Owen Anderson <resistor@mac.com> | 2008-08-21 06:20:47 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2008-08-21 06:20:47 +0000 |
| commit | 89a1a85913fb559c7e0266570738fd9cdf616fa3 (patch) | |
| tree | 52685ba9c844d715cfcb0e7cf014f92e46e59cb4 | |
| parent | 5d52c4501a3f59b134521ba7dbcf00050218a639 (diff) | |
Implement operator<< in terms of basic types rather than [u]int*_t, which is better for portability. There might be some way to factor this all with metaprogramming magic, but I'm not sure how offhand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55114 91177308-0d34-0410-b5e6-96231b3b80d8
| -rw-r--r-- | include/llvm/Support/raw_ostream.h | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index 7e33cc78b1..6ea5930d64 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -77,7 +77,7 @@ public: return write(Str.data(), Str.length()); } - raw_ostream &operator<<(uint64_t N) { + raw_ostream &operator<<(unsigned long N) { // Zero is a special case. if (N == 0) return *this << '0'; @@ -93,7 +93,7 @@ public: return write(CurPtr, EndPtr-CurPtr); } - raw_ostream &operator<<(int64_t N) { + raw_ostream &operator<<(long N) { if (N < 0) { if (OutBufCur >= OutBufEnd) flush_impl(); @@ -102,15 +102,43 @@ public: N = -N; } - return this->operator<<(static_cast<uint64_t>(N)); + return this->operator<<(static_cast<unsigned long>(N)); } - raw_ostream &operator<<(uint32_t N) { - return this->operator<<(static_cast<uint64_t>(N)); + raw_ostream &operator<<(unsigned long long N) { + // Zero is a special case. + if (N == 0) + return *this << '0'; + + char NumberBuffer[20]; + char *EndPtr = NumberBuffer+sizeof(NumberBuffer); + char *CurPtr = EndPtr; + + while (N) { + *--CurPtr = '0' + char(N % 10); + N /= 10; + } + return write(CurPtr, EndPtr-CurPtr); + } + + raw_ostream &operator<<(long long N) { + if (N < 0) { + if (OutBufCur >= OutBufEnd) + flush_impl(); + *OutBufCur++ = '-'; + + N = -N; + } + + return this->operator<<(static_cast<unsigned long long>(N)); + } + + raw_ostream &operator<<(unsigned int N) { + return this->operator<<(static_cast<unsigned long>(N)); } - raw_ostream &operator<<(int32_t N) { - return this->operator<<(static_cast<int64_t>(N)); + raw_ostream &operator<<(int N) { + return this->operator<<(static_cast<long>(N)); } raw_ostream &operator<<(double N) { |
