diff options
| author | gingerBill <bill@gingerbill.org> | 2020-05-15 18:45:24 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-05-15 18:45:24 +0100 |
| commit | e1bdaa981adf14b5caf4346e154a3a66bce8ccd7 (patch) | |
| tree | 990d5ceeea04c6a56efda4ee2a5a55580c4a7377 /src/check_expr.cpp | |
| parent | 95e8668b779ec59d9e0a3afefb51d599c6602cd2 (diff) | |
Relative pointer and relative slices
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index ab4755bd3..06c7e7f36 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7563,6 +7563,17 @@ bool check_set_index_data(Operand *o, Type *t, bool indirection, i64 *max_count, } return true; + case Type_RelativeSlice: + { + Type *slice_type = base_type(t->RelativeSlice.slice_type); + GB_ASSERT(slice_type->kind == Type_Slice); + o->type = slice_type->Slice.elem; + if (o->mode != Addressing_Constant) { + o->mode = Addressing_Variable; + } + } + return true; + case Type_DynamicArray: o->type = t->DynamicArray.elem; if (o->mode != Addressing_Constant) { @@ -9250,6 +9261,8 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type // Okay } else if (is_type_string(t)) { // Okay + } else if (is_type_relative_slice(t)) { + // Okay } else { valid = false; } @@ -9392,6 +9405,19 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type } } break; + + case Type_RelativeSlice: + valid = true; + o->type = t->RelativeSlice.slice_type; + if (o->mode != Addressing_Variable) { + gbString str = expr_to_string(node); + error(node, "Cannot relative slice '%s', value is not addressable", str); + gb_string_free(str); + o->mode = Addressing_Invalid; + o->expr = node; + return kind; + } + break; } if (!valid) { |