[Xcb-commit] 14 commits - src xcbgen

Peter Harris peterh at kemper.freedesktop.org
Thu Dec 23 10:14:58 PST 2010


 src/xcb.xsd      |    1 
 src/xkb.xml      |   33 ++++++---
 xcbgen/expr.py   |   38 ++++++++++-
 xcbgen/xtypes.py |  189 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 235 insertions(+), 26 deletions(-)

New commits:
commit c4497cdbf0640c376cdebb0a9e5ea62458e6ba51
Merge: 661fe8d... e172bed...
Author: Peter Harris <pharris at opentext.com>
Date:   Thu Dec 23 13:02:52 2010 -0500

    Merge branch 'master' of git://anongit.freedesktop.org/~peterh/xcbproto

commit e172bed68294746981eebbaa0c0740c00a0c8bd4
Author: Peter Harris <pharris at opentext.com>
Date:   Wed Oct 20 12:05:37 2010 -0400

    [xkb] Rename type, sequence, and length
    
    These fields are already defined by the protocol. Rename them to avoid
    potential name collisions.
    
    Signed-off-by: Peter Harris <pharris at opentext.com>

diff --git a/src/xkb.xml b/src/xkb.xml
index 760d3f0..157df45 100644
--- a/src/xkb.xml
+++ b/src/xkb.xml
@@ -1984,12 +1984,12 @@ authorization from the authors.
 				<bitcase name="types">
 					<enumref ref="GBNDetail">Types</enumref>
 					<!-- from the spec, this has to be a GetMap reply -->
-					<field name="type" type="CARD8" />
+					<field name="getmap_type" type="CARD8" />
 				        <!-- done 'emulating' GetMap reply header-->
 					<field name="typeDeviceID" type="CARD8" />
 					<!-- from the spec, this has to be a GetMap reply -->
-					<field name="sequence" type="CARD16" />
-					<field name="length" type="CARD32" />
+					<field name="getmap_sequence" type="CARD16" />
+					<field name="getmap_length" type="CARD32" />
 				        <!-- done 'emulating' GetMap reply header-->
 					<pad bytes="2" />
 					<field name="typeMinKeyCode" type="KEYCODE" />
commit 0ba74c7d503776ee133ee841b794a91d4a6c33a9
Author: Peter Harris <pharris at opentext.com>
Date:   Wed Oct 20 10:24:09 2010 -0400

    Revert "xproto.xml: turned valueparam in CreateWindow request into switch"
    
    This reverts commit 9895cf562c5842813782ce494253c9127e699354.
    
    This is intended to be a temporary revert. When we are ready to migrate
    to switch, we should migrate all of the valueparams at the same time.
    
    Signed-off-by: Peter Harris <pharris at opentext.com>

diff --git a/src/xproto.xml b/src/xproto.xml
index 2d76efa..b6521c3 100644
--- a/src/xproto.xml
+++ b/src/xproto.xml
@@ -813,14 +813,6 @@ authorization from the authors.
     <item name="Static">   <value>10</value></item>
   </enum>
 
-  <enum name="BorderPixmap">
-    <item name="CopyFromParent"><value>0</value></item>
-  </enum>
-
-  <enum name="ColorMap">
-    <item name="CopyFromParent"><value>0</value></item>
-  </enum>
-
   <request name="CreateWindow" opcode="1">
     <field type="CARD8" name="depth" />
     <field type="WINDOW" name="wid" />
@@ -832,70 +824,9 @@ authorization from the authors.
     <field type="CARD16" name="border_width" />
     <field type="CARD16" name="class" enum="WindowClass" />
     <field type="VISUALID" name="visual" />
