You do realize that if someone used a "return" or a "throw" then you will miss this ?<br><br>-- Matthieu<br><br><div class="gmail_quote">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>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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 class="im"><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 class="im">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 class="im"><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>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">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>