From nobody Mon Apr 29 13:08:50 2024 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 1630416017717135.94609525787166; Tue, 31 Aug 2021 06:20:17 -0700 (PDT) Received: from localhost ([::1]:33548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3gW-0003QI-6O for importer@patchew.org; Tue, 31 Aug 2021 09:20:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL324-0006Km-IB for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50311) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL31z-0005Ij-UV for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:28 -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-125-YNA3zOUoPlS2-H_BrUb_6Q-1; Tue, 31 Aug 2021 08:38:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F127100A606; Tue, 31 Aug 2021 12:38:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C11BD17AC5; Tue, 31 Aug 2021 12:38:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5A2B611380AA; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413502; 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=xWGQV+GEFCOHg6ei19E8OzrRJoAl+B6mOLDxJEKR7jE=; b=C1NxcrIVagGMAVxlVMCLHhLdGXR8KTJvYm5esIQXF6SwPoVTFh7koKZPVeYVt0m7TILl38 gj79eoOM/4tNHnLlDK2Up6CM60UXtqoU40FCmZHwj3Ri38s3b291Y0hAAACdyJnvN8lnN9 SqyF5SYAIG7XjSotLdSLvT7mV7EVTqQ= X-MC-Unique: YNA3zOUoPlS2-H_BrUb_6Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 01/12] qapi: Simplify QAPISchemaIfCond's interface for generating C Date: Tue, 31 Aug 2021 14:37:58 +0200 Message-Id: <20210831123809.1107782-2-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630416018728100001 Content-Type: text/plain; charset="utf-8" QAPISchemaIfCond.cgen() is only ever used like gen_if(ifcond.cgen()) and gen_endif(ifcond.cgen()) Simplify to ifcond.gen_if() and ifcond.gen_endif() Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/gen.py | 6 ++---- scripts/qapi/introspect.py | 6 ++---- scripts/qapi/schema.py | 10 +++++++++- scripts/qapi/types.py | 22 ++++++++++------------ scripts/qapi/visit.py | 14 ++++++-------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 51a597a025..ab26d5c937 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -24,8 +24,6 @@ from .common import ( c_fname, c_name, - gen_endif, - gen_if, guardend, guardstart, mcgen, @@ -95,9 +93,9 @@ def _wrap_ifcond(ifcond: QAPISchemaIfCond, before: str, a= fter: str) -> str: if added[0] =3D=3D '\n': out +=3D '\n' added =3D added[1:] - out +=3D gen_if(ifcond.cgen()) + out +=3D ifcond.gen_if() out +=3D added - out +=3D gen_endif(ifcond.cgen()) + out +=3D ifcond.gen_endif() return out =20 =20 diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index bd4233ecee..548bb29961 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -24,8 +24,6 @@ =20 from .common import ( c_name, - gen_endif, - gen_if, mcgen, ) from .gen import QAPISchemaMonolithicCVisitor @@ -124,10 +122,10 @@ def indent(level: int) -> str: if obj.comment: ret +=3D indent(level) + f"/* {obj.comment} */\n" if obj.ifcond.is_present(): - ret +=3D gen_if(obj.ifcond.cgen()) + ret +=3D obj.ifcond.gen_if() ret +=3D _tree_to_qlit(obj.value, level) if obj.ifcond.is_present(): - ret +=3D '\n' + gen_endif(obj.ifcond.cgen()) + ret +=3D '\n' + obj.ifcond.gen_endif() return ret =20 ret =3D '' diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 229d24fce9..1451cdec81 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -24,6 +24,8 @@ c_name, cgen_ifcond, docgen_ifcond, + gen_endif, + gen_if, ) from .error import QAPIError, QAPISemError, QAPISourceError from .expr import check_exprs @@ -34,9 +36,15 @@ class QAPISchemaIfCond: def __init__(self, ifcond=3DNone): self.ifcond =3D ifcond or {} =20 - def cgen(self): + def _cgen(self): return cgen_ifcond(self.ifcond) =20 + def gen_if(self): + return gen_if(self._cgen()) + + def gen_endif(self): + return gen_endif(self._cgen()) + def docgen(self): return docgen_ifcond(self.ifcond) =20 diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index db9ff95bd1..b358dbbc8d 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -18,8 +18,6 @@ from .common import ( c_enum_const, c_name, - gen_endif, - gen_if, mcgen, ) from .gen import QAPISchemaModularCVisitor, ifcontext @@ -51,13 +49,13 @@ def gen_enum_lookup(name: str, ''', c_name=3Dc_name(name)) for memb in members: - ret +=3D gen_if(memb.ifcond.cgen()) + ret +=3D memb.ifcond.gen_if() index =3D c_enum_const(name, memb.name, prefix) ret +=3D mcgen(''' [%(index)s] =3D "%(name)s", ''', index=3Dindex, name=3Dmemb.name) - ret +=3D gen_endif(memb.ifcond.cgen()) + ret +=3D memb.ifcond.gen_endif() =20 ret +=3D mcgen(''' }, @@ -81,12 +79,12 @@ def gen_enum(name: str, c_name=3Dc_name(name)) =20 for memb in enum_members: - ret +=3D gen_if(memb.ifcond.cgen()) + ret +=3D memb.ifcond.gen_if() ret +=3D mcgen(''' %(c_enum)s, ''', c_enum=3Dc_enum_const(name, memb.name, prefix)) - ret +=3D gen_endif(memb.ifcond.cgen()) + ret +=3D memb.ifcond.gen_endif() =20 ret +=3D mcgen(''' } %(c_name)s; @@ -126,7 +124,7 @@ def gen_array(name: str, element_type: QAPISchemaType) = -> str: def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str: ret =3D '' for memb in members: - ret +=3D gen_if(memb.ifcond.cgen()) + ret +=3D memb.ifcond.gen_if() if memb.optional: ret +=3D mcgen(''' bool has_%(c_name)s; @@ -136,7 +134,7 @@ def gen_struct_members(members: List[QAPISchemaObjectTy= peMember]) -> str: %(c_type)s %(c_name)s; ''', c_type=3Dmemb.type.c_type(), c_name=3Dc_name(memb.nam= e)) - ret +=3D gen_endif(memb.ifcond.cgen()) + ret +=3D memb.ifcond.gen_endif() return ret =20 =20 @@ -159,7 +157,7 @@ def gen_object(name: str, ifcond: QAPISchemaIfCond, ret +=3D mcgen(''' =20 ''') - ret +=3D gen_if(ifcond.cgen()) + ret +=3D ifcond.gen_if() ret +=3D mcgen(''' struct %(c_name)s { ''', @@ -193,7 +191,7 @@ def gen_object(name: str, ifcond: QAPISchemaIfCond, ret +=3D mcgen(''' }; ''') - ret +=3D gen_endif(ifcond.cgen()) + ret +=3D ifcond.gen_endif() =20 return ret =20 @@ -220,13 +218,13 @@ def gen_variants(variants: QAPISchemaVariants) -> str: for var in variants.variants: if var.type.name =3D=3D 'q_empty': continue - ret +=3D gen_if(var.ifcond.cgen()) + ret +=3D var.ifcond.gen_if() ret +=3D mcgen(''' %(c_type)s %(c_name)s; ''', c_type=3Dvar.type.c_unboxed_type(), c_name=3Dc_name(var.name)) - ret +=3D gen_endif(var.ifcond.cgen()) + ret +=3D var.ifcond.gen_endif() =20 ret +=3D mcgen(''' } u; diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 56ea516399..9d9196a143 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -18,8 +18,6 @@ from .common import ( c_enum_const, c_name, - gen_endif, - gen_if, indent, mcgen, ) @@ -79,7 +77,7 @@ def gen_visit_object_members(name: str, =20 for memb in members: deprecated =3D 'deprecated' in [f.name for f in memb.features] - ret +=3D gen_if(memb.ifcond.cgen()) + ret +=3D memb.ifcond.gen_if() if memb.optional: ret +=3D mcgen(''' if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) { @@ -112,7 +110,7 @@ def gen_visit_object_members(name: str, ret +=3D mcgen(''' } ''') - ret +=3D gen_endif(memb.ifcond.cgen()) + ret +=3D memb.ifcond.gen_endif() =20 if variants: tag_member =3D variants.tag_member @@ -126,7 +124,7 @@ def gen_visit_object_members(name: str, for var in variants.variants: case_str =3D c_enum_const(tag_member.type.name, var.name, tag_member.type.prefix) - ret +=3D gen_if(var.ifcond.cgen()) + ret +=3D var.ifcond.gen_if() if var.type.name =3D=3D 'q_empty': # valid variant and nothing to do ret +=3D mcgen(''' @@ -142,7 +140,7 @@ def gen_visit_object_members(name: str, case=3Dcase_str, c_type=3Dvar.type.c_name(), c_name=3Dc_name(v= ar.name)) =20 - ret +=3D gen_endif(var.ifcond.cgen()) + ret +=3D var.ifcond.gen_endif() ret +=3D mcgen(''' default: abort(); @@ -228,7 +226,7 @@ def gen_visit_alternate(name: str, variants: QAPISchema= Variants) -> str: c_name=3Dc_name(name)) =20 for var in variants.variants: - ret +=3D gen_if(var.ifcond.cgen()) + ret +=3D var.ifcond.gen_if() ret +=3D mcgen(''' case %(case)s: ''', @@ -254,7 +252,7 @@ def gen_visit_alternate(name: str, variants: QAPISchema= Variants) -> str: ret +=3D mcgen(''' break; ''') - ret +=3D gen_endif(var.ifcond.cgen()) + ret +=3D var.ifcond.gen_endif() =20 ret +=3D mcgen(''' case QTYPE_NONE: --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630414901214509.08138772144673; Tue, 31 Aug 2021 06:01:41 -0700 (PDT) Received: from localhost ([::1]:46928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3OV-0004to-MD for importer@patchew.org; Tue, 31 Aug 2021 09:01:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL320-0006Bz-Lw for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL31t-0005H8-SX for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38: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-57-Mk-k26aHO3GgDwHGvuvhZw-1; Tue, 31 Aug 2021 08:38:15 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B9D4587D544; Tue, 31 Aug 2021 12:38:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C16C55C1A1; Tue, 31 Aug 2021 12:38:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5D3CD11380AB; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413497; 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=yFEDXDp0O25wsKpIqB8UamfFaX89vtmvEvtMEieyWZQ=; b=Vp/CRhdVpK20dUIw+ucnzgcjBXeESp/AmAtpKWn98qqCRaKe6oAKNW59i9629CfcQnS8C0 /mlSPCE9FJPs+ILFzGNHIVI2rT3FvPXZzrawa+x8E/WC/Y2CR86pcGHeSpE+zTiw0Fm9d+ I0hwFTGnw59MBe9Z8B/GXzujNsaKe88= X-MC-Unique: Mk-k26aHO3GgDwHGvuvhZw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 02/12] qapi: Simplify how QAPISchemaIfCond represents "no condition" Date: Tue, 31 Aug 2021 14:37:59 +0200 Message-Id: <20210831123809.1107782-3-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630414918982100001 Content-Type: text/plain; charset="utf-8" None works fine, there is no need to replace it by {} in .__init__(). Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 4 ++-- scripts/qapi/schema.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 1724ac32db..1c1dc87ccb 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -200,7 +200,7 @@ def guardend(name: str) -> str: name=3Dc_fname(name).upper()) =20 =20 -def cgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -> str: +def cgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str: if not ifcond: return '' if isinstance(ifcond, str): @@ -214,7 +214,7 @@ def cgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -> = str: return '(' + (') ' + oper + ' (').join(operands) + ')' =20 =20 -def docgen_ifcond(ifcond: Union[str, Dict[str, Any]]) -> str: +def docgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str: # TODO Doc generated for conditions needs polish if not ifcond: return '' diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 1451cdec81..3d72c7dfc9 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -34,7 +34,7 @@ =20 class QAPISchemaIfCond: def __init__(self, ifcond=3DNone): - self.ifcond =3D ifcond or {} + self.ifcond =3D ifcond =20 def _cgen(self): return cgen_ifcond(self.ifcond) --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630415574186669.0548646522661; Tue, 31 Aug 2021 06:12:54 -0700 (PDT) Received: from localhost ([::1]:43800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3ZN-0005je-1c for importer@patchew.org; Tue, 31 Aug 2021 09:12:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL322-0006H7-Dh for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL31z-0005IR-63 for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:26 -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-603-p9Xl7OYjPbyYQsvd7z53RQ-1; Tue, 31 Aug 2021 08:38:19 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88D4B192FDA2; Tue, 31 Aug 2021 12:38:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C17CC5DA2D; Tue, 31 Aug 2021 12:38:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 608FB11380B0; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413501; 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=R2zPZGxgMrBJEV+cKwF/OfDnS5JDVY1jTf755tcMGXA=; b=cjQbV353nvUP6Q1IWooIntchQpalLLxAiIuvh/cjP3K/w83+U9qvzOfLD0bqm/crNU/TIc WMhbSso7/l5yw3nlbfUYqdu8NYvZMvJ7jYz21FpA5v2TzTCyLYJMIFZvT0js7SbKZFIqPp zullqgw1vr+P0Sdvzg5JPiz7Uft7Rhk= X-MC-Unique: p9Xl7OYjPbyYQsvd7z53RQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 03/12] tests/qapi-schema: Correct two 'if' conditionals Date: Tue, 31 Aug 2021 14:38:00 +0200 Message-Id: <20210831123809.1107782-4-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630415575961100001 Content-Type: text/plain; charset="utf-8" A definition's conditional should imply the conditionals of types it uses. If it doesn't, some configurations won't compile. Example (from tests/qapi-schema/qapi-schema-test.json): { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct', 'bar': { 'type': 'str', 'if': 'TEST_IF_UNION_BAR'} }, 'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } } { 'command': 'test-if-union-cmd', 'data': { 'union-cmd-arg': 'TestIfUnion' }, 'if': 'TEST_IF_UNION' } generates #if (defined(TEST_IF_UNION)) && (defined(TEST_IF_STRUCT)) typedef struct TestIfUnion TestIfUnion; #endif /* (defined(TEST_IF_UNION)) && (defined(TEST_IF_STRUCT)) */ and #if defined(TEST_IF_UNION) void qmp_test_if_union_cmd(TestIfUnion *union_cmd_arg, Error **errp); void qmp_marshal_test_if_union_cmd(QDict *args, QObject **ret, Error **= errp); #endif /* defined(TEST_IF_UNION) */ which doesn't compile when !defined(TEST_IF_STRUCT). Messed up in f8c4fdd6ae "tests/qapi: Cover commands with 'if' and union / alternate 'data'", v4.0.0. Harmless, as we don't actually use this configuration. Correct it anyway, along with another instance. This loses coverage for 'not'. The next commit will bring it back. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/qapi-schema/qapi-schema-test.json | 5 ++--- tests/qapi-schema/qapi-schema-test.out | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index fe028145e4..e20f76d84c 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -236,7 +236,7 @@ =20 { 'command': 'test-if-union-cmd', 'data': { 'union-cmd-arg': 'TestIfUnion' }, - 'if': 'TEST_IF_UNION' } + 'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } } =20 { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', @@ -245,8 +245,7 @@ =20 { 'command': 'test-if-alternate-cmd', 'data': { 'alt-cmd-arg': 'TestIfAlternate' }, - 'if': { 'all': ['TEST_IF_ALT', - {'not': 'TEST_IF_NOT_ALT'}] } } + 'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } } =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 3d0c6a8f28..517d802636 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -321,10 +321,10 @@ object TestIfUnion if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])]) object q_obj_test-if-union-cmd-arg member union-cmd-arg: TestIfUnion optional=3DFalse - if TEST_IF_UNION + if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])]) command test-if-union-cmd q_obj_test-if-union-cmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if TEST_IF_UNION + if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])]) alternate TestIfAlternate tag type case foo: int @@ -333,10 +333,10 @@ alternate TestIfAlternate if OrderedDict([('all', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])]) object q_obj_test-if-alternate-cmd-arg member alt-cmd-arg: TestIfAlternate optional=3DFalse - if OrderedDict([('all', ['TEST_IF_ALT', OrderedDict([('not', 'TEST_IF_= NOT_ALT')])])]) + if OrderedDict([('all', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])]) 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', ['TEST_IF_ALT', OrderedDict([('not', 'TEST_IF_= NOT_ALT')])])]) + if OrderedDict([('all', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])]) object q_obj_test-if-cmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630415184997998.6927688940684; Tue, 31 Aug 2021 06:06:24 -0700 (PDT) Received: from localhost ([::1]:55190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3T6-0002Gh-0P for importer@patchew.org; Tue, 31 Aug 2021 09:06:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL322-0006GZ-84 for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42984) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL31v-0005HO-R8 for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:25 -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-587-5JkFQFPBMA6cMve68UK2iw-1; Tue, 31 Aug 2021 08:38:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6906100A608; Tue, 31 Aug 2021 12:38:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C210560C05; Tue, 31 Aug 2021 12:38:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 63FF411380B7; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413499; 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=bFvsBkcFT4H4soWc1V+8KZlldijQR+OHyOKtf+J+1NE=; b=O+tgwwjEiEoRjty3pEitPWpC0CdyKUy1ZlkZJ5TCvCcV1ff+rjDy61n7PkIqBpa6MNNOSf V+Mjg5BXVDPgI7X4uWkLHJFpVS9nReV+Wz5a/A0T4fBRmgIiBytwMVrdXUEjjFiZhoEk+q SM85I+uwM2w8kyRROSnurKy1g5j2ecc= X-MC-Unique: 5JkFQFPBMA6cMve68UK2iw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 04/12] tests/qapi-schema: Demonstrate broken C code for 'if' Date: Tue, 31 Aug 2021 14:38:01 +0200 Message-Id: <20210831123809.1107782-5-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630415199188100001 Content-Type: text/plain; charset="utf-8" The C code generated for 'if' conditionals is incorrectly parenthesized. For instance, 'if': { 'not': { 'any': [ { 'not': 'TEST_IF_EVT' }, { 'not': 'TEST_IF_STRUCT' } ] } } } generates #if !(!defined(TEST_IF_EVT)) || (!defined(TEST_IF_STRUCT)) This is wrong. Correct would be: #if !(!defined(TEST_IF_EVT) || !defined(TEST_IF_STRUCT)) Cover the issue in qapi-schema-test.json. This generates bad #if in tests/test-qapi-events.h and other files. Add a similar condition to doc-good.json. The generated documentation is fine. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/qapi-schema/doc-good.json | 2 +- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/doc-good.txt | 2 +- tests/qapi-schema/qapi-schema-test.json | 5 +++++ tests/qapi-schema/qapi-schema-test.out | 3 +++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index 5e30790730..e0027e4cf6 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -127,7 +127,7 @@ { 'alternate': 'Alternate', 'features': [ 'alt-feat' ], 'data': { 'i': 'int', 'b': 'bool' }, - 'if': { 'not': 'IFNOT' } } + 'if': { 'not': { 'any': [ 'IFONE', 'IFTWO' ] } } } =20 ## # =3D=3D Another subsection diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 26d1fa5d28..d72f3047e9 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -51,7 +51,7 @@ alternate Alternate tag type case i: int case b: bool - if OrderedDict([('not', 'IFNOT')]) + if OrderedDict([('not', OrderedDict([('any', ['IFONE', 'IFTWO'])]))]) 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 5bfe06e14e..85a370831f 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -174,7 +174,7 @@ Features If ~~ =20 -"!IFNOT" +"!(IFONE or IFTWO)" =20 =20 Another subsection diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index e20f76d84c..6e37758280 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -261,6 +261,11 @@ 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } }, 'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } } =20 +{ 'event': 'TEST_IF_EVENT2', 'data': {}, + # FIXME C #if generated for this conditional is wrong + 'if': { 'not': { 'any': [ { 'not': 'TEST_IF_EVT' }, + { 'not': 'TEST_IF_STRUCT' } ] } } } + # test 'features' =20 { 'struct': 'FeatureStruct0', diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 517d802636..5d2e830ba2 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -357,6 +357,9 @@ object q_obj_TEST_IF_EVENT-arg event TEST_IF_EVENT q_obj_TEST_IF_EVENT-arg boxed=3DFalse if OrderedDict([('all', ['TEST_IF_EVT', 'TEST_IF_STRUCT'])]) +event TEST_IF_EVENT2 None + boxed=3DFalse + if OrderedDict([('not', OrderedDict([('any', [OrderedDict([('not', 'TE= ST_IF_EVT')]), OrderedDict([('not', 'TEST_IF_STRUCT')])])]))]) object FeatureStruct0 member foo: int optional=3DFalse object FeatureStruct1 --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630415090834453.87568681841856; Tue, 31 Aug 2021 06:04:50 -0700 (PDT) Received: from localhost ([::1]:52948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3RZ-0000il-P0 for importer@patchew.org; Tue, 31 Aug 2021 09:04:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL320-0006CG-NU for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51061) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL31v-0005HE-Hm for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38: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-229-p_uhmookM1WRzVGscGuEvw-1; Tue, 31 Aug 2021 08:38:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85409800482; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5692A60843; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6734A11380B8; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413498; 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=XvX/Fcp8izS8QsWpJYrqwWZ+/3PfxlDf+ifAUYDULww=; b=PRPXQLijdFKVC/xmnhAe3RmCsssBK0p0uvVGVJlyf5mCOGHly6N1WIej1k/RHl8LED2y5k MvauKH85JNL1RLsQ8cDmVnoO/flX9hfYfHhO2SfBeaqlXCQDijI0hALGMU27AxQCZDseCO pD4TsoclY9Q7EW/9z0/eTGtw7kXRazY= X-MC-Unique: p_uhmookM1WRzVGscGuEvw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 05/12] qapi: Fix C code generation for 'if' Date: Tue, 31 Aug 2021 14:38:02 +0200 Message-Id: <20210831123809.1107782-6-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630415112065100001 Content-Type: text/plain; charset="utf-8" When commit 5d83b9a130 "qapi: replace if condition list with dict {'all': [...]}" made cgen_ifcond() and docgen_ifcond() recursive, it messed up parenthesises in the former, and got them right in the latter, as the previous commit demonstrates. To fix, adopt the latter's working code for the former. This generates the correct code from the previous commit's commit message. Fixes: 5d83b9a130690f879d5f33e991beabe69cb88bc8 Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 4 ++-- tests/qapi-schema/qapi-schema-test.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 1c1dc87ccb..f31e077d7b 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -209,9 +209,9 @@ def cgen_ifcond(ifcond: Optional[Union[str, Dict[str, A= ny]]]) -> str: oper, operands =3D next(iter(ifcond.items())) if oper =3D=3D 'not': return '!' + cgen_ifcond(operands) - oper =3D {'all': '&&', 'any': '||'}[oper] + oper =3D {'all': ' && ', 'any': ' || '}[oper] operands =3D [cgen_ifcond(o) for o in operands] - return '(' + (') ' + oper + ' (').join(operands) + ')' + return '(' + oper.join(operands) + ')' =20 =20 def docgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str: diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 6e37758280..b6c36a9eee 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -262,7 +262,6 @@ 'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } } =20 { 'event': 'TEST_IF_EVENT2', 'data': {}, - # FIXME C #if generated for this conditional is wrong 'if': { 'not': { 'any': [ { 'not': 'TEST_IF_EVT' }, { 'not': 'TEST_IF_STRUCT' } ] } } } =20 --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630414681123175.22227709312028; Tue, 31 Aug 2021 05:58:01 -0700 (PDT) Received: from localhost ([::1]:38238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3Kx-0007Vv-QL for importer@patchew.org; Tue, 31 Aug 2021 08:57:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL320-0006CF-KJ for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55941) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL31v-0005HF-IX for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:23 -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-598-T_fNsC6PPTuYj7TYKc7ddw-1; Tue, 31 Aug 2021 08:38:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 846D2801B3D; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 568C260C05; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6A99F11380B9; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413498; 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=Wm69j6/CFRxwgaYQ+Xy6zXix5cpMlAE3PNNbisLdhjY=; b=bAdm2InM6Zhkr2n5f4X8Jpet12ZTkSChEjYLO9SYCMyBV3qzxGldNNoyeB0tjdFbjq65mI T6I3NQziAp33WqKAhZSp0lkpXE7LmeZis8yQ2iw57wAgaIJagOLWaYjvXwkO588wRbajSf gUUXFATFAPlm/HFHOrrR4t0TI8h0dUE= X-MC-Unique: T_fNsC6PPTuYj7TYKc7ddw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 06/12] qapi: Factor common recursion out of cgen_ifcond(), docgen_ifcond() Date: Tue, 31 Aug 2021 14:38:03 +0200 Message-Id: <20210831123809.1107782-7-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630414682876100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 45 +++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index f31e077d7b..df92cff852 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -17,6 +17,7 @@ Dict, Match, Optional, + Sequence, Union, ) =20 @@ -200,33 +201,37 @@ def guardend(name: str) -> str: name=3Dc_fname(name).upper()) =20 =20 -def cgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str: +def gen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]], + cond_fmt: str, not_fmt: str, + all_operator: str, any_operator: str) -> str: + + def do_gen(ifcond: Union[str, Dict[str, Any]]): + if isinstance(ifcond, str): + return cond_fmt % ifcond + assert isinstance(ifcond, dict) and len(ifcond) =3D=3D 1 + if 'not' in ifcond: + return not_fmt % do_gen(ifcond['not']) + if 'all' in ifcond: + gen =3D gen_infix(all_operator, ifcond['all']) + else: + gen =3D gen_infix(any_operator, ifcond['any']) + return gen + + def gen_infix(operator: str, operands: Sequence[Any]) -> str: + return '(' + operator.join([do_gen(o) for o in operands]) + ')' + if not ifcond: return '' - if isinstance(ifcond, str): - return 'defined(' + ifcond + ')' + return do_gen(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) + ')' + +def cgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str: + return gen_ifcond(ifcond, 'defined(%s)', '!%s', ' && ', ' || ') =20 =20 def docgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str: # TODO Doc generated for conditions needs polish - if not ifcond: - return '' - if isinstance(ifcond, str): - return ifcond - - 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) + ')' + return gen_ifcond(ifcond, '%s', '!%s', ' and ', ' or ') =20 =20 def gen_if(cond: str) -> str: --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630415786156941.1399124551824; Tue, 31 Aug 2021 06:16:26 -0700 (PDT) Received: from localhost ([::1]:52880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3cn-0004tc-64 for importer@patchew.org; Tue, 31 Aug 2021 09:16:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL320-0006CI-LF for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26853) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL31y-0005IN-1Y for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:23 -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-229-J_MNJznxNCCoi_gmi9lEsg-1; Tue, 31 Aug 2021 08:38:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87115802920; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56C5860CA0; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6DE4D11380BA; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413500; 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=Hd91u5E04t1VmcfaDpmv7bPokygiedERw8tBibtAcp8=; b=Jb9hD48FDD4e2adBntOLu+muOrx9JN0/fbBswl3pFvGsLZkobOrSyq7bEsa5BC+7maJx7s 8jVcncs9w2P8K1Vn0QqGAFNB/larRK8NCoXTbLPlkGTL9GjSmGFsesFahVbgVycuTICdsq 7cRE/ZIg+M+PlXeLKmgPf9pwXpvZhyc= X-MC-Unique: J_MNJznxNCCoi_gmi9lEsg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 07/12] qapi: Avoid redundant parens in code generated for conditionals Date: Tue, 31 Aug 2021 14:38:04 +0200 Message-Id: <20210831123809.1107782-8-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, WEIRD_QUOTING=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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630415788000100001 Content-Type: text/plain; charset="utf-8" Commit 6cc2e4817f "qapi: introduce QAPISchemaIfCond.cgen()" caused a minor regression: redundant parenthesis. Subsequent commits eliminated of many of them, but not all. Get rid of the rest now. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 10 ++++++---- tests/qapi-schema/doc-good.txt | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index df92cff852..c7ccc7cec7 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -205,24 +205,26 @@ def gen_ifcond(ifcond: Optional[Union[str, Dict[str, = Any]]], cond_fmt: str, not_fmt: str, all_operator: str, any_operator: str) -> str: =20 - def do_gen(ifcond: Union[str, Dict[str, Any]]): + def do_gen(ifcond: Union[str, Dict[str, Any]], need_parens: bool): if isinstance(ifcond, str): return cond_fmt % ifcond assert isinstance(ifcond, dict) and len(ifcond) =3D=3D 1 if 'not' in ifcond: - return not_fmt % do_gen(ifcond['not']) + return not_fmt % do_gen(ifcond['not'], True) if 'all' in ifcond: gen =3D gen_infix(all_operator, ifcond['all']) else: gen =3D gen_infix(any_operator, ifcond['any']) + if need_parens: + gen =3D '(' + gen + ')' return gen =20 def gen_infix(operator: str, operands: Sequence[Any]) -> str: - return '(' + operator.join([do_gen(o) for o in operands]) + ')' + return operator.join([do_gen(o, True) for o in operands]) =20 if not ifcond: return '' - return do_gen(ifcond) + return do_gen(ifcond, False) =20 =20 def cgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str: diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt index 85a370831f..75f51a6fc1 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -79,7 +79,7 @@ Members If ~~ =20 -"(IFALL1 and IFALL2)" +"IFALL1 and IFALL2" =20 =20 "Variant1" (Object) @@ -120,8 +120,8 @@ Members =20 The members of "Base" The members of "Variant1" when "base1" is ""one"" -The members of "Variant2" when "base1" is ""two"" (**If: **"(IFONE or -IFTWO)") +The members of "Variant2" when "base1" is ""two"" (**If: **"IFONE or +IFTWO") =20 Features ~~~~~~~~ --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630415362049782.3124185576153; Tue, 31 Aug 2021 06:09:22 -0700 (PDT) Received: from localhost ([::1]:35308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3Vw-00085b-Lt for importer@patchew.org; Tue, 31 Aug 2021 09:09:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL322-0006Gr-B7 for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL31y-0005IT-6s for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:26 -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-229-yYAFj-2lNG6FHFcwQTEoww-1; Tue, 31 Aug 2021 08:38:17 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85FED101C8A5; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56B6C18026; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7117411380BC; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413501; 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=FVdFY72iIBkVxdZ7AtGMjN5xqVD2yFwsnpGAo8vVbzU=; b=M0YSnSXSSCPOJu1zJEEvONtjdVzMZ7lir2Fl8+ir5QZlkT4TTyryTxQvY6KglBqH8JPNzU t5KAtWcIcKb1zfdvbwt74+nx18DBE+rxY5u0FYTJoOGq1bE6R4XXrPaZvjEmsBpUlbGvOS eQR1tFtFKTQ7ivDe6G5gr7Ehy1AHb5k= X-MC-Unique: yYAFj-2lNG6FHFcwQTEoww-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 08/12] qapi: Use "not COND" instead of "!COND" for generated documentation Date: Tue, 31 Aug 2021 14:38:05 +0200 Message-Id: <20210831123809.1107782-9-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630415363556100001 Content-Type: text/plain; charset="utf-8" Generated documentation uses operators "and", "or", and "!". Change the latter to "not". Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 2 +- tests/qapi-schema/doc-good.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c7ccc7cec7..5f8f76e5b2 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -233,7 +233,7 @@ def cgen_ifcond(ifcond: Optional[Union[str, Dict[str, A= ny]]]) -> str: =20 def docgen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]]) -> str: # TODO Doc generated for conditions needs polish - return gen_ifcond(ifcond, '%s', '!%s', ' and ', ' or ') + return gen_ifcond(ifcond, '%s', 'not %s', ' and ', ' or ') =20 =20 def gen_if(cond: str) -> str: diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt index 75f51a6fc1..0c59d75964 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -174,7 +174,7 @@ Features If ~~ =20 -"!(IFONE or IFTWO)" +"not (IFONE or IFTWO)" =20 =20 Another subsection --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630415778382924.9109011572658; Tue, 31 Aug 2021 06:16:18 -0700 (PDT) Received: from localhost ([::1]:52564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3cf-0004bE-8v for importer@patchew.org; Tue, 31 Aug 2021 09:16:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL324-0006Kl-4g for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29645) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL320-0005Id-1N for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:27 -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-461-udoH1j5kM6CTX410LZhA6w-1; Tue, 31 Aug 2021 08:38:20 -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 751F8101C8A8; Tue, 31 Aug 2021 12:38:19 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 839211001281; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7459811380C3; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413501; 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=ovxuR2ah9yPcxyn+fEI8RTgztaORi1wQSRvQawOSfFM=; b=I/HqateZgyzvAILzkOb3xC+XCgo5KgDLegWp2RcqFdVrLPGBZK/bEEfAeQXB1muGzWhUG1 Ctlq7ZOoxp2TcpX5nzEz8JkNjKk4mQzqPCG/Z+L1ab6js+kM2caNyFFxaYPtwIntw6DL0m zGWel8lGSFZ/AxnsWLNmiGz9wefbdiw= X-MC-Unique: udoH1j5kM6CTX410LZhA6w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 09/12] qapi: Use re.fullmatch() where appropriate Date: Tue, 31 Aug 2021 14:38:06 +0200 Message-Id: <20210831123809.1107782-10-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@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=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630415779837100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/expr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 019f4c97aa..9e2aa1d43a 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -275,7 +275,7 @@ def check_if(expr: _JSONObject, info: QAPISourceInfo, s= ource: str) -> None: =20 def _check_if(cond: Union[str, object]) -> None: if isinstance(cond, str): - if not re.match(r'^[A-Z][A-Z0-9_]*$', cond): + if not re.fullmatch(r'[A-Z][A-Z0-9_]*', cond): raise QAPISemError( info, "'if' condition '%s' of %s is not a valid identifier" --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630416240116511.92294545891923; Tue, 31 Aug 2021 06:24:00 -0700 (PDT) Received: from localhost ([::1]:40954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3k6-00005x-Qr for importer@patchew.org; Tue, 31 Aug 2021 09:23:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL325-0006MC-ET for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27153) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL320-0005JQ-2V for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:29 -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-35-h7k3-06UPRWhLG9hM7Aq0g-1; Tue, 31 Aug 2021 08:38:21 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E79C92504; Tue, 31 Aug 2021 12:38:20 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8476F27CA8; Tue, 31 Aug 2021 12:38:16 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 79FEB11380CC; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413502; 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=f3JUYRbr5dZuubNYJzOj/7pOZ8Gtrknv+bcLtyOWrn4=; b=WHS028Z69J6nDSA+UcewIm04Wo31RK766eqTeaO9hy9v7EtlW/2NXfm6suLKbWdpvs/gwO bFtI2+Gm+LPtgaL2En7krqM8TTtPDT0QRHcQCg5ECveU7BQSWaHpDW4ZDkZHTbbHQkGt6U 8prMsSoVtgRoq/71O8ktBy4C0AtJeys= X-MC-Unique: h7k3-06UPRWhLG9hM7Aq0g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 10/12] tests/qapi-schema: Hide OrderedDict in test output Date: Tue, 31 Aug 2021 14:38:07 +0200 Message-Id: <20210831123809.1107782-11-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630416245291100003 Content-Type: text/plain; charset="utf-8" Since commit 5d83b9a130 "qapi: replace if condition list with dict {'all': [...]}", we represent if conditionals as trees consisting of OrderedDict, list and str. This results in less than legible test output. For instance: if OrderedDict([('not', OrderedDict([('any', [OrderedDict([('not', 'TES= T_IF_EVT')]), OrderedDict([('not', 'TEST_IF_STRUCT')])])]))]) We intend to replace OrderedDict by dict when we get Python 3.7, which will result in more legible output: if {'not': {'any': [{'not': 'TEST_IF_EVT'}, {'not': 'TEST_IF_STRUCT'}]}} Can't wait: put in a hack to get that now, with a comment to revert it when we replace OrderedDict. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/qapi-schema/doc-good.out | 6 +++--- tests/qapi-schema/qapi-schema-test.out | 30 +++++++++++++------------- tests/qapi-schema/test-qapi.py | 11 +++++++++- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index d72f3047e9..478fe6f82e 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -18,7 +18,7 @@ enum Enum feature enum-feat object Base member base1: Enum optional=3DFalse - if OrderedDict([('all', ['IFALL1', 'IFALL2'])]) + if {'all': ['IFALL1', 'IFALL2']} object Variant1 member var1: str optional=3DFalse if IFSTR @@ -30,7 +30,7 @@ object Object tag base1 case one: Variant1 case two: Variant2 - if OrderedDict([('any', ['IFONE', 'IFTWO'])]) + if {'any': ['IFONE', 'IFTWO']} feature union-feat1 object q_obj_Variant1-wrapper member data: Variant1 optional=3DFalse @@ -51,7 +51,7 @@ alternate Alternate tag type case i: int case b: bool - if OrderedDict([('not', OrderedDict([('any', ['IFONE', 'IFTWO'])]))]) + if {'not': {'any': ['IFONE', 'IFTWO']}} feature alt-feat object q_obj_cmd-arg member arg1: int optional=3DFalse diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 5d2e830ba2..d557fe2d89 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -311,40 +311,40 @@ enum TestIfUnionKind member foo member bar if TEST_IF_UNION_BAR - if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']} object TestIfUnion member type: TestIfUnionKind optional=3DFalse tag type case foo: q_obj_TestStruct-wrapper case bar: q_obj_str-wrapper if TEST_IF_UNION_BAR - if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']} object q_obj_test-if-union-cmd-arg member union-cmd-arg: TestIfUnion optional=3DFalse - if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']} command test-if-union-cmd q_obj_test-if-union-cmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']} alternate TestIfAlternate tag type case foo: int case bar: TestStruct if TEST_IF_ALT_BAR - if OrderedDict([('all', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']} object q_obj_test-if-alternate-cmd-arg member alt-cmd-arg: TestIfAlternate optional=3DFalse - if OrderedDict([('all', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']} 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', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']} object q_obj_test-if-cmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse if TEST_IF_CMD_BAR - if OrderedDict([('all', ['TEST_IF_CMD', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']} command test-if-cmd q_obj_test-if-cmd-arg -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if OrderedDict([('all', ['TEST_IF_CMD', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']} command test-cmd-return-def-three None -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse array TestIfEnumList TestIfEnum @@ -353,13 +353,13 @@ object q_obj_TEST_IF_EVENT-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnumList optional=3DFalse if TEST_IF_EVT_BAR - if OrderedDict([('all', ['TEST_IF_EVT', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT']} event TEST_IF_EVENT q_obj_TEST_IF_EVENT-arg boxed=3DFalse - if OrderedDict([('all', ['TEST_IF_EVT', 'TEST_IF_STRUCT'])]) + if {'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT']} event TEST_IF_EVENT2 None boxed=3DFalse - if OrderedDict([('not', OrderedDict([('any', [OrderedDict([('not', 'TE= ST_IF_EVT')]), OrderedDict([('not', 'TEST_IF_STRUCT')])])]))]) + if {'not': {'any': [{'not': 'TEST_IF_EVT'}, {'not': 'TEST_IF_STRUCT'}]= }} object FeatureStruct0 member foo: int optional=3DFalse object FeatureStruct1 @@ -392,11 +392,11 @@ object CondFeatureStruct2 object CondFeatureStruct3 member foo: int optional=3DFalse feature feature1 - if OrderedDict([('all', ['TEST_IF_COND_1', 'TEST_IF_COND_2'])]) + if {'all': ['TEST_IF_COND_1', 'TEST_IF_COND_2']} object CondFeatureStruct4 member foo: int optional=3DFalse feature feature1 - if OrderedDict([('any', ['TEST_IF_COND_1', 'TEST_IF_COND_2'])]) + if {'any': ['TEST_IF_COND_1', 'TEST_IF_COND_2']} enum FeatureEnum1 member eins member zwei @@ -447,7 +447,7 @@ command test-command-cond-features2 None -> None command test-command-cond-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if OrderedDict([('all', ['TEST_IF_COND_1', 'TEST_IF_COND_2'])]) + if {'all': ['TEST_IF_COND_1', 'TEST_IF_COND_2']} event TEST_EVENT_FEATURES0 FeatureStruct1 boxed=3DFalse event TEST_EVENT_FEATURES1 None diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index c92be2d086..73cffae2b6 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -94,8 +94,17 @@ def _print_variants(variants): =20 @staticmethod def _print_if(ifcond, indent=3D4): + # TODO Drop this hack after replacing OrderedDict by plain + # dict (requires Python 3.7) + def _massage(subcond): + if isinstance(subcond, str): + return subcond + if isinstance(subcond, list): + return [_massage(val) for val in subcond] + return {key: _massage(val) for key, val in subcond.items()} + if ifcond.is_present(): - print('%sif %s' % (' ' * indent, ifcond.ifcond)) + print('%sif %s' % (' ' * indent, _massage(ifcond.ifcond))) =20 @classmethod def _print_features(cls, features, indent=3D4): --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630416375810777.1929241150486; Tue, 31 Aug 2021 06:26:15 -0700 (PDT) Received: from localhost ([::1]:47336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3mI-0004VT-85 for importer@patchew.org; Tue, 31 Aug 2021 09:26:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL325-0006MD-FS for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL320-0005J8-2s for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:29 -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-356-ISIiYvdpNGqqfA95YXFAVA-1; Tue, 31 Aug 2021 08:38:21 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A682802935; Tue, 31 Aug 2021 12:38:20 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7BE72854F; Tue, 31 Aug 2021 12:38:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8370B11380CD; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413502; 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=ZqWP+eieEWexYZHvgLxsxLKjkjtAwocw+bS86M/PNKA=; b=GuIHvks+cvnRGHlNzVAZLFQoKILIgMTFo4z1Hg/YuANT+aZIM11c7L9rmKxMKgpVZQQlHq u2lJTlfNVBxd6LyhMoKuuXDZ2Rh/zH3yDMGmU1i052umyNYjfTH8VXQ7DXxypQ1R/dK5P8 i2sOLhmuRC21UgsKKSeLhXzy7uuqcvs= X-MC-Unique: ISIiYvdpNGqqfA95YXFAVA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 11/12] qapi: Tweak error messages for missing / conflicting meta-type Date: Tue, 31 Aug 2021 14:38:08 +0200 Message-Id: <20210831123809.1107782-12-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630416377870100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/expr.py | 23 +++++++++-------------- tests/qapi-schema/double-type.err | 4 +--- tests/qapi-schema/missing-type.err | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 9e2aa1d43a..ae4437ba08 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -630,20 +630,15 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JS= ONObject]: if 'include' in expr: continue =20 - if 'enum' in expr: - meta =3D 'enum' - elif 'union' in expr: - meta =3D 'union' - elif 'alternate' in expr: - meta =3D 'alternate' - elif 'struct' in expr: - meta =3D 'struct' - elif 'command' in expr: - meta =3D 'command' - elif 'event' in expr: - meta =3D 'event' - else: - raise QAPISemError(info, "expression is missing metatype") + metas =3D expr.keys() & {'enum', 'struct', 'union', 'alternate', + 'command', 'event'} + if len(metas) !=3D 1: + raise QAPISemError( + info, + "expression must have exactly one key" + " 'enum', 'struct', 'union', 'alternate'," + " 'command', 'event'") + meta =3D metas.pop() =20 check_name_is_str(expr[meta], info, "'%s'" % meta) name =3D cast(str, expr[meta]) diff --git a/tests/qapi-schema/double-type.err b/tests/qapi-schema/double-t= ype.err index 576e716197..6a1e8a5990 100644 --- a/tests/qapi-schema/double-type.err +++ b/tests/qapi-schema/double-type.err @@ -1,3 +1 @@ -double-type.json: In struct 'Bar': -double-type.json:2: struct has unknown key 'command' -Valid keys are 'base', 'data', 'features', 'if', 'struct'. +double-type.json:2: expression must have exactly one key 'enum', 'struct',= 'union', 'alternate', 'command', 'event' diff --git a/tests/qapi-schema/missing-type.err b/tests/qapi-schema/missing= -type.err index 5755386a18..cb39569e49 100644 --- a/tests/qapi-schema/missing-type.err +++ b/tests/qapi-schema/missing-type.err @@ -1 +1 @@ -missing-type.json:2: expression is missing metatype +missing-type.json:2: expression must have exactly one key 'enum', 'struct'= , 'union', 'alternate', 'command', 'event' --=20 2.31.1 From nobody Mon Apr 29 13:08:50 2024 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 1630415378934942.5765490445436; Tue, 31 Aug 2021 06:09:38 -0700 (PDT) Received: from localhost ([::1]:35872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL3WB-0008Tr-W0 for importer@patchew.org; Tue, 31 Aug 2021 09:09:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL325-0006MB-4G for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL320-0005JA-2s for qemu-devel@nongnu.org; Tue, 31 Aug 2021 08:38:28 -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-356-ZBwgHWqjP72rX-98DC_5sQ-1; Tue, 31 Aug 2021 08:38:21 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C584802936; Tue, 31 Aug 2021 12:38:20 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7B682854E; Tue, 31 Aug 2021 12:38:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8AEE511380D0; Tue, 31 Aug 2021 14:38:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630413502; 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=U8yOw0yF1G5J8N3g5oCHMFDIwtDx8fQKnMh712CuHCY=; b=SBgk0mzUMCNU1Niz2umSxOOWtbE6mkmV7zwbwNxJACjrpymoUXxg4I9YjLqXyMswgRvTxa +IZ+GiShu4NtS6blnlQJ5UHFDe/AhhtzZryUnWg6TioYUUBUPK3Ux7fRcjbghdrbeJpEiA /tSYvTUXRkU92pTouCsYvfZ7p+znMDc= X-MC-Unique: ZBwgHWqjP72rX-98DC_5sQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 12/12] qapi: Tweak error messages for unknown / conflicting 'if' keys Date: Tue, 31 Aug 2021 14:38:09 +0200 Message-Id: <20210831123809.1107782-13-armbru@redhat.com> In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com> References: <20210831123809.1107782-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, 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_H2=-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: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com 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: 1630415379942100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/expr.py | 7 +++---- tests/qapi-schema/bad-if-key.err | 2 +- tests/qapi-schema/bad-if-keys.err | 2 +- tests/qapi-schema/enum-if-invalid.err | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index ae4437ba08..b62f0a3640 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -286,13 +286,12 @@ def _check_if(cond: Union[str, object]) -> None: raise QAPISemError( info, "'if' condition of %s must be a string or an object" % sou= rce) + check_keys(cond, info, "'if' condition of %s" % source, [], + ["all", "any", "not"]) if len(cond) !=3D 1: raise QAPISemError( info, - "'if' condition dict of %s must have one key: " - "'all', 'any' or 'not'" % source) - check_keys(cond, info, "'if' condition", [], - ["all", "any", "not"]) + "'if' condition of %s has conflicting keys" % source) =20 oper, operands =3D next(iter(cond.items())) if not operands: diff --git a/tests/qapi-schema/bad-if-key.err b/tests/qapi-schema/bad-if-ke= y.err index a69dc9ee86..38cf44b687 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' +bad-if-key.json:2: 'if' condition of struct has unknown key 'value' 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 aceb31dc6d..fe87bd30ac 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'= , 'any' or 'not' +bad-if-keys.json:2: 'if' condition of struct has conflicting keys diff --git a/tests/qapi-schema/enum-if-invalid.err b/tests/qapi-schema/enum= -if-invalid.err index 3bb84075a9..2b2bbffb65 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' +enum-if-invalid.json:2: 'if' condition of 'data' member 'bar' has unknown = key 'val' Valid keys are 'all', 'any', 'not'. --=20 2.31.1