浏览代码

deal with Error in SafeCom

Simon Krajewski 5 月之前
父节点
当前提交
94bff707d7
共有 2 个文件被更改,包括 31 次插入11 次删除
  1. 28 6
      src/context/safeCom.ml
  2. 3 5
      src/filters/safe/checkVarInit.ml

+ 28 - 6
src/context/safeCom.ml

@@ -17,11 +17,16 @@ type t = {
 	platform_config : platform_config;
 	debug : bool;
 	is_macro_context : bool;
+	foptimize : bool;
+	doinline : bool;
 	exceptions : exn list ref;
 	exceptions_mutex : Mutex.t;
 	warnings : saved_warning list ref;
 	warnings_mutex : Mutex.t;
+	errors : Error.error list ref;
+	errors_mutex : Mutex.t;
 	timer_ctx : Timer.timer_context;
+	find_module : path -> module_def;
 	curclass : tclass;
 	curfield : tclass_field;
 }
@@ -33,11 +38,16 @@ let of_com (com : Common.context) = {
 	platform_config = com.config;
 	debug = com.debug;
 	is_macro_context = com.is_macro_context;
+	foptimize = com.foptimize;
+	doinline = com.doinline;
 	exceptions = ref [];
 	exceptions_mutex = Mutex.create ();
 	warnings = ref [];
 	warnings_mutex = Mutex.create ();
+	errors = ref [];
+	errors_mutex = Mutex.create ();
 	timer_ctx = com.timer_ctx;
+	find_module = com.module_lut#find;
 	curclass = null_class;
 	curfield = null_field;
 }
@@ -49,12 +59,18 @@ let of_typer (ctx : Typecore.typer) = {
 }
 
 let finalize scom com =
-	List.iter (fun warning ->
-		Common.module_warning com warning.w_module warning.w_warning warning.w_options warning.w_msg warning.w_pos
-	) !(scom.warnings);
-	scom.warnings := [];
+	let warnings = !(scom.warnings) in
+	let errors = !(scom.errors) in
 	let exns = !(scom.exceptions) in
+	scom.warnings := [];
+	scom.errors := [];
 	scom.exceptions := [];
+	List.iter (fun warning ->
+		Common.module_warning com warning.w_module warning.w_warning warning.w_options warning.w_msg warning.w_pos
+	) warnings;
+	List.iter (fun err ->
+		Common.display_error_ext com err
+	) errors;
 	match exns with
 	| x :: _ ->
 		raise x
@@ -64,8 +80,14 @@ let finalize scom com =
 let run_with_scom com scom pool f =
 	Std.finally (fun() -> finalize scom com) f ()
 
-let add_exn scom exn =
-	Mutex.protect scom.exceptions_mutex (fun () -> scom.exceptions := exn :: !(scom.exceptions))
+let add_error scom err =
+	Mutex.protect scom.errors_mutex (fun () -> scom.errors := err :: !(scom.errors))
+
+let add_exn scom exn = match exn with
+	| Error.Error err ->
+		add_error scom err
+	| _ ->
+		Mutex.protect scom.exceptions_mutex (fun () -> scom.exceptions := exn :: !(scom.exceptions))
 
 let add_warning scom w msg p =
 	let options = (Warning.from_meta scom.curfield.cf_meta) @ (Warning.from_meta scom.curclass.cl_meta) in

+ 3 - 5
src/filters/safe/checkVarInit.ml

@@ -1,7 +1,5 @@
 open Globals
-open Common
-open Typecore
-open Error
+open SafeCom
 open Type
 
 let check_local_vars_init scom e =
@@ -32,8 +30,8 @@ let check_local_vars_init scom e =
 					if v.v_name = "this" then SafeCom.add_warning scom WVarInit "this might be used before assigning a value to it" e.epos
 					else SafeCom.add_warning scom WVarInit ("Local variable " ^ v.v_name ^ " might be used before being initialized") e.epos
 				else
-					if v.v_name = "this" then raise_typing_error "Missing this = value" e.epos
-					else raise_typing_error ("Local variable " ^ v.v_name ^ " used without being initialized") e.epos
+					if v.v_name = "this" then Error.raise_typing_error "Missing this = value" e.epos
+					else Error.raise_typing_error ("Local variable " ^ v.v_name ^ " used without being initialized") e.epos
 			end
 		| TVar (v,eo) ->
 			begin