Add #soa pointer type to aid with refactoring to #soa data types

a: #soa[16]Foo
p := &a[6]
#assert(type_of(p) == #soa^#soa[16]Foo)
p^.x = 123
p.x = 123
This commit is contained in:
gingerBill
2022-08-08 15:07:00 +01:00
parent 4633591918
commit 5e3cf45df3
24 changed files with 274 additions and 23 deletions
+24 -4
View File
@@ -2693,9 +2693,12 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t
case_ast_node(ue, UnaryExpr, e);
switch (ue->op.kind) {
case Token_Pointer:
*type = alloc_type_pointer(check_type(ctx, ue->expr));
set_base_type(named_type, *type);
return true;
{
Type *elem = check_type(ctx, ue->expr);
*type = alloc_type_pointer(elem);
set_base_type(named_type, *type);
return true;
}
}
case_end;
@@ -2721,7 +2724,24 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t
elem = o.type;
}
*type = alloc_type_pointer(elem);
if (pt->tag != nullptr) {
GB_ASSERT(pt->tag->kind == Ast_BasicDirective);
String name = pt->tag->BasicDirective.name.string;
if (name == "soa") {
// TODO(bill): generic #soa pointers
if (is_type_soa_struct(elem)) {
*type = alloc_type_soa_pointer(elem);
} else {
error(pt->tag, "#soa pointers require an #soa record type as the element");
*type = alloc_type_pointer(elem);
}
} else {
error(pt->tag, "Invalid tag applied to pointer, got #%.*s", LIT(name));
*type = alloc_type_pointer(elem);
}
} else {
*type = alloc_type_pointer(elem);
}
set_base_type(named_type, *type);
return true;
case_end;