Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / examples / summaries / synth.py
blob94cfbfa4c8cd0ac711ad298aba27781745f43a37
1 import lldb
4 class PythonObjectSyntheticChildProvider(object):
5 def __init__(self, value, internal_dict):
6 self.value = value
7 self.values = self.make_children()
8 self.built_values = {}
9 self.bo = self.value.target.byte_order
10 self.ps = self.value.target.addr_size
12 def make_children(self):
13 pass
15 def num_children(self):
16 return len(self.values)
18 def get_child_index(self, name):
19 i = 0
20 for N, value in self.values:
21 if N == name:
22 return i
23 i += 1
24 return None
26 def update(self):
27 pass
29 def has_children(self):
30 return len(self.values) > 0
32 def gen_child(self, name, value):
33 data = None
34 type = None
35 if isinstance(value, int):
36 data = lldb.SBData.CreateDataFromUInt64Array(self.bo, self.ps, [value])
37 type = self.value.target.GetBasicType(lldb.eBasicTypeLong)
38 elif isinstance(value, float):
39 data = lldb.SBData.CreateDataFromDoubleArray(self.bo, self.ps, [value])
40 type = self.value.target.GetBasicType(lldb.eBasicTypeDouble)
41 elif isinstance(value, str):
42 data = lldb.SBData.CreateDataFromCString(self.bo, self.ps, value)
43 type = self.value.target.GetBasicType(lldb.eBasicTypeChar).GetArrayType(
44 len(value)
46 if (data is not None) and (type is not None):
47 return self.value.CreateValueFromData(name, data, type)
48 return None
50 def get_child_at_index(self, index):
51 if index in self.built_values:
52 return self.built_values[index]
54 bv = None
56 name, value = self.values[index]
57 bv = self.gen_child(name, value)
58 self.built_values[index] = bv
59 return bv