| ... | @@ -15787,6 +15787,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -15787,6 +15787,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 15787 | assert(type_entry != nullptr); | 15787 | assert(type_entry != nullptr); |
| 15788 | assert(!type_is_invalid(type_entry)); | 15788 | assert(!type_is_invalid(type_entry)); |
| 15789 | | 15789 | |
| | 15790 | ensure_complete_type(ira->codegen, type_entry); |
| | 15791 | |
| 15790 | const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field, | 15792 | const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field, |
| 15791 | TypeTableEntry *type_info_enum_field_type) { | 15793 | TypeTableEntry *type_info_enum_field_type) { |
| 15792 | // @TODO Those cause a find_struct_type_field assertion to fail (type_entry->data.structure.complete) | 15794 | // @TODO Those cause a find_struct_type_field assertion to fail (type_entry->data.structure.complete) |
| ... | @@ -16164,6 +16166,72 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -16164,6 +16166,72 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16164 | union_field_val->data.x_struct.parent.data.p_array.elem_index = union_field_index; | 16166 | union_field_val->data.x_struct.parent.data.p_array.elem_index = union_field_index; |
| 16165 | } | 16167 | } |
| 16166 | | 16168 | |
| | 16169 | // @TODO Definitions |
| | 16170 | break; |
| | 16171 | } |
| | 16172 | case TypeTableEntryIdStruct: |
| | 16173 | { |
| | 16174 | result = create_const_vals(1); |
| | 16175 | result->special = ConstValSpecialStatic; |
| | 16176 | result->type = ir_type_info_get_type(ira, "Struct"); |
| | 16177 | |
| | 16178 | ConstExprValue *fields = create_const_vals(3); |
| | 16179 | result->data.x_struct.fields = fields; |
| | 16180 | |
| | 16181 | // layout: ContainerLayout |
| | 16182 | ensure_field_index(result->type, "layout", 0); |
| | 16183 | fields[0].special = ConstValSpecialStatic; |
| | 16184 | fields[0].type = ir_type_info_get_type(ira, "ContainerLayout"); |
| | 16185 | bigint_init_unsigned(&fields[0].data.x_enum_tag, type_entry->data.structure.layout); |
| | 16186 | // fields: []TypeInfo.StructField |
| | 16187 | ensure_field_index(result->type, "fields", 1); |
| | 16188 | |
| | 16189 | TypeTableEntry *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField"); |
| | 16190 | uint32_t struct_field_count = type_entry->data.structure.src_field_count; |
| | 16191 | |
| | 16192 | ConstExprValue *struct_field_array = create_const_vals(1); |
| | 16193 | struct_field_array->special = ConstValSpecialStatic; |
| | 16194 | struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count); |
| | 16195 | struct_field_array->data.x_array.special = ConstArraySpecialNone; |
| | 16196 | struct_field_array->data.x_array.s_none.parent.id = ConstParentIdNone; |
| | 16197 | struct_field_array->data.x_array.s_none.elements = create_const_vals(struct_field_count); |
| | 16198 | |
| | 16199 | init_const_slice(ira->codegen, &fields[1], struct_field_array, 0, struct_field_count, false); |
| | 16200 | |
| | 16201 | for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) |
| | 16202 | { |
| | 16203 | TypeStructField *struct_field = &type_entry->data.structure.fields[struct_field_index]; |
| | 16204 | ConstExprValue *struct_field_val = &struct_field_array->data.x_array.s_none.elements[struct_field_index]; |
| | 16205 | |
| | 16206 | struct_field_val->special = ConstValSpecialStatic; |
| | 16207 | struct_field_val->type = type_info_struct_field_type; |
| | 16208 | |
| | 16209 | ConstExprValue *inner_fields = create_const_vals(3); |
| | 16210 | inner_fields[1].special = ConstValSpecialStatic; |
| | 16211 | inner_fields[1].type = get_maybe_type(ira->codegen, ira->codegen->builtin_types.entry_usize); |
| | 16212 | |
| | 16213 | if (!type_has_bits(struct_field->type_entry)) |
| | 16214 | inner_fields[1].data.x_maybe = nullptr; |
| | 16215 | else |
| | 16216 | { |
| | 16217 | size_t byte_offset = LLVMOffsetOfElement(ira->codegen->target_data_ref, type_entry->type_ref, struct_field->gen_index); |
| | 16218 | inner_fields[1].data.x_maybe = create_const_vals(1); |
| | 16219 | inner_fields[1].data.x_maybe->type = ira->codegen->builtin_types.entry_usize; |
| | 16220 | bigint_init_unsigned(&inner_fields[1].data.x_maybe->data.x_bigint, byte_offset); |
| | 16221 | } |
| | 16222 | |
| | 16223 | inner_fields[2].special = ConstValSpecialStatic; |
| | 16224 | inner_fields[2].type = ira->codegen->builtin_types.entry_type; |
| | 16225 | inner_fields[2].data.x_type = struct_field->type_entry; |
| | 16226 | |
| | 16227 | ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name); |
| | 16228 | init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(struct_field->name), true); |
| | 16229 | |
| | 16230 | struct_field_val->data.x_struct.fields = inner_fields; |
| | 16231 | struct_field_val->data.x_struct.parent.id = ConstParentIdArray; |
| | 16232 | struct_field_val->data.x_struct.parent.data.p_array.array_val = struct_field_array; |
| | 16233 | struct_field_val->data.x_struct.parent.data.p_array.elem_index = struct_field_index; |
| | 16234 | } |
| 16167 | // @TODO Definitions | 16235 | // @TODO Definitions |
| 16168 | break; | 16236 | break; |
| 16169 | } | 16237 | } |