From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6A5EC10DCE for ; Sun, 15 Mar 2020 15:07:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98B8820637 for ; Sun, 15 Mar 2020 15:07:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W9NJIKt+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98B8820637 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDUr5-0004tf-L3 for qemu-devel@archiver.kernel.org; Sun, 15 Mar 2020 11:07:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40534) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDUXk-0005Zw-Sq for qemu-devel@nongnu.org; Sun, 15 Mar 2020 10:47:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDUXh-0002Rc-Ik for qemu-devel@nongnu.org; Sun, 15 Mar 2020 10:47:08 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:51087 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jDUXh-0002Lj-6R for qemu-devel@nongnu.org; Sun, 15 Mar 2020 10:47:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584283622; 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=ycQjS+KQ2EfX4cdJBg+55kDCQJ6Cwz6RE3KV5yBSIxA=; b=W9NJIKt+cLp1TyrY7VuAUbp7+k9LLVZu1AlbuVYMBKgy8qr1ZdyZYZSq3llFYKw2/5SjOy kfY+AqvZgxe+n7iZB4DA7nFNu0DgoH1++l7B1t+UMDxHXHEngHrIPKLjVg4Y0vcir3hRbH LldUFbOqHJKHP8Y7gksoIAQ//p8goVw= 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-31-SkMS032sNL-U--XuzurU_g-1; Sun, 15 Mar 2020 10:46:59 -0400 X-MC-Unique: SkMS032sNL-U--XuzurU_g-1 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 6D81A189D6C4; Sun, 15 Mar 2020 14:46:58 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-49.ams2.redhat.com [10.36.116.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14D1A60C63; Sun, 15 Mar 2020 14:46:58 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AB4611135A5A; Sun, 15 Mar 2020 15:46:53 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v3 17/34] qapi/schema: Reorder classes so related ones are together Date: Sun, 15 Mar 2020 15:46:36 +0100 Message-Id: <20200315144653.22660-18-armbru@redhat.com> In-Reply-To: <20200315144653.22660-1-armbru@redhat.com> References: <20200315144653.22660-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII 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: 207.211.31.120 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: mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 4d8ad67303..0acf8b466f 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 @@ -620,74 +688,6 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectType= Member): super().__init__(name, info, typ, 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