From: Xinliang David Li <davidxl@google.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Lawrence Crowl <crowl@googlers.com>,
Eric Botcazou <ebotcazou@adacore.com>,
gcc-patches@gcc.gnu.org, Jan Hubicka <hubicka@ucw.cz>,
Diego Novillo <dnovillo@google.com>
Subject: Re: Use conditional casting with symtab_node
Date: Fri, 12 Oct 2012 19:43:00 -0000 [thread overview]
Message-ID: <CAAkRFZL+1Srnu5SSA2XvX0TsG=dRtiUiN+-ytyMtkan6kHYe3A@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc1PaPgAADAVWwA1gwnOe7XysmJkuBHarnQy3_hgQ-yyDQ@mail.gmail.com>
On Fri, Oct 12, 2012 at 1:22 AM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Thu, Oct 11, 2012 at 10:39 PM, Xinliang David Li <davidxl@google.com> wrote:
>> On Thu, Oct 11, 2012 at 1:23 PM, Lawrence Crowl <crowl@googlers.com> wrote:
>>> On 10/10/12, Xinliang David Li <davidxl@google.com> wrote:
>>>> In a different thread, I proposed the following alternative to 'try_xxx':
>>>>
>>>> template<typename T> T* symbol::cast_to(symbol* p) {
>>>> if (p->is<T>())
>>>> return static_cast<T*>(p);
>>>> return 0;
>>>> }
>>>>
>>>> cast:
>>>>
>>>> template<typename T> T& symbol:as(symbol* p) {
>>>> assert(p->is<T>())
>>>> return static_cast<T&>(*p);
>>>>
>>>> }
>>>
>>> My concern here was never the technical feasibility, nor the
>>> desirability of having the facility for generic code, but the amount
>>> of the amount of typing in non-generic contexts. That is
>>>
>>> if (cgraph_node *q = p->try_function ())
>>>
>>> versus
>>>
>>> if (cgraph_node *q = p->cast_to <cgraph_node *> ())
>>>
>>> I thought the latter would generate objections. Does anyone object
>>> to the extra typing?
>>>
>>> If not, I can make that change.
>>
>> Think about a more complex class hierarchy and interface consistency.
>> I believe you don't want this:
>>
>> tree::try_decl () { .. }
>> tree::try_ssa_name () { ..}
>> tree::try_type() {...}
>> tree::try_int_const () {..}
>> tree::try_exp () { ...}
>> ..
>>
>> Rather one (or two with the const_cast version).
>>
>> template <T> T *tree::cast_to ()
>> {
>> if (kind_ == kind_traits<T>::value)
>> return static_cast<T*> (this);
>>
>> return 0;
>> }
>
> I also think that instead of
>
>>> if (cgraph_node *q = p->cast_to <cgraph_node *> ())
>
> we want
>
> if ((q = cast_to <cgraph_node *> (p))
>
> I see absolutely no good reason to make cast_to a member, given
> that the language has static_cast, const_cast and stuff. cast_to
> would simply be our equivalent to dynamic_cast within our OO model.
>
> Then I'd call it *_cast instead of cast_*, so, why not gcc_cast < >?
> Or dyn_cast <> (). That way
>
> if ((q = dyn_cast <function *> (p))
>
> would be how to use it. Small enough, compared to
>
> if ((q = p->try_function ()))
>
> and a lot more familiar to folks knowing C++ (and probably doesn't make
> a difference to others).
>
> Thus, please re-use or follow existing concepts.
Agree. dyn_cast<..> for try casting, and cast<..> or gcc_cast<..>
casting with assertion sounds good.
>
> As for the example with tree we'd then have
>
> if ((q = dyn_cast <INTEGER_CST> (p)))
>
> if we can overload on the template parameter kind (can we? typename vs. enum?)
> or use tree_cast <> (no I don't want dyn_cast <tree_common> all around the
> code).
yes, that also sounds good to me.
thanks,
David
>
> Thanks,
> Richard.
>
>>
>> thanks,
>>
>> David
>>
>>
>>>
>>> --
>>> Lawrence Crowl
next prev parent reply other threads:[~2012-10-12 19:22 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-18 18:02 Lawrence Crowl
2012-09-18 18:09 ` Eric Botcazou
2012-09-18 18:37 ` Lawrence Crowl
2012-09-19 7:31 ` Eric Botcazou
2012-09-19 9:17 ` Richard Guenther
2012-09-19 12:19 ` Gabriel Dos Reis
2012-09-19 19:04 ` Lawrence Crowl
2012-09-19 21:28 ` Gabriel Dos Reis
2012-09-19 22:03 ` Lawrence Crowl
2012-10-11 5:31 ` Xinliang David Li
2012-09-20 13:25 ` Michael Matz
2012-10-11 5:22 ` Xinliang David Li
2012-10-11 20:26 ` Lawrence Crowl
2012-10-11 20:41 ` Xinliang David Li
2012-10-12 8:24 ` Richard Biener
2012-10-12 19:43 ` Xinliang David Li [this message]
2012-10-13 17:56 ` Lawrence Crowl
2012-10-13 18:04 ` Gabriel Dos Reis
2012-10-14 17:08 ` Diego Novillo
2012-09-19 18:39 ` Lawrence Crowl
2012-09-20 13:26 ` Michael Matz
2012-09-20 20:01 ` Lawrence Crowl
2012-09-20 22:02 ` Gabriel Dos Reis
2012-09-20 22:06 ` Lawrence Crowl
2012-09-18 19:57 ` Richard Guenther
2012-09-18 20:32 ` Lawrence Crowl
2012-09-22 6:07 ` Lawrence Crowl
2012-09-25 21:25 ` Lawrence Crowl
2012-10-03 0:32 ` Lawrence Crowl
2012-10-03 12:07 ` Martin Jambor
2012-10-03 16:53 ` Lawrence Crowl
2012-10-04 8:00 ` Richard Guenther
2012-10-04 18:14 ` Lawrence Crowl
2012-10-04 18:17 ` Diego Novillo
2012-10-05 8:50 ` Richard Guenther
2012-10-05 9:52 ` Jan Hubicka
2012-10-10 0:58 ` Lawrence Crowl
2012-10-10 23:46 ` Diego Novillo
2012-10-05 10:50 ` Nathan Froyd
2012-10-05 11:05 ` Richard Guenther
2012-10-05 12:44 ` Diego Novillo
2012-10-05 13:58 ` Steven Bosscher
2012-10-05 14:07 ` Steven Bosscher
2012-10-05 21:50 ` Lawrence Crowl
2012-10-05 22:04 ` Steven Bosscher
2012-10-11 6:49 ` Xinliang David Li
2012-10-11 13:11 ` Richard Biener
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='CAAkRFZL+1Srnu5SSA2XvX0TsG=dRtiUiN+-ytyMtkan6kHYe3A@mail.gmail.com' \
--to=davidxl@google.com \
--cc=crowl@googlers.com \
--cc=dnovillo@google.com \
--cc=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=richard.guenther@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).