From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi05A-0008DM-GB for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:09:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi055-0003xn-Py for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:09:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41091) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi055-0003xh-Ir for qemu-devel@nongnu.org; Fri, 02 Oct 2015 09:08:59 -0400 References: <1443760312-656-1-git-send-email-eblake@redhat.com> <1443760312-656-5-git-send-email-eblake@redhat.com> <87io6pfz44.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <560E81E9.3040805@redhat.com> Date: Fri, 2 Oct 2015 07:08:57 -0600 MIME-Version: 1.0 In-Reply-To: <87io6pfz44.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Pb1mSO0H2m3n2dsAIKoeQDaXj9vmnfGCK" Subject: Re: [Qemu-devel] [PATCH v6 04/12] qapi: Create simple union type member earlier List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: marcandre.lureau@redhat.com, qemu-devel@nongnu.org, ehabkost@redhat.com, Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Pb1mSO0H2m3n2dsAIKoeQDaXj9vmnfGCK Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/02/2015 02:34 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> For simple unions, we were creating the implicit 'type' tag >> member during the QAPISchemaObjectTypeVariants constructor. >> This is different from every other implicit QAPISchemaEntity >> object, which get created by QAPISchema methods. Hoist the >> creation to the caller, and pass the entity rather than the >> string name, so that we have the nice property that no >> entities are created as a side effect within a different >> entity. A later patch will then have an easier time of >> associating location info with each entity creation. >> >> No change to generated code. >> >> Signed-off-by: Eric Blake >> >> class QAPISchemaObjectTypeVariants(object): >> - def __init__(self, tag_name, tag_enum, variants): >> + def __init__(self, tag_name, tag_member, variants): >> assert tag_name is None or isinstance(tag_name, str) >> - assert tag_enum is None or isinstance(tag_enum, str) >> + assert (tag_member is None or >> + isinstance(tag_member, QAPISchemaObjectTypeMember)) >> for v in variants: >> assert isinstance(v, QAPISchemaObjectTypeVariant) >> self.tag_name =3D tag_name >> if tag_name: >> - assert not tag_enum >> - self.tag_member =3D None >> - else: >> - self.tag_member =3D QAPISchemaObjectTypeMember('type', ta= g_enum, >> - False) >> + assert tag_member is None >=20 > Since the conditional degenerates to just checking the "either tag_name= > of tag_member" precondition, let's move it to right after the checking > of tag_name and tag_member, i.e. before the loop. >=20 > I'd also simplify to >=20 > assert not tag_name !=3D not tag_member >=20 > or >=20 > bool(tag_name) !=3D bool(tag_member) Sure, that works. I'll also add comments on the preconditions. >> @@ -1226,8 +1224,9 @@ class QAPISchema(object): >> return QAPISchemaObjectTypeVariant(case, typ) >> >> def _make_tag_enum(self, type_name, variants): >> - return self._make_implicit_enum_type(type_name, >> - [v.name for v in variant= s]) >> + typ =3D self._make_implicit_enum_type(type_name, >> + [v.name for v in variants= ]) >> + return QAPISchemaObjectTypeMember('type', typ, False) >=20 > I think this function should now be called _make_tag_member(), or > _make_implicit_tag_member(), or _make_implicit_tag(). >=20 Makes sense. I'll probably use _make_implicit_tag(). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --Pb1mSO0H2m3n2dsAIKoeQDaXj9vmnfGCK 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/ iQEcBAEBCAAGBQJWDoHpAAoJEKeha0olJ0Nq3+wH/joDkif5qzQhXN67gjFPNYpM rBnbQwymry+AcZew2entNWgxr3jsPfcXuxMTg4g2fV7z/rv/vjVpCnWSeLEUUE52 UbpJquEFNLIvUaYYXIZK08spJKs1mx630z3kPqPFiqoOje5AFILbnDyG886b4UK8 TBURgf3Dm/i5Zikz8nkEhvZGagU13DXmUH+cma3k6xNYnZ4twmTHA+5eo6aihdVI lkJJysSZ0KgYdUtXFsvdimqvFlk4yP7zks10BH86yq5G6wMbZKYNKxS9WO3eKn29 HzQAw/cqrscKtZgpQpSp72YYI5I9uVsxGw8h6gSnQWOg5FmrhzfCrv2RVlIUE5g= =l0by -----END PGP SIGNATURE----- --Pb1mSO0H2m3n2dsAIKoeQDaXj9vmnfGCK--