[webkit-dev] Type checking / casting helpers
Ryosuke Niwa
rniwa at webkit.org
Thu Sep 25 11:15:09 PDT 2014
Thanks Chris for taking the initiative to do this! New code looks much
more pleasant to read now.
On Thursday, September 25, 2014, Chris Dumez <cdumez at apple.com> wrote:
> Hi all,
>
> I started working on automatically generating the type *casting* helpers
> for HTML/SVG/MathML Elements (e.g. toHTMLDivElement()). Until now, we were
> generating only the type *checking* helpers using make_names.pl (e.g.
> isHTMLDivElement()). The type *casting* helpers had to be manually
> defined using NODE_TYPE_CASTS() macro.
>
> The type casting helpers are now automatically generated for most types.
> Part of the solution involved using a templated function for type casting
> because the types are forward-declared and we needed to do a
> static_cast<>() (a reinterpret_cast<>() could be used with forward
> declarations but wouldn't be safe due to multiple inheritance).
>
> I initially had macros in place so that toHTMLDivElement() would still
> work and would be equivalent to downcast<HTMLDivElement>(). The feedback I
> received is that we should get rid of these macros and just use
> is<HTMLDivElement>() / downcast<HTMLDivElement>() everywhere.
> The new style is very close to C++'s is_class<T>() and Boost's
> polymorphic_downcast<T>().
>
> I actually started updating the code to do this but I should have emailed
> webkit-dev about this beforehand. I apologize for sending this message a
> bit late.
>
> Please let me know if you have feedback / concerns / questions about this
> change. I hope that this email gives you a better understanding of why I am
> making this change.
>
> As I said before, the code base is not fully ported yet so the current
> situation is not necessarily pretty. I will try and go through the
> transition as fast as I can, provided that people don't raise any concerns
> about this.
>
> Please also note that these new helpers still catch unnecessary type
> checks / casts. As a matter of fact, those are now caught at build time
> instead of linking time and should give you a nice "Unnecessary type check"
> / "Unnecessary type cast" static assertion.
>
> Also note that the plan is to get rid of TYPE_CAST_BASE() macro entirely
> and extend is<>() / downcast<>() to all types, not just Nodes.
>
> Kr,
> --
> Chris Dumez - Apple Inc.
> Cupertino, CA
>
>
>
>
>
--
- R. Niwa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20140925/fe97ccfc/attachment.html>
More information about the webkit-dev
mailing list