diff options
author | Jay Foad <jay.foad@gmail.com> | 2010-12-07 08:25:19 +0000 |
---|---|---|
committer | Jay Foad <jay.foad@gmail.com> | 2010-12-07 08:25:19 +0000 |
commit | 40f8f6264d5af2c38e797e0dc59827cd231e8ff7 (patch) | |
tree | 3f3b576d6ec060c4063e4630d1ac4fad94997d82 /include/llvm/ADT/APSInt.h | |
parent | 0ea112f104215ccba8d89c839cdeded6e3d49e59 (diff) | |
download | llvm-40f8f6264d5af2c38e797e0dc59827cd231e8ff7.tar.gz llvm-40f8f6264d5af2c38e797e0dc59827cd231e8ff7.tar.bz2 llvm-40f8f6264d5af2c38e797e0dc59827cd231e8ff7.tar.xz |
PR5207: Change APInt methods trunc(), sext(), zext(), sextOrTrunc() and
zextOrTrunc(), and APSInt methods extend(), extOrTrunc() and new method
trunc(), to be const and to return a new value instead of modifying the
object in place.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121120 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/APSInt.h')
-rw-r--r-- | include/llvm/ADT/APSInt.h | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/include/llvm/ADT/APSInt.h b/include/llvm/ADT/APSInt.h index 1c9931c30f..54a7b601d1 100644 --- a/include/llvm/ADT/APSInt.h +++ b/include/llvm/ADT/APSInt.h @@ -68,20 +68,22 @@ public: } using APInt::toString; - APSInt& extend(uint32_t width) { + APSInt trunc(uint32_t width) const { + return APSInt(APInt::trunc(width), IsUnsigned); + } + + APSInt extend(uint32_t width) const { if (IsUnsigned) - zext(width); + return APSInt(zext(width), IsUnsigned); else - sext(width); - return *this; + return APSInt(sext(width), IsUnsigned); } - APSInt& extOrTrunc(uint32_t width) { + APSInt extOrTrunc(uint32_t width) const { if (IsUnsigned) - zextOrTrunc(width); + return APSInt(zextOrTrunc(width), IsUnsigned); else - sextOrTrunc(width); - return *this; + return APSInt(sextOrTrunc(width), IsUnsigned); } const APSInt &operator%=(const APSInt &RHS) { |