[lldb] Remove Scalar operator= overloads
authorPavel Labath <pavel@labath.sk>
Wed, 10 Jun 2020 13:26:50 +0000 (15:26 +0200)
committerPavel Labath <pavel@labath.sk>
Thu, 11 Jun 2020 11:55:02 +0000 (13:55 +0200)
The are not needed as Scalar is implicitly constructible from all of
these types (so the compiler will use a combination of a constructor +
move assignment instead), and they make it very easy for implementations
of assignment and construction operations to diverge.

lldb/include/lldb/Utility/Scalar.h
lldb/source/Utility/Scalar.cpp

index 0c8f745..1865a34 100644 (file)
@@ -153,16 +153,6 @@ public:
   // automagically by the compiler, so no temporary objects will need to be
   // created. As a result, we currently don't need a variety of overloaded set
   // value accessors.
-  Scalar &operator=(const int i);
-  Scalar &operator=(unsigned int v);
-  Scalar &operator=(long v);
-  Scalar &operator=(unsigned long v);
-  Scalar &operator=(long long v);
-  Scalar &operator=(unsigned long long v);
-  Scalar &operator=(float v);
-  Scalar &operator=(double v);
-  Scalar &operator=(long double v);
-  Scalar &operator=(llvm::APInt v);
   Scalar &operator+=(const Scalar &rhs);
   Scalar &operator<<=(const Scalar &rhs); // Shift left
   Scalar &operator>>=(const Scalar &rhs); // Shift right (arithmetic)
index 827a3f6..759e2a7 100644 (file)
@@ -305,101 +305,6 @@ const char *Scalar::GetTypeAsCString() const {
   return "<invalid Scalar type>";
 }
 
-Scalar &Scalar::operator=(const int v) {
-  m_type = e_sint;
-  m_integer = llvm::APInt(sizeof(int) * 8, v, true);
-  return *this;
-}
-
-Scalar &Scalar::operator=(unsigned int v) {
-  m_type = e_uint;
-  m_integer = llvm::APInt(sizeof(int) * 8, v);
-  return *this;
-}
-
-Scalar &Scalar::operator=(long v) {
-  m_type = e_slong;
-  m_integer = llvm::APInt(sizeof(long) * 8, v, true);
-  return *this;
-}
-
-Scalar &Scalar::operator=(unsigned long v) {
-  m_type = e_ulong;
-  m_integer = llvm::APInt(sizeof(long) * 8, v);
-  return *this;
-}
-
-Scalar &Scalar::operator=(long long v) {
-  m_type = e_slonglong;
-  m_integer = llvm::APInt(sizeof(long long) * 8, v, true);
-  return *this;
-}
-
-Scalar &Scalar::operator=(unsigned long long v) {
-  m_type = e_ulonglong;
-  m_integer = llvm::APInt(sizeof(long long) * 8, v);
-  return *this;
-}
-
-Scalar &Scalar::operator=(float v) {
-  m_type = e_float;
-  m_float = llvm::APFloat(v);
-  return *this;
-}
-
-Scalar &Scalar::operator=(double v) {
-  m_type = e_double;
-  m_float = llvm::APFloat(v);
-  return *this;
-}
-
-Scalar &Scalar::operator=(long double v) {
-  m_type = e_long_double;
-  m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(),
-                          llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
-                                      (reinterpret_cast<type128 *>(&v))->x));
-  return *this;
-}
-
-Scalar &Scalar::operator=(llvm::APInt rhs) {
-  m_integer = llvm::APInt(rhs);
-  switch (m_integer.getBitWidth()) {
-  case 8:
-  case 16:
-  case 32:
-    if (m_integer.isSignedIntN(sizeof(sint_t) * 8))
-      m_type = e_sint;
-    else
-      m_type = e_uint;
-    break;
-  case 64:
-    if (m_integer.isSignedIntN(sizeof(slonglong_t) * 8))
-      m_type = e_slonglong;
-    else
-      m_type = e_ulonglong;
-    break;
-  case 128:
-    if (m_integer.isSignedIntN(BITWIDTH_INT128))
-      m_type = e_sint128;
-    else
-      m_type = e_uint128;
-    break;
-  case 256:
-    if (m_integer.isSignedIntN(BITWIDTH_INT256))
-      m_type = e_sint256;
-    else
-      m_type = e_uint256;
-    break;
-  case 512:
-    if (m_integer.isSignedIntN(BITWIDTH_INT512))
-      m_type = e_sint512;
-    else
-      m_type = e_uint512;
-    break;
-  }
-  return *this;
-}
-
 Scalar::~Scalar() = default;
 
 Scalar::Type Scalar::GetBestTypeForBitSize(size_t bit_size, bool sign) {