aboutsummaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-07-30 14:52:42 +0100
committerGinger Bill <bill@gingerbill.org>2017-07-30 14:52:42 +0100
commit62a72f0163b2f35ca11cd8f4bbb4c7de2c66fca4 (patch)
treee334be658d8ed4018e8ae8bb37334dbc1834f14c /src/types.cpp
parent655931f0ea282f8dbaa769a213311a774e4f84c6 (diff)
`transmute(type)x`; Minor code clean up
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/types.cpp b/src/types.cpp
index f738dd50f..86b673796 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -2141,7 +2141,7 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
t = base_type(t);
- if (t->kind == Type_Struct && !t->Struct.is_raw_union) {
+ if (t->kind == Type_Struct) {
type_set_offsets(allocator, t);
if (gb_is_between(index, 0, t->Struct.fields.count-1)) {
return t->Struct.offsets[index];
@@ -2155,7 +2155,7 @@ i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
if (t->Basic.kind == Basic_string) {
switch (index) {
case 0: return 0; // data
- case 1: return build_context.word_size; // count
+ case 1: return build_context.word_size; // len
}
} else if (t->Basic.kind == Basic_any) {
switch (index) {
@@ -2166,16 +2166,21 @@ i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
} else if (t->kind == Type_Slice) {
switch (index) {
case 0: return 0; // data
- case 1: return 1*build_context.word_size; // count
- case 2: return 2*build_context.word_size; // capacity
+ case 1: return 1*build_context.word_size; // len
+ case 2: return 2*build_context.word_size; // cap
}
} else if (t->kind == Type_DynamicArray) {
switch (index) {
case 0: return 0; // data
- case 1: return 1*build_context.word_size; // count
- case 2: return 2*build_context.word_size; // capacity
+ case 1: return 1*build_context.word_size; // len
+ case 2: return 2*build_context.word_size; // cap
case 3: return 3*build_context.word_size; // allocator
}
+ } else if (t->kind == Type_Union) {
+ i64 s = type_size_of(allocator, t);
+ switch (index) {
+ case -1: return align_formula(t->Union.variant_block_size, build_context.word_size); // __type_info
+ }
}
return 0;
}