<div dir="ltr"><div class="gmail_extra">Something like this could work:</div><div class="gmail_extra"><br></div><div class="gmail_extra">If you have a Stmt * that corresponds to the return statement in your example, you can use the `<font color="#000000">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. </font></div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_quote">On 31 July 2017 at 15:49, Marcel Schaible via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<p>Hi everyone,</p>
<p>what is the proper way to determine the surrounding block/scope
of a statement?</p>
<p>I want to insert in each branch some diagnostic code like e.g.<br>
</p>
<p><font face="Courier New, Courier, monospace">int foo(void) {</font></p>
<font face="Courier New, Courier, monospace"> </font>
<p><font face="Courier New, Courier, monospace"> if ( ...)
return 0;</font></p>
<font face="Courier New, Courier, monospace"> </font>
<p><font face="Courier New, Courier, monospace"> else {</font></p>
<font face="Courier New, Courier, monospace"> </font>
<p><font face="Courier New, Courier, monospace"> return 1;<br>
</font> </p>
<font face="Courier New, Courier, monospace"> </font>
<p><font face="Courier New, Courier, monospace"> </font> }</p>
<p>}<br>
</p>
<p>transform into:</p>
<p><font face="Courier New, Courier, monospace">int foo(void) {</font></p>
<font face="Courier New, Courier, monospace"> </font>
<p><font face="Courier New, Courier, monospace"> if ( ...) {</font></p>
<p><font face="Courier New, Courier, monospace"> somediagnostic();<br>
</font></p>
<p><font face="Courier New, Courier, monospace"> return 0;</font></p>
<p><font face="Courier New, Courier, monospace"> } else {</font></p>
<font face="Courier New, Courier, monospace"> </font>
<p><font face="Courier New, Courier, monospace"><font face="Courier
New, Courier, monospace"> somediagnostic();</font></font></p>
<p><font face="Courier New, Courier, monospace"><font face="Courier
New, Courier, monospace"></font> return 1;<br>
</font> </p>
<font face="Courier New, Courier, monospace"> </font>
<p><font face="Courier New, Courier, monospace"> </font> }</p>
<p>}<br>
</p>
<br>
<br>
Thanks<span class="gmail-HOEnZb"><font color="#888888"><br>
<br>
Marcel<br>
</font></span></div>
<br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>