[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 03/18] qapi-visit.py: Implement 'base' for unions
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 03/18] qapi-visit.py: Implement 'base' for unions |
Date: |
Fri, 26 Jul 2013 22:20:17 +0200 |
This implements the visitor part of base types for unions. Parsed into
QMP, this example schema definition...
{ 'type': 'BlockOptionsBase', 'data': { 'read-only': 'bool' } }
{ 'type': 'BlockOptionsQcow2, 'data': { 'lazy-refcounts': 'bool' } }
{ 'union': 'BlockOptions',
'base': 'BlockOptionsBase',
'data': {
'raw': 'BlockOptionsRaw'
'qcow2': 'BlockOptionsQcow2'
} }
...would describe the following JSON object:
{ "type": "qcow2",
"read-only": true,
"data": { "lazy-refcounts": false } }
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
scripts/qapi-visit.py | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index a337d80..db6fa44 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -151,7 +151,13 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const
char *name, Error **e
''',
name=name)
-def generate_visit_union(name, members):
+def generate_visit_union(expr):
+
+ name = expr['union']
+ members = expr['data']
+
+ base = expr.get('base')
+
ret = generate_visit_enum('%sKind' % name, members.keys())
ret += mcgen('''
@@ -164,14 +170,28 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj,
const char *name, Error **
visit_start_struct(m, (void **)obj, "%(name)s", name,
sizeof(%(name)s), &err);
if (!err) {
if (obj && *obj) {
- visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err);
- if (!err) {
- switch ((*obj)->kind) {
''',
name=name)
+
push_indent()
push_indent()
+ push_indent()
+
+ if base:
+ struct = find_struct(base)
+ push_indent()
+ ret += generate_visit_struct_fields("", struct['data'])
+ pop_indent()
+
+ pop_indent()
+ ret += mcgen('''
+ visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err);
+ if (!err) {
+ switch ((*obj)->kind) {
+''',
+ name=name)
+
for key in members:
ret += mcgen('''
case %(abbrev)s_KIND_%(enum)s:
@@ -368,7 +388,7 @@ for expr in exprs:
ret = generate_declaration(expr['type'], expr['data'])
fdecl.write(ret)
elif expr.has_key('union'):
- ret = generate_visit_union(expr['union'], expr['data'])
+ ret = generate_visit_union(expr)
ret += generate_visit_list(expr['union'], expr['data'])
fdef.write(ret)
--
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, 2013/07/26
- [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 <=
- [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
- [Qemu-devel] [PULL 12/18] blockdev: Rename I/O throttling options for QMP, Kevin Wolf, 2013/07/26
- [Qemu-devel] [PULL 13/18] qcow2: Use dashes instead of underscores in options, Kevin Wolf, 2013/07/26