Use UDAs for GDC attributes

Jacob Carlborg doob at me.com
Wed Feb 27 11:30:58 PST 2013


On 2013-02-27 12:57, jerro wrote:
> I think it would be a good idea to replace GDC's pragma attribute with
> UDAs. I I have an implementation of this at
> https://github.com/jerro/GDC/tree/uda-gcc-attributes. The API consists
> of a module named gcc.attribute that contains a function template
> attribute():
>
> auto attribute(A...)(A args) if(A.length > 0 && is(A[0] == string))
>
> This function is used like this:
>
> import gcc.attribute;
>
> @attribute("gdc_attribute_name", arg1, arg2) foo()
> {
>      ...
> }
>
> This adds an attribute gdc_attribute_name(arg, arg2) to foo and is
> equivalent to
>
> pragma(attribute, gdc_attribute_name(arg1, arg2)) foo()
> {
>      ....
> }
>
> The advantage of using UDAs for GDC attributes is that you can alias
> them or use typetuples of attributes, possibly depending on the values
> of template parameters. One possible use case is this:
>
> https://github.com/TurkeyMan/phobos/pull/3#issuecomment-11694942
>
> Using UDAs for attributes would also enable us to remove a bunch of code
> that currently deals with GDC attributes from GDC's version of the
> frontend.
>
> I'd like to hear your opinions and suggestions on this.

I think someone has already suggested this.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list