From patchwork Thu Feb 25 23:38:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8427661 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BBF96C0553 for ; Thu, 25 Feb 2016 23:41:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 349CF2025B for ; Thu, 25 Feb 2016 23:41:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E03320259 for ; Thu, 25 Feb 2016 23:41:18 +0000 (UTC) Received: from localhost ([::1]:46438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ5X3-0006i3-Ue for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Feb 2016 18:41:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ5V1-0002rE-GE for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZ5V0-0005TF-PP for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZ5V0-0005T0-Do for qemu-devel@nongnu.org; Thu, 25 Feb 2016 18:39:10 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 11EB36026; Thu, 25 Feb 2016 23:39:10 +0000 (UTC) Received: from red.redhat.com (ovpn-113-105.phx2.redhat.com [10.3.113.105]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1PNd2Nl002433; Thu, 25 Feb 2016 18:39:09 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 25 Feb 2016 16:38:42 -0700 Message-Id: <1456443528-13901-14-git-send-email-eblake@redhat.com> In-Reply-To: <1456443528-13901-1-git-send-email-eblake@redhat.com> References: <1456443528-13901-1-git-send-email-eblake@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.38]); Thu, 25 Feb 2016 23:39:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v2 13/19] qapi-visit: Simplify visit of empty branch in union X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now that we have is_empty() and gen_visit_fields_call(), it's fairly easy to skip the visit of a variant type that has no members. Only one such instance exists at the moment (CpuInfoOther), but the idea of a union where some branches add no fields beyond the base type is common enough that we may add syntax for other cases, as in { 'union':'U', 'base':'B', 'discriminator':'D', 'data': { 'default': {}, 'extra':'Type' } } Note that the Abort type is another example of an empty type, but it is only used by a simple union rather than a flat union; and with simple unions, the wrapper type providing the 'data' QMP key is not empty. Signed-off-by: Eric Blake --- v2: no change --- scripts/qapi-visit.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index dbae00c..a9de393 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -37,7 +37,9 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp); def gen_visit_members_call(typ, c_name): ret = '' assert isinstance(typ, QAPISchemaObjectType) - if typ.is_implicit(): + if typ.is_empty(): + pass + elif typ.is_implicit(): # TODO ugly special case for simple union assert len(typ.members) == 1 assert not typ.variants