Getting function Name from stmt and varDecl

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting function Name from stmt and varDecl

Xin Wang via cfe-dev

Hi everyone,

I want to get function name in which variable is declared and parent
function name of statement. Is it possible to get? If yes, How? Can anyone
please help me in this.

--
Thanks and Regards
Awanish Pandey
PhD, CSE
IIT Kanpur

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting function Name from stmt and varDecl

Xin Wang via cfe-dev
Off the top of my head:

From VarDecl to the FunctionDecl: `auto FD =
dyn_cast<FunctionDecl>(VarDeclVariable->getDeclContext());` //
non-null when it's declared in a FunctionDecl
From Stmt to FunctionDecl: Don't think that's possible from a generic
Stmt which doesn't hold any reference to it's parent. One way to solve
this is to walk the TU with a RecursiveASTVisitor and check in
`VisitStmt` for your Stmt and track in `VisitDecl` in which Decl you
are. Or you keep track of where you Stmt is in the first place, which
is I think the intended way of solving this.

- Raphael

2017-07-01 15:22 GMT+02:00 via cfe-dev <[hidden email]>:

>
> Hi everyone,
>
> I want to get function name in which variable is declared and parent
> function name of statement. Is it possible to get? If yes, How? Can anyone
> please help me in this.
>
> --
> Thanks and Regards
> Awanish Pandey
> PhD, CSE
> IIT Kanpur
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...