generator: support listelement-ref PopcountList-V5
authorChristian Linhart <chris@DemoRecorder.com>
Mon, 20 Oct 2014 10:17:51 +0000 (12:17 +0200)
committerChristian Linhart <chris@demorecorder.com>
Mon, 20 Oct 2014 10:21:22 +0000 (12:21 +0200)
Support for listelement-ref needs the following three changes
(in the order as they appear in the patch):

* making the current list-element accessible with the variable
  xcb_listelement which is a pointer to the list-element

* supporting lists of simple-type for sumof with a nested expression

* using the variable for resolving a listelement-ref expression

Changes for V2 of this patch:
- adapt to removal of patch "libxcb 2/6" from patchset "ListInputDevices".

Message-ID: <5444E14F.4050807@DemoRecorder.com>
Patch-Thread-Subject: [Xcb] support popcount of a list and associated xml changes
Patch-Set: PopcountList
Patch-Number: libxcb 4/4
Patch-Version: V2
Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
src/c_client.py

index c9a9b81..884cbe1 100644 (file)
@@ -1628,6 +1628,14 @@ def _c_accessor_get_expr(expr, field_mapping):
            loopvar, loopvar, lengthvar, loopvar)
         _c_pre.indent()
 
+        # define and set xcb_listelement, so that it can be used by
+        # listelement-ref expressions.
+        if expr.contains_listelement_ref:
+            _c_pre.code(
+                "const %s *xcb_listelement = %s;",
+                field.c_field_type, listvar)
+
+        # summation
         if expr.rhs == None:
             _c_pre.code("%s += *%s;", sumvar, listvar)
         else:
@@ -1637,10 +1645,11 @@ def _c_accessor_get_expr(expr, field_mapping):
             # field mapping for the subexpression needs to include
             # the fields of the list-member type
             scoped_field_mapping = field_mapping.copy()
-            scoped_field_mapping.update(
-                _c_helper_field_mapping(
-                    field.type.member,
-                    [(listvar, '', field.type.member)]))
+            if not field.type.member.is_simple:
+                scoped_field_mapping.update(
+                    _c_helper_field_mapping(
+                        field.type.member,
+                        [(listvar, '', field.type.member)]))
 
             # cause pre-code of the subexpression be added right here
             _c_pre.end()
@@ -1658,6 +1667,8 @@ def _c_accessor_get_expr(expr, field_mapping):
         _c_pre.end()
         return sumvar;
         # return 'xcb_sumof(%s, %s)' % (list_name, c_length_func)
+    elif expr.op == 'listelement-ref':
+        return '(*xcb_listelement)';
     elif expr.op != None:
         return ('(' + _c_accessor_get_expr(expr.lhs, field_mapping) +
                 ' ' + expr.op + ' ' +