Re: [Qemu-devel] [PATCH v2 19/29] qapi: Make code-generating visitors use QAPIGen more

2018-02-23 Thread Markus Armbruster
Michael Roth  writes:

> Quoting Markus Armbruster (2018-02-11 03:35:57)
>> The use of QAPIGen is rather shallow so far: most of the output
>> accumulation is not converted.  Take the next step: convert output
>> accumulation in the code-generating visitor classes.  Helper functions
>> outside these classes are not converted.
>> 
>> Signed-off-by: Markus Armbruster 
>> ---
>>  scripts/qapi/commands.py   | 71 
>>  scripts/qapi/common.py | 13 
>>  scripts/qapi/doc.py| 74 --
>>  scripts/qapi/events.py | 55 ---
>>  scripts/qapi/introspect.py | 56 +---
>>  scripts/qapi/types.py  | 81 
>> +++---
>>  scripts/qapi/visit.py  | 80 
>> +++--
>>  7 files changed, 188 insertions(+), 242 deletions(-)
>> 
>
> 
>
>> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
>> index 29d98ca934..31d2f73e7e 100644
>> --- a/scripts/qapi/common.py
>> +++ b/scripts/qapi/common.py
>> @@ -2049,3 +2049,16 @@ class QAPIGenDoc(QAPIGen):
>>  def _top(self, fname):
>>  return (QAPIGen._top(self, fname)
>>  + '@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n')
>> +
>> +
>> +class QAPISchemaMonolithicCVisitor(QAPISchemaVisitor):
>> +
>> +def __init__(self, prefix, what, blurb, pydoc):
>> +self._prefix = prefix
>> +self._what = what
>> +self._genc = QAPIGenC(blurb, pydoc)
>> +self._genh = QAPIGenH(blurb, pydoc)
>> +
>> +def write(self, output_dir):
>> +self._genc.write(output_dir, self._prefix + self._what + '.c')
>> +self._genh.write(output_dir, self._prefix + self._what + '.h')
>
> minor nit: since subclasses of QAPISchemaVisitor and
> QAPISchemaMonolithicCVisitor all rely on .write() now, should we declare it
> in the abstract QAPISchemaVisitor?

Perhaps.  If they had more in common, the case for an abstract super
class would be clearer.

> Reviewed-by: Michael Roth 

Thanks!



Re: [Qemu-devel] [PATCH v2 19/29] qapi: Make code-generating visitors use QAPIGen more

2018-02-19 Thread Michael Roth
Quoting Markus Armbruster (2018-02-11 03:35:57)
> The use of QAPIGen is rather shallow so far: most of the output
> accumulation is not converted.  Take the next step: convert output
> accumulation in the code-generating visitor classes.  Helper functions
> outside these classes are not converted.
> 
> Signed-off-by: Markus Armbruster 
> ---
>  scripts/qapi/commands.py   | 71 
>  scripts/qapi/common.py | 13 
>  scripts/qapi/doc.py| 74 --
>  scripts/qapi/events.py | 55 ---
>  scripts/qapi/introspect.py | 56 +---
>  scripts/qapi/types.py  | 81 
> +++---
>  scripts/qapi/visit.py  | 80 +++--
>  7 files changed, 188 insertions(+), 242 deletions(-)
> 



> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index 29d98ca934..31d2f73e7e 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -2049,3 +2049,16 @@ class QAPIGenDoc(QAPIGen):
>  def _top(self, fname):
>  return (QAPIGen._top(self, fname)
>  + '@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n')
> +
> +
> +class QAPISchemaMonolithicCVisitor(QAPISchemaVisitor):
> +
> +def __init__(self, prefix, what, blurb, pydoc):
> +self._prefix = prefix
> +self._what = what
> +self._genc = QAPIGenC(blurb, pydoc)
> +self._genh = QAPIGenH(blurb, pydoc)
> +
> +def write(self, output_dir):
> +self._genc.write(output_dir, self._prefix + self._what + '.c')
> +self._genh.write(output_dir, self._prefix + self._what + '.h')

minor nit: since subclasses of QAPISchemaVisitor and
QAPISchemaMonolithicCVisitor all rely on .write() now, should we declare it
in the abstract QAPISchemaVisitor?

Reviewed-by: Michael Roth 




Re: [Qemu-devel] [PATCH v2 19/29] qapi: Make code-generating visitors use QAPIGen more

2018-02-13 Thread Marc-Andre Lureau
On Sun, Feb 11, 2018 at 10:35 AM, Markus Armbruster  wrote:
> The use of QAPIGen is rather shallow so far: most of the output
> accumulation is not converted.  Take the next step: convert output
> accumulation in the code-generating visitor classes.  Helper functions
> outside these classes are not converted.
>
> Signed-off-by: Markus Armbruster 

Reviewed-by: Marc-André Lureau 


