Merge branch 'xkb-explicit' into 'master'

c_client.py: update to handle explicit cpp keyword

See merge request xorg/lib/libxcb!73
This commit is contained in:
Will Song 2025-11-08 05:03:14 -05:00
commit 767aa783c0

View file

@ -21,6 +21,7 @@ _cplusplus_annoyances = {'class' : '_class',
'new' : '_new',
'delete': '_delete'}
_c_keywords = {'default' : '_default'}
_cplusplus_renamed_keywords = {'explicit': '_explicit'}
_hlines = []
_hlevel = 0
@ -203,6 +204,15 @@ def _cpp(str):
else:
return str
def _cpp_rename(str):
'''
Checks for additional C++ reserved words and fixes them.
'''
if str in _cplusplus_renamed_keywords:
return _cplusplus_renamed_keywords[str]
else:
return None
def _ext(str):
'''
Does C-name conversion on an extension name.
@ -426,11 +436,11 @@ def _c_type_setup(self, name, postfix):
self.c_container = 'struct'
for bitcase in self.bitcases:
bitcase.c_field_name = _cpp(bitcase.field_name)
bitcase.cpp_field_rename = _cpp_rename(bitcase.field_name)
bitcase_name = bitcase.field_type if bitcase.type.has_name else name
_c_type_setup(bitcase.type, bitcase_name, ())
elif self.is_container:
self.c_container = 'union' if self.is_union else 'struct'
prev_varsized_field = None
prev_varsized_offset = 0
@ -444,6 +454,7 @@ def _c_type_setup(self, name, postfix):
field.c_field_const_type = ('' if field.type.nmemb == 1 else 'const ') + field.c_field_type
field.c_field_name = _cpp(field.field_name)
field.cpp_field_rename = _cpp_rename(field.field_name)
field.c_subscript = '[%d]' % field.type.nmemb if (field.type.nmemb and field.type.nmemb > 1) else ''
field.c_pointer = ' ' if field.type.nmemb == 1 else '*'
@ -617,7 +628,7 @@ def _c_helper_field_mapping(complex_type, prefix, flat=False):
if f.field_name in all_fields:
raise Exception("field name %s has been registered before" % f.field_name)
all_fields[f.field_name] = (fname, f)
all_fields[f.c_field_name] = (fname, f)
if f.type.is_container and not flat:
if f.type.is_case_or_bitcase and not f.type.has_name:
new_prefix = prefix
@ -2139,16 +2150,25 @@ def _c_complex(self, force_packed = False):
maxtypelen = max(maxtypelen, length)
def _c_complex_field(self, field, space=''):
if (field.type.fixed_size() or self.is_union or
# in case of switch with switch children, don't make the field a pointer
# necessary for unserialize to work
(self.is_switch and field.type.is_switch)):
spacing = ' ' * (maxtypelen - len(field.c_field_type))
_h('%s %s%s %s%s;', space, field.c_field_type, spacing, field.c_field_name, field.c_subscript)
elif (not field.type.is_pad) or field.type.serialize:
# serialize everything except pads (unless serialization of pads is enforced by serialize=true)
spacing = ' ' * (maxtypelen - (len(field.c_field_type) + 1))
_h('%s %s%s *%s%s;', space, field.c_field_type, spacing, field.c_field_name, field.c_subscript)
def _serialize_core(field_name):
if (field.type.fixed_size() or self.is_union or
# in case of switch with switch children, don't make the field a pointer
# necessary for unserialize to work
(self.is_switch and field.type.is_switch)):
spacing = ' ' * (maxtypelen - len(field.c_field_type))
_h('%s %s%s %s%s;', space, field.c_field_type, spacing, field_name, field.c_subscript)
elif (not field.type.is_pad) or field.type.serialize:
# serialize everything except pads (unless serialization of pads is enforced by serialize=true)
spacing = ' ' * (maxtypelen - (len(field.c_field_type) + 1))
_h('%s %s%s *%s%s;', space, field.c_field_type, spacing, field_name, field.c_subscript)
if field.cpp_field_rename != None:
_h('#if defined(XCB_AVOID_CXX_KEYWORDS) && (defined(__cplusplus) || defined(c_plusplus))')
_serialize_core(field.cpp_field_rename)
_h('#else')
_serialize_core(field.c_field_name)
_h('#endif')
else:
_serialize_core(field.c_field_name)
if not self.is_switch:
for field in struct_fields: