Simplify usage code

This commit is contained in:
gingerBill
2024-02-22 19:24:16 +00:00
parent c14b9d461a
commit 3060225f46
2 changed files with 69 additions and 69 deletions

View File

@@ -4262,72 +4262,70 @@ gb_internal Type *alloc_type_proc_from_types(Type **param_types, unsigned param_
return t;
}
gb_internal Type *type_from_selection(Type *type, Selection const &sel) {
for (i32 index : sel.index) {
Type *bt = base_type(type_deref(type));
switch (bt->kind) {
case Type_Struct:
type = bt->Struct.fields[index]->type;
break;
case Type_Tuple:
type = bt->Tuple.variables[index]->type;
break;
case Type_BitField:
type = bt->BitField.fields[index]->type;
break;
case Type_Array:
type = bt->Array.elem;
break;
case Type_EnumeratedArray:
type = bt->Array.elem;
break;
case Type_Slice:
switch (index) {
case 0: type = alloc_type_multi_pointer(bt->Slice.elem); break;
case 1: type = t_int; break;
}
break;
case Type_DynamicArray:
switch (index) {
case 0: type = alloc_type_multi_pointer(bt->DynamicArray.elem); break;
case 1: type = t_int; break;
case 2: type = t_int; break;
case 3: type = t_allocator; break;
}
break;
case Type_Map:
switch (index) {
case 0: type = t_uintptr; break;
case 1: type = t_int; break;
case 2: type = t_allocator; break;
}
break;
case Type_Basic:
if (is_type_complex_or_quaternion(bt)) {
type = base_complex_elem_type(bt);
} else {
switch (type->Basic.kind) {
case Basic_any:
switch (index) {
case 0: type = t_rawptr; break;
case 1: type = t_typeid; break;
}
break;
case Basic_string:
switch (index) {
case 0: type = t_u8_multi_ptr; break;
case 1: type = t_int; break;
}
break;
}
}
break;
}
}
return type;
}
// gb_internal Type *type_from_selection(Type *type, Selection const &sel) {
// for (i32 index : sel.index) {
// Type *bt = base_type(type_deref(type));
// switch (bt->kind) {
// case Type_Struct:
// type = bt->Struct.fields[index]->type;
// break;
// case Type_Tuple:
// type = bt->Tuple.variables[index]->type;
// break;
// case Type_BitField:
// type = bt->BitField.fields[index]->type;
// break;
// case Type_Array:
// type = bt->Array.elem;
// break;
// case Type_EnumeratedArray:
// type = bt->Array.elem;
// break;
// case Type_Slice:
// switch (index) {
// case 0: type = alloc_type_multi_pointer(bt->Slice.elem); break;
// case 1: type = t_int; break;
// }
// break;
// case Type_DynamicArray:
// switch (index) {
// case 0: type = alloc_type_multi_pointer(bt->DynamicArray.elem); break;
// case 1: type = t_int; break;
// case 2: type = t_int; break;
// case 3: type = t_allocator; break;
// }
// break;
// case Type_Map:
// switch (index) {
// case 0: type = t_uintptr; break;
// case 1: type = t_int; break;
// case 2: type = t_allocator; break;
// }
// break;
// case Type_Basic:
// if (is_type_complex_or_quaternion(bt)) {
// type = base_complex_elem_type(bt);
// } else {
// switch (type->Basic.kind) {
// case Basic_any:
// switch (index) {
// case 0: type = t_rawptr; break;
// case 1: type = t_typeid; break;
// }
// break;
// case Basic_string:
// switch (index) {
// case 0: type = t_u8_multi_ptr; break;
// case 1: type = t_int; break;
// }
// break;
// }
// }
// break;
// }
// }
// return type;
// }
gb_internal gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) {
if (type == nullptr) {