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; Selection sub_sel = sel;
sub_sel.index.count -= 1; 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); lbValue a = lb_addr_get_ptr(p, addr);
if (sub_sel.index.count > 0) { if (sub_sel.index.count > 0) {
a = lb_emit_deep_field_gep(p, a, sub_sel); 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]; i32 index = sel.index[sel.index.count-1];
Entity *f = bf_type->BitField.fields[index]; 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; return t;
} }
// gb_internal Type *type_from_selection(Type *type, Selection const &sel) {
gb_internal Type *type_from_selection(Type *type, Selection const &sel) { // for (i32 index : sel.index) {
for (i32 index : sel.index) { // Type *bt = base_type(type_deref(type));
Type *bt = base_type(type_deref(type)); // switch (bt->kind) {
switch (bt->kind) { // case Type_Struct:
case Type_Struct: // type = bt->Struct.fields[index]->type;
type = bt->Struct.fields[index]->type; // break;
break; // case Type_Tuple:
case Type_Tuple: // type = bt->Tuple.variables[index]->type;
type = bt->Tuple.variables[index]->type; // break;
break; // case Type_BitField:
case Type_BitField: // type = bt->BitField.fields[index]->type;
type = bt->BitField.fields[index]->type; // break;
break; // case Type_Array:
case Type_Array: // type = bt->Array.elem;
type = bt->Array.elem; // break;
break; // case Type_EnumeratedArray:
case Type_EnumeratedArray: // type = bt->Array.elem;
type = bt->Array.elem; // break;
break; // case Type_Slice:
case Type_Slice: // switch (index) {
switch (index) { // case 0: type = alloc_type_multi_pointer(bt->Slice.elem); break;
case 0: type = alloc_type_multi_pointer(bt->Slice.elem); break; // case 1: type = t_int; break;
case 1: type = t_int; break; // }
} // break;
break; // case Type_DynamicArray:
case Type_DynamicArray: // switch (index) {
switch (index) { // case 0: type = alloc_type_multi_pointer(bt->DynamicArray.elem); break;
case 0: type = alloc_type_multi_pointer(bt->DynamicArray.elem); break; // case 1: type = t_int; break;
case 1: type = t_int; break; // case 2: type = t_int; break;
case 2: type = t_int; break; // case 3: type = t_allocator; break;
case 3: type = t_allocator; break; // }
} // break;
break; // case Type_Map:
case Type_Map: // switch (index) {
switch (index) { // case 0: type = t_uintptr; break;
case 0: type = t_uintptr; break; // case 1: type = t_int; break;
case 1: type = t_int; break; // case 2: type = t_allocator; break;
case 2: type = t_allocator; break; // }
} // break;
break; // case Type_Basic:
case Type_Basic: // if (is_type_complex_or_quaternion(bt)) {
if (is_type_complex_or_quaternion(bt)) { // type = base_complex_elem_type(bt);
type = base_complex_elem_type(bt); // } else {
} else { // switch (type->Basic.kind) {
switch (type->Basic.kind) { // case Basic_any:
case Basic_any: // switch (index) {
switch (index) { // case 0: type = t_rawptr; break;
case 0: type = t_rawptr; break; // case 1: type = t_typeid; break;
case 1: type = t_typeid; break; // }
} // break;
break; // case Basic_string:
case Basic_string: // switch (index) {
switch (index) { // case 0: type = t_u8_multi_ptr; break;
case 0: type = t_u8_multi_ptr; break; // case 1: type = t_int; break;
case 1: type = t_int; break; // }
} // break;
break; // }
} // }
} // break;
break; // }
} // }
} // return type;
return type; // }
}
gb_internal gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) { gb_internal gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) {
if (type == nullptr) { if (type == nullptr) {