From nobody Tue Feb 10 20:07:18 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628066194306714.2779442087062; Wed, 4 Aug 2021 01:36:34 -0700 (PDT) Received: from localhost ([::1]:36960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mBCO9-0005P3-A8 for importer@patchew.org; Wed, 04 Aug 2021 04:36:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBCK6-0005bM-NR for qemu-devel@nongnu.org; Wed, 04 Aug 2021 04:32:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47038) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBCK4-0002KX-Ng for qemu-devel@nongnu.org; Wed, 04 Aug 2021 04:32:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-cxmZonWNNX6GV7GL_OrbiA-1; Wed, 04 Aug 2021 04:32:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E587801B3D for ; Wed, 4 Aug 2021 08:32:18 +0000 (UTC) Received: from localhost (unknown [10.39.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C50710074E1; Wed, 4 Aug 2021 08:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628065940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k7nflWmFv7eQoa+qT2pxBsRxqMlPFeintlPo8h65o04=; b=ftUJe+O68U9eftKXj2YLJmrLsxHaBuBbVcY6ie1i9ijqswMlWgVelH3XSyjyywdXxoqfSe P8QOuRE/BYAlBM9PORamPXKf6NXEkvqwf+8Ee2Ju0U+DQ07Nn6ZONLxudxEeqlGQ4uQ56C oAMblQo+RPvzL4SMG1MIV0iopePByBk= X-MC-Unique: cxmZonWNNX6GV7GL_OrbiA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v7 09/10] qapi: add 'not' condition operation Date: Wed, 4 Aug 2021 12:31:04 +0400 Message-Id: <20210804083105.97531-10-marcandre.lureau@redhat.com> In-Reply-To: <20210804083105.97531-1-marcandre.lureau@redhat.com> References: <20210804083105.97531-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628066195670100001 From: Marc-Andr=C3=A9 Lureau For the sake of completeness, introduce the 'not' condition. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 4 ++++ scripts/qapi/expr.py | 7 +++++-- tests/qapi-schema/bad-if-key.err | 2 +- tests/qapi-schema/bad-if-keys.err | 2 +- tests/qapi-schema/doc-good.json | 3 ++- tests/qapi-schema/doc-good.out | 1 + tests/qapi-schema/doc-good.txt | 6 ++++++ tests/qapi-schema/enum-if-invalid.err | 2 +- tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qapi-schema/qapi-schema-test.out | 4 ++-- 10 files changed, 24 insertions(+), 9 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 018d2f6996..f8718e201b 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -207,6 +207,8 @@ def docgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -= > str: return ifcond =20 oper, operands =3D next(iter(ifcond.items())) + if oper =3D=3D 'not': + return '!' + docgen_ifcond(operands) oper =3D {'all': ' and ', 'any': ' or '}[oper] operands =3D [docgen_ifcond(o) for o in operands] return '(' + oper.join(operands) + ')' @@ -219,6 +221,8 @@ def cgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -> = str: return ifcond =20 oper, operands =3D next(iter(ifcond.items())) + if oper =3D=3D 'not': + return '!' + cgen_ifcond(operands) oper =3D {'all': '&&', 'any': '||'}[oper] operands =3D [cgen_ifcond(o) for o in operands] return '(' + (') ' + oper + ' (').join(operands) + ')' diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index e30fd3e31c..63943e15e9 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -296,15 +296,18 @@ def _check_if(cond: Union[str, object]) -> None: raise QAPISemError( info, "'if' condition dict of %s must have one key: " - "'all' or 'any'" % source) + "'all', 'any' or 'not'" % source) check_keys(cond, info, "'if' condition", [], - ["all", "any"]) + ["all", "any", "not"]) =20 oper, operands =3D next(iter(cond.items())) if not operands: raise QAPISemError( info, "'if' condition [] of %s is useless" % source) =20 + if oper =3D=3D "not": + _check_if(operands) + return if oper in ("all", "any") and not isinstance(operands, list): raise QAPISemError( info, "'%s' condition of %s must be a list" % (oper, sourc= e)) diff --git a/tests/qapi-schema/bad-if-key.err b/tests/qapi-schema/bad-if-ke= y.err index 7236f46e7a..a69dc9ee86 100644 --- a/tests/qapi-schema/bad-if-key.err +++ b/tests/qapi-schema/bad-if-key.err @@ -1,3 +1,3 @@ bad-if-key.json: In struct 'TestIfStruct': bad-if-key.json:2: 'if' condition has unknown key 'value' -Valid keys are 'all', 'any'. +Valid keys are 'all', 'any', 'not'. diff --git a/tests/qapi-schema/bad-if-keys.err b/tests/qapi-schema/bad-if-k= eys.err index db6d019d77..aceb31dc6d 100644 --- a/tests/qapi-schema/bad-if-keys.err +++ b/tests/qapi-schema/bad-if-keys.err @@ -1,2 +1,2 @@ bad-if-keys.json: In struct 'TestIfStruct': -bad-if-keys.json:2: 'if' condition dict of struct must have one key: 'all'= or 'any' +bad-if-keys.json:2: 'if' condition dict of struct must have one key: 'all'= , 'any' or 'not' diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index e253d89ee0..2a35c679a4 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -126,7 +126,8 @@ ## { 'alternate': 'Alternate', 'features': [ 'alt-feat' ], - 'data': { 'i': 'int', 'b': 'bool' } } + 'data': { 'i': 'int', 'b': 'bool' }, + 'if': { 'not': 'IFNOT' } } =20 ## # =3D=3D Another subsection diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index c44c346ec8..a8871e8f99 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -51,6 +51,7 @@ alternate Alternate tag type case i: int case b: bool + if OrderedDict([('not', 'IFNOT')]) feature alt-feat object q_obj_cmd-arg member arg1: int optional=3DFalse diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt index 251e9b746c..03c98c4182 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -171,6 +171,12 @@ Features a feature =20 =20 +If +~~ + +"!IFNOT" + + Another subsection =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/tests/qapi-schema/enum-if-invalid.err b/tests/qapi-schema/enum= -if-invalid.err index b96d94c48a..3bb84075a9 100644 --- a/tests/qapi-schema/enum-if-invalid.err +++ b/tests/qapi-schema/enum-if-invalid.err @@ -1,3 +1,3 @@ enum-if-invalid.json: In enum 'TestIfEnum': enum-if-invalid.json:2: 'if' condition has unknown key 'val' -Valid keys are 'all', 'any'. +Valid keys are 'all', 'any', 'not'. diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 5e3dbc0f72..1b3311ce89 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -244,7 +244,7 @@ 'if': { 'all': ['defined(TEST_IF_ALT)', 'defined(TEST_IF_STRUCT)'] } } =20 { 'command': 'test-if-alternate-cmd', 'data': { 'alt-cmd-arg': 'TestIfAlte= rnate' }, - 'if': { 'all': ['defined(TEST_IF_ALT)'] } } + 'if': { 'all': ['defined(TEST_IF_ALT)', {'not': 'defined(TEST_IF_NOT_ALT= )'}] } } =20 { 'command': 'test-if-cmd', 'data': { diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index e5625f2542..df2c57de54 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -333,10 +333,10 @@ alternate TestIfAlternate if OrderedDict([('all', ['defined(TEST_IF_ALT)', 'defined(TEST_IF_STRU= CT)'])]) object q_obj_test-if-alternate-cmd-arg member alt-cmd-arg: TestIfAlternate optional=3DFalse - if OrderedDict([('all', ['defined(TEST_IF_ALT)'])]) + if OrderedDict([('all', ['defined(TEST_IF_ALT)', OrderedDict([('not', = 'defined(TEST_IF_NOT_ALT)')])])]) command test-if-alternate-cmd q_obj_test-if-alternate-cmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if OrderedDict([('all', ['defined(TEST_IF_ALT)'])]) + if OrderedDict([('all', ['defined(TEST_IF_ALT)', OrderedDict([('not', = 'defined(TEST_IF_NOT_ALT)')])])]) object q_obj_test-if-cmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse --=20 2.32.0.264.g75ae10bc75