From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57534 invoked by alias); 10 Jan 2019 16:45:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 57524 invoked by uid 89); 10 Jan 2019 16:45:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=inf, Though, braces, naming X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Jan 2019 16:45:49 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B2878AE6E; Thu, 10 Jan 2019 16:45:48 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3275717CE6; Thu, 10 Jan 2019 16:45:47 +0000 (UTC) Subject: Re: [PATCH 00/12] Remove some ALL_* iteration macros To: Tom Tromey , Simon Marchi References: <20181125165439.13773-1-tom@tromey.com> <4406ff6a-975d-0db7-747c-27c7edda8bdb@simark.ca> <87y381v2iu.fsf@tromey.com> <87h8el1raa.fsf@tromey.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <1565370d-7094-ab55-26ea-b4efa92ac139@redhat.com> Date: Thu, 10 Jan 2019 16:45:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <87h8el1raa.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-01/txt/msg00216.txt.bz2 On 01/06/2019 08:10 PM, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi writes: > > Simon> I think what you did is easy to read, since it's pretty > Simon> straightforward. We could always make an exception for these > Simon> constructs, but it would probably end up being confusing to understand > Simon> and explain when you can omit the braces and when you can't. > > [...] > > Simon> And let's say that all_compunits (program_space *) returns tuples of > Simon> , we'll be able to use structured > Simon> bindings when we switch to C++17 :). Something like: > > Simon> for (const auto &[objfile, compunit] : all_compunits (pspace)) > > I gave this a brief try. I wrote a "nested" iterator to make this > generic and then converted all_compunits. > > With the nested iterator, one needs to write: > > for (auto blah : all_compunits ()) > { > compunit_symtab *s = blah.second; > > This looked ugly to me. Yeah. Though, I think that if we took this route, then all_compunits () could still return just a compunit pointer, not two things: compunit_symtab *all_compunits () because you can always get the objfile pointer from compunit_symtab::objfile. > > > Alternatively, we'd have to write a "second-selecting" wrapper iterator. > I didn't implement it but I suppose it would look like: > > for (compunit_symtab *s : second_adapter ()) > ... > > This seemed a bit obscure to me, though. Definitely. > > In the end I think I prefer the explicit route. It does need more > indentation (I will add the missing braces), but the explicitness seems > good. To me, there doesn't seem to be a strong reason to prefer the > shorter formulations; and the new iterators and adapters that would be > needed are just a bunch more code to try to track through. > > Let me know what you think about this. If you like the second_adapter > approach, I can implement that. Me, I don't. BTW, in > +/* A range adapter that makes it possible to iterate over all > + compunits in one objfile. */ > + > +class objfile_compunits : public next_adapter > +{ > +public: > in the threads/inferiors iterators I named the range types xxx_range and then added methods to return the range instead of calling the ctor directly. In this case, it'd be the equivalent of naming the class above class objfile_compunits_range : public next_adapter { and then adding a method to objfile::compunits() method like: objfile_compunits_range compunits () { return objfile_compunits_range (this); } Then the client code would look like: > - ALL_OBJFILE_COMPUNITS (objfile, cust) > + for (struct compunit_symtab *cust : objfile->compunits ()) Instead of: > - ALL_OBJFILE_COMPUNITS (objfile, cust) > + for (struct compunit_symtab *cust : objfile_compunits (objfile)) At the time, I thought that read better on the client side. I.e., we have: inf->threads () instead of: inf_threads (inf) OOC, did you consider following that, and decided again? No need to redo the series or anything, I'm just curious, since I would have taken a different choice. Thanks, Pedro Alves