diff options
| author | gingerBill <bill@gingerbill.org> | 2018-12-21 11:34:15 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-12-21 11:34:15 +0000 |
| commit | b504d6e12ab70de583f70955c8ba6150b23ddc56 (patch) | |
| tree | 0099847c4b351afff21ff63b5196ef9ea42b0bb9 /src/check_expr.cpp | |
| parent | b4e83a430a8401e915346cd2d6063d8a8a2d1e03 (diff) | |
`notin` operator
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 97df8e3be..932f9c061 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2123,6 +2123,7 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, bool use_lhs_as } case Token_in: + case Token_notin: check_expr(c, x, be->left); check_expr(c, y, be->right); if (x->mode == Addressing_Invalid) { @@ -2136,13 +2137,21 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, bool use_lhs_as if (is_type_map(y->type)) { Type *yt = base_type(y->type); - check_assignment(c, x, yt->Map.key, str_lit("map 'in'")); + if (op.kind == Token_in) { + check_assignment(c, x, yt->Map.key, str_lit("map 'in'")); + } else { + check_assignment(c, x, yt->Map.key, str_lit("map 'notin'")); + } add_package_dependency(c, "runtime", "__dynamic_map_get"); } else if (is_type_bit_set(y->type)) { Type *yt = base_type(y->type); - check_assignment(c, x, yt->BitSet.elem, str_lit("bit_set 'in'")); + if (op.kind == Token_in) { + check_assignment(c, x, yt->BitSet.elem, str_lit("bit_set 'in'")); + } else { + check_assignment(c, x, yt->BitSet.elem, str_lit("bit_set 'notin'")); + } 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); @@ -2158,7 +2167,11 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, bool use_lhs_as x->mode = Addressing_Constant; x->type = t_untyped_bool; - x->value = exact_value_bool((bit & bits) != 0); + if (op.kind == Token_in) { + x->value = exact_value_bool((bit & bits) != 0); + } else { + x->value = exact_value_bool((bit & bits) == 0); + } x->expr = node; return; } else { |