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.