[cfe-dev] Options for tagging function in source
Sebastian Dreßler
dressler at zib.de
Fri May 18 07:26:11 PDT 2012
Hi Jordy,
thanks. This works as expected.
Cheers,
Sebastian
On 05/18/2012 04:04 PM, Jordy Rose wrote:
> Hi, Sebastian. I'd suggest using the [[annotate]] attribute, then checking each declaration afterwards to see if it has the tag. That requires no changes to the existing code, just an ASTConsumer in your plugin.
>
> void test(int) __attribute__((annotate("NameOfTag")));
>
> Best,
> Jordy
>
>
> On May 18, 2012, at 9:47, Sebastian Dreßler wrote:
>
>> Hi,
>>
>> I'm investigating possible solutions for tagging one or more functions
>> of interest within C / C++ source code. By using clang I'd like to get
>> the name of the tagged function. I "only" have two requirements:
>>
>> - Not much more code required for tagging (best case is a one-liner)
>> - Implementation should be a clang plugin
>>
>> So far there are three ideas how to achieve this:
>>
>> 1. Use #pragma tag<NameOfTag>. This would be the preferred solution,
>> but as far as I have seen clang does not support #pragma plugins. Or is
>> this information wrong and plugins for pragmas can be done somewhow?
>>
>> 2. Use __attribute__. Here I'm not sure whether, e.g.
>>
>> void foo(args) __attribute__((tag<NameOfTag>))
>>
>> is usable within clang, since I wasn't able to implement this for
>> instance by using hasAttr() within a ASTConsumer, the return value is
>> always false.
>>
>> 3. Use a label, e.g. tag_<NameOfTag>:. Right now this is the solution
>> I'm using, but here I have to ensure that no one re-uses this label
>> which is rather hard to achieve, although I assume that no one uses
>> labels within C / C++ these days, but you never know.
>>
>> So, maybe I'm missing something (or my assumptions are wrong) and it
>> would be nice to get some feedback regarding this.
>>
>>
>> Thanks,
>> Sebastian
>>
>>
>> --
>> Mit freundlichen Grüßen / Kind regards
>>
>> Sebastian Dreßler
>>
>> Zuse Institute Berlin (ZIB)
>> Takustraße 7
>> D-14195 Berlin-Dahlem
>> Germany
>>
>> dressler at zib.de
>> Phone: +49 30 84185-261
>>
>> http://www.zib.de/
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
--
Mit freundlichen Grüßen / Kind regards
Sebastian Dreßler
Zuse Institute Berlin (ZIB)
Takustraße 7
D-14195 Berlin-Dahlem
Germany
dressler at zib.de
Phone: +49 30 84185-261
http://www.zib.de/
More information about the cfe-dev
mailing list