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

Kamil Skalski kamil.skalski at gmail.com
Fri Dec 8 21:07:18 CET 2006


Ok, I guess you would like to use existing transformation function you
are writing, which performs
TExpr -> CodeDomExpression

We need to create following codedom structure:

CodeAttachEventStatement (
       CodeEventReferenceExpression  (
           CodeExpression targetObject,
   	   string eventName
       )
       CodeExpression listener
)

So assuming we have
TExpr.DefValIn (LocalVal ("_N_cached"), TExpr  (this.button1) as t1,
   TExpr.Call (TExpr.MethodRef (TExpr  (_N_cached), IMethod (add_Click)  as m1),
       [  TExpr (System.EventHandler(this.button1_Click)) as listener ] )

I would do:

CodeAttachEventStatement (
       CodeEventReferenceExpression  (
           texpr_to_codeexpr (t1),
   	   m1.Name.Substring (4)
       ),
       texpr_to_codeexpr (listener)
)


If you prefer to operate on PExpr, then you should fetch method's name
just like before, but
use  pexpr_to_codeexpr  on respectively  $e and $method

Hope this helps. :)


On 12/8/06, Andrey Khropov <andrey.khropov at gmail.com> wrote:
> Kamil Skalski wrote:
>
> > I thought you are transforming TExpr into CodeDom tree? Why do you
> > need to generate TExprs from those expressions?
>
> Yes. But in TExpr.MacroEnvelope original is PExpr. I can't use expanded because
> Form designer doesn't understand what it does:
> ----------------------------------------------------------------
> mutable _N_cached_obj4611 = this.button1;
> _N_cached_obj4611.add_Click(System.EventHandler(this.button1_Click));
> ----------------------------------------------------------------
>
> It needs CodeDom.CodeAttachEventStatement. That's why I need to somehow create
> typed e and method from their PExpr representations:
> -------------------------------------
> match (original) {
>  | <[ $e += $method ]> =>
>         CreateCodeAttachEventStatement(e,method)
> }
> ...
>
> CreateCodeAttachEventStatement(e:PExpr, method:PExpr) : CodeAttachEventStatement
> {
>         ?
> }
> -------------------------------------
>
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>


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



More information about the devel-en mailing list