diff mbox

[v2,09/12] qapi: remove the "middle" mode

Message ID 20160721140030.28383-10-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau July 21, 2016, 2 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Now that the register function is always generated, we can
remove the so-called "middle" mode from the generator script.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/qapi-commands.py | 29 +++++------------------------
 1 file changed, 5 insertions(+), 24 deletions(-)

Comments

Eric Blake July 21, 2016, 10:55 p.m. UTC | #1
On 07/21/2016 08:00 AM, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Now that the register function is always generated, we can
> remove the so-called "middle" mode from the generator script.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  scripts/qapi-commands.py | 29 +++++------------------------
>  1 file changed, 5 insertions(+), 24 deletions(-)
> 
> diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
> index a06a2c4..4754ae0 100644
> --- a/scripts/qapi-commands.py
> +++ b/scripts/qapi-commands.py
> @@ -84,17 +84,8 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out,
>  
>  
>  def gen_marshal_proto(name):
> -    ret = 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
> -    if not middle_mode:
> -        ret = 'static ' + ret
> -    return ret
> -
> -
> -def gen_marshal_decl(name):
> -    return mcgen('''
> -%(proto)s;
> -''',
> -                 proto=gen_marshal_proto(name))
> +    return 'static void qmp_marshal_%s' % c_name(name) + \
> +        '(QDict *args, QObject **ret, Error **errp)'

I'm wondering if this should be:

    return mcgen('''
static void qmp_marshal_%(c_name)s(QDict *args, QObject **ret, Error **errp)
''',
                 c_name=c_name(name))

for consistency with our other code (I'm not sure why we weren't already
using mcgen(), though).

Otherwise, nice to see it go!
Marc-André Lureau July 22, 2016, 7:35 a.m. UTC | #2
Hi

On Fri, Jul 22, 2016 at 2:55 AM, Eric Blake <eblake@redhat.com> wrote:
> On 07/21/2016 08:00 AM, marcandre.lureau@redhat.com wrote:
>> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>>
>> Now that the register function is always generated, we can
>> remove the so-called "middle" mode from the generator script.
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>  scripts/qapi-commands.py | 29 +++++------------------------
>>  1 file changed, 5 insertions(+), 24 deletions(-)
>>
>> diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
>> index a06a2c4..4754ae0 100644
>> --- a/scripts/qapi-commands.py
>> +++ b/scripts/qapi-commands.py
>> @@ -84,17 +84,8 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out,
>>
>>
>>  def gen_marshal_proto(name):
>> -    ret = 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
>> -    if not middle_mode:
>> -        ret = 'static ' + ret
>> -    return ret
>> -
>> -
>> -def gen_marshal_decl(name):
>> -    return mcgen('''
>> -%(proto)s;
>> -''',
>> -                 proto=gen_marshal_proto(name))
>> +    return 'static void qmp_marshal_%s' % c_name(name) + \
>> +        '(QDict *args, QObject **ret, Error **errp)'
>
> I'm wondering if this should be:
>
>     return mcgen('''
> static void qmp_marshal_%(c_name)s(QDict *args, QObject **ret, Error **errp)
> ''',
>                  c_name=c_name(name))
>
> for consistency with our other code (I'm not sure why we weren't already
> using mcgen(), though).

yes, it works fine too, and we can simplify a bit the code around.
Markus Armbruster Aug. 5, 2016, 1:31 p.m. UTC | #3
marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Now that the register function is always generated, we can
> remove the so-called "middle" mode from the generator script.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  scripts/qapi-commands.py | 29 +++++------------------------
>  1 file changed, 5 insertions(+), 24 deletions(-)
>
> diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
> index a06a2c4..4754ae0 100644
> --- a/scripts/qapi-commands.py
> +++ b/scripts/qapi-commands.py
> @@ -84,17 +84,8 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out,
>  
>  
>  def gen_marshal_proto(name):
> -    ret = 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
> -    if not middle_mode:
> -        ret = 'static ' + ret
> -    return ret
> -
> -
> -def gen_marshal_decl(name):
> -    return mcgen('''
> -%(proto)s;
> -''',
> -                 proto=gen_marshal_proto(name))
> +    return 'static void qmp_marshal_%s' % c_name(name) + \
> +        '(QDict *args, QObject **ret, Error **errp)'

Eric's suggestion to use mcgen() here seconded.

>  
>  
>  def gen_marshal(name, arg_type, boxed, ret_type):
> @@ -209,8 +200,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
>          self._visited_ret_types = set()
>  
>      def visit_end(self):
> -        if not middle_mode:
> -            self.defn += gen_registry(self._regy)
> +        self.defn += gen_registry(self._regy)
>          self._regy = None
>          self._visited_ret_types = None
>  
> @@ -222,21 +212,12 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
>          if ret_type and ret_type not in self._visited_ret_types:
>              self._visited_ret_types.add(ret_type)
>              self.defn += gen_marshal_output(ret_type)
> -        if middle_mode:
> -            self.decl += gen_marshal_decl(name)
>          self.defn += gen_marshal(name, arg_type, boxed, ret_type)
> -        if not middle_mode:
> -            self._regy += gen_register_command(name, success_response)
> -
> +        self._regy += gen_register_command(name, success_response)
>  
> -middle_mode = False
>  
>  (input_file, output_dir, do_c, do_h, prefix, opts) = \
> -    parse_command_line("m", ["middle"])
> -
> -for o, a in opts:
> -    if o in ("-m", "--middle"):
> -        middle_mode = True
> +    parse_command_line()
>  
>  c_comment = '''
>  /*

Let's get rid of the line continuation, too:

   (input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
diff mbox

Patch

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index a06a2c4..4754ae0 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -84,17 +84,8 @@  static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out,
 
 
 def gen_marshal_proto(name):
-    ret = 'void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
-    if not middle_mode:
-        ret = 'static ' + ret
-    return ret
-
-
-def gen_marshal_decl(name):
-    return mcgen('''
-%(proto)s;
-''',
-                 proto=gen_marshal_proto(name))
+    return 'static void qmp_marshal_%s' % c_name(name) + \
+        '(QDict *args, QObject **ret, Error **errp)'
 
 
 def gen_marshal(name, arg_type, boxed, ret_type):
@@ -209,8 +200,7 @@  class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
         self._visited_ret_types = set()
 
     def visit_end(self):
-        if not middle_mode:
-            self.defn += gen_registry(self._regy)
+        self.defn += gen_registry(self._regy)
         self._regy = None
         self._visited_ret_types = None
 
@@ -222,21 +212,12 @@  class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
         if ret_type and ret_type not in self._visited_ret_types:
             self._visited_ret_types.add(ret_type)
             self.defn += gen_marshal_output(ret_type)
-        if middle_mode:
-            self.decl += gen_marshal_decl(name)
         self.defn += gen_marshal(name, arg_type, boxed, ret_type)
-        if not middle_mode:
-            self._regy += gen_register_command(name, success_response)
-
+        self._regy += gen_register_command(name, success_response)
 
-middle_mode = False
 
 (input_file, output_dir, do_c, do_h, prefix, opts) = \
-    parse_command_line("m", ["middle"])
-
-for o, a in opts:
-    if o in ("-m", "--middle"):
-        middle_mode = True
+    parse_command_line()
 
 c_comment = '''
 /*