xcbgen: new expr-type listelement-ref
authorChristian Linhart <chris@demorecorder.com>
Thu, 4 Sep 2014 15:48:56 +0000 (17:48 +0200)
committerChristian Linhart <chris@demorecorder.com>
Mon, 3 Nov 2014 10:23:23 +0000 (11:23 +0100)
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)

Message-ID: <1409845742-38797-2-git-send-email-chris@demorecorder.com>
Patch-Thread-Subject: [Xcb] support popcount of a list and associated xml changes
Patch-Set: PopcountList
Patch-Number: proto 2/8
Patch-Version: V1
Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
xcbgen/expr.py

index a03703f..f3bf462 100644 (file)
@@ -53,6 +53,8 @@ class Expression(object):
         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'
@@ -111,6 +113,11 @@ class Expression(object):
                 # 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)
@@ -118,6 +125,12 @@ class Expression(object):
     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])
@@ -134,4 +147,6 @@ class Expression(object):
                         self.lenfield_parent = p
                     self.lenfield_type = fields[self.lenfield_name].field_type
                     break
+
+        self.recursive_resolve_tasks(module, parents)