def subst_strong(doc):
"""Replaces *foo* by @strong{foo}"""
- return re.sub(r'\*([^*\n]+)\*', r'@emph{\1}', doc)
+ return re.sub(r'\*([^*\n]+)\*', r'@strong{\1}', doc)
def subst_emph(doc):
"""Replaces _foo_ by @emph{foo}"""
- return re.sub(r'\b_([^_\n]+)_\b', r' @emph{\1} ', doc)
+ return re.sub(r'\b_([^_\n]+)_\b', r'@emph{\1}', doc)
def subst_vars(doc):
return '@item @code{%s}\n' % value.name
-def texi_member(member):
+def texi_member(member, suffix=''):
"""Format a table of members item for an object type member"""
typ = member.type.doc_type()
- return '@item @code{%s%s%s}%s\n' % (
+ return '@item @code{%s%s%s}%s%s\n' % (
member.name,
': ' if typ else '',
typ if typ else '',
- ' (optional)' if member.optional else '')
+ ' (optional)' if member.optional else '',
+ suffix)
-def texi_members(doc, what, base, member_func):
+def texi_members(doc, what, base, variants, member_func):
"""Format the table of members"""
items = ''
for section in doc.args.itervalues():
+ # TODO Drop fallbacks when undocumented members are outlawed
if section.content:
- desc = str(section)
+ desc = texi_format(str(section))
+ elif (variants and variants.tag_member == section.member
+ and not section.member.type.doc_type()):
+ values = section.member.type.member_names()
+ desc = 'One of ' + ', '.join(['@t{"%s"}' % v for v in values])
else:
desc = 'Not documented'
- items += member_func(section.member) + texi_format(desc) + '\n'
+ items += member_func(section.member) + desc + '\n'
if base:
items += '@item The members of @code{%s}\n' % base.doc_type()
+ if variants:
+ for v in variants.variants:
+ when = ' when @code{%s} is @t{"%s"}' % (
+ variants.tag_member.name, v.name)
+ if v.type.is_implicit():
+ assert not v.type.base and not v.type.variants
+ for m in v.type.local_members:
+ items += member_func(m, when)
+ else:
+ items += '@item The members of @code{%s}%s\n' % (
+ v.type.doc_type(), when)
if not items:
return ''
return '\n@b{%s:}\n@table @asis\n%s@end table\n' % (what, items)
return body
-def texi_entity(doc, what, base=None, member_func=texi_member):
+def texi_entity(doc, what, base=None, variants=None,
+ member_func=texi_member):
return (texi_body(doc)
- + texi_members(doc, what, base, member_func)
+ + texi_members(doc, what, base, variants, member_func)
+ texi_sections(doc))
def visit_object_type(self, name, info, base, members, variants):
doc = self.cur_doc
- if not variants:
- typ = 'Struct'
- elif variants._tag_name: # TODO unclean member access
- typ = 'Flat Union'
- else:
- typ = 'Simple Union'
if base and base.is_implicit():
base = None
if self.out:
self.out += '\n'
- self.out += TYPE_FMT(type=typ,
+ self.out += TYPE_FMT(type='Object',
name=doc.symbol,
- body=texi_entity(doc, 'Members', base))
+ body=texi_entity(doc, 'Members', base, variants))
def visit_alternate_type(self, name, info, variants):
doc = self.cur_doc
if not qapi.doc_required:
print >>sys.stderr, ("%s: need pragma 'doc-required' "
"to generate documentation" % argv[0])
+ sys.exit(1)
print texi_schema(schema)