Received: from eggs.gnu.org ([2001:4830:134:3::10]:39005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJyB8-00030V-F4 for qemu-devel@nongnu.org; Tue, 28 Jul 2015 02:15:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJyB5-0001VY-9o for qemu-devel@nongnu.org; Tue, 28 Jul 2015 02:15:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42574) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJyB5-0001VM-4Q for qemu-devel@nongnu.org; Tue, 28 Jul 2015 02:15:51 -0400 From: Markus Armbruster References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-8-git-send-email-armbru@redhat.com> <55AD7F18.1010205@redhat.com> <87380d4vds.fsf@blackfin.pond.sub.org> <55B6A3C8.4050006@redhat.com> Date: Tue, 28 Jul 2015 08:15:47 +0200 In-Reply-To: <55B6A3C8.4050006@redhat.com> (Eric Blake's message of "Mon, 27 Jul 2015 15:34:00 -0600") Message-ID: <87h9ooq030.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH RFC v2 07/47] qapi: Generate a nicer struct for flat unions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com Eric Blake writes: > On 07/24/2015 06:01 AM, Markus Armbruster wrote: > >>> It might be worth tweaking the generator to output a C comment either >>> here (at the start of the larger struct)... >>> >>>> char *string; >>>> EnumOne enum1; >>> >>> ...or here (at the end of the base struct) mentioning that >>> UserDefFlatUnion can be cast into its base struct UserDefUnionBase, to >>> make it easier when reading the generated code to trace back to that >>> "inheritance" relationship. Right now, there is nothing in the >>> generated UserDefFlatUnion that points you back to the qapi relationship >>> of a base class. But it's not a show-stopper if you don't like my >>> suggestion. >> >> I do like it. Perhaps something like >> >> struct UserDefFlatUnion >> { >> /* Members inherited from UserDefUnionBase: */ >> char *string; >> EnumOne enum1; >> /* Own members: */ >> ... >> }; > > What about nested types? Whatever we pick has to look good when > indirect bases are involved. Suppose we have Base -> Mid -> Derived as a > struct inheritance. If we generate a comment at both start and end of > visiting a base class (and visit base classes recursively), we'd have > something like: > > struct Derived > { > /* Members inherited from Mid */ > /* Members inherited from Base */ > int one; > /* End members inherited from Base */ > int two; > /* End members inherited from Mid */ > /* own members */ > int three; > ... > }; Documenting the direct ancestor in the code is more important than the others, because you can always peruse the direct ancestor to find the next one. > Don't know if that helps you think about it more, but now I'm just > painting a bikeshed that just adds the tail comment. Here's the > resulting RFC: > > http://thread.gmane.org/gmane.comp.emulators.qemu/353204 > > and the resulting generated structs: > > struct BlockdevOptionsQcow2 { > - BlockdevOptionsGenericCOWFormat *base; > + BlockdevRef *file; > + /* End fields inherited from BlockdevOptionsGenericFormat. */ > + bool has_backing; > + BlockdevRef *backing; > + /* End fields inherited from BlockdevOptionsGenericCOWFormat. */ > bool has_lazy_refcounts; > bool lazy_refcounts; > ... This and other followup patches are encouraging. I'll gladly review them when I can spare the cycles. Right now, I need to focus them on introspection.