From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619703838; cv=none; d=zohomail.com; s=zohoarc; b=lEZjmfNhKKbTGRSO5nTST0JZo3XyyH7QhcfL6WixGAzJiuCsgaWzLTlGJ839J4krE4LS2KU9Iq4Ab8d1ncYvIXcGhQxPlsNEQ6ZQlVWRq3djWD+ptZc+AFMbydDBUvd2r9h4PpfTL0OQoZZftj+YParcEQ75p6xVTyPURbcQL54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619703838; 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=374zTNOmprZBs7o1dH9AG7V8cbL64TYGwjzkZF2ZHVI=; b=lQViJ4JdWNdXZ8JAtDTA7XZHWm4ZLR4yp+NjLmtLgxdn3mWiQo1KfruhrZTsxnSJvW85dOXZpNKUzA6VBdM0T8mG3npt3p0kADFlt0Rcc5yl0RA8rkePbMx/lcKJEMBZeCfI0E8fnNhk9OtPDQ9sl4I9zn7MK1UnKL93oQdelwQ= 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 1619703838516373.91708466559976; Thu, 29 Apr 2021 06:43:58 -0700 (PDT) Received: from localhost ([::1]:50370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc6xR-0006kD-98 for importer@patchew.org; Thu, 29 Apr 2021 09:43:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6uY-00053F-Iz for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:40:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6uR-0002Kx-Lj for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:40:58 -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-214-tWXyzFdONMKxHEt8gOv_xg-1; Thu, 29 Apr 2021 09:40:47 -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 B3742CC628 for ; Thu, 29 Apr 2021 13:40:46 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63BF360C17; Thu, 29 Apr 2021 13:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703651; 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=374zTNOmprZBs7o1dH9AG7V8cbL64TYGwjzkZF2ZHVI=; b=cEpr7tzGrm1SNBkCojVLjfcLIDfdAMhspGqXj9LxTLEteO0HAAdYUCuvUA9Gqk1H3T6Yss SK2nXdR3l5lirAybqFUys2baZ0HrC9hGxT0eX38lRrJb514Yxf74cnDpbTWptOk5JXpWoV MkPnwbuqi4BjNKmBnCepoyf47o4fL14= X-MC-Unique: tWXyzFdONMKxHEt8gOv_xg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 1/9] qapi: replace List[str] by QAPISchemaIfCond Date: Thu, 29 Apr 2021 17:40:24 +0400 Message-Id: <20210429134032.1125111-2-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-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=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 allows more type safety but also further refactoring without too much churn. The following patches will change the syntax of the schema 'if' conditions to be predicate expressions, and will generate code for different target languages (C, and Rust in another series). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- docs/sphinx/qapidoc.py | 2 +- scripts/qapi/commands.py | 4 +- scripts/qapi/events.py | 5 ++- scripts/qapi/gen.py | 14 +++---- scripts/qapi/introspect.py | 26 ++++++------- scripts/qapi/schema.py | 78 +++++++++++++++++++++++++++----------- scripts/qapi/types.py | 33 ++++++++-------- scripts/qapi/visit.py | 23 +++++------ 8 files changed, 110 insertions(+), 75 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index 87c67ab23f..b737949007 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -116,7 +116,7 @@ def _nodes_for_ifcond(self, ifcond, with_if=3DTrue): 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 0e13d51054..3654825968 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -17,7 +17,6 @@ Dict, List, Optional, - Sequence, Set, ) =20 @@ -31,6 +30,7 @@ from .schema import ( QAPISchema, QAPISchemaFeature, + QAPISchemaIfCond, QAPISchemaObjectType, QAPISchemaType, ) @@ -301,7 +301,7 @@ def visit_end(self) -> None: def visit_command(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], ret_type: Optional[QAPISchemaType], diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index fee8c671e7..82475e84ec 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,7 +12,7 @@ See the COPYING file in the top-level directory. """ =20 -from typing import List, Optional, Sequence +from typing import List, Optional =20 from .common import c_enum_const, c_name, mcgen from .gen import QAPISchemaModularCVisitor, build_params, ifcontext @@ -20,6 +20,7 @@ QAPISchema, QAPISchemaEnumMember, QAPISchemaFeature, + QAPISchemaIfCond, QAPISchemaObjectType, ) from .source import QAPISourceInfo @@ -227,7 +228,7 @@ def visit_end(self) -> None: def visit_event(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], boxed: bool) -> None: diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 1fa503bdbd..1c5b190276 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -18,7 +18,6 @@ Dict, Iterator, Optional, - Sequence, Tuple, ) =20 @@ -32,6 +31,7 @@ mcgen, ) from .schema import ( + QAPISchemaIfCond, QAPISchemaModule, QAPISchemaObjectType, QAPISchemaVisitor, @@ -85,7 +85,7 @@ def write(self, output_dir: str) -> None: fp.write(text) =20 =20 -def _wrap_ifcond(ifcond: Sequence[str], before: str, after: str) -> str: +def _wrap_ifcond(ifcond: QAPISchemaIfCond, before: str, after: str) -> str: if before =3D=3D after: return after # suppress empty #if ... #endif =20 @@ -95,9 +95,9 @@ def _wrap_ifcond(ifcond: Sequence[str], before: str, afte= r: str) -> str: if added[0] =3D=3D '\n': out +=3D '\n' added =3D added[1:] - out +=3D gen_if(ifcond) + out +=3D gen_if(ifcond.ifcond) out +=3D added - out +=3D gen_endif(ifcond) + out +=3D gen_endif(ifcond.ifcond) return out =20 =20 @@ -127,9 +127,9 @@ def build_params(arg_type: Optional[QAPISchemaObjectTyp= e], class QAPIGenCCode(QAPIGen): def __init__(self, fname: str): super().__init__(fname) - self._start_if: Optional[Tuple[Sequence[str], str, str]] =3D None + self._start_if: Optional[Tuple[QAPISchemaIfCond, str, str]] =3D No= ne =20 - def start_if(self, ifcond: Sequence[str]) -> None: + def start_if(self, ifcond: QAPISchemaIfCond) -> None: assert self._start_if is None self._start_if =3D (ifcond, self._body, self._preamble) =20 @@ -187,7 +187,7 @@ def _bottom(self) -> str: =20 =20 @contextmanager -def ifcontext(ifcond: Sequence[str], *args: QAPIGenCCode) -> Iterator[None= ]: +def ifcontext(ifcond: QAPISchemaIfCond, *args: QAPIGenCCode) -> Iterator[N= one]: """ 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 9a348ca2e5..77a8c33ad4 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -15,11 +15,9 @@ Any, Dict, Generic, - Iterable, List, Optional, Sequence, - Tuple, TypeVar, Union, ) @@ -38,6 +36,7 @@ QAPISchemaEntity, QAPISchemaEnumMember, QAPISchemaFeature, + QAPISchemaIfCond, QAPISchemaObjectType, QAPISchemaObjectTypeMember, QAPISchemaType, @@ -91,11 +90,11 @@ class Annotated(Generic[_ValueT]): """ # TODO: Remove after Python 3.7 adds @dataclass: # pylint: disable=3Dtoo-few-public-methods - def __init__(self, value: _ValueT, ifcond: Iterable[str], + def __init__(self, value: _ValueT, ifcond: QAPISchemaIfCond, comment: Optional[str] =3D None): self.value =3D value self.comment: Optional[str] =3D comment - self.ifcond: Tuple[str, ...] =3D tuple(ifcond) + self.ifcond =3D ifcond =20 =20 def _tree_to_qlit(obj: JSONValue, @@ -125,10 +124,10 @@ def indent(level: int) -> str: if obj.comment: ret +=3D indent(level) + f"/* {obj.comment} */\n" if obj.ifcond: - ret +=3D gen_if(obj.ifcond) + ret +=3D gen_if(obj.ifcond.ifcond) ret +=3D _tree_to_qlit(obj.value, level) if obj.ifcond: - ret +=3D '\n' + gen_endif(obj.ifcond) + ret +=3D '\n' + gen_endif(obj.ifcond.ifcond) return ret =20 ret =3D '' @@ -254,7 +253,7 @@ def _gen_features(features: Sequence[QAPISchemaFeature] return [Annotated(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object], - ifcond: Sequence[str] =3D (), + ifcond: QAPISchemaIfCond =3D QAPISchemaIfCond(), features: Sequence[QAPISchemaFeature] =3D ()) -> None: """ Build and append a SchemaInfo object to self._trees. @@ -305,7 +304,7 @@ def visit_builtin_type(self, name: str, info: Optional[= QAPISourceInfo], self._gen_tree(name, 'builtin', {'json-type': json_type}) =20 def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: @@ -316,14 +315,14 @@ def visit_enum_type(self, name: str, info: Optional[Q= APISourceInfo], ) =20 def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, element_type: QAPISchemaType) -> None: element =3D self._use_type(element_type) self._gen_tree('[' + element + ']', 'array', {'element-type': elem= ent}, ifcond) =20 def visit_object_type_flat(self, name: str, info: Optional[QAPISourceI= nfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], members: List[QAPISchemaObjectTypeMember], variants: Optional[QAPISchemaVariants]) -> = None: @@ -336,7 +335,7 @@ def visit_object_type_flat(self, name: str, info: Optio= nal[QAPISourceInfo], self._gen_tree(name, 'object', obj, ifcond, features) =20 def visit_alternate_type(self, name: str, info: Optional[QAPISourceInf= o], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: self._gen_tree( @@ -348,7 +347,7 @@ def visit_alternate_type(self, name: str, info: Optiona= l[QAPISourceInfo], ) =20 def visit_command(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], ret_type: Optional[QAPISchemaType], gen: bool, @@ -367,7 +366,8 @@ def visit_command(self, name: str, info: Optional[QAPIS= ourceInfo], self._gen_tree(name, 'command', obj, ifcond, features) =20 def visit_event(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], features: List[QAPISchemaFeatur= e], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], boxed: bool) -> None: assert self._schema is not None diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 3a4172fb74..7d6f390fa6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -25,6 +25,22 @@ from .parser import QAPISchemaParser =20 =20 +class QAPISchemaIfCond: + def __init__(self, ifcond=3DNone): + self.ifcond =3D ifcond or [] + + def __bool__(self): + return bool(self.ifcond) + + def __repr__(self): + return repr(self.ifcond) + + def __eq__(self, other): + if not isinstance(other, QAPISchemaIfCond): + return NotImplemented + return self.ifcond =3D=3D other.ifcond + + class QAPISchemaEntity: meta: Optional[str] =3D None =20 @@ -42,7 +58,7 @@ def __init__(self, name: str, info, doc, ifcond=3DNone, f= eatures=3DNone): # such place). self.info =3D info self.doc =3D doc - self._ifcond =3D ifcond or [] + self._ifcond =3D ifcond or QAPISchemaIfCond() self.features =3D features or [] self._checked =3D False =20 @@ -77,7 +93,7 @@ def set_module(self, schema): =20 @property def ifcond(self): - assert self._checked + assert self._checked and isinstance(self._ifcond, QAPISchemaIfCond) return self._ifcond =20 def is_implicit(self): @@ -601,7 +617,7 @@ def check(self, schema, seen): 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} @@ -646,7 +662,7 @@ def __init__(self, name, info, ifcond=3DNone): assert isinstance(name, str) self.name =3D name self.info =3D info - self.ifcond =3D ifcond or [] + self.ifcond =3D ifcond or QAPISchemaIfCond() self.defined_in =3D None =20 def set_defined_in(self, name): @@ -958,14 +974,20 @@ def _def_predefineds(self): self._def_entity(QAPISchemaEnumType('QType', None, None, None, Non= e, qtype_values, 'QTYPE')) =20 + def _get_if(self, f) -> QAPISchemaIfCond: + ifcond =3D f.get('if') + if isinstance(ifcond, QAPISchemaIfCond): + return ifcond + return QAPISchemaIfCond(ifcond) + def _make_features(self, features, info): if features is None: return [] - return [QAPISchemaFeature(f['name'], info, f.get('if')) + return [QAPISchemaFeature(f['name'], info, self._get_if(f)) for f in features] =20 def _make_enum_members(self, values, info): - return [QAPISchemaEnumMember(v['name'], info, v.get('if')) + return [QAPISchemaEnumMember(v['name'], info, self._get_if(v)) for v in values] =20 def _make_implicit_enum_type(self, name, info, ifcond, values): @@ -1001,7 +1023,7 @@ def _make_implicit_object_type(self, name, info, ifco= nd, role, members): # 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)) @@ -1011,7 +1033,7 @@ def _def_enum_type(self, expr, info, doc): name =3D expr['enum'] data =3D expr['data'] prefix =3D expr.get('prefix') - ifcond =3D expr.get('if') + ifcond =3D QAPISchemaIfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaEnumType( name, info, doc, ifcond, features, @@ -1029,7 +1051,8 @@ def _make_member(self, name, typ, ifcond, features, i= nfo): self._make_features(features, in= fo)) =20 def _make_members(self, data, info): - return [self._make_member(key, value['type'], value.get('if'), + return [self._make_member(key, value['type'], + QAPISchemaIfCond(value.get('if')), value.get('features'), info) for (key, value) in data.items()] =20 @@ -1037,7 +1060,7 @@ def _def_struct_type(self, expr, info, doc): name =3D expr['struct'] base =3D expr.get('base') data =3D expr['data'] - ifcond =3D expr.get('if') + ifcond =3D QAPISchemaIfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaObjectType( name, info, doc, ifcond, features, base, @@ -1060,7 +1083,7 @@ def _def_union_type(self, expr, info, doc): name =3D expr['union'] data =3D expr['data'] base =3D expr.get('base') - ifcond =3D expr.get('if') + ifcond =3D QAPISchemaIfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) tag_name =3D expr.get('discriminator') tag_member =3D None @@ -1069,14 +1092,20 @@ def _def_union_type(self, expr, info, doc): name, info, ifcond, 'base', self._make_members(base, info)) if tag_name: - variants =3D [self._make_variant(key, value['type'], - value.get('if'), info) - for (key, value) in data.items()] + variants =3D [ + self._make_variant(key, value['type'], + QAPISchemaIfCond(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) - for (key, value) in data.items()] + variants =3D [ + self._make_simple_variant(key, value['type'], + QAPISchemaIfCond(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) tag_member =3D QAPISchemaObjectTypeMember('type', info, typ, F= alse) @@ -1090,11 +1119,14 @@ def _def_union_type(self, expr, info, doc): def _def_alternate_type(self, expr, info, doc): name =3D expr['alternate'] data =3D expr['data'] - ifcond =3D expr.get('if') + ifcond =3D QAPISchemaIfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) - variants =3D [self._make_variant(key, value['type'], value.get('if= '), - info) - for (key, value) in data.items()] + variants =3D [ + self._make_variant(key, value['type'], + QAPISchemaIfCond(value.get('if')), + info) + for (key, value) in data.items() + ] tag_member =3D QAPISchemaObjectTypeMember('type', info, 'QType', F= alse) self._def_entity( QAPISchemaAlternateType(name, info, doc, ifcond, features, @@ -1111,7 +1143,7 @@ def _def_command(self, expr, info, doc): 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 QAPISchemaIfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( @@ -1130,7 +1162,7 @@ def _def_event(self, expr, info, doc): name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) - ifcond =3D expr.get('if') + ifcond =3D QAPISchemaIfCond(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 20d572a23a..3673cf0f49 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -13,7 +13,7 @@ # See the COPYING file in the top-level directory. """ =20 -from typing import List, Optional, Sequence +from typing import List, Optional =20 from .common import ( c_enum_const, @@ -27,6 +27,7 @@ QAPISchema, QAPISchemaEnumMember, QAPISchemaFeature, + QAPISchemaIfCond, QAPISchemaObjectType, QAPISchemaObjectTypeMember, QAPISchemaType, @@ -50,13 +51,13 @@ def gen_enum_lookup(name: str, ''', c_name=3Dc_name(name)) for memb in members: - ret +=3D gen_if(memb.ifcond) + ret +=3D gen_if(memb.ifcond.ifcond) 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 gen_endif(memb.ifcond.ifcond) =20 ret +=3D mcgen(''' }, @@ -80,12 +81,12 @@ def gen_enum(name: str, c_name=3Dc_name(name)) =20 for memb in enum_members: - ret +=3D gen_if(memb.ifcond) + ret +=3D gen_if(memb.ifcond.ifcond) ret +=3D mcgen(''' %(c_enum)s, ''', c_enum=3Dc_enum_const(name, memb.name, prefix)) - ret +=3D gen_endif(memb.ifcond) + ret +=3D gen_endif(memb.ifcond.ifcond) =20 ret +=3D mcgen(''' } %(c_name)s; @@ -125,7 +126,7 @@ def gen_array(name: str, element_type: QAPISchemaType) = -> str: def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str: ret =3D '' for memb in members: - ret +=3D gen_if(memb.ifcond) + ret +=3D gen_if(memb.ifcond.ifcond) if memb.optional: ret +=3D mcgen(''' bool has_%(c_name)s; @@ -135,11 +136,11 @@ def gen_struct_members(members: List[QAPISchemaObject= TypeMember]) -> 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 gen_endif(memb.ifcond.ifcond) return ret =20 =20 -def gen_object(name: str, ifcond: Sequence[str], +def gen_object(name: str, ifcond: QAPISchemaIfCond, base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], variants: Optional[QAPISchemaVariants]) -> str: @@ -158,7 +159,7 @@ def gen_object(name: str, ifcond: Sequence[str], ret +=3D mcgen(''' =20 ''') - ret +=3D gen_if(ifcond) + ret +=3D gen_if(ifcond.ifcond) ret +=3D mcgen(''' struct %(c_name)s { ''', @@ -192,7 +193,7 @@ def gen_object(name: str, ifcond: Sequence[str], ret +=3D mcgen(''' }; ''') - ret +=3D gen_endif(ifcond) + ret +=3D gen_endif(ifcond.ifcond) =20 return ret =20 @@ -219,13 +220,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 gen_if(var.ifcond.ifcond) 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 gen_endif(var.ifcond.ifcond) =20 ret +=3D mcgen(''' } u; @@ -307,7 +308,7 @@ def _gen_type_cleanup(self, name: str) -> None: def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: @@ -318,7 +319,7 @@ def visit_enum_type(self, def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, 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 @@ def visit_array_type(self, def visit_object_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], @@ -351,7 +352,7 @@ def visit_object_type(self, def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh): diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 9e96f3c566..67721b2470 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -13,7 +13,7 @@ See the COPYING file in the top-level directory. """ =20 -from typing import List, Optional, Sequence +from typing import List, Optional =20 from .common import ( c_enum_const, @@ -29,6 +29,7 @@ QAPISchemaEnumMember, QAPISchemaEnumType, QAPISchemaFeature, + QAPISchemaIfCond, QAPISchemaObjectType, QAPISchemaObjectTypeMember, QAPISchemaType, @@ -78,7 +79,7 @@ def gen_visit_object_members(name: str, =20 for memb in members: deprecated =3D 'deprecated' in [f.name for f in memb.features] - ret +=3D gen_if(memb.ifcond) + ret +=3D gen_if(memb.ifcond.ifcond) if memb.optional: ret +=3D mcgen(''' if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) { @@ -111,7 +112,7 @@ def gen_visit_object_members(name: str, ret +=3D mcgen(''' } ''') - ret +=3D gen_endif(memb.ifcond) + ret +=3D gen_endif(memb.ifcond.ifcond) =20 if variants: tag_member =3D variants.tag_member @@ -125,7 +126,7 @@ def gen_visit_object_members(name: str, for var in variants.variants: case_str =3D c_enum_const(tag_member.type.name, var.name, tag_member.type.prefix) - ret +=3D gen_if(var.ifcond) + ret +=3D gen_if(var.ifcond.ifcond) if var.type.name =3D=3D 'q_empty': # valid variant and nothing to do ret +=3D mcgen(''' @@ -141,7 +142,7 @@ def gen_visit_object_members(name: str, case=3Dcase_str, c_type=3Dvar.type.c_name(), c_name=3Dc_name(v= ar.name)) =20 - ret +=3D gen_endif(var.ifcond) + ret +=3D gen_endif(var.ifcond.ifcond) ret +=3D mcgen(''' default: abort(); @@ -227,7 +228,7 @@ def gen_visit_alternate(name: str, variants: QAPISchema= Variants) -> str: c_name=3Dc_name(name)) =20 for var in variants.variants: - ret +=3D gen_if(var.ifcond) + ret +=3D gen_if(var.ifcond.ifcond) ret +=3D mcgen(''' case %(case)s: ''', @@ -253,7 +254,7 @@ def gen_visit_alternate(name: str, variants: QAPISchema= Variants) -> str: ret +=3D mcgen(''' break; ''') - ret +=3D gen_endif(var.ifcond) + ret +=3D gen_endif(var.ifcond.ifcond) =20 ret +=3D mcgen(''' case QTYPE_NONE: @@ -352,7 +353,7 @@ def _begin_user_module(self, name: str) -> None: def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: @@ -363,7 +364,7 @@ def visit_enum_type(self, def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, element_type: QAPISchemaType) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) @@ -372,7 +373,7 @@ def visit_array_type(self, def visit_object_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], @@ -394,7 +395,7 @@ def visit_object_type(self, def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: Sequence[str], + ifcond: QAPISchemaIfCond, features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh, self._genc): --=20 2.29.0 From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619703837; cv=none; d=zohomail.com; s=zohoarc; b=Sk/mZOOqDOxRqHRCGhERSPcZ6Jdb5Nawe8monitu/bTlo4HIfgr2rZYQnHB3Qx0/OT5xW+yWQIHAj7bk4nDCbkKL1eIPcDB1XFNjkeKMCdLsWVN0XIfUr9iSR4spsT/8d49aIBZImfyf2L55l4M4pFR8B+0uINZlovvoz/LMKNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619703837; 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=EzOYjLLS7ZXruBmt1bkaO9lVP9s7RVR/toaIlc+d34g=; b=oAubweDrEdzOH8yFG14y4a0tNLfs4RRF/o+ufmcac+z6cyD+5Tv4X7FIQgJOjZSUy4TMUjORxOEa/drFqjkI6sXKZMrZKhRHYLjhXHMLDdk0cxU2MxHs/UVaR/rUS/NbaGam0YO7coE695nakjqcYllxDwvQMLgEdw0EzS2SRpA= 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 1619703837371192.4043094045652; Thu, 29 Apr 2021 06:43:57 -0700 (PDT) Received: from localhost ([::1]:50368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc6xQ-0006kB-7J for importer@patchew.org; Thu, 29 Apr 2021 09:43:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6ui-00054h-RC for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50915) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6ua-0002R2-Dq for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:08 -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-339-je2TvHNJMh2GEa8tUpXMXA-1; Thu, 29 Apr 2021 09:40:57 -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 41B3F107ACFA for ; Thu, 29 Apr 2021 13:40:56 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02C81100AE4E; Thu, 29 Apr 2021 13:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703659; 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=EzOYjLLS7ZXruBmt1bkaO9lVP9s7RVR/toaIlc+d34g=; b=MilrkwNQtaQEWkCGdDRMaJvUfbsqWO/3pSqbHliFRzpSea8zylZYmD8+Sp2vrwqJiJ1FMq 2CDp+31B0Qui/12chfDArBIl/BrTFt3FGFEJ6yNPCpr2QOiZa0799duUyJ9QoKwF1Vq9wK ViKd6fddIKPnZ+4Iz1tOwJc8P2/npIw= X-MC-Unique: je2TvHNJMh2GEa8tUpXMXA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 2/9] qapi: move gen_if/gen_endif to QAPISchemaIfCond Date: Thu, 29 Apr 2021 17:40:25 +0400 Message-Id: <20210429134032.1125111-3-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-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=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 QAPISchemaIfCond class. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- scripts/qapi/common.py | 20 +------------------- scripts/qapi/gen.py | 6 ++---- scripts/qapi/introspect.py | 11 +++-------- scripts/qapi/schema.py | 18 +++++++++++++++++- scripts/qapi/types.py | 28 +++++++++++----------------- scripts/qapi/visit.py | 14 ++++++-------- 6 files changed, 40 insertions(+), 57 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index cbd3fd81d3..b7f475a160 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 =20 =20 #: Magic string that gets removed along with all space to its right. @@ -192,21 +192,3 @@ def guardend(name: str) -> str: #endif /* %(name)s */ ''', name=3Dc_fname(name).upper()) - - -def gen_if(ifcond: Sequence[str]) -> str: - ret =3D '' - for ifc in ifcond: - ret +=3D mcgen(''' -#if %(cond)s -''', cond=3Difc) - return ret - - -def gen_endif(ifcond: Sequence[str]) -> str: - ret =3D '' - for ifc in reversed(ifcond): - ret +=3D mcgen(''' -#endif /* %(cond)s */ -''', cond=3Difc) - return ret diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 1c5b190276..ab26d5c937 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -24,8 +24,6 @@ from .common import ( c_fname, c_name, - gen_endif, - gen_if, guardend, guardstart, mcgen, @@ -95,9 +93,9 @@ def _wrap_ifcond(ifcond: QAPISchemaIfCond, before: str, a= fter: str) -> str: if added[0] =3D=3D '\n': out +=3D '\n' added =3D added[1:] - out +=3D gen_if(ifcond.ifcond) + out +=3D ifcond.gen_if() out +=3D added - out +=3D gen_endif(ifcond.ifcond) + out +=3D ifcond.gen_endif() return out =20 =20 diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 77a8c33ad4..a2a8a57b9a 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -22,12 +22,7 @@ Union, ) =20 -from .common import ( - c_name, - gen_endif, - gen_if, - mcgen, -) +from .common import c_name, mcgen from .gen import QAPISchemaMonolithicCVisitor from .schema import ( QAPISchema, @@ -124,10 +119,10 @@ def indent(level: int) -> str: if obj.comment: ret +=3D indent(level) + f"/* {obj.comment} */\n" if obj.ifcond: - ret +=3D gen_if(obj.ifcond.ifcond) + ret +=3D obj.ifcond.gen_if() ret +=3D _tree_to_qlit(obj.value, level) if obj.ifcond: - ret +=3D '\n' + gen_endif(obj.ifcond.ifcond) + ret +=3D '\n' + obj.ifcond.gen_endif() return ret =20 ret =3D '' diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 7d6f390fa6..8e6d0a5296 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -19,7 +19,7 @@ import re from typing import Optional =20 -from .common import POINTER_SUFFIX, c_name +from .common import POINTER_SUFFIX, c_name, mcgen from .error import QAPISemError, QAPISourceError from .expr import check_exprs from .parser import QAPISchemaParser @@ -29,6 +29,22 @@ class QAPISchemaIfCond: def __init__(self, ifcond=3DNone): self.ifcond =3D ifcond or [] =20 + def gen_if(self): + ret =3D '' + for ifc in self.ifcond: + ret +=3D mcgen(''' +#if %(cond)s +''', cond=3Difc) + return ret + + def gen_endif(self): + ret =3D '' + for ifc in reversed(self.ifcond): + ret +=3D mcgen(''' +#endif /* %(cond)s */ +''', cond=3Difc) + return ret + def __bool__(self): return bool(self.ifcond) =20 diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 3673cf0f49..831294fe42 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -15,13 +15,7 @@ =20 from typing import List, Optional =20 -from .common import ( - c_enum_const, - c_name, - gen_endif, - gen_if, - mcgen, -) +from .common import c_enum_const, c_name, mcgen from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import ( QAPISchema, @@ -51,13 +45,13 @@ def gen_enum_lookup(name: str, ''', c_name=3Dc_name(name)) for memb in members: - ret +=3D gen_if(memb.ifcond.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.ifcond) + ret +=3D memb.ifcond.gen_endif() =20 ret +=3D mcgen(''' }, @@ -81,12 +75,12 @@ def gen_enum(name: str, c_name=3Dc_name(name)) =20 for memb in enum_members: - ret +=3D gen_if(memb.ifcond.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.ifcond) + ret +=3D memb.ifcond.gen_endif() =20 ret +=3D mcgen(''' } %(c_name)s; @@ -126,7 +120,7 @@ def gen_array(name: str, element_type: QAPISchemaType) = -> str: def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str: ret =3D '' for memb in members: - ret +=3D gen_if(memb.ifcond.ifcond) + ret +=3D memb.ifcond.gen_if() if memb.optional: ret +=3D mcgen(''' bool has_%(c_name)s; @@ -136,7 +130,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.ifcond) + ret +=3D memb.ifcond.gen_endif() return ret =20 =20 @@ -159,7 +153,7 @@ def gen_object(name: str, ifcond: QAPISchemaIfCond, ret +=3D mcgen(''' =20 ''') - ret +=3D gen_if(ifcond.ifcond) + ret +=3D ifcond.gen_if() ret +=3D mcgen(''' struct %(c_name)s { ''', @@ -193,7 +187,7 @@ def gen_object(name: str, ifcond: QAPISchemaIfCond, ret +=3D mcgen(''' }; ''') - ret +=3D gen_endif(ifcond.ifcond) + ret +=3D ifcond.gen_endif() =20 return ret =20 @@ -220,13 +214,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.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.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 67721b2470..9d9196a143 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -18,8 +18,6 @@ from .common import ( c_enum_const, c_name, - gen_endif, - gen_if, indent, mcgen, ) @@ -79,7 +77,7 @@ def gen_visit_object_members(name: str, =20 for memb in members: deprecated =3D 'deprecated' in [f.name for f in memb.features] - ret +=3D gen_if(memb.ifcond.ifcond) + ret +=3D memb.ifcond.gen_if() if memb.optional: ret +=3D mcgen(''' if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) { @@ -112,7 +110,7 @@ def gen_visit_object_members(name: str, ret +=3D mcgen(''' } ''') - ret +=3D gen_endif(memb.ifcond.ifcond) + ret +=3D memb.ifcond.gen_endif() =20 if variants: tag_member =3D variants.tag_member @@ -126,7 +124,7 @@ def gen_visit_object_members(name: str, for var in variants.variants: case_str =3D c_enum_const(tag_member.type.name, var.name, tag_member.type.prefix) - ret +=3D gen_if(var.ifcond.ifcond) + ret +=3D var.ifcond.gen_if() if var.type.name =3D=3D 'q_empty': # valid variant and nothing to do ret +=3D mcgen(''' @@ -142,7 +140,7 @@ def gen_visit_object_members(name: str, case=3Dcase_str, c_type=3Dvar.type.c_name(), c_name=3Dc_name(v= ar.name)) =20 - ret +=3D gen_endif(var.ifcond.ifcond) + ret +=3D var.ifcond.gen_endif() ret +=3D mcgen(''' default: abort(); @@ -228,7 +226,7 @@ def gen_visit_alternate(name: str, variants: QAPISchema= Variants) -> str: c_name=3Dc_name(name)) =20 for var in variants.variants: - ret +=3D gen_if(var.ifcond.ifcond) + ret +=3D var.ifcond.gen_if() ret +=3D mcgen(''' case %(case)s: ''', @@ -254,7 +252,7 @@ def gen_visit_alternate(name: str, variants: QAPISchema= Variants) -> str: ret +=3D mcgen(''' break; ''') - ret +=3D gen_endif(var.ifcond.ifcond) + ret +=3D var.ifcond.gen_endif() =20 ret +=3D mcgen(''' case QTYPE_NONE: --=20 2.29.0 From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619703966; cv=none; d=zohomail.com; s=zohoarc; b=IweUg08v0JxiI/6tcjerud3ocsc6NnQKC+kiX4l/62FKh1+ygt8Up6aBvH5KSmQhaMj/vFz3ctxKMZtefgmYN0UUBnj1GY3F7r2Ig83N8zePsA/tLHSPw6j18dsZJ2R8IQhPl9gqrQM6a0ne6Mzc6MUDDKhd5cycVrOopAMLICc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619703966; 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=NIXK4EiT4FLgQJRcYl5hLwfRcRPBcJNMMBZTCVoTToQ=; b=A6UUE2te8H0yOHEib5G8ep0nFHQrQPiZAezCsQwEqSC1BNXY46sgQS/OaK5nZTCaGcRqA6jxG2o3swMtIYJqM+5aLGb12/xkAjZvA8xT+fRkzNXBL/+kUIk1pYwFdotaueH5nenhHp3POJK9VIPspZoxbUR51CUokvoiZHvowOQ= 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 1619703966794496.09732060825695; Thu, 29 Apr 2021 06:46:06 -0700 (PDT) Received: from localhost ([::1]:58868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc6zU-0001ik-Uy for importer@patchew.org; Thu, 29 Apr 2021 09:46:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6uo-00058L-2z for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35997) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6uk-0002Tj-H8 for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:13 -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-199-IFYTZ_OnOKqtPtq-UadTBQ-1; Thu, 29 Apr 2021 09:41:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 934108014C1 for ; Thu, 29 Apr 2021 13:41:06 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8057119EF1; Thu, 29 Apr 2021 13:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703669; 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=NIXK4EiT4FLgQJRcYl5hLwfRcRPBcJNMMBZTCVoTToQ=; b=Xbzt/H/hXKdFda+hFdsSucL0Qva5rIBQk0vki1TemHlZirGZYGHHoTIOEp+tUBrdC6z/DB W4tD/M8xORP40Uzhu7qvsqUbsqcoXwRqr6lryyv2XJEzw8mup5WDJW6PSh/lIu+f0lpO1M BnG0Iy4CeXYd4bYDW2cPnH9ptpwauq8= X-MC-Unique: IFYTZ_OnOKqtPtq-UadTBQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 3/9] qapi: start building an 'if' predicate tree Date: Thu, 29 Apr 2021 17:40:26 +0400 Message-Id: <20210429134032.1125111-4-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 schema 'if' conditions in a target language agnostic way. For that, let's start building a predicate tree of the configuration options. This intermediary steps still uses C-preprocessor expressions as the predicates: "if: [STR, ..]" is translated to a "IfCond -> IfAll -> [IfOption, ..]" tree, which will generate "#if STR && .." C code. Once the boolean operation tree nodes are introduced, the 'if' expressions will be converted to replace the C syntax (no more !defined(), &&, ...) and based only on option identifiers. For now, the condition tree will be less expressive than a full C macro expression as it will only support these operations: 'all', 'any' and 'not', the only ones needed so far. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- docs/sphinx/qapidoc.py | 6 +-- scripts/qapi/common.py | 54 +++++++++++++++++++++++- scripts/qapi/schema.py | 42 ++++++++++++------- tests/qapi-schema/doc-good.out | 12 +++--- tests/qapi-schema/qapi-schema-test.out | 58 +++++++++++++------------- 5 files changed, 116 insertions(+), 56 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index b737949007..a93f3f1c4d 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -112,12 +112,10 @@ def _make_section(self, title): 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: 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_doc())] if not with_if: return condlist =20 diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index b7f475a160..59a7ee2f32 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -11,8 +11,9 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 +from abc import ABC, abstractmethod import re -from typing import Optional +from typing import Optional, Sequence =20 =20 #: Magic string that gets removed along with all space to its right. @@ -192,3 +193,54 @@ def guardend(name: str) -> str: #endif /* %(name)s */ ''', name=3Dc_fname(name).upper()) + + +class IfPredicate(ABC): + @abstractmethod + def cgen(self) -> str: + pass + + @abstractmethod + def docgen(self) -> str: + pass + + +class IfOption(IfPredicate): + def __init__(self, option: str): + self.option =3D option + + def cgen(self) -> str: + return self.option + + def docgen(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 docgen(self) -> str: + return " and ".join([p.docgen() 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 diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 8e6d0a5296..366a53ab64 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -19,7 +19,13 @@ import re from typing import Optional =20 -from .common import POINTER_SUFFIX, c_name, mcgen +from .common import ( + POINTER_SUFFIX, + IfAll, + IfOption, + c_name, + mcgen, +) from .error import QAPISemError, QAPISourceError from .expr import check_exprs from .parser import QAPISchemaParser @@ -27,34 +33,38 @@ =20 class QAPISchemaIfCond: def __init__(self, ifcond=3DNone): - self.ifcond =3D ifcond or [] + pred_list =3D [IfOption(opt) for opt in ifcond or []] + self.pred =3D IfAll(pred_list) + + def gen_doc(self): + if self.pred: + return self.pred.docgen() + return "" =20 def gen_if(self): - 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): - 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 "" =20 def __bool__(self): - return bool(self.ifcond) + return bool(self.pred) =20 def __repr__(self): - return repr(self.ifcond) + return repr(self.pred) =20 def __eq__(self, other): if not isinstance(other, QAPISchemaIfCond): return NotImplemented - return self.ifcond =3D=3D other.ifcond + return self.pred =3D=3D other.pred =20 =20 class QAPISchemaEntity: diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 8f54ceff2e..6bf996f539 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 e0b8a5f0b6..c2d303aa18 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 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 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_test-if-union-cmd-arg member union-cmd-arg: TestIfUnion optional=3DFalse - if ['defined(TEST_IF_UNION)'] + if IfAll(['defined(TEST_IF_UNION)']) command test-if-union-cmd q_obj_test-if-union-cmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if ['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_test-if-alternate-cmd-arg member alt-cmd-arg: TestIfAlternate optional=3DFalse - if ['defined(TEST_IF_ALT)'] + if IfAll(['defined(TEST_IF_ALT)']) command test-if-alternate-cmd q_obj_test-if-alternate-cmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if ['defined(TEST_IF_ALT)'] + if IfAll(['defined(TEST_IF_ALT)']) object q_obj_test-if-cmd-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 test-if-cmd q_obj_test-if-cmd-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 test-cmd-return-def-three 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_TEST_IF_EVENT-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 TEST_IF_EVENT q_obj_TEST_IF_EVENT-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_FEATURES0 FeatureStruct1 boxed=3DFalse event TEST_EVENT_FEATURES1 None --=20 2.29.0 From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619703842; cv=none; d=zohomail.com; s=zohoarc; b=Zq6KkV3QW6rZ7VkXpiLH7VA4DonNCP9ncFCismOqVGYqkT24oBXhQKgQxzYSLrs8E8UGPTG79MtvpjmWyFrK+gdFIum2Gf7KuO0tcmWI3xEJeirgGxznfMN90XU/QtMwjV/WOGKqQ5g+hSB/8HayJCWjowm0/AZVBWhBvV5CwtQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619703842; 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=EqsUVszJoWDAzbTByKZLXqJyoxdRjmLsXocgE4TVN2E=; b=cQvvKyneWZvsijI6xlf0OSoezNk1uU7UsiCcnhfWfPY7IocS3ZP/ut4dyosUBzPiAPz2Va2V4krvon1RBxor83IqrZI2+gn2ybT9IHlbhKLfaWpGpeFXWNIikzHZIpOdQcjPi6JzVG5qBP/gbcHFQJBatIQe9wHoyq9YhGVTkxQ= 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 1619703842847202.97091106534697; Thu, 29 Apr 2021 06:44:02 -0700 (PDT) Received: from localhost ([::1]:50970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc6xV-0006yr-Pc for importer@patchew.org; Thu, 29 Apr 2021 09:44:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6ux-0005FB-JE for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6uu-0002YU-KU for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41: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-489-9FO-egn4NqO_5mPlG8TKIw-1; Thu, 29 Apr 2021 09:41:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F275C8BEB82 for ; Thu, 29 Apr 2021 13:41:14 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA6DC5D9C6; Thu, 29 Apr 2021 13:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703678; 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=EqsUVszJoWDAzbTByKZLXqJyoxdRjmLsXocgE4TVN2E=; b=QpeWAq00G6XYdM03F4G+FXetDTQhanEo0K9XSKTCeTb9Q8n0VdW1o+LfMBZFMQiU6nZ6HN yuJNvSYSxjDZcd/r+8il54IAwwJEAcrR6C3EQDcRbAdnp2GY77xH4GRbPOVyMuOWcj+Lmo GUx+ERB1+5oMmQQZNY1Z98Ub4P2K4CQ= X-MC-Unique: 9FO-egn4NqO_5mPlG8TKIw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 4/9] qapi: introduce IfPredicateList and IfAny Date: Thu, 29 Apr 2021 17:40:27 +0400 Message-Id: <20210429134032.1125111-5-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 Refactor IfAll class, to introduce a base class IfPredicateList and add IfAny for the 'any' conditions. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- scripts/qapi/common.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 59a7ee2f32..102d347348 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -224,23 +224,45 @@ def __eq__(self, other: object) -> bool: return self.option =3D=3D other.option =20 =20 -class IfAll(IfPredicate): +class IfPredicateList(IfPredicate): + C_SEP =3D "" + DOC_SEP =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]) + sep =3D " " + self.C_SEP + " " + gen =3D sep.join([p.cgen() for p in self.pred_list]) + if len(self.pred_list) =3D=3D 1: + return gen + return "(%s)" % gen =20 def docgen(self) -> str: - return " and ".join([p.docgen() for p in self.pred_list]) + sep =3D " " + self.DOC_SEP + " " + gen =3D sep.join([p.docgen() for p in self.pred_list]) + if len(self.pred_list) =3D=3D 1: + return gen + return "(%s)" % gen =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 + + +class IfAll(IfPredicateList): + C_SEP =3D "&&" + DOC_SEP =3D "and" + + +class IfAny(IfPredicateList): + C_SEP =3D "||" + DOC_SEP =3D "or" --=20 2.29.0 From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619704109; cv=none; d=zohomail.com; s=zohoarc; b=VfO83DM32xOCuF8YUhWAXoRYKc1JUu2E3ImqufBNaN9aU7m3iwZcTLLVWunKhLB6FJtN8DetklgtxczuZxqdU3AupKPpT1fa+6KP1aa9TP0xRpEsWMl+oDW/Rg4/BNIKsm6zklW/Cqglkj5hutCc5bCpXbuZCG/mY+bjO8WI2sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619704109; 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=We1zZDJqXr65g8j+1L71psk2lqix3XVZIyeTb7L2dhQ=; b=D/nVVQo4vY2RlcLcaQPnYl9ERTnmfiC/r7CavAgI2/ypNTYc8Wfi6TYaCRFOFdO6FbOZ7+9buwkNeJMpdxSOhCKTplScPQEpLaEbxFVaaawPtcmZxcJH0W3hZhi56odfShMrMpubw5WiZLa4v1ethLvSJ3ddpU8iKVppNpqQPIA= 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 1619704109477439.20015461837966; Thu, 29 Apr 2021 06:48:29 -0700 (PDT) Received: from localhost ([::1]:37948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc71o-0004lp-Bo for importer@patchew.org; Thu, 29 Apr 2021 09:48:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6v3-0005QM-LJ for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54831) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6v1-0002eo-U3 for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-isX_bXiVPMaAlmz_MMwvvA-1; Thu, 29 Apr 2021 09:41:25 -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 92533CC64C for ; Thu, 29 Apr 2021 13:41:24 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 717AC19C44; Thu, 29 Apr 2021 13:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703687; 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=We1zZDJqXr65g8j+1L71psk2lqix3XVZIyeTb7L2dhQ=; b=ehBqCIx+V9aLAQaggJVq0evq4hTMFZzZPWDbUl/VuJdzdIVyIQjMagfqv1ATk9uK83osQr aaSNcc0UmDmAPQXaI9Ix+nLJ7zh4cRQSFBURRbaUwC84z5sjRuiQGgirc2as7ipR33DKee JqaZUL1ftlY/4gSiA/DjQ1OgEd9U4p8= X-MC-Unique: isX_bXiVPMaAlmz_MMwvvA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 5/9] qapi: add IfNot Date: Thu, 29 Apr 2021 17:40:28 +0400 Message-Id: <20210429134032.1125111-6-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-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-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 Introduce IfNot predicate class, for 'not' condition expressions. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- scripts/qapi/common.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 102d347348..6236bfc457 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -224,6 +224,28 @@ def __eq__(self, other: object) -> bool: return self.option =3D=3D other.option =20 =20 +class IfNot(IfPredicate): + def __init__(self, pred: IfPredicate): + self.pred =3D pred + + def docgen(self) -> str: + return "not " + self.pred.docgen() + + 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 IfPredicateList(IfPredicate): C_SEP =3D "" DOC_SEP =3D "" --=20 2.29.0 From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619704192; cv=none; d=zohomail.com; s=zohoarc; b=E4H69Vvv1QtYznZCEDgMT6Fp/e4iphmWiwvs0OCSkFX3bYViFKSY10pFG/kvLM5n4hRv9VDLQDSKG/X6zpg9b7KSzmjJ0AqlGNrOW36uXRVosElSC4eiPNnUD23qvj1XaInq17o2Az7WWJcLeQGvqudo/UItp/vKmB3rQ8MhI70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619704192; 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=4cYdEUa7bN1Q2AUqT2AahXJL6Mic+ZIwuuATd7CBS68=; b=IQpsd00JpDh+y0mSgJjJ2tZ5saYmlqA21+U9A+fccXaYK80c5T14imP1mo+GbV1mP/N10VNhHABQiULGGcq5JPJ6G2AzhvFn1xeUevwuKZG9MLYEGYzZRNYkhV3nu42UEIqyfGsIFjlStpTjhKLIo+gtrEJGbvYmMETNfTWlJyw= 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 161970419203433.511082851592164; Thu, 29 Apr 2021 06:49:52 -0700 (PDT) Received: from localhost ([::1]:33884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc70T-00036s-0v for importer@patchew.org; Thu, 29 Apr 2021 09:47:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6vQ-0005Yx-4J for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6vG-0002oO-A0 for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:51 -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-254-81j64WxBMHSw9B8TQ35veQ-1; Thu, 29 Apr 2021 09:41:38 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4B76CC62C for ; Thu, 29 Apr 2021 13:41:37 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id C81D763BA7; Thu, 29 Apr 2021 13:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703700; 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=4cYdEUa7bN1Q2AUqT2AahXJL6Mic+ZIwuuATd7CBS68=; b=g0jbgriotfNf2C3gJq4uWZ/Tr6E0vl6ea1xUfNSFnz2aF0S2h8D1p2QFNPEy6Sz0kwfRcc snBGO3MqoayRqQtQcYPf2g3Ax6DlxCFlnOt3JQQlmpAaKiD0FGcoeUHv4Fqq2J4SNf18/1 1C2GebT3MMzUIvZrUXJOHWhFiHUtepk= X-MC-Unique: 81j64WxBMHSw9B8TQ35veQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 6/9] qapi: normalize 'if' condition to IfPredicate tree Date: Thu, 29 Apr 2021 17:40:29 +0400 Message-Id: <20210429134032.1125111-7-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 Modify check_if() to build an IfPredicate tree (the schema documentation is updated in a following patch). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- tests/unit/test-qmp-cmds.c | 1 + scripts/qapi/expr.py | 62 ++++++++++++++----- scripts/qapi/schema.py | 13 +--- 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 | 20 +++--- tests/qapi-schema/qapi-schema-test.out | 59 ++++++++++-------- .../qapi-schema/struct-member-if-invalid.err | 2 +- 10 files changed, 106 insertions(+), 71 deletions(-) diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c index 1b0b7d99df..83efa39720 100644 --- a/tests/unit/test-qmp-cmds.c +++ b/tests/unit/test-qmp-cmds.c @@ -51,6 +51,7 @@ FeatureStruct1 *qmp_test_features0(bool has_fs0, FeatureS= truct0 *fs0, bool has_cfs1, CondFeatureStruct1 *cfs1, bool has_cfs2, CondFeatureStruct2 *cfs2, bool has_cfs3, CondFeatureStruct3 *cfs3, + bool has_cfs4, CondFeatureStruct4 *cfs4, Error **errp) { return g_new0(FeatureStruct1, 1); diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 496f7e0333..0a97a6f020 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -42,7 +42,14 @@ cast, ) =20 -from .common import c_name +from .common import ( + IfAll, + IfAny, + IfNot, + IfOption, + IfPredicate, + c_name, +) from .error import QAPISemError from .parser import QAPIDoc from .source import QAPISourceInfo @@ -261,6 +268,10 @@ def check_if(expr: _JSONObject, info: QAPISourceInfo, = source: str) -> None: """ Normalize and validate the ``if`` member of an object. =20 + 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([str])``. + The ``if`` member may be either a ``str`` or a ``List[str]``. A ``str`` value will be normalized to ``List[str]``. =20 @@ -281,25 +292,44 @@ def check_if(expr: _JSONObject, info: QAPISourceInfo,= source: str) -> None: if ifcond is None: return =20 - if isinstance(ifcond, list): - if not ifcond: - raise QAPISemError( - info, "'if' condition [] of %s is useless" % source) - else: - # Normalize to a list - ifcond =3D expr['if'] =3D [ifcond] - - for elt in ifcond: - if not isinstance(elt, 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" - % source) - if not elt.strip(): + "'if' condition of %s must be a string, " + "a list of strings or a dict" % source) + if len(cond) !=3D 1: raise QAPISemError( info, - "'if' condition '%s' of %s makes no sense" - % (elt, source)) + "'if' condition dict of %s must have one key: " + "'all', 'any' or 'not'" % source) + check_keys(cond, info, "'if' condition", [], + ["all", "any", "not"]) + oper, operands =3D next(iter(cond.items())) + if oper =3D=3D "not": + return IfNot(normalize(operands)) + if not operands: + raise QAPISemError( + info, "'if' condition [] of %s is useless" % source) + if not isinstance(operands, list): + raise QAPISemError( + info, "'%s' condition of %s must be a list" % (oper, sourc= e)) + operands =3D [normalize(o) for o in operands] + return IfAll(operands) if oper =3D=3D "all" else IfAny(operands) + + ifcond =3D expr.get('if') + if ifcond is None: + return + expr['if'] =3D normalize(ifcond) =20 =20 def normalize_members(members: object) -> None: diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 366a53ab64..61664a4c5e 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -19,22 +19,15 @@ import re from typing import Optional =20 -from .common import ( - POINTER_SUFFIX, - IfAll, - IfOption, - c_name, - mcgen, -) +from .common import POINTER_SUFFIX, c_name, mcgen from .error import QAPISemError, QAPISourceError from .expr import check_exprs from .parser import QAPISchemaParser =20 =20 class QAPISchemaIfCond: - def __init__(self, ifcond=3DNone): - pred_list =3D [IfOption(opt) for opt in ifcond or []] - self.pred =3D IfAll(pred_list) + def __init__(self, pred=3DNone): + self.pred =3D pred =20 def gen_doc(self): if self.pred: 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 6bf996f539..ca7e53f3b5 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 84b9d41f15..2d5e480b44 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -231,8 +231,8 @@ =20 { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct', - 'bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} }, - 'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' } + 'union-bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} }, + 'if': ['defined(TEST_IF_UNION)', 'defined(TEST_IF_STRUCT)'] } =20 { 'command': 'test-if-union-cmd', 'data': { 'union-cmd-arg': 'TestIfUnion' }, @@ -241,11 +241,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': 'test-if-alternate-cmd', - 'data': { 'alt-cmd-arg': 'TestIfAlternate' }, - 'if': 'defined(TEST_IF_ALT)' } +{ 'command': 'test-if-alternate-cmd', 'data': { 'alt-cmd-arg': 'TestIfAlte= rnate' }, + 'if': {'all': ['defined(TEST_IF_ALT)', {'not': 'defined(TEST_IF_NOT_ALT)= '}] } } =20 { 'command': 'test-if-cmd', 'data': { @@ -259,7 +258,7 @@ { 'event': 'TEST_IF_EVENT', '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 @@ -290,6 +289,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' ], @@ -313,7 +316,8 @@ '*fs4': 'FeatureStruct4', '*cfs1': 'CondFeatureStruct1', '*cfs2': 'CondFeatureStruct2', - '*cfs3': 'CondFeatureStruct3' }, + '*cfs3': 'CondFeatureStruct3', + '*cfs4': 'CondFeatureStruct4' }, 'returns': 'FeatureStruct1', 'features': [] } =20 diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index c2d303aa18..f859bf648d 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 bar - if IfAll(['defined(TEST_IF_UNION_BAR)']) - if IfAll(['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']) + member union-bar + 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 bar: q_obj_str-wrapper - if IfAll(['defined(TEST_IF_UNION_BAR)']) - if IfAll(['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']) + case union-bar: q_obj_str-wrapper + if 'defined(TEST_IF_UNION_BAR)' + if IfAll(['defined(TEST_IF_UNION)', 'defined(TEST_IF_STRUCT)']) object q_obj_test-if-union-cmd-arg member union-cmd-arg: TestIfUnion optional=3DFalse - if IfAll(['defined(TEST_IF_UNION)']) + if 'defined(TEST_IF_UNION)' command test-if-union-cmd q_obj_test-if-union-cmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if 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_test-if-alternate-cmd-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 test-if-alternate-cmd q_obj_test-if-alternate-cmd-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_test-if-cmd-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 test-if-cmd q_obj_test-if-cmd-arg -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse @@ -348,15 +348,15 @@ command test-if-cmd q_obj_test-if-cmd-arg -> UserDefT= hree command test-cmd-return-def-three 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_TEST_IF_EVENT-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 TEST_IF_EVENT q_obj_TEST_IF_EVENT-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=3DTrue member cfs2: CondFeatureStruct2 optional=3DTrue member cfs3: CondFeatureStruct3 optional=3DTrue + member cfs4: CondFeatureStruct4 optional=3DTrue command test-features0 q_obj_test-features0-arg -> FeatureStruct1 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 --=20 2.29.0 From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619703954; cv=none; d=zohomail.com; s=zohoarc; b=e4pr8kKFC8ClU5pdQbflkMfE2zTJWPBYP45Th+boSQUrUNC/LBnlFjm/a83ysJznN8jfbDvw+GNBiUV64jcGTJKlMJH9cnSNCjzC+OWiRi+rdD4v9zSYIFWg332Uf4k6IBuNf2NGiF4UILBSxvDEBpWuz6V4VGmcvEvqRGadk/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619703954; 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=9GO1/RofcESgTCd5CChnD9KyFoKgnAVQZlUbSt2nCUs=; b=iOuUdyYA3E/XqSntneYvF2utlds+a5IFIbM0j/COsy4Fh0NuZ4OtAqFjT2GLu0x+r490Rm5mittFwI61HoDvAFkaPXV/5n+DxtteL07fb4O7s02Cey4OCWrYansZ7IvUe4J0RP61VjM15bmXYAe40t2fKfUPxkx/Gjpj0BonpDw= 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 1619703954871265.43106665075265; Thu, 29 Apr 2021 06:45:54 -0700 (PDT) Received: from localhost ([::1]:58232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc6zJ-0001Se-4m for importer@patchew.org; Thu, 29 Apr 2021 09:45:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6vQ-0005Z6-6p for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36569) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6vN-0002qP-UG for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:41:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-598-fq5rx_-xOwqYEYg9z80aOA-1; Thu, 29 Apr 2021 09:41:47 -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 7B5578189D4 for ; Thu, 29 Apr 2021 13:41:46 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 000C01017CF5; Thu, 29 Apr 2021 13:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703708; 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=9GO1/RofcESgTCd5CChnD9KyFoKgnAVQZlUbSt2nCUs=; b=KoCcVjgT3wf1Lj+9VSjfkWbEgqpu7Xkj+kOQkY9TWo+vGpRoWLHim/dWvlSc2AAkyqvFN3 jjdb2mI5YMP0jprUhxd7Lpk/sATRvLJD+juNM7eg04SjkGEdlSyDFh2b1zy9hCzJUgL3WN C/GNAkOiSitoP5PrBIvXlTtwi/02fbo= X-MC-Unique: fq5rx_-xOwqYEYg9z80aOA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 7/9] qapi: convert 'if' C-expressions to the new syntax tree Date: Thu, 29 Apr 2021 17:40:30 +0400 Message-Id: <20210429134032.1125111-8-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- 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 e7811654b7..9b56b81bea 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: @@ -316,7 +320,11 @@ 'typename': 'str', '*alias-of' : 'str', 'deprecated' : 'bool' }, - '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: @@ -328,4 +336,8 @@ # Since: 1.2 ## { '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 0c7491cd82..2891df6890 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.29.0 From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619703998; cv=none; d=zohomail.com; s=zohoarc; b=jFGpuBP8mHoW35Zh0GDBr779o+cRQIGxb2vDl7fk720POoQlVhhIp84hROTJiYx9RMXy4pVK5ZKGS8GNbeIs11xSk6jFhpMBh3GdpV53CfJZAMVK+fR3TI6UOTo/vx2LEW/rSqOHKYyzD692j+Pue9Z165jpQIMG8+nSuJIP/bU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619703998; 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=wK5LAVJE2lSL08KWIMnTmLLwjrZq4SLntJO5ytH4hbc=; b=EtgQJ8wBsyebgQgm+fWMYEMQJF6kkBwfoy6z7fMFFTgoo5gnfJ0X9oqIu6oxidpus8tUKe/XTEzbVUce86iE/gFERk6plRnz59Zs8jCiXOkd66rmAsgh5W8cpXCSZkHH0SXoMm/db3soG4IA6oW4oag0z+97JcypDgXj4Igb/9k= 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 1619703998663881.8357768290072; Thu, 29 Apr 2021 06:46:38 -0700 (PDT) Received: from localhost ([::1]:59654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc701-00021c-BC for importer@patchew.org; Thu, 29 Apr 2021 09:46:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6vd-0005sS-28 for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:42:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33309) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6vY-0002ul-JG for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:42:04 -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-395-HzDonAfkN0Gy91XbQCrkUg-1; Thu, 29 Apr 2021 09:41: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 09E468BEB84 for ; Thu, 29 Apr 2021 13:41:57 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 813F07013D; Thu, 29 Apr 2021 13:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703720; 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=wK5LAVJE2lSL08KWIMnTmLLwjrZq4SLntJO5ytH4hbc=; b=NdQlENgj0izopAq2IfYRrhHLhaGeLyV+ZVdEfYFgv4vmUkrl0sEMNB9vrPu4f1GHIbvM8h VNVarTORd/pZmMB/iq1fQJh01meVgvx2lLeAYKCWpIxW7riaSDlfxxdYZBomY8XUPmfXhO COa4nXiBiHRC7F7woDZRfjmxAy8Z76M= X-MC-Unique: HzDonAfkN0Gy91XbQCrkUg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 8/9] qapi: make 'if' condition strings simple identifiers Date: Thu, 29 Apr 2021 17:40:31 +0400 Message-Id: <20210429134032.1125111-9-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-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=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- docs/devel/qapi-code-gen.txt | 8 +-- qapi/block-core.json | 16 ++--- qapi/block-export.json | 6 +- qapi/char.json | 8 +-- qapi/machine-target.json | 40 ++++++------- qapi/migration.json | 10 ++-- qapi/misc-target.json | 48 +++++++-------- qapi/qom.json | 10 ++-- qapi/sockets.json | 4 +- qapi/ui.json | 48 +++++++-------- qga/qapi-schema.json | 8 +-- scripts/qapi/common.py | 2 +- scripts/qapi/expr.py | 4 +- .../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/doc-good.txt | 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 +- 24 files changed, 177 insertions(+), 177 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index c1cb6f987d..edaaf7ec40 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -791,7 +791,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 @@ -810,7 +810,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 @@ -822,7 +822,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. @@ -832,7 +832,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 6d227924d0..82213feb18 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2779,7 +2779,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: @@ -2817,7 +2817,7 @@ 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscs= i', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallel= s', 'preallocate', '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 @@ -2860,10 +2860,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: @@ -3683,7 +3683,7 @@ # Since: 2.9 ## { 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ], - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @BlockdevOptionsReplication: @@ -3702,7 +3702,7 @@ 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', '*top-id': 'str' }, - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @NFSTransport: @@ -4036,7 +4036,7 @@ 'raw': 'BlockdevOptionsRaw', 'rbd': 'BlockdevOptionsRbd', 'replication': { 'type': 'BlockdevOptionsReplication', - 'if': 'defined(CONFIG_REPLICATION)' }, + 'if': 'CONFIG_REPLICATION' }, 'sheepdog': 'BlockdevOptionsSheepdog', 'ssh': 'BlockdevOptionsSsh', 'throttle': 'BlockdevOptionsThrottle', @@ -4338,7 +4338,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/block-export.json b/qapi/block-export.json index e819e70cac..319992b1b0 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -137,7 +137,7 @@ { 'struct': 'BlockExportOptionsFuse', 'data': { 'mountpoint': 'str', '*growable': 'bool' }, - 'if': 'defined(CONFIG_FUSE)' } + 'if': 'CONFIG_FUSE' } =20 ## # @NbdServerAddOptions: @@ -247,7 +247,7 @@ ## { 'enum': 'BlockExportType', 'data': [ 'nbd', 'vhost-user-blk', - { 'name': 'fuse', 'if': 'defined(CONFIG_FUSE)' } ] } + { 'name': 'fuse', 'if': 'CONFIG_FUSE' } ] } =20 ## # @BlockExportOptions: @@ -290,7 +290,7 @@ 'nbd': 'BlockExportOptionsNbd', 'vhost-user-blk': 'BlockExportOptionsVhostUserBlk', 'fuse': { 'type': 'BlockExportOptionsFuse', - 'if': 'defined(CONFIG_FUSE)' } + 'if': 'CONFIG_FUSE' } } } =20 ## diff --git a/qapi/char.json b/qapi/char.json index 6413970fa7..bf3f8d54e5 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -342,7 +342,7 @@ { 'struct': 'ChardevSpiceChannel', 'data': { 'type': 'str' }, 'base': 'ChardevCommon', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @ChardevSpicePort: @@ -356,7 +356,7 @@ { 'struct': 'ChardevSpicePort', 'data': { 'fqdn': 'str' }, 'base': 'ChardevCommon', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @ChardevVC: @@ -414,9 +414,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 9b56b81bea..f5ec4bc172 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: @@ -320,11 +320,11 @@ 'typename': 'str', '*alias-of' : 'str', 'deprecated' : 'bool' }, - '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: @@ -336,8 +336,8 @@ # Since: 1.2 ## { '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 0b17cce46b..43e7b7620d 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -539,7 +539,7 @@ ## { 'enum': 'MultiFDCompression', 'data': [ 'none', 'zlib', - { 'name': 'zstd', 'if': 'defined(CONFIG_ZSTD)' } ] } + { 'name': 'zstd', 'if': 'CONFIG_ZSTD' } ] } =20 ## # @BitmapMigrationBitmapAliasTransform: @@ -1568,7 +1568,7 @@ ## { 'command': 'xen-set-replication', 'data': { 'enable': 'bool', 'primary': 'bool', '*failover' : 'bool' }, - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @ReplicationStatus: @@ -1584,7 +1584,7 @@ ## { 'struct': 'ReplicationStatus', 'data': { 'error': 'bool', '*desc': 'str' }, - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @query-xen-replication-status: @@ -1602,7 +1602,7 @@ ## { 'command': 'query-xen-replication-status', 'returns': 'ReplicationStatus', - 'if': 'defined(CONFIG_REPLICATION)' } + 'if': 'CONFIG_REPLICATION' } =20 ## # @xen-colo-do-checkpoint: @@ -1619,7 +1619,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 2891df6890..5d3c816eb8 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 ## # @sev-inject-launch-secret: @@ -228,7 +228,7 @@ ## { 'command': 'sev-inject-launch-secret', 'data': { 'packet-header': 'str', 'secret': 'str', '*gpa': 'uint64' }, - 'if': 'defined(TARGET_I386)' } + 'if': 'TARGET_I386' } =20 ## # @dump-skeys: @@ -250,7 +250,7 @@ ## { 'command': 'dump-skeys', 'data': { 'filename': 'str' }, - 'if': 'defined(TARGET_S390X)' } + 'if': 'TARGET_S390X' } =20 ## # @GICCapability: @@ -275,7 +275,7 @@ 'data': { 'version': 'int', 'emulated': 'bool', 'kernel': 'bool' }, - 'if': 'defined(TARGET_ARM)' } + 'if': 'TARGET_ARM' } =20 ## # @query-gic-capabilities: @@ -295,4 +295,4 @@ # ## { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'], - 'if': 'defined(TARGET_ARM)' } + 'if': 'TARGET_ARM' } diff --git a/qapi/qom.json b/qapi/qom.json index cd0e76d564..6c41ec61b0 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -603,7 +603,7 @@ 'data': { '*align': 'size', '*discard-data': 'bool', 'mem-path': 'str', - '*pmem': { 'type': 'bool', 'if': 'defined(CONFIG_LIBPMEM)' }, + '*pmem': { 'type': 'bool', 'if': 'CONFIG_LIBPMEM' }, '*readonly': 'bool' } } =20 ## @@ -752,7 +752,7 @@ 'cryptodev-backend', 'cryptodev-backend-builtin', { 'name': 'cryptodev-vhost-user', - 'if': 'defined(CONFIG_VHOST_CRYPTO)' }, + 'if': 'CONFIG_VHOST_CRYPTO' }, 'dbus-vmstate', 'filter-buffer', 'filter-dump', @@ -765,7 +765,7 @@ 'iothread', 'memory-backend-file', { 'name': 'memory-backend-memfd', - 'if': 'defined(CONFIG_LINUX)' }, + 'if': 'CONFIG_LINUX' }, 'memory-backend-ram', 'pef-guest', 'pr-manager-helper', @@ -809,7 +809,7 @@ 'cryptodev-backend': 'CryptodevBackendProperties', 'cryptodev-backend-builtin': 'CryptodevBackendProperties', 'cryptodev-vhost-user': { 'type': 'CryptodevVhostUserPropertie= s', - 'if': 'defined(CONFIG_VHOST_CRYPTO)'= }, + 'if': 'CONFIG_VHOST_CRYPTO' }, 'dbus-vmstate': 'DBusVMStateProperties', 'filter-buffer': 'FilterBufferProperties', 'filter-dump': 'FilterDumpProperties', @@ -822,7 +822,7 @@ 'iothread': 'IothreadProperties', 'memory-backend-file': 'MemoryBackendFileProperties', 'memory-backend-memfd': { 'type': 'MemoryBackendMemfdPropertie= s', - 'if': 'defined(CONFIG_LINUX)' }, + 'if': 'CONFIG_LINUX' }, 'memory-backend-ram': 'MemoryBackendProperties', 'pr-manager-helper': 'PrManagerHelperProperties', 'rng-builtin': 'RngProperties', diff --git a/qapi/sockets.json b/qapi/sockets.json index 2e83452797..a0c08aa4ba 100644 --- a/qapi/sockets.json +++ b/qapi/sockets.json @@ -86,8 +86,8 @@ { 'struct': 'UnixSocketAddress', 'data': { 'path': 'str', - '*abstract': { 'type': 'bool', 'if': 'defined(CONFIG_LINUX)' }, - '*tight': { 'type': 'bool', 'if': 'defined(CONFIG_LINUX)' } } } + '*abstract': { 'type': 'bool', 'if': 'CONFIG_LINUX' }, + '*tight': { 'type': 'bool', 'if': 'CONFIG_LINUX' } } } =20 ## # @VsockSocketAddress: diff --git a/qapi/ui.json b/qapi/ui.json index 1052ca9c38..ec29a66c9f 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -123,7 +123,7 @@ 'data': { 'host': 'str', 'port': 'str', 'family': 'NetworkAddressFamily' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SpiceServerInfo: @@ -137,7 +137,7 @@ { 'struct': 'SpiceServerInfo', 'base': 'SpiceBasicInfo', 'data': { '*auth': 'str' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SpiceChannel: @@ -163,7 +163,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: @@ -183,7 +183,7 @@ ## { 'enum': 'SpiceQueryMouseMode', 'data': [ 'client', 'server', 'unknown' ], - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SpiceInfo: @@ -222,7 +222,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: @@ -268,7 +268,7 @@ # ## { 'command': 'query-spice', 'returns': 'SpiceInfo', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SPICE_CONNECTED: @@ -294,7 +294,7 @@ { 'event': 'SPICE_CONNECTED', 'data': { 'server': 'SpiceBasicInfo', 'client': 'SpiceBasicInfo' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SPICE_INITIALIZED: @@ -323,7 +323,7 @@ { 'event': 'SPICE_INITIALIZED', 'data': { 'server': 'SpiceServerInfo', 'client': 'SpiceChannel' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SPICE_DISCONNECTED: @@ -349,7 +349,7 @@ { 'event': 'SPICE_DISCONNECTED', 'data': { 'server': 'SpiceBasicInfo', 'client': 'SpiceBasicInfo' }, - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # @SPICE_MIGRATE_COMPLETED: @@ -365,7 +365,7 @@ # ## { 'event': 'SPICE_MIGRATE_COMPLETED', - 'if': 'defined(CONFIG_SPICE)' } + 'if': 'CONFIG_SPICE' } =20 ## # =3D=3D VNC @@ -393,7 +393,7 @@ 'service': 'str', 'family': 'NetworkAddressFamily', 'websocket': 'bool' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncServerInfo: @@ -408,7 +408,7 @@ { 'struct': 'VncServerInfo', 'base': 'VncBasicInfo', 'data': { '*auth': 'str' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncClientInfo: @@ -426,7 +426,7 @@ { 'struct': 'VncClientInfo', 'base': 'VncBasicInfo', 'data': { '*x509_dname': 'str', '*sasl_username': 'str' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncInfo: @@ -469,7 +469,7 @@ 'data': {'enabled': 'bool', '*host': 'str', '*family': 'NetworkAddressFamily', '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo'= ]}, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncPrimaryAuth: @@ -481,7 +481,7 @@ { 'enum': 'VncPrimaryAuth', 'data': [ 'none', 'vnc', 'ra2', 'ra2ne', 'tight', 'ultra', 'tls', 'vencrypt', 'sasl' ], - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncVencryptSubAuth: @@ -496,7 +496,7 @@ 'tls-vnc', 'x509-vnc', 'tls-plain', 'x509-plain', 'tls-sasl', 'x509-sasl' ], - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncServerInfo2: @@ -514,7 +514,7 @@ 'base': 'VncBasicInfo', 'data': { 'auth' : 'VncPrimaryAuth', '*vencrypt' : 'VncVencryptSubAuth' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VncInfo2: @@ -547,7 +547,7 @@ 'auth' : 'VncPrimaryAuth', '*vencrypt' : 'VncVencryptSubAuth', '*display' : 'str' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @query-vnc: @@ -579,7 +579,7 @@ # ## { 'command': 'query-vnc', 'returns': 'VncInfo', - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } ## # @query-vnc-servers: # @@ -590,7 +590,7 @@ # Since: 2.3 ## { 'command': 'query-vnc-servers', 'returns': ['VncInfo2'], - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @change-vnc-password: @@ -606,7 +606,7 @@ ## { 'command': 'change-vnc-password', 'data': { 'password': 'str' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VNC_CONNECTED: @@ -636,7 +636,7 @@ { 'event': 'VNC_CONNECTED', 'data': { 'server': 'VncServerInfo', 'client': 'VncBasicInfo' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VNC_INITIALIZED: @@ -664,7 +664,7 @@ { 'event': 'VNC_INITIALIZED', 'data': { 'server': 'VncServerInfo', 'client': 'VncClientInfo' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # @VNC_DISCONNECTED: @@ -691,7 +691,7 @@ { 'event': 'VNC_DISCONNECTED', 'data': { 'server': 'VncServerInfo', 'client': 'VncClientInfo' }, - 'if': 'defined(CONFIG_VNC)' } + 'if': 'CONFIG_VNC' } =20 ## # =3D Input diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index fb17eebde3..c60f5e669d 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1380,7 +1380,7 @@ 'data': { 'keys': ['str'] }, - 'if': 'defined(CONFIG_POSIX)' } + 'if': 'CONFIG_POSIX' } =20 =20 ## @@ -1398,7 +1398,7 @@ { 'command': 'guest-ssh-get-authorized-keys', 'data': { 'username': 'str' }, 'returns': 'GuestAuthorizedKeys', - 'if': 'defined(CONFIG_POSIX)' } + 'if': 'CONFIG_POSIX' } =20 ## # @guest-ssh-add-authorized-keys: @@ -1416,7 +1416,7 @@ ## { 'command': 'guest-ssh-add-authorized-keys', 'data': { 'username': 'str', 'keys': ['str'], '*reset': 'bool' }, - 'if': 'defined(CONFIG_POSIX)' } + 'if': 'CONFIG_POSIX' } =20 ## # @guest-ssh-remove-authorized-keys: @@ -1434,4 +1434,4 @@ ## { 'command': 'guest-ssh-remove-authorized-keys', 'data': { 'username': 'str', 'keys': ['str'] }, - 'if': 'defined(CONFIG_POSIX)' } + 'if': 'CONFIG_POSIX' } diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 6236bfc457..2a36e0366e 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -210,7 +210,7 @@ def __init__(self, option: str): self.option =3D option =20 def cgen(self) -> str: - return self.option + return f"defined({self.option})" =20 def docgen(self) -> str: return self.option diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 0a97a6f020..a605a796db 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -294,10 +294,10 @@ def check_if(expr: _JSONObject, info: QAPISourceInfo,= source: str) -> None: =20 def normalize(cond: Union[str, List[str], object]) -> IfPredicate: if isinstance(cond, str): - if not cond.strip(): + if not cond.isidentifier(): raise QAPISemError( info, - "'if' condition '%s' of %s makes no sense" + "'if' condition '%s' of %s is not a valid identifier" % (cond, source)) return IfOption(cond) if isinstance(cond, list): diff --git a/tests/qapi-schema/alternate-branch-if-invalid.err b/tests/qapi= -schema/alternate-branch-if-invalid.err index d384929c51..03bad877a3 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' condition ' ' of 'data' member 'b= ranch' 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..5208f543ce 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' condition '' of struct is not a valid identifier diff --git a/tests/qapi-schema/bad-if-list.err b/tests/qapi-schema/bad-if-l= ist.err index c462f11b90..fa01894d03 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' condition ' ' of struct is not a valid identifier 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 423ea23e07..ae531e89b5 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 ca7e53f3b5..869d0b8636 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/doc-good.txt b/tests/qapi-schema/doc-good.txt index 726727af74..27b7ce8799 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -43,7 +43,7 @@ Example: Values ~~~~~~ =20 -"one" (**If: **"defined(IFONE)") +"one" (**If: **"IFONE") The _one_ {and only} =20 "two" @@ -62,7 +62,7 @@ Features If ~~ =20 -"defined(IFCOND)" +"IFCOND" =20 =20 "Base" (Object) @@ -87,7 +87,7 @@ Another paragraph (but no "var": line) Members ~~~~~~~ =20 -"var1": "string" (**If: **"defined(IFSTR)") +"var1": "string" (**If: **"IFSTR") Not documented =20 =20 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 2d5e480b44..fad64d879f 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -222,43 +222,43 @@ =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': 'test-if-union-cmd', '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': 'test-if-alternate-cmd', 'data': { 'alt-cmd-arg': 'TestIfAlte= rnate' }, - 'if': {'all': ['defined(TEST_IF_ALT)', {'not': 'defined(TEST_IF_NOT_ALT)= '}] } } + 'if': {'all': ['TEST_IF_ALT', {'not': 'TEST_IF_NOT_ALT'}] } } =20 { 'command': 'test-if-cmd', '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': 'test-cmd-return-def-three', 'returns': 'UserDefThree' } =20 { 'event': 'TEST_IF_EVENT', '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 @@ -280,19 +280,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' ], @@ -327,13 +327,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_FEATURES0', 'data': 'FeatureStruct1' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index f859bf648d..95006e60c4 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_test-if-union-cmd-arg member union-cmd-arg: TestIfUnion optional=3DFalse - if 'defined(TEST_IF_UNION)' + if 'TEST_IF_UNION' command test-if-union-cmd q_obj_test-if-union-cmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse - if '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_test-if-alternate-cmd-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 test-if-alternate-cmd q_obj_test-if-alternate-cmd-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_test-if-cmd-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 test-if-cmd q_obj_test-if-cmd-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 test-cmd-return-def-three 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_TEST_IF_EVENT-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 TEST_IF_EVENT q_obj_TEST_IF_EVENT-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_FEATURES0 FeatureStruct1 boxed=3DFalse event TEST_EVENT_FEATURES1 None diff --git a/tests/qapi-schema/union-branch-if-invalid.err b/tests/qapi-sch= ema/union-branch-if-invalid.err index dd4518233e..046187a5b9 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' condition '' of 'data' member 'branch= 1' is not a valid identifier --=20 2.29.0 From nobody Sat May 18 09:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619704159; cv=none; d=zohomail.com; s=zohoarc; b=BAuWHHU9Mexo7jssJRpfolUdDIuvArQ63NFvd2cUFrUhCXYJ557QezvayRq0z8IRyYMJUEOG5fhYUE1RmKm6NxFHAUNJDCGFnuVG+HX07dlN52Ha1nmWochwIVDjgSgI/gEQCUk0+Mdp/93+ASKYfmxkfVsS4ar0JO7gA7SxVZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619704159; 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=sMTl8I0rV5gWwbcLcMxNMuxOvsZcUTDOqDEH+ovcP3U=; b=NnEcHpJ6z7Pz8vfVAf1JPvfrsFOIrc4xhmH1kBini0GvUM5utD+nMmardHejVzSaGfLxF0RmuE/Y6dtDNajIPcFGci1dRuXlagqtyzo439cNAp9/7l36gd9amjNxmsdpBBUEMxpI7nF0SuLuJLHH7DamHzh2q9c0ojRYfIa4ROs= 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 1619704159202867.3889501160031; Thu, 29 Apr 2021 06:49:19 -0700 (PDT) Received: from localhost ([::1]:38794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc72b-00056x-Nv for importer@patchew.org; Thu, 29 Apr 2021 09:49:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6vk-00062C-ER for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:42:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc6vh-0002yd-Mw for qemu-devel@nongnu.org; Thu, 29 Apr 2021 09:42:12 -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-41-BjaNdvvpPfeVv7WbFsVa2w-1; Thu, 29 Apr 2021 09:42:07 -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 435D48BEB82 for ; Thu, 29 Apr 2021 13:42:06 +0000 (UTC) Received: from localhost (unknown [10.36.110.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D0B261D31; Thu, 29 Apr 2021 13:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619703729; 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=sMTl8I0rV5gWwbcLcMxNMuxOvsZcUTDOqDEH+ovcP3U=; b=ACyEm9tt4QRFgI9EQNGMNe/vEqRjBBUN74pEPqJ6aOAb+en16HvPN4ChW+IWIu06Oap/PB 8FZEZ76CKhDyUlmmM255ghc0ZFQ4roWqgVBq3FTWQeu/MyBXDBP0WdGIRuCJc6Ws9tovVH ML84RpnLWEV5w51EcNkcTi6GJHohc2Q= X-MC-Unique: BjaNdvvpPfeVv7WbFsVa2w-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH v3 9/9] docs: update the documentation about schema configuration Date: Thu, 29 Apr 2021 17:40:32 +0400 Message-Id: <20210429134032.1125111-10-marcandre.lureau@redhat.com> In-Reply-To: <20210429134032.1125111-1-marcandre.lureau@redhat.com> References: <20210429134032.1125111-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=216.205.24.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.22, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jsnow@redhat.com, armbru@redhat.com 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 Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- docs/devel/qapi-code-gen.txt | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index edaaf7ec40..4a3fd02723 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -780,26 +780,31 @@ 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 + | [ COND, ... ] + | { 'all: [ COND, ... ] } + | { 'any: [ COND, ... ] } + | { '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 generated from that condition: 'all': [COND= , ...] +will generate '(COND && ...)', 'any': [COND, ...] '(COND || ...)', 'not': = COND '!COND'. =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.29.0