From nobody Tue Feb 10 02:55:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503410648204130.71982260317475; Tue, 22 Aug 2017 07:04:08 -0700 (PDT) Received: from localhost ([::1]:47275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9mo-0000P1-Ru for importer@patchew.org; Tue, 22 Aug 2017 10:04:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JN-00083l-0p for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JI-0006xl-5u for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58296) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JH-0006wh-SL for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:36 -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 mx1.redhat.com (Postfix) with ESMTPS id D7B6FC04D2B3; Tue, 22 Aug 2017 13:24:37 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A8BE60466; Tue, 22 Aug 2017 13:24:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D7B6FC04D2B3 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 22 Aug 2017 15:22:18 +0200 Message-Id: <20170822132255.23945-18-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 22 Aug 2017 13:24:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 17/54] qapi: add 'if' condition on entity objects X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Take 'if' from expression, and use it to construct entity objects. Shared implicit objects must share the same 'if' condition. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi.py | 81 +++++++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index a94d93ada4..dc40d74abb 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -992,7 +992,7 @@ def check_exprs(exprs): # =20 class QAPISchemaEntity(object): - def __init__(self, name, info, doc): + def __init__(self, name, info, doc, ifcond=3DNone): assert isinstance(name, str) self.name =3D name # For explicitly defined entities, info points to the (explicit) @@ -1002,6 +1002,7 @@ class QAPISchemaEntity(object): # such place). self.info =3D info self.doc =3D doc + self.ifcond =3D ifcond =20 def c_name(self): return c_name(self.name) @@ -1118,8 +1119,8 @@ class QAPISchemaBuiltinType(QAPISchemaType): =20 =20 class QAPISchemaEnumType(QAPISchemaType): - def __init__(self, name, info, doc, values, prefix): - QAPISchemaType.__init__(self, name, info, doc) + def __init__(self, name, info, doc, values, prefix, ifcond=3DNone): + QAPISchemaType.__init__(self, name, info, doc, ifcond) for v in values: assert isinstance(v, QAPISchemaMember) v.set_owner(name) @@ -1162,6 +1163,7 @@ class QAPISchemaArrayType(QAPISchemaType): def check(self, schema): self.element_type =3D schema.lookup_type(self._element_type_name) assert self.element_type + self.ifcond =3D self.element_type.ifcond =20 def is_implicit(self): return True @@ -1183,11 +1185,12 @@ class QAPISchemaArrayType(QAPISchemaType): =20 =20 class QAPISchemaObjectType(QAPISchemaType): - def __init__(self, name, info, doc, base, local_members, variants): + def __init__(self, name, info, doc, base, local_members, variants, + ifcond=3DNone): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no base - QAPISchemaType.__init__(self, name, info, doc) + QAPISchemaType.__init__(self, name, info, doc, ifcond) assert base is None or isinstance(base, str) for m in local_members: assert isinstance(m, QAPISchemaObjectTypeMember) @@ -1375,8 +1378,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTyp= eMember): =20 =20 class QAPISchemaAlternateType(QAPISchemaType): - def __init__(self, name, info, doc, variants): - QAPISchemaType.__init__(self, name, info, doc) + def __init__(self, name, info, doc, variants, ifcond): + QAPISchemaType.__init__(self, name, info, doc, ifcond) assert isinstance(variants, QAPISchemaObjectTypeVariants) assert variants.tag_member variants.set_owner(name) @@ -1413,8 +1416,8 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, doc, arg_type, ret_type, - gen, success_response, boxed): - QAPISchemaEntity.__init__(self, name, info, doc) + gen, success_response, boxed, ifcond): + QAPISchemaEntity.__init__(self, name, info, doc, ifcond) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) self._arg_type_name =3D arg_type @@ -1451,8 +1454,8 @@ class QAPISchemaCommand(QAPISchemaEntity): =20 =20 class QAPISchemaEvent(QAPISchemaEntity): - def __init__(self, name, info, doc, arg_type, boxed): - QAPISchemaEntity.__init__(self, name, info, doc) + def __init__(self, name, info, doc, arg_type, boxed, ifcond): + QAPISchemaEntity.__init__(self, name, info, doc, ifcond) assert not arg_type or isinstance(arg_type, str) self._arg_type_name =3D arg_type self.arg_type =3D None @@ -1547,11 +1550,11 @@ class QAPISchema(object): def _make_enum_members(self, values): return [QAPISchemaMember(v) for v in values] =20 - def _make_implicit_enum_type(self, name, info, values): + def _make_implicit_enum_type(self, name, info, values, ifcond): # See also QAPISchemaObjectTypeMember._pretty_owner() name =3D name + 'Kind' # Use namespace reserved by add_name() self._def_entity(QAPISchemaEnumType( - name, info, None, self._make_enum_members(values), None)) + name, info, None, self._make_enum_members(values), None, ifcon= d)) return name =20 def _make_array_type(self, element_type, info): @@ -1560,22 +1563,29 @@ class QAPISchema(object): self._def_entity(QAPISchemaArrayType(name, info, element_type)) return name =20 - def _make_implicit_object_type(self, name, info, doc, role, members): + def _make_implicit_object_type(self, name, info, doc, role, members, + ifcond=3DNone): if not members: return None # See also QAPISchemaObjectTypeMember._pretty_owner() name =3D 'q_obj_%s-%s' % (name, role) - if not self.lookup_entity(name, QAPISchemaObjectType): + typ =3D self.lookup_entity(name, QAPISchemaObjectType) + if typ: + # FIXME: generating the disjunction of all conditions + assert ifcond =3D=3D typ.ifcond + else: self._def_entity(QAPISchemaObjectType(name, info, doc, None, - members, None)) + members, None, ifcond)) return name =20 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') self._def_entity(QAPISchemaEnumType( - name, info, doc, self._make_enum_members(data), prefix)) + name, info, doc, self._make_enum_members(data), prefix, + ifcond)) =20 def _make_member(self, name, typ, info): optional =3D False @@ -1595,9 +1605,10 @@ class QAPISchema(object): name =3D expr['struct'] base =3D expr.get('base') data =3D expr['data'] + ifcond =3D expr.get('if') self._def_entity(QAPISchemaObjectType(name, info, doc, base, self._make_members(data, inf= o), - None)) + None, ifcond)) =20 def _make_variant(self, case, typ): return QAPISchemaObjectTypeVariant(case, typ) @@ -1606,19 +1617,23 @@ class QAPISchema(object): if isinstance(typ, list): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) + type_entity =3D self.lookup_type(typ) typ =3D self._make_implicit_object_type( - typ, info, None, 'wrapper', [self._make_member('data', typ, in= fo)]) + typ, info, None, 'wrapper', + [self._make_member('data', typ, info)], type_entity.ifcond) return QAPISchemaObjectTypeVariant(case, typ) =20 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') tag_name =3D expr.get('discriminator') tag_member =3D None if isinstance(base, dict): - base =3D (self._make_implicit_object_type( - name, info, doc, 'base', self._make_members(base, info))) + base =3D self._make_implicit_object_type( + name, info, doc, 'base', self._make_members(base, info), + ifcond) if tag_name: variants =3D [self._make_variant(key, value) for (key, value) in data.iteritems()] @@ -1627,18 +1642,21 @@ class QAPISchema(object): variants =3D [self._make_simple_variant(key, value, info) for (key, value) in data.iteritems()] typ =3D self._make_implicit_enum_type(name, info, - [v.name for v in variants]) + [v.name for v in variants], + ifcond) tag_member =3D QAPISchemaObjectTypeMember('type', typ, False) members =3D [tag_member] self._def_entity( QAPISchemaObjectType(name, info, doc, base, members, QAPISchemaObjectTypeVariants(tag_name, tag_member, - variants))) + variants), + ifcond)) =20 def _def_alternate_type(self, expr, info, doc): name =3D expr['alternate'] data =3D expr['data'] + ifcond =3D expr.get('if') variants =3D [self._make_variant(key, value) for (key, value) in data.iteritems()] tag_member =3D QAPISchemaObjectTypeMember('type', 'QType', False) @@ -1646,7 +1664,8 @@ class QAPISchema(object): QAPISchemaAlternateType(name, info, doc, QAPISchemaObjectTypeVariants(None, tag_membe= r, - variants)= )) + variants), + ifcond)) =20 def _def_command(self, expr, info, doc): name =3D expr['command'] @@ -1655,23 +1674,29 @@ class QAPISchema(object): gen =3D expr.get('gen', True) success_response =3D expr.get('success-response', True) boxed =3D expr.get('boxed', False) + ifcond =3D expr.get('if') if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, doc, 'arg', self._make_members(data, info)) + name, info, doc, 'arg', self._make_members(data, info), + ifcond) if isinstance(rets, list): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) self._def_entity(QAPISchemaCommand(name, info, doc, data, rets, - gen, success_response, boxed)) + gen, success_response, boxed, + ifcond)) =20 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') if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, doc, 'arg', self._make_members(data, info)) - self._def_entity(QAPISchemaEvent(name, info, doc, data, boxed)) + name, info, doc, 'arg', self._make_members(data, info), + ifcond) + self._def_entity(QAPISchemaEvent(name, info, doc, data, boxed, + ifcond)) =20 def _def_exprs(self): for expr_elem in self.exprs: --=20 2.14.1.146.gd35faa819