qapi/commands: Simplify command registry generation
commitc6cd7e4151794194f804ac3b8d2bc9347142c024
authorMarkus Armbruster <armbru@redhat.com>
Mon, 1 Feb 2021 19:37:44 +0000 (1 14:37 -0500)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 8 Feb 2021 13:15:58 +0000 (8 14:15 +0100)
tree226e35d1249140b8131b2f4c350b4f3d4ccf93f3
parentd921d27c1bac0765370a9b9b891f9f0429f4c7c3
qapi/commands: Simplify command registry generation

QAPISchemaGenCommandVisitor.visit_command() needs to generate the
marshalling function into the current module, and also generate its
registration into the ./init system module.  The latter is done
somewhat awkwardly: .__init__() creates a QAPIGenCCode that will not
be written out, each .visit_command() adds its registration to it, and
.visit_end() copies its contents into the ./init module it creates.

Instead provide the means to temporarily switch to another module.
Create the ./init module in .visit_begin(), and generate its initial
part.  Add registrations to it in .visit_command().  Finish it in
.visit_end().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-14-jsnow@redhat.com>
scripts/qapi/commands.py