[llvm-commits] [llvm] r55114 - /llvm/trunk/include/llvm/Support/raw_ostream.h
Owen Anderson
resistor at mac.com
Wed Aug 20 23:20:47 PDT 2008
Author: resistor
Date: Thu Aug 21 01:20:47 2008
New Revision: 55114
URL: http://llvm.org/viewvc/llvm-project?rev=55114&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Support/raw_ostream.h
Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=55114&r1=55113&r2=55114&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Thu Aug 21 01:20:47 2008
@@ -77,7 +77,7 @@
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 @@
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 @@
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) {
More information about the llvm-commits
mailing list