Skip to content

Commit 85d2443

Browse files
committed
Add decimal_fast32_t pretty printer
1 parent 995293e commit 85d2443

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

extra/decimal_printer.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,29 @@ def decimal128_summary(valobj, internal_dict):
5353
except Exception as e:
5454
return f"<invalid decimal128_t: {e}>"
5555

56+
def decimal_fast32_summary(valobj, internal_dict):
57+
"""
58+
Custom summary for decimal_fast32_t type
59+
Displays in scientific notation
60+
"""
61+
62+
try:
63+
val = valobj.GetNonSyntheticValue()
64+
significand = val.GetChildMemberWithName("significand_").GetValueAsUnsigned()
65+
exp = val.GetChildMemberWithName("exponent_").GetValueAsUnsigned()
66+
sign = val.GetChildMemberWithName("sign_").GetValueAsUnsigned()
67+
return decode_fast_type(significand, exp, sign)
68+
69+
except Exception as e:
70+
return f"<invalid decimal_fast32_t: {e}>"
71+
5672
def __lldb_init_module(debugger, internal_dict):
5773
decimal32_pattern = r"^(const )?(boost::decimal::decimal32_t|(\w+::)*decimal32_t)( &| \*)?$"
5874
decimal64_pattern = r"^(const )?(boost::decimal::decimal64_t|(\w+::)*decimal64_t)( &| \*)?$"
5975
decimal128_pattern = r"^(const )?(boost::decimal::decimal128_t|(\w+::)*decimal128_t)( &| \*)?$"
6076

77+
decimal_fast32_pattern = r"^(const )?(boost::decimal::decimal_fast32_t|(\w+::)*decimal_fast32_t)( &| \*)?$"
78+
6179
debugger.HandleCommand(
6280
f'type summary add -x "{decimal32_pattern}" -e -F decimal_printer.decimal32_summary'
6381
)
@@ -85,6 +103,15 @@ def __lldb_init_module(debugger, internal_dict):
85103

86104
print("decimal128_t printer loaded successfully")
87105

106+
debugger.HandleCommand(
107+
f'type summary add -x "{decimal_fast32_pattern}" -e -F decimal_printer.decimal_fast32_summary'
108+
)
109+
debugger.HandleCommand(
110+
f'type synthetic add -x "{decimal_fast32_pattern}" -l decimal_printer.DecimalFastSyntheticProvider'
111+
)
112+
113+
print("decimal_fast32_t printer loaded successfully")
114+
88115
class DecimalSyntheticProvider:
89116
def __init__(self, valobj, internal_dict):
90117
self.valobj = valobj

0 commit comments

Comments
 (0)