digitalmars.D - Use UDAs for GDC attributes
- jerro (27/27) Feb 27 2013 I think it would be a good idea to replace GDC's pragma attribute
- Jacob Carlborg (4/30) Feb 27 2013 I think someone has already suggested this.
- jerro (2/3) Feb 27 2013 Sure, Iain has some time ago. Now I have an implementation and he
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.
Feb 27 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
Feb 27 2013
I think someone has already suggested this.Sure, Iain has some time ago. Now I have an implementation and he told me to post it here for feedback.
Feb 27 2013