[cfe-dev] Getting function Name from stmt and varDecl

Raphael Isemann via cfe-dev cfe-dev at lists.llvm.org
Sun Jul 2 01:53:15 PDT 2017


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 <cfe-dev at lists.llvm.org>:
>
> 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
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list