qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v8 15/26] qapi-commands: Rearrange code
Date: Wed, 16 Sep 2015 13:06:18 +0200	[thread overview]
Message-ID: <1442401589-24189-16-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1442401589-24189-1-git-send-email-armbru@redhat.com>

Rename gen_marshal_input() to gen_marshal(), because the generated
function marshals both arguments and results.

Rename gen_visitor_input_containers_decl() to gen_marshal_vars(), and
move the other variable declarations there, too.

Rename gen_visitor_input_block() to gen_marshal_input_visit(), and
rearrange its code slightly.

Rename gen_marshal_input_decl() to gen_marshal_proto(), because the
result isn't a full declaration, unlike gen_command_decl()'s.

New gen_marshal_decl() actually returns a full declaration.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
---
 scripts/qapi-commands.py | 87 ++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 48 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 0501582..6a52c88 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -59,6 +59,7 @@ def gen_call(name, arg_type, ret_type):
 
     push_indent()
     ret = mcgen('''
+
 %(lhs)sqmp_%(c_name)s(%(args)s&local_err);
 ''',
                 c_name=c_name(name), args=argstr, lhs=lhs)
@@ -73,26 +74,26 @@ qmp_marshal_output_%(c_name)s(retval, ret, &local_err);
     return ret
 
 
-def gen_visitor_input_containers_decl(arg_type):
-    ret = ''
+def gen_marshal_vars(arg_type, ret_type):
+    ret = mcgen('''
+    Error *local_err = NULL;
+''')
 
     push_indent()
+
+    if ret_type:
+        ret += mcgen('''
+%(c_type)s retval;
+''',
+                     c_type=ret_type.c_type())
+
     if arg_type:
         ret += mcgen('''
 QmpInputVisitor *mi = qmp_input_visitor_new_strict(QOBJECT(args));
 QapiDeallocVisitor *md;
 Visitor *v;
 ''')
-    pop_indent()
 
-    return ret
-
-
-def gen_visitor_input_vars_decl(arg_type):
-    ret = ''
-    push_indent()
-
-    if arg_type:
         for memb in arg_type.members:
             if memb.optional:
                 ret += mcgen('''
@@ -105,15 +106,19 @@ bool has_%(c_name)s = false;
                          c_name=c_name(memb.name),
                          c_type=memb.type.c_type(),
                          c_null=memb.type.c_null())
+        ret += '\n'
+    else:
+        ret += mcgen('''
+
+(void)args;
+''')
 
     pop_indent()
     return ret
 
 
-def gen_visitor_input_block(arg_type, dealloc=False):
+def gen_marshal_input_visit(arg_type, dealloc=False):
     ret = ''
-    errparg = '&local_err'
-    errarg = 'local_err'
 
     if not arg_type:
         return ret
@@ -129,6 +134,8 @@ md = qapi_dealloc_visitor_new();
 v = qapi_dealloc_get_visitor(md);
 ''')
     else:
+        errparg = '&local_err'
+        errarg = 'local_err'
         ret += mcgen('''
 v = qmp_input_get_visitor(mi);
 ''')
@@ -167,10 +174,7 @@ qapi_dealloc_visitor_cleanup(md);
 
 
 def gen_marshal_output(name, ret_type):
