From: Christoph Reimann Date: Wed, 14 Jul 2010 23:06:49 +0000 (+0200) Subject: assign switch name to bitcases as well (important in case of switch that appear insid... X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?p=free-sw%2Fxcb%2Fproto;a=commitdiff_plain;h=946817d43e10a581b75d8fcab91a6b68e31fb965 assign switch name to bitcases as well (important in case of switch that appear inside another switch) --- diff --git a/xcbgen/expr.py b/xcbgen/expr.py index ddfb76c..274c290 100644 --- a/xcbgen/expr.py +++ b/xcbgen/expr.py @@ -117,7 +117,11 @@ class Expression(object): for p in reversed(parents): fields = dict([(f.field_name, f) for f in p.fields]) if self.lenfield_name in fields.keys(): - self.lenfield_parent = p + if p.is_bitcase: + # switch is the anchestor + self.lenfield_parent = p.parents[-1] + else: + self.lenfield_parent = p self.lenfield_type = fields[self.lenfield_name].field_type break diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py index 046513e..abfb841 100644 --- a/xcbgen/xtypes.py +++ b/xcbgen/xtypes.py @@ -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): ''' @@ -372,12 +373,14 @@ class SwitchType(ComplexType): return # pads = 0 + parents = list(self.parent) + [self] + # Resolve all of our field datatypes. for index, child in enumerate(list(self.elt)): if child.tag == 'bitcase': # use self.parent to indicate anchestor, # as switch does not contain named fields itself - type = BitcaseType(index, child, *self.parent) + type = BitcaseType(index, self.name, child, *parents) visible = True # Get the full type name for the field @@ -463,12 +466,14 @@ 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.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): '''