summaryrefslogtreecommitdiff
path: root/scripts/qapi-types.py
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2013-07-03 15:58:57 +0200
committerKevin Wolf <kwolf@redhat.com>2013-07-26 21:09:37 +0200
commit50f2bdc75c5ee00617ad874c9ceac2cea660aa1e (patch)
tree331eee5391b95110ce3960b5623dcf8646f65e57 /scripts/qapi-types.py
parent761d524dbcc5bb41213dd0f238f43c273bc2b077 (diff)
downloadqemu-50f2bdc75c5ee00617ad874c9ceac2cea660aa1e.tar.gz
qapi: Flat unions with arbitrary discriminator
Instead of the rather verbose syntax that distinguishes base and subclass fields... { "type": "file", "read-only": true, "data": { "filename": "test" } } ...we can now have both in the same namespace, allowing a more direct mapping of the command line, and moving fields between the common base and subclasses without breaking the API: { "driver": "file", "read-only": true, "filename": "test" } Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi-types.py')
-rw-r--r--scripts/qapi-types.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 07bd311657..84d46fb863 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -154,7 +154,9 @@ def generate_union(expr):
name = expr['union']
typeinfo = expr['data']
+
base = expr.get('base')
+ discriminator = expr.get('discriminator')
ret = mcgen('''
struct %(name)s
@@ -177,8 +179,13 @@ struct %(name)s
''')
if base:
- struct = find_struct(base)
- ret += generate_struct_fields(struct['data'])
+ base_fields = find_struct(base)['data']
+ if discriminator:
+ base_fields = base_fields.copy()
+ del base_fields[discriminator]
+ ret += generate_struct_fields(base_fields)
+ else:
+ assert not discriminator
ret += mcgen('''
};