Fix check_remove_expr_info

This commit is contained in:
gingerBill
2021-10-22 14:12:48 +01:00
parent 28af376d10
commit ef73a284e3
4 changed files with 33 additions and 22 deletions

View File

@@ -1111,9 +1111,15 @@ void check_set_expr_info(CheckerContext *c, Ast *expr, AddressingMode mode, Type
void check_remove_expr_info(CheckerContext *c, Ast *e) {
if (c->untyped != nullptr) {
map_remove(c->untyped, hash_pointer(e));
if (map_get(c->untyped, hash_pointer(e)) != nullptr) {
map_remove(c->untyped, hash_pointer(e));
GB_ASSERT(map_get(c->untyped, hash_pointer(e)) == nullptr);
}
} else {
auto *untyped = &c->info->global_untyped;
mutex_lock(&c->info->global_untyped_mutex);
map_remove(&c->info->global_untyped, hash_pointer(e));
map_remove(untyped, hash_pointer(e));
GB_ASSERT(map_get(untyped, hash_pointer(e)) == nullptr);
mutex_unlock(&c->info->global_untyped_mutex);
}
}
@@ -1191,6 +1197,7 @@ void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mode, Type *ty
prev_expr = expr;
expr->tav.mode = mode;
expr->tav.type = type;
if (mode == Addressing_Constant || mode == Addressing_Invalid) {
expr->tav.value = value;
} else if (mode == Addressing_Value && is_type_typeid(type)) {

View File

@@ -2258,9 +2258,9 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
if (tv.value.kind != ExactValue_Invalid) {
// NOTE(bill): The commented out code below is just for debug purposes only
// GB_ASSERT_MSG(!is_type_untyped(tv.type), "%s @ %s\n%s", type_to_string(tv.type), token_pos_to_string(expr_pos), expr_to_string(expr));
// if (is_type_untyped(type)) {
// gb_printf_err("%s %s\n", token_pos_to_string(expr_pos), expr_to_string(expr));
// gb_printf_err("%s %s : %s @ %p\n", token_pos_to_string(expr_pos), expr_to_string(expr), type_to_string(expr->tav.type), expr);
// GB_PANIC("%s\n", type_to_string(tv.type));
// }
// NOTE(bill): Short on constant values

View File

@@ -114,16 +114,17 @@ gb_internal isize map__add_entry(Map<T> *h, HashKey const &key) {
template <typename T>
gb_internal MapFindResult map__find(Map<T> *h, HashKey const &key) {
MapFindResult fr = {-1, -1, -1};
if (h->hashes.count > 0) {
fr.hash_index = key.key & (h->hashes.count-1);
fr.entry_index = h->hashes.data[fr.hash_index];
while (fr.entry_index >= 0) {
if (hash_key_equal(h->entries.data[fr.entry_index].key, key)) {
return fr;
}
fr.entry_prev = fr.entry_index;
fr.entry_index = h->entries.data[fr.entry_index].next;
if (h->hashes.count == 0) {
return fr;
}
fr.hash_index = key.key & (h->hashes.count-1);
fr.entry_index = h->hashes.data[fr.hash_index];
while (fr.entry_index >= 0) {
if (hash_key_equal(h->entries.data[fr.entry_index].key, key)) {
return fr;
}
fr.entry_prev = fr.entry_index;
fr.entry_index = h->entries.data[fr.entry_index].next;
}
return fr;
}
@@ -131,16 +132,17 @@ gb_internal MapFindResult map__find(Map<T> *h, HashKey const &key) {
template <typename T>
gb_internal MapFindResult map__find_from_entry(Map<T> *h, MapEntry<T> *e) {
MapFindResult fr = {-1, -1, -1};
if (h->hashes.count > 0) {
fr.hash_index = e->key.key & (h->hashes.count-1);
fr.entry_index = h->hashes.data[fr.hash_index];
while (fr.entry_index >= 0) {
if (&h->entries.data[fr.entry_index] == e) {
return fr;
}
fr.entry_prev = fr.entry_index;
fr.entry_index = h->entries.data[fr.entry_index].next;
if (h->hashes.count == 0) {
return fr;
}
fr.hash_index = e->key.key & (h->hashes.count-1);
fr.entry_index = h->hashes.data[fr.hash_index];
while (fr.entry_index >= 0) {
if (&h->entries.data[fr.entry_index] == e) {
return fr;
}
fr.entry_prev = fr.entry_index;
fr.entry_index = h->entries.data[fr.entry_index].next;
}
return fr;
}
@@ -246,6 +248,8 @@ void map__erase(Map<T> *h, MapFindResult const &fr) {
return;
}
h->entries.data[fr.entry_index] = h->entries.data[h->entries.count-1];
array_pop(&h->entries);
last = map__find(h, h->entries.data[fr.entry_index].key);
if (last.entry_prev >= 0) {
h->entries.data[last.entry_prev].next = fr.entry_index;

View File

@@ -28,9 +28,9 @@ enum AddressingMode : u8 {
};
struct TypeAndValue {
Type * type;
AddressingMode mode;
bool is_lhs; // Debug info
Type * type;
ExactValue value;
};