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

Sean Silva silvas at purdue.edu
Tue Jan 1 12:48:13 PST 2013


For questions like this, it is usually easiest to just dump the AST
created for a snippet of sample code. See
<http://clang.llvm.org/docs/IntroductionToTheClangAST.html> for
information about how to do that.

-- Sean Silva

On Tue, Jan 1, 2013 at 7: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`
>             }
>     }
>
> Thanks.
>
> 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.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list