X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FSmallString.h;h=687fa2d26e246f42680b365956c5687b1e00ac43;hb=e8bc475668ddd2f31f44dd00b042d15b255e1b9e;hp=c7a292d8b9098b08f93d2ab51b9fe290e2ea31a9;hpb=dd94c8d6b2afb9c33c364ac8f0c8f8ed5d4c04a0;p=oota-llvm.git diff --git a/include/llvm/ADT/SmallString.h b/include/llvm/ADT/SmallString.h index c7a292d8b90..687fa2d26e2 100644 --- a/include/llvm/ADT/SmallString.h +++ b/include/llvm/ADT/SmallString.h @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Chris Lattner and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -15,6 +15,7 @@ #define LLVM_ADT_SMALLSTRING_H #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/DataTypes.h" #include namespace llvm { @@ -30,11 +31,11 @@ public: // Initialize with a range. template SmallString(ItTy S, ItTy E) : SmallVector(S, E) {} - + // Copy ctor. SmallString(const SmallString &RHS) : SmallVector(RHS) {} - + // Extra methods. const char *c_str() const { SmallString *This = const_cast(this); @@ -43,15 +44,66 @@ public: This->End[0] = 0; return this->begin(); } - + // Extra operators. + const SmallString &operator=(const char *RHS) { + this->clear(); + return *this += RHS; + } + SmallString &operator+=(const char *RHS) { this->append(RHS, RHS+strlen(RHS)); return *this; } + SmallString &operator+=(char C) { + this->push_back(C); + return *this; + } + + SmallString &append_uint_32(uint32_t N) { + char Buffer[20]; + char *BufPtr = Buffer+20; + + if (N == 0) *--BufPtr = '0'; // Handle special case. + + while (N) { + *--BufPtr = '0' + char(N % 10); + N /= 10; + } + this->append(BufPtr, Buffer+20); + return *this; + } + + SmallString &append_uint(uint64_t N) { + if (N == uint32_t(N)) + return append_uint_32(uint32_t(N)); + + char Buffer[40]; + char *BufPtr = Buffer+40; + + if (N == 0) *--BufPtr = '0'; // Handle special case... + + while (N) { + *--BufPtr = '0' + char(N % 10); + N /= 10; + } + + this->append(BufPtr, Buffer+40); + return *this; + } + + SmallString &append_sint(int64_t N) { + // TODO, wrong for minint64. + if (N < 0) { + this->push_back('-'); + N = -N; + } + return append_uint(N); + } + }; - - + + } #endif