aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2019-10-24 13:02:25 +0200
committerMarkus Armbruster <armbru@redhat.com>2019-10-29 07:35:16 +0100
commita4bd91d3f3d69414c9c76b856a0d69b12773503c (patch)
tree9b74cd9e17084e4559ea9a865882773ab1552c88 /scripts
parentb621a26040dd626cf9098c277e763f55fcfacf67 (diff)
qapi: De-duplicate entity documentation generation code
QAPISchemaGenDocVisitor.visit_command() duplicates texi_entity() for its boxed arguments case. The previous commit added another copy in .visit_event(). Replace texi_entity() by texi_type() and texi_msg(). Use texi_msg() for the boxed arguments case as well. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20191024110237.30963-8-armbru@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi/doc.py82
1 files changed, 40 insertions, 42 deletions
diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
index f2462c9877..c8c4bda153 100644
--- a/scripts/qapi/doc.py
+++ b/scripts/qapi/doc.py
@@ -12,7 +12,7 @@ from qapi.gen import QAPIGenDoc, QAPISchemaVisitor
MSG_FMT = """
@deftypefn {type} {{}} {name}
-{body}
+{body}{members}{features}{sections}
@end deftypefn
""".format
@@ -20,7 +20,7 @@ MSG_FMT = """
TYPE_FMT = """
@deftp {{{type}}} {name}
-{body}
+{body}{members}{features}{sections}
@end deftp
""".format
@@ -149,7 +149,8 @@ def texi_member(member, desc, suffix):
suffix, desc, texi_if(member.ifcond, prefix='@*'))
-def texi_members(doc, what, base, variants, member_func):
+def texi_members(doc, what, base=None, variants=None,
+ member_func=texi_member):
"""Format the table of members"""
items = ''
for section in doc.args.values():
@@ -182,6 +183,13 @@ def texi_members(doc, what, base, variants, member_func):
return '\n@b{%s:}\n@table @asis\n%s@end table\n' % (what, items)
+def texi_arguments(doc, boxed_arg_type):
+ if boxed_arg_type:
+ return ('\n@b{Arguments:} the members of @code{%s}\n'
+ % boxed_arg_type.name)
+ return texi_members(doc, 'Arguments')
+
+
def texi_features(doc):
"""Format the table of features"""
items = ''
@@ -208,12 +216,22 @@ def texi_sections(doc, ifcond):
return body
-def texi_entity(doc, what, ifcond, base=None, variants=None,
- member_func=texi_member):
- return (texi_body(doc)
- + texi_members(doc, what, base, variants, member_func)
- + texi_features(doc)
- + texi_sections(doc, ifcond))
+def texi_type(typ, doc, ifcond, members):
+ return TYPE_FMT(type=typ,
+ name=doc.symbol,
+ body=texi_body(doc),
+ members=members,
+ features=texi_features(doc),
+ sections=texi_sections(doc, ifcond))
+
+
+def texi_msg(typ, doc, ifcond, members):
+ return MSG_FMT(type=typ,
+ name=doc.symbol,
+ body=texi_body(doc),
+ members=members,
+ features=texi_features(doc),
+ sections=texi_sections(doc, ifcond))
class QAPISchemaGenDocVisitor(QAPISchemaVisitor):
@@ -227,56 +245,36 @@ class QAPISchemaGenDocVisitor(QAPISchemaVisitor):
def visit_enum_type(self, name, info, ifcond, members, prefix):
doc = self.cur_doc
- self._gen.add(TYPE_FMT(type='Enum',
- name=doc.symbol,
- body=texi_entity(doc, 'Values', ifcond,
- member_func=texi_enum_value)))
+ self._gen.add(texi_type('Enum', doc, ifcond,
+ texi_members(doc, 'Values',
+ member_func=texi_enum_value)))
def visit_object_type(self, name, info, ifcond, base, members, variants,
features):
doc = self.cur_doc
if base and base.is_implicit():
base = None
- self._gen.add(TYPE_FMT(type='Object',
- name=doc.symbol,
- body=texi_entity(doc, 'Members', ifcond,
- base, variants)))
+ self._gen.add(texi_type('Object', doc, ifcond,
+ texi_members(doc, 'Members', base, variants)))
def visit_alternate_type(self, name, info, ifcond, variants):
doc = self.cur_doc
- self._gen.add(TYPE_FMT(type='Alternate',
- name=doc.symbol,
- body=texi_entity(doc, 'Members', ifcond)))
+ self._gen.add(texi_type('Alternate', doc, ifcond,
+ texi_members(doc, 'Members')))
def visit_command(self, name, info, ifcond, arg_type, ret_type, gen,
success_response, boxed, allow_oob, allow_preconfig,
features):
doc = self.cur_doc
- if boxed:
- body = texi_body(doc)
- body += ('\n@b{Arguments:} the members of @code{%s}\n'
- % arg_type.name)
- body += texi_features(doc)
- body += texi_sections(doc, ifcond)
- else:
- body = texi_entity(doc, 'Arguments', ifcond)
- self._gen.add(MSG_FMT(type='Command',
- name=doc.symbol,
- body=body))
+ self._gen.add(texi_msg('Command', doc, ifcond,
+ texi_arguments(doc,
+ arg_type if boxed else None)))
def visit_event(self, name, info, ifcond, arg_type, boxed):
doc = self.cur_doc
- if boxed:
- body = texi_body(doc)
- body += ('\n@b{Arguments:} the members of @code{%s}\n'
- % arg_type.name)
- body += texi_features(doc)
- body += texi_sections(doc, ifcond)
- else:
- body = texi_entity(doc, 'Arguments', ifcond)
- self._gen.add(MSG_FMT(type='Event',
- name=doc.symbol,
- body=body))
+ self._gen.add(texi_msg('Event', doc, ifcond,
+ texi_arguments(doc,
+ arg_type if boxed else None)))
def symbol(self, doc, entity):
if self._gen._body: