From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602781419; cv=none; d=zohomail.com; s=zohoarc; b=bsOwo1dI771kWHtvWqIELrmvBl+AntGBN27K+7SJsTDxd8rjiUwnEG8DMogFWXFgfZFlKmhSMrDy/OhQvMThADcOAMrGCGI3RfQVjZobHporxPB2BJ1FCH813Q5JcvQ1emhKpvimW6by0q/gVDeCXHHCOyP0VdXKtRlXkeXvbmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602781419; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/65jF4dN+hiIiX2ScXqyOrgcQndQ6YQjrO4QYF6wiSM=; b=mDA1BhOWdnwwf0nf7EJGPG3qwFHRIeA1Un8zdpe6pRGkyOC4ZU13cyx0KLMa3MxjBgFI6A6s/gIBzFYdHino5v+zPBEpXjpqKutuTskTNanNur3SbxI4UqMW2s7xwHBmhCpBWeR49GaC9Ax3heEurn5Oo/78jxIqmzLctxksdgs= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602781419253966.5498422909657; Thu, 15 Oct 2020 10:03:39 -0700 (PDT) Received: from localhost ([::1]:34666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6fC-0006l2-F9 for importer@patchew.org; Thu, 15 Oct 2020 13:03:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6VH-0002wD-3e for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:53:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6VA-0001VT-QI for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:53: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-246-Q2KNrmzaMfu0XDZ0ONC8EQ-1; Thu, 15 Oct 2020 12:53:12 -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 586BA1019634; Thu, 15 Oct 2020 16:53:11 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CEF35C1BD; Thu, 15 Oct 2020 16:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780795; 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=/65jF4dN+hiIiX2ScXqyOrgcQndQ6YQjrO4QYF6wiSM=; b=AeWg7hikaLBPbVLbFb6Ud2jtCILpRunccKwcFWTdcRFNb2h0ya/UaT18bU0F26P66jvW5Q JLwlJW8m1AMOvVKRp6zkC/+lBZEVXTjpIC2a4BbQqmgJyv/8TFAIc2bp2v3V4XY+sOyuGu NcItJDbBHO7Pi2zfVISgenNTMejmluI= X-MC-Unique: Q2KNrmzaMfu0XDZ0ONC8EQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 1/9] qapi: replace List[str] by IfCond Date: Thu, 15 Oct 2020 20:52:47 +0400 Message-Id: <20201015165255.1573897-2-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-1-marcandre.lureau@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=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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:10:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Wrap the 'if' condition in a higher-level object. Not only this is allows more type safety but also further refactoring without too much chrun. The following patches will extend the syntax of 'if' and will have some extra handling and types. Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/sphinx/qapidoc.py | 2 +- scripts/qapi/commands.py | 4 +- scripts/qapi/common.py | 26 ++++++++--- scripts/qapi/events.py | 4 +- scripts/qapi/gen.py | 9 ++-- scripts/qapi/introspect.py | 21 ++++----- scripts/qapi/schema.py | 91 ++++++++++++++++++++------------------ scripts/qapi/types.py | 11 ++--- scripts/qapi/visit.py | 9 ++-- 9 files changed, 102 insertions(+), 75 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index 11e97839de..db9520f37f 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -116,7 +116,7 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor): the conditions are in literal-text and the commas are not. If with_if is False, we don't return the "(If: " and ")". """ - condlist =3D intersperse([nodes.literal('', c) for c in ifcond], + condlist =3D intersperse([nodes.literal('', c) for c in ifcond.ifc= ond], nodes.Text(', ')) if not with_if: return condlist diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 50978090b4..03deac5fdd 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -20,7 +20,7 @@ from typing import ( Set, ) =20 -from .common import c_name, mcgen +from .common import IfCond, c_name, mcgen from .gen import ( QAPIGenC, QAPIGenCCode, @@ -301,7 +301,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); def visit_command(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], ret_type: Optional[QAPISchemaType], diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 11b86beeab..59e6a400da 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -12,7 +12,7 @@ # See the COPYING file in the top-level directory. =20 import re -from typing import Optional, Sequence +from typing import Optional, Sequence, Union =20 =20 #: Magic string that gets removed along with all space to its right. @@ -194,18 +194,34 @@ def guardend(name: str) -> str: name=3Dc_fname(name).upper()) =20 =20 -def gen_if(ifcond: Sequence[str]) -> str: +class IfCond: + def __init__(self, ifcond: Optional[Sequence[str]] =3D None): + self.ifcond =3D ifcond or [] + + def __bool__(self) -> bool: + return bool(self.ifcond) + + def __repr__(self) -> str: + return repr(self.ifcond) + + def __eq__(self, other: object) -> bool: + if not isinstance(other, IfCond): + return NotImplemented + return self.ifcond =3D=3D other.ifcond + + +def gen_if(c: IfCond) -> str: ret =3D '' - for ifc in ifcond: + for ifc in c.ifcond: ret +=3D mcgen(''' #if %(cond)s ''', cond=3Difc) return ret =20 =20 -def gen_endif(ifcond: Sequence[str]) -> str: +def gen_endif(c: IfCond) -> str: ret =3D '' - for ifc in reversed(ifcond): + for ifc in reversed(c.ifcond): ret +=3D mcgen(''' #endif /* %(cond)s */ ''', cond=3Difc) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 599f3d1f56..e95a95feca 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -14,7 +14,7 @@ See the COPYING file in the top-level directory. =20 from typing import List =20 -from .common import c_enum_const, c_name, mcgen +from .common import IfCond, c_enum_const, c_name, mcgen from .gen import QAPISchemaModularCVisitor, build_params, ifcontext from .schema import ( QAPISchema, @@ -212,7 +212,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); def visit_event(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], arg_type: QAPISchemaObjectType, boxed: bool) -> None: diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index b40f18eee3..b35ccb201f 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -23,6 +23,7 @@ from typing import ( ) =20 from .common import ( + IfCond, c_fname, c_name, gen_endif, @@ -81,7 +82,7 @@ class QAPIGen: fp.write(text) =20 =20 -def _wrap_ifcond(ifcond: List[str], before: str, after: str) -> str: +def _wrap_ifcond(ifcond: IfCond, before: str, after: str) -> str: if before =3D=3D after: return after # suppress empty #if ... #endif =20 @@ -123,9 +124,9 @@ def build_params(arg_type: Optional[QAPISchemaObjectTyp= e], class QAPIGenCCode(QAPIGen): def __init__(self, fname: Optional[str]): super().__init__(fname) - self._start_if: Optional[Tuple[List[str], str, str]] =3D None + self._start_if: Optional[Tuple[IfCond, str, str]] =3D None =20 - def start_if(self, ifcond: List[str]) -> None: + def start_if(self, ifcond: IfCond) -> None: assert self._start_if is None self._start_if =3D (ifcond, self._body, self._preamble) =20 @@ -186,7 +187,7 @@ class QAPIGenH(QAPIGenC): =20 =20 @contextmanager -def ifcontext(ifcond: List[str], *args: QAPIGenCCode) -> Iterator[None]: +def ifcontext(ifcond: IfCond, *args: QAPIGenCCode) -> Iterator[None]: """ A with-statement context manager that wraps with `start_if()` / `end_i= f()`. =20 diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 1817f1d34e..103b8515eb 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -21,6 +21,7 @@ from typing import ( ) =20 from .common import ( + IfCond, c_name, gen_endif, gen_if, @@ -58,11 +59,11 @@ class Node(Generic[_NodeType]): """ # Remove after 3.7 adds @dataclass: # pylint: disable=3Dtoo-few-public-methods - def __init__(self, data: _NodeType, ifcond: Iterable[str], + def __init__(self, data: _NodeType, ifcond: IfCond, comment: Optional[str] =3D None): self.data =3D data self.comment: Optional[str] =3D comment - self.ifcond: Sequence[str] =3D tuple(ifcond) + self.ifcond =3D ifcond =20 =20 def _tree_to_qlit(obj: TreeNode, level: int =3D 0, @@ -197,7 +198,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; return [Node(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name: str, mtype: str, obj: _DObject, - ifcond: List[str], + ifcond: IfCond, features: Optional[List[QAPISchemaFeature]]) -> None: comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): @@ -238,10 +239,10 @@ const QLitObject %(c_name)s =3D %(c_string)s; =20 def visit_builtin_type(self, name: str, info: Optional[QAPISourceInfo], json_type: str) -> None: - self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) + self._gen_tree(name, 'builtin', {'json-type': json_type}, IfCond()= , None) =20 def visit_enum_type(self, name: str, info: QAPISourceInfo, - ifcond: List[str], features: List[QAPISchemaFeatur= e], + ifcond: IfCond, features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: self._gen_tree(name, 'enum', @@ -249,14 +250,14 @@ const QLitObject %(c_name)s =3D %(c_string)s; ifcond, features) =20 def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, element_type: QAPISchemaType) -> None: element =3D self._use_type(element_type) self._gen_tree('[' + element + ']', 'array', {'element-type': elem= ent}, ifcond, None) =20 def visit_object_type_flat(self, name: str, info: Optional[QAPISourceI= nfo], - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], members: Sequence[QAPISchemaObjectTypeMembe= r], variants: Optional[QAPISchemaVariants]) -> = None: @@ -268,7 +269,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; self._gen_tree(name, 'object', obj, ifcond, features) =20 def visit_alternate_type(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: self._gen_tree(name, 'alternate', @@ -278,7 +279,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; ]}, ifcond, features) =20 - def visit_command(self, name: str, info: QAPISourceInfo, ifcond: List[= str], + def visit_command(self, name: str, info: QAPISourceInfo, ifcond: IfCon= d, features: List[QAPISchemaFeature], arg_type: QAPISchemaObjectType, ret_type: Optional[QAPISchemaType], gen: bool, @@ -295,7 +296,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; self._gen_tree(name, 'command', obj, ifcond, features) =20 def visit_event(self, name: str, info: QAPISourceInfo, - ifcond: List[str], features: List[QAPISchemaFeature], + ifcond: IfCond, features: List[QAPISchemaFeature], arg_type: QAPISchemaObjectType, boxed: bool) -> None: arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type= )}, diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index e388b3bced..b0287e2a8a 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -66,7 +66,7 @@ from typing import ( overload, ) =20 -from .common import POINTER_SUFFIX, c_name +from .common import IfCond, POINTER_SUFFIX, c_name from .error import QAPISemError, QAPISourceError from .expr import check_exprs from .parser import ParsedExpression, QAPIDoc, QAPISchemaParser @@ -86,7 +86,7 @@ class QAPISchemaEntity(Visitable): name: str, info: Optional[QAPISourceInfo], doc: Optional[QAPIDoc], - ifcond: Optional[Union[List[str], 'QAPISchemaType']] =3D = None, + ifcond: Optional[Union[IfCond, 'QAPISchemaType']] =3D Non= e, features: Optional[List['QAPISchemaFeature']] =3D None): assert name is None or isinstance(name, str) =20 @@ -103,7 +103,7 @@ class QAPISchemaEntity(Visitable): # such place). self.info =3D info self.doc =3D doc - self._ifcond =3D ifcond or [] + self._ifcond =3D ifcond or IfCond() self.features =3D features or [] self._checked =3D False self._meta =3D '' @@ -148,8 +148,8 @@ class QAPISchemaEntity(Visitable): self._set_module(schema, self.info) =20 @property - def ifcond(self) -> List[str]: - assert self._checked and isinstance(self._ifcond, list) + def ifcond(self) -> IfCond: + assert self._checked and isinstance(self._ifcond, IfCond) return self._ifcond =20 def is_implicit(self) -> bool: @@ -189,7 +189,7 @@ class QAPISchemaVisitor: def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, features: List['QAPISchemaFeature'], members: List['QAPISchemaEnumMember'], prefix: Optional[str]) -> None: @@ -198,14 +198,14 @@ class QAPISchemaVisitor: def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, element_type: 'QAPISchemaType') -> None: pass =20 def visit_object_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, features: List['QAPISchemaFeature'], base: Optional['QAPISchemaObjectType'], members: List['QAPISchemaObjectTypeMember'], @@ -215,7 +215,7 @@ class QAPISchemaVisitor: def visit_object_type_flat(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, features: List['QAPISchemaFeature'], members: List['QAPISchemaObjectTypeMember'], variants: Optional['QAPISchemaVariants'], @@ -225,7 +225,7 @@ class QAPISchemaVisitor: def visit_alternate_type(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List['QAPISchemaFeature'], variants: 'QAPISchemaVariants') -> None: pass @@ -233,7 +233,7 @@ class QAPISchemaVisitor: def visit_command(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List['QAPISchemaFeature'], arg_type: 'QAPISchemaObjectType', ret_type: Optional['QAPISchemaType'], @@ -248,7 +248,7 @@ class QAPISchemaVisitor: def visit_event(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List['QAPISchemaFeature'], arg_type: 'QAPISchemaObjectType', boxed: bool) -> None: @@ -361,7 +361,7 @@ class QAPISchemaEnumType(QAPISchemaType): name: str, info: Optional[QAPISourceInfo], doc: Optional[QAPIDoc], - ifcond: Optional[List[str]], + ifcond: Optional[IfCond], features: Optional[List['QAPISchemaFeature']], members: List['QAPISchemaEnumMember'], prefix: Optional[str]): @@ -427,7 +427,7 @@ class QAPISchemaArrayType(QAPISchemaType): self._set_module(schema, self.element_type.info) =20 @property - def ifcond(self) -> List[str]: + def ifcond(self) -> IfCond: assert self._checked return self.element_type.ifcond =20 @@ -461,7 +461,7 @@ class QAPISchemaObjectType(QAPISchemaType): name: str, info: Optional[QAPISourceInfo], doc: Optional[QAPIDoc], - ifcond: Optional['QAPISchemaType'], + ifcond: Optional[Union[IfCond, 'QAPISchemaType']], features: Optional[List['QAPISchemaFeature']], base: Optional[str], local_members: List['QAPISchemaObjectTypeMember'], @@ -545,7 +545,7 @@ class QAPISchemaObjectType(QAPISchemaType): member.connect_doc(doc) =20 @property - def ifcond(self) -> List[str]: + def ifcond(self) -> IfCond: assert self._checked if isinstance(self._ifcond, QAPISchemaType): # Simple union wrapper type inherits from wrapped type; @@ -591,7 +591,7 @@ class QAPISchemaAlternateType(QAPISchemaType): name: str, info: QAPISourceInfo, doc: QAPIDoc, - ifcond: Optional[List[str]], + ifcond: Optional[IfCond], features: List['QAPISchemaFeature'], variants: 'QAPISchemaVariants'): super().__init__(name, info, doc, ifcond, features) @@ -725,7 +725,7 @@ class QAPISchemaVariants: else: # simple union assert isinstance(self.tag_member.type, QAPISchemaEnumType) assert not self.tag_member.optional - assert self.tag_member.ifcond =3D=3D [] + assert not self.tag_member.ifcond if self._tag_name: # flat union # branches that are not explicitly covered get an empty type cases =3D {v.name for v in self.variants} @@ -772,11 +772,11 @@ class QAPISchemaMember: =20 def __init__(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Optional[List[str]] =3D None): + ifcond: Optional[IfCond] =3D None): assert isinstance(name, str) self.name =3D name self.info =3D info - self.ifcond =3D ifcond or [] + self.ifcond =3D ifcond or IfCond() self.defined_in: Optional[str] =3D None =20 def set_defined_in(self, name: str) -> None: @@ -843,7 +843,7 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): info: QAPISourceInfo, typ: str, optional: bool, - ifcond: Optional[List[str]] =3D None, + ifcond: Optional[IfCond] =3D None, features: Optional[List[QAPISchemaFeature]] =3D None): super().__init__(name, info, ifcond) assert isinstance(typ, str) @@ -878,7 +878,7 @@ class QAPISchemaVariant(QAPISchemaObjectTypeMember): name: str, info: QAPISourceInfo, typ: str, - ifcond: Optional[List[str]] =3D None): + ifcond: Optional[IfCond] =3D None): super().__init__(name, info, typ, False, ifcond) =20 =20 @@ -887,7 +887,7 @@ class QAPISchemaCommand(QAPISchemaEntity): name: str, info: QAPISourceInfo, doc: QAPIDoc, - ifcond: Optional[List[str]], + ifcond: Optional[IfCond], features: List[QAPISchemaFeature], arg_type: str, ret_type: Optional[str], @@ -963,7 +963,7 @@ class QAPISchemaEvent(QAPISchemaEntity): name: str, info: QAPISourceInfo, doc: QAPIDoc, - ifcond: Optional[List[str]], + ifcond: Optional[IfCond], features: List[QAPISchemaFeature], arg_type: str, boxed: bool): @@ -1143,13 +1143,20 @@ class QAPISchema(Visitable): self._def_entity(QAPISchemaEnumType('QType', None, None, None, Non= e, qtype_values, 'QTYPE')) =20 + @classmethod + def _get_if(cls, d: Dict[str, Any]) -> IfCond: + ifcond =3D d.get('if') + if isinstance(ifcond, IfCond): + return ifcond + return IfCond(ifcond) + @classmethod def _make_features(cls, features: Optional[List[Dict[str, Any]]], info: QAPISourceInfo) -> List[QAPISchemaFeature]: if features is None: return [] - return [QAPISchemaFeature(f['name'], info, f.get('if')) + return [QAPISchemaFeature(f['name'], info, cls._get_if(f)) for f in features] =20 @classmethod @@ -1157,13 +1164,13 @@ class QAPISchema(Visitable): values: List[Dict[str, Any]], info: Optional[QAPISourceInfo], ) -> List[QAPISchemaEnumMember]: - return [QAPISchemaEnumMember(v['name'], info, v.get('if')) + return [QAPISchemaEnumMember(v['name'], info, cls._get_if(v)) for v in values] =20 def _make_implicit_enum_type(self, name: str, info: QAPISourceInfo, - ifcond: Optional[List[str]], + ifcond: Optional[IfCond], values: List[Dict[str, Any]]) -> str: # See also QAPISchemaObjectTypeMember.describe() name =3D name + 'Kind' # reserved by check_defn_name_str() @@ -1184,7 +1191,7 @@ class QAPISchema(Visitable): def _make_implicit_object_type(self, name: str, info: QAPISourceInfo, - ifcond: Optional[QAPISchemaType], + ifcond: Union[IfCond, Optional[QAPISche= maType]], role: str, members: List[QAPISchemaObjectTypeMembe= r], ) -> Optional[str]: @@ -1205,7 +1212,7 @@ class QAPISchema(Visitable): # TODO kill simple unions or implement the disjunction =20 # pylint: disable=3Dprotected-access - assert (ifcond or []) =3D=3D typ._ifcond + assert ifcond =3D=3D typ._ifcond else: self._def_entity(QAPISchemaObjectType( name, info, None, ifcond, None, None, members, None)) @@ -1218,7 +1225,7 @@ class QAPISchema(Visitable): name =3D expr['enum'] data =3D expr['data'] prefix =3D expr.get('prefix') - ifcond =3D expr.get('if') + ifcond =3D IfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaEnumType( name, info, doc, ifcond, features, @@ -1227,7 +1234,7 @@ class QAPISchema(Visitable): def _make_member(self, name: str, typ: str, - ifcond: Optional[List[str]], + ifcond: Optional[IfCond], features: Optional[List[Dict[str, Any]]], info: QAPISourceInfo) -> QAPISchemaObjectTypeMember: optional =3D False @@ -1244,7 +1251,7 @@ class QAPISchema(Visitable): data: Dict[str, Dict[str, Any]], info: QAPISourceInfo, ) -> List[QAPISchemaObjectTypeMember]: - return [self._make_member(key, value['type'], value.get('if'), + return [self._make_member(key, value['type'], IfCond(value.get('if= ')), value.get('features'), info) for (key, value) in data.items()] =20 @@ -1255,7 +1262,7 @@ class QAPISchema(Visitable): name =3D expr['struct'] base =3D expr.get('base') data =3D expr['data'] - ifcond =3D expr.get('if') + ifcond =3D IfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaObjectType( name, info, doc, ifcond, features, base, @@ -1266,14 +1273,14 @@ class QAPISchema(Visitable): def _make_variant(cls, case: str, typ: str, - ifcond: Optional[List[str]], + ifcond: Optional[IfCond], info: QAPISourceInfo) -> QAPISchemaVariant: return QAPISchemaVariant(case, info, typ, ifcond) =20 def _make_simple_variant(self, case: str, typ: str, - ifcond: Optional[List[str]], + ifcond: Optional[IfCond], info: QAPISourceInfo) -> QAPISchemaVariant: if isinstance(typ, list): assert len(typ) =3D=3D 1 @@ -1290,7 +1297,7 @@ class QAPISchema(Visitable): name =3D expr['union'] data =3D expr['data'] base =3D expr.get('base') - ifcond =3D expr.get('if') + ifcond =3D IfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) tag_name =3D expr.get('discriminator') tag_member =3D None @@ -1300,12 +1307,12 @@ class QAPISchema(Visitable): 'base', self._make_members(base, info)) if tag_name: variants =3D [self._make_variant(key, value['type'], - value.get('if'), info) + IfCond(value.get('if')), info) for (key, value) in data.items()] members =3D [] else: variants =3D [self._make_simple_variant(key, value['type'], - value.get('if'), info) + IfCond(value.get('if')),= info) for (key, value) in data.items()] enum =3D [{'name': v.name, 'if': v.ifcond} for v in variants] typ =3D self._make_implicit_enum_type(name, info, ifcond, enum) @@ -1323,9 +1330,9 @@ class QAPISchema(Visitable): doc: QAPIDoc) -> None: name =3D expr['alternate'] data =3D expr['data'] - ifcond =3D expr.get('if') + ifcond =3D IfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) - variants =3D [self._make_variant(key, value['type'], value.get('if= '), + variants =3D [self._make_variant(key, value['type'], IfCond(value.= get('if')), info) for (key, value) in data.items()] tag_member =3D QAPISchemaObjectTypeMember('type', info, 'QType', F= alse) @@ -1347,7 +1354,7 @@ class QAPISchema(Visitable): allow_oob =3D expr.get('allow-oob', False) allow_preconfig =3D expr.get('allow-preconfig', False) coroutine =3D expr.get('coroutine', False) - ifcond =3D expr.get('if') + ifcond =3D IfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( @@ -1369,7 +1376,7 @@ class QAPISchema(Visitable): name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) - ifcond =3D expr.get('if') + ifcond =3D IfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 2b4916cdaa..c15613d13b 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -16,6 +16,7 @@ This work is licensed under the terms of the GNU GPL, ver= sion 2. from typing import List, Optional =20 from .common import ( + IfCond, c_enum_const, c_name, gen_endif, @@ -139,7 +140,7 @@ def gen_struct_members(members: List[QAPISchemaObjectTy= peMember]) -> str: return ret =20 =20 -def gen_object(name: str, ifcond: List[str], +def gen_object(name: str, ifcond: IfCond, base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], variants: Optional[QAPISchemaVariants]) -> str: @@ -307,7 +308,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: @@ -318,7 +319,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, element_type: QAPISchemaType) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.preamble_add(gen_fwd_object_or_array(name)) @@ -328,7 +329,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): def visit_object_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], @@ -351,7 +352,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): def visit_alternate_type(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh): diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 339f152152..d10840bf7b 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -16,6 +16,7 @@ See the COPYING file in the top-level directory. from typing import List, Optional =20 from .common import ( + IfCond, c_enum_const, c_name, gen_endif, @@ -337,7 +338,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): def visit_enum_type(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: @@ -348,7 +349,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, element_type: QAPISchemaType) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) @@ -357,7 +358,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): def visit_object_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], @@ -379,7 +380,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): def visit_alternate_type(self, name: str, info: QAPISourceInfo, - ifcond: List[str], + ifcond: IfCond, features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh, self._genc): --=20 2.28.0 From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602780960; cv=none; d=zohomail.com; s=zohoarc; b=YDGRAG2WM2yDmrNAGcVDZU2dw8omibTRBo1jW5fW7jKgbJscpL0yj7OQeTu1HRZ+L9OeD1p85Iqsh48298o4qmQbNKJeALpvgzFX8elbkNQG9qXO1ncE/Fm9yd+hR8XIK5VRPIWPpI8snaF6wQZAqzVkfwATor0D7GCI29LkRMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602780960; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xYpymDkGf3DkVnqKu28Cu3ciHcdts5cGa4LEARgxQZ0=; b=I8a9E5bBanJp9RIIYCJYUkWLsbRECqFNtPWKPaJqYtSQhKSGvdW9MWCIAVB4vIpyxYk7IHWYHnM8fg1pRKGIZ2P+DjveJM8o14bZHbyr09fs83vIaw2NFePVmAlOyZoiHftDaHLqrJJOU3hBK6BfE8cydKR/GMYC+WM0Il78O1A= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602780960733347.0726509332985; Thu, 15 Oct 2020 09:56:00 -0700 (PDT) Received: from localhost ([::1]:38858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6Xn-0004yq-Dl for importer@patchew.org; Thu, 15 Oct 2020 12:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6VL-00036D-3q for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:53:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6VI-0001WO-RW for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:53: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-450-MPyF2GcxOk-xRMbNObGwog-1; Thu, 15 Oct 2020 12:53: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 E3CA5101962A; Thu, 15 Oct 2020 16:53:19 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 946A610013C1; Thu, 15 Oct 2020 16:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780803; 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=xYpymDkGf3DkVnqKu28Cu3ciHcdts5cGa4LEARgxQZ0=; b=HgB91sSEsJeGvedN82c4oDyg392hP0MVv6RCir+rvBjr1lZPwev8iQYdCM5fCgpMS8Yt1B SOyV/Stt4qz4336G3oHzOawYJc1UQKmZAkcmEEdiBVoPkare86AJ6CrfsZ8s26hUvxN9t4 XEDmsnXK6B5uNgMN8nrJN/1pK1XHLkE= X-MC-Unique: MPyF2GcxOk-xRMbNObGwog-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 2/9] qapi: move gen_if/gen_endif to IfCond Date: Thu, 15 Oct 2020 20:52:48 +0400 Message-Id: <20201015165255.1573897-3-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:10:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Move the generating function to the IfCond class. (avoid cluttering and potential missuse of global functions, allow access to private members etc) Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 22 ++++++++++------------ scripts/qapi/gen.py | 6 ++---- scripts/qapi/introspect.py | 6 ++---- scripts/qapi/types.py | 22 ++++++++++------------ scripts/qapi/visit.py | 14 ++++++-------- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 59e6a400da..58ddec3bc5 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -209,20 +209,18 @@ class IfCond: return NotImplemented return self.ifcond =3D=3D other.ifcond =20 - -def gen_if(c: IfCond) -> str: - ret =3D '' - for ifc in c.ifcond: - ret +=3D mcgen(''' + def gen_if(self) -> str: + ret =3D '' + for ifc in self.ifcond: + ret +=3D mcgen(''' #if %(cond)s ''', cond=3Difc) - return ret - + return ret =20 -def gen_endif(c: IfCond) -> str: - ret =3D '' - for ifc in reversed(c.ifcond): - ret +=3D mcgen(''' + def gen_endif(self) -> str: + ret =3D '' + for ifc in reversed(self.ifcond): + ret +=3D mcgen(''' #endif /* %(cond)s */ ''', cond=3Difc) - return ret + return ret diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index b35ccb201f..5a8c66e628 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -26,8 +26,6 @@ from .common import ( IfCond, c_fname, c_name, - gen_endif, - gen_if, guardend, guardstart, mcgen, @@ -92,9 +90,9 @@ def _wrap_ifcond(ifcond: IfCond, before: str, after: str)= -> str: if added[0] =3D=3D '\n': out +=3D '\n' added =3D added[1:] - out +=3D gen_if(ifcond) + out +=3D ifcond.gen_if() out +=3D added - out +=3D gen_endif(ifcond) + out +=3D ifcond.gen_endif() return out =20 =20 diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 103b8515eb..d97dea8e4e 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -23,8 +23,6 @@ from typing import ( from .common import ( IfCond, c_name, - gen_endif, - gen_if, mcgen, ) from .gen import QAPISchemaMonolithicCVisitor @@ -77,10 +75,10 @@ def _tree_to_qlit(obj: TreeNode, level: int =3D 0, if obj.comment: ret +=3D indent(level) + '/* %s */\n' % obj.comment if obj.ifcond: - ret +=3D gen_if(obj.ifcond) + ret +=3D obj.ifcond.gen_if() ret +=3D _tree_to_qlit(obj.data, level) if obj.ifcond: - ret +=3D '\n' + gen_endif(obj.ifcond) + ret +=3D '\n' + obj.ifcond.gen_endif() return ret =20 ret =3D '' diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index c15613d13b..66ba2f62e4 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -19,8 +19,6 @@ from .common import ( IfCond, c_enum_const, c_name, - gen_endif, - gen_if, mcgen, ) from .gen import QAPISchemaModularCVisitor, ifcontext @@ -51,13 +49,13 @@ const QEnumLookup %(c_name)s_lookup =3D { ''', c_name=3Dc_name(name)) for memb in members: - ret +=3D gen_if(memb.ifcond) + 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) + ret +=3D memb.ifcond.gen_endif() =20 ret +=3D mcgen(''' }, @@ -81,12 +79,12 @@ typedef enum %(c_name)s { c_name=3Dc_name(name)) =20 for memb in enum_members: - ret +=3D gen_if(memb.ifcond) + 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) + ret +=3D memb.ifcond.gen_endif() =20 ret +=3D mcgen(''' } %(c_name)s; @@ -126,7 +124,7 @@ struct %(c_name)s { def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str: ret =3D '' for memb in members: - ret +=3D gen_if(memb.ifcond) + 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) + ret +=3D memb.ifcond.gen_endif() return ret =20 =20 @@ -159,7 +157,7 @@ def gen_object(name: str, ifcond: IfCond, ret +=3D mcgen(''' =20 ''') - ret +=3D gen_if(ifcond) + ret +=3D ifcond.gen_if() ret +=3D mcgen(''' struct %(c_name)s { ''', @@ -193,7 +191,7 @@ struct %(c_name)s { ret +=3D mcgen(''' }; ''') - ret +=3D gen_endif(ifcond) + 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) + 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) + ret +=3D var.ifcond.gen_endif() =20 ret +=3D mcgen(''' } u; diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index d10840bf7b..b199e75946 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -19,8 +19,6 @@ from .common import ( IfCond, c_enum_const, c_name, - gen_endif, - gen_if, indent, mcgen, ) @@ -78,7 +76,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) c_type=3Dbase.c_name()) =20 for memb in members: - ret +=3D gen_if(memb.ifcond) + ret +=3D memb.ifcond.gen_if() if memb.optional: ret +=3D mcgen(''' if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) { @@ -97,7 +95,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) ret +=3D mcgen(''' } ''') - ret +=3D gen_endif(memb.ifcond) + ret +=3D memb.ifcond.gen_endif() =20 if variants: tag_member =3D variants.tag_member @@ -111,7 +109,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name= )s *obj, Error **errp) 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) + ret +=3D var.ifcond.gen_if() if var.type.name =3D=3D 'q_empty': # valid variant and nothing to do ret +=3D mcgen(''' @@ -127,7 +125,7 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name= )s *obj, Error **errp) case=3Dcase_str, c_type=3Dvar.type.c_name(), c_name=3Dc_name(v= ar.name)) =20 - ret +=3D gen_endif(var.ifcond) + ret +=3D var.ifcond.gen_endif() ret +=3D mcgen(''' default: abort(); @@ -213,7 +211,7 @@ bool visit_type_%(c_name)s(Visitor *v, const char *name, c_name=3Dc_name(name)) =20 for var in variants.variants: - ret +=3D gen_if(var.ifcond) + ret +=3D var.ifcond.gen_if() ret +=3D mcgen(''' case %(case)s: ''', @@ -239,7 +237,7 @@ bool visit_type_%(c_name)s(Visitor *v, const char *name, ret +=3D mcgen(''' break; ''') - ret +=3D gen_endif(var.ifcond) + ret +=3D var.ifcond.gen_endif() =20 ret +=3D mcgen(''' case QTYPE_NONE: --=20 2.28.0 From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602781092; cv=none; d=zohomail.com; s=zohoarc; b=Em7O35A/smRqAUsE1m1/sKagsc0mtmnFPeX1FtCVbwNt7+tX+jIBF2NI6ufAUjtKI48lTApWifGhAaNmvC55oeYInsiohhaYr6v5ZIuP15MCyXTz/JPC96fMN4E87Hauk85fYAqsbTmA5xlv5BZ4WaUSZpLl1frfv0fOE+q1xw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602781092; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=x6XqbdTmAAMKzjvPz+W9jXvLZtl93eke5o8q4430lAk=; b=UxsuVlOl7eG5gxmOqZIkrKzUOytfgnivy/IMEUVMsXPs+h95QtGFNWA5Lm6NFqy3Hj52H3UphT44RM/VRibxJsQXRmyUkp+D/CzDBabJtwO/ZbjWLn065qZwenHHiq6eYFzDAIQaWTwcoW5ms7HblyvWFGssPeTUm4VcGxv7JqA= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602781092331660.044675397781; Thu, 15 Oct 2020 09:58:12 -0700 (PDT) Received: from localhost ([::1]:47176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6Zv-00007Y-1m for importer@patchew.org; Thu, 15 Oct 2020 12:58:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6VX-0003CM-4z for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:53:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41271) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6VT-0001XT-6m for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:53:38 -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-536-yIO1wSHuPM63wJ_Hr4CRTg-1; Thu, 15 Oct 2020 12:53:29 -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 B4B9BAF9A0; Thu, 15 Oct 2020 16:53:28 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id E526E60CD0; Thu, 15 Oct 2020 16:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780812; 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=x6XqbdTmAAMKzjvPz+W9jXvLZtl93eke5o8q4430lAk=; b=JSFqTfB+oAG94X2JiZCmQT8Yt5MqrU/UhdfDwmTI0jbfipHUoBfvpA7XtpJrFMuNSpwr2x COYHPMrskwaIUePjP/p/1CP4br4Qpm28YkIpTWh278SnhSe0D4m3087T7dKCsaxHP4aXAx TiWq27HPVJN2aM7eyRj1Xg6l+xfc3Hk= X-MC-Unique: yIO1wSHuPM63wJ_Hr4CRTg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 3/9] qapi: start building an 'if' predicate tree Date: Thu, 15 Oct 2020 20:52:49 +0400 Message-Id: <20201015165255.1573897-4-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-1-marcandre.lureau@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=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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:10:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau The following patches are going to express conditions in some target language agostic way. For that, let's start building a predicate tree of configuration options. The tree will be less expressive than full C macros expressions, and will be based only on identifier. For this reason, it will use have operations: 'all', 'any' and 'not'. ('and'/'or' have a connotation of expression operands) For now, the documentation will use the C condition expression (as that's already what is exposed with defined(FOO), &&, || etc). Eventually, we may want to generate a more human friendly syntax later. Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/sphinx/qapidoc.py | 6 +-- scripts/qapi/common.py | 69 ++++++++++++++++++++------ tests/qapi-schema/doc-good.out | 12 ++--- tests/qapi-schema/qapi-schema-test.out | 58 +++++++++++----------- 4 files changed, 91 insertions(+), 54 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index db9520f37f..31b47e4745 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -112,12 +112,10 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor): def _nodes_for_ifcond(self, ifcond, with_if=3DTrue): """Return list of Text, literal nodes for the ifcond =20 - Return a list which gives text like ' (If: cond1, cond2, cond3)', = where - the conditions are in literal-text and the commas are not. + Return a list which gives text like ' (If: C-condition)'. If with_if is False, we don't return the "(If: " and ")". """ - condlist =3D intersperse([nodes.literal('', c) for c in ifcond.ifc= ond], - nodes.Text(', ')) + condlist =3D [nodes.literal('', ifcond.gen_if())] if not with_if: return condlist =20 diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 58ddec3bc5..29e0697c27 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -194,33 +194,72 @@ def guardend(name: str) -> str: name=3Dc_fname(name).upper()) =20 =20 +class IfPredicate: + def cgen(self) -> str: + raise NotImplementedError() + + +class IfOption(IfPredicate): + def __init__(self, option: str): + self.option =3D option + + def cgen(self) -> str: + return self.option + + def __repr__(self) -> str: + return repr(self.option) + + def __eq__(self, other: object) -> bool: + if not isinstance(other, IfOption): + return False + return self.option =3D=3D other.option + + +class IfAll(IfPredicate): + def __init__(self, pred_list: Sequence[IfPredicate]): + self.pred_list =3D pred_list + + def cgen(self) -> str: + return " && ".join([p.cgen() for p in self.pred_list]) + + def __bool__(self) -> bool: + return bool(self.pred_list) + + def __repr__(self) -> str: + return f"IfAll({self.pred_list})" + + def __eq__(self, other: object) -> bool: + if not isinstance(other, IfAll): + return False + return self.pred_list =3D=3D other.pred_list + + class IfCond: def __init__(self, ifcond: Optional[Sequence[str]] =3D None): - self.ifcond =3D ifcond or [] + pred_list =3D [IfOption(opt) for opt in ifcond or []] + self.pred =3D IfAll(pred_list) =20 def __bool__(self) -> bool: - return bool(self.ifcond) + return bool(self.pred) =20 def __repr__(self) -> str: - return repr(self.ifcond) + return repr(self.pred) =20 def __eq__(self, other: object) -> bool: if not isinstance(other, IfCond): return NotImplemented - return self.ifcond =3D=3D other.ifcond + return self.pred =3D=3D other.pred =20 def gen_if(self) -> str: - ret =3D '' - for ifc in self.ifcond: - ret +=3D mcgen(''' + if self.pred: + return mcgen(''' #if %(cond)s -''', cond=3Difc) - return ret +''', cond=3Dself.pred.cgen()) + return "" =20 def gen_endif(self) -> str: - ret =3D '' - for ifc in reversed(self.ifcond): - ret +=3D mcgen(''' -#endif /* %(cond)s */ -''', cond=3Difc) - return ret + if self.pred: + return mcgen(''' +#endif // %(cond)s +''', cond=3Dself.pred.cgen()) + return "" diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 419284dae2..0d27323c47 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -12,15 +12,15 @@ enum QType module doc-good.json enum Enum member one - if ['defined(IFONE)'] + if IfAll(['defined(IFONE)']) member two - if ['defined(IFCOND)'] + if IfAll(['defined(IFCOND)']) feature enum-feat object Base member base1: Enum optional=3DFalse object Variant1 member var1: str optional=3DFalse - if ['defined(IFSTR)'] + if IfAll(['defined(IFSTR)']) feature member-feat feature variant1-feat object Variant2 @@ -29,7 +29,7 @@ object Object tag base1 case one: Variant1 case two: Variant2 - if ['IFTWO'] + if IfAll(['IFTWO']) feature union-feat1 object q_obj_Variant1-wrapper member data: Variant1 optional=3DFalse @@ -38,13 +38,13 @@ object q_obj_Variant2-wrapper enum SugaredUnionKind member one member two - if ['IFTWO'] + if IfAll(['IFTWO']) object SugaredUnion member type: SugaredUnionKind optional=3DFalse tag type case one: q_obj_Variant1-wrapper case two: q_obj_Variant2-wrapper - if ['IFTWO'] + if IfAll(['IFTWO']) feature union-feat2 alternate Alternate tag type diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 8868ca0dca..8ba658cd38 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -298,65 +298,65 @@ command __org.qemu_x-command q_obj___org.qemu_x-comma= nd-arg -> __org.qemu_x-Unio object TestIfStruct member foo: int optional=3DFalse member bar: int optional=3DFalse - if ['defined(TEST_IF_STRUCT_BAR)'] - if ['defined(TEST_IF_STRUCT)'] + if IfAll(['defined(TEST_IF_STRUCT_BAR)']) + if IfAll(['defined(TEST_IF_STRUCT)']) enum TestIfEnum member foo member bar - if ['defined(TEST_IF_ENUM_BAR)'] - if ['defined(TEST_IF_ENUM)'] + if IfAll(['defined(TEST_IF_ENUM_BAR)']) + if IfAll(['defined(TEST_IF_ENUM)']) object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse enum TestIfUnionKind member foo member union_bar - if ['defined(TEST_IF_UNION_BAR)'] - if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)'] + if IfAll(['defined(TEST_IF_UNION_BAR)']) + if IfAll(['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']) object TestIfUnion member type: TestIfUnionKind optional=3DFalse tag type case foo: q_obj_TestStruct-wrapper case union_bar: q_obj_str-wrapper - if ['defined(TEST_IF_UNION_BAR)'] - if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)'] + if IfAll(['defined(TEST_IF_UNION_BAR)']) + if IfAll(['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']) object q_obj_TestIfUnionCmd-arg member union_cmd_arg: TestIfUnion optional=3DFalse - if ['defined(TEST_IF_UNION)'] + if IfAll(['defined(TEST_IF_UNION)']) command TestIfUnionCmd q_obj_TestIfUnionCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if ['defined(TEST_IF_UNION)'] + if IfAll(['defined(TEST_IF_UNION)']) alternate TestIfAlternate tag type case foo: int case bar: TestStruct - if ['defined(TEST_IF_ALT_BAR)'] - if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)'] + if IfAll(['defined(TEST_IF_ALT_BAR)']) + if IfAll(['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']) object q_obj_TestIfAlternateCmd-arg member alt_cmd_arg: TestIfAlternate optional=3DFalse - if ['defined(TEST_IF_ALT)'] + if IfAll(['defined(TEST_IF_ALT)']) command TestIfAlternateCmd q_obj_TestIfAlternateCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if ['defined(TEST_IF_ALT)'] + if IfAll(['defined(TEST_IF_ALT)']) object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse - if ['defined(TEST_IF_CMD_BAR)'] - if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] + if IfAll(['defined(TEST_IF_CMD_BAR)']) + if IfAll(['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']) command TestIfCmd q_obj_TestIfCmd-arg -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] + if IfAll(['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']) command TestCmdReturnDefThree None -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse array TestIfEnumList TestIfEnum - if ['defined(TEST_IF_ENUM)'] + if IfAll(['defined(TEST_IF_ENUM)']) object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnumList optional=3DFalse - if ['defined(TEST_IF_EVT_BAR)'] - if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)'] + if IfAll(['defined(TEST_IF_EVT_BAR)']) + if IfAll(['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']) event TestIfEvent q_obj_TestIfEvent-arg boxed=3DFalse - if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)'] + if IfAll(['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']) object FeatureStruct0 member foo: int optional=3DFalse object FeatureStruct1 @@ -379,17 +379,17 @@ object FeatureStruct4 object CondFeatureStruct1 member foo: int optional=3DFalse feature feature1 - if ['defined(TEST_IF_FEATURE_1)'] + if IfAll(['defined(TEST_IF_FEATURE_1)']) object CondFeatureStruct2 member foo: int optional=3DFalse feature feature1 - if ['defined(TEST_IF_FEATURE_1)'] + if IfAll(['defined(TEST_IF_FEATURE_1)']) feature feature2 - if ['defined(TEST_IF_FEATURE_2)'] + if IfAll(['defined(TEST_IF_FEATURE_2)']) object CondFeatureStruct3 member foo: int optional=3DFalse feature feature1 - if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] + if IfAll(['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']) enum FeatureEnum1 member eins member zwei @@ -429,17 +429,17 @@ command test-command-features3 None -> None command test-command-cond-features1 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if ['defined(TEST_IF_FEATURE_1)'] + if IfAll(['defined(TEST_IF_FEATURE_1)']) command test-command-cond-features2 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if ['defined(TEST_IF_FEATURE_1)'] + if IfAll(['defined(TEST_IF_FEATURE_1)']) feature feature2 - if ['defined(TEST_IF_FEATURE_2)'] + if IfAll(['defined(TEST_IF_FEATURE_2)']) command test-command-cond-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] + if IfAll(['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']) event TEST-EVENT-FEATURES1 None boxed=3DFalse feature deprecated --=20 2.28.0 From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602781365; cv=none; d=zohomail.com; s=zohoarc; b=j+lpISbuo2L8u3W9rzORVwYA+VycY6XYHWiasDM4Z4GlldBhL2nXUUSCJ+qi/+xECjsRRYVLAIcxmjPCXTf4iAqFV+PVQWt+Kl3xJrjZyO+BoKJEzOVXSYcTR7cxj0akIYBH8td/OBJhGOcEK7Fjjw/iLQdcJmYvlL+h6uxDPHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602781365; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kPSewU/obJZZ+xmFVwvCb+4WWA37/u+KC2O9DKCBvlk=; b=TpfzKQd/HTQJubggYf0Hs+bL50ozTua9MNj8+6Hja8NRgBriX6iqeX0Y2zjvbuOxBfTFb0D5o29BsFMln1m1CB5HQE5tIgciAThSYbd4ey/EXzFNbQ1Dp8xS7V22q79RINT4RhVn6s8P02lMTIRT9mqq57xji69tZBODtqZSXGw= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602781365244704.6857699974119; Thu, 15 Oct 2020 10:02:45 -0700 (PDT) Received: from localhost ([::1]:55770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6cv-0003dd-Uk for importer@patchew.org; Thu, 15 Oct 2020 13:01:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6Vg-0003E8-Ff for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:53:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6Ve-0001ZU-7K for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:53:48 -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-220-7DP-mpoRPMmT2PFdAFugSQ-1; Thu, 15 Oct 2020 12:53:37 -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 7DB2480363A; Thu, 15 Oct 2020 16:53:36 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id C65C16EF68; Thu, 15 Oct 2020 16:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780820; 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=kPSewU/obJZZ+xmFVwvCb+4WWA37/u+KC2O9DKCBvlk=; b=iucCv+0bQQGTuwF3+Fp6e/KycyAWoEeeQgyevSkOP5b4fqcXgC8bb+kXRieq9ibchcVhnN nKODkITe+zpoSY6b4oLZ1SRTcMCrCAzvo6BLBKd9aiNmUy5b5+5cQ82T9d4ioDruMSIili aAHcinpCE2KBLHOMyrYSCAN0mGnj4Ng= X-MC-Unique: 7DP-mpoRPMmT2PFdAFugSQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 4/9] qapi: introduce IfPredicateList and IfAny Date: Thu, 15 Oct 2020 20:52:50 +0400 Message-Id: <20201015165255.1573897-5-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-1-marcandre.lureau@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=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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:10:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Generalize IfAll to allow 'any' conditions. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 29e0697c27..f5166e0bad 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -215,25 +215,37 @@ class IfOption(IfPredicate): return self.option =3D=3D other.option =20 =20 -class IfAll(IfPredicate): +class IfPredicateList(IfPredicate): + C_OP =3D "" + def __init__(self, pred_list: Sequence[IfPredicate]): self.pred_list =3D pred_list =20 def cgen(self) -> str: - return " && ".join([p.cgen() for p in self.pred_list]) + op =3D " " + self.C_OP + " " + return "(%s)" % op.join([p.cgen() for p in self.pred_list]) =20 def __bool__(self) -> bool: return bool(self.pred_list) =20 def __repr__(self) -> str: - return f"IfAll({self.pred_list})" + ty =3D type(self) + return f"{ty.__qualname__}({self.pred_list})" =20 def __eq__(self, other: object) -> bool: - if not isinstance(other, IfAll): + if not isinstance(other, type(self)): return False return self.pred_list =3D=3D other.pred_list =20 =20 +class IfAll(IfPredicateList): + C_OP =3D "&&" + + +class IfAny(IfPredicateList): + C_OP =3D "||" + + class IfCond: def __init__(self, ifcond: Optional[Sequence[str]] =3D None): pred_list =3D [IfOption(opt) for opt in ifcond or []] --=20 2.28.0 From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602781368; cv=none; d=zohomail.com; s=zohoarc; b=IeL0zyw3G2HOtUBj1BmJgAYUF2bSrLxfDXrBgDdiF+FI+v+YqP518yRvBHhSVjY26iSvf+IKDNlpuqtIy9p+ipysTw6xnj43thtH1ixQ0GDL6jlbd5THQQEsJTXvqmbXFk/P8Q/P5oo+AxopD9WAgCOY2PF/JZCL1+ILqLxyu2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602781368; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MUXZphrqJGIwQzIovujd6SoGzcgr40qfk5SzO9qgt+4=; b=mw4X2C8Wts8VXV++gGPDUXfibE5BeicTRhLS1tIsabxEEoMXkbonCMmp4R8oBz9tZkQCGl7fz50MtUMGejsGkezH2+1ZxxROwvq3OghGODa+8RfqF8DVKoQr7dd2HimoBHbkmK4aT8mifmAQHUjbrKG0HmKyV18+eobuNNBVHLs= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602781368165896.536286242399; Thu, 15 Oct 2020 10:02:48 -0700 (PDT) Received: from localhost ([::1]:60198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6eN-0005dd-BF for importer@patchew.org; Thu, 15 Oct 2020 13:02:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6Vt-0003VZ-Bl for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6Vr-0001aT-NW for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:01 -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-182-JiEtAF8fPjy7uT2D8YwU7g-1; Thu, 15 Oct 2020 12:53:52 -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 23ECD56BE7; Thu, 15 Oct 2020 16:53:50 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA2BC60E1C; Thu, 15 Oct 2020 16:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780836; 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=MUXZphrqJGIwQzIovujd6SoGzcgr40qfk5SzO9qgt+4=; b=UtxXcjli2c9deLIWdp80p8LUGpR4BfAheBCfUY6gM1obeSxhYw0t3yumuzAwJpAh2Z4G5F GyDbsyohP3aJQZ8qwk/zbWNjHF7u1Jiw8gNRgv+bUn8B6ahbBjqy9OCzgZn929+Zw5sk+R xpFg3FzXrwAyIO91cS52xd9WMu+Ma7w= X-MC-Unique: JiEtAF8fPjy7uT2D8YwU7g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 5/9] qapi: add IfNot Date: Thu, 15 Oct 2020 20:52:51 +0400 Message-Id: <20201015165255.1573897-6-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-1-marcandre.lureau@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=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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:10:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index f5166e0bad..566913d69e 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -246,6 +246,25 @@ class IfAny(IfPredicateList): C_OP =3D "||" =20 =20 +class IfNot(IfPredicate): + def __init__(self, pred: IfPredicate): + self.pred =3D pred + + def cgen(self) -> str: + return "!" + self.pred.cgen() + + def __bool__(self) -> bool: + return bool(self.pred) + + def __repr__(self) -> str: + return f"IfNot({self.pred!r})" + + def __eq__(self, other: object) -> bool: + if not isinstance(other, type(self)): + return False + return self.pred =3D=3D other.pred + + class IfCond: def __init__(self, ifcond: Optional[Sequence[str]] =3D None): pred_list =3D [IfOption(opt) for opt in ifcond or []] --=20 2.28.0 From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602781653; cv=none; d=zohomail.com; s=zohoarc; b=i1gGm26qTv3M4uWyoaXq6AtByGgzj6es9r1YDCRBWNxc9XYeIe5mJUSrGNQt4kt7IzUBr8IFVheVIK+gL/uh9IQ3nBHeLP2wyufxq+8ysb2QIurXflbmKD6azgSoQ2kCOOgI+lYcHQJ5u75iGoLIFcbZnw9wbNeczSmL9FdxbZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602781653; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5jVq0vy0+KQxX05D86UmCcGrqlQpd+U2wEwC00ddQo8=; b=c5VN9n8HvAZ59BRBCNstCsjpnwH+wIcIkFPq8ogV6NvijwgQC+rJwZKJtFii5N0D7pOnnVbVvAQEvutgLFci8yrLDsDHxE8KrBTabh+Wsp3uzaJKC1PJ3aYZ+Swhv5Dx1ZuNObOhXS1Hu/7izOQzBgvAa3DmrW4uO4xYIkmZCvg= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602781653458266.0286091545223; Thu, 15 Oct 2020 10:07:33 -0700 (PDT) Received: from localhost ([::1]:43852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6iy-0002Cv-NN for importer@patchew.org; Thu, 15 Oct 2020 13:07:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6Vv-0003bb-L0 for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45685) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6Vs-0001aZ-IZ for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:03 -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-274-RWIqMN3lPhO7LLmyb6ZYnA-1; Thu, 15 Oct 2020 12:53:57 -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 452F656BE7; Thu, 15 Oct 2020 16:53:56 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 600A560E1C; Thu, 15 Oct 2020 16:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780839; 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=5jVq0vy0+KQxX05D86UmCcGrqlQpd+U2wEwC00ddQo8=; b=C0XRtVLvpjqnmIXYws1T6Rhd7TYxk2CDtb2zHrudQDrgPRaZtVL4FuEJ3yfAncSMSQIhvo 5qXl9wRjuPxM7TPuhrQ1z1iKCeiCLes4Ov00X52th8Y70zrz5CaFGPtdIahcJ9KeaSLsnu vxCYwk6xMQPgFAUMenzOUAJ3fC7B/rs= X-MC-Unique: RWIqMN3lPhO7LLmyb6ZYnA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 6/9] qapi: normalize 'if' condition to IfPredicate Date: Thu, 15 Oct 2020 20:52:52 +0400 Message-Id: <20201015165255.1573897-7-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-1-marcandre.lureau@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=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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:10:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/common.py | 5 +- scripts/qapi/expr.py | 55 ++++++++++++------- tests/qapi-schema/bad-if.err | 3 +- tests/qapi-schema/doc-good.out | 12 ++-- tests/qapi-schema/enum-if-invalid.err | 3 +- tests/qapi-schema/features-if-invalid.err | 2 +- tests/qapi-schema/qapi-schema-test.json | 15 +++-- tests/qapi-schema/qapi-schema-test.out | 55 ++++++++++--------- .../qapi-schema/struct-member-if-invalid.err | 2 +- tests/test-qmp-cmds.c | 1 + 10 files changed, 90 insertions(+), 63 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 566913d69e..b855a6dc78 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -266,9 +266,8 @@ class IfNot(IfPredicate): =20 =20 class IfCond: - def __init__(self, ifcond: Optional[Sequence[str]] =3D None): - pred_list =3D [IfOption(opt) for opt in ifcond or []] - self.pred =3D IfAll(pred_list) + def __init__(self, pred: Optional[IfPredicate] =3D None): + self.pred =3D pred =20 def __bool__(self) -> bool: return bool(self.pred) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index ad1e214386..0f0e01cb78 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -44,7 +44,7 @@ from typing import ( cast, ) =20 -from .common import c_name +from .common import c_name, IfPredicate, IfAll, IfAny, IfNot, IfOption from .error import QAPISemError from .parser import ParsedExpression from .source import QAPISourceInfo @@ -196,41 +196,56 @@ def check_if(expr: _JSObject, info: QAPISourceInfo, s= ource: str) -> None: """ Syntactically validate and normalize the ``if`` field of an object. [R= W] =20 - The ``if`` field may be either a ``str`` or a ``List[str]``. - A ``str`` element will be normalized to ``List[str]``. + The ``if`` field may be either a ``str``, a ``List[str]`` or a dict. + A ``str`` element or a ``List[str]`` will be normalized to ``IfAll([st= r])``. =20 :param expr: A ``dict``; the ``if`` field, if present, will be validat= ed. :param info: QAPI source file information. =20 :forms: - :sugared: ``Union[str, List[str]]`` - :canonical: ``List[str]`` + :sugared: ``Union[str, List[str], dict[str, object]]`` + :canonical: ``IfPredicate`` """ =20 - def check_if_str(ifcond: object) -> None: - if not isinstance(ifcond, str): + def normalize(cond: Union[str, List[str], object]) -> IfPredicate: + if isinstance(cond, str): + if not cond.strip(): + raise QAPISemError( + info, + "'if' condition '%s' of %s makes no sense" + % (cond, source)) + return IfOption(cond) + if isinstance(cond, list): + cond =3D {'all': cond} + if not isinstance(cond, dict): raise QAPISemError( info, - "'if' condition of %s must be a string or a list of string= s" + "'if' condition of %s must be a string, a list of strings = or a dict" % source) - if ifcond.strip() =3D=3D '': + if len(cond) !=3D 1: raise QAPISemError( info, - "'if' condition '%s' of %s makes no sense" - % (ifcond, source)) + "'if' condition dict of %s must have one key: 'all', 'any'= or 'not'" + % source) + check_keys(cond, info, "'if' condition", optional=3D('all', 'any',= 'not')) + op, operands =3D next(iter(cond.items())) + if op =3D=3D "not": + if isinstance(operands, list): + raise QAPISemError( + info, + "'if not' condition of %s must be a string or a dict" + % source) + return IfNot(normalize(operands)) + if not operands: + raise QAPISemError( + info, "'if' condition [] of %s is useless" % source) + operands =3D [normalize(o) for o in operands] + return IfAll(operands) if op =3D=3D "all" else IfAny(operands) =20 ifcond =3D expr.get('if') if ifcond is None: return - - if not isinstance(ifcond, list): - ifcond =3D [ifcond] - expr['if'] =3D ifcond - if not ifcond: - raise QAPISemError( - info, "'if' condition [] of %s is useless" % source) - for elt in ifcond: - check_if_str(elt) + expr['if'] =3D normalize(ifcond) =20 =20 def normalize_members(members: object) -> None: diff --git a/tests/qapi-schema/bad-if.err b/tests/qapi-schema/bad-if.err index f83dee65da..454fbae387 100644 --- a/tests/qapi-schema/bad-if.err +++ b/tests/qapi-schema/bad-if.err @@ -1,2 +1,3 @@ bad-if.json: In struct 'TestIfStruct': -bad-if.json:2: 'if' condition of struct must be a string or a list of stri= ngs +bad-if.json:2: 'if' condition has unknown key 'value' +Valid keys are 'all', 'any', 'not'. diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 0d27323c47..6b723d2341 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -12,15 +12,15 @@ enum QType module doc-good.json enum Enum member one - if IfAll(['defined(IFONE)']) + if 'defined(IFONE)' member two - if IfAll(['defined(IFCOND)']) + if 'defined(IFCOND)' feature enum-feat object Base member base1: Enum optional=3DFalse object Variant1 member var1: str optional=3DFalse - if IfAll(['defined(IFSTR)']) + if 'defined(IFSTR)' feature member-feat feature variant1-feat object Variant2 @@ -29,7 +29,7 @@ object Object tag base1 case one: Variant1 case two: Variant2 - if IfAll(['IFTWO']) + if 'IFTWO' feature union-feat1 object q_obj_Variant1-wrapper member data: Variant1 optional=3DFalse @@ -38,13 +38,13 @@ object q_obj_Variant2-wrapper enum SugaredUnionKind member one member two - if IfAll(['IFTWO']) + if 'IFTWO' object SugaredUnion member type: SugaredUnionKind optional=3DFalse tag type case one: q_obj_Variant1-wrapper case two: q_obj_Variant2-wrapper - if IfAll(['IFTWO']) + if 'IFTWO' feature union-feat2 alternate Alternate tag type diff --git a/tests/qapi-schema/enum-if-invalid.err b/tests/qapi-schema/enum= -if-invalid.err index 0556dc967b..3bb84075a9 100644 --- a/tests/qapi-schema/enum-if-invalid.err +++ b/tests/qapi-schema/enum-if-invalid.err @@ -1,2 +1,3 @@ enum-if-invalid.json: In enum 'TestIfEnum': -enum-if-invalid.json:2: 'if' condition of 'data' member 'bar' must be a st= ring or a list of strings +enum-if-invalid.json:2: 'if' condition has unknown key 'val' +Valid keys are 'all', 'any', 'not'. diff --git a/tests/qapi-schema/features-if-invalid.err b/tests/qapi-schema/= features-if-invalid.err index f63b89535e..724a810086 100644 --- a/tests/qapi-schema/features-if-invalid.err +++ b/tests/qapi-schema/features-if-invalid.err @@ -1,2 +1,2 @@ features-if-invalid.json: In struct 'Stru': -features-if-invalid.json:2: 'if' condition of 'features' member 'f' must b= e a string or a list of strings +features-if-invalid.json:2: 'if' condition of 'features' member 'f' must b= e a string, a list of strings or a dict diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 63f92adf68..6b3089a553 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -228,7 +228,7 @@ { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct', 'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} }, - 'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' } + 'if': ['defined(TEST_IF_UNION)', 'defined(TEST_IF_STRUCT)'] } =20 { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' }, 'if': 'defined(TEST_IF_UNION)' } @@ -236,10 +236,10 @@ { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} }, - 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } + 'if': {'all': ['defined(TEST_IF_ALT)', 'defined(TEST_IF_STRUCT)'] } } =20 { 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlterna= te' }, - 'if': 'defined(TEST_IF_ALT)' } + 'if': {'all': ['defined(TEST_IF_ALT)', {'not': 'defined(TEST_IF_NOT_ALT)= '}] } } =20 { 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', @@ -252,7 +252,7 @@ { 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct', 'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } }, - 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } + 'if': ['defined(TEST_IF_EVT)', 'defined(TEST_IF_STRUCT)'] } =20 # test 'features' =20 @@ -283,6 +283,10 @@ 'data': { 'foo': 'int' }, 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)'] }= ] } +{ 'struct': 'CondFeatureStruct4', + 'data': { 'foo': 'int' }, + 'features': [ { 'name': 'feature1', 'if': {'any': ['defined(TEST_IF_COND= _1)', + 'defined(TEST_IF_COND= _2)'] } } ] } =20 { 'enum': 'FeatureEnum1', 'data': [ 'eins', 'zwei', 'drei' ], @@ -306,7 +310,8 @@ 'fs4': 'FeatureStruct4', 'cfs1': 'CondFeatureStruct1', 'cfs2': 'CondFeatureStruct2', - 'cfs3': 'CondFeatureStruct3' }, + 'cfs3': 'CondFeatureStruct3', + 'cfs4': 'CondFeatureStruct4' }, 'features': [] } =20 { 'command': 'test-command-features1', diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 8ba658cd38..558427f6fa 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -298,49 +298,49 @@ command __org.qemu_x-command q_obj___org.qemu_x-comma= nd-arg -> __org.qemu_x-Unio object TestIfStruct member foo: int optional=3DFalse member bar: int optional=3DFalse - if IfAll(['defined(TEST_IF_STRUCT_BAR)']) - if IfAll(['defined(TEST_IF_STRUCT)']) + if 'defined(TEST_IF_STRUCT_BAR)' + if 'defined(TEST_IF_STRUCT)' enum TestIfEnum member foo member bar - if IfAll(['defined(TEST_IF_ENUM_BAR)']) - if IfAll(['defined(TEST_IF_ENUM)']) + if 'defined(TEST_IF_ENUM_BAR)' + if 'defined(TEST_IF_ENUM)' object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse enum TestIfUnionKind member foo member union_bar - if IfAll(['defined(TEST_IF_UNION_BAR)']) - if IfAll(['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']) + if 'defined(TEST_IF_UNION_BAR)' + if IfAll(['defined(TEST_IF_UNION)', 'defined(TEST_IF_STRUCT)']) object TestIfUnion member type: TestIfUnionKind optional=3DFalse tag type case foo: q_obj_TestStruct-wrapper case union_bar: q_obj_str-wrapper - if IfAll(['defined(TEST_IF_UNION_BAR)']) - if IfAll(['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']) + if 'defined(TEST_IF_UNION_BAR)' + if IfAll(['defined(TEST_IF_UNION)', 'defined(TEST_IF_STRUCT)']) object q_obj_TestIfUnionCmd-arg member union_cmd_arg: TestIfUnion optional=3DFalse - if IfAll(['defined(TEST_IF_UNION)']) + if 'defined(TEST_IF_UNION)' command TestIfUnionCmd q_obj_TestIfUnionCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if IfAll(['defined(TEST_IF_UNION)']) + if 'defined(TEST_IF_UNION)' alternate TestIfAlternate tag type case foo: int case bar: TestStruct - if IfAll(['defined(TEST_IF_ALT_BAR)']) - if IfAll(['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']) + if 'defined(TEST_IF_ALT_BAR)' + if IfAll(['defined(TEST_IF_ALT)', 'defined(TEST_IF_STRUCT)']) object q_obj_TestIfAlternateCmd-arg member alt_cmd_arg: TestIfAlternate optional=3DFalse - if IfAll(['defined(TEST_IF_ALT)']) + if IfAll(['defined(TEST_IF_ALT)', IfNot('defined(TEST_IF_NOT_ALT)')]) command TestIfAlternateCmd q_obj_TestIfAlternateCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if IfAll(['defined(TEST_IF_ALT)']) + if IfAll(['defined(TEST_IF_ALT)', IfNot('defined(TEST_IF_NOT_ALT)')]) object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse - if IfAll(['defined(TEST_IF_CMD_BAR)']) + if 'defined(TEST_IF_CMD_BAR)' if IfAll(['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']) command TestIfCmd q_obj_TestIfCmd-arg -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse @@ -348,15 +348,15 @@ command TestIfCmd q_obj_TestIfCmd-arg -> UserDefThree command TestCmdReturnDefThree None -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse array TestIfEnumList TestIfEnum - if IfAll(['defined(TEST_IF_ENUM)']) + if 'defined(TEST_IF_ENUM)' object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnumList optional=3DFalse - if IfAll(['defined(TEST_IF_EVT_BAR)']) - if IfAll(['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']) + if 'defined(TEST_IF_EVT_BAR)' + if IfAll(['defined(TEST_IF_EVT)', 'defined(TEST_IF_STRUCT)']) event TestIfEvent q_obj_TestIfEvent-arg boxed=3DFalse - if IfAll(['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']) + if IfAll(['defined(TEST_IF_EVT)', 'defined(TEST_IF_STRUCT)']) object FeatureStruct0 member foo: int optional=3DFalse object FeatureStruct1 @@ -379,17 +379,21 @@ object FeatureStruct4 object CondFeatureStruct1 member foo: int optional=3DFalse feature feature1 - if IfAll(['defined(TEST_IF_FEATURE_1)']) + if 'defined(TEST_IF_FEATURE_1)' object CondFeatureStruct2 member foo: int optional=3DFalse feature feature1 - if IfAll(['defined(TEST_IF_FEATURE_1)']) + if 'defined(TEST_IF_FEATURE_1)' feature feature2 - if IfAll(['defined(TEST_IF_FEATURE_2)']) + if 'defined(TEST_IF_FEATURE_2)' object CondFeatureStruct3 member foo: int optional=3DFalse feature feature1 if IfAll(['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']) +object CondFeatureStruct4 + member foo: int optional=3DFalse + feature feature1 + if IfAny(['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']) enum FeatureEnum1 member eins member zwei @@ -417,6 +421,7 @@ object q_obj_test-features0-arg member cfs1: CondFeatureStruct1 optional=3DFalse member cfs2: CondFeatureStruct2 optional=3DFalse member cfs3: CondFeatureStruct3 optional=3DFalse + member cfs4: CondFeatureStruct4 optional=3DFalse command test-features0 q_obj_test-features0-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse command test-command-features1 None -> None @@ -429,13 +434,13 @@ command test-command-features3 None -> None command test-command-cond-features1 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if IfAll(['defined(TEST_IF_FEATURE_1)']) + if 'defined(TEST_IF_FEATURE_1)' command test-command-cond-features2 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if IfAll(['defined(TEST_IF_FEATURE_1)']) + if 'defined(TEST_IF_FEATURE_1)' feature feature2 - if IfAll(['defined(TEST_IF_FEATURE_2)']) + if 'defined(TEST_IF_FEATURE_2)' command test-command-cond-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 diff --git a/tests/qapi-schema/struct-member-if-invalid.err b/tests/qapi-sc= hema/struct-member-if-invalid.err index 42e7fdae3c..c18157c1f9 100644 --- a/tests/qapi-schema/struct-member-if-invalid.err +++ b/tests/qapi-schema/struct-member-if-invalid.err @@ -1,2 +1,2 @@ struct-member-if-invalid.json: In struct 'Stru': -struct-member-if-invalid.json:2: 'if' condition of 'data' member 'member' = must be a string or a list of strings +struct-member-if-invalid.json:2: 'if' condition of 'data' member 'member' = must be a string, a list of strings or a dict diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index d3413bfef0..9aabf8ccd4 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -53,6 +53,7 @@ void qmp_test_features0(FeatureStruct0 *fs0, FeatureStruc= t1 *fs1, FeatureStruct2 *fs2, FeatureStruct3 *fs3, FeatureStruct4 *fs4, CondFeatureStruct1 *cfs1, CondFeatureStruct2 *cfs2, CondFeatureStruct3 *cfs3, + CondFeatureStruct4 *cfs4, Error **errp) { } --=20 2.28.0 From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602781577; cv=none; d=zohomail.com; s=zohoarc; b=YanFI5UC7di4TNT/JpQQnBzicEDcMg7ff6YvDDAHEPBdjqNcJxiLrXttDBtoRK720p1AFxPdIaMKUzZKwZSUFi6qvc4mA1Ae+agFNYU+ZsmE7Pp+9B0cy6IDBQE2+tnLw5tEahrXE1CPb0h7ADRVuhfCrsskextlULg3+CRpz0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602781577; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BzPE1ddA6M4fszTrzyMfKzVcxkVKauCY9P6JekU2oOM=; b=axmva7jDvcqY/mb+YI90nDH2ppOA1MCkK2eh4nbhdhPsqZ6triYwxFa5q9W7Lb5KRTG889D1A6Q0b2hPEeYEqWGVX1RaW/LXFlHPRtgPs7oxuBZ87N0nC1dFFWwtsQOzhTaSuICQtfcqlomyRUZqnfxv3zp2Xix1nmmres82HR8= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602781577811981.3343576168141; Thu, 15 Oct 2020 10:06:17 -0700 (PDT) Received: from localhost ([::1]:39086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6hl-0000Gx-43 for importer@patchew.org; Thu, 15 Oct 2020 13:06:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6W3-0003ue-Jk for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20849) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6W1-0001bZ-SL for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:11 -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-427-C1zHoL5-MQSerh6kDvCQ9g-1; Thu, 15 Oct 2020 12:54:04 -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 D379718C5204; Thu, 15 Oct 2020 16:54:03 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 288B619C59; Thu, 15 Oct 2020 16:53:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780849; 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=BzPE1ddA6M4fszTrzyMfKzVcxkVKauCY9P6JekU2oOM=; b=hzY7DNmaReLVD30UG0rTZtPrvTqYvB+D4thSvqP/CO4Re6inpbr6/LWDjo1f6bffh4qESa Cy1kdo6IVSqIdnZAOUoaZ+yWqZC9CT9Ra1CqxmWOdgQK6S1wOWkN4nbbPrm+PAAhZhVnOM Dt40GMjKBSUThNpCU34DA6aUHuj4whs= X-MC-Unique: C1zHoL5-MQSerh6kDvCQ9g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 7/9] qapi: convert 'if' C expressions to literal form Date: Thu, 15 Oct 2020 20:52:53 +0400 Message-Id: <20201015165255.1573897-8-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-1-marcandre.lureau@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=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=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:38:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/machine-target.json | 20 ++++++++++++++++---- qapi/misc-target.json | 13 ++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/qapi/machine-target.json b/qapi/machine-target.json index 698850cc78..de52a5ab59 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -213,7 +213,9 @@ ## { 'struct': 'CpuModelExpansionInfo', 'data': { 'model': 'CpuModelInfo' }, - 'if': 'defined(TARGET_S390X) || defined(TARGET_I386) || defined(TARGET_A= RM)' } + 'if': { 'any': [ 'defined(TARGET_S390X)', + 'defined(TARGET_I386)', + 'defined(TARGET_ARM)'] } } =20 ## # @query-cpu-model-expansion: @@ -252,7 +254,9 @@ 'data': { 'type': 'CpuModelExpansionType', 'model': 'CpuModelInfo' }, 'returns': 'CpuModelExpansionInfo', - 'if': 'defined(TARGET_S390X) || defined(TARGET_I386) || defined(TARGET_A= RM)' } + 'if': { 'any': [ 'defined(TARGET_S390X)', + 'defined(TARGET_I386)', + 'defined(TARGET_ARM)' ] } } =20 ## # @CpuDefinitionInfo: @@ -311,7 +315,11 @@ '*unavailable-features': [ 'str' ], 'typename': 'str', '*alias-of' : 'str' }, - 'if': 'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386= ) || defined(TARGET_S390X) || defined(TARGET_MIPS)' } + 'if': { 'any': [ 'defined(TARGET_PPC)', + 'defined(TARGET_ARM)', + 'defined(TARGET_I386)', + 'defined(TARGET_S390X)', + 'defined(TARGET_MIPS)' ] } } =20 ## # @query-cpu-definitions: @@ -323,4 +331,8 @@ # Since: 1.2.0 ## { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'], - 'if': 'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386= ) || defined(TARGET_S390X) || defined(TARGET_MIPS)' } + 'if': { 'any': [ 'defined(TARGET_PPC)', + 'defined(TARGET_ARM)', + 'defined(TARGET_I386)', + 'defined(TARGET_S390X)', + 'defined(TARGET_MIPS)' ] } } diff --git a/qapi/misc-target.json b/qapi/misc-target.json index 1e561fa97b..c1aa592137 100644 --- a/qapi/misc-target.json +++ b/qapi/misc-target.json @@ -23,7 +23,18 @@ ## { 'event': 'RTC_CHANGE', 'data': { 'offset': 'int' }, - 'if': 'defined(TARGET_ALPHA) || defined(TARGET_ARM) || defined(TARGET_HP= PA) || defined(TARGET_I386) || defined(TARGET_MIPS) || defined(TARGET_MIPS6= 4) || defined(TARGET_MOXIE) || defined(TARGET_PPC) || defined(TARGET_PPC64)= || defined(TARGET_S390X) || defined(TARGET_SH4) || defined(TARGET_SPARC)' } + 'if': { 'any': [ 'defined(TARGET_ALPHA)', + 'defined(TARGET_ARM)', + 'defined(TARGET_HPPA)', + 'defined(TARGET_I386)', + 'defined(TARGET_MIPS)', + 'defined(TARGET_MIPS64)', + 'defined(TARGET_MOXIE)', + 'defined(TARGET_PPC)', + 'defined(TARGET_PPC64)', + 'defined(TARGET_S390X)', + 'defined(TARGET_SH4)', + 'defined(TARGET_SPARC)' ] } } =20 ## # @rtc-reset-reinjection: --=20 2.28.0 From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602781958; cv=none; d=zohomail.com; s=zohoarc; b=nRIiTZ9wHuyHh9feM+aXhcGyMDQa15QTXqZvxU4xKwgGhs4ORlCeD0N20NjPwOJ3XqiG/4d6VAVsSjwXVZZDQP/VcVrKQos91thugS/QTrSS1ypfyaIaYymHiufoIlVrC0nDI38U1UjsC6qXNAl2DNMCCvMCJ42KTAq8n0CRMik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602781958; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sGpUUKTxHlXgN8S5gqoa96F/bOnf/O9i/MJWfJYLO0E=; b=aRPeBCsgD7AIrwNgN7VPYP44Erg5niisuNI45NTWPngOKO+lpw0yTntxjAcJI5qnx2xYntWn05kDwW4EziKXYcnlgeBuGB2NKslRBvLcb6kCTUrhyXFAQZa5Hi1nsOv07VxXnxEStO8ctsncwG6W2NioIm9pa7hxSB2TqPhjYzg= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602781958272290.91630989057614; Thu, 15 Oct 2020 10:12:38 -0700 (PDT) Received: from localhost ([::1]:57048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6nt-0007nz-F4 for importer@patchew.org; Thu, 15 Oct 2020 13:12:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6WP-0004HY-2i for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50432) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6WJ-0001cP-H5 for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:32 -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-154-jd7IJCLwMiqirmHClGeKAw-1; Thu, 15 Oct 2020 12:54:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1761B8D4421; Thu, 15 Oct 2020 16:54:13 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id A238075134; Thu, 15 Oct 2020 16:54:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780866; 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=sGpUUKTxHlXgN8S5gqoa96F/bOnf/O9i/MJWfJYLO0E=; b=fMasu1jt3xMDXVsPZGfGiDdFIjhtPnSKkokV+7ASUmr5BZ306800w2A3blWncdLHLJvFcG yaX7mfmeuT89OnsnJLeDSTq2R6pYT9JCk+Z3kILfSaV7xEPy8EaglvRBDzEqpxrvz2UbPo wA/IsC2PrsDCoS60ReyGpHThqzxYbu4= X-MC-Unique: jd7IJCLwMiqirmHClGeKAw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 8/9] qapi: make 'if' condition strings simple identifiers Date: Thu, 15 Oct 2020 20:52:54 +0400 Message-Id: <20201015165255.1573897-9-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:10:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Change the 'if' condition strings to be C-agnostic and be simple identifiers. Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/devel/qapi-code-gen.txt | 8 +-- qapi/block-core.json | 16 ++--- qapi/char.json | 8 +-- qapi/machine-target.json | 40 ++++++------- qapi/migration.json | 10 ++-- qapi/misc-target.json | 46 +++++++------- qapi/ui.json | 48 +++++++-------- scripts/qapi/common.py | 2 +- scripts/qapi/expr.py | 10 ++-- .../alternate-branch-if-invalid.err | 2 +- tests/qapi-schema/bad-if-empty.err | 2 +- tests/qapi-schema/bad-if-list.err | 2 +- tests/qapi-schema/bad-if.json | 2 +- tests/qapi-schema/doc-good.json | 6 +- tests/qapi-schema/doc-good.out | 6 +- tests/qapi-schema/features-missing-name.json | 2 +- tests/qapi-schema/qapi-schema-test.json | 52 ++++++++-------- tests/qapi-schema/qapi-schema-test.out | 60 +++++++++---------- tests/qapi-schema/union-branch-if-invalid.err | 2 +- 19 files changed, 162 insertions(+), 162 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index c6438c6aa9..3d22a7ae21 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -783,7 +783,7 @@ will then be guarded by #if STRING for each STRING in t= he COND list. Example: a conditional struct =20 { 'struct': 'IfStruct', 'data': { 'foo': 'int' }, - 'if': ['defined(CONFIG_FOO)', 'defined(HAVE_BAR)'] } + 'if': ['CONFIG_FOO', 'HAVE_BAR'] } =20 gets its generated code guarded like this: =20 @@ -802,7 +802,7 @@ member 'bar' =20 { 'struct': 'IfStruct', 'data': { 'foo': 'int', - 'bar': { 'type': 'int', 'if': 'defined(IFCOND)'} } } + 'bar': { 'type': 'int', 'if': 'IFCOND'} } } =20 A union's discriminator may not be conditional. =20 @@ -814,7 +814,7 @@ value 'bar' =20 { 'enum': 'IfEnum', 'data': [ 'foo', - { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] } + { 'name' : 'bar', 'if': 'IFCOND' } ] } =20 Likewise, features can be conditional. This requires the longhand form of FEATURE. @@ -824,7 +824,7 @@ Example: a struct with conditional feature 'allow-negat= ive-numbers' { 'struct': 'TestType', 'data': { 'number': 'int' }, 'features': [ { 'name': 'allow-negative-numbers', - 'if' 'defined(IFCOND)' } ] } + 'if': 'IFCOND' } ] } =20 Please note that you are responsible to ensure that the C code will compile with an arbitrary combination of conditions, since the diff --git a/qapi/block-core.json b/qapi/block-core.json index 18f4ea90f1..9ebef3a705 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2791,7 +2791,7 @@ ## { 'enum': 'BlockdevAioOptions', 'data': [ 'threads', 'native', - { 'name': 'io_uring', 'if': 'defined(CONFIG_LINUX_IO_URING)' }= ] } + { 'name': 'io_uring', 'if': 'CONFIG_LINUX_IO_URING' } ] } =20 ## # @BlockdevCacheOptions: @@ -2829,7 +2829,7 @@ 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscs= i', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallel= s', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', - { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' }, + { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, 'sheepdog', 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } =20 @@ -2872,10 +2872,10 @@ '*locking': 'OnOffAuto', '*aio': 'BlockdevAioOptions', '*drop-cache': {'type': 'bool', - 'if': 'defined(CONFIG_LINUX)'}, + 'if': 'CONFIG_LINUX'}, '*x-check-cache-dropped': 'bool' }, 'features': [ { 'name': 'dynamic-auto-read-only', - 'if': 'defined(CONFIG_POSIX)' } ] } + 'if': 'CONFIG_POSIX' } ] } =20 ## # @BlockdevOptionsNull: @@ -3678,7 +3678,7 @@ # Since: 2.9 ## { 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ], - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @BlockdevOptionsReplication: @@ -3697,7 +3697,7 @@ 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', '*top-id': 'str' }, - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @NFSTransport: @@ -4009,7 +4009,7 @@ 'raw': 'BlockdevOptionsRaw', 'rbd': 'BlockdevOptionsRbd', 'replication': { 'type': 'BlockdevOptionsReplication', - 'if': 'defined(CONFIG_REPLICATION)' }, + 'if': 'CONFIG_REPLICATION' }, 'sheepdog': 'BlockdevOptionsSheepdog', 'ssh': 'BlockdevOptionsSsh', 'throttle': 'BlockdevOptionsThrottle', @@ -4311,7 +4311,7 @@ # Since: 5.1 ## { 'enum': 'Qcow2CompressionType', - 'data': [ 'zlib', { 'name': 'zstd', 'if': 'defined(CONFIG_ZSTD)' } ] } + 'data': [ 'zlib', { 'name': 'zstd', 'if': 'CONFIG_ZSTD' } ] } =20 ## # @BlockdevCreateOptionsQcow2: diff --git a/qapi/char.json b/qapi/char.json index b4d66ec90b..be28845cf9 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -343,7 +343,7 @@ { 'struct': 'ChardevSpiceChannel', 'data': { 'type': 'str' }, 'base': 'ChardevCommon', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @ChardevSpicePort: @@ -357,7 +357,7 @@ { 'struct': 'ChardevSpicePort', 'data': { 'fqdn': 'str' }, 'base': 'ChardevCommon', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @ChardevVC: @@ -415,9 +415,9 @@ 'stdio': 'ChardevStdio', 'console': 'ChardevCommon', 'spicevmc': { 'type': 'ChardevSpiceChannel', - 'if': 'defined(CONFIG_SPICE)' }, + 'if': 'CONFIG_SPICE' }, 'spiceport': { 'type': 'ChardevSpicePort', - 'if': 'defined(CONFIG_SPICE)' }, + 'if': 'CONFIG_SPICE' }, 'vc': 'ChardevVC', 'ringbuf': 'ChardevRingbuf', # next one is just for compatibility diff --git a/qapi/machine-target.json b/qapi/machine-target.json index de52a5ab59..4848ef70db 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -89,7 +89,7 @@ ## { 'struct': 'CpuModelBaselineInfo', 'data': { 'model': 'CpuModelInfo' }, - 'if': 'defined(TARGET_S390X)' } + 'if': 'TARGET_S390X' } =20 ## # @CpuModelCompareInfo: @@ -112,7 +112,7 @@ { 'struct': 'CpuModelCompareInfo', 'data': { 'result': 'CpuModelCompareResult', 'responsible-properties': ['str'] }, - 'if': 'defined(TARGET_S390X)' } + 'if': 'TARGET_S390X' } =20 ## # @query-cpu-model-comparison: @@ -156,7 +156,7 @@ { 'command': 'query-cpu-model-comparison', 'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' }, 'returns': 'CpuModelCompareInfo', - 'if': 'defined(TARGET_S390X)' } + 'if': 'TARGET_S390X' } =20 ## # @query-cpu-model-baseline: @@ -200,7 +200,7 @@ 'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' }, 'returns': 'CpuModelBaselineInfo', - 'if': 'defined(TARGET_S390X)' } + 'if': 'TARGET_S390X' } =20 ## # @CpuModelExpansionInfo: @@ -213,9 +213,9 @@ ## { 'struct': 'CpuModelExpansionInfo', 'data': { 'model': 'CpuModelInfo' }, - 'if': { 'any': [ 'defined(TARGET_S390X)', - 'defined(TARGET_I386)', - 'defined(TARGET_ARM)'] } } + 'if': { 'any': [ 'TARGET_S390X', + 'TARGET_I386', + 'TARGET_ARM' ] } } =20 ## # @query-cpu-model-expansion: @@ -254,9 +254,9 @@ 'data': { 'type': 'CpuModelExpansionType', 'model': 'CpuModelInfo' }, 'returns': 'CpuModelExpansionInfo', - 'if': { 'any': [ 'defined(TARGET_S390X)', - 'defined(TARGET_I386)', - 'defined(TARGET_ARM)' ] } } + 'if': { 'any': [ 'TARGET_S390X', + 'TARGET_I386', + 'TARGET_ARM' ] } } =20 ## # @CpuDefinitionInfo: @@ -315,11 +315,11 @@ '*unavailable-features': [ 'str' ], 'typename': 'str', '*alias-of' : 'str' }, - 'if': { 'any': [ 'defined(TARGET_PPC)', - 'defined(TARGET_ARM)', - 'defined(TARGET_I386)', - 'defined(TARGET_S390X)', - 'defined(TARGET_MIPS)' ] } } + 'if': { 'any': [ 'TARGET_PPC', + 'TARGET_ARM', + 'TARGET_I386', + 'TARGET_S390X', + 'TARGET_MIPS' ] } } =20 ## # @query-cpu-definitions: @@ -331,8 +331,8 @@ # Since: 1.2.0 ## { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'], - 'if': { 'any': [ 'defined(TARGET_PPC)', - 'defined(TARGET_ARM)', - 'defined(TARGET_I386)', - 'defined(TARGET_S390X)', - 'defined(TARGET_MIPS)' ] } } + 'if': { 'any': [ 'TARGET_PPC', + 'TARGET_ARM', + 'TARGET_I386', + 'TARGET_S390X', + 'TARGET_MIPS' ] } } diff --git a/qapi/migration.json b/qapi/migration.json index 7f5e6fd681..ebdd664dc7 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -506,7 +506,7 @@ ## { 'enum': 'MultiFDCompression', 'data': [ 'none', 'zlib', - { 'name': 'zstd', 'if': 'defined(CONFIG_ZSTD)' } ] } + { 'name': 'zstd', 'if': 'CONFIG_ZSTD' } ] } =20 ## # @BitmapMigrationBitmapAlias: @@ -1575,7 +1575,7 @@ ## { 'command': 'xen-set-replication', 'data': { 'enable': 'bool', 'primary': 'bool', '*failover' : 'bool' }, - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @ReplicationStatus: @@ -1591,7 +1591,7 @@ ## { 'struct': 'ReplicationStatus', 'data': { 'error': 'bool', '*desc': 'str' }, - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @query-xen-replication-status: @@ -1609,7 +1609,7 @@ ## { 'command': 'query-xen-replication-status', 'returns': 'ReplicationStatus', - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @xen-colo-do-checkpoint: @@ -1626,7 +1626,7 @@ # Since: 2.9 ## { 'command': 'xen-colo-do-checkpoint', - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @COLOStatus: diff --git a/qapi/misc-target.json b/qapi/misc-target.json index c1aa592137..6799a4c977 100644 --- a/qapi/misc-target.json +++ b/qapi/misc-target.json @@ -23,18 +23,18 @@ ## { 'event': 'RTC_CHANGE', 'data': { 'offset': 'int' }, - 'if': { 'any': [ 'defined(TARGET_ALPHA)', - 'defined(TARGET_ARM)', - 'defined(TARGET_HPPA)', - 'defined(TARGET_I386)', - 'defined(TARGET_MIPS)', - 'defined(TARGET_MIPS64)', - 'defined(TARGET_MOXIE)', - 'defined(TARGET_PPC)', - 'defined(TARGET_PPC64)', - 'defined(TARGET_S390X)', - 'defined(TARGET_SH4)', - 'defined(TARGET_SPARC)' ] } } + 'if': { 'any': [ 'TARGET_ALPHA', + 'TARGET_ARM', + 'TARGET_HPPA', + 'TARGET_I386', + 'TARGET_MIPS', + 'TARGET_MIPS64', + 'TARGET_MOXIE', + 'TARGET_PPC', + 'TARGET_PPC64', + 'TARGET_S390X', + 'TARGET_SH4', + 'TARGET_SPARC' ] } } =20 ## # @rtc-reset-reinjection: @@ -53,7 +53,7 @@ # ## { 'command': 'rtc-reset-reinjection', - 'if': 'defined(TARGET_I386)' } + 'if': 'TARGET_I386' } =20 =20 ## @@ -80,7 +80,7 @@ { 'enum': 'SevState', 'data': ['uninit', 'launch-update', 'launch-secret', 'running', 'send-update', 'receive-update' ], - 'if': 'defined(TARGET_I386)' } + 'if': 'TARGET_I386' } =20 ## # @SevInfo: @@ -112,7 +112,7 @@ 'state' : 'SevState', 'handle' : 'uint32' }, - 'if': 'defined(TARGET_I386)' + 'if': 'TARGET_I386' } =20 ## @@ -133,7 +133,7 @@ # ## { 'command': 'query-sev', 'returns': 'SevInfo', - 'if': 'defined(TARGET_I386)' } + 'if': 'TARGET_I386' } =20 =20 ## @@ -147,7 +147,7 @@ # ## { 'struct': 'SevLaunchMeasureInfo', 'data': {'data': 'str'}, - 'if': 'defined(TARGET_I386)' } + 'if': 'TARGET_I386' } =20 ## # @query-sev-launch-measure: @@ -165,7 +165,7 @@ # ## { 'command': 'query-sev-launch-measure', 'returns': 'SevLaunchMeasureInfo', - 'if': 'defined(TARGET_I386)' } + 'if': 'TARGET_I386' } =20 =20 ## @@ -190,7 +190,7 @@ 'cert-chain': 'str', 'cbitpos': 'int', 'reduced-phys-bits': 'int'}, - 'if': 'defined(TARGET_I386)' } + 'if': 'TARGET_I386' } =20 ## # @query-sev-capabilities: @@ -210,7 +210,7 @@ # ## { 'command': 'query-sev-capabilities', 'returns': 'SevCapability', - 'if': 'defined(TARGET_I386)' } + 'if': 'TARGET_I386' } =20 ## # @dump-skeys: @@ -232,7 +232,7 @@ ## { 'command': 'dump-skeys', 'data': { 'filename': 'str' }, - 'if': 'defined(TARGET_S390X)' } + 'if': 'TARGET_S390X' } =20 ## # @GICCapability: @@ -257,7 +257,7 @@ 'data': { 'version': 'int', 'emulated': 'bool', 'kernel': 'bool' }, - 'if': 'defined(TARGET_ARM)' } + 'if': 'TARGET_ARM' } =20 ## # @query-gic-capabilities: @@ -277,4 +277,4 @@ # ## { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'], - 'if': 'defined(TARGET_ARM)' } + 'if': 'TARGET_ARM' } diff --git a/qapi/ui.json b/qapi/ui.json index 9d6721037f..989fb4ff5e 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -121,7 +121,7 @@ 'data': { 'host': 'str', 'port': 'str', 'family': 'NetworkAddressFamily' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SpiceServerInfo: @@ -135,7 +135,7 @@ { 'struct': 'SpiceServerInfo', 'base': 'SpiceBasicInfo', 'data': { '*auth': 'str' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SpiceChannel: @@ -161,7 +161,7 @@ 'base': 'SpiceBasicInfo', 'data': {'connection-id': 'int', 'channel-type': 'int', 'channel-id': 'i= nt', 'tls': 'bool'}, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SpiceQueryMouseMode: @@ -181,7 +181,7 @@ ## { 'enum': 'SpiceQueryMouseMode', 'data': [ 'client', 'server', 'unknown' ], - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SpiceInfo: @@ -220,7 +220,7 @@ 'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str', '*port':= 'int', '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str', 'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChanne= l']}, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @query-spice: @@ -266,7 +266,7 @@ # ## { 'command': 'query-spice', 'returns': 'SpiceInfo', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SPICE_CONNECTED: @@ -292,7 +292,7 @@ { 'event': 'SPICE_CONNECTED', 'data': { 'server': 'SpiceBasicInfo', 'client': 'SpiceBasicInfo' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SPICE_INITIALIZED: @@ -321,7 +321,7 @@ { 'event': 'SPICE_INITIALIZED', 'data': { 'server': 'SpiceServerInfo', 'client': 'SpiceChannel' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SPICE_DISCONNECTED: @@ -347,7 +347,7 @@ { 'event': 'SPICE_DISCONNECTED', 'data': { 'server': 'SpiceBasicInfo', 'client': 'SpiceBasicInfo' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SPICE_MIGRATE_COMPLETED: @@ -363,7 +363,7 @@ # ## { 'event': 'SPICE_MIGRATE_COMPLETED', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # =3D=3D VNC @@ -391,7 +391,7 @@ 'service': 'str', 'family': 'NetworkAddressFamily', 'websocket': 'bool' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncServerInfo: @@ -406,7 +406,7 @@ { 'struct': 'VncServerInfo', 'base': 'VncBasicInfo', 'data': { '*auth': 'str' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncClientInfo: @@ -424,7 +424,7 @@ { 'struct': 'VncClientInfo', 'base': 'VncBasicInfo', 'data': { '*x509_dname': 'str', '*sasl_username': 'str' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncInfo: @@ -467,7 +467,7 @@ 'data': {'enabled': 'bool', '*host': 'str', '*family': 'NetworkAddressFamily', '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo'= ]}, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncPrimaryAuth: @@ -479,7 +479,7 @@ { 'enum': 'VncPrimaryAuth', 'data': [ 'none', 'vnc', 'ra2', 'ra2ne', 'tight', 'ultra', 'tls', 'vencrypt', 'sasl' ], - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncVencryptSubAuth: @@ -494,7 +494,7 @@ 'tls-vnc', 'x509-vnc', 'tls-plain', 'x509-plain', 'tls-sasl', 'x509-sasl' ], - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncServerInfo2: @@ -512,7 +512,7 @@ 'base': 'VncBasicInfo', 'data': { 'auth' : 'VncPrimaryAuth', '*vencrypt' : 'VncVencryptSubAuth' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncInfo2: @@ -545,7 +545,7 @@ 'auth' : 'VncPrimaryAuth', '*vencrypt' : 'VncVencryptSubAuth', '*display' : 'str' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @query-vnc: @@ -577,7 +577,7 @@ # ## { 'command': 'query-vnc', 'returns': 'VncInfo', - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } ## # @query-vnc-servers: # @@ -588,7 +588,7 @@ # Since: 2.3 ## { 'command': 'query-vnc-servers', 'returns': ['VncInfo2'], - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @change-vnc-password: @@ -604,7 +604,7 @@ ## { 'command': 'change-vnc-password', 'data': { 'password': 'str' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VNC_CONNECTED: @@ -634,7 +634,7 @@ { 'event': 'VNC_CONNECTED', 'data': { 'server': 'VncServerInfo', 'client': 'VncBasicInfo' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VNC_INITIALIZED: @@ -662,7 +662,7 @@ { 'event': 'VNC_INITIALIZED', 'data': { 'server': 'VncServerInfo', 'client': 'VncClientInfo' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VNC_DISCONNECTED: @@ -689,7 +689,7 @@ { 'event': 'VNC_DISCONNECTED', 'data': { 'server': 'VncServerInfo', 'client': 'VncClientInfo' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # =3D Input diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index b855a6dc78..fcd29636a0 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -204,7 +204,7 @@ class IfOption(IfPredicate): self.option =3D option =20 def cgen(self) -> str: - return self.option + return f"defined({self.option})" =20 def __repr__(self) -> str: return repr(self.option) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 0f0e01cb78..655b010a7c 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -209,11 +209,11 @@ def check_if(expr: _JSObject, info: QAPISourceInfo, s= ource: str) -> None: =20 def normalize(cond: Union[str, List[str], object]) -> IfPredicate: if isinstance(cond, str): - if not cond.strip(): - raise QAPISemError( - info, - "'if' condition '%s' of %s makes no sense" - % (cond, source)) + if not cond.isidentifier(): + raise QAPISemError( + info, + "'if' option string '%s' of %s is not a valid identifi= er" + % (cond, source)) return IfOption(cond) if isinstance(cond, list): cond =3D {'all': cond} diff --git a/tests/qapi-schema/alternate-branch-if-invalid.err b/tests/qapi= -schema/alternate-branch-if-invalid.err index d384929c51..e36580845e 100644 --- a/tests/qapi-schema/alternate-branch-if-invalid.err +++ b/tests/qapi-schema/alternate-branch-if-invalid.err @@ -1,2 +1,2 @@ alternate-branch-if-invalid.json: In alternate 'Alt': -alternate-branch-if-invalid.json:2: 'if' condition ' ' of 'data' member 'b= ranch' makes no sense +alternate-branch-if-invalid.json:2: 'if' option string ' ' of 'data' membe= r 'branch' is not a valid identifier diff --git a/tests/qapi-schema/bad-if-empty.err b/tests/qapi-schema/bad-if-= empty.err index a0f3effefb..011aaab017 100644 --- a/tests/qapi-schema/bad-if-empty.err +++ b/tests/qapi-schema/bad-if-empty.err @@ -1,2 +1,2 @@ bad-if-empty.json: In struct 'TestIfStruct': -bad-if-empty.json:2: 'if' condition '' of struct makes no sense +bad-if-empty.json:2: 'if' option string '' of struct is not a valid identi= fier diff --git a/tests/qapi-schema/bad-if-list.err b/tests/qapi-schema/bad-if-l= ist.err index c462f11b90..f84b945bea 100644 --- a/tests/qapi-schema/bad-if-list.err +++ b/tests/qapi-schema/bad-if-list.err @@ -1,2 +1,2 @@ bad-if-list.json: In struct 'TestIfStruct': -bad-if-list.json:2: 'if' condition ' ' of struct makes no sense +bad-if-list.json:2: 'if' option string ' ' of struct is not a valid identi= fier diff --git a/tests/qapi-schema/bad-if.json b/tests/qapi-schema/bad-if.json index 3edd1a0bf2..67818888de 100644 --- a/tests/qapi-schema/bad-if.json +++ b/tests/qapi-schema/bad-if.json @@ -1,3 +1,3 @@ # check invalid 'if' type { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, - 'if': { 'value': 'defined(TEST_IF_STRUCT)' } } + 'if': { 'value': 'TEST_IF_STRUCT' } } diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index e9af0857db..b4a4175f26 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -61,9 +61,9 @@ # @two is undocumented ## { 'enum': 'Enum', 'data': - [ { 'name': 'one', 'if': 'defined(IFONE)' }, 'two' ], + [ { 'name': 'one', 'if': 'IFONE' }, 'two' ], 'features': [ 'enum-feat' ], - 'if': 'defined(IFCOND)' } + 'if': 'IFCOND' } =20 ## # @Base: @@ -86,7 +86,7 @@ 'features': [ 'variant1-feat' ], 'data': { 'var1': { 'type': 'str', 'features': [ 'member-feat' ], - 'if': 'defined(IFSTR)' } } } + 'if': 'IFSTR' } } } =20 ## # @Variant2: diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 6b723d2341..f9af1836e1 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -12,15 +12,15 @@ enum QType module doc-good.json enum Enum member one - if 'defined(IFONE)' + if 'IFONE' member two - if 'defined(IFCOND)' + if 'IFCOND' feature enum-feat object Base member base1: Enum optional=3DFalse object Variant1 member var1: str optional=3DFalse - if 'defined(IFSTR)' + if 'IFSTR' feature member-feat feature variant1-feat object Variant2 diff --git a/tests/qapi-schema/features-missing-name.json b/tests/qapi-sche= ma/features-missing-name.json index 2314f97c00..8772c8f7b3 100644 --- a/tests/qapi-schema/features-missing-name.json +++ b/tests/qapi-schema/features-missing-name.json @@ -1,3 +1,3 @@ { 'struct': 'FeatureStruct0', 'data': { 'foo': 'int' }, - 'features': [ { 'if': 'defined(NAMELESS_FEATURES)' } ] } + 'features': [ { 'if': 'NAMELESS_FEATURES' } ] } diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 6b3089a553..a84d922bac 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -218,41 +218,41 @@ =20 { 'struct': 'TestIfStruct', 'data': { 'foo': 'int', - 'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} }, - 'if': 'defined(TEST_IF_STRUCT)' } + 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} }, + 'if': 'TEST_IF_STRUCT' } =20 { 'enum': 'TestIfEnum', 'data': - [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ], - 'if': 'defined(TEST_IF_ENUM)' } + [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ], + 'if': 'TEST_IF_ENUM' } =20 { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct', - 'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} }, - 'if': ['defined(TEST_IF_UNION)', 'defined(TEST_IF_STRUCT)'] } + 'union_bar': { 'type': 'str', 'if': 'TEST_IF_UNION_BAR'} }, + 'if': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } =20 { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' }, - 'if': 'defined(TEST_IF_UNION)' } + 'if': 'TEST_IF_UNION' } =20 { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', - 'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} }, - 'if': {'all': ['defined(TEST_IF_ALT)', 'defined(TEST_IF_STRUCT)'] } } + 'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_BAR'} }, + 'if': {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } } =20 { 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlterna= te' }, - 'if': {'all': ['defined(TEST_IF_ALT)', {'not': 'defined(TEST_IF_NOT_ALT)= '}] } } + 'if': {'all': ['TEST_IF_ALT', {'not': 'TEST_IF_NOT_ALT'}] } } =20 { 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', - 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } }, + 'bar': { 'type': 'TestIfEnum', 'if': 'TEST_IF_CMD_BAR' } }, 'returns': 'UserDefThree', - 'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] } + 'if': ['TEST_IF_CMD', 'TEST_IF_STRUCT'] } =20 { 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' } =20 { 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct', - 'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } }, - 'if': ['defined(TEST_IF_EVT)', 'defined(TEST_IF_STRUCT)'] } + 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } }, + 'if': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } =20 # test 'features' =20 @@ -274,19 +274,19 @@ =20 { 'struct': 'CondFeatureStruct1', 'data': { 'foo': 'int' }, - 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} = ] } + 'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'} ] } { 'struct': 'CondFeatureStruct2', 'data': { 'foo': 'int' }, - 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'}, - { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} = ] } + 'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'}, + { 'name': 'feature2', 'if': 'TEST_IF_FEATURE_2'} ] } { 'struct': 'CondFeatureStruct3', 'data': { 'foo': 'int' }, - 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', - 'defined(TEST_IF_COND_2)'] }= ] } + 'features': [ { 'name': 'feature1', 'if': [ 'TEST_IF_COND_1', + 'TEST_IF_COND_2'] } ] } { 'struct': 'CondFeatureStruct4', 'data': { 'foo': 'int' }, - 'features': [ { 'name': 'feature1', 'if': {'any': ['defined(TEST_IF_COND= _1)', - 'defined(TEST_IF_COND= _2)'] } } ] } + 'features': [ { 'name': 'feature1', 'if': {'any': ['TEST_IF_COND_1', + 'TEST_IF_COND_2'] } }= ] } =20 { 'enum': 'FeatureEnum1', 'data': [ 'eins', 'zwei', 'drei' ], @@ -320,13 +320,13 @@ 'features': [ 'feature1', 'feature2' ] } =20 { 'command': 'test-command-cond-features1', - 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'} = ] } + 'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'} ] } { 'command': 'test-command-cond-features2', - 'features': [ { 'name': 'feature1', 'if': 'defined(TEST_IF_FEATURE_1)'}, - { 'name': 'feature2', 'if': 'defined(TEST_IF_FEATURE_2)'} = ] } + 'features': [ { 'name': 'feature1', 'if': 'TEST_IF_FEATURE_1'}, + { 'name': 'feature2', 'if': 'TEST_IF_FEATURE_2'} ] } { 'command': 'test-command-cond-features3', - 'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)', - 'defined(TEST_IF_COND_2)'] }= ] } + 'features': [ { 'name': 'feature1', 'if': [ 'TEST_IF_COND_1', + 'TEST_IF_COND_2' ] } ] } =20 { 'event': 'TEST-EVENT-FEATURES1', 'features': [ 'deprecated' ] } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 558427f6fa..24a9f42172 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -298,65 +298,65 @@ command __org.qemu_x-command q_obj___org.qemu_x-comma= nd-arg -> __org.qemu_x-Unio object TestIfStruct member foo: int optional=3DFalse member bar: int optional=3DFalse - if 'defined(TEST_IF_STRUCT_BAR)' - if 'defined(TEST_IF_STRUCT)' + if 'TEST_IF_STRUCT_BAR' + if 'TEST_IF_STRUCT' enum TestIfEnum member foo member bar - if 'defined(TEST_IF_ENUM_BAR)' - if 'defined(TEST_IF_ENUM)' + if 'TEST_IF_ENUM_BAR' + if 'TEST_IF_ENUM' object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse enum TestIfUnionKind member foo member union_bar - if 'defined(TEST_IF_UNION_BAR)' - if IfAll(['defined(TEST_IF_UNION)', 'defined(TEST_IF_STRUCT)']) + if 'TEST_IF_UNION_BAR' + if IfAll(['TEST_IF_UNION', 'TEST_IF_STRUCT']) object TestIfUnion member type: TestIfUnionKind optional=3DFalse tag type case foo: q_obj_TestStruct-wrapper case union_bar: q_obj_str-wrapper - if 'defined(TEST_IF_UNION_BAR)' - if IfAll(['defined(TEST_IF_UNION)', 'defined(TEST_IF_STRUCT)']) + if 'TEST_IF_UNION_BAR' + if IfAll(['TEST_IF_UNION', 'TEST_IF_STRUCT']) object q_obj_TestIfUnionCmd-arg member union_cmd_arg: TestIfUnion optional=3DFalse - if 'defined(TEST_IF_UNION)' + if 'TEST_IF_UNION' command TestIfUnionCmd q_obj_TestIfUnionCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if 'defined(TEST_IF_UNION)' + if 'TEST_IF_UNION' alternate TestIfAlternate tag type case foo: int case bar: TestStruct - if 'defined(TEST_IF_ALT_BAR)' - if IfAll(['defined(TEST_IF_ALT)', 'defined(TEST_IF_STRUCT)']) + if 'TEST_IF_ALT_BAR' + if IfAll(['TEST_IF_ALT', 'TEST_IF_STRUCT']) object q_obj_TestIfAlternateCmd-arg member alt_cmd_arg: TestIfAlternate optional=3DFalse - if IfAll(['defined(TEST_IF_ALT)', IfNot('defined(TEST_IF_NOT_ALT)')]) + if IfAll(['TEST_IF_ALT', IfNot('TEST_IF_NOT_ALT')]) command TestIfAlternateCmd q_obj_TestIfAlternateCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if IfAll(['defined(TEST_IF_ALT)', IfNot('defined(TEST_IF_NOT_ALT)')]) + if IfAll(['TEST_IF_ALT', IfNot('TEST_IF_NOT_ALT')]) object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse - if 'defined(TEST_IF_CMD_BAR)' - if IfAll(['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']) + if 'TEST_IF_CMD_BAR' + if IfAll(['TEST_IF_CMD', 'TEST_IF_STRUCT']) command TestIfCmd q_obj_TestIfCmd-arg -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if IfAll(['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']) + if IfAll(['TEST_IF_CMD', 'TEST_IF_STRUCT']) command TestCmdReturnDefThree None -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse array TestIfEnumList TestIfEnum - if 'defined(TEST_IF_ENUM)' + if 'TEST_IF_ENUM' object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnumList optional=3DFalse - if 'defined(TEST_IF_EVT_BAR)' - if IfAll(['defined(TEST_IF_EVT)', 'defined(TEST_IF_STRUCT)']) + if 'TEST_IF_EVT_BAR' + if IfAll(['TEST_IF_EVT', 'TEST_IF_STRUCT']) event TestIfEvent q_obj_TestIfEvent-arg boxed=3DFalse - if IfAll(['defined(TEST_IF_EVT)', 'defined(TEST_IF_STRUCT)']) + if IfAll(['TEST_IF_EVT', 'TEST_IF_STRUCT']) object FeatureStruct0 member foo: int optional=3DFalse object FeatureStruct1 @@ -379,21 +379,21 @@ object FeatureStruct4 object CondFeatureStruct1 member foo: int optional=3DFalse feature feature1 - if 'defined(TEST_IF_FEATURE_1)' + if 'TEST_IF_FEATURE_1' object CondFeatureStruct2 member foo: int optional=3DFalse feature feature1 - if 'defined(TEST_IF_FEATURE_1)' + if 'TEST_IF_FEATURE_1' feature feature2 - if 'defined(TEST_IF_FEATURE_2)' + if 'TEST_IF_FEATURE_2' object CondFeatureStruct3 member foo: int optional=3DFalse feature feature1 - if IfAll(['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']) + if IfAll(['TEST_IF_COND_1', 'TEST_IF_COND_2']) object CondFeatureStruct4 member foo: int optional=3DFalse feature feature1 - if IfAny(['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']) + if IfAny(['TEST_IF_COND_1', 'TEST_IF_COND_2']) enum FeatureEnum1 member eins member zwei @@ -434,17 +434,17 @@ command test-command-features3 None -> None command test-command-cond-features1 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if 'defined(TEST_IF_FEATURE_1)' + if 'TEST_IF_FEATURE_1' command test-command-cond-features2 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if 'defined(TEST_IF_FEATURE_1)' + if 'TEST_IF_FEATURE_1' feature feature2 - if 'defined(TEST_IF_FEATURE_2)' + if 'TEST_IF_FEATURE_2' command test-command-cond-features3 None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse feature feature1 - if IfAll(['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']) + if IfAll(['TEST_IF_COND_1', 'TEST_IF_COND_2']) event TEST-EVENT-FEATURES1 None boxed=3DFalse feature deprecated diff --git a/tests/qapi-schema/union-branch-if-invalid.err b/tests/qapi-sch= ema/union-branch-if-invalid.err index dd4518233e..b3c44d4068 100644 --- a/tests/qapi-schema/union-branch-if-invalid.err +++ b/tests/qapi-schema/union-branch-if-invalid.err @@ -1,2 +1,2 @@ union-branch-if-invalid.json: In union 'Uni': -union-branch-if-invalid.json:4: 'if' condition '' of 'data' member 'branch= 1' makes no sense +union-branch-if-invalid.json:4: 'if' option string '' of 'data' member 'br= anch1' is not a valid identifier --=20 2.28.0 From nobody Mon Feb 9 08:41:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1602781830; cv=none; d=zohomail.com; s=zohoarc; b=AfFy+TyZN//GxrF3u5ysNgEFmueh+ozr4vrBLdf8hEv0epDvGkHN1kftZ8fRrgaST0zb4xvIvHPxTPD2Eb/ZsswMhMBEjP5ZgFUreIzeeUaDUhekZbX98S3L6BhcS4qf/qMrawXhOEDwjLMOt75WBX/1wQlrUIzpjNYKDVD4dJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602781830; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5Sj26bIfwzoSh0pwf4xCUF0bjGAIiIkNlullUUrKThk=; b=Tb+HI55CG/Xyl/Ap6DWYV00o2c2MiaZy7+ksYvqGCl/zP/Z5LBTEeRUix/o+Yffj67kieI5Uk4knNpcm/Pu/Wt81SXyjgLBVyxLzWm6+nomBFQxtoL0QbMQDD1CP8VYeE0ue4XwzeHD+unnvC4HDfNp1y6XjIYG8ziudFqoD8KM= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602781830947935.2981488989473; Thu, 15 Oct 2020 10:10:30 -0700 (PDT) Received: from localhost ([::1]:50440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT6lq-0004zG-3i for importer@patchew.org; Thu, 15 Oct 2020 13:10:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT6WF-0004EV-RL for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kT6WE-0001c6-0Q for qemu-devel@nongnu.org; Thu, 15 Oct 2020 12:54: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-474-NUhOTj1SM1iiwADUthbnGw-1; Thu, 15 Oct 2020 12:54:19 -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 1A1CF80363A; Thu, 15 Oct 2020 16:54:18 +0000 (UTC) Received: from localhost (unknown [10.36.110.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 145C419C59; Thu, 15 Oct 2020 16:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602780861; 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=5Sj26bIfwzoSh0pwf4xCUF0bjGAIiIkNlullUUrKThk=; b=GNIfKh3xoshtu8uPkv1hQdP5pzJgytze2tA2nbIS15jZlHN3U7Ef3Co2+H4D9f1eg3qTY5 zLSWzJ+WlKpisJrBloUSrv7IlUzGREmV0w39p+L8dK+hbM1komNafDdsq4TRfbo8VAmbE5 8GTckJCRF/uE53Er/eXaX+7sSCfvKGg= X-MC-Unique: NUhOTj1SM1iiwADUthbnGw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 9/9] docs: update the documentation about schema configuration Date: Thu, 15 Oct 2020 20:52:55 +0400 Message-Id: <20201015165255.1573897-10-marcandre.lureau@redhat.com> In-Reply-To: <20201015165255.1573897-1-marcandre.lureau@redhat.com> References: <20201015165255.1573897-1-marcandre.lureau@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=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=63.128.21.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 02:10:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: jsnow@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/devel/qapi-code-gen.txt | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 3d22a7ae21..517bc29507 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -772,26 +772,30 @@ downstream command __com.redhat_drive-mirror. =3D=3D=3D Configuring the schema =3D=3D=3D =20 Syntax: - COND =3D STRING - | [ STRING, ... ] + COND =3D CFG-ID + | [ CFG-ID, ... ] + | { 'all: [ CFG-ID, ... ] } + | { 'any: [ CFG-ID, ... ] } + | { 'not': COND } =20 -All definitions take an optional 'if' member. Its value must be a -string or a list of strings. A string is shorthand for a list -containing just that string. The code generated for the definition -will then be guarded by #if STRING for each STRING in the COND list. + CFG-ID =3D STRING + +All definitions take an optional 'if' member. Its value must be a string, = a list +of strings or an object with a single member 'all', 'any' or 'not'. A stri= ng is +shorthand for a list containing just that string. A list is a shorthand fo= r a +'all'-member object. The C code generated for the definition will then be = guarded +by an #if precessor expression. =20 Example: a conditional struct =20 { 'struct': 'IfStruct', 'data': { 'foo': 'int' }, - 'if': ['CONFIG_FOO', 'HAVE_BAR'] } + 'if': { 'all': [ 'CONFIG_FOO', 'HAVE_BAR' ] } } =20 gets its generated code guarded like this: =20 - #if defined(CONFIG_FOO) - #if defined(HAVE_BAR) + #if defined(CONFIG_FOO) && defined(HAVE_BAR) ... generated code ... - #endif /* defined(HAVE_BAR) */ - #endif /* defined(CONFIG_FOO) */ + #endif /* defined(HAVE_BAR) && defined(CONFIG_FOO) */ =20 Individual members of complex types, commands arguments, and event-specific data can also be made conditional. This requires the --=20 2.28.0