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.
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.
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