From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsCfS-0001Oe-2t for qemu-devel@nongnu.org; Fri, 30 Oct 2015 12:36:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZsCfM-00054m-7O for qemu-devel@nongnu.org; Fri, 30 Oct 2015 12:36:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsCfM-00054K-0J for qemu-devel@nongnu.org; Fri, 30 Oct 2015 12:36:36 -0400 References: <1446052473-19170-1-git-send-email-eblake@redhat.com> <1446052473-19170-7-git-send-email-eblake@redhat.com> <87h9l8jyse.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <56339C92.3090404@redhat.com> Date: Fri, 30 Oct 2015 10:36:34 -0600 MIME-Version: 1.0 In-Reply-To: <87h9l8jyse.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="heuVnnDu1bPelOR3P4BjoXuiFV5ASmAqu" Subject: Re: [Qemu-devel] [PATCH v8 06/17] qapi-types: Consolidate gen_struct() and gen_union() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --heuVnnDu1bPelOR3P4BjoXuiFV5ASmAqu Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/30/2015 07:01 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> These two methods are now close enough that we can finally merge >> them, relying on the fact that simple unions now provide a >> reasonable local_members. Change gen_struct() to gen_object() >> that handles all forms of QAPISchemaObjectType, and rename and >> shrink gen_union() to gen_variants() to handle the portion of >> gen_object() needed when variants are present. >> >> gen_struct_fields() now has a single caller, so it no longer >> needs an optional parameter; however, I did not choose to inline >> it into the caller. >> >> No difference to generated code. >> >> Signed-off-by: Eric Blake >> >> def visit_object_type(self, name, info, base, members, variants):= >> self._fwdecl +=3D gen_fwd_object_or_array(name) >> - if variants: >> - if members: >> - assert len(members) =3D=3D 1 >> - assert members[0] =3D=3D variants.tag_member >> - self.decl +=3D gen_union(name, base, variants) >> - else: >> - self.decl +=3D gen_struct(name, base, members) >> + self.decl +=3D gen_object(name, base, members, variants) >> if base: >> self.decl +=3D gen_upcast(name, base) >> self._gen_type_cleanup(name) >> @@ -282,7 +268,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):= >> def visit_alternate_type(self, name, info, variants): >> self._fwdecl +=3D gen_fwd_object_or_array(name) >> self._fwdefn +=3D gen_alternate_qtypes(name, variants) >> - self.decl +=3D gen_union(name, None, variants) >> + self.decl +=3D gen_object(name, None, [variants.tag_member], = variants) >> self.decl +=3D gen_alternate_qtypes_decl(name) >> self._gen_type_cleanup(name) >=20 > Turned out nicely. Yes, I was pretty pleased with it. It gives more credence to our choice of introspection representation. >=20 > We could morph gen_struct_field() back into its original shape in a > separate patch: >=20 > def gen_struct_fields(members): > ret =3D '' >=20 > for memb in members: > ret +=3D gen_struct_field(memb.name, memb.type, memb.option= al) > return ret >=20 > with calling code >=20 > ret +=3D mcgen(''' > /* Members inherited from %(c_name)s: */ > ''', > c_name=3Dbase.c_name()) > ret +=3D gen_struct_fields(base.members) > ret +=3D mcgen(''' > /* Own members: */ > ''') > ret +=3D gen_struct_fields(local_members) >=20 > Matter of taste. Reasonable idea; I'll add it in for the v9 spin. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --heuVnnDu1bPelOR3P4BjoXuiFV5ASmAqu Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWM5ySAAoJEKeha0olJ0NqcXQH/2zMlFKxuiEYXtE0ODX++xOP Y0N0KdlmjXqnGZRY9I++7V54kPlIt17wc50ovJ8y3I+s+/3UTjKc1BPK/LlbMUYp 6qX3iQsSsNpHItZj/ueWng5kGvDpCc5knUuH41TbYdEb8t3cqe3JFQaxKWx9/vEe oGutcWyzB6s89N37bio6En+vGZxJfeHmoog7hNL8ZdX5zf7mmN6yAaAVgaQufCEd cceC8KgsovgFJxmddiRXmzG01GvbCbtjJlVsL8LFjAFg30Zs6eotd9hWyup9bqQx sVk89C3zeWTRfS/JhOCd2CMIqhOkuPgjg+I8bH9A784mSCUJg1IKYtH5bAdtS0E= =bSp7 -----END PGP SIGNATURE----- --heuVnnDu1bPelOR3P4BjoXuiFV5ASmAqu--