[Xcb] [PATCH libxcb 1/6] generator: fix absname for fields with only accessor function

Christian Linhart chris at demorecorder.com
Wed Sep 3 04:22:36 PDT 2014


Fix _c_helper_absolute_name for fields which cannot be accessed
as a struct/union member but which can be accessed by an
accessor function.

The fix calls the accessor function in these cases.

Example:
<struct name="AbsnameTest">
   <field type="CARD32" name="len" />
   <list type="CARD8" name="mylist1">
       <fieldref>len</fieldref>
   </list>
   <list type="CARD8" name="mylist2">
       <sumof ref="mylist1"/>
   </list>
</struct>

The sumof-expression ( <sumof ref="mylist1"/> ) refers to mylist1
which is only acessible by an accessor function.

Previously, sumof was only used inside bitcases,
where such lists are accessible by members of the
deserialized parent struct.
(there is a difference between deserialization of switches
and structs.)
---
 src/c_client.py | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/c_client.py b/src/c_client.py
index 9216c7f..488f0e6 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -430,24 +430,50 @@ def _c_type_setup(self, name, postfix):
 def _c_helper_absolute_name(prefix, field=None):
     """
     turn prefix, which is a list of tuples (name, separator, Type obj) into a string
     representing a valid name in C (based on the context)
     if field is not None, append the field name as well
     """
     prefix_str = ''
+    last_sep =''
     for name, sep, obj in prefix:
+        if '' != last_sep:
+            prefix_str += last_sep
         prefix_str += name
         if '' == sep:
             sep = '->'
             if ((obj.is_case_or_bitcase and obj.has_name) or     # named bitcase
                 (obj.is_switch and len(obj.parents)>1)):
                 sep = '.'
-        prefix_str += sep
+        last_sep = sep
+
+    prefix_str_without_lastsep = prefix_str
+    prefix_str += last_sep
+
     if field is not None:
         prefix_str += _cpp(field.field_name)
+
+
+    if (
+        field != None
+        and hasattr(field, 'c_accessor_name')
+        and field.parent != None
+        and field.parent.is_container
+        and not field.parent.is_switch
+        and not field.parent.is_case_or_bitcase
+        and ( #the following conditions are taken from _c_accessors()
+                ( field.type.is_list and not field.type.fixed_size() )
+                or
+                ( field.prev_varsized_field is not None
+                  or not field.type.fixed_size()
+                )
+        )
+    ):
+        prefix_str = field.c_accessor_name + "(" + prefix_str_without_lastsep + ")";
+
     return prefix_str
 # _c_absolute_name
 
 def _c_helper_field_mapping(complex_type, prefix, flat=False):
     """
     generate absolute names, based on prefix, for all fields starting from complex_type
     if flat == True, nested complex types are not taken into account
-- 
2.0.1



More information about the Xcb mailing list