From patchwork Fri Oct 18 07:43:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 11197689 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB17D17E1 for ; Fri, 18 Oct 2019 07:56:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BBBB221897 for ; Fri, 18 Oct 2019 07:56:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBBB221897 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLN7b-0006Sb-F5 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Oct 2019 03:56:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59541) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLMvR-0000Uu-Qn for qemu-devel@nongnu.org; Fri, 18 Oct 2019 03:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iLMvQ-0007gq-Cw for qemu-devel@nongnu.org; Fri, 18 Oct 2019 03:43:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55854) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iLMvQ-0007g8-42 for qemu-devel@nongnu.org; Fri, 18 Oct 2019 03:43:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5440018CB916; Fri, 18 Oct 2019 07:43:51 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EBD085D9CC; Fri, 18 Oct 2019 07:43:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 942FC1132A0B; Fri, 18 Oct 2019 09:43:45 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 5/7] qapi: Move gen_enum(), gen_enum_lookup() back to qapi/types.py Date: Fri, 18 Oct 2019 09:43:43 +0200 Message-Id: <20191018074345.24034-6-armbru@redhat.com> In-Reply-To: <20191018074345.24034-1-armbru@redhat.com> References: <20191018074345.24034-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Fri, 18 Oct 2019 07:43:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The next commit will split up qapi/common.py. gen_enum() needs QAPISchemaEnumMember, and that's in the way. Move it to qapi/types.py along with its buddy gen_enum_lookup(). Permit me a short a digression on history: how did gen_enum() end up in qapi/common.py? Commit 21cd70dfc1 "qapi script: add event support" duplicated qapi-types.py's gen_enum() and gen_enum_lookup() in qapi-event.py. Simply importing them would have been cleaner, but wasn't possible as qapi-types.py was a program, not a module. Commit efd2eaa6c2 "qapi: De-duplicate enum code generation" de-duplicated by moving them to qapi.py, which was a module. Since then, program qapi-types.py has morphed into module types.py. It's where gen_enum() and gen_enum_lookup() started, and where they belong. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/common.py | 59 ------------------------------------------ scripts/qapi/events.py | 1 + scripts/qapi/types.py | 59 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 59 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 9d5c05f6a1..306857f0c0 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -2239,65 +2239,6 @@ def _wrap_ifcond(ifcond, before, after): return out -def gen_enum_lookup(name, members, prefix=None): - ret = mcgen(''' - -const QEnumLookup %(c_name)s_lookup = { - .array = (const char *const[]) { -''', - c_name=c_name(name)) - for m in members: - ret += gen_if(m.ifcond) - index = c_enum_const(name, m.name, prefix) - ret += mcgen(''' - [%(index)s] = "%(name)s", -''', - index=index, name=m.name) - ret += gen_endif(m.ifcond) - - ret += mcgen(''' - }, - .size = %(max_index)s -}; -''', - max_index=c_enum_const(name, '_MAX', prefix)) - return ret - - -def gen_enum(name, members, prefix=None): - # append automatically generated _MAX value - enum_members = members + [QAPISchemaEnumMember('_MAX', None)] - - ret = mcgen(''' - -typedef enum %(c_name)s { -''', - c_name=c_name(name)) - - for m in enum_members: - ret += gen_if(m.ifcond) - ret += mcgen(''' - %(c_enum)s, -''', - c_enum=c_enum_const(name, m.name, prefix)) - ret += gen_endif(m.ifcond) - - ret += mcgen(''' -} %(c_name)s; -''', - c_name=c_name(name)) - - ret += mcgen(''' - -#define %(c_name)s_str(val) \\ - qapi_enum_lookup(&%(c_name)s_lookup, (val)) - -extern const QEnumLookup %(c_name)s_lookup; -''', - c_name=c_name(name)) - return ret - - def build_params(arg_type, boxed, extra=None): ret = '' sep = '' diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 7308e8e589..a716a1d27f 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -13,6 +13,7 @@ See the COPYING file in the top-level directory. """ from qapi.common import * +from qapi.types import gen_enum, gen_enum_lookup def build_event_send_proto(name, arg_type, boxed): diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 3edd9374aa..711543147d 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -21,6 +21,65 @@ from qapi.common import * objects_seen = set() +def gen_enum_lookup(name, members, prefix=None): + ret = mcgen(''' + +const QEnumLookup %(c_name)s_lookup = { + .array = (const char *const[]) { +''', + c_name=c_name(name)) + for m in members: + ret += gen_if(m.ifcond) + index = c_enum_const(name, m.name, prefix) + ret += mcgen(''' + [%(index)s] = "%(name)s", +''', + index=index, name=m.name) + ret += gen_endif(m.ifcond) + + ret += mcgen(''' + }, + .size = %(max_index)s +}; +''', + max_index=c_enum_const(name, '_MAX', prefix)) + return ret + + +def gen_enum(name, members, prefix=None): + # append automatically generated _MAX value + enum_members = members + [QAPISchemaEnumMember('_MAX', None)] + + ret = mcgen(''' + +typedef enum %(c_name)s { +''', + c_name=c_name(name)) + + for m in enum_members: + ret += gen_if(m.ifcond) + ret += mcgen(''' + %(c_enum)s, +''', + c_enum=c_enum_const(name, m.name, prefix)) + ret += gen_endif(m.ifcond) + + ret += mcgen(''' +} %(c_name)s; +''', + c_name=c_name(name)) + + ret += mcgen(''' + +#define %(c_name)s_str(val) \\ + qapi_enum_lookup(&%(c_name)s_lookup, (val)) + +extern const QEnumLookup %(c_name)s_lookup; +''', + c_name=c_name(name)) + return ret + + def gen_fwd_object_or_array(name): return mcgen('''