<br><br><div class="gmail_quote">On Wed, Jan 2, 2013 at 11:23 PM, Nikola Smiljanic <span dir="ltr"><<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I was under the impression that he's trying to verify that every case has an explicit break in order to enforce a coding standard that forbids fall-through. But I might be wrong.<br><br></blockquote><div> </div><div>I suppose so too, and I can assure you that `return` does not allow a fall-through to ensue.<br>
<br>-- Matthieu<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote">On Thu, Jan 3, 2013 at 4:36 AM, Matthieu Monrocq <span dir="ltr"><<a href="mailto:matthieu.monrocq@gmail.com" target="_blank">matthieu.monrocq@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You do realize that if someone used a "return" or a "throw" then you will miss this ?<span><font color="#888888"><br>


<br>-- Matthieu<br><br></font></span><div class="gmail_quote"><div><div>On Wed, Jan 2, 2013 at 10:15 AM, kevinlynx <span dir="ltr"><<a href="mailto:kevinlynx@gmail.com" target="_blank">kevinlynx@gmail.com</a>></span> wrote:<br>



</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>I only want to know if there's a break between two cases (or between a case and default). I dump a CastStmt AST, but not found a BreakStmt. That's why i asked for help here. <br>



<div><div><br></div><div><br></div><div style="font-size:12px;font-family:Arial Narrow;padding:2px 0 2px 0">------------------ Original ------------------</div><div style="font-size:12px;background:#efefef;padding:8px"><div>



<b>From: </b> "Alexander Kornienko"<<a href="mailto:alexfh@google.com" target="_blank">alexfh@google.com</a>>;</div><div><b>Date: </b> Wed, Jan 2, 2013 10:17 AM</div><div><b>To: </b> "kevinlynx"<<a href="mailto:kevinlynx@gmail.com" target="_blank">kevinlynx@gmail.com</a>>; <u></u></div>



<div><b>Cc: </b> "cfe-dev"<<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a>>; <u></u></div><div><b>Subject: </b> Re: [cfe-dev] check whether a `case` statement has a `break` statement?</div>



</div><div><br></div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div dir="ltr"><div><div class="gmail_default">I guess you're trying to do something similar to -Wimplicit-fallthrough diagnostics. If this is the case, take a look at <a href="http://llvm.org/svn/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp" target="_blank">http://llvm.org/svn/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp</a>, <span style="white-space:pre-wrap">DiagnoseSwitchLabelsFallthrough function. In short: you can use CFG (control-flow graph) to reason about execution paths, and, for example, detect if there's an execution path between two case labels.</span></div>




<div class="gmail_default"><span style="white-space:pre-wrap"><br></span></div><div class="gmail_default"><span style="white-space:pre-wrap">If you need something simpler, and just detect if there's any 'break' somewhere between two case labels (I'm not sure I understand why you would need this, though), you can just use RecursiveASTVisitor and handle SwitchStmt, </span><span style="white-space:pre-wrap">SwitchCase (which can be either </span><span style="white-space:pre-wrap">CaseStmt or </span><font color="#000000"><span style="white-space:pre-wrap">DefaultStmt)</span></font><span style="white-space:pre-wrap"> and BreakStmt.</span></div>




</div><div class="gmail_extra"><br><div class="gmail_quote"><div>On Tue, Jan 1, 2013 at 3:30 PM, kevinlynx <span dir="ltr"><<a href="mailto:kevinlynx@gmail.com" target="_blank">kevinlynx@gmail.com</a>></span> wrote:<br>



</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
In my parser, I get a `SwitchStmt`, and I can traverse all `case` statements of it. I want to check whether a `case` statement has a `break` statement.. But i can not figure it out. Here is my codes:<div><br><br>
    for (SwitchCase *c = stmt->getSwitchCaseList(); c != NULL; c = c->getNextSwitchCase()) {<br>
            if (isa<CaseStmt>(c)) {<br>                CaseStmt *caseStmt = cast<CaseStmt>(c)<br>                // I do not know how to check `CaseStmt` has a `BreakStmt`<br>            }<br>    }<br><br>Thanks.<br>




<br>BTW, I'm writing a static c code analyzer recently, this tool will check a number of c coding style rules for c codes. And because I'm a newbie to clang, so there will be more newbie questions coming, i'm sorry if i bother you guys. <br>




<br></div></blockquote><div><br></div><div><br></div><div>-- </div><div>Regards,</div><div>Alexander Kornienko </div></div>
</div></div></div></div><br></div></div><div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></div></blockquote></div><br>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br>
</blockquote></div><br>