-    <field type="CARD32" name="value_mask" enum="CW" />
-    <switch name="value_list">
-      <fieldref>value_mask</fieldref>
-      <bitcase>
-	<enumref ref="CW">BackPixmap</enumref>
-	<field name="background_pixmap" type="PIXMAP" altenum="BackPixmap" />
-      </bitcase>
-      <bitcase>
-	<enumref ref="CW">BackPixel</enumref>
-	<field name="background_pixel" type="CARD32" />
-      </bitcase>
-      <bitcase>
-	<enumref ref="CW">BorderPixmap</enumref>
-	<field name="border_pixmap" type="PIXMAP" altenum="BorderPixmap" />
-      </bitcase>
-      <bitcase>
-	<enumref ref="CW">BorderPixel</enumref>
-	<field name="border_pixel" type="CARD32" />
-      </bitcase>
-      <bitcase>
-	<enumref ref="CW">BitGravity</enumref>
-	<field name="bit_gravity" type="CARD32" enum="Gravity" />
-      </bitcase>
-      <bitcase>
-	<enumref ref="CW">WinGravity</enumref>
-	<field name="win_gravity" type="CARD32" enum="Gravity" />
-      </bitcase>
-      <bitcase>
-	<enumref ref="CW">BackingStore</enumref>
-	<field name="backing_store" type="CARD32" enum="BackingStore" />
-      </bitcase>
-      <bitcase>      
-	<enumref ref="CW">BackingPlanes</enumref>
-	<field name="backing_planes" type="CARD32" />
-      </bitcase>
-      <bitcase>      
-	<enumref ref="CW">BackingPixel</enumref>
-	<field name="backing_pixel" type="CARD32" />
-      </bitcase>
-      <bitcase>      
-	<enumref ref="CW">OverrideRedirect</enumref>
-	<field name="override_redirect" type="CARD32" />
-      </bitcase>
-      <bitcase>      
-	<enumref ref="CW">SaveUnder</enumref>
-	<field name="save_under" type="CARD32" />
-      </bitcase>
-      <bitcase>      
-	<enumref ref="CW">EventMask</enumref>
-	<field name="event_mask" type="CARD32" enum="EventMask" />
-      </bitcase>
-      <bitcase>      
-	<enumref ref="CW">DontPropagate</enumref>
-	<field name="dont_propagate" type="CARD32" enum="EventMask" />
-      </bitcase>
-      <bitcase>      
-	<enumref ref="CW">Colormap</enumref>
-	<field name="colormap" type="COLORMAP" altenum="ColorMap" />
-      </bitcase>
-      <bitcase>      
-	<enumref ref="CW">Cursor</enumref>
-	<field name="cursor" type="CURSOR" altenum="Cursor" />
-      </bitcase>
-    </switch>
+    <valueparam value-mask-type="CARD32"
+                value-mask-name="value_mask"
+                value-list-name="value_list" />
   </request>
 
   <request name="ChangeWindowAttributes" opcode="2">
commit 476a3fdbc9f4f6256cd64f6683f4529bab1aecec
Author: Peter Harris <pharris at opentext.com>
Date:   Wed Sep 22 23:26:16 2010 -0400

    Fix 'make check'
    
    Adds support for optional bitcase names.
    Partially reverts 76ca2c0b152 which appears to have added fixed_type to
    xproto.xml by accident.
    
    Signed-off-by: Peter Harris <pharris at opentext.com>

diff --git a/src/xcb.xsd b/src/xcb.xsd
index 5169b48..7fdf125 100644
--- a/src/xcb.xsd
+++ b/src/xcb.xsd
@@ -66,6 +66,7 @@ authorization from the authors.
         <xsd:element ref="switch" minOccurs="0" maxOccurs="unbounded" />
       </xsd:choice>
     </xsd:sequence>
+    <xsd:attribute name="name" type="xsd:string" use="optional" />
   </xsd:complexType>
 
   <!-- switch expression -->
diff --git a/src/xproto.xml b/src/xproto.xml
index 87dd762..2d76efa 100644
--- a/src/xproto.xml
+++ b/src/xproto.xml
@@ -833,7 +833,7 @@ authorization from the authors.
     <field type="CARD16" name="class" enum="WindowClass" />
     <field type="VISUALID" name="visual" />
     <field type="CARD32" name="value_mask" enum="CW" />
-    <switch name="value_list" fixed_type="CARD32">
+    <switch name="value_list">
       <fieldref>value_mask</fieldref>
       <bitcase>
 	<enumref ref="CW">BackPixmap</enumref>
