authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-17 20:15:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-17 20:15:19-04:00
logc7852bd596a632644e9e94e785f32e6ddcf00c16
tree8c7cb70fab20076fa7263d835ce53431c8644d7c
parent32665856064dde5a08a64de8641c8bec9c6f352f

minor clean ups from previous commit


2 files changed, 28 insertions(+), 21 deletions(-)

.vscode/settings.json deleted-8
......@@ -1,8 +0,0 @@
1{
2 "files.associations": {
3 "*.zig": "c",
4 "type_traits": "cpp",
5 "*.inc": "cpp",
6 "thread": "cpp"
7 }
8}
\ No newline at end of file
src/ir.cpp+28-13
......@@ -5827,12 +5827,25 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
58275827 return true;
58285828 }
58295829 } else if ((other_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) ||
5830 (other_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt )) {
5831 return true;
5832 } else if ((other_type->id == TypeTableEntryIdMaybe &&
5833 other_type->data.maybe.child_type->id == TypeTableEntryIdInt &&
5834 const_val->data.x_bignum.kind == BigNumKindInt)) {
5830 (other_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt ))
5831 {
58355832 return true;
5833 } else if (other_type->id == TypeTableEntryIdMaybe) {
5834 TypeTableEntry *child_type = other_type->data.maybe.child_type;
5835 if ((child_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) ||
5836 (child_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt ))
5837 {
5838 return true;
5839 } else if (child_type->id == TypeTableEntryIdInt && const_val->data.x_bignum.kind == BigNumKindInt) {
5840 if (bignum_fits_in_bits(&const_val->data.x_bignum,
5841 child_type->data.integral.bit_count,
5842 child_type->data.integral.is_signed))
5843 {
5844 return true;
5845 }
5846 } else if (child_type->id == TypeTableEntryIdFloat && const_val->data.x_bignum.kind == BigNumKindFloat) {
5847 return true;
5848 }
58365849 }
58375850
58385851 const char *num_lit_str = (const_val->data.x_bignum.kind == BigNumKindFloat) ? "float" : "integer";
......@@ -5898,11 +5911,9 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
58985911 // implicit conversion from T to %?T
58995912 if (expected_type->id == TypeTableEntryIdErrorUnion &&
59005913 expected_type->data.error.child_type->id == TypeTableEntryIdMaybe &&
5901 ir_types_match_with_implicit_cast(
5902 ira,
5914 ir_types_match_with_implicit_cast(ira,
59035915 expected_type->data.error.child_type->data.maybe.child_type,
5904 actual_type,
5905 value))
5916 actual_type, value))
59065917 {
59075918 return ImplicitCastMatchResultYes;
59085919 }
......@@ -7083,10 +7094,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
70837094 // explicit cast from T to %?T
70847095 if (wanted_type->id == TypeTableEntryIdErrorUnion &&
70857096 wanted_type->data.error.child_type->id == TypeTableEntryIdMaybe &&
7086 actual_type->id != TypeTableEntryIdMaybe) {
7087 if (types_match_const_cast_only(wanted_type->data.error.child_type->data.maybe.child_type, actual_type) ||
7097 actual_type->id != TypeTableEntryIdMaybe)
7098 {
7099 TypeTableEntry *wanted_child_type = wanted_type->data.error.child_type->data.maybe.child_type;
7100 if (types_match_const_cast_only(wanted_child_type, actual_type) ||
70887101 actual_type->id == TypeTableEntryIdNullLit ||
7089 actual_type->id == TypeTableEntryIdNumLitInt ) {
7102 actual_type->id == TypeTableEntryIdNumLitInt ||
7103 actual_type->id == TypeTableEntryIdNumLitFloat)
7104 {
70907105 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error.child_type, value);
70917106 if (type_is_invalid(cast1->value.type))
70927107 return ira->codegen->invalid_instruction;
......@@ -7094,7 +7109,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
70947109 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
70957110 if (type_is_invalid(cast2->value.type))
70967111 return ira->codegen->invalid_instruction;
7097
7112
70987113 return cast2;
70997114 }
71007115 }