blob: 2730498465124b15670df39fcf6c9b0553964bda [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 num_children = (finish_val-start_val)/self.data_size
Enrico Granata7718f3f2011-08-04 02:35:14 +000029 return num_children
Enrico Granatac92eb402011-08-04 01:41:02 +000030
Enrico Granata7718f3f2011-08-04 02:35:14 +000031 def get_child_index(self,name):
32 return int(name.lstrip('[').rstrip(']'))
Enrico Granatac92eb402011-08-04 01:41:02 +000033
Enrico Granata7718f3f2011-08-04 02:35:14 +000034 def get_child_at_index(self,index):
35 if index >= self.num_children():
36 return None;
37 offset = index * self.data_size
38 return self.start.CreateChildAtOffset('['+str(index)+']',offset,self.data_type)
Enrico Granatac92eb402011-08-04 01:41:02 +000039
Enrico Granata7718f3f2011-08-04 02:35:14 +000040 def update(self):
41 impl = self.valobj.GetChildMemberWithName('_M_impl')
42 self.start = impl.GetChildMemberWithName('_M_start')
43 self.finish = impl.GetChildMemberWithName('_M_finish')
44 self.end = impl.GetChildMemberWithName('_M_end_of_storage')
45 self.data_type = self.start.GetType().GetPointeeType()
46 self.data_size = self.data_type.GetByteSize()
47