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>
This commit is contained in:
Markus Armbruster 2018-02-11 10:35:44 +01:00 committed by Eric Blake
parent 47a6ea9aab
commit 93b564c444
5 changed files with 34 additions and 31 deletions

View file

@ -41,7 +41,8 @@ def to_c_string(string):
class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor):
def __init__(self, unmask):
def __init__(self, prefix, unmask):
self._prefix = prefix
self._unmask = unmask
self.defn = None
self.decl = None
@ -65,7 +66,7 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor):
# generate C
# TODO can generate awfully long lines
jsons.extend(self._jsons)
name = c_name(prefix, protect=False) + 'qmp_schema_json'
name = c_name(self._prefix, protect=False) + 'qmp_schema_json'
self.decl = mcgen('''
extern const char %(c_name)s[];
''',
@ -190,7 +191,7 @@ genc.add(mcgen('''
prefix=prefix))
schema = QAPISchema(input_file)
vis = QAPISchemaGenIntrospectVisitor(opt_unmask)
vis = QAPISchemaGenIntrospectVisitor(prefix, opt_unmask)
schema.visit(vis)
genc.add(vis.defn)
genh.add(vis.decl)