[cfe-dev] LibTooling: Source Annotations

Fabian Schlebusch via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 19 03:27:13 PDT 2018


Hello all,

we are encountering a very similar problem to what has been described in 
this posting: http://lists.llvm.org/pipermail/cfe-dev/2017-April/053487.html

What we need is a "comment AST Node" at the correct location in the AST 
which can hold information (i.e., a string). For example this code:

foo();
#pragma comment (user, "Begin Section1")
bar();
#pragma comment (user, "End Section1")

should translate to this AST subtree:

- CallExpr(foo)
- PragmaCommentDecl("Begin Section1")
- CallExpr(bar)
- PragmaCommentDecl("End Section1")

However, as described in the posting linked above, the PragmaCommentDecl 
is always a direct child of the TranslationUnitDecl, meaning that its 
location in the AST does not reflect its location in the source code. 
The main concern with javadoc style C comments is, that they are only 
generated in the AST when they are attached to declarations. Therefore, 
none of the two are really suitable for the task at hand.

Are there any other ways, we did not discover yet? If you encountered 
this problem as well: how did you solve it? Thanks in advance.


Best Regards

Fabian





More information about the cfe-dev mailing list