[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:
@@ -22,12 +22,17 @@ class TestStructuredDataAPI(TestBase):
|
||||
s = lldb.SBStream()
|
||||
|
||||
dict_str = json.dumps(
|
||||
{"key_dict":
|
||||
{"key_string":"STRING",
|
||||
"key_uint":0xffffffff00000000,
|
||||
"key_float":2.99,
|
||||
"key_bool":True,
|
||||
"key_array":["23","arr"]}})
|
||||
{
|
||||
"key_dict": {
|
||||
"key_string": "STRING",
|
||||
"key_uint": 0xFFFFFFFF00000000,
|
||||
"key_sint": -42,
|
||||
"key_float": 2.99,
|
||||
"key_bool": True,
|
||||
"key_array": ["23", "arr"],
|
||||
}
|
||||
}
|
||||
)
|
||||
s.Print(dict_str)
|
||||
example = lldb.SBStructuredData()
|
||||
|
||||
@@ -46,7 +51,7 @@ class TestStructuredDataAPI(TestBase):
|
||||
self.assertSuccess(error, "GetDescription works")
|
||||
if not "key_float" in s.GetData():
|
||||
self.fail("FAILED: could not find key_float in description output")
|
||||
|
||||
|
||||
dict_struct = lldb.SBStructuredData()
|
||||
dict_struct = example.GetValueForKey("key_dict")
|
||||
|
||||
@@ -59,6 +64,9 @@ class TestStructuredDataAPI(TestBase):
|
||||
# Tests for integer data type
|
||||
self.uint_struct_test(dict_struct)
|
||||
|
||||
# Tests for integer data type
|
||||
self.sint_struct_test(dict_struct)
|
||||
|
||||
# Tests for floating point data type
|
||||
self.double_struct_test(dict_struct)
|
||||
|
||||
@@ -90,7 +98,7 @@ class TestStructuredDataAPI(TestBase):
|
||||
self.fail("Wrong type returned: " + str(dict_struct.GetType()))
|
||||
|
||||
# Check Size API for 'dictionary' type
|
||||
if not dict_struct.GetSize() == 5:
|
||||
if not dict_struct.GetSize() == 6:
|
||||
self.fail("Wrong no of elements returned: " +
|
||||
str(dict_struct.GetSize()))
|
||||
|
||||
@@ -131,14 +139,38 @@ class TestStructuredDataAPI(TestBase):
|
||||
if not uint_struct.GetType() == lldb.eStructuredDataTypeInteger:
|
||||
self.fail("Wrong type returned: " + str(uint_struct.GetType()))
|
||||
|
||||
# Check API returning 'integer' value
|
||||
output = uint_struct.GetIntegerValue()
|
||||
# Check API returning unsigned integer value
|
||||
output = uint_struct.GetUnsignedIntegerValue()
|
||||
if not output == 0xffffffff00000000:
|
||||
self.fail("wrong output: " + str(output))
|
||||
|
||||
# Calling wrong API on a SBStructuredData
|
||||
# (e.g. getting a string value from an integer type structure)
|
||||
output = uint_struct.GetStringValue(25)
|
||||
if output:
|
||||
self.fail("Valid string " + output + " returned for an integer object")
|
||||
|
||||
def sint_struct_test(self, dict_struct):
|
||||
# Check a valid SBStructuredData containing an signed integer.
|
||||
# We intentionally make this smaller than what an uint64_t can hold but
|
||||
# still small enough to fit a int64_t
|
||||
sint_struct = lldb.SBStructuredData()
|
||||
sint_struct = dict_struct.GetValueForKey("key_sint")
|
||||
if not sint_struct.IsValid():
|
||||
self.fail("A valid object should have been returned")
|
||||
|
||||
# Check Type API
|
||||
if not sint_struct.GetType() == lldb.eStructuredDataTypeSignedInteger:
|
||||
self.fail("Wrong type returned: " + str(sint_struct.GetType()))
|
||||
|
||||
# Check API returning signed integer value
|
||||
output = sint_struct.GetSignedIntegerValue()
|
||||
if not output == -42:
|
||||
self.fail("wrong output: " + str(output))
|
||||
|
||||
# Calling wrong API on a SBStructuredData
|
||||
# (e.g. getting a string value from an integer type structure)
|
||||
output = sint_struct.GetStringValue(69)
|
||||
if output:
|
||||
self.fail(
|
||||
"Valid string " +
|
||||
|
||||
Reference in New Issue
Block a user