[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 02/11] qapi-types.py: Implement 'base' for union
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [RFC PATCH 02/11] qapi-types.py: Implement 'base' for unions |
Date: |
Tue, 9 Jul 2013 11:53:28 +0200 |
The new 'base' key in a union definition refers to a struct type, which
is inlined into the union definition and can represent fields common to
all kinds.
Signed-off-by: Kevin Wolf <address@hidden>
---
scripts/qapi-types.py | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index e1239e1..960065b 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -157,7 +157,16 @@ typedef enum %(name)s
return lookup_decl + enum_decl
-def generate_union(name, typeinfo):
+def generate_union(expr):
+
+ name = expr['union']
+ typeinfo = expr['data']
+
+ if expr.has_key('base'):
+ base = expr['base']
+ else:
+ base = None
+
ret = mcgen('''
struct %(name)s
{
@@ -176,6 +185,13 @@ struct %(name)s
ret += mcgen('''
};
+''')
+
+ if base:
+ struct = find_struct(base)
+ ret += generate_struct_fields(struct['data'])
+
+ ret += mcgen('''
};
''')
@@ -359,7 +375,7 @@ for expr in exprs:
ret += generate_type_cleanup_decl(expr['type'])
fdef.write(generate_type_cleanup(expr['type']) + "\n")
elif expr.has_key('union'):
- ret += generate_union(expr['union'], expr['data'])
+ ret += generate_union(expr)
ret += generate_type_cleanup_decl(expr['union'] + "List")
fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
ret += generate_type_cleanup_decl(expr['union'])
--
1.8.1.4
- [Qemu-devel] [RFC PATCH 00/11] qapi changes in preparation for blockdev-add, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 01/11] qapi-types.py: Split off generate_struct_fields(), Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 03/11] qapi-visit.py: Split off generate_visit_struct_fields(), Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 04/11] qapi-visit.py: Implement 'base' for unions, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 02/11] qapi-types.py: Implement 'base' for unions,
Kevin Wolf <=
- [Qemu-devel] [RFC PATCH 05/11] qapi: Add visitor for implicit structs, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 06/11] qapi: Flat unions with arbitrary discriminator, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 09/11] Implement qdict_flatten(), Kevin Wolf, 2013/07/09