generator: support listelement-ref PopcountList-V3
authorChristian Linhart <chris@demorecorder.com>
Thu, 4 Sep 2014 15:50:51 +0000 (17:50 +0200)
committerChristian Linhart <chris@demorecorder.com>
Tue, 9 Sep 2014 00:05:45 +0000 (02:05 +0200)
Support for listelement-ref needs the follwing 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

Message-ID: <1409845851-38950-4-git-send-email-chris@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: V1
Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
src/c_client.py

index 4db8d16..ae6bf87 100644 (file)
@@ -1643,6 +1643,19 @@ 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:
+            if needs_iterator:
+                _c_pre.code(
+                    "const %s *xcb_listelement = %s.data;",
+                    field.c_field_type, iteratorvar)
+            else:
+                _c_pre.code(
+                    "const %s *xcb_listelement = %s;",
+                    field.c_field_type, listvar)
+
+        # summation
         if expr.rhs == None:
             if needs_iterator:
                 _c_pre.code("TODO")
@@ -1655,16 +1668,17 @@ 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()
-            if needs_iterator:
-                scoped_field_mapping.update(
-                    _c_helper_field_mapping(
-                        field.type.member,
-                        [(iteratorvar + ".data", '', field.type.member)]))
-            else:
-                scoped_field_mapping.update(
-                    _c_helper_field_mapping(
-                        field.type.member,
-                        [(listvar, '', field.type.member)]))
+            if not field.type.member.is_simple:
+                if needs_iterator:
+                    scoped_field_mapping.update(
+                        _c_helper_field_mapping(
+                            field.type.member,
+                            [(iteratorvar + ".data", '', field.type.member)]))
+                else:
+                    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()
@@ -1685,6 +1699,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 + ' ' +