[cfe-dev] A documentation tool based on clang AST.
Dmitri Gribenko
gribozavr at gmail.com
Tue Sep 10 14:44:20 PDT 2013
On Tue, Sep 10, 2013 at 1:34 AM, Juan Jose Lopez Villarejo
<jj.lopezvillarejo at cern.ch> wrote:
> Consider a (doxygen-like) comment such as "///action 2".
> We have to associate somehow this comment with the compound statement inside
> the if statement in the AST. The problem is that clang won't store in
> general that information. Only some comments before certain declarations /
> statements get properly stored in the AST.
Take a look at ASTContext::getRawCommentForDeclNoCache(). Given a
Decl, it gets its source location and does a binary search over all
comments in the translation unit, trying to find the last comment that
is before the given source location. After that, it checks if there
are any other decls between the comment and the decl source location.
If there are no other decls -- then the comment is attached to the
decl. All other functions that call getRawCommentForDeclNoCache()
implement the cache. The main entry point (the function that users
should call) is getCommentForDecl().
In your case, a similar strategy is applicable for statements.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the cfe-dev
mailing list