[cfe-dev] Options for tagging function in source

Sebastian Dreßler dressler at zib.de
Fri May 18 06:47:55 PDT 2012


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/



More information about the cfe-dev mailing list