mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-06 13:07:59 +00:00
Fix for in enum iteration
This commit is contained in:
@@ -717,9 +717,6 @@ enum_value_to_string :: proc(v: any) -> (string, bool) {
|
||||
case u64: return get_str(v, e);
|
||||
case uint: return get_str(v, e);
|
||||
case uintptr: return get_str(v, e);
|
||||
|
||||
case f32: return get_str(v, e);
|
||||
case f64: return get_str(v, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,8 +775,6 @@ enum_value_to_u64 :: proc(ev: runtime.Type_Info_Enum_Value) -> u64 {
|
||||
case u64: return u64(i);
|
||||
case uint: return u64(i);
|
||||
case uintptr: return u64(i);
|
||||
case f32: return u64(i);
|
||||
case f64: return u64(i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ Type_Info_Enum_Value :: union {
|
||||
rune,
|
||||
i8, i16, i32, i64, int,
|
||||
u8, u16, u32, u64, uint, uintptr,
|
||||
f32, f64,
|
||||
};
|
||||
|
||||
// Variant Types
|
||||
|
||||
@@ -299,7 +299,7 @@ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column
|
||||
|
||||
fd := os.stderr;
|
||||
__print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
||||
os.write_string(fd, " Invalid type assertion from");
|
||||
os.write_string(fd, " Invalid type assertion from ");
|
||||
__print_typeid(fd, from);
|
||||
os.write_string(fd, " to ");
|
||||
__print_typeid(fd, to);
|
||||
|
||||
@@ -1839,23 +1839,10 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) {
|
||||
|
||||
// Cast between pointers
|
||||
if (is_type_pointer(src) && is_type_pointer(dst)) {
|
||||
#if 0
|
||||
Type *s = base_type(type_deref(src));
|
||||
if (is_type_union(s)) {
|
||||
// NOTE(bill): Should the error be here?!
|
||||
// NOTE(bill): This error should suppress the next casting error as it's at the same position
|
||||
gbString xs = type_to_string(x);
|
||||
gbString ys = type_to_string(y);
|
||||
error(operand->expr, "Cannot cast from a union pointer '%s' to '%s', try using 'union_cast' or cast to a 'rawptr'", xs, ys);
|
||||
gb_string_free(ys);
|
||||
gb_string_free(xs);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
// (u)int <-> pointer
|
||||
// uintptr <-> pointer
|
||||
if (is_type_uintptr(src) && is_type_pointer(dst)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
17
src/ir.cpp
17
src/ir.cpp
@@ -6419,11 +6419,12 @@ void ir_build_range_enum(irProcedure *proc, Type *enum_type, Type *val_type, irV
|
||||
Type *enum_ptr = alloc_type_pointer(t);
|
||||
t = base_type(t);
|
||||
Type *core_elem = core_type(t);
|
||||
GB_ASSERT(t->kind == Type_Enum);
|
||||
i64 enum_count = t->Enum.fields.count;
|
||||
irValue *max_count = ir_const_int(enum_count);
|
||||
|
||||
irValue *ti = ir_type_info(proc, t);
|
||||
irValue *variant = ir_emit_struct_ep(proc, ti, 2);
|
||||
irValue *variant = ir_emit_struct_ep(proc, ti, 3);
|
||||
irValue *eti_ptr = ir_emit_conv(proc, variant, t_type_info_enum_ptr);
|
||||
irValue *values = ir_emit_load(proc, ir_emit_struct_ep(proc, eti_ptr, 2));
|
||||
irValue *values_data = ir_slice_elem(proc, values);
|
||||
@@ -6448,10 +6449,9 @@ void ir_build_range_enum(irProcedure *proc, Type *enum_type, Type *val_type, irV
|
||||
|
||||
irValue *val = nullptr;
|
||||
if (val_type != nullptr) {
|
||||
if (is_type_float(core_elem)) {
|
||||
irValue *f = ir_emit_load(proc, ir_emit_conv(proc, val_ptr, t_f64_ptr));
|
||||
val = ir_emit_conv(proc, f, t);
|
||||
} else if (is_type_integer(core_elem)) {
|
||||
GB_ASSERT(are_types_identical(enum_type, val_type));
|
||||
|
||||
if (is_type_integer(core_elem)) {
|
||||
irValue *i = ir_emit_load(proc, ir_emit_conv(proc, val_ptr, t_i64_ptr));
|
||||
val = ir_emit_conv(proc, i, t);
|
||||
} else {
|
||||
@@ -6831,7 +6831,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
|
||||
if (is_ast_range(expr)) {
|
||||
ir_build_range_interval(proc, &expr->BinaryExpr, val0_type, &val, &key, &loop, &done);
|
||||
} else if (tav.mode == Addressing_Type) {
|
||||
ir_build_range_enum(proc, tav.type, val0_type, &val, &key, &loop, &done);
|
||||
ir_build_range_enum(proc, type_deref(tav.type), val0_type, &val, &key, &loop, &done);
|
||||
} else {
|
||||
Type *expr_type = type_of_expr(rs->expr);
|
||||
Type *et = base_type(type_deref(expr_type));
|
||||
@@ -7936,10 +7936,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
irValue *value_array = ir_generate_array(m, t_type_info_enum_value, fields.count,
|
||||
str_lit("__$enum_values"), cast(i64)entry_index);
|
||||
|
||||
bool is_value_int = is_type_integer(t->Enum.base_type);
|
||||
if (!is_value_int) {
|
||||
GB_ASSERT(is_type_float(t->Enum.base_type));
|
||||
}
|
||||
GB_ASSERT(is_type_integer(t->Enum.base_type));
|
||||
|
||||
for_array(i, fields) {
|
||||
irValue *name_ep = ir_emit_array_epi(proc, name_array, cast(i32)i);
|
||||
|
||||
Reference in New Issue
Block a user