aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-04-17 20:15:19 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-04-17 20:15:19 -0400
commitc7852bd596a632644e9e94e785f32e6ddcf00c16 (patch)
tree8c7cb70fab20076fa7263d835ce53431c8644d7c /src
parent32665856064dde5a08a64de8641c8bec9c6f352f (diff)
downloadzig-c7852bd596a632644e9e94e785f32e6ddcf00c16.tar.gz
zig-c7852bd596a632644e9e94e785f32e6ddcf00c16.zip
minor clean ups from previous commit
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 1c9f1c5fe2..9b6cb8ab36 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -5827,12 +5827,25 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
return true;
}
} else if ((other_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) ||
- (other_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt )) {
- return true;
- } else if ((other_type->id == TypeTableEntryIdMaybe &&
- other_type->data.maybe.child_type->id == TypeTableEntryIdInt &&
- const_val->data.x_bignum.kind == BigNumKindInt)) {
+ (other_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt ))
+ {
return true;
+ } else if (other_type->id == TypeTableEntryIdMaybe) {
+ TypeTableEntry *child_type = other_type->data.maybe.child_type;
+ if ((child_type->id == TypeTableEntryIdNumLitFloat && const_val->data.x_bignum.kind == BigNumKindFloat) ||
+ (child_type->id == TypeTableEntryIdNumLitInt && const_val->data.x_bignum.kind == BigNumKindInt ))
+ {
+ return true;
+ } else if (child_type->id == TypeTableEntryIdInt && const_val->data.x_bignum.kind == BigNumKindInt) {
+ if (bignum_fits_in_bits(&const_val->data.x_bignum,
+ child_type->data.integral.bit_count,
+ child_type->data.integral.is_signed))
+ {
+ return true;
+ }
+ } else if (child_type->id == TypeTableEntryIdFloat && const_val->data.x_bignum.kind == BigNumKindFloat) {
+ return true;
+ }
}
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,
// implicit conversion from T to %?T
if (expected_type->id == TypeTableEntryIdErrorUnion &&
expected_type->data.error.child_type->id == TypeTableEntryIdMaybe &&
- ir_types_match_with_implicit_cast(
- ira,
+ ir_types_match_with_implicit_cast(ira,
expected_type->data.error.child_type->data.maybe.child_type,
- actual_type,
- value))
+ actual_type, value))
{
return ImplicitCastMatchResultYes;
}
@@ -7083,10 +7094,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// explicit cast from T to %?T
if (wanted_type->id == TypeTableEntryIdErrorUnion &&
wanted_type->data.error.child_type->id == TypeTableEntryIdMaybe &&
- actual_type->id != TypeTableEntryIdMaybe) {
- if (types_match_const_cast_only(wanted_type->data.error.child_type->data.maybe.child_type, actual_type) ||
+ actual_type->id != TypeTableEntryIdMaybe)
+ {
+ TypeTableEntry *wanted_child_type = wanted_type->data.error.child_type->data.maybe.child_type;
+ if (types_match_const_cast_only(wanted_child_type, actual_type) ||
actual_type->id == TypeTableEntryIdNullLit ||
- actual_type->id == TypeTableEntryIdNumLitInt ) {
+ actual_type->id == TypeTableEntryIdNumLitInt ||
+ actual_type->id == TypeTableEntryIdNumLitFloat)
+ {
IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error.child_type, value);
if (type_is_invalid(cast1->value.type))
return ira->codegen->invalid_instruction;
@@ -7094,7 +7109,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
if (type_is_invalid(cast2->value.type))
return ira->codegen->invalid_instruction;
-
+
return cast2;
}
}