[nem-en] Re: += Macro and delegates

Kamil Skalski kamil.skalski at gmail.com
Fri Dec 8 23:31:41 CET 2006


>
> Well, but I guess this is just a sketch. And the problem is that it depends on
> a particular way "+=" is implemented today. One day optimizer may eliminate
> unnecessary caching and this pattern won't work anymore.

Yes, I agree. But you will probably get into many points where TExpr
does not very closely relate to the original code and might have some
changes in structure...

> > I would do:
> >
> > CodeAttachEventStatement (
> >       CodeEventReferenceExpression  (
> >           texpr_to_codeexpr (t1),
> >          m1.Name.Substring (4)
> >       ),
> >       texpr_to_codeexpr (listener)
> > )
>
> Something like that but this will require a sort of pattern matching on
> 'expanded' like you wrote above.

It is also not a very "stable" and elegant solution, but maybe just
Walk the TExpr in search for parts with the same location as $e and
$method?
Then you could then check the Type of those expressions and also
search the add method call.

(see  public Walk (f : TExpr -> TExpr) : TExpr in
http://nemerle.org/svn/nemerle/trunk/ncc/typing/TypedTree.n)

This topic is very close to the questions raised several times by Vlad
and IT... And I'm still getting closer to the conclusion that Location
is the best way to map TExpr into original PExpr (assuming you have
the parse-tree at hand).

>
> What I'm looking for is an easy way to perform PExpr -> TExpr conversion for
> these relatively easy expressions for e and method given some context.

Sure, it is  Typer's method TypeExpr, but... this will not give you
the correct results, as for +=, especially with event handler
addition, it is crucial to perform typing of whole expression , not
just $e and $method parts alone. This is because of overloading:
$e might resolve to something different if used in $e += $method, than
e.g   bar ($e)

So, my opinion is that if you want to perform the correct
transformation to CodeDom, which has many "strong typed" parts in it,
you need to analyze the original TExpr.
As we do not have special nodes for much of the constructs
distinguished by CodeDom, you will need to guess :(

>
>
> P.S. I see discussing such a subject in forum isn't interactive enough. Do you
> mind if I contact you by Jabber/IRC/ICQ ?
>

Sure, my gtalk/jabber is the same as my current email.

-- 
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list