public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Petr Machata <pmachata@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: Re: [PATCH 2/2] Add C++ iterators
Date: Thu, 16 Apr 2015 17:42:49 +0200	[thread overview]
Message-ID: <87a8y8m64m.fsf@redhat.com> (raw)
In-Reply-To: 1429196768.31971.76.camel@bordewijk.wildebeest.org

[-- Attachment #1: Type: text/plain, Size: 2638 bytes --]

Mark Wielaard <mjw@redhat.com> writes:

> But given the nice idea above of defining a "next iterator as end" for
> another. Would adding that functionality just be introducing a new
> constructor that takes a Dwarf_Die and a next_sibling () method that
> returns an iterator that one can use as above in a for loop to test
> whether one has walked a subtree?

Yes, that's how I'd do it.

> The only disadvantage of that seems to be that it would immediately
> introduce a v2 variant if we do it after a public release.

I don't even think it would.  Adding a new constructor doesn't break any
existing clients.  API-wise it would be stable as well, this adds use
cases, doesn't change any (not even by way of implicit conversions from,
say, Dwarf_Die * to unit_iterator).

As long as your iteration is limited to well-formed sub-tree (i.e. you
don't wan't to e.g. start at one leaf node and progress through half the
CU to another leaf node), the simple vector of offsets would, I think,
be still enough to keep all the context that you need.  There might be
code that assumes that iteration starts and ends at CU DIE's, but that
could be transparently fixed.

> I was thinking just doing it on the C++ level. But yes, it would be nice
> to also have that on the C level libdw interface. That was this
> discussion where you came up with a pretty nice plan:
> https://lists.fedorahosted.org/pipermail/elfutils-devel/2014-October/004204.html
>
> Again my worry is about whether retrofitting such a design into the
> current class is possible or not. Would it be as simple as adding a new
> constructor, a boolean field and using the new C functions (and updating
> the version) or would we need a whole new class/interface for it?

I'm not sure.  I don't think so, at least you would need a different way
of keeping track of context.  Personally I think adding a new iterator
that builds on the raw one is the best option.

That would mean that you couldn't pass a logical iterator to a function
that expects a raw one.  But you can't likewise pass, say, a child
iterator to such function--the genericity is just not there.  This sort
of thing would have to be achieved by making the function template.

One could also make the new iterator configurable, like Frank says in
his mail.  Then you would have a single tree iterator type that can
behave either way.

I still think exposing raw iterator is the right way forward, because it
is a logical building block.  A logical tree iterator can be built on
top of that even without C support, if that's what's deemed best.

Thanks,
Petr

             reply	other threads:[~2015-04-16 15:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-16 15:42 Petr Machata [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-04-20  9:28 Mark Wielaard
2015-04-17 16:54 Petr Machata
2015-04-16 19:23 Mark Wielaard
2015-04-16 15:06 Mark Wielaard
2015-04-16 14:07 Frank Ch. Eigler
2015-04-16 13:52 Petr Machata
2015-04-16 13:29 Mark Wielaard
2015-04-14 14:47 Petr Machata
2015-04-14 13:53 Petr Machata
2015-04-14 13:52 Petr Machata
2015-04-03 21:34 Petr Machata
2015-04-03 13:39 Petr Machata
2015-04-03 12:56 Mark Wielaard
2015-04-03 11:27 Petr Machata
2015-04-03  8:51 Petr Machata

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=87a8y8m64m.fsf@redhat.com \
    --to=pmachata@redhat.com \
    --cc=elfutils-devel@lists.fedorahosted.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).