Type parameter substitution

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Type parameter substitution

Juraj Kirchheim
Hi,

I was wondering, when given a TInst(cl, params), is there a straight
forward way to get all the fields of cl, where the type parameter
variables (as found in cl.get().params) are substituted with the
actual type parameters (as found in params)? Since the compiler
actually does this, I was wondering, whether there's a way to use this
logic from within a macro, rather than doing this by hand or by hack.

greetz
back2dos

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Type parameter substitution

Nicolas Cannasse
Le 05/11/2011 19:53, Juraj Kirchheim a écrit :
> I was wondering, when given a TInst(cl, params), is there a straight
> forward way to get all the fields of cl, where the type parameter
> variables (as found in cl.get().params) are substituted with the
> actual type parameters (as found in params)? Since the compiler
> actually does this, I was wondering, whether there's a way to use this
> logic from within a macro, rather than doing this by hand or by hack.

This is a bit complex but what about the following ?

typeof(EField(ECheckType(EConst(CIdent(null)),TInst(cl,params),"fieldName"))

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Type parameter substitution

Juraj Kirchheim
> This is a bit complex but what about the following ?
>
> typeof(EField(ECheckType(EConst(CIdent(null)),TInst(cl,params),"fieldName"))

This looks quite interesting. ECheckType is a haXe 3.0 feature, right?
What exactly does it do?
Because here it seems that the second parameter must be ComplexType:
http://code.google.com/p/haxe/source/browse/trunk/std/sys/db/SpodMacros.hx?spec=svn4015&r=4015#738,
while in this example it's Type. Is there more information on this?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Type parameter substitution

Nicolas Cannasse
Le 06/11/2011 10:58, Juraj Kirchheim a écrit :
>> This is a bit complex but what about the following ?
>>
>> typeof(EField(ECheckType(EConst(CIdent(null)),TInst(cl,params),"fieldName"))
>
> This looks quite interesting. ECheckType is a haXe 3.0 feature, right?
> What exactly does it do?

It's a macro-only AST expression that ensure that the given expression
is of the given type (and infer it with this type if it was not typed).

> Because here it seems that the second parameter must be ComplexType:
> http://code.google.com/p/haxe/source/browse/trunk/std/sys/db/SpodMacros.hx?spec=svn4015&r=4015#738,
> while in this example it's Type. Is there more information on this?

Indeed, my mistake.

In that case it might be necessary to add specific api for
type-parameters substitution. There's also per-function type parameters
as well to turn into Unknown (TMono)

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org