diff options
| author | gingerBill <bill@gingerbill.org> | 2018-02-17 19:24:02 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-02-17 19:24:02 +0000 |
| commit | f51de2e488977fa10896eb343a7f09b9013380d3 (patch) | |
| tree | 32d7c209d413468971304d79ba469cea0dd5a048 /src | |
| parent | cabb2bb9920096e8a91ac4ed36c5778f2f114d98 (diff) | |
Disallow #complete switch ranges
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_stmt.cpp | 37 |
1 files changed, 4 insertions, 33 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 2d99a4fbc..a24d4477a 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -739,41 +739,12 @@ void check_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) { Operand b1 = rhs; check_comparison(c, &a1, &b1, op); if (complete) { - if (lhs.mode != Addressing_Constant) { - error(lhs.expr, "#complete switch statement only allows constant case clauses"); - } - if (rhs.mode != Addressing_Constant) { - error(rhs.expr, "#complete switch statement only allows constant case clauses"); - } + error(lhs.expr, "#complete switch statement does not allow ranges"); } - if (complete && - a1.mode != Addressing_Invalid && b1.mode != Addressing_Invalid && - lhs.mode == Addressing_Constant && rhs.mode == Addressing_Constant && - is_type_number(lhs.type) && is_type_number(rhs.type)) { - ExactValue start = lhs.value; - ExactValue end = rhs.value; - ExactValue one = exact_value_i64(1); - match_exact_values(&one, &start); - for (ExactValue i = start; - compare_exact_values(op, i, end); - i = exact_value_add(i, one)) { - bool use_expr = false; - Operand x = lhs; - x.value = i; - if (compare_exact_values(Token_CmpEq, i, start)) { - use_expr = true; - } else if (compare_exact_values(Token_CmpEq, i, end)) { - x = rhs; - use_expr = true; - } - add_constant_switch_case(c, &seen, x, use_expr); - } - } else { - add_constant_switch_case(c, &seen, lhs); - if (op == Token_LtEq) { - add_constant_switch_case(c, &seen, rhs); - } + add_constant_switch_case(c, &seen, lhs); + if (op == Token_LtEq) { + add_constant_switch_case(c, &seen, rhs); } } else { Operand y = {}; |