aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi-visit.py
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-02-26 13:19:40 -0600
committerEric Blake <eblake@redhat.com>2018-03-02 13:14:09 -0600
commit47a6ea9aab1d857015684cda387ffba05a036721 (patch)
treecb0682a858e5a545bdb525c1b96364a91e6d22c6 /scripts/qapi-visit.py
parentd46eec4260540d83bafba91608842ab03dabf339 (diff)
qapi: New classes QAPIGenC, QAPIGenH, QAPIGenDoc
These classes encapsulate accumulating and writing output. Convert C code generation to QAPIGenC and QAPIGenH. The conversion is rather shallow: most of the output accumulation is not converted. Left for later. The indentation machinery uses a single global variable indent_level, even though we generally interleave creation of a .c and its .h. It should become instance variable of QAPIGenC. Also left for later. Documentation generation isn't converted, and QAPIGenDoc isn't used. This will change shortly. 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-6-armbru@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> [eblake: fix nits spotted by Michael] Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi-visit.py')
-rw-r--r--scripts/qapi-visit.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 0e78cf3bbb..51eeaa1fc2 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -272,7 +272,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
def visit_begin(self, schema):
self.decl = ''
self.defn = ''
- self._btin = guardstart('QAPI_VISIT_BUILTIN')
+ self._btin = '\n' + guardstart('QAPI_VISIT_BUILTIN')
def visit_end(self):
# To avoid header dependency hell, we always generate
@@ -337,30 +337,32 @@ for o, a in opts:
blurb = ' * Schema-defined QAPI visitors'
-(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
- 'qapi-visit.c', 'qapi-visit.h',
- blurb, __doc__)
+genc = QAPIGenC(blurb, __doc__)
+genh = QAPIGenH(blurb, __doc__)
-fdef.write(mcgen('''
+genc.add(mcgen('''
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
#include "%(prefix)sqapi-visit.h"
''',
- prefix=prefix))
+ prefix=prefix))
-fdecl.write(mcgen('''
+genh.add(mcgen('''
#include "qapi/visitor.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix))
+ prefix=prefix))
schema = QAPISchema(input_file)
vis = QAPISchemaGenVisitVisitor()
schema.visit(vis)
-fdef.write(vis.defn)
-fdecl.write(vis.decl)
+genc.add(vis.defn)
+genh.add(vis.decl)
-close_output(fdef, fdecl)
+if do_c:
+ genc.write(output_dir, prefix + 'qapi-visit.c')
+if do_h:
+ genh.write(output_dir, prefix + 'qapi-visit.h')