From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UwUcP-00020B-9G for qemu-devel@nongnu.org; Tue, 09 Jul 2013 05:54:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UwUcN-0007Tn-BN for qemu-devel@nongnu.org; Tue, 09 Jul 2013 05:53:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UwUcN-0007Te-3Y for qemu-devel@nongnu.org; Tue, 09 Jul 2013 05:53:55 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r699rslp008315 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Jul 2013 05:53:54 -0400 From: Kevin Wolf Date: Tue, 9 Jul 2013 11:53:28 +0200 Message-Id: <1373363617-4723-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1373363617-4723-1-git-send-email-kwolf@redhat.com> References: <1373363617-4723-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [RFC PATCH 02/11] qapi-types.py: Implement 'base' for unions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com, lcapitulino@redhat.com The new 'base' key in a union definition refers to a struct type, which is inlined into the union definition and can represent fields common to all kinds. Signed-off-by: Kevin Wolf --- scripts/qapi-types.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index e1239e1..960065b 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -157,7 +157,16 @@ typedef enum %(name)s return lookup_decl + enum_decl -def generate_union(name, typeinfo): +def generate_union(expr): + + name = expr['union'] + typeinfo = expr['data'] + + if expr.has_key('base'): + base = expr['base'] + else: + base = None + ret = mcgen(''' struct %(name)s { @@ -176,6 +185,13 @@ struct %(name)s ret += mcgen(''' }; +''') + + if base: + struct = find_struct(base) + ret += generate_struct_fields(struct['data']) + + ret += mcgen(''' }; ''') @@ -359,7 +375,7 @@ for expr in exprs: ret += generate_type_cleanup_decl(expr['type']) fdef.write(generate_type_cleanup(expr['type']) + "\n") elif expr.has_key('union'): - ret += generate_union(expr['union'], expr['data']) + ret += generate_union(expr) ret += generate_type_cleanup_decl(expr['union'] + "List") fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n") ret += generate_type_cleanup_decl(expr['union']) -- 1.8.1.4