diff options
author | Med Ismail Bennani <ismail@bennani.ma> | 2023-05-22 13:52:09 -0700 |
---|---|---|
committer | Med Ismail Bennani <ismail@bennani.ma> | 2023-05-22 16:14:00 -0700 |
commit | 1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68 (patch) | |
tree | a281d98fa2d451a04b2b657c02ee19a98c674e3c /lldb/unittests/ScriptInterpreter/Python | |
parent | 01c5ec3d6209875de05de94cd7923c4e462c3317 (diff) | |
download | llvm-1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68.zip llvm-1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68.tar.gz llvm-1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68.tar.bz2 |
[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 <ismail@bennani.ma>
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python')
-rw-r--r-- | lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
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 <variant> + 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<StructuredData::UnsignedIntegerSP>(int_sp)); + StructuredData::UnsignedIntegerSP uint_sp = + std::get<StructuredData::UnsignedIntegerSP>(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<StructuredData::SignedIntegerSP>(int_sp)); + StructuredData::SignedIntegerSP sint_sp = + std::get<StructuredData::SignedIntegerSP>(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); } } |