mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
qapi: allow empty branches in flat unions
It often happens that just a few discriminator values imply extra data in a flat union. Existing checks did not make possible to leave other values uncovered. Such cases had to be worked around by either stating a dummy (empty) type or introducing another (subset) discriminator enumeration. Both options create redundant entities in qapi files for little profit. With this patch it is not necessary anymore to add designated union fields for every possible value of a discriminator enumeration. Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com> Message-Id: <1529311206-76847-2-git-send-email-anton.nefedov@virtuozzo.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
fe170d8bfa
commit
800877bb16
11 changed files with 35 additions and 30 deletions
|
@ -779,13 +779,6 @@ def check_union(expr, info):
|
|||
"enum '%s'"
|
||||
% (key, enum_define['enum']))
|
||||
|
||||
# If discriminator is user-defined, ensure all values are covered
|
||||
if enum_define:
|
||||
for value in enum_define['data']:
|
||||
if value not in members.keys():
|
||||
raise QAPISemError(info, "Union '%s' data missing '%s' branch"
|
||||
% (name, value))
|
||||
|
||||
|
||||
def check_alternate(expr, info):
|
||||
name = expr['alternate']
|
||||
|
@ -1357,6 +1350,14 @@ class QAPISchemaObjectTypeVariants(object):
|
|||
self.tag_member = seen[c_name(self._tag_name)]
|
||||
assert self._tag_name == self.tag_member.name
|
||||
assert isinstance(self.tag_member.type, QAPISchemaEnumType)
|
||||
if self._tag_name: # flat union
|
||||
# branches that are not explicitly covered get an empty type
|
||||
cases = set([v.name for v in self.variants])
|
||||
for val in self.tag_member.type.values:
|
||||
if val.name not in cases:
|
||||
v = QAPISchemaObjectTypeVariant(val.name, 'q_empty')
|
||||
v.set_owner(self.tag_member.owner)
|
||||
self.variants.append(v)
|
||||
for v in self.variants:
|
||||
v.check(schema)
|
||||
# Union names must match enum values; alternate names are
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue