qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RFC 07/10] qapi script: support direct inheritance f


From: Wenchao Xia
Subject: [Qemu-devel] [PATCH RFC 07/10] qapi script: support direct inheritance for struct
Date: Tue, 5 Nov 2013 08:37:37 +0800

Now it is possible to inherit another struct inside data directly,
which saves trouble to define trivial structure.

Signed-off-by: Wenchao Xia <address@hidden>
---
 docs/qapi-code-gen.txt |   21 +++++++++++++++++++++
 scripts/qapi-visit.py  |   14 ++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index 0728f36..3e42ff4 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -70,6 +70,27 @@ both fields like this:
  { "file": "/some/place/my-image",
    "backing": "/some/place/my-backing-file" }
 
+It is possible to directly inherit other struct by keyword '_base':
+
+ { 'type': 'NetworkConnectionInfo', 'data': { 'host': 'str', 'service': 'str' 
} }
+ { 'type': 'VncConnectionInfo',
+   'data': {
+      'server': {
+          '_base': 'NetworkConnectionInfo',
+          '*auth': 'str' },
+      'client': 'NetworkConnectionInfo'
+      } }
+
+Result on the wire could be:
+
+{
+  "server": { "host": "192.168.1.1",
+              "service": "8080",
+              "auth': "none" },
+  "client": { "host": "192.168.1.2",
+              "service": "1223" }
+}
+
 === Enumeration types ===
 
 An enumeration type is a dictionary containing a single key whose value is a
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 2b13ad0..f0f0942 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -17,7 +17,7 @@ import os
 import getopt
 import errno
 
-def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base 
= None):
+def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base 
= None, base_name = 'base'):
     substructs = []
     ret = ''
     full_name = name if not fn_prefix else "%s_%s" % (name, fn_prefix)
@@ -30,8 +30,14 @@ def generate_visit_struct_fields(name, field_prefix, 
fn_prefix, members, base =
                 nested_fn_prefix = "%s_%s" % (fn_prefix, argname)
 
             nested_field_prefix = "%s%s." % (field_prefix, argname)
+
+            _base = argentry.get('_base')
+            if _base:
+                del argentry['_base']
+
             ret += generate_visit_struct_fields(name, nested_field_prefix,
-                                                nested_fn_prefix, argentry)
+                                                nested_fn_prefix, argentry,
+                                                _base, '_base')
 
     ret += mcgen('''
 
@@ -44,7 +50,7 @@ static void visit_type_%(full_name)s_fields(Visitor *m, 
%(name)s ** obj, Error *
 
     if base:
         ret += mcgen('''
-visit_start_implicit_struct(m, obj ? (void**) &(*obj)->%(c_name)s : NULL, 
sizeof(%(type)s), &err);
+visit_start_implicit_struct(m, obj ? (void**) &(*obj)->%(c_prefix)s%(c_name)s 
: NULL, sizeof(%(type)s), &err);
 if (!err) {
     visit_type_%(type)s_fields(m, obj ? &(*obj)->%(c_prefix)s%(c_name)s : 
NULL, &err);
     error_propagate(errp, err);
@@ -53,7 +59,7 @@ if (!err) {
 }
 ''',
                      c_prefix=c_var(field_prefix),
-                     type=type_name(base), c_name=c_var('base'))
+                     type=type_name(base), c_name=c_var(base_name))
 
     for argname, argentry, optional, structured in parse_args(members):
         if optional:
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]