commit 9da6ea6269f91602293ad2a4ebccceafa35123f4
Merge: e7aa34e... 76ca2c0...
Author: Peter Harris <pharris at opentext.com>
Date:   Wed Sep 8 14:35:32 2010 -0400

    Merge branch 'gsoc2010' of git://anongit.freedesktop.org/~chr/xcb_proto
    
    Signed-off-by: Peter Harris <pharris at opentext.com>

commit 76ca2c0b1527541be59c344118c538ba055ad9d8
Author: Christoph Reimann <oss at arcor.de>
Date:   Mon Aug 16 18:32:13 2010 +0200

    xcbgen: small fix to store anchestor objects more systematic
    xml: small fixes according to Xlib or the spec

diff --git a/src/xkb.xml b/src/xkb.xml
index 3ccc586..760d3f0 100644
--- a/src/xkb.xml
+++ b/src/xkb.xml
@@ -401,8 +401,12 @@ authorization from the authors.
 
 	<struct name="KTMapEntry">
 		<field name="active" type="BOOL" />
+		<!-- Xlib uses a different arrangement of fields
 		<field name="mods_mask" type="CARD8" mask="ModMask" />
 		<field name="level" type="CARD8" />
+		-->
+		<field name="level" type="CARD8" />
+		<field name="mods_mask" type="CARD8" mask="ModMask" />
 		<field name="mods_mods" type="CARD8" mask="ModMask" />
 		<field name="mods_vmods" type="CARD16" mask="VMod" />
 		<pad bytes="2" />
@@ -1626,7 +1630,11 @@ authorization from the authors.
 				<bitcase>
 					<enumref ref="NameDetail">KTLevelNames</enumref>
 					<list name="nLevelsPerType" type="CARD8">
-						<fieldref>nKTLevels</fieldref>
+					  <!-- Xlib uses NTypes here - 
+					       the spec says nKTLevels is correct, but
+					       it does not work in reality
+					       <fieldref>nKTLevels</fieldref> -->
+					        <fieldref>nTypes</fieldref>
 					</list>
 					<list name="ktLevelNames" type="ATOM">
 						<sumof ref="nLevelsPerType" />
@@ -1975,7 +1983,14 @@ authorization from the authors.
 				<fieldref>reported</fieldref>
 				<bitcase name="types">
 					<enumref ref="GBNDetail">Types</enumref>
+					<!-- from the spec, this has to be a GetMap reply -->
+					<field name="type" type="CARD8" />
+				        <!-- done 'emulating' GetMap reply header-->
 					<field name="typeDeviceID" type="CARD8" />
+					<!-- from the spec, this has to be a GetMap reply -->
+					<field name="sequence" type="CARD16" />
+					<field name="length" type="CARD32" />
+				        <!-- done 'emulating' GetMap reply header-->
 					<pad bytes="2" />
 					<field name="typeMinKeyCode" type="KEYCODE" />
 					<field name="typeMaxKeyCode" type="KEYCODE" />
diff --git a/src/xproto.xml b/src/xproto.xml
index 2d76efa..87dd762 100644
--- a/src/xproto.xml
+++ b/src/xproto.xml
@@ -833,7 +833,7 @@ authorization from the authors.
     <field type="CARD16" name="class" enum="WindowClass" />
     <field type="VISUALID" name="visual" />
     <field type="CARD32" name="value_mask" enum="CW" />
-    <switch name="value_list">
+    <switch name="value_list" fixed_type="CARD32">
       <fieldref>value_mask</fieldref>
       <bitcase>
 	<enumref ref="CW">BackPixmap</enumref>
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 4836205..1a6c7ce 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -159,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)
@@ -180,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
@@ -198,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
@@ -357,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, 
@@ -373,7 +373,7 @@ class SwitchType(ComplexType):
             return
 #        pads = 0
 
-        parents = list(self.parent) + [self]
+        parents = list(self.parents) + [self]
 
         # Resolve all of our field datatypes.
         for index, child in enumerate(list(self.elt)):
@@ -413,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.
@@ -424,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
commit 854e2a05c76ad72bc11fb56c78d707a81e5cf614
Author: Christoph Reimann <oss at arcor.de>
Date:   Mon Aug 2 23:27:06 2010 +0200

    small fix wrt bitcase type names

diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 363608d..4836205 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -379,7 +379,6 @@ class SwitchType(ComplexType):
         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:
@@ -387,14 +386,14 @@ class SwitchType(ComplexType):
 
                 # use self.parent to indicate anchestor, 
                 # as switch does not contain named fields itself
-                type = BitcaseType(index, self.name, child, *parents)
+                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, field_name, visible, True, False)
 
commit dd227908abdb36ba630ac9d8a5449470721e38b8
Author: Christoph Reimann <oss at arcor.de>
Date:   Thu Jul 22 22:53:49 2010 +0200

    support name attribute for bitcases and set BitcaseType.has_name accordingly

diff --git a/src/xkb.xml b/src/xkb.xml
index 33d3ea3..3ccc586 100644
--- a/src/xkb.xml
+++ b/src/xkb.xml
@@ -1973,7 +1973,7 @@ authorization from the authors.
 			<pad bytes="16" />
 			<switch name="replies">
 				<fieldref>reported</fieldref>
-				<bitcase>
+				<bitcase name="types">
 					<enumref ref="GBNDetail">Types</enumref>
 					<field name="typeDeviceID" type="CARD8" />
 					<pad bytes="2" />
@@ -2058,7 +2058,7 @@ authorization from the authors.
 						</bitcase>
 					</switch>
 				</bitcase>
-				<bitcase>
+				<bitcase name="compat_map">
 					<enumref ref="GBNDetail">CompatMap</enumref>
 					<field name="compatDeviceID" type="CARD8" />
 					<field name="groupsRtrn" type="CARD8" mask="SetOfGroup" />
@@ -2079,7 +2079,7 @@ authorization from the authors.
 						</popcount>
 					</list>
 				</bitcase>
-				<bitcase>
+				<bitcase name="client_symbols">
 					<enumref ref="GBNDetail">ClientSymbols</enumref>
 					<field name="clientDeviceID" type="CARD8" />
 					<pad bytes="2" />
@@ -2164,7 +2164,7 @@ authorization from the authors.
 						</bitcase>
 					</switch>
 				</bitcase>
-				<bitcase>
+				<bitcase name="server_symbols">
 					<enumref ref="GBNDetail">ServerSymbols</enumref>
 					<field name="serverDeviceID" type="CARD8" />
 					<pad bytes="2" />
@@ -2249,7 +2249,7 @@ authorization from the authors.
 						</bitcase>
 					</switch>
 				</bitcase>
-				<bitcase>
+				<bitcase name="indicator_maps">
 					<enumref ref="GBNDetail">IndicatorMaps</enumref>
 					<field name="indicatorDeviceID" type="CARD8" />
 					<field name="which" type="CARD32" />
@@ -2260,7 +2260,7 @@ authorization from the authors.
 						<fieldref>nIndicators</fieldref>
 					</list>
 				</bitcase>
-				<bitcase>
+				<bitcase name="key_names">
 					<enumref ref="GBNDetail">KeyNames</enumref>
 					<field name="keyDeviceID" type="CARD8" />
 					<field name="which" type="CARD32" mask="NameDetail" />
@@ -2361,7 +2361,7 @@ authorization from the authors.
 						</bitcase>
 					</switch>
 				</bitcase>
-				<bitcase>
+				<bitcase name="other_names">
 					<enumref ref="GBNDetail">OtherNames</enumref>
 					<field name="otherDeviceID" type="CARD8" />
 					<field name="which" type="CARD32" mask="NameDetail" />
@@ -2462,7 +2462,7 @@ authorization from the authors.
 						</bitcase>
 					</switch>
 				</bitcase>
-				<bitcase>
+				<bitcase name="geometry">
 					<enumref ref="GBNDetail">Geometry</enumref>
 					<field name="geometryDeviceID" type="CARD8" />
 					<field name="name" type="ATOM" />
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index abfb841..363608d 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -378,16 +378,25 @@ class SwitchType(ComplexType):
         # 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, 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)
