aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-10-22 14:12:48 +0100
committergingerBill <bill@gingerbill.org>2021-10-22 14:12:48 +0100
commitef73a284e3e438a25a4e329d59057cfa8cddf44c (patch)
tree5b4e37bf64f4e8bc43b38a66ba46e103864f548a /src
parent28af376d103da1b7820032de0b6d8fc6ca9d6d3a (diff)
Fix check_remove_expr_info
Diffstat (limited to 'src')
-rw-r--r--src/checker.cpp9
-rw-r--r--src/llvm_backend_expr.cpp4
-rw-r--r--src/map.cpp40
-rw-r--r--src/parser.hpp2
4 files changed, 33 insertions, 22 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index d3c0080de..ec20d45d6 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -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)) {
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp
index caeae2fb0..6ad0e1191 100644
--- a/src/llvm_backend_expr.cpp
+++ b/src/llvm_backend_expr.cpp
@@ -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
diff --git a/src/map.cpp b/src/map.cpp
index 55eb4fbce..3a34764bf 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -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;
diff --git a/src/parser.hpp b/src/parser.hpp
index f1779bdbc..8acc3f419 100644
--- a/src/parser.hpp
+++ b/src/parser.hpp
@@ -28,9 +28,9 @@ enum AddressingMode : u8 {
};
struct TypeAndValue {
+ Type * type;
AddressingMode mode;
bool is_lhs; // Debug info
- Type * type;
ExactValue value;
};