Reading and Attaching Comments to CLANG AST

Hello,

I am new to Clang, LLVM and have some questions regarding attaching comments to the clang AST. I would like to parse a C/C++ file and get preceeding comments to variable declarations and attach these to the AST. The comments are annotations of model objects in the source code. I need to get the source location for certain actions in the model based on these comments.

So far I can visit the VarDecl, statements using the ASTRecursive visitor. I have read several tutorials and searched, but could not find any straight forward way of reading the comments and attaching it to the AST node. I also noticed that the getRawCommentForDeclNoCache(VarDecl) is always null. From one of the tutorials it was mentioned that the option -fparse-all-comments must be passed to clang inorder to have non-doxygen style of comments.

Can someone please provide me with more clarification on this? Why do I always get nullptr for getRawCommentForDeclNoCache(VarDecl). Where to pass this option.

Thanks inadvance,

Bewoayia

Hi,

can anyone help in providing clarification to this query?

I am new to Clang, LLVM and have some questions regarding attaching comments to the clang AST. I would like to parse a C/C++ file and get preceeding comments to variable declarations and attach these to the AST. The comments are annotations of model objects in the source code. I need to get the source location for certain actions in the model based on these comments.

So far I can visit the VarDecl, statements using the ASTRecursive visitor. I have read several tutorials and searched, but could not find any straight forward way of reading the comments and attaching it to the AST node. I also noticed that the getRawCommentForDeclNoCache(VarDecl) is always null. From one of the tutorials it was mentioned that the option -fparse-all-comments must be passed to clang inorder to have non-doxygen style of comments.

Can someone please provide me with more clarification on this? Why do I always get nullptr for getRawCommentForDeclNoCache(VarDecl). Where to pass this option.

Thanks inadvance,

Bewoayia

-----"cfe-users" <cfe-users-bounces@lists.llvm.org> schrieb: -----

Hi Bewoayia,

I think you would have more luck asking your question at cfe-dev, in my understanding very few people read cfe-users.

George