> ---
>  scripts/qapi/commands.py   | 71 
>  scripts/qapi/common.py | 13 
>  scripts/qapi/doc.py| 74 --
>  scripts/qapi/events.py | 55 ---
>  scripts/qapi/introspect.py | 56 +---
>  scripts/qapi/types.py  | 81 
> +++---
>  scripts/qapi/visit.py  | 80 +++--
>  7 files changed, 188 insertions(+), 242 deletions(-)
>
> diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
> index 05fe33a03b..46757db771 100644
> --- a/scripts/qapi/commands.py
> +++ b/scripts/qapi/commands.py
> @@ -223,44 +223,15 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds)
>  return ret
>
>
> -class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
> +class QAPISchemaGenCommandVisitor(QAPISchemaMonolithicCVisitor):
> +
>  def __init__(self, prefix):
> -self._prefix = prefix
> -self.decl = None
> -self.defn = None
> -self._regy = None
> -self._visited_ret_types = None
> -
> -def visit_begin(self, schema):
> -self.decl = ''
> -self.defn = ''
> +QAPISchemaMonolithicCVisitor.__init__(
> +self, prefix, 'qmp-commands',
> +' * Schema-defined QAPI/QMP commands', __doc__)
>  self._regy = ''
>  self._visited_ret_types = set()
> -
> -def visit_end(self):
> -self.defn += gen_registry(self._regy, self._prefix)
> -self._regy = None
> -self._visited_ret_types = None
> -
> -def visit_command(self, name, info, arg_type, ret_type,
> -  gen, success_response, boxed):
> -if not gen:
> -return
> -self.decl += gen_command_decl(name, arg_type, boxed, ret_type)
> -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)
> -self.decl += gen_marshal_decl(name)
> -self.defn += gen_marshal(name, arg_type, boxed, ret_type)
> -self._regy += gen_register_command(name, success_response)
> -
> -
> -def gen_commands(schema, output_dir, prefix):
> -blurb = ' * Schema-defined QAPI/QMP commands'
> -genc = QAPIGenC(blurb, __doc__)
> -genh = QAPIGenH(blurb, __doc__)
> -
> -genc.add(mcgen('''
> +self._genc.add(mcgen('''
>  #include "qemu/osdep.h"
>  #include "qemu-common.h"
>  #include "qemu/module.h"
> @@ -275,19 +246,33 @@ def gen_commands(schema, output_dir, prefix):
>  #include "%(prefix)sqmp-commands.h"
>
>  ''',
> -   prefix=prefix))
> -
> -genh.add(mcgen('''
> + prefix=prefix))
> +self._genh.add(mcgen('''
>  #include "%(prefix)sqapi-types.h"
>  #include "qapi/qmp/dispatch.h"
>
>  void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds);
>  ''',
> -   prefix=prefix, c_prefix=c_name(prefix, protect=False)))
> + prefix=prefix,
> + c_prefix=c_name(prefix, protect=False)))
>
> +def visit_end(self):
> +self._genc.add(gen_registry(self._regy, self._prefix))
> +
> +def visit_command(self, name, info, arg_type, ret_type,
> +  gen, success_response, boxed):
> +if not gen:
> +return
> +self._genh.add(gen_command_decl(name, arg_type, boxed, ret_type))
> +if ret_type and ret_type not in self._visited_ret_types:
> +self._visited_ret_types.add(ret_type)
> +self._genc.add(gen_marshal_output(ret_type))
> +self._genh.add(gen_marshal_decl(name))
> +self._genc.add(gen_marshal(name, arg_type, boxed, ret_type))
> +self._regy += gen_register_command(name, success_response)
> +
> +
> +def gen_commands(schema, output_dir, prefix):
>  vis = QAPISchemaGenCommandVisitor(prefix)
>  schema.visit(vis)
> -genc.add(vis.defn)
> -genh.add(vis.decl)
> -genc.write(output_dir, prefix + 'qmp-commands.c')
> -genh.write(output_dir, prefix + 'qmp-commands.h')
> +vis.write(output_dir)
> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index 29d98ca934..31d2f73e7e 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -2049,3 +2049,16 @@ class QAPIGenDoc(QAPIGen):
>  def _top(self, fname):
>  return (QAPIGen._top(self, fname)
>

Re: [Qemu-devel] [PATCH v2 19/29] qapi: Make code-generating visitors use QAPIGen more

2018-02-12 Thread Eric Blake

On 02/11/2018 03:35 AM, Markus Armbruster wrote:

The use of QAPIGen is rather shallow so far: most of the output
accumulation is not converted.  Take the next step: convert output
accumulation in the code-generating visitor classes.  Helper functions
outside these classes are not converted.

Signed-off-by: Markus Armbruster 
---
  scripts/qapi/commands.py   | 71 
  scripts/qapi/common.py | 13 
  scripts/qapi/doc.py| 74 --
  scripts/qapi/events.py | 55 ---
  scripts/qapi/introspect.py | 56 +---
  scripts/qapi/types.py  | 81 +++---
  scripts/qapi/visit.py  | 80 +++--
  7 files changed, 188 insertions(+), 242 deletions(-)



Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



[Qemu-devel] [PATCH v2 19/29] qapi: Make code-generating visitors use QAPIGen more

2018-02-11 Thread Markus Armbruster
The use of QAPIGen is rather shallow so far: most of the output
accumulation is not converted.  Take the next step: convert output
accumulation in the code-generating visitor classes.  Helper functions
outside these classes are not converted.

Signed-off-by: Markus Armbruster 
---
 scripts/qapi/commands.py   | 71 
 scripts/qapi/common.py | 13 
 scripts/qapi/doc.py| 74 --
 scripts/qapi/events.py | 55 ---
 scripts/qapi/introspect.py | 56 +---
 scripts/qapi/types.py  | 81 +++---
 scripts/qapi/visit.py  | 80 +++--
 7 files changed, 188 insertions(+), 242 deletions(-)

diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 05fe33a03b..46757db771 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -223,44 +223,15 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds)
 return ret
 
 
