Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / python_api / formatters / synth.py
blob474c18bc62ebd942716e4e7e3649943a1032fc0c
1 import lldb
4 class jasSynthProvider:
5 def __init__(self, valobj, dict):
6 self.valobj = valobj
8 def num_children(self):
9 return 2
11 def get_child_at_index(self, index):
12 child = None
13 if index == 0:
14 child = self.valobj.GetChildMemberWithName("A")
15 if index == 1:
16 child = self.valobj.CreateValueFromExpression("X", "(int)1")
17 return child
19 def get_child_index(self, name):
20 if name == "A":
21 return 0
22 if name == "X":
23 return 1
24 return None
27 def ccc_summary(sbvalue, internal_dict):
28 sbvalue = sbvalue.GetNonSyntheticValue()
29 # This tests that the SBValue.GetNonSyntheticValue() actually returns a
30 # non-synthetic value. If it does not, then sbvalue.GetChildMemberWithName("a")
31 # in the following statement will call the 'get_child_index' method of the
32 # synthetic child provider CCCSynthProvider below (which raises an
33 # exception).
34 return "CCC object with leading value " + str(sbvalue.GetChildMemberWithName("a"))
37 class CCCSynthProvider(object):
38 def __init__(self, sbvalue, internal_dict):
39 self._sbvalue = sbvalue
41 def num_children(self):
42 return 3
44 def get_child_index(self, name):
45 raise RuntimeError("I don't want to be called!")
47 def get_child_at_index(self, index):
48 if index == 0:
49 return self._sbvalue.GetChildMemberWithName("a")
50 if index == 1:
51 return self._sbvalue.GetChildMemberWithName("b")
52 if index == 2:
53 return self._sbvalue.GetChildMemberWithName("c")
56 def empty1_summary(sbvalue, internal_dict):
57 return "I am an empty Empty1"
60 class Empty1SynthProvider(object):
61 def __init__(self, sbvalue, internal_dict):
62 self._sbvalue = sbvalue
64 def num_children(self):
65 return 0
67 def get_child_at_index(self, index):
68 return None
71 def empty2_summary(sbvalue, internal_dict):
72 return "I am an empty Empty2"
75 class Empty2SynthProvider(object):
76 def __init__(self, sbvalue, internal_dict):
77 self._sbvalue = sbvalue
79 def num_children(self):
80 return 0
82 def get_child_at_index(self, index):
83 return None
86 def __lldb_init_module(debugger, dict):
87 debugger.CreateCategory("JASSynth").AddTypeSynthetic(
88 lldb.SBTypeNameSpecifier("JustAStruct"),
89 lldb.SBTypeSynthetic.CreateWithClassName("synth.jasSynthProvider"),
91 cat = debugger.CreateCategory("CCCSynth")
92 cat.AddTypeSynthetic(
93 lldb.SBTypeNameSpecifier("CCC"),
94 lldb.SBTypeSynthetic.CreateWithClassName(
95 "synth.CCCSynthProvider", lldb.eTypeOptionCascade
98 cat.AddTypeSummary(
99 lldb.SBTypeNameSpecifier("CCC"),
100 lldb.SBTypeSummary.CreateWithFunctionName(
101 "synth.ccc_summary", lldb.eTypeOptionCascade
104 cat.AddTypeSynthetic(
105 lldb.SBTypeNameSpecifier("Empty1"),
106 lldb.SBTypeSynthetic.CreateWithClassName("synth.Empty1SynthProvider"),
108 cat.AddTypeSummary(
109 lldb.SBTypeNameSpecifier("Empty1"),
110 lldb.SBTypeSummary.CreateWithFunctionName("synth.empty1_summary"),
112 cat.AddTypeSynthetic(
113 lldb.SBTypeNameSpecifier("Empty2"),
114 lldb.SBTypeSynthetic.CreateWithClassName("synth.Empty2SynthProvider"),
116 cat.AddTypeSummary(
117 lldb.SBTypeNameSpecifier("Empty2"),
118 lldb.SBTypeSummary.CreateWithFunctionName(
119 "synth.empty2_summary", lldb.eTypeOptionHideEmptyAggregates