To better ensure that bytecode `@update` implementations return a 0/1 value (see https://github.com/llvm/llvm-project/pull/181199), this changes the Python -> formatter bytecode compiler to require that Python `update` methods be declared to return `bool`. A declaration like this will be a compiler error: ```py def update(self): # implementation... ```
33 lines
1.2 KiB
Plaintext
33 lines
1.2 KiB
Plaintext
# RUN: mkdir -p %t
|
|
# RUN: %python %S/../../../../examples/python/formatter_bytecode.py --compile %s --format c --type-name RigidArray --output %t/c-output.txt --skip-invocation-comment
|
|
# RUN: %python %S/../../../../examples/python/formatter_bytecode.py --compile %s --format swift --type-name RigidArray --output %t/swift-output.txt --skip-invocation-comment
|
|
# RUN: diff -u --strip-trailing-cr %S/Inputs/FormatterBytecode/RigidArrayLLDBFormatterC.txt %t/c-output.txt
|
|
# RUN: diff -u --strip-trailing-cr %S/Inputs/FormatterBytecode/RigidArrayLLDBFormatterSwift.txt %t/swift-output.txt
|
|
import lldb
|
|
|
|
|
|
class RigidArraySynthetic:
|
|
valobj: lldb.SBValue
|
|
storage: lldb.SBValue
|
|
count: int
|
|
|
|
def __init__(self, valobj: lldb.SBValue, _) -> None:
|
|
self.valobj = valobj
|
|
|
|
def num_children(self) -> int:
|
|
return self.count
|
|
|
|
def get_child_at_index(self, idx: int) -> lldb.SBValue:
|
|
return self.storage.GetChildAtIndex(idx)
|
|
|
|
def update(self) -> bool:
|
|
self.storage = self.valobj.GetChildMemberWithName(
|
|
"_storage"
|
|
).GetSyntheticValue()
|
|
self.count = (
|
|
self.valobj.GetChildMemberWithName("_count")
|
|
.GetSyntheticValue()
|
|
.GetValueAsUnsigned()
|
|
)
|
|
return True
|