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
+5 -3
View File
@@ -4684,15 +4684,17 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) {
Selection sub_sel = sel;
sub_sel.index.count -= 1;
Type *bf_type = type_from_selection(type, sub_sel);
bf_type = base_type(type_deref(bf_type));
GB_ASSERT(bf_type->kind == Type_BitField);
lbValue a = lb_addr_get_ptr(p, addr);
if (sub_sel.index.count > 0) {
a = lb_emit_deep_field_gep(p, a, sub_sel);
}
Type *bf_type = type_deref(a.type);
bf_type = base_type(type_deref(bf_type));
GB_ASSERT(bf_type->kind == Type_BitField);
i32 index = sel.index[sel.index.count-1];
Entity *f = bf_type->BitField.fields[index];
+64 -66
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) {