[cfe-dev] check whether a `case` statement has a `break` statement?
Marshall Clow
mclow.lists at gmail.com
Fri Jan 4 10:19:39 PST 2013
On Jan 3, 2013, at 12:56 PM, John McCall <rjmccall at apple.com> wrote:
> 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.
Make sure that you have a version of Duff's device in your test matrix for this.
http://en.wikipedia.org/wiki/Duff's_device
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists at gmail.com>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
More information about the cfe-dev
mailing list