Commit 47a6ea9a authored by Markus Armbruster's avatar Markus Armbruster Committed by Eric Blake
Browse files

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: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20180211093607.27351-6-armbru@redhat.com>
Reviewed-by: default avatarMichael Roth <mdroth@linux.vnet.ibm.com>
[eblake: fix nits spotted by Michael]
Signed-off-by: default avatarEric Blake <eblake@redhat.com>
parent d46eec42
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -258,12 +258,10 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):

blurb = ' * Schema-defined QAPI/QMP commands'

(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
                            'qmp-marshal.c', 'qmp-commands.h',
                            blurb, __doc__)

fdef.write(mcgen('''
genc = QAPIGenC(blurb, __doc__)
genh = QAPIGenH(blurb, __doc__)

genc.add(mcgen('''
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/module.h"
@@ -280,7 +278,7 @@ fdef.write(mcgen('''
''',
               prefix=prefix))

fdecl.write(mcgen('''
genh.add(mcgen('''
#include "%(prefix)sqapi-types.h"
#include "qapi/qmp/dispatch.h"

@@ -291,7 +289,10 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds);
schema = QAPISchema(input_file)
vis = QAPISchemaGenCommandVisitor()
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 + 'qmp-marshal.c')
if do_h:
    genh.write(output_dir, prefix + 'qmp-commands.h')
+12 −10
Original line number Diff line number Diff line
@@ -174,11 +174,10 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):

blurb = ' * Schema-defined QAPI/QMP events'

(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
                            'qapi-event.c', 'qapi-event.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 "%(prefix)sqapi-event.h"
@@ -191,7 +190,7 @@ fdef.write(mcgen('''
''',
               prefix=prefix))

fdecl.write(mcgen('''
genh.add(mcgen('''
#include "qapi/util.h"
#include "%(prefix)sqapi-types.h"

@@ -203,7 +202,10 @@ event_enum_name = c_name(prefix + 'QAPIEvent', protect=False)
schema = QAPISchema(input_file)
vis = QAPISchemaGenEventVisitor()
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-event.c')
if do_h:
    genh.write(output_dir, prefix + 'qapi-event.h')
+10 −8
Original line number Diff line number Diff line
@@ -179,11 +179,10 @@ for o, a in opts:

blurb = ' * QAPI/QMP schema introspection'

(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
                            'qmp-introspect.c', 'qmp-introspect.h',
                            blurb, __doc__)
genc = QAPIGenC(blurb, __doc__)
genh = QAPIGenH(blurb, __doc__)

fdef.write(mcgen('''
genc.add(mcgen('''
#include "qemu/osdep.h"
#include "%(prefix)sqmp-introspect.h"

@@ -193,7 +192,10 @@ fdef.write(mcgen('''
schema = QAPISchema(input_file)
vis = QAPISchemaGenIntrospectVisitor(opt_unmask)
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 + 'qmp-introspect.c')
if do_h:
    genh.write(output_dir, prefix + 'qmp-introspect.h')
+12 −10
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
        self.decl = ''
        self.defn = ''
        self._fwdecl = ''
        self._btin = guardstart('QAPI_TYPES_BUILTIN')
        self._btin = '\n' + guardstart('QAPI_TYPES_BUILTIN')

    def visit_end(self):
        self.decl = self._fwdecl + self.decl
@@ -254,11 +254,10 @@ for o, a in opts:

blurb = ' * Schema-defined QAPI types'

(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
                            'qapi-types.c', 'qapi-types.h',
                            blurb, __doc__)
genc = QAPIGenC(blurb, __doc__)
genh = QAPIGenH(blurb, __doc__)

fdef.write(mcgen('''
genc.add(mcgen('''
#include "qemu/osdep.h"
#include "qapi/dealloc-visitor.h"
#include "%(prefix)sqapi-types.h"
@@ -266,14 +265,17 @@ fdef.write(mcgen('''
''',
               prefix=prefix))

fdecl.write(mcgen('''
genh.add(mcgen('''
#include "qapi/util.h"
'''))

schema = QAPISchema(input_file)
vis = QAPISchemaGenTypeVisitor()
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-types.c')
if do_h:
    genh.write(output_dir, prefix + 'qapi-types.h')
+13 −11
Original line number Diff line number Diff line
@@ -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,11 +337,10 @@ 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"
@@ -350,7 +349,7 @@ fdef.write(mcgen('''
''',
               prefix=prefix))

fdecl.write(mcgen('''
genh.add(mcgen('''
#include "qapi/visitor.h"
#include "%(prefix)sqapi-types.h"

@@ -360,7 +359,10 @@ fdecl.write(mcgen('''
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')
Loading