Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tom@tromey.com>, Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 00/12] Remove some ALL_* iteration macros
Date: Thu, 10 Jan 2019 16:45:00 -0000	[thread overview]
Message-ID: <1565370d-7094-ab55-26ea-b4efa92ac139@redhat.com> (raw)
In-Reply-To: <87h8el1raa.fsf@tromey.com>

On 01/06/2019 08:10 PM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> 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> <objfile *, compunit_symtab *>, 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<all_compunits> ())
>      ...
> 
> 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<struct compunit_symtab>
> +{
> +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<struct compunit_symtab>
  {

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


  parent reply	other threads:[~2019-01-10 16:45 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-25 16:54 Tom Tromey
2018-11-25 16:54 ` [PATCH 10/12] Remove ALL_OBJFILES and ALL_FILETABS Tom Tromey
2018-11-25 16:54 ` [PATCH 09/12] Remove ALL_OBJFILE_FILETABS Tom Tromey
2018-11-25 16:54 ` [PATCH 12/12] Remove ALL_OBJFILE_PSYMTABS Tom Tromey
2018-11-25 16:54 ` [PATCH 01/12] Introduce all_objfiles and next_iterator Tom Tromey
2018-11-25 16:54 ` [PATCH 03/12] Remove most uses of ALL_OBJFILES Tom Tromey
2018-11-25 16:54 ` [PATCH 05/12] Remove ALL_MSYMBOLS and ALL_OBJFILE_MSYMBOLS Tom Tromey
2018-11-25 16:54 ` [PATCH 04/12] Remove ALL_OBJFILES_SAFE Tom Tromey
2018-11-25 16:54 ` [PATCH 08/12] Remove ALL_COMPUNIT_FILETABS Tom Tromey
2018-11-25 16:54 ` [PATCH 11/12] Remove ALL_OBJSECTIONS Tom Tromey
2018-11-25 16:54 ` [PATCH 07/12] Remove ALL_COMPUNITS Tom Tromey
2018-11-25 16:55 ` [PATCH 06/12] Remove ALL_OBJFILE_COMPUNITS Tom Tromey
2018-11-25 16:55 ` [PATCH 02/12] Remove ALL_PSPACE_OBJFILES Tom Tromey
2018-12-23  7:00 ` [PATCH 00/12] Remove some ALL_* iteration macros Joel Brobecker
2018-12-24 20:54   ` Tom Tromey
2018-12-26 17:30     ` Simon Marchi
2018-12-26 22:28       ` Tom Tromey
2018-12-26 22:32         ` Tom Tromey
2018-12-26 22:35           ` Simon Marchi
2018-12-26 22:52             ` Tom Tromey
2018-12-26 23:45               ` Tom Tromey
2018-12-27  0:46                 ` Simon Marchi
2018-12-27  6:22                   ` Tom Tromey
2018-12-27  1:52 ` Simon Marchi
2019-01-03 21:46   ` Tom Tromey
2019-01-03 22:45     ` Simon Marchi
2019-01-06 20:10       ` Tom Tromey
2019-01-09 19:49         ` Simon Marchi
2019-01-10  1:29           ` Tom Tromey
2019-01-10 16:45         ` Pedro Alves [this message]
2019-01-10 18:10           ` Tom Tromey
2019-01-10 19:58             ` Pedro Alves
2019-01-10 16:44 ` Pedro Alves
2019-01-10 18:06   ` Tom Tromey
2019-01-10 18:09     ` Pedro Alves
2019-01-10 22:53       ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1565370d-7094-ab55-26ea-b4efa92ac139@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox