| ... | @@ -15787,8 +15787,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -15787,8 +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 | const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field) { | 15790 | const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field, |
| 15791 | TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField"); | 15791 | TypeTableEntry *type_info_enum_field_type) { |
| 15792 | // @TODO Those cause a find_struct_type_field assertion to fail (type_entry->data.structure.complete) | 15792 | // @TODO Those cause a find_struct_type_field assertion to fail (type_entry->data.structure.complete) |
| 15793 | // ensure_field_index(type_info_enum_field_type, "name", 0); | 15793 | // ensure_field_index(type_info_enum_field_type, "name", 0); |
| 15794 | // ensure_field_index(type_info_enum_field_type, "value", 1); | 15794 | // ensure_field_index(type_info_enum_field_type, "value", 1); |
| ... | @@ -15990,10 +15990,6 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -15990,10 +15990,6 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 15990 | ensure_field_index(result->type, "fields", 2); | 15990 | ensure_field_index(result->type, "fields", 2); |
| 15991 | | 15991 | |
| 15992 | TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField"); | 15992 | TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField"); |
| 15993 | // @TODO Those cause a find_struct_type_field assertion to fail (type_entry->data.structure.complete) | | |
| 15994 | // ensure_field_index(type_info_enum_field_type, "name", 0); | | |
| 15995 | // ensure_field_index(type_info_enum_field_type, "value", 1); | | |
| 15996 | | | |
| 15997 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; | 15993 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; |
| 15998 | | 15994 | |
| 15999 | ConstExprValue *enum_field_array = create_const_vals(1); | 15995 | ConstExprValue *enum_field_array = create_const_vals(1); |
| ... | @@ -16009,14 +16005,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -16009,14 +16005,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16009 | { | 16005 | { |
| 16010 | TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index]; | 16006 | TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index]; |
| 16011 | ConstExprValue *enum_field_val = &enum_field_array->data.x_array.s_none.elements[enum_field_index]; | 16007 | ConstExprValue *enum_field_val = &enum_field_array->data.x_array.s_none.elements[enum_field_index]; |
| 16012 | make_enum_field_val(enum_field_val, enum_field); | 16008 | make_enum_field_val(enum_field_val, enum_field, type_info_enum_field_type); |
| 16013 | enum_field_val->data.x_struct.parent.id = ConstParentIdArray; | 16009 | enum_field_val->data.x_struct.parent.id = ConstParentIdArray; |
| 16014 | enum_field_val->data.x_struct.parent.data.p_array.array_val = enum_field_array; | 16010 | enum_field_val->data.x_struct.parent.data.p_array.array_val = enum_field_array; |
| 16015 | enum_field_val->data.x_struct.parent.data.p_array.elem_index = enum_field_index; | 16011 | enum_field_val->data.x_struct.parent.data.p_array.elem_index = enum_field_index; |
| 16016 | } | 16012 | } |
| 16017 | | 16013 | |
| 16018 | // @TODO | 16014 | // @TODO Definitions |
| 16019 | // methods: []TypeInfo.Method | | |
| 16020 | break; | 16015 | break; |
| 16021 | } | 16016 | } |
| 16022 | case TypeTableEntryIdErrorSet: | 16017 | case TypeTableEntryIdErrorSet: |
| ... | @@ -16032,10 +16027,6 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -16032,10 +16027,6 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16032 | ensure_field_index(result->type, "errors", 0); | 16027 | ensure_field_index(result->type, "errors", 0); |
| 16033 | | 16028 | |
| 16034 | TypeTableEntry *type_info_error_type = ir_type_info_get_type(ira, "Error"); | 16029 | TypeTableEntry *type_info_error_type = ir_type_info_get_type(ira, "Error"); |
| 16035 | // @TODO Same as above in Enum TypeInfo generation. | | |
| 16036 | // ensure_field_index(type_info_error_type, "name", 0); | | |
| 16037 | // ensure_field_index(type_info_error_type, "value", 1); | | |
| 16038 | | | |
| 16039 | uint32_t error_count = type_entry->data.error_set.err_count; | 16030 | uint32_t error_count = type_entry->data.error_set.err_count; |
| 16040 | ConstExprValue *error_array = create_const_vals(1); | 16031 | ConstExprValue *error_array = create_const_vals(1); |
| 16041 | error_array->special = ConstValSpecialStatic; | 16032 | error_array->special = ConstValSpecialStatic; |
| ... | @@ -16115,21 +16106,18 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -16115,21 +16106,18 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16115 | fields[1].special = ConstValSpecialStatic; | 16106 | fields[1].special = ConstValSpecialStatic; |
| 16116 | fields[1].type = ira->codegen->builtin_types.entry_type; | 16107 | fields[1].type = ira->codegen->builtin_types.entry_type; |
| 16117 | // @TODO ?type instead of using @typeOf(undefined) when we have no type. | 16108 | // @TODO ?type instead of using @typeOf(undefined) when we have no type. |
| 16118 | if (type_entry->data.unionation.tag_type == nullptr) | 16109 | AstNode *union_decl_node = type_entry->data.unionation.decl_node; |
| 16119 | fields[1].data.x_type = ira->codegen->builtin_types.entry_undef; | 16110 | if (union_decl_node->data.container_decl.auto_enum || |
| 16120 | else | 16111 | union_decl_node->data.container_decl.init_arg_expr != nullptr) |
| | 16112 | { |
| 16121 | fields[1].data.x_type = type_entry->data.unionation.tag_type; | 16113 | fields[1].data.x_type = type_entry->data.unionation.tag_type; |
| 16122 | | 16114 | } |
| 16123 | fields[1].data.x_type = type_entry->data.unionation.tag_type; | 16115 | else |
| | 16116 | fields[1].data.x_type = ira->codegen->builtin_types.entry_undef; |
| 16124 | // fields: []TypeInfo.UnionField | 16117 | // fields: []TypeInfo.UnionField |
| 16125 | ensure_field_index(result->type, "fields", 2); | 16118 | ensure_field_index(result->type, "fields", 2); |
| 16126 | | 16119 | |
| 16127 | TypeTableEntry *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField"); | 16120 | TypeTableEntry *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField"); |
| 16128 | // @TODO Those cause a find_struct_type_field assertion to fail (type_entry->data.structure.complete) | | |
| 16129 | // ensure_field_index(type_info_union_field_type, "name", 0); | | |
| 16130 | // ensure_field_index(type_info_union_field_type, "enum_field", 1); | | |
| 16131 | // ensure_field_index(type_info_union_field_type, "field_type", 2); | | |
| 16132 | | | |
| 16133 | uint32_t union_field_count = type_entry->data.unionation.src_field_count; | 16121 | uint32_t union_field_count = type_entry->data.unionation.src_field_count; |
| 16134 | | 16122 | |
| 16135 | ConstExprValue *union_field_array = create_const_vals(1); | 16123 | ConstExprValue *union_field_array = create_const_vals(1); |
| ... | @@ -16141,6 +16129,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -16141,6 +16129,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16141 | | 16129 | |
| 16142 | init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false); | 16130 | init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false); |
| 16143 | | 16131 | |
| | 16132 | TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField"); |
| | 16133 | |
| 16144 | for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) | 16134 | for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) |
| 16145 | { | 16135 | { |
| 16146 | TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; | 16136 | TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; |
| ... | @@ -16151,10 +16141,15 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -16151,10 +16141,15 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16151 | | 16141 | |
| 16152 | ConstExprValue *inner_fields = create_const_vals(3); | 16142 | ConstExprValue *inner_fields = create_const_vals(3); |
| 16153 | inner_fields[1].special = ConstValSpecialStatic; | 16143 | inner_fields[1].special = ConstValSpecialStatic; |
| 16154 | make_enum_field_val(&inner_fields[1], union_field->enum_field); | 16144 | inner_fields[1].type = get_maybe_type(ira->codegen, type_info_enum_field_type); |
| 16155 | inner_fields[1].data.x_struct.parent.id = ConstParentIdStruct; | 16145 | |
| 16156 | inner_fields[1].data.x_struct.parent.data.p_struct.struct_val = union_field_val; | 16146 | if (fields[1].data.x_type == ira->codegen->builtin_types.entry_undef) |
| 16157 | inner_fields[1].data.x_struct.parent.data.p_struct.field_index = 1; | 16147 | inner_fields[1].data.x_maybe = nullptr; |
| | 16148 | else |
| | 16149 | { |
| | 16150 | inner_fields[1].data.x_maybe = create_const_vals(1); |
| | 16151 | make_enum_field_val(inner_fields[1].data.x_maybe, union_field->enum_field, type_info_enum_field_type); |
| | 16152 | } |
| 16158 | | 16153 | |
| 16159 | inner_fields[2].special = ConstValSpecialStatic; | 16154 | inner_fields[2].special = ConstValSpecialStatic; |
| 16160 | inner_fields[2].type = ira->codegen->builtin_types.entry_type; | 16155 | inner_fields[2].type = ira->codegen->builtin_types.entry_type; |
| ... | @@ -16163,18 +16158,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t | ... | @@ -16163,18 +16158,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t |
| 16163 | ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name); | 16158 | ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name); |
| 16164 | init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(union_field->name), true); | 16159 | init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(union_field->name), true); |
| 16165 | | 16160 | |
| 16166 | | | |
| 16167 | union_field_val->data.x_struct.fields = inner_fields; | 16161 | union_field_val->data.x_struct.fields = inner_fields; |
| 16168 | union_field_val->data.x_struct.parent.id = ConstParentIdArray; | 16162 | union_field_val->data.x_struct.parent.id = ConstParentIdArray; |
| 16169 | union_field_val->data.x_struct.parent.data.p_array.array_val = union_field_array; | 16163 | union_field_val->data.x_struct.parent.data.p_array.array_val = union_field_array; |
| 16170 | union_field_val->data.x_struct.parent.data.p_array.elem_index = union_field_index; | 16164 | union_field_val->data.x_struct.parent.data.p_array.elem_index = union_field_index; |
| 16171 | | | |
| 16172 | // @TODO Check if TypeUnionField::enum_field == nullptr when tag_type == nullptr | | |
| 16173 | // If it is, make enum_field: ?EnumField, set it when available, done. | | |
| 16174 | } | 16165 | } |
| 16175 | | 16166 | |
| 16176 | // @TODO | 16167 | // @TODO Definitions |
| 16177 | // methods: []TypeInfo.Method | | |
| 16178 | break; | 16168 | break; |
| 16179 | } | 16169 | } |
| 16180 | } | 16170 | } |