[cfe-users] Reading and Attaching Comments to CLANG AST

Bewoayia Kebianyor via cfe-users cfe-users at lists.llvm.org
Wed Feb 28 05:35:57 PST 2018


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
 



More information about the cfe-users mailing list