From nobody Sun Nov 9 20:21:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 155180600239951.72567514652076; Tue, 5 Mar 2019 09:13:22 -0800 (PST) Received: from localhost ([127.0.0.1]:46111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1Dd0-0003ME-7b for importer@patchew.org; Tue, 05 Mar 2019 12:13:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1DJI-00031y-FQ for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:52:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1DJH-0002ex-2D for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:52:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41623) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1DJG-0002Z1-NC for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:52:54 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 959B23DD99 for ; Tue, 5 Mar 2019 16:52:45 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E7BD5D9CC for ; Tue, 5 Mar 2019 16:52:45 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AA91A11385D5; Tue, 5 Mar 2019 17:52:36 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 5 Mar 2019 17:52:32 +0100 Message-Id: <20190305165236.8389-4-armbru@redhat.com> In-Reply-To: <20190305165236.8389-1-armbru@redhat.com> References: <20190305165236.8389-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 05 Mar 2019 16:52:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/7] qapi: Pass file name to QAPIGen constructor instead of methods 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Not much of an improvement now, but the next commit will profit. Signed-off-by: Markus Armbruster Message-Id: <20190301154051.23317-4-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/commands.py | 2 +- scripts/qapi/common.py | 68 +++++++++++++++++++++------------------- scripts/qapi/doc.py | 4 +-- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index ebf488953d..6d66bf6aa3 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -239,7 +239,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVis= itor): QAPISchemaModularCVisitor.__init__( self, prefix, 'qapi-commands', ' * Schema-defined QAPI/QMP commands', __doc__) - self._regy =3D QAPIGenCCode() + self._regy =3D QAPIGenCCode(None) self._visited_ret_types =3D {} =20 def _begin_user_module(self, name): diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c327ae5036..8512cac427 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -2158,7 +2158,8 @@ def build_params(arg_type, boxed, extra=3DNone): =20 class QAPIGen(object): =20 - def __init__(self): + def __init__(self, fname): + self.fname =3D fname self._preamble =3D '' self._body =3D '' =20 @@ -2168,18 +2169,17 @@ class QAPIGen(object): def add(self, text): self._body +=3D text =20 - def get_content(self, fname=3DNone): - return (self._top(fname) + self._preamble + self._body - + self._bottom(fname)) + def get_content(self): + return self._top() + self._preamble + self._body + self._bottom() =20 - def _top(self, fname): + def _top(self): return '' =20 - def _bottom(self, fname): + def _bottom(self): return '' =20 - def write(self, output_dir, fname): - pathname =3D os.path.join(output_dir, fname) + def write(self, output_dir): + pathname =3D os.path.join(output_dir, self.fname) dir =3D os.path.dirname(pathname) if dir: try: @@ -2192,7 +2192,7 @@ class QAPIGen(object): f =3D open(fd, 'r+', encoding=3D'utf-8') else: f =3D os.fdopen(fd, 'r+') - text =3D self.get_content(fname) + text =3D self.get_content() oldtext =3D f.read(len(text) + 1) if text !=3D oldtext: f.seek(0) @@ -2229,8 +2229,8 @@ def ifcontext(ifcond, *args): =20 class QAPIGenCCode(QAPIGen): =20 - def __init__(self): - QAPIGen.__init__(self) + def __init__(self, fname): + QAPIGen.__init__(self, fname) self._start_if =3D None =20 def start_if(self, ifcond): @@ -2248,20 +2248,20 @@ class QAPIGenCCode(QAPIGen): self._preamble =3D _wrap_ifcond(self._start_if[0], self._start_if[2], self._preamble) =20 - def get_content(self, fname=3DNone): + def get_content(self): assert self._start_if is None - return QAPIGen.get_content(self, fname) + return QAPIGen.get_content(self) =20 =20 class QAPIGenC(QAPIGenCCode): =20 - def __init__(self, blurb, pydoc): - QAPIGenCCode.__init__(self) + def __init__(self, fname, blurb, pydoc): + QAPIGenCCode.__init__(self, fname) self._blurb =3D blurb self._copyright =3D '\n * '.join(re.findall(r'^Copyright .*', pydo= c, re.MULTILINE)) =20 - def _top(self, fname): + def _top(self): return mcgen(''' /* AUTOMATICALLY GENERATED, DO NOT MODIFY */ =20 @@ -2277,28 +2277,28 @@ class QAPIGenC(QAPIGenCCode): ''', blurb=3Dself._blurb, copyright=3Dself._copyright) =20 - def _bottom(self, fname): + def _bottom(self): return mcgen(''' =20 /* Dummy declaration to prevent empty .o file */ char dummy_%(name)s; ''', - name=3Dc_name(fname)) + name=3Dc_name(self.fname)) =20 =20 class QAPIGenH(QAPIGenC): =20 - def _top(self, fname): - return QAPIGenC._top(self, fname) + guardstart(fname) + def _top(self): + return QAPIGenC._top(self) + guardstart(self.fname) =20 - def _bottom(self, fname): - return guardend(fname) + def _bottom(self): + return guardend(self.fname) =20 =20 class QAPIGenDoc(QAPIGen): =20 - def _top(self, fname): - return (QAPIGen._top(self, fname) + def _top(self): + return (QAPIGen._top(self) + '@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n') =20 =20 @@ -2307,12 +2307,14 @@ class QAPISchemaMonolithicCVisitor(QAPISchemaVisito= r): def __init__(self, prefix, what, blurb, pydoc): self._prefix =3D prefix self._what =3D what - self._genc =3D QAPIGenC(blurb, pydoc) - self._genh =3D QAPIGenH(blurb, pydoc) + self._genc =3D QAPIGenC(self._prefix + self._what + '.c', + blurb, pydoc) + self._genh =3D QAPIGenH(self._prefix + self._what + '.h', + blurb, pydoc) =20 def write(self, output_dir): - self._genc.write(output_dir, self._prefix + self._what + '.c') - self._genh.write(output_dir, self._prefix + self._what + '.h') + self._genc.write(output_dir) + self._genh.write(output_dir) =20 =20 class QAPISchemaModularCVisitor(QAPISchemaVisitor): @@ -2349,8 +2351,9 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): return ret =20 def _add_module(self, name, blurb): - genc =3D QAPIGenC(blurb, self._pydoc) - genh =3D QAPIGenH(blurb, self._pydoc) + basename =3D self._module_basename(self._what, name) + genc =3D QAPIGenC(basename + '.c', blurb, self._pydoc) + genh =3D QAPIGenH(basename + '.h', blurb, self._pydoc) self._module[name] =3D (genc, genh) self._set_module(name) =20 @@ -2370,10 +2373,9 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): for name in self._module: if self._is_builtin_module(name) and not opt_builtins: continue - basename =3D self._module_basename(self._what, name) (genc, genh) =3D self._module[name] - genc.write(output_dir, basename + '.c') - genh.write(output_dir, basename + '.h') + genc.write(output_dir) + genh.write(output_dir) =20 def _begin_user_module(self, name): pass diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index c03b690161..5c8c136899 100755 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -207,11 +207,11 @@ def texi_entity(doc, what, ifcond, base=3DNone, varia= nts=3DNone, class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor): def __init__(self, prefix): self._prefix =3D prefix - self._gen =3D qapi.common.QAPIGenDoc() + self._gen =3D qapi.common.QAPIGenDoc(self._prefix + 'qapi-doc.texi= ') self.cur_doc =3D None =20 def write(self, output_dir): - self._gen.write(output_dir, self._prefix + 'qapi-doc.texi') + self._gen.write(output_dir) =20 def visit_enum_type(self, name, info, ifcond, members, prefix): doc =3D self.cur_doc --=20 2.17.2