authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-25 11:59:35+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2018-04-25 11:59:35+03:00
log2606993cb48e69015a9152b860e48fca29d330e1
treefcf8dc4e910ee9ac83a1dc2cd871068a701b76a1
parentd68aea4f35fe935f3bf80c86dac4da7c4b88dc5b

Fixed ir_type_info_struct_set_parent for struct parents.


1 files changed, 18 insertions(+), 14 deletions(-)

src/ir.cpp+18-14
......@@ -15747,7 +15747,7 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz
1574715747 (buf_deinit(field_name_buf), true));
1574815748}
1574915749
15750static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExprValue *parent) {
15750static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExprValue *parent, ssize_t parent_field_index) {
1575115751 assert(struct_val->type->id == TypeTableEntryIdStruct);
1575215752 assert(parent->type != nullptr && !type_is_invalid(parent->type));
1575315753
......@@ -15756,10 +15756,13 @@ static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExpr
1575615756 case TypeTableEntryIdArray:
1575715757 zig_panic("TODO - Only expected struct or union parent.");
1575815758 case TypeTableEntryIdStruct:
15759 assert(parent_field_index >= 0);
1575915760 struct_val->data.x_struct.parent.id = ConstParentIdStruct;
15760 struct_val->data.x_struct.parent.data.p_union.union_val = parent;
15761 struct_val->data.x_struct.parent.data.p_struct.struct_val = parent;
15762 struct_val->data.x_struct.parent.data.p_struct.field_index = parent_field_index;
1576115763 break;
1576215764 case TypeTableEntryIdUnion:
15765 assert(parent_field_index == -1);
1576315766 struct_val->data.x_struct.parent.id = ConstParentIdUnion;
1576415767 struct_val->data.x_struct.parent.data.p_union.union_val = parent;
1576515768 break;
......@@ -15768,7 +15771,8 @@ static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExpr
1576815771 }
1576915772}
1577015773
15771static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent, TypeTableEntry *type_entry)
15774static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *parent,
15775 ssize_t parent_field_index, TypeTableEntry *type_entry)
1577215776{
1577315777 assert(type_entry != nullptr);
1577415778 assert(!type_is_invalid(type_entry));
......@@ -15802,7 +15806,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1580215806 ConstExprValue *fields = create_const_vals(2);
1580315807 payload->data.x_struct.fields = fields;
1580415808
15805 ir_type_info_struct_set_parent(payload, parent);
15809 ir_type_info_struct_set_parent(payload, parent, parent_field_index);
1580615810
1580715811 // is_signed: bool
1580815812 ensure_field_index(payload->type, "is_signed", 0);
......@@ -15829,7 +15833,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1582915833 ConstExprValue *fields = create_const_vals(1);
1583015834 payload->data.x_struct.fields = fields;
1583115835
15832 ir_type_info_struct_set_parent(payload, parent);
15836 ir_type_info_struct_set_parent(payload, parent, parent_field_index);
1583315837
1583415838 // bits: u8
1583515839 ensure_field_index(payload->type, "bits", 0);
......@@ -15851,7 +15855,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1585115855 ConstExprValue *fields = create_const_vals(4);
1585215856 payload->data.x_struct.fields = fields;
1585315857
15854 ir_type_info_struct_set_parent(payload, parent);
15858 ir_type_info_struct_set_parent(payload, parent, parent_field_index);
1585515859
1585615860 // is_const: bool
1585715861 ensure_field_index(payload->type, "is_const", 0);
......@@ -15880,7 +15884,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1588015884 union_val->special = ConstValSpecialStatic;
1588115885 union_val->type = type_info_type->data.x_type;
1588215886 bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.pointer.child_type->id));
15883 union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, type_entry->data.pointer.child_type);
15887 union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, type_entry->data.pointer.child_type);
1588415888 fields[3].data.x_ptr.data.ref.pointee = union_val;
1588515889 return payload;
1588615890 }
......@@ -15896,7 +15900,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1589615900 ConstExprValue *fields = create_const_vals(2);
1589715901 payload->data.x_struct.fields = fields;
1589815902
15899 ir_type_info_struct_set_parent(payload, parent);
15903 ir_type_info_struct_set_parent(payload, parent, parent_field_index);
1590015904
1590115905 // len: usize
1590215906 ensure_field_index(payload->type, "len", 0);
......@@ -15915,7 +15919,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1591515919 union_val->special = ConstValSpecialStatic;
1591615920 union_val->type = type_info_type->data.x_type;
1591715921 bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.array.child_type->id));
15918 union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, type_entry->data.array.child_type);
15922 union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, type_entry->data.array.child_type);
1591915923 fields[1].data.x_ptr.data.ref.pointee = union_val;
1592015924 return payload;
1592115925 }
......@@ -15931,7 +15935,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1593115935 ConstExprValue *fields = create_const_vals(1);
1593215936 payload->data.x_struct.fields = fields;
1593315937
15934 ir_type_info_struct_set_parent(payload, parent);
15938 ir_type_info_struct_set_parent(payload, parent, parent_field_index);
1593515939
1593615940 // child: &TypeInfo
1593715941 ensure_field_index(payload->type, "child", 0);
......@@ -15945,7 +15949,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1594515949 union_val->special = ConstValSpecialStatic;
1594615950 union_val->type = type_info_type->data.x_type;
1594715951 bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.maybe.child_type->id));
15948 union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, type_entry->data.maybe.child_type);
15952 union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, type_entry->data.maybe.child_type);
1594915953 fields[0].data.x_ptr.data.ref.pointee = union_val;
1595015954 return payload;
1595115955 }
......@@ -15961,7 +15965,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1596115965 ConstExprValue *fields = create_const_vals(1);
1596215966 payload->data.x_struct.fields = fields;
1596315967
15964 ir_type_info_struct_set_parent(payload, parent);
15968 ir_type_info_struct_set_parent(payload, parent, parent_field_index);
1596515969
1596615970 // child: ?&TypeInfo
1596715971 ensure_field_index(payload->type, "child", 0);
......@@ -15990,7 +15994,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
1599015994 union_val->special = ConstValSpecialStatic;
1599115995 union_val->type = type_info_type->data.x_type;
1599215996 bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.promise.result_type->id));
15993 union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, type_entry->data.promise.result_type);
15997 union_val->data.x_union.payload = ir_make_type_info_value(ira, union_val, -1, type_entry->data.promise.result_type);
1599415998
1599515999 maybe_value->data.x_ptr.data.ref.pointee = union_val;
1599616000 fields[0].data.x_maybe = maybe_value;
......@@ -16017,7 +16021,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
1601716021 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1601816022 out_val->type = result_type;
1601916023 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry->id));
16020 out_val->data.x_union.payload = ir_make_type_info_value(ira, out_val, type_entry);
16024 out_val->data.x_union.payload = ir_make_type_info_value(ira, out_val, -1, type_entry);
1602116025
1602216026 return result_type;
1602316027}