[cfe-dev] A documentation tool based on clang AST.
Juan Jose Lopez Villarejo
jj.lopezvillarejo at cern.ch
Wed Sep 11 03:51:42 PDT 2013
Hello, and thanks for the reply, Dimitri.
You give me half of a solution: as you point out, we would need to attach comments to statements.
Is there any developper that would be willing to do such an extension as you propose:
ASTContext::getRawCommentForStmtNoCache()
getCommentForStmt()
Alternatively, how feasible you see that we could implement such an extension (novel to clang, physicist) and that it be maintained?!
Regards,
Juan
________________________________________
From: Dmitri Gribenko [gribozavr at gmail.com]
Sent: 10 September 2013 23:44
To: Juan Jose Lopez Villarejo
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] A documentation tool based on clang AST.
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