From nobody Tue Feb 10 12:43:13 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 150340961686627.34017073969585; Tue, 22 Aug 2017 06:46:56 -0700 (PDT) Received: from localhost ([::1]:47113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9WB-0002Gp-JI for importer@patchew.org; Tue, 22 Aug 2017 09:46:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9H3-0005xj-0i for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Gz-0005KM-49 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37992) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Gy-0005K4-S5 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:13 -0400 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 266087E449; Tue, 22 Aug 2017 13:25:15 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3599083D8B; Tue, 22 Aug 2017 13:25:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 266087E449 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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: Tue, 22 Aug 2017 15:22:27 +0200 Message-Id: <20170822132255.23945-27-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 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.27]); Tue, 22 Aug 2017 13:25:15 +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 v2 26/54] qapi-types: refactor variants handling 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?= , Markus Armbruster , 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" Generate variants objects outside gen_object(). This will allow to easily wrap gen_object() with ifcond_decorator in the following patch. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-types.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 6f06720adc..05b0eee482 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -53,19 +53,23 @@ def gen_struct_members(members): return ret =20 =20 -def gen_object(name, base, members, variants): - if name in objects_seen: - return '' - objects_seen.add(name) - +def gen_variants_objects(variants): ret =3D '' if variants: for v in variants.variants: if isinstance(v.type, QAPISchemaObjectType): + ret +=3D gen_variants_objects(v.type.variants) ret +=3D gen_object(v.type.name, v.type.base, v.type.local_members, v.type.variants) + return ret =20 - ret +=3D mcgen(''' + +def gen_object(name, base, members, variants): + if name in objects_seen: + return '' + objects_seen.add(name) + + ret =3D mcgen(''' =20 struct %(c_name)s { ''', @@ -224,11 +228,7 @@ typedef struct QEnumLookup { self.decl +=3D gen_array(name, element_type) self._gen_type_cleanup(name) =20 - def visit_object_type(self, name, info, base, members, variants, ifcon= d): - # Nothing to do for the special empty builtin - if name =3D=3D 'q_empty': - return - self._fwdecl +=3D gen_fwd_object_or_array(name) + def _gen_object(self, name, info, base, members, variants): self.decl +=3D gen_object(name, base, members, variants) if base and not base.is_implicit(): self.decl +=3D gen_upcast(name, base) @@ -238,10 +238,18 @@ typedef struct QEnumLookup { # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) =20 + def visit_object_type(self, name, info, base, members, variants, ifcon= d): + # 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_variants_objects(variants) + self._gen_object(name, info, base, members, variants) + def visit_alternate_type(self, name, info, variants, ifcond): self._fwdecl +=3D gen_fwd_object_or_array(name) - self.decl +=3D gen_object(name, None, [variants.tag_member], varia= nts) - self._gen_type_cleanup(name) + self.decl +=3D gen_variants_objects(variants) + self._gen_object(name, info, None, [variants.tag_member], variants) =20 # If you link code generated from multiple schemata, you want only one # instance of the code for built-in types. Generate it only when --=20 2.14.1.146.gd35faa819