[cfe-dev] How to detect all return statements by Clang Libtooling?

Manuel Klimek klimek at google.com
Fri Feb 7 00:27:35 PST 2014


On Fri, Feb 7, 2014 at 1:37 AM, M. J. Cho <happybrown at naver.com> wrote:

> Wow!
>
>
>
> Thanks Klimek! It works. (Your insight is definitely correct.)
>
>
>
> Can I ask an another question?
>
>
>
> When I set all includes paths completely, all return statements could be
> detected.
>
>
>
> However, so many functions are detected due to included header files.
>
>
>
> If I want to detect only functions in a target source file, what should I
> do?
>

What I do is match on all nodes, and then filter the results based on the
SourceLocation afterwards...


>
>
> Thanks
>
>
>
> *From:* Manuel Klimek [mailto:klimek at google.com]
> *Sent:* Friday, February 07, 2014 12:17 AM
> *To:* 조명진
> *Cc:* clang-dev Developers
> *Subject:* Re: [cfe-dev] How to detect all return statements by Clang
> Libtooling?
>
>
>
> On Thu, Feb 6, 2014 at 8:49 AM, 조명진 <happybrown at naver.com> wrote:
>
> Hi all,
>
>
>
> I’m trying to use clang libtooling for detecting all return statements.
>
>
>
> I used the “VisitReturnStmt” function but sometimes it is not working as
> follow case.
>
>
>
> //target code
>
> class ExampleFrontendAction : public ASTFrontendAction {
>
> public:
>
>     virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, StringRef
> file) {
>
>         return new ExampleASTConsumer(&CI); // pass CI pointer to
> ASTConsumer
>
>     }
>
> };
>
> //target code end
>
>
>
> //results
>
> CXXMethodDecl 0x2468cb0 </project/llvm/Debug+Asserts/bin/a.cpp:107:5,
> line:115:5> CreateASTConsumer 'int *(int &, int)'
>
> |-ParmVarDecl 0x2468b60 <line:107:44, col:62> CI 'int &' invalid
>
> |-ParmVarDecl 0x2468bd0 <col:66, col:76> file 'int' invalid
>
> `-CompoundStmt 0x2469138 <col:82, line:115:5> invalid
>
>
>
> As you can see, we cannot find any ReturnStmt. (It is included in
> CompoundStmt. Also the CompoundStmt is a leaf statement.)
>
>
>
> How can I detect this case? Please help me!
>
>
>
> Thanks in advance.
>
>
>
> Additional Question.
>
> Why does clang return “int *” instead of “ASTConsumer *” in the case of
> CreateASTConsumer method when I use getReturnType() in VisitFunctionDecl()?
>
>
>
> My guess is that the headers are not correctly found; are you sure you're
> using a compilation database that works?
>
>
>
>
>
> Any ideas?
>
>
>
> Brown.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140207/36af8f6f/attachment.html>


More information about the cfe-dev mailing list