mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Remove constant from switch for strings
This commit is contained in:
+8
-10
@@ -745,7 +745,8 @@ void check_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (a1.mode != Addressing_Invalid &&
|
if (a1.mode != Addressing_Invalid &&
|
||||||
lhs.mode == Addressing_Constant && rhs.mode == Addressing_Constant) {
|
lhs.mode == Addressing_Constant && rhs.mode == Addressing_Constant &&
|
||||||
|
!is_type_string(lhs.type) && !is_type_string(rhs.type)) {
|
||||||
ExactValue start = lhs.value;
|
ExactValue start = lhs.value;
|
||||||
ExactValue end = rhs.value;
|
ExactValue end = rhs.value;
|
||||||
ExactValue one = exact_value_i64(1);
|
ExactValue one = exact_value_i64(1);
|
||||||
@@ -950,9 +951,9 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<bool> seen = {}; // Key: Type *
|
PtrSet<Type *> seen = {};
|
||||||
map_init(&seen, heap_allocator());
|
ptr_set_init(&seen, heap_allocator());
|
||||||
defer (map_destroy(&seen));
|
defer (ptr_set_destroy(&seen));
|
||||||
|
|
||||||
for_array(i, bs->stmts) {
|
for_array(i, bs->stmts) {
|
||||||
AstNode *stmt = bs->stmts[i];
|
AstNode *stmt = bs->stmts[i];
|
||||||
@@ -995,9 +996,7 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
|
|||||||
GB_PANIC("Unknown type to type switch statement");
|
GB_PANIC("Unknown type to type switch statement");
|
||||||
}
|
}
|
||||||
|
|
||||||
HashKey key = hash_type(y.type);
|
if (ptr_set_exists(&seen, y.type)) {
|
||||||
bool *found = map_get(&seen, key);
|
|
||||||
if (found) {
|
|
||||||
TokenPos pos = cc->token.pos;
|
TokenPos pos = cc->token.pos;
|
||||||
gbString expr_str = expr_to_string(y.expr);
|
gbString expr_str = expr_to_string(y.expr);
|
||||||
error(y.expr,
|
error(y.expr,
|
||||||
@@ -1008,7 +1007,7 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
|
|||||||
gb_string_free(expr_str);
|
gb_string_free(expr_str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
map_set(&seen, key, cast(bool)true);
|
ptr_set_add(&seen, y.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1053,8 +1052,7 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
|
|||||||
|
|
||||||
for_array(i, variants) {
|
for_array(i, variants) {
|
||||||
Type *t = variants[i];
|
Type *t = variants[i];
|
||||||
auto found = map_get(&seen, hash_type(t));
|
if (!ptr_set_exists(&seen, t)) {
|
||||||
if (!found) {
|
|
||||||
array_add(&unhandled, t);
|
array_add(&unhandled, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -117,12 +117,12 @@ struct TypeStruct {
|
|||||||
TYPE_KIND(Slice, struct { Type *elem; }) \
|
TYPE_KIND(Slice, struct { Type *elem; }) \
|
||||||
TYPE_KIND(DynamicArray, struct { Type *elem; }) \
|
TYPE_KIND(DynamicArray, struct { Type *elem; }) \
|
||||||
TYPE_KIND(Map, struct { \
|
TYPE_KIND(Map, struct { \
|
||||||
Type * key; \
|
Type *key; \
|
||||||
Type * value; \
|
Type *value; \
|
||||||
Type * entry_type; \
|
Type *entry_type; \
|
||||||
Type * generated_struct_type; \
|
Type *generated_struct_type; \
|
||||||
Type * internal_type; \
|
Type *internal_type; \
|
||||||
Type * lookup_result_type; \
|
Type *lookup_result_type; \
|
||||||
}) \
|
}) \
|
||||||
TYPE_KIND(Struct, TypeStruct) \
|
TYPE_KIND(Struct, TypeStruct) \
|
||||||
TYPE_KIND(Enum, struct { \
|
TYPE_KIND(Enum, struct { \
|
||||||
|
|||||||
Reference in New Issue
Block a user