From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHgNP-0005tf-9z for qemu-devel@nongnu.org; Tue, 21 Jul 2015 18:51:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZHgNL-00054g-8d for qemu-devel@nongnu.org; Tue, 21 Jul 2015 18:51:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44056) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZHgNL-00054b-0i for qemu-devel@nongnu.org; Tue, 21 Jul 2015 18:51:03 -0400 References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-26-git-send-email-armbru@redhat.com> From: Eric Blake Message-ID: <55AECCD0.6020907@redhat.com> Date: Tue, 21 Jul 2015 16:50:56 -0600 MIME-Version: 1.0 In-Reply-To: <1435782155-31412-26-git-send-email-armbru@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="L1MhbS6mjjLT3b77NqjVWm7eNQTe9dG4Q" Subject: Re: [Qemu-devel] [PATCH RFC v2 25/47] qapi: Make generators work on sorted schema expressions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: kwolf@redhat.com, berto@igalia.com, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --L1MhbS6mjjLT3b77NqjVWm7eNQTe9dG4Q Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/01/2015 02:22 PM, Markus Armbruster wrote: > Order of expressions doesn't matter. QAPISchema().get_exprs() returns > expressions in the order they're parsed. >=20 > I'm going to refactor this code. To check refactorings, I want to > diff the generated code, and for that I need to preserve its order. >=20 > Since I don't feel like preserving parse order, I'm changing > get_expr() to return the expressions sorted by name. This order will > be trivial to preserve. It also makes the generated code slightly > easier to navigate. Huge change to the generated files, but that's to be expected. Diffstat shows it is not a straight 1:1 reshuffle: qapi-event.c | 890 +-- qapi-event.h | 190 qapi-types.c | 1996 +++---- qapi-types.h | 5420 ++++++++++---------- qapi-visit.c | 9088 +++++++++++++++++----------------- qapi-visit.h | 746 +- qga/qapi-generated/qga-qapi-types.c | 148 qga/qapi-generated/qga-qapi-types.h | 340 - qga/qapi-generated/qga-qapi-visit.c | 446 - qga/qapi-generated/qga-qapi-visit.h | 54 qga/qapi-generated/qga-qmp-commands.h | 38 qga/qapi-generated/qga-qmp-marshal.c | 864 +-- qmp-commands.h | 376 - 13 files changed, 10308 insertions(+), 10288 deletions(-) but that's probably because you now emit forward declarations for things that occur alphabetically after their first use (since 8/47 in this series touched forward declarations), whereas before they happened to occurr in topological order from the parse. >=20 > Signed-off-by: Markus Armbruster > --- > scripts/qapi.py | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) >=20 > diff --git a/scripts/qapi.py b/scripts/qapi.py > index cac7ab5..20ffdaf 100644 > --- a/scripts/qapi.py > +++ b/scripts/qapi.py > @@ -1017,7 +1017,14 @@ class QAPISchema(object): > self.check() > =20 > def get_exprs(self): > - return [expr_elem['expr'] for expr_elem in self.exprs] > + def expr_name(expr): > + name =3D expr.get('enum') or expr.get('union') \ > + or expr.get('alternate') or expr.get('struct') \ > + or expr.get('command') or expr.get('event') > + assert name > + return name When I was working on this file earlier, I half toyed with the idea of adding expr_elem['name'] holding the entity name, and expr_elem['meta'] holding what meta-type the entity represents; it might have made some of our later 6-way switches simpler. But with your hierarchy of actual objects, I'm not sure my idea helps any more. > + return sorted([expr_elem['expr'] for expr_elem in self.exprs],= > + key=3Dexpr_name) Python has some nice compact syntactical gems - I'd hate the amount of boilerplate required to write this same filter using straight C code :) Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --L1MhbS6mjjLT3b77NqjVWm7eNQTe9dG4Q 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/ iQEcBAEBCAAGBQJVrszQAAoJEKeha0olJ0NqX1QH/Ak6b0rFu0O74sOALOfJr/KK CDnGJD0Hahc+0G74HtFWKenx2h3shQLRDJc2LuVG4pHAQvuAdA2F/8xWgNScQgOP 5LtEP4SBDBDvR1QV3o8YewTGZFrN+0d8BYmcD84jg0yjXMgL4pBbeuzuJ5YINAxp xoaiURibDXK0sGYw5aATl1GId9NL+fl6LCFmfvt+6ger9cxSbJj3tUHG+zqTCnC9 bhmC9gjluU8aKyP41VNdTdDbjSG+Bhe5CTNlkZtWqGaNrbXlsnftmliuSs0OikOa luFyuNpZUdPXPUmunyFU968VAGh2w1lItUoptgJ6bEhoq0oKfm3L6DeH9bB6s84= =6dyh -----END PGP SIGNATURE----- --L1MhbS6mjjLT3b77NqjVWm7eNQTe9dG4Q--