commit 744df74ba45e019f6b8027597c5a6982b4484535
parent b95fe43114f4c5ffa80c3593192edaf97427aac3
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 9 Aug 2021 10:13:52 +0200
Implement len() et al for pointers to composites
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -1879,9 +1879,10 @@ check_expr_measure(struct context *ctx,
errors = check_expression(ctx, aexpr->measure.value,
expr->measure.value, NULL, errors);
enum type_storage vstor =
- type_dealias(expr->measure.value->result)->storage;
- if (vstor != STORAGE_ARRAY && vstor != STORAGE_SLICE
- && vstor != STORAGE_STRING) {
+ type_dereference(expr->measure.value->result)->storage;
+ bool valid = vstor == STORAGE_ARRAY || vstor == STORAGE_SLICE
+ || vstor == STORAGE_STRING;
+ if (!valid) {
return error(aexpr->measure.value->loc, expr, errors,
"len argument must be of an array, slice, or str type");
}
diff --git a/src/gen.c b/src/gen.c
@@ -1409,12 +1409,14 @@ gen_expr_measure(struct gen_context *ctx, const struct expression *expr)
{
size_t len;
struct gen_value gv, temp;
+ const struct type *type;
const struct expression *value = expr->measure.value;
switch (expr->measure.op) {
case M_LEN:
- switch (type_dealias(value->result)->storage) {
+ type = type_dereference(value->result);
+ switch (type->storage) {
case STORAGE_ARRAY:
- len = type_dealias(value->result)->array.length;
+ len = type->array.length;
assert(len != SIZE_UNDEFINED);
return (struct gen_value){
.kind = GV_CONST,