<div dir="ltr"><div>You do realize that to do this, you'd have to basically build a full parser that understand the C-code, and can analyze and reason about the code's flow, and then rebuild the same flow using the state-machine you want. It has to manage things like `break;`, `goto` and `continue` in the loops. It's really simple to do for the case you proposed, by try to do it for a a REAL piece of code that actually does something more complex than produce a constant of 5050 in `s` (your first example will compile to "nothing" if you don't add a something that uses `s`, and if you add `printf("%d\n", s);`, it will calculate 5050 as a compile-time constant, because clang understands "calculate the sum of all numbers from 1..n and performas n*(n-1)/2 as a constant calculation - even if you use a unknown value to the compiler, it just does that simple math).<br><br></div><div>And for C++ with scoping and destruction, you'd also have to deal with keeping track of the life-time of variables with non-trivial constructor/destructors (such as `std::lock`)<br></div><div><br>--<br></div>Mats<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 19 November 2016 at 07:01, John Tan 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div id="m_3337213533580898753divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif" dir="ltr">
<p>A example what i want to achieve, but i'm stucked. </p>
<p><br>
</p>
<p>Any help would be appreciated.</p>
</div>
</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>