From nobody Thu Nov 13 23:24:14 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583253379; cv=none; d=zohomail.com; s=zohoarc; b=K4OmPehT8Ol3bcKG8YG/H+V5PXfm2dJCC/oXzj5WSXe1dux6LJ/1iOp+p428v7QkCq6+ALZGNEqiSfJyFqsMc04t46Tqf742h8+r1JrJyf9l+L/Mzv2f0LKz03SZFUZTNx+Yy15JFKzPrVPbbAtBh6LPc8P9poSEK3TNWWpht8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583253379; 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=xege0Pw+GKvVLkCuOgENwHcnrmc+6NSA93kTUN6HE3c=; b=SnLMjLrPnI6aHugaG1+oydSL/GLsdUzsOgVd/ArbTpohRY1d7Nzi8aSqUws8hCVgkiYO3Il5sXtWX2pM/IOyk66hOT9PWwMsEBIBUsZJQ5GFxfSbeoJfh0qgTbanULo56CECTRNVrudsZ9riLS9kmh2S+9nT585Hu13dtnU0hFE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1583253379207694.5265690434076; Tue, 3 Mar 2020 08:36:19 -0800 (PST) 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-367-sHtzrfsePSGr-paEeEWSDA-1; Tue, 03 Mar 2020 11:36:02 -0500 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 94AB418FE86C; Tue, 3 Mar 2020 16:35:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63B0889F1C; Tue, 3 Mar 2020 16:35:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0147086A13; Tue, 3 Mar 2020 16:35:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 023GZFoO001299 for ; Tue, 3 Mar 2020 11:35:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 808915C578; Tue, 3 Mar 2020 16:35:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-129.ams2.redhat.com [10.36.116.129]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 656AA5C219; Tue, 3 Mar 2020 16:35:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E7B9D1132A06; Tue, 3 Mar 2020 17:35:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583253377; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xege0Pw+GKvVLkCuOgENwHcnrmc+6NSA93kTUN6HE3c=; b=L/c3j//gxKYiO3U7HLbjS76KXEitgSqpr950n9q6AwlapPrIEaXICY3n6AE8zZ2Bw5lH5g M26O2qzmRk40x7SVDR2czkQo2IUj4WIhWTeYc8L2Ar33hdHb2wvoUUbbro2ER1TG18zXeQ SLAlyrSKAyh/B1Q38hJuuD46UNUgkUk= X-MC-Unique: sHtzrfsePSGr-paEeEWSDA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 17/30] qapi/schema: Reorder classes so related ones are together Date: Tue, 3 Mar 2020 17:34:52 +0100 Message-Id: <20200303163505.32041-18-armbru@redhat.com> In-Reply-To: <20200303163505.32041-1-armbru@redhat.com> References: <20200303163505.32041-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Move QAPISchemaAlternateType up some, so that all QAPISchemaFOOType are together. Move QAPISchemaObjectTypeVariants right behind its users. Signed-off-by: Markus Armbruster --- scripts/qapi/schema.py | 284 ++++++++++++++++++++--------------------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 2ab6dc67e4..f0fb0d1c4d 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -444,82 +444,72 @@ class QAPISchemaObjectType(QAPISchemaType): self.members, self.variants) =20 =20 -class QAPISchemaMember: - """ Represents object members, enum members and features """ - role =3D 'member' - - 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.defined_in =3D None - - def set_defined_in(self, name): - assert not self.defined_in - self.defined_in =3D name - - def check_clash(self, info, seen): - cname =3D c_name(self.name) - if cname in seen: - raise QAPISemError( - info, - "%s collides with %s" - % (self.describe(info), seen[cname].describe(info))) - seen[cname] =3D self - - def describe(self, info): - role =3D self.role - defined_in =3D self.defined_in - assert defined_in - - if defined_in.startswith('q_obj_'): - # See QAPISchema._make_implicit_object_type() - reverse the - # mapping there to create a nice human-readable description - defined_in =3D defined_in[6:] - if defined_in.endswith('-arg'): - # Implicit type created for a command's dict 'data' - assert role =3D=3D 'member' - role =3D 'parameter' - elif defined_in.endswith('-base'): - # Implicit type created for a flat union's dict 'base' - role =3D 'base ' + role - else: - # Implicit type created for a simple union's branch - assert defined_in.endswith('-wrapper') - # Unreachable and not implemented - assert False - elif defined_in.endswith('Kind'): - # See QAPISchema._make_implicit_enum_type() - # Implicit enum created for simple union's branches - assert role =3D=3D 'value' - role =3D 'branch' - elif defined_in !=3D info.defn_name: - return "%s '%s' of type '%s'" % (role, self.name, defined_in) - return "%s '%s'" % (role, self.name) - - -class QAPISchemaEnumMember(QAPISchemaMember): - role =3D 'value' - - -class QAPISchemaFeature(QAPISchemaMember): - role =3D 'feature' - - -class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, info, typ, optional, ifcond=3DNone): - super().__init__(name, info, ifcond) - assert isinstance(typ, str) - assert isinstance(optional, bool) - self._type_name =3D typ - self.type =3D None - self.optional =3D optional +class QAPISchemaAlternateType(QAPISchemaType): + meta =3D 'alternate' + + def __init__(self, name, info, doc, ifcond, features, variants): + super().__init__(name, info, doc, ifcond, features) + assert isinstance(variants, QAPISchemaObjectTypeVariants) + assert variants.tag_member + variants.set_defined_in(name) + variants.tag_member.set_defined_in(self.name) + self.variants =3D variants =20 def check(self, schema): - assert self.defined_in - self.type =3D schema.resolve_type(self._type_name, self.info, - self.describe) + super().check(schema) + self.variants.tag_member.check(schema) + # Not calling self.variants.check_clash(), because there's nothing + # to clash with + self.variants.check(schema, {}) + # Alternate branch names have no relation to the tag enum values; + # so we have to check for potential name collisions ourselves. + seen =3D {} + types_seen =3D {} + for v in self.variants.variants: + v.check_clash(self.info, seen) + qtype =3D v.type.alternate_qtype() + if not qtype: + raise QAPISemError( + self.info, + "%s cannot use %s" + % (v.describe(self.info), v.type.describe())) + conflicting =3D set([qtype]) + if qtype =3D=3D 'QTYPE_QSTRING': + if isinstance(v.type, QAPISchemaEnumType): + for m in v.type.members: + if m.name in ['on', 'off']: + conflicting.add('QTYPE_QBOOL') + if re.match(r'[-+0-9.]', m.name): + # lazy, could be tightened + conflicting.add('QTYPE_QNUM') + else: + conflicting.add('QTYPE_QNUM') + conflicting.add('QTYPE_QBOOL') + for qt in conflicting: + if qt in types_seen: + raise QAPISemError( + self.info, + "%s can't be distinguished from '%s'" + % (v.describe(self.info), types_seen[qt])) + types_seen[qt] =3D v.name + + def connect_doc(self, doc=3DNone): + super().connect_doc(doc) + doc =3D doc or self.doc + if doc: + for v in self.variants.variants: + doc.connect_member(v) + + def c_type(self): + return c_name(self.name) + pointer_suffix + + def json_type(self): + return 'value' + + def visit(self, visitor): + super().visit(visitor) + visitor.visit_alternate_type( + self.name, self.info, self.ifcond, self.features, self.variant= s) =20 =20 class QAPISchemaObjectTypeVariants: @@ -613,6 +603,84 @@ class QAPISchemaObjectTypeVariants: v.type.check_clash(info, dict(seen)) =20 =20 +class QAPISchemaMember: + """ Represents object members, enum members and features """ + role =3D 'member' + + 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.defined_in =3D None + + def set_defined_in(self, name): + assert not self.defined_in + self.defined_in =3D name + + def check_clash(self, info, seen): + cname =3D c_name(self.name) + if cname in seen: + raise QAPISemError( + info, + "%s collides with %s" + % (self.describe(info), seen[cname].describe(info))) + seen[cname] =3D self + + def describe(self, info): + role =3D self.role + defined_in =3D self.defined_in + assert defined_in + + if defined_in.startswith('q_obj_'): + # See QAPISchema._make_implicit_object_type() - reverse the + # mapping there to create a nice human-readable description + defined_in =3D defined_in[6:] + if defined_in.endswith('-arg'): + # Implicit type created for a command's dict 'data' + assert role =3D=3D 'member' + role =3D 'parameter' + elif defined_in.endswith('-base'): + # Implicit type created for a flat union's dict 'base' + role =3D 'base ' + role + else: + # Implicit type created for a simple union's branch + assert defined_in.endswith('-wrapper') + # Unreachable and not implemented + assert False + elif defined_in.endswith('Kind'): + # See QAPISchema._make_implicit_enum_type() + # Implicit enum created for simple union's branches + assert role =3D=3D 'value' + role =3D 'branch' + elif defined_in !=3D info.defn_name: + return "%s '%s' of type '%s'" % (role, self.name, defined_in) + return "%s '%s'" % (role, self.name) + + +class QAPISchemaEnumMember(QAPISchemaMember): + role =3D 'value' + + +class QAPISchemaFeature(QAPISchemaMember): + role =3D 'feature' + + +class QAPISchemaObjectTypeMember(QAPISchemaMember): + def __init__(self, name, info, typ, optional, ifcond=3DNone): + super().__init__(name, info, ifcond) + assert isinstance(typ, str) + assert isinstance(optional, bool) + self._type_name =3D typ + self.type =3D None + self.optional =3D optional + + def check(self, schema): + assert self.defined_in + self.type =3D schema.resolve_type(self._type_name, self.info, + self.describe) + + class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): role =3D 'branch' =20 @@ -621,74 +689,6 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectType= Member): False, ifcond) =20 =20 -class QAPISchemaAlternateType(QAPISchemaType): - meta =3D 'alternate' - - def __init__(self, name, info, doc, ifcond, features, variants): - super().__init__(name, info, doc, ifcond, features) - assert isinstance(variants, QAPISchemaObjectTypeVariants) - assert variants.tag_member - variants.set_defined_in(name) - variants.tag_member.set_defined_in(self.name) - self.variants =3D variants - - def check(self, schema): - super().check(schema) - self.variants.tag_member.check(schema) - # Not calling self.variants.check_clash(), because there's nothing - # to clash with - self.variants.check(schema, {}) - # Alternate branch names have no relation to the tag enum values; - # so we have to check for potential name collisions ourselves. - seen =3D {} - types_seen =3D {} - for v in self.variants.variants: - v.check_clash(self.info, seen) - qtype =3D v.type.alternate_qtype() - if not qtype: - raise QAPISemError( - self.info, - "%s cannot use %s" - % (v.describe(self.info), v.type.describe())) - conflicting =3D set([qtype]) - if qtype =3D=3D 'QTYPE_QSTRING': - if isinstance(v.type, QAPISchemaEnumType): - for m in v.type.members: - if m.name in ['on', 'off']: - conflicting.add('QTYPE_QBOOL') - if re.match(r'[-+0-9.]', m.name): - # lazy, could be tightened - conflicting.add('QTYPE_QNUM') - else: - conflicting.add('QTYPE_QNUM') - conflicting.add('QTYPE_QBOOL') - for qt in conflicting: - if qt in types_seen: - raise QAPISemError( - self.info, - "%s can't be distinguished from '%s'" - % (v.describe(self.info), types_seen[qt])) - types_seen[qt] =3D v.name - - def connect_doc(self, doc=3DNone): - super().connect_doc(doc) - doc =3D doc or self.doc - if doc: - for v in self.variants.variants: - doc.connect_member(v) - - def c_type(self): - return c_name(self.name) + pointer_suffix - - def json_type(self): - return 'value' - - def visit(self, visitor): - super().visit(visitor) - visitor.visit_alternate_type( - self.name, self.info, self.ifcond, self.features, self.variant= s) - - class QAPISchemaCommand(QAPISchemaEntity): meta =3D 'command' =20 --=20 2.21.1