From patchwork Fri Oct 30 15:42:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 538426 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 9CF91140157 for ; Sat, 31 Oct 2015 02:53:22 +1100 (AEDT) Received: from localhost ([::1]:51484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsBzU-0007n3-5f for incoming@patchwork.ozlabs.org; Fri, 30 Oct 2015 11:53:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsBpb-0005lr-IC for qemu-devel@nongnu.org; Fri, 30 Oct 2015 11:43:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZsBpa-00059U-98 for qemu-devel@nongnu.org; Fri, 30 Oct 2015 11:43:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsBpa-000592-12 for qemu-devel@nongnu.org; Fri, 30 Oct 2015 11:43:06 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id B1F7DFA9D1 for ; Fri, 30 Oct 2015 15:43:05 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9UFh1he018897 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 30 Oct 2015 11:43:05 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6072630052F7; Fri, 30 Oct 2015 16:42:56 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 30 Oct 2015 16:42:53 +0100 Message-Id: <1446219774-1802-25-git-send-email-armbru@redhat.com> In-Reply-To: <1446219774-1802-1-git-send-email-armbru@redhat.com> References: <1446219774-1802-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 24/25] qapi: Simplify gen_struct_field() 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 From: Eric Blake Rather than having all callers pass a name, type, and optional flag, have them instead pass a QAPISchemaObjectTypeMember which already has all that information. No change to generated code. Signed-off-by: Eric Blake Message-Id: <1445898903-12082-25-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 7e35bb6..b37900f 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -36,18 +36,18 @@ struct %(c_name)s { c_name=c_name(name), c_type=element_type.c_type()) -def gen_struct_field(name, typ, optional): +def gen_struct_field(member): ret = '' - if optional: + if member.optional: ret += mcgen(''' bool has_%(c_name)s; ''', - c_name=c_name(name)) + c_name=c_name(member.name)) ret += mcgen(''' %(c_type)s %(c_name)s; ''', - c_type=typ.c_type(), c_name=c_name(name)) + c_type=member.type.c_type(), c_name=c_name(member.name)) return ret @@ -60,13 +60,13 @@ def gen_struct_fields(local_members, base=None): ''', c_name=base.c_name()) for memb in base.members: - ret += gen_struct_field(memb.name, memb.type, memb.optional) + ret += gen_struct_field(memb) ret += mcgen(''' /* Own members: */ ''') for memb in local_members: - ret += gen_struct_field(memb.name, memb.type, memb.optional) + ret += gen_struct_field(memb) return ret @@ -149,9 +149,7 @@ struct %(c_name)s { if base: ret += gen_struct_fields([], base) else: - ret += gen_struct_field(variants.tag_member.name, - variants.tag_member.type, - False) + ret += gen_struct_field(variants.tag_member) # FIXME: What purpose does data serve, besides preventing a union that # has a branch named 'data'? We use it in qapi-visit.py to decide