From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhzay-0004sJ-Ap for qemu-devel@nongnu.org; Fri, 02 Oct 2015 08:37:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zhzat-0004wT-Tr for qemu-devel@nongnu.org; Fri, 02 Oct 2015 08:37:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38829) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhzHa-0004fX-9R for qemu-devel@nongnu.org; Fri, 02 Oct 2015 08:17:50 -0400 References: <1443760312-656-1-git-send-email-eblake@redhat.com> <1443760312-656-2-git-send-email-eblake@redhat.com> <87mvw1hilh.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <560E75BA.3050100@redhat.com> Date: Fri, 2 Oct 2015 06:16:58 -0600 MIME-Version: 1.0 In-Reply-To: <87mvw1hilh.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Hj6fD6Ckdooxv0qPEcKTmOCOwq3nrfp1P" Subject: Re: [Qemu-devel] [PATCH v6 01/12] qapi: Use predicate callback to determine visit filtering 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) --Hj6fD6Ckdooxv0qPEcKTmOCOwq3nrfp1P Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/02/2015 12:47 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> Previously, qapi-types and qapi-visit filtered out implicit >> objects during visit_object_type() by using 'info' (works since >> implicit objects do not [yet] have associated info); meanwhile >> qapi-introspect filtered out all schema types on the first pass >> by returning a python type from visit_begin(), which was then >> used in QAPISchema.visit(). Rather than keeping these ad hoc >> approaches, add a new visitor callback visit_predicate() which >> returns False to skip a given entity, and which defaults to >> True unless overridden. Use the new mechanism to simplify all >> three visitors that need filtering. No change to the generated >> code. >=20 > Let's call it visit_wanted(). Ah, that's nicer. >=20 >> Suggested-by: Markus Armbruster >> Signed-off-by: Eric Blake >> >> --- >> v6: new patch >> +++ b/scripts/qapi-types.py >> @@ -233,6 +233,9 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):= >> self.decl =3D self._btin + self.decl >> self._btin =3D None >> >> + def visit_predicate(self, entity): >> + return not isinstance(entity, QAPISchemaObjectType) or entity= =2Einfo >> + >=20 > This is the faithful translation. But the left hand side is superfluou= s > because non-types laways have info, isn't it? Not yet. 3/12 adds info to arrays, but even then, intList still has info of None. And 4/12 adds info to implicit enums. Without the left half, we choke hard for any implicit UnionKind enum type being omitted as implicit. However, I do think you're on to something - the only time name[0] =3D=3D= ':' is for objects (implicit enums are NameKind, but since we don't have anonymous unions, we won't have an enum starting with :; likewise, arrays are NameList, but you can only have an array of a named type). So if I hoist is_implicit() to the QAPISchemaEntity level, then it should only ever return True for an object, and while _this_ patch has to keep the left side, patch 2 gets the shorter conditional. >> @@ -1304,10 +1307,10 @@ class QAPISchema(object): >> ent.check(self) >> >> def visit(self, visitor): >> - ignore =3D visitor.visit_begin(self) >> - for name in sorted(self._entity_dict.keys()): >> - if not ignore or not isinstance(self._entity_dict[name], = ignore): >> - self._entity_dict[name].visit(visitor) >> + visitor.visit_begin(self) >> + for (name, entity) in sorted(self._entity_dict.items()): >> + if visitor.visit_predicate(entity): >> + entity.visit(visitor) >> visitor.visit_end() >=20 > Much nicer than my ad hoc hackery! >=20 Yeah, I like how it turned out. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --Hj6fD6Ckdooxv0qPEcKTmOCOwq3nrfp1P 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/ iQEcBAEBCAAGBQJWDnW6AAoJEKeha0olJ0Nq2kQIAIARg5xdQGnkvja27cpFFOuX XTTGpjszzjzO9bqfOywwaOBnqhkWg5/ffzDi57ZA47KAEKyfcHQ4UyyEcIR86bWz +kbTjwRa8b5pLCYOm5teu/Wzvy3FgvMfpspkpyylSveaFMs/3EjvpRtrczHdGKzA GMomwynq8B2F1bbXrU9p1KtuWIXrTKo3zPvIeapQSI/yiKYMAHzCkul5CBeBDkvL 3nLD3rDNKFSg1k/I9qWmFguadebdb/JWXwuVSMFFOM3gJ5qAq6f/wMEXQ+emZSpI d4p/zi9gAO6rkzkOAdKwCife09jNoPNM3psLig3qVkLiEupfEavhjGafCcrzdQM= =NS4m -----END PGP SIGNATURE----- --Hj6fD6Ckdooxv0qPEcKTmOCOwq3nrfp1P--