Proposal: user defined attributes

F i L witte2008 at gmail.com
Sun Mar 18 03:50:13 PDT 2012


On Sunday, 18 March 2012 at 10:38:19 UTC, Tove wrote:
> On Sunday, 18 March 2012 at 10:25:20 UTC, F i L wrote:
>> F i L wrote:
>> class CoolClass
>> {
>>    mixin Attribute!("int", "a", "Cool", "Heh");
>>    mixin Attribute!("int", "b", "Cool", "Sup");
>> }
>>
>> void main()
>> {
>>    auto c = new CoolClass();
>>    writeln(c.a, ", ", c.b); // 0, 0
>>    writeln(c.a_Cool().s); // Heh
>>    writeln(c.b_Cool().s); // Sup
>> }
>
> Is it not possible to alias a mixin to just one letter, and 
> then use it to have any syntax we want... something like this:
>
> 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.


More information about the Digitalmars-d mailing list