[cfe-dev] How to know in what CXXRecordDecl is a Stmt?
Manuel Klimek
klimek at google.com
Fri Apr 11 01:45:55 PDT 2014
On Fri, Apr 11, 2014 at 10:43 AM, victor <pedretti_86 at hotmail.com> wrote:
> Well, as I said, not necessarily - you will definitely find a
> CXXMethodDecl, but from there you have to go to its CXXRecordDecl directly,
> not via getParents(), as it might be an out-of-line definition.
>
>
> Ok, that's much clearer. I hope I can implement it without problems.
>
>
> No, you get the children directly from the AST nodes.
>
>
> Sorry if my question is too trivial, but I am not so expert using these
> libraries. I can find children in Stmt:
>
> http://clang.llvm.org/doxygen/classclang_1_1Stmt.html#a489148e5d234a5a7f00d8b02981bcee5
>
> but I couldn't find it in Decl. What is the way in this case?
>
You can go from the DeclContext:
http://clang.llvm.org/doxygen/classclang_1_1DeclContext.html
But generally, you'll want to use the AST matchers, or the
RecursiveASTVisitor if you want to traverse the ast...
>
>
> ------------------------------
> Date: Fri, 11 Apr 2014 10:02:59 +0200
>
> Subject: Re: [cfe-dev] How to know in what CXXRecordDecl is a Stmt?
> From: klimek at google.com
> To: pedretti_86 at hotmail.com
> CC: cfe-dev at cs.uiuc.edu
>
> On Fri, Apr 11, 2014 at 9:19 AM, victor <pedretti_86 at hotmail.com> wrote:
>
> Oh, thanks, I didn't know that method.
>
> Note that you'll not always end up in a CXXRecordDecl - sometimes you'll
> also end up in a method decl that is defined out-of-line.
>
> Ok, so I will go through the ParentVector and, if finding a method decl, I
> will get the CXXRecordDecl of that method with getParent() in
> CXXMethodDecl, is this right?
>
>
> Well, as I said, not necessarily - you will definitely find a
> CXXMethodDecl, but from there you have to go to its CXXRecordDecl directly,
> not via getParents(), as it might be an out-of-line definition.
>
>
> BTW, Isn't there a getChildren in ASTContext for the contrary purpose? I
> was wondering the reason.
>
>
> No, you get the children directly from the AST nodes.
>
>
>
> Thanks.
>
>
> ------------------------------
> Date: Thu, 10 Apr 2014 10:48:50 +0200
> Subject: Re: [cfe-dev] How to know in what CXXRecordDecl is a Stmt?
> From: klimek at google.com
> To: pedretti_86 at hotmail.com
> CC: cfe-dev at cs.uiuc.edu
>
>
> ASTContext (http://clang.llvm.org/doxygen/classclang_1_1ASTContext.html)
> has a getParents() method. Note that you'll not always end up in a
> CXXRecordDecl - sometimes you'll also end up in a method decl that is
> defined out-of-line.
>
>
> On Thu, Apr 10, 2014 at 9:40 AM, victor <pedretti_86 at hotmail.com> wrote:
>
> Hello,
>
> When I retrieve a Stmt in the AST, how can I know the CXXRecordDel to
> which that Stmt belongs to? I have been looking over the methods in the
> Stmt class, but I couldn't find an appropriate method to this end.
>
> Thanks in advance.
>
> _______________________________________________
> 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/20140411/5c3b1cc2/attachment.html>
More information about the cfe-dev
mailing list