diff options
author | Markus Armbruster <armbru@redhat.com> | 2018-02-26 13:50:08 -0600 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2018-03-02 13:14:10 -0600 |
commit | 71b3f0459c460c9e16a47372ccddbfa6e2c7aadf (patch) | |
tree | cd09eb26b84f76dbe839460bdb55a45e3f269dbc /scripts/qapi/events.py | |
parent | 834a3f349806e543db5c347feef5ef8de0a78559 (diff) |
qapi: Make code-generating visitors use QAPIGen more
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 <armbru@redhat.com>
Message-Id: <20180211093607.27351-20-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
[eblake: rebase to earlier guardstart cleanup]
Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi/events.py')
-rw-r--r-- | scripts/qapi/events.py | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index b7dc82004f..81ab3abb30 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -148,35 +148,15 @@ out: return ret -class QAPISchemaGenEventVisitor(QAPISchemaVisitor): +class QAPISchemaGenEventVisitor(QAPISchemaMonolithicCVisitor): + def __init__(self, prefix): + QAPISchemaMonolithicCVisitor.__init__( + self, prefix, 'qapi-event', + ' * Schema-defined QAPI/QMP events', __doc__) self._enum_name = c_name(prefix + 'QAPIEvent', protect=False) - self.decl = None - self.defn = None - self._event_names = None - - def visit_begin(self, schema): - self.decl = '' - self.defn = '' self._event_names = [] - - def visit_end(self): - self.decl += gen_enum(self._enum_name, self._event_names) - self.defn += gen_enum_lookup(self._enum_name, self._event_names) - self._event_names = None - - def visit_event(self, name, info, arg_type, boxed): - self.decl += gen_event_send_decl(name, arg_type, boxed) - self.defn += gen_event_send(name, arg_type, boxed, self._enum_name) - self._event_names.append(name) - - -def gen_events(schema, output_dir, prefix): - blurb = ' * Schema-defined QAPI/QMP events' - genc = QAPIGenC(blurb, __doc__) - genh = QAPIGenH(blurb, __doc__) - - genc.add(mcgen(''' + self._genc.add(mcgen(''' #include "qemu/osdep.h" #include "qemu-common.h" #include "%(prefix)sqapi-event.h" @@ -187,18 +167,25 @@ def gen_events(schema, output_dir, prefix): #include "qapi/qmp-event.h" ''', - prefix=prefix)) - - genh.add(mcgen(''' + prefix=prefix)) + self._genh.add(mcgen(''' #include "qapi/util.h" #include "%(prefix)sqapi-types.h" ''', - prefix=prefix)) + prefix=prefix)) + def visit_end(self): + self._genh.add(gen_enum(self._enum_name, self._event_names)) + self._genc.add(gen_enum_lookup(self._enum_name, self._event_names)) + + def visit_event(self, name, info, arg_type, boxed): + self._genh.add(gen_event_send_decl(name, arg_type, boxed)) + self._genc.add(gen_event_send(name, arg_type, boxed, self._enum_name)) + self._event_names.append(name) + + +def gen_events(schema, output_dir, prefix): vis = QAPISchemaGenEventVisitor(prefix) schema.visit(vis) - genc.add(vis.defn) - genh.add(vis.decl) - genc.write(output_dir, prefix + 'qapi-event.c') - genh.write(output_dir, prefix + 'qapi-event.h') + vis.write(output_dir) |