diff options
| author | gingerBill <bill@gingerbill.org> | 2022-08-08 15:07:00 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-08-08 15:07:00 +0100 |
| commit | 5e3cf45df3e781b0e5e01a55490a32bed0d9c7e3 (patch) | |
| tree | a77078831df35c7b232a4c55714c00a22a48782c /src/check_type.cpp | |
| parent | 4633591918030497728675a026a45dda6201ea83 (diff) | |
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
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 5d37ff208..da0a9706b 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -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; |