xcbgen: sumof with nested expression
[free-sw/xcb/proto] / xcbgen / expr.py
index f9d5179..a03703f 100644 (file)
@@ -22,6 +22,7 @@ class Field(object):
         self.wire = wire
         self.auto = auto
         self.isfd = isfd
+        self.parent = None
 
 
 class Expression(object):
@@ -103,6 +104,12 @@ class Expression(object):
         elif elt.tag == 'sumof':
             self.op = 'sumof'
             self.lenfield_name = elt.get('ref')
+            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)
 
         else:
             # Notreached
@@ -120,7 +127,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: