[cfe-dev] check whether a `case` statement has a `break` statement?

John McCall rjmccall at apple.com
Thu Jan 3 12:56:57 PST 2013


On Jan 1, 2013, at 6:30 AM, kevinlynx <kevinlynx at gmail.com> wrote:
> 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:
> 
>     for (SwitchCase *c = stmt->getSwitchCaseList(); c != NULL; c = c->getNextSwitchCase()) {
>             if (isa<CaseStmt>(c)) {
>                 CaseStmt *caseStmt = cast<CaseStmt>(c)
>                 // I do not know how to check `CaseStmt` has a `BreakStmt`
>             }
>     }

Unfortunately, C does not work the way you think it does;  a switch statement
simply opens a new statement scope, and case statements can be embedded
at arbitrary positions within those statements.  This really is a control-flow
analysis, and you need to use the CFG.

John.



More information about the cfe-dev mailing list