diff options
| author | gingerBill <bill@gingerbill.org> | 2018-08-16 00:07:26 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-08-16 00:07:26 +0100 |
| commit | 85ac95f81be8632c3fa3584f67714337181003de (patch) | |
| tree | c2e34e536d284d1bf7602b53c1a0fa78421a6d55 /src/check_expr.cpp | |
| parent | 042550cf87048d0a05c1de8caec4e59a280b4270 (diff) | |
Constant evaluation for `in` expression for `bit_set`s
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 958bd6a77..1bcac33ae 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2041,6 +2041,22 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, bool use_lhs_as } else if (is_type_bit_set(y->type)) { Type *yt = base_type(y->type); check_assignment(c, x, yt->BitSet.base, str_lit("bit_set 'in'")); + + if (x->mode == Addressing_Constant && y->mode == Addressing_Constant) { + ExactValue k = exact_value_to_integer(x->value); + ExactValue v = exact_value_to_integer(y->value); + GB_ASSERT(k.kind == ExactValue_Integer); + GB_ASSERT(v.kind == ExactValue_Integer); + i64 bit = 1ll<<big_int_to_i64(&k.value_integer); + i64 bits = big_int_to_i64(&v.value_integer); + + x->mode = Addressing_Constant; + x->type = t_untyped_bool; + x->value = exact_value_bool((bit & bits) != 0); + x->expr = node; + return; + } + } else { gbString t = type_to_string(y->type); error(x->expr, "expected either a map or bitset for 'in', got %s", t); |