@@ -470,6 +479,7 @@ class BitcaseType(ComplexType):
         elts = list(elt)
         self.expr = Expression(elts[0] if len(elts) else elt, self)
         ComplexType.__init__(self, name, elts[1:])        
+        self.has_name = True
         self.index = 1
         self.lenfield_parent = list(parent) + [self]
         self.parents = list(parent)
commit 9895cf562c5842813782ce494253c9127e699354
Author: Christoph Reimann <oss at arcor.de>
Date:   Thu Jul 15 10:44:12 2010 +0200

    xproto.xml: turned valueparam in CreateWindow request into switch

diff --git a/src/xproto.xml b/src/xproto.xml
index b6521c3..2d76efa 100644
--- a/src/xproto.xml
+++ b/src/xproto.xml
@@ -813,6 +813,14 @@ authorization from the authors.
     <item name="Static">   <value>10</value></item>
   </enum>
 
+  <enum name="BorderPixmap">
+    <item name="CopyFromParent"><value>0</value></item>
+  </enum>
+
+  <enum name="ColorMap">
+    <item name="CopyFromParent"><value>0</value></item>
+  </enum>
+
   <request name="CreateWindow" opcode="1">
     <field type="CARD8" name="depth" />
     <field type="WINDOW" name="wid" />
@@ -824,9 +832,70 @@ authorization from the authors.
     <field type="CARD16" name="border_width" />
     <field type="CARD16" name="class" enum="WindowClass" />
     <field type="VISUALID" name="visual" />
-    <valueparam value-mask-type="CARD32"
-                value-mask-name="value_mask"
-                value-list-name="value_list" />
+    <field type="CARD32" name="value_mask" enum="CW" />
+    <switch name="value_list">
+      <fieldref>value_mask</fieldref>
+      <bitcase>
+	<enumref ref="CW">BackPixmap</enumref>
+	<field name="background_pixmap" type="PIXMAP" altenum="BackPixmap" />
+      </bitcase>
+      <bitcase>
+	<enumref ref="CW">BackPixel</enumref>
+	<field name="background_pixel" type="CARD32" />
+      </bitcase>
+      <bitcase>
+	<enumref ref="CW">BorderPixmap</enumref>
+	<field name="border_pixmap" type="PIXMAP" altenum="BorderPixmap" />
+      </bitcase>
+      <bitcase>
+	<enumref ref="CW">BorderPixel</enumref>
+	<field name="border_pixel" type="CARD32" />
+      </bitcase>
+      <bitcase>
+	<enumref ref="CW">BitGravity</enumref>
+	<field name="bit_gravity" type="CARD32" enum="Gravity" />
+      </bitcase>
+      <bitcase>
+	<enumref ref="CW">WinGravity</enumref>
+	<field name="win_gravity" type="CARD32" enum="Gravity" />
+      </bitcase>
+      <bitcase>
+	<enumref ref="CW">BackingStore</enumref>
+	<field name="backing_store" type="CARD32" enum="BackingStore" />
+      </bitcase>
+      <bitcase>      
+	<enumref ref="CW">BackingPlanes</enumref>
+	<field name="backing_planes" type="CARD32" />
+      </bitcase>
+      <bitcase>      
+	<enumref ref="CW">BackingPixel</enumref>
+	<field name="backing_pixel" type="CARD32" />
+      </bitcase>
+      <bitcase>      
+	<enumref ref="CW">OverrideRedirect</enumref>
+	<field name="override_redirect" type="CARD32" />
+      </bitcase>
+      <bitcase>      
+	<enumref ref="CW">SaveUnder</enumref>
+	<field name="save_under" type="CARD32" />
+      </bitcase>
+      <bitcase>      
+	<enumref ref="CW">EventMask</enumref>
+	<field name="event_mask" type="CARD32" enum="EventMask" />
+      </bitcase>
+      <bitcase>      
+	<enumref ref="CW">DontPropagate</enumref>
+	<field name="dont_propagate" type="CARD32" enum="EventMask" />
+      </bitcase>
+      <bitcase>      
+	<enumref ref="CW">Colormap</enumref>
+	<field name="colormap" type="COLORMAP" altenum="ColorMap" />
+      </bitcase>
+      <bitcase>      
+	<enumref ref="CW">Cursor</enumref>
+	<field name="cursor" type="CURSOR" altenum="Cursor" />
+      </bitcase>
+    </switch>
   </request>
 
   <request name="ChangeWindowAttributes" opcode="2">
