[Lldb-commits] [lldb] e89414f - [lldb/Utility] Clean up Scalar constructors
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Jul 27 01:07:14 PDT 2020
Author: Pavel Labath
Date: 2020-07-27T10:06:56+02:00
New Revision: e89414f4060d3ff2afcd1c89fc028d61270c4d22
URL: https://github.com/llvm/llvm-project/commit/e89414f4060d3ff2afcd1c89fc028d61270c4d22
DIFF: https://github.com/llvm/llvm-project/commit/e89414f4060d3ff2afcd1c89fc028d61270c4d22.diff
LOG: [lldb/Utility] Clean up Scalar constructors
- move initialization to initializer lists
- make desctructor non-virtual (nothing else is)
- fix long double constructor so that it actually works
Added:
Modified:
lldb/include/lldb/Utility/Scalar.h
lldb/source/Utility/Scalar.cpp
lldb/unittests/Utility/ScalarTest.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Utility/Scalar.h b/lldb/include/lldb/Utility/Scalar.h
index 524b71523074..1dbcf80bfd89 100644
--- a/lldb/include/lldb/Utility/Scalar.h
+++ b/lldb/include/lldb/Utility/Scalar.h
@@ -60,41 +60,30 @@ class Scalar {
};
// Constructors and Destructors
- Scalar();
- Scalar(int v) : m_type(e_sint), m_float(static_cast<float>(0)) {
- m_integer = llvm::APInt(sizeof(int) * 8, v, true);
- }
- Scalar(unsigned int v) : m_type(e_uint), m_float(static_cast<float>(0)) {
- m_integer = llvm::APInt(sizeof(int) * 8, v);
- }
- Scalar(long v) : m_type(e_slong), m_float(static_cast<float>(0)) {
- m_integer = llvm::APInt(sizeof(long) * 8, v, true);
- }
- Scalar(unsigned long v) : m_type(e_ulong), m_float(static_cast<float>(0)) {
- m_integer = llvm::APInt(sizeof(long) * 8, v);
- }
- Scalar(long long v) : m_type(e_slonglong), m_float(static_cast<float>(0)) {
- m_integer = llvm::APInt(sizeof(long long) * 8, v, true);
- }
+ Scalar() : m_type(e_void), m_float(0.0f) {}
+ Scalar(int v)
+ : m_type(e_sint), m_integer(sizeof(v) * 8, v, true), m_float(0.0f) {}
+ Scalar(unsigned int v)
+ : m_type(e_uint), m_integer(sizeof(v) * 8, v, false), m_float(0.0f) {}
+ Scalar(long v)
+ : m_type(e_slong), m_integer(sizeof(v) * 8, v, true), m_float(0.0f) {}
+ Scalar(unsigned long v)
+ : m_type(e_ulong), m_integer(sizeof(v) * 8, v, false), m_float(0.0f) {}
+ Scalar(long long v)
+ : m_type(e_slonglong), m_integer(sizeof(v) * 8, v, true), m_float(0.0f) {}
Scalar(unsigned long long v)
- : m_type(e_ulonglong), m_float(static_cast<float>(0)) {
- m_integer = llvm::APInt(sizeof(long long) * 8, v);
- }
- Scalar(float v) : m_type(e_float), m_float(v) { m_float = llvm::APFloat(v); }
- Scalar(double v) : m_type(e_double), m_float(v) {
- m_float = llvm::APFloat(v);
+ : m_type(e_ulonglong), m_integer(sizeof(v) * 8, v, false), m_float(0.0f) {
}
- Scalar(long double v)
- : m_type(e_long_double),
- m_float(llvm::APFloat::x87DoubleExtended(),
- llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
- (reinterpret_cast<type128 *>(&v))->x)) {}
- Scalar(llvm::APInt v) : m_type(), m_float(static_cast<float>(0)) {
- m_integer = llvm::APInt(std::move(v));
- m_type = GetBestTypeForBitSize(m_integer.getBitWidth(), true);
+ Scalar(float v) : m_type(e_float), m_float(v) {}
+ Scalar(double v) : m_type(e_double), m_float(v) {}
+ Scalar(long double v) : m_type(e_long_double), m_float(double(v)) {
+ bool ignore;
+ m_float.convert(llvm::APFloat::x87DoubleExtended(),
+ llvm::APFloat::rmNearestTiesToEven, &ignore);
}
- // Scalar(const RegisterValue& reg_value);
- virtual ~Scalar();
+ Scalar(llvm::APInt v)
+ : m_type(GetBestTypeForBitSize(v.getBitWidth(), true)),
+ m_integer(std::move(v)), m_float(0.0f) {}
/// Return the most efficient Scalar::Type for the requested bit size.
static Type GetBestTypeForBitSize(size_t bit_size, bool sign);
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index 27d5b3b88d33..9309f8d662da 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -126,8 +126,6 @@ static Scalar::Type PromoteToMaxType(
return Scalar::e_void;
}
-Scalar::Scalar() : m_type(e_void), m_float(static_cast<float>(0)) {}
-
bool Scalar::GetData(DataExtractor &data, size_t limit_byte_size) const {
size_t byte_size = GetByteSize();
if (byte_size == 0) {
@@ -232,8 +230,6 @@ void Scalar::GetValue(Stream *s, bool show_type) const {
}
}
-Scalar::~Scalar() = default;
-
Scalar::Type Scalar::GetBestTypeForBitSize(size_t bit_size, bool sign) {
// Scalar types are always host types, hence the sizeof().
if (sign) {
diff --git a/lldb/unittests/Utility/ScalarTest.cpp b/lldb/unittests/Utility/ScalarTest.cpp
index f6bc6a404c15..70ce0a81627d 100644
--- a/lldb/unittests/Utility/ScalarTest.cpp
+++ b/lldb/unittests/Utility/ScalarTest.cpp
@@ -92,6 +92,7 @@ TEST(ScalarTest, Getters) {
CheckConversion<unsigned long long>(0x8765432112345678ull);
CheckConversion<float>(42.25f);
CheckConversion<double>(42.25);
+ CheckConversion<long double>(42.25L);
EXPECT_EQ(APInt(128, 1) << 70, Scalar(std::pow(2.0f, 70.0f)).SInt128(APInt()));
EXPECT_EQ(APInt(128, -1, true) << 70,
More information about the lldb-commits
mailing list