X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=xcbgen%2Fxtypes.py;h=14c318ac3882d076e91e5793c1f4d443c9603d4b;hb=d0b88e5119a93436ac6eb5b604e2743cd3c43a3c;hp=046513ef069037fbf4dc38e3dd52612f00d18c82;hpb=73c14cd5f2cebc0255a395c4cb1d5a85a11a0120;p=free-sw%2Fxcb%2Fproto diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py index 046513e..14c318a 100644 --- a/xcbgen/xtypes.py +++ b/xcbgen/xtypes.py @@ -1,7 +1,7 @@ ''' This module contains the classes which represent XCB data types. ''' -from expr import Field, Expression +from xcbgen.expr import Field, Expression import __main__ class Type(object): @@ -33,6 +33,7 @@ class Type(object): self.is_union = False self.is_pad = False self.is_switch = False + self.is_bitcase = False def resolve(self, module): ''' @@ -158,7 +159,7 @@ class ListType(Type): Type.__init__(self, member.name) self.is_list = True self.member = member - self.parent = list(parent) + self.parents = list(parent) if elt.tag == 'list': elts = list(elt) @@ -179,7 +180,7 @@ class ListType(Type): needlen = True # See if the length field is already in the structure. - for parent in self.parent: + for parent in self.parents: for field in parent.fields: if field.field_name == lenfield_name: needlen = False @@ -197,12 +198,12 @@ class ListType(Type): if self.resolved: return self.member.resolve(module) - self.expr.resolve(module, self.parent) + self.expr.resolve(module, self.parents) # Find my length field again. We need the actual Field object in the expr. # This is needed because we might have added it ourself above. if not self.fixed_size(): - for parent in self.parent: + for parent in self.parents: for field in parent.fields: if field.field_name == self.expr.lenfield_name and field.wire: self.expr.lenfield = field @@ -356,7 +357,7 @@ class SwitchType(ComplexType): def __init__(self, name, elt, *parents): ComplexType.__init__(self, name, elt) - self.parent = parents + self.parents = parents # FIXME: switch cannot store lenfields, so it should just delegate the parents self.lenfield_parent = list(parents) + [self] # self.fields contains all possible fields collected from the Bitcase objects, @@ -372,19 +373,29 @@ class SwitchType(ComplexType): return # pads = 0 + parents = list(self.parents) + [self] + # Resolve all of our field datatypes. for index, child in enumerate(list(self.elt)): if child.tag == 'bitcase': + field_name = child.get('name') + if field_name is None: + field_type = self.name + ('bitcase%d' % index,) + else: + field_type = self.name + (field_name,) + # use self.parent to indicate anchestor, # as switch does not contain named fields itself - type = BitcaseType(index, child, *self.parent) + type = BitcaseType(index, field_type, child, *parents) + # construct the switch type name from the parent type and the field name + if field_name is None: + type.has_name = False + # Get the full type name for the field + field_type = type.name visible = True - # Get the full type name for the field - field_type = type.name - # add the field to ourself - type.make_member_of(module, self, field_type, index, visible, True, False) + type.make_member_of(module, self, field_type, field_name, visible, True, False) # recursively resolve the type (could be another structure, list) type.resolve(module) @@ -402,7 +413,6 @@ class SwitchType(ComplexType): self.calc_size() # Figure out how big we are self.resolved = True - # FIXME: really necessary for Switch?? def make_member_of(self, module, complex_type, field_type, field_name, visible, wire, auto): if not self.fixed_size(): # We need a length field. @@ -413,7 +423,7 @@ class SwitchType(ComplexType): needlen = True # See if the length field is already in the structure. - for parent in self.parent: + for parent in self.parents: for field in parent.fields: if field.field_name == lenfield_name: needlen = False @@ -463,12 +473,15 @@ class BitcaseType(ComplexType): ''' Derived class representing a struct data type. ''' - def __init__(self, index, elt, *parent): + def __init__(self, index, name, elt, *parent): elts = list(elt) self.expr = Expression(elts[0] if len(elts) else elt, self) - ComplexType.__init__(self, ('bitcase%d' % index,), elts[1:]) + ComplexType.__init__(self, name, elts[1:]) + self.has_name = True + self.index = 1 self.lenfield_parent = list(parent) + [self] self.parents = list(parent) + self.is_bitcase = True def make_member_of(self, module, switch_type, field_type, field_name, visible, wire, auto): '''