commit 946817d43e10a581b75d8fcab91a6b68e31fb965
Author: Christoph Reimann <oss at arcor.de>
Date:   Thu Jul 15 01:06:49 2010 +0200

    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):
         '''
commit 73c14cd5f2cebc0255a395c4cb1d5a85a11a0120
Author: Christoph Reimann <oss at arcor.de>
Date:   Tue Jul 13 07:59:58 2010 +0200

    - changed handling of anchestor types (may be more than one now)
    - added SwitchType and BitcaseType

diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 32ba8c1..046513e 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -32,6 +32,7 @@ class Type(object):
         self.is_reply = False
         self.is_union = False
         self.is_pad = False
+        self.is_switch = False
 
     def resolve(self, module):
         '''
@@ -73,6 +74,7 @@ class Type(object):
 
         complex_type.fields.append(new_field)
 
+
 class SimpleType(Type):
     '''
     Derived class which represents a cardinal type like CARD32 or char.
@@ -156,7 +158,7 @@ class ListType(Type):
         Type.__init__(self, member.name)
         self.is_list = True
         self.member = member
-        self.parent = parent
+        self.parent = list(parent)
 
         if elt.tag == 'list':
             elts = list(elt)
@@ -195,6 +197,7 @@ class ListType(Type):
         if self.resolved:
             return
         self.member.resolve(module)
+        self.expr.resolve(module, self.parent)
 
         # 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.
@@ -204,7 +207,7 @@ class ListType(Type):
                     if field.field_name == self.expr.lenfield_name and field.wire:
                         self.expr.lenfield = field
                         break
-            
+
         self.resolved = True
 
     def fixed_size(self):
@@ -303,6 +306,15 @@ class ComplexType(Type):
                 fkey = 'CARD32'
                 type = ListType(child, module.get_type(fkey), *self.lenfield_parent)
                 visible = True
+            elif child.tag == 'switch':
+                field_name = child.get('name')
+                # construct the switch type name from the parent type and the field name
+                field_type = self.name + (field_name,)
+                type = SwitchType(field_type, child, *self.lenfield_parent)
+                visible = True
+                type.make_member_of(module, self, field_type, field_name, visible, True, False)
+                type.resolve(module)
+                continue
             else:
                 # Hit this on Reply
                 continue 
@@ -334,6 +346,100 @@ class ComplexType(Type):
                 return False
         return True
 
+class SwitchType(ComplexType):
+    '''
+    Derived class which represents a List of Items.  
+
+    Public fields added:
+    bitcases is an array of Bitcase objects describing the list items
+    '''
+
+    def __init__(self, name, elt, *parents):
+        ComplexType.__init__(self, name, elt)
+        self.parent = 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, 
+        # whereas self.items contains the Bitcase objects themselves
+        self.bitcases = []
+
+        self.is_switch = True
+        elts = list(elt)
+        self.expr = Expression(elts[0] if len(elts) else elt, self)
+
+    def resolve(self, module):
+        if self.resolved:
+            return
+#        pads = 0
+
+        # 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)
+                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)
+
+                # recursively resolve the type (could be another structure, list)
+                type.resolve(module)
+                inserted = False
+                for new_field in type.fields:
+                    # We dump the _placeholder_byte if any fields are added.
+                    for (idx, field) in enumerate(self.fields):
+                        if field == _placeholder_byte:
+                            self.fields[idx] = new_field
+                            inserted = True
+                            break
+                    if False == inserted:
+                        self.fields.append(new_field)
+
+        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.
+            # Ask our Expression object for it's name, type, and whether it's on the wire.
+            lenfid = self.expr.lenfield_type
+            lenfield_name = self.expr.lenfield_name
+            lenwire = self.expr.lenwire
+            needlen = True
+
+            # See if the length field is already in the structure.
+            for parent in self.parent:
+                for field in parent.fields:
+                    if field.field_name == lenfield_name:
+                        needlen = False
+
+            # It isn't, so we need to add it to the structure ourself.
+            if needlen:
+                type = module.get_type(lenfid)
+                lenfield_type = module.get_type_name(lenfid)
+                type.make_member_of(module, complex_type, lenfield_type, lenfield_name, True, lenwire, False)
+
+        # Add ourself to the structure by calling our original method.
+        Type.make_member_of(self, module, complex_type, field_type, field_name, visible, wire, auto)
+
+    # size for switch can only be calculated at runtime
+    def calc_size(self):
+        pass
+
+    # note: switch is _always_ of variable size, but we indicate here wether 
+    # it contains elements that are variable-sized themselves
+    def fixed_size(self):
+        return False
+#        for m in self.fields:
+#            if not m.type.fixed_size():
+#                return False
+#        return True
+
 
 class Struct(ComplexType):
     '''
