mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-07-08 15:30:48 +00:00
qapi: Forbid base without discriminator in unions
None of the existing QMP or QGA interfaces uses a union with a base type but no discriminator; it is easier to avoid this in the generator to save room for other future extensions more likely to be useful. An earlier commit added a union-base-no-discriminator test to ensure that we eventually give a decent error message; likewise, removing UserDefUnion outright is okay, because we moved all the tests we wish to keep into the tests of the simple union UserDefNativeListUnion in the previous commit. Now is the time to actually forbid simple union with base, and remove the last vestiges from the testsuite. Backports commit a8d4a2e4d7e1a0207699de47142c9bdbf2cc8675 from qemu
This commit is contained in:
parent
d8f8b1925c
commit
8023795233
|
@ -231,10 +231,9 @@ struct %(name)s
|
||||||
''')
|
''')
|
||||||
|
|
||||||
if base:
|
if base:
|
||||||
base_fields = find_struct(base)['data']
|
assert discriminator
|
||||||
if discriminator:
|
base_fields = find_struct(base)['data'].copy()
|
||||||
base_fields = base_fields.copy()
|
del base_fields[discriminator]
|
||||||
del base_fields[discriminator]
|
|
||||||
ret += generate_struct_fields(base_fields)
|
ret += generate_struct_fields(base_fields)
|
||||||
else:
|
else:
|
||||||
assert not discriminator
|
assert not discriminator
|
||||||
|
|
|
@ -310,16 +310,15 @@ def generate_visit_union(expr):
|
||||||
ret = ""
|
ret = ""
|
||||||
disc_type = enum_define['enum_name']
|
disc_type = enum_define['enum_name']
|
||||||
else:
|
else:
|
||||||
# There will always be a discriminator in the C switch code, by default it
|
# There will always be a discriminator in the C switch code, by default
|
||||||
# is an enum type generated silently as "'%sKind' % (name)"
|
# it is an enum type generated silently as "'%sKind' % (name)"
|
||||||
ret = generate_visit_enum('%sKind' % name, members.keys())
|
ret = generate_visit_enum('%sKind' % name, members.keys())
|
||||||
disc_type = '%sKind' % (name)
|
disc_type = '%sKind' % (name)
|
||||||
|
|
||||||
if base:
|
if base:
|
||||||
base_fields = find_struct(base)['data']
|
assert discriminator
|
||||||
if discriminator:
|
base_fields = find_struct(base)['data'].copy()
|
||||||
base_fields = base_fields.copy()
|
del base_fields[discriminator]
|
||||||
del base_fields[discriminator]
|
|
||||||
ret += generate_visit_struct_fields(name, "", "", base_fields)
|
ret += generate_visit_struct_fields(name, "", "", base_fields)
|
||||||
|
|
||||||
if discriminator:
|
if discriminator:
|
||||||
|
|
|
@ -259,22 +259,22 @@ def check_union(expr, expr_info):
|
||||||
discriminator = expr.get('discriminator')
|
discriminator = expr.get('discriminator')
|
||||||
members = expr['data']
|
members = expr['data']
|
||||||
|
|
||||||
# If the object has a member 'base', its value must name a complex type.
|
# If the object has a member 'base', its value must name a complex type,
|
||||||
if base:
|
# and there must be a discriminator.
|
||||||
|
if base is not None:
|
||||||
|
if discriminator is None:
|
||||||
|
raise QAPIExprError(expr_info,
|
||||||
|
"Union '%s' requires a discriminator to go "
|
||||||
|
"along with base" %name)
|
||||||
base_fields = find_base_fields(base)
|
base_fields = find_base_fields(base)
|
||||||
if not base_fields:
|
if not base_fields:
|
||||||
raise QAPIExprError(expr_info,
|
raise QAPIExprError(expr_info,
|
||||||
"Base '%s' is not a valid type"
|
"Base '%s' is not a valid type"
|
||||||
% base)
|
% base)
|
||||||
|
|
||||||
# If the union object has no member 'discriminator', it's an
|
# If the union object has no member 'discriminator', it's a
|
||||||
# ordinary union.
|
# simple union. If 'discriminator' is {}, it is an anonymous union.
|
||||||
if not discriminator:
|
if not discriminator or discriminator == {}:
|
||||||
enum_define = None
|
|
||||||
|
|
||||||
# Else if the value of member 'discriminator' is {}, it's an
|
|
||||||
# anonymous union.
|
|
||||||
elif discriminator == {}:
|
|
||||||
enum_define = None
|
enum_define = None
|
||||||
|
|
||||||
# Else, it's a flat union.
|
# Else, it's a flat union.
|
||||||
|
|
Loading…
Reference in a new issue