qapi: add 'If:' section to generated documentation

The documentation is generated only once, and doesn't know C
pre-conditions. Add 'If:' sections for top-level entities.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20180703155648.11933-13-marcandre.lureau@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
Marc-André Lureau 2018-07-03 17:56:46 +02:00 committed by Markus Armbruster
parent 9f88c66211
commit 901a34a400
4 changed files with 16 additions and 11 deletions

View File

@ -174,7 +174,7 @@ def texi_members(doc, what, base, variants, member_func):
return '\n@b{%s:}\n@table @asis\n%s@end table\n' % (what, items) return '\n@b{%s:}\n@table @asis\n%s@end table\n' % (what, items)
def texi_sections(doc): def texi_sections(doc, ifcond):
"""Format additional sections following arguments""" """Format additional sections following arguments"""
body = '' body = ''
for section in doc.sections: for section in doc.sections:
@ -185,14 +185,16 @@ def texi_sections(doc):
body += texi_example(section.text) body += texi_example(section.text)
else: else:
body += texi_format(section.text) body += texi_format(section.text)
if ifcond:
body += '\n\n@b{If:} @code{%s}' % ", ".join(ifcond)
return body return body
def texi_entity(doc, what, base=None, variants=None, def texi_entity(doc, what, ifcond, base=None, variants=None,
member_func=texi_member): member_func=texi_member):
return (texi_body(doc) return (texi_body(doc)
+ texi_members(doc, what, base, variants, member_func) + texi_members(doc, what, base, variants, member_func)
+ texi_sections(doc)) + texi_sections(doc, ifcond))
class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor): class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
@ -208,7 +210,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
doc = self.cur_doc doc = self.cur_doc
self._gen.add(TYPE_FMT(type='Enum', self._gen.add(TYPE_FMT(type='Enum',
name=doc.symbol, name=doc.symbol,
body=texi_entity(doc, 'Values', body=texi_entity(doc, 'Values', ifcond,
member_func=texi_enum_value))) member_func=texi_enum_value)))
def visit_object_type(self, name, info, ifcond, base, members, variants): def visit_object_type(self, name, info, ifcond, base, members, variants):
@ -217,14 +219,14 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
base = None base = None
self._gen.add(TYPE_FMT(type='Object', self._gen.add(TYPE_FMT(type='Object',
name=doc.symbol, name=doc.symbol,
body=texi_entity(doc, 'Members', body=texi_entity(doc, 'Members', ifcond,
base, variants))) base, variants)))
def visit_alternate_type(self, name, info, ifcond, variants): def visit_alternate_type(self, name, info, ifcond, variants):
doc = self.cur_doc doc = self.cur_doc
self._gen.add(TYPE_FMT(type='Alternate', self._gen.add(TYPE_FMT(type='Alternate',
name=doc.symbol, name=doc.symbol,
body=texi_entity(doc, 'Members'))) body=texi_entity(doc, 'Members', ifcond)))
def visit_command(self, name, info, ifcond, arg_type, ret_type, gen, def visit_command(self, name, info, ifcond, arg_type, ret_type, gen,
success_response, boxed, allow_oob, allow_preconfig): success_response, boxed, allow_oob, allow_preconfig):
@ -233,9 +235,9 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
body = texi_body(doc) body = texi_body(doc)
body += ('\n@b{Arguments:} the members of @code{%s}\n' body += ('\n@b{Arguments:} the members of @code{%s}\n'
% arg_type.name) % arg_type.name)
body += texi_sections(doc) body += texi_sections(doc, ifcond)
else: else:
body = texi_entity(doc, 'Arguments') body = texi_entity(doc, 'Arguments', ifcond)
self._gen.add(MSG_FMT(type='Command', self._gen.add(MSG_FMT(type='Command',
name=doc.symbol, name=doc.symbol,
body=body)) body=body))
@ -244,7 +246,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
doc = self.cur_doc doc = self.cur_doc
self._gen.add(MSG_FMT(type='Event', self._gen.add(MSG_FMT(type='Event',
name=doc.symbol, name=doc.symbol,
body=texi_entity(doc, 'Arguments'))) body=texi_entity(doc, 'Arguments', ifcond)))
def symbol(self, doc, entity): def symbol(self, doc, entity):
if self._gen._body: if self._gen._body:
@ -257,7 +259,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
assert not doc.args assert not doc.args
if self._gen._body: if self._gen._body:
self._gen.add('\n') self._gen.add('\n')
self._gen.add(texi_body(doc) + texi_sections(doc)) self._gen.add(texi_body(doc) + texi_sections(doc, None))
def gen_doc(schema, output_dir, prefix): def gen_doc(schema, output_dir, prefix):

View File

@ -55,7 +55,7 @@
# #
# @two is undocumented # @two is undocumented
## ##
{ 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'enum': 'Enum', 'data': [ 'one', 'two' ], 'if': 'defined(IFCOND)' }
## ##
# @Base: # @Base:

View File

@ -3,6 +3,7 @@ enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
prefix QTYPE prefix QTYPE
module doc-good.json module doc-good.json
enum Enum ['one', 'two'] enum Enum ['one', 'two']
if ['defined(IFCOND)']
object Base object Base
member base1: Enum optional=False member base1: Enum optional=False
object Variant1 object Variant1

View File

@ -89,6 +89,8 @@ Not documented
@end table @end table
@code{two} is undocumented @code{two} is undocumented
@b{If:} @code{defined(IFCOND)}
@end deftp @end deftp