support name attribute for bitcases and set BitcaseType.has_name accordingly
[free-sw/xcb/proto] / xcbgen / xtypes.py
index 046513e..363608d 100644 (file)
@@ -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,19 +373,30 @@ 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':
+                field_name = child.get('name')
+                # construct the switch type name from the parent type and the field 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, self.name, child, *parents)
+                if field_name is None:
+                    type.has_name = False
                 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)
@@ -463,12 +475,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):
         '''