[cfe-dev] Custom C++ extension

Philip Reames listmail at philipreames.com
Wed Jun 17 10:15:36 PDT 2015


On 06/15/2015 06:48 AM, Jonathan Roelofs wrote:
>
>
> On 6/13/15 7:53 PM, rzaghi at mosaic3dx.com wrote:
>>
>> As an example, the extension would allow us to "tag" some identifiers
>> in the code as follows:
>>
>> class CLXYZ { public: int <tag1> x; };
>>
>> The identifier tagged as such is later picked at one of the phases
>> and operated on.
>
> For this particular example, have you considered using __attribute__ 
> syntax [1], [2]?
>
> i.e. something like:
>
>   class CLXYZ { public: int x __attribute__((tag("1"))); };
>
> If you're able to leverage existing infrastructure, that will
> significantly reduce your patch burden and make following trunk _much_ 
> easier.
You've already responded that you don't like the syntax, but I'd 
strongly suggest considering attributes as an implementation mechanism.  
If you can reduce your patches to a custom bit of parsing which adds an 
attribute to the appropriate AST nodes and then phrase everything in 
terms of attributes, your merging/support is going to be much easier.  
It also gives you the possibility of pushing bug fixes and small 
extensions to the attribute mechanism upstream with standalone test cases.

I played with an extension a while back for supporting pre and post 
conditions on methods + object invariants.  I went through a couple of 
designs before setting on a "syntactic sugar" + "attributes" design and 
that really was the simplest to maintain.  (Mind you, this was strictly 
a hobby project so I wasn't that worried about perfection in the syntax 
or semantic analysis.)
>
>>
>> (ps, not so related to my question but we call this
>> "tagged-programming" paradigm. Actually we hope that the combination
>> of these extensions can eventually help programmers in scenarios as
>> the very question I am asking above!).
>
> How so?
>
>
> Cheers,
>
> Jon
>
>
> 1: 
> https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Variable-Attributes.html#Variable-Attributes
>
> 2: 
> http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute
>
>>
>>
>>
>> _______________________________________________ cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>




More information about the cfe-dev mailing list