[Xcb-commit] xcb/proto: 4 commits - doc src xcbgen

Peter Harris peterh at kemper.freedesktop.org
Mon Aug 25 16:50:20 PDT 2014


 doc/xml-xcb.txt  |   38 ++++++++++++++++++++++++++++++--------
 src/xcb.xsd      |    4 +++-
 src/xinput.xml   |   16 ++++++----------
 xcbgen/expr.py   |    2 +-
 xcbgen/xtypes.py |   35 +++++++++++++++++++++++++++++------
 5 files changed, 69 insertions(+), 26 deletions(-)

New commits:
commit dc0c544fe044ddeb4917bba0c2fed66c70e6db43
Author: Christian Linhart <chris at demorecorder.com>
Date:   Mon Aug 25 16:58:37 2014 +0200

    schema: add switch-case
    
    Reviewed-by: Peter Harris <pharris at opentext.com>
    Reviewed-by: Ran Benita <ran234 at gmail.com>

diff --git a/src/xcb.xsd b/src/xcb.xsd
index 20cee5b..85f5bc2 100644
--- a/src/xcb.xsd
+++ b/src/xcb.xsd
@@ -78,7 +78,9 @@ authorization from the authors.
       <xsd:group ref="expression" minOccurs="1" maxOccurs="1" />
       <xsd:choice>
         <!-- bitcase expression - bit test -->
-        <xsd:element name="bitcase" type="caseexpr" minOccurs="1" maxOccurs="unbounded" />
+        <xsd:element name="bitcase" type="caseexpr" minOccurs="0" maxOccurs="unbounded" />
+        <!-- case expression - value test -->
+        <xsd:element name="case" type="caseexpr" minOccurs="0" maxOccurs="unbounded" />
       </xsd:choice>
       <!-- default: -->
       <xsd:group ref="fields" minOccurs="0" maxOccurs="1" />
commit 754c73787522e44c2c98ec75688732a414284cc3
Author: Christian Linhart <chris at demorecorder.com>
Date:   Tue Aug 19 15:55:34 2014 +0200

    xinput: req ChangeDeviceProperty: bitcase to case
    
    Change the bitcases to cases
    and remove the comment which says that bitcases should converted to cases.
    
    Reviewed-by: Peter Harris <pharris at opentext.com>
    Reviewed-by: Ran Benita <ran234 at gmail.com>

diff --git a/src/xinput.xml b/src/xinput.xml
index 976855a..dc87e78 100644
--- a/src/xinput.xml
+++ b/src/xinput.xml
@@ -1135,30 +1135,26 @@ in struct DeviceTimeCoord.
         <field type="CARD32" name="num_items" />
         <switch name="items">
             <fieldref>format</fieldref>
-            <!-- <bitcase> is not correct, this would need <cases>s.
-                 It works in that case, because PropertyFormat items can be
-                 distinguished exactly as their values don't have equal bits.
-            -->
-            <bitcase>
+            <case>
                 <enumref ref="PropertyFormat">8Bits</enumref>
                 <list type="CARD8" name="data8">
                     <fieldref>num_items</fieldref>
                 </list>
                 <pad align="4" />
-            </bitcase>
-            <bitcase>
+            </case>
+            <case>
                 <enumref ref="PropertyFormat">16Bits</enumref>
                 <list type="CARD16" name="data16">
                     <fieldref>num_items</fieldref>
                 </list>
                 <pad align="4" />
-            </bitcase>
-            <bitcase>
+            </case>
+            <case>
                 <enumref ref="PropertyFormat">32Bits</enumref>
                 <list type="CARD32" name="data32">
                     <fieldref>num_items</fieldref>
                 </list>
-            </bitcase>
+            </case>
         </switch>
     </request>
 
commit 127d34ac4fc42ecf005f9f2ef02a0e4b74ad1cb3
Author: Christian Linhart <chris at demorecorder.com>
Date:   Tue Aug 19 15:55:33 2014 +0200

    xcbgen-parser: support switch-case
    
    "case" is implemented as a variation of "bitcase" as follows:
    
    The old class "BitCaseType" became the abstract class
    "CaseOrBitcaseType" with two derived classes
    "CaseType" and "BitcaseType".
    (Therefore BitcaseType keeps the old semantic which may
    be important for some generators)
    
    There are two additional flags in class Type:
    * is_case
    * is_case_or_bitcase
    The latter is for convenience because case and bitcase
    have to be treated the same way in many cases.
    
    The list of cases and bitcases in a SwitchType object
    is still called "bitcases".
    Reasons:
    * Renaming that list would break generators based on the parser.
    * Creating an extra list for cases would make other code more
      complicated because you usually want to iterate over all
      case and bitcase members of a switch.
    
    Reviewed-by: Ran Benita <ran234 at gmail.com>

diff --git a/xcbgen/expr.py b/xcbgen/expr.py
index f9d5179..e4fb06e 100644
--- a/xcbgen/expr.py
+++ b/xcbgen/expr.py
@@ -120,7 +120,7 @@ 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():
-                    if p.is_bitcase:
+                    if p.is_case_or_bitcase:
                         # switch is the anchestor 
                         self.lenfield_parent = p.parents[-1]
                     else:
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 3cd9032..45d7568 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -33,7 +33,9 @@ class Type(object):
         self.is_union = False
         self.is_pad = False
         self.is_switch = False
