| ... | ... | @@ -16172,6 +16172,63 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p |
| 16172 | 16172 | |
| 16173 | 16173 | // @TODO |
| 16174 | 16174 | // methods: []TypeInfo.Method |
| 16175 | return result; |
| 16176 | } |
| 16177 | case TypeTableEntryIdErrorSet: |
| 16178 | { |
| 16179 | ConstExprValue *result = create_const_vals(1); |
| 16180 | result->special = ConstValSpecialStatic; |
| 16181 | result->type = ir_type_info_get_type(ira, "ErrorSet"); |
| 16182 | |
| 16183 | ConstExprValue *fields = create_const_vals(1); |
| 16184 | result->data.x_struct.fields = fields; |
| 16185 | |
| 16186 | ir_type_info_struct_set_parent(result, parent, parent_field_index); |
| 16187 | ira->codegen->type_info_cache.put(type_entry, result); |
| 16188 | |
| 16189 | // errors: []TypeInfo.Error |
| 16190 | ensure_field_index(result->type, "errors", 0); |
| 16191 | |
| 16192 | TypeTableEntry *type_info_error_type = ir_type_info_get_type(ira, "Error"); |
| 16193 | // @TODO Same as above in Enum TypeInfo generation. |
| 16194 | // ensure_field_index(type_info_error_type, "name", 0); |
| 16195 | // ensure_field_index(type_info_error_type, "value", 1); |
| 16196 | |
| 16197 | uint32_t error_count = type_entry->data.error_set.err_count; |
| 16198 | ConstExprValue *error_array = create_const_vals(1); |
| 16199 | error_array->special = ConstValSpecialStatic; |
| 16200 | error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count); |
| 16201 | error_array->data.x_array.special = ConstArraySpecialNone; |
| 16202 | error_array->data.x_array.s_none.parent.id = ConstParentIdNone; |
| 16203 | error_array->data.x_array.s_none.elements = create_const_vals(error_count); |
| 16204 | |
| 16205 | init_const_slice(ira->codegen, &fields[0], error_array, 0, error_count, false); |
| 16206 | for (uint32_t error_index = 0; error_index < error_count; error_index++) |
| 16207 | { |
| 16208 | ErrorTableEntry *error = type_entry->data.error_set.errors[error_index]; |
| 16209 | ConstExprValue *error_val = &error_array->data.x_array.s_none.elements[error_index]; |
| 16210 | |
| 16211 | error_val->special = ConstValSpecialStatic; |
| 16212 | error_val->type = type_info_error_type; |
| 16213 | |
| 16214 | ConstExprValue *inner_fields = create_const_vals(2); |
| 16215 | inner_fields[1].special = ConstValSpecialStatic; |
| 16216 | inner_fields[1].type = ira->codegen->builtin_types.entry_usize; |
| 16217 | |
| 16218 | ConstExprValue *name = nullptr; |
| 16219 | if (error->cached_error_name_val != nullptr) |
| 16220 | name = error->cached_error_name_val; |
| 16221 | if (name == nullptr) |
| 16222 | name = create_const_str_lit(ira->codegen, &error->name); |
| 16223 | init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(&error->name), true); |
| 16224 | bigint_init_unsigned(&inner_fields[1].data.x_bigint, error->value); |
| 16225 | |
| 16226 | error_val->data.x_struct.fields = inner_fields; |
| 16227 | error_val->data.x_struct.parent.id = ConstParentIdArray; |
| 16228 | error_val->data.x_struct.parent.data.p_array.array_val = error_array; |
| 16229 | error_val->data.x_struct.parent.data.p_array.elem_index = error_index; |
| 16230 | } |
| 16231 | |
| 16175 | 16232 | return result; |
| 16176 | 16233 | } |
| 16177 | 16234 | default: |