diff options
Diffstat (limited to 'rt_struct.c')
-rw-r--r-- | rt_struct.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/rt_struct.c b/rt_struct.c index 34556ca..4117def 100644 --- a/rt_struct.c +++ b/rt_struct.c @@ -11,6 +11,21 @@ static int member_is_ptr(rts_member_type type) { return type >= MBR_PTR && type <= MBR_PTR_ARRAY_NULL; } +static int member_is_fixed_array(rts_member_type type) { + return type == MBR_ARRAY || type == MBR_PTR_ARRAY; +} + +static size_t member_size(rts_member *member) { + const rts_type *type = (member_is_ptr(member->mbr_type)) ? &RTS_TYPE_POINTER : member->type; + size_t size = type->size; + if (member_is_fixed_array(member->mbr_type)) { + for (int i = 0; i < member->dim_count && member->dim_sizes[i]; ++i) { + size *= member->dim_sizes[i]; + } + } + return size; +} + int create_rts(rts_type *type) { if (type == NULL) { return 1; @@ -41,7 +56,7 @@ int create_rts(rts_type *type) { padding = (remainder) ? align - remainder : 0; offset += padding; type->offsets[i] = offset; - offset += member_type->size; + offset += member_size(members[i]); } } } |