|
|
9ae3a8 |
From da3719ca3f47e716394f3a572f0f1403518a8442 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 9 Sep 2013 14:28:07 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 16/38] qapi-types.py: Implement 'base' for unions
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1378736903-18489-17-git-send-email-kwolf@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 54203
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 16/32] qapi-types.py: Implement 'base' for unions
|
|
|
9ae3a8 |
Bugzilla: 1005818
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Bugzilla: 1005818
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
The new 'base' key in a union definition refers to a struct type, which
|
|
|
9ae3a8 |
is inlined into the union definition and can represent fields common to
|
|
|
9ae3a8 |
all kinds.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
For example the following schema definition...
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
{ 'type': 'BlockOptionsBase', 'data': { 'read-only': 'bool' } }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
{ 'union': 'BlockOptions',
|
|
|
9ae3a8 |
'base': 'BlockOptionsBase',
|
|
|
9ae3a8 |
'data': {
|
|
|
9ae3a8 |
'raw': 'BlockOptionsRaw'
|
|
|
9ae3a8 |
'qcow2': 'BlockOptionsQcow2'
|
|
|
9ae3a8 |
} }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
...would result in this generated C struct:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
struct BlockOptions
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
BlockOptionsKind kind;
|
|
|
9ae3a8 |
union {
|
|
|
9ae3a8 |
void *data;
|
|
|
9ae3a8 |
BlockOptionsRaw * raw;
|
|
|
9ae3a8 |
BlockOptionsQcow2 * qcow2;
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
bool read_only;
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit e2503f5e213e30e3e9a397d454a35c10b5bdc899)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
scripts/qapi-types.py | 16 ++++++++++++++--
|
|
|
9ae3a8 |
1 file changed, 14 insertions(+), 2 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
scripts/qapi-types.py | 16 ++++++++++++++--
|
|
|
9ae3a8 |
1 files changed, 14 insertions(+), 2 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
|
|
|
9ae3a8 |
index 9e19920..c0684a7 100644
|
|
|
9ae3a8 |
--- a/scripts/qapi-types.py
|
|
|
9ae3a8 |
+++ b/scripts/qapi-types.py
|
|
|
9ae3a8 |
@@ -131,7 +131,12 @@ typedef enum %(name)s
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
return lookup_decl + enum_decl
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-def generate_union(name, typeinfo):
|
|
|
9ae3a8 |
+def generate_union(expr):
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ name = expr['union']
|
|
|
9ae3a8 |
+ typeinfo = expr['data']
|
|
|
9ae3a8 |
+ base = expr.get('base')
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
ret = mcgen('''
|
|
|
9ae3a8 |
struct %(name)s
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
@@ -150,6 +155,13 @@ struct %(name)s
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ret += mcgen('''
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
+''')
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if base:
|
|
|
9ae3a8 |
+ struct = find_struct(base)
|
|
|
9ae3a8 |
+ ret += generate_struct_fields(struct['data'])
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ ret += mcgen('''
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
''')
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -307,7 +319,7 @@ for expr in exprs:
|
|
|
9ae3a8 |
ret += generate_type_cleanup_decl(expr['type'])
|
|
|
9ae3a8 |
fdef.write(generate_type_cleanup(expr['type']) + "\n")
|
|
|
9ae3a8 |
elif expr.has_key('union'):
|
|
|
9ae3a8 |
- ret += generate_union(expr['union'], expr['data'])
|
|
|
9ae3a8 |
+ ret += generate_union(expr)
|
|
|
9ae3a8 |
ret += generate_type_cleanup_decl(expr['union'] + "List")
|
|
|
9ae3a8 |
fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
|
|
|
9ae3a8 |
ret += generate_type_cleanup_decl(expr['union'])
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|