[cfe-dev] add namespaces to C (in my local clang) OR "tag" a couple of functions

Jonas Gefele llvm.org at schrieb.de
Fri Oct 21 01:03:08 PDT 2011


(In my local clang copy) I would like to "tag" a bunch of C/C++
functions/globals with some additional string/attribute.

As I am not yet very experienced with hacking clang, I'd appreciate your
comment whether one of the following approaches achievable without hacking
clang too much.

Way 1
In fact, C++ namespaces perfectly do what I want. If I could define a
"c-with-namespaces" language version which allows to write

namespace tag1 {
   void foo();
   int  bar;
namespace tag2 {
   void baz();

and where name are resolved/mangled as in C++ I'd be happy (compability
with "real world" C does not matter in my case).

Way 2
Another way that came into my mind is to define some new
__attribute__((tag("name"))). The only thing which keeps me from this (and
led me to desiring namespaces) is that I want to avoid writing

void foo() __attribute__((tag("name")));
void bar() __attribute__((tag("name")));
void baz() __attribute__((tag("name")));

but would like apply a given attribute to all declarations within a given
range. Something like:

   void bar();
   void baz();

If any one of these approaches is doable relatively easily, in which
places would I have to look? Or is there some other approach I have

Thank you very much!


More information about the cfe-dev mailing list