From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upz51-0003KP-3c for qemu-devel@nongnu.org; Fri, 21 Jun 2013 07:00:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Upz4z-00074F-Ro for qemu-devel@nongnu.org; Fri, 21 Jun 2013 07:00:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upz4z-000743-Js for qemu-devel@nongnu.org; Fri, 21 Jun 2013 07:00:33 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5LB0ViL006562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Jun 2013 07:00:33 -0400 Date: Fri, 21 Jun 2013 13:00:24 +0200 From: Kevin Wolf Message-ID: <20130621110024.GE2986@dhcp-200-207.str.redhat.com> References: <1371659287-14331-1-git-send-email-kwolf@redhat.com> <1371659287-14331-3-git-send-email-kwolf@redhat.com> <51C42B2A.6040607@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51C42B2A.6040607@redhat.com> Subject: Re: [Qemu-devel] [PATCH 2/3] qapi.py: Allow top-level type reference for command definitions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: lcapitulino@redhat.com, Amos Kong , qemu-devel@nongnu.org, stefanha@redhat.com, armbru@redhat.com Am 21.06.2013 um 12:30 hat Eric Blake geschrieben: > On 06/19/2013 05:28 PM, Kevin Wolf wrote: > > If 'data' for a command definition isn't a dict, but a string, it is > > taken as a (struct) type name and the fields of this struct are directly > > used as parameters. > > I like it! I suspect it may cause conflicts with Amos' work on adding > introspection, but it is still worth doing. > > > > > def parse_args(typeinfo): > > + if isinstance(typeinfo, basestring): > > + struct = find_struct(typeinfo) > > + assert struct != None > > + typeinfo = struct['data'] > > + > > Does this mean that .json files must be written in topological order (in > that we can't use 'data':'Type' unless 'Type' was declared earlier in > the file)? No, you have effectively two passes: First the qapi.py function reads in the file and adds any structs, enums and unions to the respective lists and returns something like an array of all objects found. The generator scripts then filter that array for the type of objects they want (e.g. only commands, or only types) and indirectly call parse_args(). At this point all types have already been registered. > As the .json file gets larger, I've been wondering if > enforcing alphabetical ordering would make it easier to manage; but if > topological sorting is required, alphabetical sorting might not always > be possible. Yeah, possibly. Another thing I was considering is introducing include files, so that I could for example specify { 'include': 'block/qapi-schema.json' } and have all block-related things separated in this file. Kevin