blob: dc226902d1eb3fa5d4db5260567656cebee22844 [file] [log] [blame]
Enrico Granata979e20d2011-07-29 19:53:35 +00001class StdVectorSynthProvider:
Enrico Granatac92eb402011-08-04 01:41:02 +00002
Enrico Granata979e20d2011-07-29 19:53:35 +00003 def __init__(self, valobj, dict):
4 self.valobj = valobj;
5 self.update()
Enrico Granatac92eb402011-08-04 01:41:02 +00006
Enrico Granata979e20d2011-07-29 19:53:35 +00007 def num_children(self):
Enrico Granatac92eb402011-08-04 01:41:02 +00008 start_val = self.start.GetValueAsUnsigned(0)
9 finish_val = self.finish.GetValueAsUnsigned(0)
10 end_val = self.end.GetValueAsUnsigned(0)
11 # Before a vector has been constructed, it will contain bad values
12 # so we really need to be careful about the length we return since
13 # unitialized data can cause us to return a huge number. We need
14 # to also check for any of the start, finish or end of storage values
15 # being zero (NULL). If any are, then this vector has not been
16 # initialized yet and we should return zero
17
18 # Make sure nothing is NULL
19 if start_val == 0 or finish_val == 0 or end_val == 0:
20 return 0
21 # Make sure start is less than finish
22 if start_val >= finish_val:
23 return 0
24 # Make sure finish is less than or equal to end of storage
25 if finish_val > end_val:
26 return 0
27
28 # We might still get things wrong, so cap things at 256 items for now
29 # TODO: read a target "settings set" variable for this to allow it to
30 # be customized
31 num_children = (finish_val-start_val)/self.data_size
32 if num_children > 256:
33 return 256
34 return num_children
35
Enrico Granata979e20d2011-07-29 19:53:35 +000036 def get_child_index(self,name):
37 if name == "len":
38 return self.num_children();
39 else:
40 return int(name.lstrip('[').rstrip(']'))
Enrico Granatac92eb402011-08-04 01:41:02 +000041
Enrico Granata979e20d2011-07-29 19:53:35 +000042 def get_child_at_index(self,index):
43 if index == self.num_children():
44 return self.valobj.CreateValueFromExpression("len",str(self.num_children()))
45 else:
46 offset = index * self.data_size
Enrico Granatac92eb402011-08-04 01:41:02 +000047 return self.start.CreateChildAtOffset('['+str(index)+']',offset,self.data_type)
48
Enrico Granata979e20d2011-07-29 19:53:35 +000049 def update(self):
Enrico Granatac92eb402011-08-04 01:41:02 +000050 impl = self.valobj.GetChildMemberWithName('_M_impl')
51 self.start = impl.GetChildMemberWithName('_M_start')
52 self.finish = impl.GetChildMemberWithName('_M_finish')
53 self.end = impl.GetChildMemberWithName('_M_end_of_storage')
54 self.data_type = self.start.GetType().GetPointeeType()
Enrico Granata979e20d2011-07-29 19:53:35 +000055 self.data_size = self.data_type.GetByteSize()