[Xcb] [PATCH libxcb 4/4] generator: support listelement-ref
Christian Linhart
chris at demorecorder.com
Thu Sep 4 08:50:51 PDT 2014
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
---
src/c_client.py | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/src/c_client.py b/src/c_client.py
index bd14959..fa0d2fc 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -1639,36 +1639,50 @@ def _c_accessor_get_expr(expr, field_mapping):
else:
_c_pre.code( "%s = %s;", listvar, list_name )
_c_pre.code(
"for ( %s = 0; %s < %s; %s++) {",
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" )
else:
_c_pre.code( "%s += *%s;", sumvar, listvar )
else:
#sumof has a nested expression which
#has to be evaluated in the context of this list element
#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()
#compute the subexpression
rhs_expr_str = _c_accessor_get_expr(expr.rhs, scoped_field_mapping)
#resume with our code
_c_pre.start()
@@ -1681,14 +1695,16 @@ def _c_accessor_get_expr(expr, field_mapping):
_c_pre.code( "%s++;", listvar );
_c_pre.pop_indent()
_c_pre.code( "}" )
_c_pre.code( "/* sumof end. Result is in %s */", sumvar )
_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 + ' ' +
_c_accessor_get_expr(expr.rhs, field_mapping) + ')')
elif expr.bitfield:
return 'xcb_popcount(' + lenexp + ')'
else:
--
2.0.1
More information about the Xcb
mailing list