From nobody Tue Feb 10 08:27:21 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517591630319524.1045178384873; Fri, 2 Feb 2018 09:13:50 -0800 (PST) Received: from localhost ([::1]:40591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eheuL-0005IX-A5 for importer@patchew.org; Fri, 02 Feb 2018 12:13:49 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehdOj-0002hf-P7 for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:38:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ehdKW-0003XA-I9 for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:37:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ehdKW-0003VR-0Z for qemu-devel@nongnu.org; Fri, 02 Feb 2018 10:32:44 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 522493C47; Fri, 2 Feb 2018 13:04:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-148.ams2.redhat.com [10.36.116.148]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 210A77C855; Fri, 2 Feb 2018 13:04:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DBD3F1138667; Fri, 2 Feb 2018 14:03:36 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 2 Feb 2018 14:03:31 +0100 Message-Id: <20180202130336.24719-17-armbru@redhat.com> In-Reply-To: <20180202130336.24719-1-armbru@redhat.com> References: <20180202130336.24719-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Feb 2018 13:04:59 +0000 (UTC) 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 RFC 16/21] qapi/types qapi/visit: Make visitors use QAPIGen more 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The conversion is rather shallow so far: most of the output accumulation is not converted. Take the next step: convert output accumulation in QAPISchemaGenTypeVisitor and QAPISchemaGenVisitVisitor. Helper functions outside these classes are not converted. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi/types.py | 83 +++++++++++++++++++++++------------------------= ---- scripts/qapi/visit.py | 83 +++++++++++++++++++++++------------------------= ---- 2 files changed, 74 insertions(+), 92 deletions(-) diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index b2095120e0..eeffcbf32c 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -168,35 +168,44 @@ void qapi_free_%(c_name)s(%(c_name)s *obj) =20 =20 class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): - def __init__(self, opt_builtins): + def __init__(self, opt_builtins, prefix): self._opt_builtins =3D opt_builtins - self.decl =3D None - self.defn =3D None - self._fwdecl =3D None - self._btin =3D None + self._prefix =3D prefix + blurb =3D ' * Schema-defined QAPI types' + self._genc =3D QAPIGenC(blurb, __doc__) + self._genh =3D QAPIGenH(blurb, __doc__) + self._genc.preamble(mcgen(''' +#include "qemu/osdep.h" +#include "qapi/dealloc-visitor.h" +#include "%(prefix)sqapi-types.h" +#include "%(prefix)sqapi-visit.h" +''', + prefix=3Dprefix)) + self._genh.preamble(mcgen(''' +#include "qapi/util.h" +''')) + self._btin =3D '\n' + guardstart('QAPI_TYPES_BUILTIN') + + def write(self, output_dir): + self._genc.write(output_dir, self._prefix + 'qapi-types.c') + self._genh.write(output_dir, self._prefix + 'qapi-types.h') =20 def visit_begin(self, schema): # gen_object() is recursive, ensure it doesn't visit the empty type objects_seen.add(schema.the_empty_object_type.name) - self.decl =3D '' - self.defn =3D '' - self._fwdecl =3D '' - self._btin =3D '\n' + guardstart('QAPI_TYPES_BUILTIN') =20 def visit_end(self): - self.decl =3D self._fwdecl + self.decl - self._fwdecl =3D None # To avoid header dependency hell, we always generate # declarations for built-in types in our header files and # simply guard them. See also opt_builtins (command line # option -b). self._btin +=3D guardend('QAPI_TYPES_BUILTIN') - self.decl =3D self._btin + self.decl + self._genh.preamble(self._btin) self._btin =3D None =20 def _gen_type_cleanup(self, name): - self.decl +=3D gen_type_cleanup_decl(name) - self.defn +=3D gen_type_cleanup(name) + self._genh.body(gen_type_cleanup_decl(name)) + self._genc.body(gen_type_cleanup(name)) =20 def visit_enum_type(self, name, info, values, prefix): # Special case for our lone builtin enum type @@ -204,10 +213,10 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): if not info: self._btin +=3D gen_enum(name, values, prefix) if self._opt_builtins: - self.defn +=3D gen_enum_lookup(name, values, prefix) + self._genc.body(gen_enum_lookup(name, values, prefix)) else: - self._fwdecl +=3D gen_enum(name, values, prefix) - self.defn +=3D gen_enum_lookup(name, values, prefix) + self._genh.preamble(gen_enum(name, values, prefix)) + self._genc.body(gen_enum_lookup(name, values, prefix)) =20 def visit_array_type(self, name, info, element_type): if isinstance(element_type, QAPISchemaBuiltinType): @@ -215,20 +224,20 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._btin +=3D gen_array(name, element_type) self._btin +=3D gen_type_cleanup_decl(name) if self._opt_builtins: - self.defn +=3D gen_type_cleanup(name) + self._genc.body(gen_type_cleanup(name)) else: - self._fwdecl +=3D gen_fwd_object_or_array(name) - self.decl +=3D gen_array(name, element_type) + self._genh.preamble(gen_fwd_object_or_array(name)) + self._genh.body(gen_array(name, element_type)) self._gen_type_cleanup(name) =20 def visit_object_type(self, name, info, base, members, variants): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return - self._fwdecl +=3D gen_fwd_object_or_array(name) - self.decl +=3D gen_object(name, base, members, variants) + self._genh.preamble(gen_fwd_object_or_array(name)) + self._genh.body(gen_object(name, base, members, variants)) if base and not base.is_implicit(): - self.decl +=3D gen_upcast(name, base) + self._genh.body(gen_upcast(name, base)) # TODO Worth changing the visitor signature, so we could # directly use rather than repeat type.is_implicit()? if not name.startswith('q_'): @@ -236,31 +245,13 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._gen_type_cleanup(name) =20 def visit_alternate_type(self, name, info, variants): - self._fwdecl +=3D gen_fwd_object_or_array(name) - self.decl +=3D gen_object(name, None, [variants.tag_member], varia= nts) + self._genh.preamble(gen_fwd_object_or_array(name)) + self._genh.body(gen_object(name, None, + [variants.tag_member], variants)) self._gen_type_cleanup(name) =20 =20 def gen_types(schema, output_dir, prefix, opt_builtins): - blurb =3D ' * Schema-defined QAPI types' - genc =3D QAPIGenC(blurb, __doc__) - genh =3D QAPIGenH(blurb, __doc__) - - genc.body(mcgen(''' -#include "qemu/osdep.h" -#include "qapi/dealloc-visitor.h" -#include "%(prefix)sqapi-types.h" -#include "%(prefix)sqapi-visit.h" -''', - prefix=3Dprefix)) - - genh.body(mcgen(''' -#include "qapi/util.h" -''')) - - vis =3D QAPISchemaGenTypeVisitor(opt_builtins) + vis =3D QAPISchemaGenTypeVisitor(opt_builtins, prefix) schema.visit(vis) - genc.body(vis.defn) - genh.body(vis.decl) - genc.write(output_dir, prefix + 'qapi-types.c') - genh.write(output_dir, prefix + 'qapi-types.h') + vis.write(output_dir) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 80c0b85f8c..ee1a849574 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -264,24 +264,38 @@ out: =20 =20 class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): - def __init__(self, opt_builtins): + def __init__(self, opt_builtins, prefix): self._opt_builtins =3D opt_builtins - self.decl =3D None - self.defn =3D None - self._btin =3D None - - def visit_begin(self, schema): - self.decl =3D '' - self.defn =3D '' + self._prefix =3D prefix + blurb =3D ' * Schema-defined QAPI visitors' + self._genc =3D QAPIGenC(blurb, __doc__) + self._genh =3D QAPIGenH(blurb, __doc__) + self._genc.preamble(mcgen(''' +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "%(prefix)sqapi-visit.h" +''', + prefix=3Dprefix)) + self._genh.preamble(mcgen(''' +#include "qapi/visitor.h" +#include "qapi/qmp/qerror.h" +#include "%(prefix)sqapi-types.h" +''', + prefix=3Dprefix)) self._btin =3D guardstart('QAPI_VISIT_BUILTIN') =20 + def write(self, output_dir): + self._genc.write(output_dir, self._prefix + 'qapi-visit.c') + self._genh.write(output_dir, self._prefix + 'qapi-visit.h') + def visit_end(self): # To avoid header dependency hell, we always generate # declarations for built-in types in our header files and # simply guard them. See also opt_builtins (command line # option -b). self._btin +=3D guardend('QAPI_VISIT_BUILTIN') - self.decl =3D self._btin + self.decl + self._genh.preamble(self._btin) self._btin =3D None =20 def visit_enum_type(self, name, info, values, prefix): @@ -290,10 +304,10 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): if not info: self._btin +=3D gen_visit_decl(name, scalar=3DTrue) if self._opt_builtins: - self.defn +=3D gen_visit_enum(name) + self._genc.body(gen_visit_enum(name)) else: - self.decl +=3D gen_visit_decl(name, scalar=3DTrue) - self.defn +=3D gen_visit_enum(name) + self._genh.body(gen_visit_decl(name, scalar=3DTrue)) + self._genc.body(gen_visit_enum(name)) =20 def visit_array_type(self, name, info, element_type): decl =3D gen_visit_decl(name) @@ -301,53 +315,30 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): if isinstance(element_type, QAPISchemaBuiltinType): self._btin +=3D decl if self._opt_builtins: - self.defn +=3D defn + self._genc.body(defn) else: - self.decl +=3D decl - self.defn +=3D defn + self._genh.body(decl) + self._genc.body(defn) =20 def visit_object_type(self, name, info, base, members, variants): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return - self.decl +=3D gen_visit_members_decl(name) - self.defn +=3D gen_visit_object_members(name, base, members, varia= nts) + self._genh.body(gen_visit_members_decl(name)) + self._genc.body(gen_visit_object_members(name, base, members, vari= ants)) # TODO Worth changing the visitor signature, so we could # directly use rather than repeat type.is_implicit()? if not name.startswith('q_'): # only explicit types need an allocating visit - self.decl +=3D gen_visit_decl(name) - self.defn +=3D gen_visit_object(name, base, members, variants) + self._genh.body(gen_visit_decl(name)) + self._genc.body(gen_visit_object(name, base, members, variants= )) =20 def visit_alternate_type(self, name, info, variants): - self.decl +=3D gen_visit_decl(name) - self.defn +=3D gen_visit_alternate(name, variants) + self._genh.body(gen_visit_decl(name)) + self._genc.body(gen_visit_alternate(name, variants)) =20 =20 def gen_visit(schema, output_dir, prefix, opt_builtins): - blurb =3D ' * Schema-defined QAPI visitors' - genc =3D QAPIGenC(blurb, __doc__) - genh =3D QAPIGenH(blurb, __doc__) - - genc.body(mcgen(''' -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "qapi/error.h" -#include "%(prefix)sqapi-visit.h" -''', - prefix=3Dprefix)) - - genh.body(mcgen(''' -#include "qapi/visitor.h" -#include "qapi/qmp/qerror.h" -#include "%(prefix)sqapi-types.h" - -''', - prefix=3Dprefix)) - - vis =3D QAPISchemaGenVisitVisitor(opt_builtins) + vis =3D QAPISchemaGenVisitVisitor(opt_builtins, prefix) schema.visit(vis) - genc.body(vis.defn) - genh.body(vis.decl) - genc.write(output_dir, prefix + 'qapi-visit.c') - genh.write(output_dir, prefix + 'qapi-visit.h') + vis.write(output_dir) --=20 2.13.6