aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi-event.py
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-02-11 10:35:44 +0100
committerEric Blake <eblake@redhat.com>2018-03-02 13:14:09 -0600
commit93b564c444edc41901d0f7e922833eeb751f8249 (patch)
treeaf0b36e50877b556dcf2b16c2094586af51ff881 /scripts/qapi-event.py
parent47a6ea9aab1d857015684cda387ffba05a036721 (diff)
qapi: Reduce use of global variables in generators some
In preparation of the next commit, which will turn the generators into modules. These global variables will become local to main() then. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20180211093607.27351-7-armbru@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi-event.py')
-rw-r--r--scripts/qapi-event.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index e063f6b8d1..f65ccdc8ea 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -58,7 +58,7 @@ def gen_param_var(typ):
return ret
-def gen_event_send(name, arg_type, boxed):
+def gen_event_send(name, arg_type, boxed, event_enum_name):
# FIXME: Our declaration of local variables (and of 'errp' in the
# parameter list) can collide with exploded members of the event's
# data type passed in as parameters. If this collision ever hits in
@@ -149,7 +149,8 @@ out:
class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
- def __init__(self):
+ def __init__(self, prefix):
+ self._enum_name = c_name(prefix + 'QAPIEvent', protect=False)
self.decl = None
self.defn = None
self._event_names = None
@@ -160,13 +161,13 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
self._event_names = []
def visit_end(self):
- self.decl += gen_enum(event_enum_name, self._event_names)
- self.defn += gen_enum_lookup(event_enum_name, self._event_names)
+ 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.defn += gen_event_send(name, arg_type, boxed, self._enum_name)
self._event_names.append(name)
@@ -197,10 +198,8 @@ genh.add(mcgen('''
''',
prefix=prefix))
-event_enum_name = c_name(prefix + 'QAPIEvent', protect=False)
-
schema = QAPISchema(input_file)
-vis = QAPISchemaGenEventVisitor()
+vis = QAPISchemaGenEventVisitor(prefix)
schema.visit(vis)
genc.add(vis.defn)
genh.add(vis.decl)