diff --git a/ruamoko/qwaq/debugger/typeencodings.h b/ruamoko/qwaq/debugger/typeencodings.h index 11b78d0da..0ed0f83d7 100644 --- a/ruamoko/qwaq/debugger/typeencodings.h +++ b/ruamoko/qwaq/debugger/typeencodings.h @@ -8,6 +8,7 @@ @interface TypeEncodings : Object +(qfot_type_t *)getType:(unsigned)typeAddr fromTarget:(qdb_target_t)target; ++(int)typeSize:(qfot_type_t *)type; @end #endif//__qwaq_debugger_typeencodings_h diff --git a/ruamoko/qwaq/debugger/typeencodings.r b/ruamoko/qwaq/debugger/typeencodings.r index 109bc33d3..d6246e2ef 100644 --- a/ruamoko/qwaq/debugger/typeencodings.r +++ b/ruamoko/qwaq/debugger/typeencodings.r @@ -191,4 +191,48 @@ error: return nil; } ++(int)typeSize:(qfot_type_t *)type +{ + qfot_type_t *aux_type; + int size = 0; + + switch (type.meta) { + case ty_basic: + size = pr_type_size[type.type]; + break; + case ty_array: + aux_type = type.array.type; + size = type.array.size * [TypeEncodings typeSize:aux_type]; + break; + case ty_struct: + for (int i = 0; i < type.strct.num_fields; i++) { + aux_type = type.strct.fields[i].type; + size += [TypeEncodings typeSize:aux_type]; + } + break; + case ty_union: + for (int i = 0; i < type.strct.num_fields; i++) { + aux_type = type.strct.fields[i].type; + int s = [TypeEncodings typeSize:aux_type]; + if (s > size) { + size = s; + } + } + break; + case ty_enum: + // enums are ints + size = pr_type_size[ev_integer]; + break; + case ty_class: + //FIXME + size = 1; + break; + case ty_alias: + aux_type = type.alias.aux_type; + size = [TypeEncodings typeSize:aux_type]; + break; + } + return size; +} + @end