mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-03-08 10:09:43 +00:00
qapi: Reuse code for flat union base validation
Rather than open-code the check for a valid base type, we should reuse the common functionality. This allows for consistent error messages, and also makes it easier for a later patch to turn on support for inline anonymous base structures. Test flat-union-inline is updated to test only one feature (anonymous branch dictionaries), which can be implemented independently (test flat-union-bad-base already covers the idea of an anonymous base dictionary). Backports commit 376863ef4895ae709aadb6f26365a5973310ef09 from qemu
This commit is contained in:
parent
c09db972fe
commit
4294815ee3
|
@ -557,15 +557,15 @@ def check_union(expr, expr_info):
|
|||
# Else, it's a flat union.
|
||||
else:
|
||||
# The object must have a string member 'base'.
|
||||
if not isinstance(base, str):
|
||||
check_type(expr_info, "'base' for union '%s'" % name,
|
||||
base, allow_metas=['struct'])
|
||||
if not base:
|
||||
raise QAPIExprError(expr_info,
|
||||
"Flat union '%s' must have a string base field"
|
||||
"Flat union '%s' must have a base"
|
||||
% name)
|
||||
base_fields = find_base_fields(base)
|
||||
if not base_fields:
|
||||
raise QAPIExprError(expr_info,
|
||||
"Base '%s' is not a valid struct"
|
||||
% base)
|
||||
assert base_fields
|
||||
|
||||
# The value of member 'discriminator' must name a non-optional
|
||||
# member of the base struct.
|
||||
check_name(expr_info, "Discriminator of flat union '%s'" % name,
|
||||
|
|
Loading…
Reference in a new issue