-class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
+class QAPISchemaGenCommandVisitor(QAPISchemaMonolithicCVisitor):
+
 def __init__(self, prefix):
-self._prefix = prefix
-self.decl = None
-self.defn = None
-self._regy = None
-self._visited_ret_types = None
-
-def visit_begin(self, schema):
-self.decl = ''
-self.defn = ''
+QAPISchemaMonolithicCVisitor.__init__(
+self, prefix, 'qmp-commands',
+' * Schema-defined QAPI/QMP commands', __doc__)
 self._regy = ''
 self._visited_ret_types = set()
-
-def visit_end(self):
-self.defn += gen_registry(self._regy, self._prefix)
-self._regy = None
-self._visited_ret_types = None
-
-def visit_command(self, name, info, arg_type, ret_type,
-  gen, success_response, boxed):
-if not gen:
-return
-self.decl += gen_command_decl(name, arg_type, boxed, ret_type)
-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)
-self.decl += gen_marshal_decl(name)
-self.defn += gen_marshal(name, arg_type, boxed, ret_type)
-self._regy += gen_register_command(name, success_response)
-
-
-def gen_commands(schema, output_dir, prefix):
-blurb = ' * Schema-defined QAPI/QMP commands'
-genc = QAPIGenC(blurb, __doc__)
-genh = QAPIGenH(blurb, __doc__)
-
-genc.add(mcgen('''
+self._genc.add(mcgen('''
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/module.h"
@@ -275,19 +246,33 @@ def gen_commands(schema, output_dir, prefix):
 #include "%(prefix)sqmp-commands.h"
 
 ''',
-   prefix=prefix))
-
-genh.add(mcgen('''
+ prefix=prefix))
+self._genh.add(mcgen('''
 #include "%(prefix)sqapi-types.h"
 #include "qapi/qmp/dispatch.h"
 
 void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds);
 ''',
-   prefix=prefix, c_prefix=c_name(prefix, protect=False)))
+ prefix=prefix,
+ c_prefix=c_name(prefix, protect=False)))
 
+def visit_end(self):
+self._genc.add(gen_registry(self._regy, self._prefix))
+
+def visit_command(self, name, info, arg_type, ret_type,
+  gen, success_response, boxed):
+if not gen:
+return
+self._genh.add(gen_command_decl(name, arg_type, boxed, ret_type))
+if ret_type and ret_type not in self._visited_ret_types:
+self._visited_ret_types.add(ret_type)
+self._genc.add(gen_marshal_output(ret_type))
+self._genh.add(gen_marshal_decl(name))
+self._genc.add(gen_marshal(name, arg_type, boxed, ret_type))
+self._regy += gen_register_command(name, success_response)
+
+
+def gen_commands(schema, output_dir, prefix):
 vis = QAPISchemaGenCommandVisitor(prefix)
 schema.visit(vis)
-genc.add(vis.defn)
-genh.add(vis.decl)
-genc.write(output_dir, prefix + 'qmp-commands.c')
-genh.write(output_dir, prefix + 'qmp-commands.h')
+vis.write(output_dir)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 29d98ca934..31d2f73e7e 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -2049,3 +2049,16 @@ class QAPIGenDoc(QAPIGen):
 def _top(self, fname):
 return (QAPIGen._top(self, fname)
 + '@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n')
+
+
+class QAPISchemaMonolithicCVisitor(QAPISchemaVisitor):
+
+def __init__(self, prefix, what, blurb, pydoc):
+self._prefix = prefix
+self._what = what
+self._genc = QAPIGenC(blurb, pydoc)
+self._genh = QAPIGenH(blurb, pydoc)
+
+def write(self, output_dir):
+