blob: f2b3d4429251b8cd89300592efc8d61c6ce25f6b [file] [log] [blame]
Enrico Granata979e20d2011-07-29 19:53:35 +00001class StdVectorSynthProvider:
Enrico Granatac92eb402011-08-04 01:41:02 +00002
Enrico Granata7718f3f2011-08-04 02:35:14 +00003 def __init__(self, valobj, dict):
4 self.valobj = valobj;
5 self.update()
Enrico Granatac92eb402011-08-04 01:41:02 +00006
Enrico Granata7718f3f2011-08-04 02:35:14 +00007 def num_children(self):
8 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
Enrico Granatac92eb402011-08-04 01:41:02 +000017
Enrico Granata7718f3f2011-08-04 02:35:14 +000018 # 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
Enrico Granatac92eb402011-08-04 01:41:02 +000027
Enrico Granata7718f3f2011-08-04 02:35:14 +000028 # 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
Enrico Granatac92eb402011-08-04 01:41:02 +000035
Enrico Granata7718f3f2011-08-04 02:35:14 +000036 def get_child_index(self,name):
37 return int(name.lstrip('[').rstrip(']'))
Enrico Granatac92eb402011-08-04 01:41:02 +000038
Enrico Granata7718f3f2011-08-04 02:35:14 +000039 def get_child_at_index(self,index):
40 if index >= self.num_children():
41 return None;
42 offset = index * self.data_size
43 return self.start.CreateChildAtOffset('['+str(index)+']',offset,self.data_type)
Enrico Granatac92eb402011-08-04 01:41:02 +000044
Enrico Granata7718f3f2011-08-04 02:35:14 +000045 def update(self):
46 impl = self.valobj.GetChildMemberWithName('_M_impl')
47 self.start = impl.GetChildMemberWithName('_M_start')
48 self.finish = impl.GetChildMemberWithName('_M_finish')
49 self.end = impl.GetChildMemberWithName('_M_end_of_storage')
50 self.data_type = self.start.GetType().GetPointeeType()
51 self.data_size = self.data_type.GetByteSize()
52