Browse Source

`ERROR_BLOCK()` any usages of "Did you mean?" like behaviour whilst iterating across a scope entry map

gingerBill 4 years ago
parent
commit
b88e945268
4 changed files with 10 additions and 7 deletions
  1. 4 6
      src/check_expr.cpp
  2. 4 0
      src/check_stmt.cpp
  3. 0 1
      src/main.cpp
  4. 2 0
      src/tokenizer.cpp

+ 4 - 6
src/check_expr.cpp

@@ -3726,11 +3726,8 @@ void check_did_you_mean_print(DidYouMeanAnswers *d) {
 	}
 	}
 }
 }
 
 
-gb_global BlockingMutex did_you_mean_mutex;
-
 void check_did_you_mean_type(String const &name, Array<Entity *> const &fields) {
 void check_did_you_mean_type(String const &name, Array<Entity *> const &fields) {
-	mutex_lock(&did_you_mean_mutex);
-	defer (mutex_unlock(&did_you_mean_mutex));
+	ERROR_BLOCK();
 	
 	
 	DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), fields.count, name);
 	DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), fields.count, name);
 	defer (did_you_mean_destroy(&d));
 	defer (did_you_mean_destroy(&d));
@@ -3742,8 +3739,7 @@ void check_did_you_mean_type(String const &name, Array<Entity *> const &fields)
 }
 }
 
 
 void check_did_you_mean_scope(String const &name, Scope *scope) {
 void check_did_you_mean_scope(String const &name, Scope *scope) {
-	mutex_lock(&did_you_mean_mutex);
-	defer (mutex_unlock(&did_you_mean_mutex));
+	ERROR_BLOCK();
 	
 	
 	DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), scope->elements.entries.count, name);
 	DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), scope->elements.entries.count, name);
 	defer (did_you_mean_destroy(&d));
 	defer (did_you_mean_destroy(&d));
@@ -4977,6 +4973,8 @@ bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, S
 				return false;
 				return false;
 			} else if (!o.value.value_bool) {
 			} else if (!o.value.value_bool) {
 				if (print_err) {
 				if (print_err) {
+					ERROR_BLOCK();
+					
 					gbString str = expr_to_string(clause);
 					gbString str = expr_to_string(clause);
 					error(clause, "'where' clause evaluated to false:\n\t%s", str);
 					error(clause, "'where' clause evaluated to false:\n\t%s", str);
 					gb_string_free(str);
 					gb_string_free(str);

+ 4 - 0
src/check_stmt.cpp

@@ -578,6 +578,8 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b
 	}
 	}
 
 
 	add_entity_use(ctx, expr, e);
 	add_entity_use(ctx, expr, e);
+	
+	ERROR_BLOCK();
 
 
 	switch (e->kind) {
 	switch (e->kind) {
 	case Entity_TypeName: {
 	case Entity_TypeName: {
@@ -2336,6 +2338,8 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
 					if (is_blank_ident(name)) {
 					if (is_blank_ident(name)) {
 						error(token, "'using' cannot be applied variable declared as '_'");
 						error(token, "'using' cannot be applied variable declared as '_'");
 					} else if (is_type_struct(t) || is_type_raw_union(t)) {
 					} else if (is_type_struct(t) || is_type_raw_union(t)) {
+						ERROR_BLOCK();
+						
 						Scope *scope = scope_of_node(t->Struct.node);
 						Scope *scope = scope_of_node(t->Struct.node);
 						for_array(i, scope->elements.entries) {
 						for_array(i, scope->elements.entries) {
 							Entity *f = scope->elements.entries[i].value;
 							Entity *f = scope->elements.entries[i].value;

+ 0 - 1
src/main.cpp

@@ -2019,7 +2019,6 @@ int main(int arg_count, char const **arg_ptr) {
 	virtual_memory_init();
 	virtual_memory_init();
 	mutex_init(&fullpath_mutex);
 	mutex_init(&fullpath_mutex);
 	mutex_init(&hash_exact_value_mutex);
 	mutex_init(&hash_exact_value_mutex);
-	mutex_init(&did_you_mean_mutex);
 
 
 	init_string_buffer_memory();
 	init_string_buffer_memory();
 	init_string_interner();
 	init_string_interner();

+ 2 - 0
src/tokenizer.cpp

@@ -377,6 +377,8 @@ void end_error_block(void) {
 	mutex_unlock(&global_error_collector.block_mutex);
 	mutex_unlock(&global_error_collector.block_mutex);
 }
 }
 
 
+#define ERROR_BLOCK() begin_error_block(); defer (end_error_block())
+
 
 
 #define ERROR_OUT_PROC(name) void name(char const *fmt, va_list va)
 #define ERROR_OUT_PROC(name) void name(char const *fmt, va_list va)
 typedef ERROR_OUT_PROC(ErrorOutProc);
 typedef ERROR_OUT_PROC(ErrorOutProc);