@@ -353,6 +459,45 @@ class Union(ComplexType):
     out = __main__.output['union']
 
 
+class BitcaseType(ComplexType):
+    '''
+    Derived class representing a struct data type.
+    '''
+    def __init__(self, index, elt, *parent):
+        elts = list(elt)
+        self.expr = Expression(elts[0] if len(elts) else elt, self)
+        ComplexType.__init__(self, ('bitcase%d' % index,), elts[1:])        
+        self.lenfield_parent = list(parent) + [self]
+        self.parents = list(parent)
+
+    def make_member_of(self, module, switch_type, field_type, field_name, visible, wire, auto):
+        '''
+        register BitcaseType with the corresponding SwitchType
+
+        module is the global module object.
+        complex_type is the structure object.
+        see Field for the meaning of the other parameters.
+        '''
+        new_field = Field(self, field_type, field_name, visible, wire, auto)
+
+        # We dump the _placeholder_byte if any bitcases are added.
+        for (idx, field) in enumerate(switch_type.bitcases):
+            if field == _placeholder_byte:
+                switch_type.bitcases[idx] = new_field
+                return
+
+        switch_type.bitcases.append(new_field)
+
+    def resolve(self, module):
+        if self.resolved:
+            return
+        
+        self.expr.resolve(module, self.parents+[self])
+
+        # Resolve the bitcase expression
+        ComplexType.resolve(self, module)
+
+
 class Reply(ComplexType):
     '''
     Derived class representing a reply.  Only found as a field of Request.
commit d30664b58016687379d42d18056827fe57830d20
Author: Christoph Reimann <oss at arcor.de>
Date:   Tue Jul 13 07:58:24 2010 +0200

    add support for new expr tags popcount, enumref, sumof

diff --git a/xcbgen/expr.py b/xcbgen/expr.py
index b10b2eb..ddfb76c 100644
--- a/xcbgen/expr.py
+++ b/xcbgen/expr.py
@@ -40,6 +40,7 @@ class Expression(object):
 
         self.lenfield_name = None
         self.lenfield_type = None
+        self.lenfield_parent = None
         self.lenfield = None
         self.lenwire = False
         self.bitfield = False
@@ -86,10 +87,37 @@ class Expression(object):
             # Constant expression
             self.nmemb = int(elt.text, 0)
 
+        elif elt.tag == 'popcount':
+            self.op = 'popcount'
+            self.rhs = Expression(list(elt)[0], parent)
+            self.lenfield_name = self.rhs.lenfield_name
+            # xcb_popcount returns 'int' - handle the type in the language-specific part
+
+        elif elt.tag == 'enumref':
+            self.op = 'enumref'
+            self.lenfield_name = (elt.get('ref'), elt.text)
+            
+        elif elt.tag == 'sumof':
+            self.op = 'sumof'
+            self.lenfield_name = elt.get('ref')
+
         else:
             # Notreached
             raise Exception("undefined tag '%s'" % elt.tag)
 
-
     def fixed_size(self):
         return self.nmemb != None
+
+    def resolve(self, module, parents):
+        if self.op == 'enumref':
+            self.lenfield_type = module.get_type(self.lenfield_name[0])
+            self.lenfield_name = self.lenfield_name[1]
+        elif self.op == 'sumof':
+            # need to find the field with lenfield_name
+            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
+                    self.lenfield_type = fields[self.lenfield_name].field_type
+                    break
+                    
commit 29da739948419b660ff4a94706b1cb59c93ab9cc
Author: Christoph Reimann <oss at arcor.de>
Date:   Sat Jun 12 23:25:08 2010 +0200

    xcbgen: perform lenfield lookup within all anchestors

diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 35fcb91..32ba8c1 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -152,7 +152,7 @@ class ListType(Type):
     parent is the structure type containing the list.
     expr is an Expression object containing the length information, for variable-sized lists.
     '''
