# recurse into this field this has to be done here, i.e.,
# after the field has been set up. Otherwise the function
- # _c_helper_absolute_name will produce garbage or crash
+ # _c_helper_fieldaccess_expr will produce garbage or crash
_c_type_setup(field.type, field.field_type, ())
if field.type.is_list:
_c_type_setup(field.type.member, field.field_type, ())
def _c_field_is_member_of_case_or_bitcase(field):
return field.parent and field.parent.is_case_or_bitcase
-def _c_helper_absolute_name(prefix, field=None):
+def _c_helper_fieldaccess_expr(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
+ representing a valid field-access-expression in C (based on the context)
+ if field is not None, append access to the field as well.
+
+ "separator" is one of the C-operators "." or "->".
+
+ A field access expression can consist of the following components:
+ * struct/union member access from a value with the "."-operator
+ * struct/union member access from a pointer with "->"-operator
+ * function-call of an accessor function:
+ This is used when a xcb-field is not contained in a struct.
+ This can, e.g., happen for fields after var-sized fields, etc.
"""
prefix_str = ''
last_sep =''
for name, sep, obj in prefix:
prefix_str += last_sep + 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 = '.'
last_sep = sep
if field is None:
all_fields.update(_c_helper_field_mapping(b.type, bitcase_prefix, flat))
else:
for f in complex_type.fields:
- fname = _c_helper_absolute_name(prefix, f)
+ fname = _c_helper_fieldaccess_expr(prefix, f)
if f.field_name in all_fields:
raise Exception("field name %s has been registered before" % f.field_name)
# switch is handled by this function as a special case
param_fields, wire_fields, params = get_serialize_params(context, self)
field_mapping = _c_helper_field_mapping(self, prefix)
- prefix_str = _c_helper_absolute_name(prefix)
+ prefix_str = _c_helper_fieldaccess_expr(prefix)
# find the parameters that need to be passed to _serialize()/_unpack():
# all switch expr fields must be given as parameters
helper function to cope with lists of variable length
"""
expr = field.type.expr
- prefix_str = _c_helper_absolute_name(prefix)
+ prefix_str = _c_helper_fieldaccess_expr(prefix)
param_fields, wire_fields, params = get_serialize_params('sizeof', self)
param_names = [p[2] for p in params]
typename = reduce(lambda x,y: "%s.%s" % (x, y), scoped_name)
code_lines.append('%s /* %s.%s */' % (space, typename, field.c_field_name))
- abs_field_name = _c_helper_absolute_name(prefix, field)
+ abs_field_name = _c_helper_fieldaccess_expr(prefix, field)
# default for simple cases: call sizeof()
length = "sizeof(%s)" % field.c_field_type
def _c_serialize_helper_fields_variable_size(context, self, field,
code_lines, temp_vars,
space, prefix):
- prefix_str = _c_helper_absolute_name(prefix)
+ prefix_str = _c_helper_fieldaccess_expr(prefix)
if context in ('unserialize', 'unpack', 'sizeof'):
value = ''
force_packed = any(f.type.size == 8 and f.type.is_simple for f in self.fields[(idx+1):])
break
- _c_type_setup(self, name, ('event',))
+ if self.name == name:
+ _c_type_setup(self, name, ('event',))
+ else:
+ # no type-setup needed for eventcopies
+ # (the type-setup of an eventcopy would overwrite members of the original
+ # event, and it would create sizeof-etc funtions which
+ # called undefined accessor functions)
+ pass
# Opcode define
_c_opcode(name, self.opcodes[name])
_h('')
_h('typedef %s %s;', _t(self.name + ('event',)), _t(name + ('event',)))
+ # Create sizeof-function for eventcopies for compatibility reasons
+ if self.c_need_sizeof:
+ _h_setlevel(1)
+ _c_setlevel(1)
+ _h('')
+ _h('int')
+ _h('%s (const void *_buffer /**< */);', _n(name + ('sizeof',)))
+ _c('')
+ _c('int')
+ _c('%s (const void *_buffer /**< */)', _n(name + ('sizeof',)))
+ _c('{');
+ _c(' return %s(_buffer);', _n(self.name + ('sizeof',)))
+ _c('}');
+ _h_setlevel(0)
+ _c_setlevel(0)
+
_man_event(self, name)
def c_error(self, name):