mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Remove the need for parapoly to print an enum as a string
This commit is contained in:
+8
-25
@@ -797,18 +797,15 @@ enum_value_to_string :: proc(val: any) -> (string, bool) {
|
|||||||
#partial switch e in type_info.variant {
|
#partial switch e in type_info.variant {
|
||||||
case: return "", false;
|
case: return "", false;
|
||||||
case runtime.Type_Info_Enum:
|
case runtime.Type_Info_Enum:
|
||||||
get_str :: proc(i: $T, e: runtime.Type_Info_Enum) -> (string, bool) {
|
get_str :: proc(data: rawptr, e: runtime.Type_Info_Enum) -> (string, bool) {
|
||||||
if reflect.is_string(e.base) {
|
if len(e.values) == 0 {
|
||||||
for val, idx in e.values {
|
|
||||||
if v, ok := val.(T); ok && v == i {
|
|
||||||
return e.names[idx], true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if len(e.values) == 0 {
|
|
||||||
return "", true;
|
return "", true;
|
||||||
} else {
|
} else {
|
||||||
for val, idx in e.values {
|
for _, idx in e.values {
|
||||||
if v, ok := val.(T); ok && v == i {
|
val := &e.values[idx];
|
||||||
|
// NOTE(bill): Removes need for parametric polymorphic check
|
||||||
|
res := mem.compare_ptrs(val, data, e.base.size);
|
||||||
|
if res == 0 {
|
||||||
return e.names[idx], true;
|
return e.names[idx], true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -816,21 +813,7 @@ enum_value_to_string :: proc(val: any) -> (string, bool) {
|
|||||||
return "", false;
|
return "", false;
|
||||||
}
|
}
|
||||||
|
|
||||||
a := any{v.data, runtime.type_info_base(e.base).id};
|
return get_str(v.data, e);
|
||||||
switch v in a {
|
|
||||||
case rune: return get_str(v, e);
|
|
||||||
case i8: return get_str(v, e);
|
|
||||||
case i16: return get_str(v, e);
|
|
||||||
case i32: return get_str(v, e);
|
|
||||||
case i64: return get_str(v, e);
|
|
||||||
case int: return get_str(v, e);
|
|
||||||
case u8: return get_str(v, e);
|
|
||||||
case u16: return get_str(v, e);
|
|
||||||
case u32: return get_str(v, e);
|
|
||||||
case u64: return get_str(v, e);
|
|
||||||
case uint: return get_str(v, e);
|
|
||||||
case uintptr: return get_str(v, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", false;
|
return "", false;
|
||||||
|
|||||||
Reference in New Issue
Block a user