[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 01/18] qapi-types.py: Implement 'base' for unions
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 01/18] qapi-types.py: Implement 'base' for unions |
Date: |
Fri, 26 Jul 2013 22:20:15 +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.
For example the following schema definition...
{ 'type': 'BlockOptionsBase', 'data': { 'read-only': 'bool' } }
{ 'union': 'BlockOptions',
'base': 'BlockOptionsBase',
'data': {
'raw': 'BlockOptionsRaw'
'qcow2': 'BlockOptionsQcow2'
} }
...would result in this generated C struct:
struct BlockOptions
{
BlockOptionsKind kind;
union {
void *data;
BlockOptionsRaw * raw;
BlockOptionsQcow2 * qcow2;
};
bool read_only;
};
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
scripts/qapi-types.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index ddcfed9..07bd311 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -150,7 +150,12 @@ typedef enum %(name)s
return lookup_decl + enum_decl
-def generate_union(name, typeinfo):
+def generate_union(expr):
+
+ name = expr['union']
+ typeinfo = expr['data']
+ base = expr.get('base')
+
ret = mcgen('''
struct %(name)s
{
@@ -169,6 +174,13 @@ struct %(name)s
ret += mcgen('''
};
+''')
+
+ if base:
+ struct = find_struct(base)
+ ret += generate_struct_fields(struct['data'])
+
+ ret += mcgen('''
};
''')
@@ -352,7 +364,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] [PULL 00/18] Block patches, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 01/18] qapi-types.py: Implement 'base' for unions,
Kevin Wolf <=
- [Qemu-devel] [PULL 02/18] qapi-visit.py: Split off generate_visit_struct_fields(), Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 03/18] qapi-visit.py: Implement 'base' for unions, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 04/18] docs: Document QAPI union types, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 05/18] qapi: Add visitor for implicit structs, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 06/18] qapi: Flat unions with arbitrary discriminator, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 07/18] qapi: Add consume argument to qmp_input_get_object(), Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 08/18] qapi.py: Maintain a list of union types, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 09/18] qapi: Anonymous unions, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 10/18] block: Allow "driver" option on the top level, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 11/18] QemuOpts: Add qemu_opt_unset(), Kevin Wolf, 2013/07/26