-    def __init__(self, elt, member, parent):
+    def __init__(self, elt, member, *parent):
         Type.__init__(self, member.name)
         self.is_list = True
         self.member = member
@@ -177,9 +177,10 @@ class ListType(Type):
             needlen = True
 
             # See if the length field is already in the structure.
-            for field in self.parent.fields:
-                if field.field_name == lenfield_name:
-                    needlen = False
+            for parent in self.parent:
+                for field in parent.fields:
+                    if field.field_name == lenfield_name:
+                        needlen = False
 
             # It isn't, so we need to add it to the structure ourself.
             if needlen:
@@ -198,10 +199,11 @@ class ListType(Type):
         # 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 field in self.parent.fields:
-                if field.field_name == self.expr.lenfield_name and field.wire:
-                    self.expr.lenfield = field
-                    break
+            for parent in self.parent:
+                for field in parent.fields:
+                    if field.field_name == self.expr.lenfield_name and field.wire:
+                        self.expr.lenfield = field
+                        break
             
         self.resolved = True
 
@@ -215,7 +217,7 @@ class ExprType(Type):
     Public fields added:
     expr is an Expression object containing the value of the field.
     '''
-    def __init__(self, elt, member, parent):
+    def __init__(self, elt, member, *parent):
         Type.__init__(self, member.name)
         self.is_expr = True
         self.member = member
@@ -266,6 +268,7 @@ class ComplexType(Type):
         self.fields = []
         self.nmemb = 1
         self.size = 0
+        self.lenfield_parent = [self]
 
     def resolve(self, module):
         if self.resolved:
@@ -288,17 +291,17 @@ class ComplexType(Type):
             elif child.tag == 'exprfield':
                 field_name = child.get('name')
                 fkey = child.get('type')
-                type = ExprType(child, module.get_type(fkey), self)
+                type = ExprType(child, module.get_type(fkey), *self.lenfield_parent)
                 visible = False
             elif child.tag == 'list':
                 field_name = child.get('name')
                 fkey = child.get('type')
-                type = ListType(child, module.get_type(fkey), self)
+                type = ListType(child, module.get_type(fkey), *self.lenfield_parent)
                 visible = True
             elif child.tag == 'valueparam':
                 field_name = child.get('value-list-name')
                 fkey = 'CARD32'
-                type = ListType(child, module.get_type(fkey), self)
+                type = ListType(child, module.get_type(fkey), *self.lenfield_parent)
                 visible = True
             else:
                 # Hit this on Reply
commit cb4c5d2f464660abc596aa2761b2fb034be1c59a
Author: Christoph Reimann <oss at arcor.de>
Date:   Sat May 22 18:04:53 2010 +0200

    changed Exception message in case of unknown/unhandled XML tags

diff --git a/xcbgen/expr.py b/xcbgen/expr.py
index 79ad8f6..b10b2eb 100644
--- a/xcbgen/expr.py
+++ b/xcbgen/expr.py
@@ -81,14 +81,14 @@ class Expression(object):
             self.rhs = Expression(list(elt)[0], parent)
 
             self.lenfield_name = self.rhs.lenfield_name
-
+            
         elif elt.tag == 'value':
             # Constant expression
             self.nmemb = int(elt.text, 0)
 
         else:
             # Notreached
-            raise Exception('XXX')
+            raise Exception("undefined tag '%s'" % elt.tag)
 
 
     def fixed_size(self):


More information about the xcb-commit mailing list