From patchwork Thu Nov 3 05:19:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 9410259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D4C25601C2 for ; Thu, 3 Nov 2016 05:19:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8BF72A7C9 for ; Thu, 3 Nov 2016 05:19:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD6FB2A831; Thu, 3 Nov 2016 05:19:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7AB372A7C9 for ; Thu, 3 Nov 2016 05:19:58 +0000 (UTC) Received: from localhost ([::1]:59070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c2ARR-0001pd-P0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Nov 2016 01:19:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c2AQr-0001mr-6j for qemu-devel@nongnu.org; Thu, 03 Nov 2016 01:19:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c2AQq-0006wL-8R for qemu-devel@nongnu.org; Thu, 03 Nov 2016 01:19:21 -0400 Received: from prv-mh.provo.novell.com ([137.65.248.74]:39023) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c2AQp-0006w8-W3 for qemu-devel@nongnu.org; Thu, 03 Nov 2016 01:19:20 -0400 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Wed, 02 Nov 2016 23:19:19 -0600 Message-Id: <581B394E02000062000ACC62@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.1 Date: Wed, 02 Nov 2016 23:19:10 -0600 From: "Lin Ma" To: References: <20161020112829.14589-1-lma@suse.com> <20161020112829.14589-3-lma@suse.com> In-Reply-To: <20161020112829.14589-3-lma@suse.com> Mime-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.248.74 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [Qemu-devel] =?utf-8?b?562U5aSN77yaICBbUEFUQ0ggdjQgMi81XSBxYXBp?= =?utf-8?q?=3A_auto_generate_enum_value_strings?= X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, armbru@redhat.com, afaerber@suse.de Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP ping... >>> Lin Ma 2016/10/20 星期四 下午 7:28 >>> Automatically generate enum value strings that containing the acceptable values. (Borrowed Daniel's code.) Signed-off-by: Lin Ma --- scripts/qapi-types.py | 2 ++ scripts/qapi.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index dabc42e..0446839 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -202,9 +202,11 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._btin += gen_enum(name, values, prefix) if do_builtins: self.defn += gen_enum_lookup(name, values, prefix) + self._btin += gen_enum_value_str(name, values) else: self._fwdecl += gen_enum(name, values, prefix) self.defn += gen_enum_lookup(name, values, prefix) + self._fwdecl += gen_enum_value_str(name, values) def visit_array_type(self, name, info, element_type): if isinstance(element_type, QAPISchemaBuiltinType): diff --git a/scripts/qapi.py b/scripts/qapi.py index 21bc32f..d11c414 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1649,6 +1649,15 @@ const char *const %(c_name)s_lookup[] = { return ret +def gen_enum_value_str(name, values): + return mcgen(''' + +#define %(c_name)s_value_str "%(value_str)s" +''', + c_name=c_name(name), + value_str=", ".join(["'%s'" % c for c in values])) + + def gen_enum(name, values, prefix=None): # append automatically generated _MAX value enum_values = values + ['_MAX']