From nobody Mon Feb 9 23:18:23 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505129111253815.6912009964396; Mon, 11 Sep 2017 04:25:11 -0700 (PDT) Received: from localhost ([::1]:56817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drMpy-0003y6-74 for importer@patchew.org; Mon, 11 Sep 2017 07:25:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drMYg-0005XY-9c for qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:07:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drMYa-0006NE-6n for qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:07:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29830) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drMYZ-0006MZ-Ui for qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:07:12 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 0C0E72E2151; Mon, 11 Sep 2017 11:07:11 +0000 (UTC) Received: from localhost (ovpn-112-47.ams2.redhat.com [10.36.112.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DE46649CC; Mon, 11 Sep 2017 11:07:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0C0E72E2151 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 11 Sep 2017 13:05:49 +0200 Message-Id: <20170911110623.24981-17-marcandre.lureau@redhat.com> In-Reply-To: <20170911110623.24981-1-marcandre.lureau@redhat.com> References: <20170911110623.24981-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 11 Sep 2017 11:07:11 +0000 (UTC) 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: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 16/50] qapi-types: add #if conditions to types & visitors 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Types & visitors are coupled and must be handled together to avoid temporary build regression. Wrap generated types/visitor code with #if/#endif using the ifcond_decorator & helpers. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-types.py | 18 ++++++++++++++---- scripts/qapi-visit.py | 5 +++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 2b3588267b..789e89ff59 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -59,8 +59,10 @@ def gen_variants_objects(variants): for v in variants.variants: if isinstance(v.type, QAPISchemaObjectType): ret +=3D gen_variants_objects(v.type.variants) + ret +=3D gen_if(v.type.ifcond) ret +=3D gen_object(v.type.name, v.type.base, v.type.local_members, v.type.variants) + ret +=3D gen_endif(v.type.ifcond) return ret =20 =20 @@ -175,6 +177,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.defn =3D None self._fwdecl =3D None self._btin =3D None + self.if_members =3D ['decl', 'defn', '_fwdecl', '_btin'] =20 def visit_begin(self, schema): # gen_object() is recursive, ensure it doesn't visit the empty type @@ -199,6 +202,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl +=3D gen_type_cleanup_decl(name) self.defn +=3D gen_type_cleanup(name) =20 + @ifcond_decorator def visit_enum_type(self, name, info, ifcond, values, prefix): # Special case for our lone builtin enum type # TODO use something cleaner than existence of info @@ -210,6 +214,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._fwdecl +=3D gen_enum(name, values, prefix) self.defn +=3D gen_enum_lookup(name, values, prefix) =20 + @ifcond_decorator def visit_array_type(self, name, info, ifcond, element_type): if isinstance(element_type, QAPISchemaBuiltinType): self._btin +=3D gen_fwd_object_or_array(name) @@ -222,6 +227,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl +=3D gen_array(name, element_type) self._gen_type_cleanup(name) =20 + @ifcond_decorator def _gen_object(self, name, info, ifcond, base, members, variants): self.decl +=3D gen_object(name, base, members, variants) if base and not base.is_implicit(): @@ -232,18 +238,22 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) =20 + @ifcond_decorator + def _gen_fwd_object_or_array(self, name, ifcond): + self._fwdecl +=3D gen_fwd_object_or_array(name) + def visit_object_type(self, name, info, ifcond, base, members, variant= s): # 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._gen_fwd_object_or_array(name, ifcond) self.decl +=3D gen_variants_objects(variants) - self._gen_object(name, info, None, base, members, variants) + self._gen_object(name, info, ifcond, base, members, variants) =20 def visit_alternate_type(self, name, info, ifcond, variants): - self._fwdecl +=3D gen_fwd_object_or_array(name) + self._gen_fwd_object_or_array(name, ifcond) self.decl +=3D gen_variants_objects(variants) - self._gen_object(name, info, None, None, + self._gen_object(name, info, ifcond, None, [variants.tag_member], variants) =20 # If you link code generated from multiple schemata, you want only one diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index aceea2a9f9..4b0e005437 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -267,6 +267,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl =3D None self.defn =3D None self._btin =3D None + self.if_members =3D ['decl', 'defn', '_btin'] =20 def visit_begin(self, schema): self.decl =3D '' @@ -282,6 +283,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl =3D self._btin + self.decl self._btin =3D None =20 + @ifcond_decorator def visit_enum_type(self, name, info, ifcond, values, prefix): # Special case for our lone builtin enum type # TODO use something cleaner than existence of info @@ -293,6 +295,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D gen_visit_decl(name, scalar=3DTrue) self.defn +=3D gen_visit_enum(name) =20 + @ifcond_decorator def visit_array_type(self, name, info, ifcond, element_type): decl =3D gen_visit_decl(name) defn =3D gen_visit_list(name, element_type) @@ -304,6 +307,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D decl self.defn +=3D defn =20 + @ifcond_decorator def visit_object_type(self, name, info, ifcond, base, members, variant= s): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': @@ -317,6 +321,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D gen_visit_decl(name) self.defn +=3D gen_visit_object(name, base, members, variants) =20 + @ifcond_decorator def visit_alternate_type(self, name, info, ifcond, variants): self.decl +=3D gen_visit_decl(name) self.defn +=3D gen_visit_alternate(name, variants) --=20 2.14.1.146.gd35faa819