From 1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 22 May 2023 13:52:09 -0700 Subject: [lldb] Add support for negative integer to {SB,}StructuredData This patch refactors the `StructuredData::Integer` class to make it templated, makes it private and adds 2 public specialization for both `int64_t` & `uint64_t` with a public type aliases, respectively `SignedInteger` & `UnsignedInteger`. It adds new getter for signed and unsigned interger values to the `StructuredData::Object` base class and changes the implementation of `StructuredData::Array::GetItemAtIndexAsInteger` and `StructuredData::Dictionary::GetValueForKeyAsInteger` to support signed and unsigned integers. This patch also adds 2 new `Get{Signed,Unsigned}IntegerValue` to the `SBStructuredData` class and marks `GetIntegerValue` as deprecated. Finally, this patch audits all the caller of `StructuredData::Integer` or `StructuredData::GetIntegerValue` to use the proper type as well the various tests that uses `SBStructuredData.GetIntegerValue`. rdar://105575764 Differential Revision: https://reviews.llvm.org/D150485 Signed-off-by: Med Ismail Bennani --- .../Python/PythonDataObjectsTests.cpp | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp') diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp index 733b919..3450712 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp @@ -19,6 +19,8 @@ #include "PythonTestSuite.h" +#include + using namespace lldb_private; using namespace lldb_private::python; using llvm::Error; @@ -266,10 +268,23 @@ TEST_F(PythonDataObjectsTest, TestPythonStringToStr) { TEST_F(PythonDataObjectsTest, TestPythonIntegerToStr) {} -TEST_F(PythonDataObjectsTest, TestPythonIntegerToStructuredInteger) { +TEST_F(PythonDataObjectsTest, TestPythonIntegerToStructuredUnsignedInteger) { PythonInteger integer(7); auto int_sp = integer.CreateStructuredInteger(); - EXPECT_EQ(7U, int_sp->GetValue()); + EXPECT_TRUE( + std::holds_alternative(int_sp)); + StructuredData::UnsignedIntegerSP uint_sp = + std::get(int_sp); + EXPECT_EQ(7U, uint_sp->GetValue()); +} + +TEST_F(PythonDataObjectsTest, TestPythonIntegerToStructuredSignedInteger) { + PythonInteger integer(-42); + auto int_sp = integer.CreateStructuredInteger(); + EXPECT_TRUE(std::holds_alternative(int_sp)); + StructuredData::SignedIntegerSP sint_sp = + std::get(int_sp); + EXPECT_EQ(-42, sint_sp->GetValue()); } TEST_F(PythonDataObjectsTest, TestPythonStringToStructuredString) { @@ -358,7 +373,7 @@ TEST_F(PythonDataObjectsTest, TestPythonListToStructuredList) { EXPECT_EQ(lldb::eStructuredDataTypeString, array_sp->GetItemAtIndex(1)->GetType()); - auto int_sp = array_sp->GetItemAtIndex(0)->GetAsInteger(); + auto int_sp = array_sp->GetItemAtIndex(0)->GetAsUnsignedInteger(); auto string_sp = array_sp->GetItemAtIndex(1)->GetAsString(); EXPECT_EQ(long_value0, long(int_sp->GetValue())); @@ -522,7 +537,7 @@ TEST_F(PythonDataObjectsTest, TestPythonDictionaryToStructuredDictionary) { EXPECT_TRUE(dict_sp->HasKey(string_key1)); auto string_sp = dict_sp->GetValueForKey(string_key0)->GetAsString(); - auto int_sp = dict_sp->GetValueForKey(string_key1)->GetAsInteger(); + auto int_sp = dict_sp->GetValueForKey(string_key1)->GetAsUnsignedInteger(); EXPECT_EQ(string_value0, string_sp->GetValue()); EXPECT_EQ(int_value1, long(int_sp->GetValue())); @@ -592,7 +607,7 @@ TEST_F(PythonDataObjectsTest, TestExtractingUInt64ThroughStructuredData) { structured_dict_ptr->GetValueForKey(key_name); EXPECT_TRUE((bool)structured_addr_value_sp); const uint64_t extracted_value = - structured_addr_value_sp->GetIntegerValue(123); + structured_addr_value_sp->GetUnsignedIntegerValue(123); EXPECT_TRUE(extracted_value == value); } } -- cgit v1.1