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"<alexfh@google.com>;</div><div><b>Date: </b> Wed, Jan 2, 2013 10:17 AM</div><div><b>To: </b> "kevinlynx"<kevinlynx@gmail.com>; <wbr></div><div><b>Cc: </b> "cfe-dev"<cfe-dev@cs.uiuc.edu>; <wbr></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="gmail_default" style="#">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">http://llvm.org/svn/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp</a>, <span style="color:rgb(0,0,0);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" style="#"><span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div class="gmail_default" style="#"><span style="color:rgb(0,0,0);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="color:rgb(0,0,0);white-space:pre-wrap">SwitchCase (which can be either </span><span style="color:rgb(0,0,0);white-space:pre-wrap">CaseStmt or </span><font color="#000000"><span style="white-space:pre-wrap">DefaultStmt)</span></font><span style="color:rgb(0,0,0);white-space:pre-wrap"> and BreakStmt.</span></div>
<div class="gmail_extra"><br><div class="gmail_quote">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><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:<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></blockquote><div><br></div><div><br></div><div style="#">-- </div><div style="#">Regards,</div><div style="#">Alexander Kornienko </div></div>
</div></div></div></div>