Received: from eggs.gnu.org ([2001:4830:134:3::10]:49047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWvHB-0004d4-QA for qemu-devel@nongnu.org; Fri, 19 Feb 2016 19:19:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWvHA-0003vl-3w for qemu-devel@nongnu.org; Fri, 19 Feb 2016 19:19:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52676) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWvH9-0003vI-TU for qemu-devel@nongnu.org; Fri, 19 Feb 2016 19:19:55 -0500 From: Eric Blake Date: Fri, 19 Feb 2016 17:19:41 -0700 Message-Id: <1455927587-28033-12-git-send-email-eblake@redhat.com> In-Reply-To: <1455927587-28033-1-git-send-email-eblake@redhat.com> References: <1455927587-28033-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH 11/17] qapi-visit: Simplify visit of empty branch in union List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, Michael Roth 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 --- 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 ab773f6..127c84e0 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -44,7 +44,9 @@ static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s *obj, Error **er def gen_visit_fields_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 -- 2.5.0