From patchwork Tue Aug 22 13:22:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 804458 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3xcBmj5TN5z9sxR for ; Tue, 22 Aug 2017 23:51:33 +1000 (AEST) Received: from localhost ([::1]:47140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9ad-0006LL-Jt for incoming@patchwork.ozlabs.org; Tue, 22 Aug 2017 09:51:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Ho-0006fA-3h for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hk-00064F-67 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33394) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hj-00063K-Ss for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3895761476; Tue, 22 Aug 2017 13:26:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3895761476 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A75B2617A9; Tue, 22 Aug 2017 13:26:06 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 22 Aug 2017 15:22:38 +0200 Message-Id: <20170822132255.23945-38-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 22 Aug 2017 13:26:10 +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 Subject: [Qemu-devel] [PATCH v2 37/54] qapi: 'if' to alternate variant 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Marc-André Lureau --- scripts/qapi.py | 8 +++++++- tests/qapi-schema/qapi-schema-test.json | 6 +++++- tests/qapi-schema/qapi-schema-test.out | 8 +++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index cd5d151809..bcd8d37c12 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -829,6 +829,8 @@ def check_alternate(expr, info): check_type(info, "Member '%s' of alternate '%s'" % (key, name), value, allow_metas=['built-in', 'union', 'struct', 'enum']) + if isinstance(value, dict): + value = value['type'] qtype = find_alternate_member_qtype(value) if not qtype: raise QAPISemError(info, "Alternate '%s' member '%s' cannot use " @@ -1644,7 +1646,11 @@ class QAPISchema(object): None, ifcond)) def _make_variant(self, case, typ): - return QAPISchemaObjectTypeVariant(case, typ) + ifcond = None + if isinstance(typ, dict): + ifcond = typ.get('if') + typ = typ['type'] + return QAPISchemaObjectTypeVariant(case, typ, ifcond) def _make_simple_variant(self, case, typ, info): ifcond = None diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index 23dae79f92..0032e4f026 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -206,9 +206,13 @@ { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' }, 'if': 'defined(TEST_IF_UNION)' } -{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct' }, +{ 'alternate': 'TestIfAlternate', 'data': + { 'foo': 'int', 'alt_bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } +{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' }, + 'if': 'defined(TEST_IF_ALT)' } + { 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } }, 'if': 'defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index 12fc5a4425..8b8144574b 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -55,8 +55,11 @@ enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] alternate TestIfAlternate tag type case foo: int - case bar: TestStruct + case alt_bar: TestStruct if=defined(TEST_IF_ALT_BAR) if defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT) +command TestIfAlternateCmd q_obj_TestIfAlternateCmd-arg -> None + gen=True success_response=True boxed=False + if defined(TEST_IF_ALT) command TestIfCmd q_obj_TestIfCmd-arg -> None gen=True success_response=True boxed=False if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT) @@ -200,6 +203,9 @@ object q_obj_EVENT_D-arg member b: str optional=False member c: str optional=True member enum3: EnumOne optional=True +object q_obj_TestIfAlternateCmd-arg + member alt_cmd_arg: TestIfAlternate optional=False + if defined(TEST_IF_ALT) object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=False member bar: TestIfEnum optional=False if=defined(TEST_IF_CMD_BAR)