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 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 DE974C33CB1 for ; Tue, 14 Jan 2020 10:27:22 +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 AD1C1207FF for ; Tue, 14 Jan 2020 10:27:22 +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="Fr0Byo03" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD1C1207FF 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]:36434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irJPt-00021o-Qj for qemu-devel@archiver.kernel.org; Tue, 14 Jan 2020 05:27:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40793) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irJJq-0001sL-Oh for qemu-devel@nongnu.org; Tue, 14 Jan 2020 05:21:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irJJn-0006UC-11 for qemu-devel@nongnu.org; Tue, 14 Jan 2020 05:21:06 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:41955 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irJJm-0006TK-TT for qemu-devel@nongnu.org; Tue, 14 Jan 2020 05:21:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578997262; 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=dZPO5CKIjizq2YPGlIJxcJNQerUddJt7LdYSkITV7go=; b=Fr0Byo036m7VV01XoqcFkb7AuY8uGR4XWFKV2CYqeBSarS3AgQa0688FeHsirvDv8Rqv+I K1Rk3dYcwdvDO8NUBhS4cuLeZx3ViLdAxEtpnMXBKVkRn6psLo3UK+ZxVRyZbPSiP36y/K 9AfGhlMIbZnLjkaoDz64hLFjR6tCvIU= 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-104-E2J_0EAlNMqo2B3aDW56gw-1; Tue, 14 Jan 2020 05:20:58 -0500 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 BDB89106BC0A for ; Tue, 14 Jan 2020 10:20:57 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-131.ams2.redhat.com [10.36.116.131]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 017035C1B0; Tue, 14 Jan 2020 10:20:56 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6E77611366C1; Tue, 14 Jan 2020 11:20:55 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 4/6] qapi: Proper intermediate representation for modules Date: Tue, 14 Jan 2020 11:20:53 +0100 Message-Id: <20200114102055.24058-5-armbru@redhat.com> In-Reply-To: <20200114102055.24058-1-armbru@redhat.com> References: <20200114102055.24058-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: E2J_0EAlNMqo2B3aDW56gw-1 X-Mimecast-Spam-Score: 0 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: 205.139.110.61 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Modules are represented only by their names so far. Introduce class QAPISchemaModule. So far, it merely wraps the name. The next patch will put it to more interesting use. Once again, arrays spice up the patch a bit. For any other type, @info points to the definition, which lets us map from @info to module. For arrays, there is no definition, and @info points to the first use instead. We have to use the element type's module instead, which is only available after .check(). Signed-off-by: Markus Armbruster Message-Id: <20191120182551.23795-5-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/schema.py | 63 ++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index cfb574c85d..0f2e0dcfce 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -50,9 +50,6 @@ class QAPISchemaEntity(object): =20 def check(self, schema): assert not self._checked - if self.info: - self._module =3D os.path.relpath(self.info.fname, - os.path.dirname(schema.fname)) seen =3D {} for f in self.features: f.check_clash(self.info, seen) @@ -68,6 +65,13 @@ class QAPISchemaEntity(object): if self.doc: self.doc.check() =20 + def _set_module(self, schema, info): + assert self._checked + self._module =3D schema.module_by_fname(info and info.fname) + + def set_module(self, schema): + self._set_module(schema, self.info) + @property def ifcond(self): assert self._checked @@ -75,7 +79,7 @@ class QAPISchemaEntity(object): =20 @property def module(self): - assert self._checked + assert self._module or not self.info return self._module =20 def is_implicit(self): @@ -135,15 +139,19 @@ class QAPISchemaVisitor(object): pass =20 =20 +class QAPISchemaModule(object): + def __init__(self, name): + self.name =3D name + + class QAPISchemaInclude(QAPISchemaEntity): - - def __init__(self, fname, info): + def __init__(self, sub_module, info): QAPISchemaEntity.__init__(self, None, info, None) - self.fname =3D fname + self._sub_module =3D sub_module =20 def visit(self, visitor): QAPISchemaEntity.visit(self, visitor) - visitor.visit_include(self.fname, self.info) + visitor.visit_include(self._sub_module.name, self.info) =20 =20 class QAPISchemaType(QAPISchemaEntity): @@ -276,16 +284,14 @@ class QAPISchemaArrayType(QAPISchemaType): self.info and self.info.defn_meta) assert not isinstance(self.element_type, QAPISchemaArrayType) =20 + def set_module(self, schema): + self._set_module(schema, self.element_type.info) + @property def ifcond(self): assert self._checked return self.element_type.ifcond =20 - @property - def module(self): - assert self._checked - return self.element_type.module - def is_implicit(self): return True =20 @@ -783,6 +789,10 @@ class QAPISchema(object): self.docs =3D parser.docs self._entity_list =3D [] self._entity_dict =3D {} + self._module_dict =3D {} + self._schema_dir =3D os.path.dirname(fname) + self._make_module(None) # built-ins + self._make_module(fname) self._predefining =3D True self._def_predefineds() self._predefining =3D False @@ -826,14 +836,26 @@ class QAPISchema(object): info, "%s uses unknown type '%s'" % (what, name)) return typ =20 + def _module_name(self, fname): + if fname is None: + return None + return os.path.relpath(fname, self._schema_dir) + + def _make_module(self, fname): + name =3D self._module_name(fname) + if not name in self._module_dict: + self._module_dict[name] =3D QAPISchemaModule(name) + return self._module_dict[name] + + def module_by_fname(self, fname): + name =3D self._module_name(fname) + assert name in self._module_dict + return self._module_dict[name] + def _def_include(self, expr, info, doc): include =3D expr['include'] assert doc is None - main_info =3D info - while main_info.parent: - main_info =3D main_info.parent - fname =3D os.path.relpath(include, os.path.dirname(main_info.fname= )) - self._def_entity(QAPISchemaInclude(fname, info)) + self._def_entity(QAPISchemaInclude(self._make_module(include), inf= o)) =20 def _def_builtin_type(self, name, json_type, c_type): self._def_entity(QAPISchemaBuiltinType(name, json_type, c_type)) @@ -1065,15 +1087,16 @@ class QAPISchema(object): ent.check(self) ent.connect_doc() ent.check_doc() + for ent in self._entity_list: + ent.set_module(self) =20 def visit(self, visitor): visitor.visit_begin(self) module =3D None - visitor.visit_module(module) for entity in self._entity_list: if visitor.visit_needed(entity): if entity.module !=3D module: module =3D entity.module - visitor.visit_module(module) + visitor.visit_module(module.name) entity.visit(visitor) visitor.visit_end() --=20 2.21.1