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...@@ -15747,7 +15747,7 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz
15747 (buf_deinit(field_name_buf), true));15747 (buf_deinit(field_name_buf), true));
15748}15748}
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) {
15751 assert(struct_val->type->id == TypeTableEntryIdStruct);15751 assert(struct_val->type->id == TypeTableEntryIdStruct);
15752 assert(parent->type != nullptr && !type_is_invalid(parent->type));15752 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...@@ -15756,10 +15756,13 @@ static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExpr
15756 case TypeTableEntryIdArray:15756 case TypeTableEntryIdArray:
15757 zig_panic("TODO - Only expected struct or union parent.");15757 zig_panic("TODO - Only expected struct or union parent.");
15758 case TypeTableEntryIdStruct:15758 case TypeTableEntryIdStruct:
15759 assert(parent_field_index >= 0);
15759 struct_val->data.x_struct.parent.id = ConstParentIdStruct;15760 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;
15761 break;15763 break;
15762 case TypeTableEntryIdUnion:15764 case TypeTableEntryIdUnion:
15765 assert(parent_field_index == -1);
15763 struct_val->data.x_struct.parent.id = ConstParentIdUnion;15766 struct_val->data.x_struct.parent.id = ConstParentIdUnion;
15764 struct_val->data.x_struct.parent.data.p_union.union_val = parent;15767 struct_val->data.x_struct.parent.data.p_union.union_val = parent;
15765 break;15768 break;
...@@ -15768,7 +15771,8 @@ static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExpr...@@ -15768,7 +15771,8 @@ static void ir_type_info_struct_set_parent(ConstExprValue *struct_val, ConstExpr
15768 }15771 }
15769}15772}
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)
15772{15776{
15773 assert(type_entry != nullptr);15777 assert(type_entry != nullptr);
15774 assert(!type_is_invalid(type_entry));15778 assert(!type_is_invalid(type_entry));
...@@ -15802,7 +15806,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15802,7 +15806,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15802 ConstExprValue *fields = create_const_vals(2);15806 ConstExprValue *fields = create_const_vals(2);
15803 payload->data.x_struct.fields = fields;15807 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
15807 // is_signed: bool15811 // is_signed: bool
15808 ensure_field_index(payload->type, "is_signed", 0);15812 ensure_field_index(payload->type, "is_signed", 0);
...@@ -15829,7 +15833,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15829,7 +15833,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15829 ConstExprValue *fields = create_const_vals(1);15833 ConstExprValue *fields = create_const_vals(1);
15830 payload->data.x_struct.fields = fields;15834 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
15834 // bits: u815838 // bits: u8
15835 ensure_field_index(payload->type, "bits", 0);15839 ensure_field_index(payload->type, "bits", 0);
...@@ -15851,7 +15855,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15851,7 +15855,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15851 ConstExprValue *fields = create_const_vals(4);15855 ConstExprValue *fields = create_const_vals(4);
15852 payload->data.x_struct.fields = fields;15856 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
15856 // is_const: bool15860 // is_const: bool
15857 ensure_field_index(payload->type, "is_const", 0);15861 ensure_field_index(payload->type, "is_const", 0);
...@@ -15880,7 +15884,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15880,7 +15884,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15880 union_val->special = ConstValSpecialStatic;15884 union_val->special = ConstValSpecialStatic;
15881 union_val->type = type_info_type->data.x_type;15885 union_val->type = type_info_type->data.x_type;
15882 bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.pointer.child_type->id));15886 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);
15884 fields[3].data.x_ptr.data.ref.pointee = union_val;15888 fields[3].data.x_ptr.data.ref.pointee = union_val;
15885 return payload;15889 return payload;
15886 }15890 }
...@@ -15896,7 +15900,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15896,7 +15900,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15896 ConstExprValue *fields = create_const_vals(2);15900 ConstExprValue *fields = create_const_vals(2);
15897 payload->data.x_struct.fields = fields;15901 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
15901 // len: usize15905 // len: usize
15902 ensure_field_index(payload->type, "len", 0);15906 ensure_field_index(payload->type, "len", 0);
...@@ -15915,7 +15919,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15915,7 +15919,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15915 union_val->special = ConstValSpecialStatic;15919 union_val->special = ConstValSpecialStatic;
15916 union_val->type = type_info_type->data.x_type;15920 union_val->type = type_info_type->data.x_type;
15917 bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.array.child_type->id));15921 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);
15919 fields[1].data.x_ptr.data.ref.pointee = union_val;15923 fields[1].data.x_ptr.data.ref.pointee = union_val;
15920 return payload;15924 return payload;
15921 }15925 }
...@@ -15931,7 +15935,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15931,7 +15935,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15931 ConstExprValue *fields = create_const_vals(1);15935 ConstExprValue *fields = create_const_vals(1);
15932 payload->data.x_struct.fields = fields;15936 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
15936 // child: &TypeInfo15940 // child: &TypeInfo
15937 ensure_field_index(payload->type, "child", 0);15941 ensure_field_index(payload->type, "child", 0);
...@@ -15945,7 +15949,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15945,7 +15949,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15945 union_val->special = ConstValSpecialStatic;15949 union_val->special = ConstValSpecialStatic;
15946 union_val->type = type_info_type->data.x_type;15950 union_val->type = type_info_type->data.x_type;
15947 bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.maybe.child_type->id));15951 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);
15949 fields[0].data.x_ptr.data.ref.pointee = union_val;15953 fields[0].data.x_ptr.data.ref.pointee = union_val;
15950 return payload;15954 return payload;
15951 }15955 }
...@@ -15961,7 +15965,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15961,7 +15965,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15961 ConstExprValue *fields = create_const_vals(1);15965 ConstExprValue *fields = create_const_vals(1);
15962 payload->data.x_struct.fields = fields;15966 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
15966 // child: ?&TypeInfo15970 // child: ?&TypeInfo
15967 ensure_field_index(payload->type, "child", 0);15971 ensure_field_index(payload->type, "child", 0);
...@@ -15990,7 +15994,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p...@@ -15990,7 +15994,7 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, ConstExprValue *p
15990 union_val->special = ConstValSpecialStatic;15994 union_val->special = ConstValSpecialStatic;
15991 union_val->type = type_info_type->data.x_type;15995 union_val->type = type_info_type->data.x_type;
15992 bigint_init_unsigned(&union_val->data.x_union.tag, type_id_index(type_entry->data.promise.result_type->id));15996 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
15995 maybe_value->data.x_ptr.data.ref.pointee = union_val;15999 maybe_value->data.x_ptr.data.ref.pointee = union_val;
15996 fields[0].data.x_maybe = maybe_value;16000 fields[0].data.x_maybe = maybe_value;
...@@ -16017,7 +16021,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -16017,7 +16021,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
16017 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);16021 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
16018 out_val->type = result_type;16022 out_val->type = result_type;
16019 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry->id));16023 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
16022 return result_type;16026 return result_type;
16023}16027}