Source annotations in LibTooling

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Source annotations in LibTooling

Alex Denisov via cfe-dev
Hi all,

I've been using clang as a frontend for a while now, through libtooling, in a BMC tool. However, I've been having some hard time trying to get some annotations from the code, does anyone knows how I can do it? 

I want to be able to get the AST from a program like:

int main() 
  unsigned int i = 0;
  int a[10] = {0};

  /// bar
  #pragma comment(user, "foobar")
  a[i - 1] = 3; 

and have access to "bar", "foo" or "foobar", before or when parsing the assignment. Those are some failing attempts.

Basically, we have some other tools that do source to source transformation of C programs and we would like to add extra information to the new source, to be able to better reason about them. 

I've tried a number of things so far:

1. Use doxygen style comments: I think it's the best solution, but the AST nodes (FullComment, etc) are only generated for declarations (Maybe I'm missing a flag?).

2. Use _Pragma("x y z"): it prints a message but no new AST node is generated.

3. Use the [[attr]] syntax: C++ only and I don't think it supports custom attributes.

4. Use #pragma comment(user, "foo") + -fms-extensions: with this I'm able to generate any comment I want but the AST node (PragmaCommentDecl) is always a child of the translation unit. I know I could get the location using the source_manager but it would be a huge pain to insert it in the correct position once it's converted to our internal AST.

Does anyone else have an idea how it can be done? 

Thank you,


Mikhail Ramalho.

cfe-dev mailing list
[hidden email]