From patchwork Tue Jul 23 13:03:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 261072 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E68982C00C3 for ; Tue, 23 Jul 2013 23:04:21 +1000 (EST) Received: from localhost ([::1]:39731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1cGJ-0008WE-Ce for incoming@patchwork.ozlabs.org; Tue, 23 Jul 2013 09:04:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1cFj-0008Oj-In for qemu-devel@nongnu.org; Tue, 23 Jul 2013 09:03:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1cFi-0007Py-1c for qemu-devel@nongnu.org; Tue, 23 Jul 2013 09:03:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1cFh-0007Pl-Mi for qemu-devel@nongnu.org; Tue, 23 Jul 2013 09:03:41 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6ND3fP6019508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Jul 2013 09:03:41 -0400 Received: from dhcp-200-207.str.redhat.com (ovpn-116-56.ams2.redhat.com [10.36.116.56]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6ND3U6C008625; Tue, 23 Jul 2013 09:03:39 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 23 Jul 2013 15:03:12 +0200 Message-Id: <1374584606-5615-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1374584606-5615-1-git-send-email-kwolf@redhat.com> References: <1374584606-5615-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 04/18] qapi-visit.py: Implement 'base' for unions 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This implements the visitor part of base types for unions. Parsed into QMP, this example schema definiton... { 'type': 'BlockOptionsBase', 'data': { 'read-only': 'bool' } } { 'type': 'BlockOptionsQcow2, 'data': { 'lazy-refcounts': 'bool' } } { 'union': 'BlockOptions', 'base': 'BlockOptionsBase', 'data': { 'raw': 'BlockOptionsRaw' 'qcow2': 'BlockOptionsQcow2' } } ...would describe the following JSON object: { "type": "qcow2", "read-only": true, "data": { "lazy-refcounts": false } } Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- scripts/qapi-visit.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index a337d80..db6fa44 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -151,7 +151,13 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **e ''', name=name) -def generate_visit_union(name, members): +def generate_visit_union(expr): + + name = expr['union'] + members = expr['data'] + + base = expr.get('base') + ret = generate_visit_enum('%sKind' % name, members.keys()) ret += mcgen(''' @@ -164,14 +170,28 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error ** visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err); if (!err) { if (obj && *obj) { - visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err); - if (!err) { - switch ((*obj)->kind) { ''', name=name) + push_indent() push_indent() + push_indent() + + if base: + struct = find_struct(base) + push_indent() + ret += generate_visit_struct_fields("", struct['data']) + pop_indent() + + pop_indent() + ret += mcgen(''' + visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err); + if (!err) { + switch ((*obj)->kind) { +''', + name=name) + for key in members: ret += mcgen(''' case %(abbrev)s_KIND_%(enum)s: @@ -368,7 +388,7 @@ for expr in exprs: ret = generate_declaration(expr['type'], expr['data']) fdecl.write(ret) elif expr.has_key('union'): - ret = generate_visit_union(expr['union'], expr['data']) + ret = generate_visit_union(expr) ret += generate_visit_list(expr['union'], expr['data']) fdef.write(ret)