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:
Jon Siwek 2013-01-16 16:17:17 -06:00
parent 8695053e27
commit be71a42f4c
8 changed files with 150 additions and 33 deletions

View file

@ -16,6 +16,7 @@ typedef enum {
STMT_ADD, STMT_DELETE,
STMT_LIST, STMT_EVENT_BODY_LIST,
STMT_INIT,
STMT_FALLTHROUGH,
STMT_NULL
#define NUM_STMTS (int(STMT_NULL) + 1)
} BroStmtTag;
@ -24,7 +25,8 @@ typedef enum {
FLOW_NEXT, // continue on to next statement
FLOW_LOOP, // go to top of loop
FLOW_BREAK, // break out of loop
FLOW_RETURN // return from function
FLOW_RETURN, // return from function
FLOW_FALLTHROUGH// fall through to next switch case
} stmt_flow_type;
extern const char* stmt_name(BroStmtTag t);