summaryrefslogtreecommitdiff
path: root/scripts/qapi/doc.py
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-02-26 13:50:08 -0600
committerEric Blake <eblake@redhat.com>2018-03-02 13:14:10 -0600
commit71b3f0459c460c9e16a47372ccddbfa6e2c7aadf (patch)
treecd09eb26b84f76dbe839460bdb55a45e3f269dbc /scripts/qapi/doc.py
parent834a3f349806e543db5c347feef5ef8de0a78559 (diff)
downloadqemu-71b3f0459c460c9e16a47372ccddbfa6e2c7aadf.tar.gz
qapi: Make code-generating visitors use QAPIGen more
The use of QAPIGen is rather shallow so far: most of the output accumulation is not converted. Take the next step: convert output accumulation in the code-generating visitor classes. Helper functions outside these classes are not converted. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20180211093607.27351-20-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> [eblake: rebase to earlier guardstart cleanup] Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi/doc.py')
-rw-r--r--scripts/qapi/doc.py74
1 files changed, 35 insertions, 39 deletions
diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
index cc4d5a43fb..0ea68bf813 100644
--- a/scripts/qapi/doc.py
+++ b/scripts/qapi/doc.py
@@ -197,33 +197,35 @@ def texi_entity(doc, what, base=None, variants=None,
class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
- def __init__(self):
- self.out = None
+ def __init__(self, prefix):
+ self._prefix = prefix
+ self._gen = qapi.common.QAPIGenDoc()
self.cur_doc = None
- def visit_begin(self, schema):
- self.out = ''
+ def write(self, output_dir):
+ self._gen.write(output_dir, self._prefix + 'qapi-doc.texi')
def visit_enum_type(self, name, info, values, prefix):
doc = self.cur_doc
- self.out += TYPE_FMT(type='Enum',
- name=doc.symbol,
- body=texi_entity(doc, 'Values',
- member_func=texi_enum_value))
+ self._gen.add(TYPE_FMT(type='Enum',
+ name=doc.symbol,
+ body=texi_entity(doc, 'Values',
+ member_func=texi_enum_value)))
def visit_object_type(self, name, info, base, members, variants):
doc = self.cur_doc
if base and base.is_implicit():
base = None
- self.out += TYPE_FMT(type='Object',
- name=doc.symbol,
- body=texi_entity(doc, 'Members', base, variants))
+ self._gen.add(TYPE_FMT(type='Object',
+ name=doc.symbol,
+ body=texi_entity(doc, 'Members',
+ base, variants)))
def visit_alternate_type(self, name, info, variants):
doc = self.cur_doc
- self.out += TYPE_FMT(type='Alternate',
- name=doc.symbol,
- body=texi_entity(doc, 'Members'))
+ self._gen.add(TYPE_FMT(type='Alternate',
+ name=doc.symbol,
+ body=texi_entity(doc, 'Members')))
def visit_command(self, name, info, arg_type, ret_type,
gen, success_response, boxed):
@@ -235,44 +237,38 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
body += texi_sections(doc)
else:
body = texi_entity(doc, 'Arguments')
- self.out += MSG_FMT(type='Command',
- name=doc.symbol,
- body=body)
+ self._gen.add(MSG_FMT(type='Command',
+ name=doc.symbol,
+ body=body))
def visit_event(self, name, info, arg_type, boxed):
doc = self.cur_doc
- self.out += MSG_FMT(type='Event',
- name=doc.symbol,
- body=texi_entity(doc, 'Arguments'))
+ self._gen.add(MSG_FMT(type='Event',
+ name=doc.symbol,
+ body=texi_entity(doc, 'Arguments')))
def symbol(self, doc, entity):
- if self.out:
- self.out += '\n'
+ if self._gen._body:
+ self._gen.add('\n')
self.cur_doc = doc
entity.visit(self)
self.cur_doc = None
def freeform(self, doc):
assert not doc.args
- if self.out:
- self.out += '\n'
- self.out += texi_body(doc) + texi_sections(doc)
+ if self._gen._body:
+ self._gen.add('\n')
+ self._gen.add(texi_body(doc) + texi_sections(doc))
-def texi_schema(schema):
- """Convert QAPI schema documentation to Texinfo"""
- gen = QAPISchemaGenDocVisitor()
- gen.visit_begin(schema)
+def gen_doc(schema, output_dir, prefix):
+ if not qapi.common.doc_required:
+ return
+ vis = QAPISchemaGenDocVisitor(prefix)
+ vis.visit_begin(schema)
for doc in schema.docs:
if doc.symbol:
- gen.symbol(doc, schema.lookup_entity(doc.symbol))
+ vis.symbol(doc, schema.lookup_entity(doc.symbol))
else:
- gen.freeform(doc)
- return gen.out
-
-
-def gen_doc(schema, output_dir, prefix):
- if qapi.common.doc_required:
- gen = qapi.common.QAPIGenDoc()
- gen.add(texi_schema(schema))
- gen.write(output_dir, prefix + 'qapi-doc.texi')
+ vis.freeform(doc)
+ vis.write(output_dir)