From patchwork Mon Mar 13 06:18:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 738001 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vhSnb65Kpz9s78 for ; Mon, 13 Mar 2017 17:36:35 +1100 (AEDT) Received: from localhost ([::1]:50434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnJar-0004uQ-8H for incoming@patchwork.ozlabs.org; Mon, 13 Mar 2017 02:36:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnJJr-0007bI-3o for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:19:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnJJm-0003dW-5r for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49204) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnJJl-0003aL-Rx for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:54 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB7779D76B; Mon, 13 Mar 2017 06:18:53 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2D6IqFL023394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 02:18:53 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6E12F11384B1; Mon, 13 Mar 2017 07:18:47 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 13 Mar 2017 07:18:27 +0100 Message-Id: <1489385927-6735-28-git-send-email-armbru@redhat.com> In-Reply-To: <1489385927-6735-1-git-send-email-armbru@redhat.com> References: <1489385927-6735-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 13 Mar 2017 06:18:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 27/47] qapi2texi: Generate documentation for variant members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" A flat union's branch brings in the members of another type. Generate a suitable reference to that type. Example change (qemu-qmp-ref.txt): -- Flat Union: QCryptoBlockOpenOptions The options that are available for all encryption formats when opening an existing volume Members: The members of 'QCryptoBlockOptionsBase' + The members of 'QCryptoBlockOptionsQCow' when 'format' is "qcow" + The members of 'QCryptoBlockOptionsLUKS' when 'format' is "luks" Since: 2.6 A simple union's branch adds a member 'data' of some other type. Generate documentation for that member. Example change (qemu-qmp-ref.txt): -- Simple Union: SocketAddress Captures the address of a socket, which could also be a named file descriptor Members: 'type' Not documented + 'data: InetSocketAddress' when 'type' is "inet" + 'data: UnixSocketAddress' when 'type' is "unix" + 'data: VsockSocketAddress' when 'type' is "vsock" + 'data: String' when 'type' is "fd" Since: 1.3 Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi2texi.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index 7083d0c..ab6b6cd 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -133,17 +133,18 @@ def texi_enum_value(value): 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(): @@ -154,6 +155,17 @@ def texi_members(doc, what, base, member_func): items += member_func(section.member) + texi_format(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) @@ -176,9 +188,10 @@ def texi_sections(doc): 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)) @@ -213,7 +226,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): self.out += '\n' self.out += TYPE_FMT(type=typ, 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