mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Add "fallthrough" keyword, require a flow statement to end case blocks.
Case blocks in switch statements now must end in a break, return, or fallthrough statement to give best mix of safety, readability, and flexibility. The new fallthrough keyword explicitly allows control to be passed to the next case block in a switch statement. Addresses #754.
This commit is contained in:
parent
8695053e27
commit
be71a42f4c
8 changed files with 150 additions and 33 deletions
18
src/Stmt.h
18
src/Stmt.h
|
@ -195,8 +195,7 @@ protected:
|
|||
|
||||
class Case : public BroObj {
|
||||
public:
|
||||
Case(ListExpr* c, Stmt* arg_s) :
|
||||
cases(simplify_expr_list(c,SIMPLIFY_GENERAL)), s(arg_s) { }
|
||||
Case(ListExpr* c, Stmt* arg_s);
|
||||
~Case();
|
||||
|
||||
const ListExpr* Cases() const { return cases; }
|
||||
|
@ -371,6 +370,21 @@ protected:
|
|||
DECLARE_SERIAL(BreakStmt);
|
||||
};
|
||||
|
||||
class FallthroughStmt : public Stmt {
|
||||
public:
|
||||
FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { }
|
||||
|
||||
Val* Exec(Frame* f, stmt_flow_type& flow) const;
|
||||
int IsPure() const;
|
||||
|
||||
void Describe(ODesc* d) const;
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(FallthroughStmt);
|
||||
};
|
||||
|
||||
class ReturnStmt : public ExprStmt {
|
||||
public:
|
||||
ReturnStmt(Expr* e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue