[Xcb] [PATCH proto 2/8] xcbgen: new expr-type listelement-ref

Christian Linhart chris at demorecorder.com
Thu Sep 4 08:48:56 PDT 2014


Add parser-support for the new expression-type "listelement-ref"
which represents the current list-element when used inside
a list-iteration expression such as <sumof>.

This patch includes computation of the flag "contains_listelement_ref"
which is set to True when an expression or any of its
subexpressions is a listelement-ref.
(This is needed by the generator)
---
 xcbgen/expr.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/xcbgen/expr.py b/xcbgen/expr.py
index ee2d3fd..bdb930b 100644
--- a/xcbgen/expr.py
+++ b/xcbgen/expr.py
@@ -49,14 +49,16 @@ class Expression(object):
         self.lenwire = False
         self.bitfield = False
 
         self.op = None
         self.lhs = None
         self.rhs = None
 
+        self.contains_listelement_ref = False
+
         if elt.tag == 'list':
             # List going into a request, which has no length field (inferred by server)
             self.lenfield_name = elt.get('name') + '_len'
             self.lenfield_type = 'CARD32'
 
         elif elt.tag == 'fieldref':
             # Standard list with a fieldref
@@ -107,21 +109,32 @@ class Expression(object):
             subexpressions = list(elt)
             if len(subexpressions) > 0:
                 #sumof with a nested expression which is to be evaluated
                 #for each list-element in the context of that list-element.
                 #sumof then returns the sum of the results of these evaluations
                 self.rhs = Expression(subexpressions[0], parent)
 
+        elif elt.tag == 'listelement-ref':
+            #current list element inside iterating expressions such as sumof
+            self.op = 'listelement-ref'
+            self.contains_listelement_ref = True
+
         else:
             # Notreached
             raise Exception("undefined tag '%s'" % elt.tag)
 
     def fixed_size(self):
         return self.nmemb != None
 
+    def recursive_resolve_tasks(self, module, parents):
+        for subexpr in ( self.lhs, self.rhs ):
+            if subexpr != None:
+                subexpr.recursive_resolve_tasks(module, parents)
+                self.contains_listelement_ref |= subexpr.contains_listelement_ref
+
     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): 
@@ -130,8 +143,10 @@ class Expression(object):
                     if p.is_case_or_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
+
+        self.recursive_resolve_tasks(module, parents)
                     
-- 
2.0.1



More information about the Xcb mailing list