From patchwork Thu Dec 17 08:33:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 558088 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 4DC8E1402EC for ; Thu, 17 Dec 2015 19:38:38 +1100 (AEDT) Received: from localhost ([::1]:51371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9U56-0000L1-0v for incoming@patchwork.ozlabs.org; Thu, 17 Dec 2015 03:38:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9U0W-0000LY-OW for qemu-devel@nongnu.org; Thu, 17 Dec 2015 03:33:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9U0U-00017B-Pk for qemu-devel@nongnu.org; Thu, 17 Dec 2015 03:33:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40043) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9U0U-000176-Kc for qemu-devel@nongnu.org; Thu, 17 Dec 2015 03:33:50 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 4DEB3C00040F for ; Thu, 17 Dec 2015 08:33:50 +0000 (UTC) Received: from blackfin.pond.sub.org ([10.3.113.12]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBH8Xk3B013623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 17 Dec 2015 03:33:49 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EFF903001100; Thu, 17 Dec 2015 09:33:45 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 17 Dec 2015 09:33:08 +0100 Message-Id: <1450341225-2735-4-git-send-email-armbru@redhat.com> In-Reply-To: <1450341225-2735-1-git-send-email-armbru@redhat.com> References: <1450341225-2735-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/40] qapi-types: Simplify gen_struct_field[s] 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 Simplify gen_struct_fields() back to a single iteration over a list of fields (like it was prior to commit f87ab7f9), by moving the generated comments to gen_object(). Then, inline gen_struct_field() into its only caller. Signed-off-by: Eric Blake Message-Id: <1447836791-369-4-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 403768b..2f2f7df 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -36,48 +36,38 @@ struct %(c_name)s { c_name=c_name(name), c_type=element_type.c_type()) -def gen_struct_field(member): +def gen_struct_fields(members): ret = '' - - if member.optional: - ret += mcgen(''' + for memb in members: + if memb.optional: + ret += mcgen(''' bool has_%(c_name)s; ''', - c_name=c_name(member.name)) - ret += mcgen(''' + c_name=c_name(memb.name)) + ret += mcgen(''' %(c_type)s %(c_name)s; ''', - c_type=member.type.c_type(), c_name=c_name(member.name)) + c_type=memb.type.c_type(), c_name=c_name(memb.name)) return ret -def gen_struct_fields(local_members, base): - ret = '' +def gen_object(name, base, members, variants): + ret = mcgen(''' + +struct %(c_name)s { +''', + c_name=c_name(name)) if base: ret += mcgen(''' /* Members inherited from %(c_name)s: */ ''', c_name=base.c_name()) - for memb in base.members: - ret += gen_struct_field(memb) + ret += gen_struct_fields(base.members) ret += mcgen(''' /* Own members: */ ''') - - for memb in local_members: - ret += gen_struct_field(memb) - return ret - - -def gen_object(name, base, members, variants): - ret = mcgen(''' - -struct %(c_name)s { -''', - c_name=c_name(name)) - - ret += gen_struct_fields(members, base) + ret += gen_struct_fields(members) if variants: ret += gen_variants(variants)