How to determine the corresponding block of a statement?

Hi everyone,

what is the proper way to determine the surrounding block/scope of a statement?

I want to insert in each branch some diagnostic code like e.g.

int foo(void) {

if ( …) return 0;

else {

return 1;

}

}

transform into:

int foo(void) {

if ( …) {

somediagnostic();

return 0;

} else {

somediagnostic();

return 1;

}

}

Thanks

Marcel

Something like this could work:

If you have a Stmt * that corresponds to the return statement in your
example, you can use the `getParents()` method from `ASTContext` to get the
list of its parents. Then you can check whether the `if` has a body with
braces by iterating over the parents until you find the `if`, and checking
if the `if`s body is a CompoundStmt.