[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>
This commit is contained in:
1 parent
01c5ec3d62
commit
1370a1cb5b
37 files changed
+365
-185
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user