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...@@ -5827,12 +5827,25 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
5827 return true;5827 return true;
5828 }5828 }
5829 } else if ((other_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) ||5829 } 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 )) {5830 (other_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt ))
5831 return true;5831 {
5832 } else if ((other_type->id == TypeTableEntryIdMaybe &&
5833 other_type->data.maybe.child_type->id == TypeTableEntryIdInt &&
5834 const_val->data.x_bignum.kind == BigNumKindInt)) {
5835 return true;5832 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 }
5836 }5849 }
58375850
5838 const char *num_lit_str = (const_val->data.x_bignum.kind == BigNumKindFloat) ? "float" : "integer";5851 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,...@@ -5898,11 +5911,9 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
5898 // implicit conversion from T to %?T5911 // implicit conversion from T to %?T
5899 if (expected_type->id == TypeTableEntryIdErrorUnion &&5912 if (expected_type->id == TypeTableEntryIdErrorUnion &&
5900 expected_type->data.error.child_type->id == TypeTableEntryIdMaybe &&5913 expected_type->data.error.child_type->id == TypeTableEntryIdMaybe &&
5901 ir_types_match_with_implicit_cast(5914 ir_types_match_with_implicit_cast(ira,
5902 ira,
5903 expected_type->data.error.child_type->data.maybe.child_type,5915 expected_type->data.error.child_type->data.maybe.child_type,
5904 actual_type,5916 actual_type, value))
5905 value))
5906 {5917 {
5907 return ImplicitCastMatchResultYes;5918 return ImplicitCastMatchResultYes;
5908 }5919 }
...@@ -7083,10 +7094,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -7083,10 +7094,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
7083 // explicit cast from T to %?T7094 // explicit cast from T to %?T
7084 if (wanted_type->id == TypeTableEntryIdErrorUnion &&7095 if (wanted_type->id == TypeTableEntryIdErrorUnion &&
7085 wanted_type->data.error.child_type->id == TypeTableEntryIdMaybe &&7096 wanted_type->data.error.child_type->id == TypeTableEntryIdMaybe &&
7086 actual_type->id != TypeTableEntryIdMaybe) {7097 actual_type->id != TypeTableEntryIdMaybe)
7087 if (types_match_const_cast_only(wanted_type->data.error.child_type->data.maybe.child_type, actual_type) || 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) ||
7088 actual_type->id == TypeTableEntryIdNullLit ||7101 actual_type->id == TypeTableEntryIdNullLit ||
7089 actual_type->id == TypeTableEntryIdNumLitInt ) {7102 actual_type->id == TypeTableEntryIdNumLitInt ||
7103 actual_type->id == TypeTableEntryIdNumLitFloat)
7104 {
7090 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error.child_type, value);7105 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error.child_type, value);
7091 if (type_is_invalid(cast1->value.type))7106 if (type_is_invalid(cast1->value.type))
7092 return ira->codegen->invalid_instruction;7107 return ira->codegen->invalid_instruction;
...@@ -7094,7 +7109,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -7094,7 +7109,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
7094 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);7109 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
7095 if (type_is_invalid(cast2->value.type))7110 if (type_is_invalid(cast2->value.type))
7096 return ira->codegen->invalid_instruction;7111 return ira->codegen->invalid_instruction;
7097 7112
7098 return cast2;7113 return cast2;
7099 }7114 }
7100 }7115 }