Is it possible to use an UDA to generate a struct inside a class ?
BBaz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 30 03:00:24 PST 2015
On Thursday, 1 January 2015 at 22:49:40 UTC, Basile Burg wrote:
> On Thursday, 1 January 2015 at 21:15:27 UTC, Ali Çehreli wrote:
>> On 01/01/2015 09:35 AM, Basile Burg wrote:
>>
>> > On Tuesday, 30 December 2014 at 19:18:41 UTC, Basile Burg
>> wrote:
>>
>> > an ICE (every
>> > compiler crash is an ICE right ?),
>>
>> Yes, the compiler should never crash but produce an error
>> message. Please report it preferably with a reduced code
>> sample:
>
> The report is filed. I was not sure of its validity or if it
> could be a dup.
>
> -----------------
>
>> You realize, all of those foreach'es are processed at
>> compile-time for code generation. There will be no 'o' at run
>> time; so its address cannot be used.
>
> Instead, Can I get the *relative offset* of a particular member
> at compile-time ?
> Then at run-time I could easily define the delegate, eg:
>
> // the AA or some arrays filled at compile-time
> ptrdiff_t[string] gettersOffset;
> ptrdiff_t[string] settersOffset;
>
> // a delegate, set at run-time, for example in this().
> myDelegate.funcptr = gettersOffset["propIdentifier"];
> myDelegate.ptr = cast(void*) this;
>
> If so then the problem is solved...even if other problems could
> appends, for example if the methods are final, if they are
> inlined...
>
> Actually I'd be surprised that nobody has already designed
> something similar for properties (kind of "published" attribute
> as defined in Pascal-like languages.)
This was the way to go (the relative-offset "thing"):
1/ __traits(getVirtualIndex,...) works at compile time
2/ then the method pointer can be constructed using vtbl
And it works, though I'm still open to another solution (since
now the get/set >>must<< be virtual)
Current implementation:
https://github.com/BBasile/Iz/blob/master/import/iz/properties.d#L383
:)
More information about the Digitalmars-d-learn
mailing list