Fix case label type conversions.

The previous method made too many assumptions.
This commit is contained in:
Bill Currie 2011-03-06 11:41:01 +09:00
parent fe4df03896
commit dc7a78b2ff

View file

@ -132,13 +132,18 @@ case_label_expr (switch_block_t *switch_block, expr_t *value)
type_t *val_type = get_type (value); type_t *val_type = get_type (value);
if (!type_assignable (type, get_type (value))) if (!type_assignable (type, get_type (value)))
return error (value, "type mismatch in case label"); return error (value, "type mismatch in case label");
if (type != val_type) { if (is_integral (type) && is_integral (val_type)) {
//FIXME shorts? // do nothing
if (type == &type_float) debug (value, "integeral label used in integral switch");
value->e.value.v.float_val = value->e.value.v.integer_val; } else if (is_integral (type) && is_float (val_type)) {
else warning (value, "float label used in integral switch");
value->e.value.v.integer_val = value->e.value.v.float_val; value = new_integer_expr (expr_float (value));
value->e.value.type = type->type; } else if (is_float (type) && is_integral (val_type)) {
debug (value, "integeral label used in float switch");
value = new_float_expr (expr_integer (value));
} else if (is_float (type) && is_float (val_type)) {
// do nothing
debug (value, "float label used in float switch");
} }
} }
cl->value = value; cl->value = value;