Browse Source

Fix check_remove_expr_info

gingerBill 3 years ago
parent
commit
ef73a284e3
4 changed files with 33 additions and 22 deletions
  1. 8 1
      src/checker.cpp
  2. 2 2
      src/llvm_backend_expr.cpp
  3. 22 18
      src/map.cpp
  4. 1 1
      src/parser.hpp

+ 8 - 1
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) {
 void check_remove_expr_info(CheckerContext *c, Ast *e) {
 	if (c->untyped != nullptr) {
 	if (c->untyped != nullptr) {
 		map_remove(c->untyped, hash_pointer(e));
 		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 {
 	} else {
+		auto *untyped = &c->info->global_untyped;
 		mutex_lock(&c->info->global_untyped_mutex);
 		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);
 		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;
 		prev_expr = expr;
 		expr->tav.mode = mode;
 		expr->tav.mode = mode;
 		expr->tav.type = type;
 		expr->tav.type = type;
+
 		if (mode == Addressing_Constant || mode == Addressing_Invalid) {
 		if (mode == Addressing_Constant || mode == Addressing_Invalid) {
 			expr->tav.value = value;
 			expr->tav.value = value;
 		} else if (mode == Addressing_Value && is_type_typeid(type)) {
 		} else if (mode == Addressing_Value && is_type_typeid(type)) {

+ 2 - 2
src/llvm_backend_expr.cpp

@@ -2258,9 +2258,9 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
 
 
 	if (tv.value.kind != ExactValue_Invalid) {
 	if (tv.value.kind != ExactValue_Invalid) {
 		// NOTE(bill): The commented out code below is just for debug purposes only
 		// 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)) {
 		// 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
 		// NOTE(bill): Short on constant values

+ 22 - 18
src/map.cpp

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

+ 1 - 1
src/parser.hpp

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