Proposal: user defined attributes

Tove tove at fransson.se
Sun Mar 18 04:23:24 PDT 2012


On Sunday, 18 March 2012 at 10:50:14 UTC, F i L wrote:
>> x("@attribute(Serializable.yes) int a");
>
> Sure, but there's still the issue of using attributes for 
> codegen. For instance compare:
>
>     struct Test {
>         @GC.NoScan int value;
>     }
>
> to, the current:
>
>     struct Test {
>         int value;
>         this() { GC.setAttr(&value, NO_SCAN); }
>     }
>
> How can we do that with mixin templates? If attributes where a 
> language type the compiler could exploit in a consistent way, 
> It would be *trivial* describing this behavior in a declarative 
> way.

Hmm... well if the x declarations store all NoScan objects in a 
collection, it could be injected into the constructor token 
stream later...

x!("@GC.NoScan int value;");

// modified by x to insert a foreach with GC.setAttr
x!(q{this() {/* foreach(...) GC.setAttr(...); */ });

But I guess one lose the opportunity for some compile time 
magic... in a more efficient way than exposed by the GC.settAttr 
API.(just pure speculation, I don't have sufficient knowledge of 
the internal representation of our GC design.).





More information about the Digitalmars-d mailing list