-    if not ret_type:
-        return ''
-
-    ret = mcgen('''
+    return mcgen('''
 
 static void qmp_marshal_output_%(c_cmd_name)s(%(c_type)s ret_in, QObject **ret_out, Error **errp)
 {
@@ -195,47 +199,34 @@ out:
     qapi_dealloc_visitor_cleanup(md);
 }
 ''',
-                c_type=ret_type.c_type(), c_cmd_name=c_name(name),
-                c_name=ret_type.c_name())
+                 c_type=ret_type.c_type(), c_cmd_name=c_name(name),
+                 c_name=ret_type.c_name())
 
-    return ret
 
-
-def gen_marshal_input_decl(name):
+def gen_marshal_proto(name):
     ret = 'void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
     if not middle_mode:
         ret = 'static ' + ret
     return ret
 
 
-def gen_marshal_input(name, arg_type, ret_type):
-    hdr = gen_marshal_input_decl(name)
+def gen_marshal_decl(name):
+    return mcgen('''
+%(proto)s;
+''',
+                 proto=gen_marshal_proto(name))
 
+
+def gen_marshal(name, arg_type, ret_type):
     ret = mcgen('''
 
-%(header)s
+%(proto)s
 {
-    Error *local_err = NULL;
 ''',
-                header=hdr)
-
-    if ret_type:
-        ret += mcgen('''
-    %(c_type)s retval;
-''',
-                     c_type=ret_type.c_type())
-
-    if arg_type:
-        ret += gen_visitor_input_containers_decl(arg_type)
-        ret += gen_visitor_input_vars_decl(arg_type) + '\n'
-        ret += gen_visitor_input_block(arg_type) + '\n'
-    else:
-        ret += mcgen('''
-
-    (void)args;
-
-''')
+                proto=gen_marshal_proto(name))
 
+    ret += gen_marshal_vars(arg_type, ret_type)
+    ret += gen_marshal_input_visit(arg_type)
     ret += gen_call(name, arg_type, ret_type)
 
     if re.search('^ *goto out;', ret, re.MULTILINE):
@@ -246,7 +237,7 @@ out:
     ret += mcgen('''
     error_propagate(errp, local_err);
 ''')
-    ret += gen_visitor_input_block(arg_type, dealloc=True)
+    ret += gen_marshal_input_visit(arg_type, dealloc=True)
     ret += mcgen('''
 }
 ''')
@@ -307,8 +298,8 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
         if ret_type:
             self.defn += gen_marshal_output(name, ret_type)
         if middle_mode:
-            self.decl += gen_marshal_input_decl(name) + ';\n'
-        self.defn += gen_marshal_input(name, arg_type, ret_type)
+            self.decl += gen_marshal_decl(name)
+        self.defn += gen_marshal(name, arg_type, ret_type)
         if not middle_mode:
             self._regy += gen_register_command(name, success_response)
 
-- 
2.4.3

  parent reply	other threads:[~2015-09-16 11:06 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16 11:06 [Qemu-devel] [PATCH v8 00/26] qapi: QMP introspection Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 01/26] qapi: Rename class QAPISchema to QAPISchemaParser Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 02/26] qapi: New QAPISchema intermediate reperesentation Markus Armbruster
2015-09-16 14:44   ` Daniel P. Berrange
2015-09-16 15:08   ` Eric Blake
2015-09-17  7:44     ` Markus Armbruster
2015-09-17 15:40       ` Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 03/26] qapi: QAPISchema code generation helper methods Markus Armbruster
2015-09-16 14:51   ` Daniel P. Berrange
2015-09-16 15:11   ` Eric Blake
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 04/26] qapi: New QAPISchemaVisitor Markus Armbruster
2015-09-16 14:51   ` Daniel P. Berrange
2015-09-16 15:21   ` Eric Blake
2015-09-17  7:46     ` Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 05/26] tests/qapi-schema: Convert test harness to QAPISchemaVisitor Markus Armbruster
2015-09-16 14:53   ` Daniel P. Berrange
2015-09-16 15:27   ` Eric Blake
2015-09-17  7:49     ` Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 06/26] qapi-types: Convert to QAPISchemaVisitor, fixing flat unions Markus Armbruster
2015-09-16 14:54   ` Daniel P. Berrange
2015-09-16 17:09   ` Eric Blake
2015-09-17 17:00   ` Eric Blake
2015-09-18  6:54     ` Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 07/26] qapi-visit: Convert to QAPISchemaVisitor, fixing bugs Markus Armbruster
2015-09-16 14:54   ` Daniel P. Berrange
2015-09-16 17:10   ` Eric Blake
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 08/26] qapi-commands: Convert to QAPISchemaVisitor Markus Armbruster
2015-09-16 14:57   ` Daniel P. Berrange
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 09/26] qapi: De-duplicate enum code generation Markus Armbruster
2015-09-16 14:58   ` Daniel P. Berrange
2015-09-16 17:16   ` Eric Blake
2015-09-17  8:04     ` Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 10/26] qapi-event: Eliminate global variable event_enum_value Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 11/26] qapi-event: Convert to QAPISchemaVisitor, fixing data with base Markus Armbruster
2015-09-16 14:59   ` Daniel P. Berrange
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 12/26] qapi: Replace dirty is_c_ptr() by method c_null() Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 13/26] qapi: Clean up after recent conversions to QAPISchemaVisitor Markus Armbruster
2015-09-16 15:00   ` Daniel P. Berrange
2015-09-16 17:20   ` Eric Blake
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 14/26] qapi-visit: Rearrange code a bit Markus Armbruster
2015-09-16 11:06 ` Markus Armbruster [this message]
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 16/26] qapi: Rename qmp_marshal_input_FOO() to qmp_marshal_FOO() Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 17/26] qapi: De-duplicate parameter list generation Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 18/26] qapi-commands: De-duplicate output marshaling functions Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 19/26] qapi: Improve built-in type documentation Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 20/26] qapi: Make output visitor return qnull() instead of NULL Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 21/26] qapi: Introduce a first class 'any' type Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 22/26] qom: Don't use 'gen': false for qom-get, qom-set, object-add Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 23/26] qapi-schema: Fix up misleading specification of netdev_add Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 24/26] qapi: Pseudo-type '**' is now unused, drop it Markus Armbruster
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 25/26] qapi: New QMP command query-qmp-schema for QMP introspection Markus Armbruster
2015-09-16 20:08   ` Eric Blake
2015-09-16 11:06 ` [Qemu-devel] [PATCH v8 26/26] qapi-introspect: Hide type names Markus Armbruster
2015-09-16 15:07 ` [Qemu-devel] [PATCH v8 00/26] qapi: QMP introspection Daniel P. Berrange
2015-09-17 16:16 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442401589-24189-16-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).