+        self.is_case_or_bitcase = False
         self.is_bitcase = False
+        self.is_case = False
 
     def resolve(self, module):
         '''
@@ -405,16 +407,20 @@ class SwitchType(ComplexType):
 
         # Resolve all of our field datatypes.
         for index, child in enumerate(list(self.elt)):
-            if child.tag == 'bitcase':
+            if child.tag == 'bitcase' or child.tag == 'case':
                 field_name = child.get('name')
                 if field_name is None:
-                    field_type = self.name + ('bitcase%d' % index,)
+                    field_type = self.name + ('%s%d' % ( child.tag, 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, field_type, child, *parents)
+                if child.tag == 'bitcase':
+                    type = BitcaseType(index, field_type, child, *parents)
+                else:
+                    type = CaseType(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
@@ -497,9 +503,9 @@ class Union(ComplexType):
     out = __main__.output['union']
 
 
-class BitcaseType(ComplexType):
+class CaseOrBitcaseType(ComplexType):
     '''
-    Derived class representing a struct data type.
+    Derived class representing a case or bitcase.
     '''
     def __init__(self, index, name, elt, *parent):
         elts = list(elt)
@@ -515,7 +521,7 @@ class BitcaseType(ComplexType):
         self.index = 1
         self.lenfield_parent = list(parent) + [self]
         self.parents = list(parent)
-        self.is_bitcase = True
+        self.is_case_or_bitcase = True
 
     def make_member_of(self, module, switch_type, field_type, field_name, visible, wire, auto, enum=None):
         '''
@@ -546,6 +552,23 @@ class BitcaseType(ComplexType):
         ComplexType.resolve(self, module)
 
 
+class BitcaseType(CaseOrBitcaseType):
+    '''
+    Derived class representing a bitcase.
+    '''
+    def __init__(self, index, name, elt, *parent):
+        CaseOrBitcaseType.__init__(self, index, name, elt, *parent)
+        self.is_bitcase = True
+
+class CaseType(CaseOrBitcaseType):
+    '''
+    Derived class representing a case.
+    '''
+    def __init__(self, index, name, elt, *parent):
+        CaseOrBitcaseType.__init__(self, index, name, elt, *parent)
+        self.is_case = True
+
+
 class Reply(ComplexType):
     '''
     Derived class representing a reply.  Only found as a field of Request.
commit 4987a5c6bcb971d851a71ec3b3d9783a4cbc7554
Author: Christian Linhart <chris at DemoRecorder.com>
Date:   Wed Aug 20 11:10:35 2014 +0200

    xml-xcb spec: describe switch-case
    
    V2: patch revised according to suggestion from Peter Harris:
    * add the restriction that <enumref>
      inside <bitcase> can only refer to an enum's <bit> members, and
      <enumref> inside <case> can only refer to an enum's <value> members.
    
    Reviewed-by: Peter Harris <pharris at opentext.com>
    Reviewed-by: Ran Benita <ran234 at gmail.com>

diff --git a/doc/xml-xcb.txt b/doc/xml-xcb.txt
index 6aa789b..235958d 100644
--- a/doc/xml-xcb.txt
+++ b/doc/xml-xcb.txt
@@ -244,18 +244,40 @@ enum; the value is restricted to one of the constants named in the enum.
   <switch> instead for new protocol definitions.
 
 <switch name="identifier"> switch expression
-    <bitcase> bitcase expression(s), fields </bitcase> </switch>
+    <bitcase> bitcase expression(s), fields </bitcase>
+    <case> case expression(s), fields </case>
+</switch>
 
   This element represents conditional inclusion of fields. It can be viewed
-  as sequence of multiple ifs: if ( switch expression & bitcase expression )
-  is non-zero, bitcase fields are included in structure.  It can be used only
-  as the last field of a structure.
+  as sequence of multiple ifs:
 
-  When a bitcase includes multiple <enumref> clauses, the contents of the
-  bitcase are only present once regardless of the number of bitcase expressions
-  that match.
+  <bitcase>:
+    if ( switch expression & bitcase expression ) is non-zero,
+    bitcase fields are included in structure.
+
+  <case>:
+    if ( switch expression == case expression ) is true,
+    then case fields are included in structure.
+
+  It can be used only as the last field of a structure.
+
+  When a bitcase or case includes multiple <enumref> clauses, the contents
+  of the bitcase or case are only present once regardless of the number of
+  bitcase or case expressions that match.
+
+  <enumref> inside <bitcase> can only refer to an enum's <bit> members.
+  <enumref> inside <case> can only refer to an enum's <value> members.
+
+  A switch may contain multiple <bitcase> or <case> elements.
+  Usually it will only contain <bitcase> elements
+  or only contain <case> elements.
+  That is, mixing of <case> and <bitcase> usually doesn't make any sense.
+
+  The same value may appear in multiple <case> or <bitcase> elements.
+
+  New protocol definitions should prefer to use this instead of <valueparam>
+  and instead of <union>.
 
-  New protocol definitions should prefer to use this instead of <valueparam>.
 
 Expressions
 -----------


More information about the xcb-commit mailing list