Proposal: user defined attributes
Steven Schveighoffer
schveiguy at yahoo.com
Wed Mar 21 14:32:05 PDT 2012
On Wed, 21 Mar 2012 17:10:06 -0400, Jacob Carlborg <doob at me.com> wrote:
> On 2012-03-21 19:32, Steven Schveighoffer wrote:
>
>> In my proposal, I specified that the annotation can be applied only to
>> module-level functions (normal or templated), and the result of those
>> functions is what gets saved. So with that capability, you should be
>> able to store any CTFE-evaluatable struct:
>>
>> @annotation auto makeAPoint() {Point2d p; return p;}
>>
>> @makeAPoint int x;
>
> Does "@makeAPoint int x;" expand to "Point2d p; return p;"?
What I envision is that @makeAPoint translates to the CTFE engine calling
makeAPoint with no arguments. This returns a Point2d default
initialized. That result is stored in the TypeInfo (or ModuleInfo) in the
appropriate location for the 'x' member.
Then you can query this using runtime or compile-time functions later on,
using the name "makeAPoint".
So in effect, you can use any struct or type that can be constructed at
compile-time. But it allows you to specify which types (and in which ways
they can be constructed) can be used as annotations. It also allows you
to name the way that type is used.
It also could give you a way to use the same type for different
annotations, discernible by name.
-Steve
More information about the Digitalmars-d
mailing list