harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 2013834e47cdf8bf375e8587229263a430359915
parent 03979e833ccff6a255346394668e695cb0b40c78
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  6 Feb 2021 17:03:18 -0500

parse, check: assign to slice expression

Diffstat:
Msrc/check.c | 3++-
Msrc/gen.c | 13+++++++++++++
Msrc/parse.c | 3++-
3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -338,7 +338,8 @@ check_expr_assign(struct context *ctx, "Value type is not assignable to pointer type"); value = lower_implicit_cast(object->result->pointer.referent, value); } else { - assert(object->type == EXPR_ACCESS); // Invariant + assert(object->type == EXPR_ACCESS + || object->type == EXPR_SLICE); // Invariant expect(&aexpr->loc, !(object->result->flags & TYPE_CONST), "Cannot assign to const object"); expect(&aexpr->loc, diff --git a/src/gen.c b/src/gen.c @@ -711,6 +711,14 @@ gen_expr_assert(struct gen_context *ctx, } static void +gen_expr_assign_slice(struct gen_context *ctx, + const struct expression *expr, + const struct qbe_value *out) +{ + assert(0); // TODO +} + +static void gen_expr_assign(struct gen_context *ctx, const struct expression *expr, const struct qbe_value *out) @@ -718,6 +726,11 @@ gen_expr_assign(struct gen_context *ctx, assert(out == NULL); // Invariant struct expression *object = expr->assign.object; + if (object->type == EXPR_SLICE) { + gen_expr_assign_slice(ctx, expr, out); + return; + } + assert(object->type == EXPR_ACCESS || expr->assign.indirect); // Invariant const struct expression *value = expr->assign.value; diff --git a/src/parse.c b/src/parse.c @@ -1975,7 +1975,8 @@ parse_scope_expression(struct lexer *lexer) default: unlex(lexer, &tok); value = parse_cast_expression(lexer, NULL); - if (!indirect && value->type != EXPR_ACCESS) { + if (!indirect && value->type != EXPR_ACCESS + && value->type != EXPR_SLICE) { return parse_bin_expression(lexer, value, 0); } // Is possible object-selector, try for assignment