cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From f1567daa732a9f61641e6089525db0ae7f75aa06 Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Mon, 9 Sep 2013 14:28:09 +0200
218e99
Subject: [PATCH 18/38] qapi-visit.py: Implement 'base' for unions
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1378736903-18489-19-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 54205
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 18/32] qapi-visit.py: Implement 'base' for unions
218e99
Bugzilla: 1005818
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
Bugzilla: 1005818
218e99
218e99
This implements the visitor part of base types for unions. Parsed into
218e99
QMP, this example schema definition...
218e99
218e99
    { 'type': 'BlockOptionsBase', 'data': { 'read-only': 'bool' } }
218e99
    { 'type': 'BlockOptionsQcow2, 'data': { 'lazy-refcounts': 'bool' } }
218e99
218e99
    { 'union': 'BlockOptions',
218e99
      'base': 'BlockOptionsBase',
218e99
      'data': {
218e99
          'raw': 'BlockOptionsRaw'
218e99
          'qcow2': 'BlockOptionsQcow2'
218e99
      } }
218e99
218e99
...would describe the following JSON object:
218e99
218e99
    { "type": "qcow2",
218e99
      "read-only": true,
218e99
      "data": { "lazy-refcounts": false } }
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit 0aef92b90d24858eea1ebd52a51bc31563f1fb52)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 scripts/qapi-visit.py | 30 +++++++++++++++++++++++++-----
218e99
 1 file changed, 25 insertions(+), 5 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 scripts/qapi-visit.py |   30 +++++++++++++++++++++++++-----
218e99
 1 files changed, 25 insertions(+), 5 deletions(-)
218e99
218e99
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
218e99
index 5adc2af..be56ba4 100644
218e99
--- a/scripts/qapi-visit.py
218e99
+++ b/scripts/qapi-visit.py
218e99
@@ -151,7 +151,13 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **e
218e99
 ''',
218e99
                  name=name)
218e99
 
218e99
-def generate_visit_union(name, members):
218e99
+def generate_visit_union(expr):
218e99
+
218e99
+    name = expr['union']
218e99
+    members = expr['data']
218e99
+
218e99
+    base = expr.get('base')
218e99
+
218e99
     ret = generate_visit_enum('%sKind' % name, members.keys())
218e99
 
218e99
     ret += mcgen('''
218e99
@@ -164,14 +170,28 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
218e99
         visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err;;
218e99
         if (!err) {
218e99
             if (obj && *obj) {
218e99
-                visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err;;
218e99
-                if (!err) {
218e99
-                    switch ((*obj)->kind) {
218e99
 ''',
218e99
                  name=name)
218e99
 
218e99
+
218e99
     push_indent()
218e99
     push_indent()
218e99
+    push_indent()
218e99
+
218e99
+    if base:
218e99
+        struct = find_struct(base)
218e99
+        push_indent()
218e99
+        ret += generate_visit_struct_fields("", struct['data'])
218e99
+        pop_indent()
218e99
+
218e99
+    pop_indent()
218e99
+    ret += mcgen('''
218e99
+        visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err;;
218e99
+        if (!err) {
218e99
+            switch ((*obj)->kind) {
218e99
+''',
218e99
+                 name=name)
218e99
+
218e99
     for key in members:
218e99
         ret += mcgen('''
218e99
             case %(abbrev)s_KIND_%(enum)s:
218e99
@@ -344,7 +364,7 @@ for expr in exprs:
218e99
         ret = generate_declaration(expr['type'], expr['data'])
218e99
         fdecl.write(ret)
218e99
     elif expr.has_key('union'):
218e99
-        ret = generate_visit_union(expr['union'], expr['data'])
218e99
+        ret = generate_visit_union(expr)
218e99
         ret += generate_visit_list(expr['union'], expr['data'])
218e99
         fdef.write(ret)
218e99
 
218e99
-- 
218e99
1.7.1
218e99