瀏覽代碼

move abort to Error

no reason to depend on common.ml just for that
Simon Krajewski 1 年之前
父節點
當前提交
e6746636df

+ 1 - 1
src/codegen/gencommon/gencommon.ml

@@ -819,7 +819,7 @@ let run_filters gen =
 
 
 	reorder_modules gen;
 	reorder_modules gen;
 	t();
 	t();
-	if !has_errors then abort "Compilation aborted with errors" null_pos
+	if !has_errors then Error.abort "Compilation aborted with errors" null_pos
 
 
 (* ******************************************* *)
 (* ******************************************* *)
 (* basic generation module that source code compilation implementations can use *)
 (* basic generation module that source code compilation implementations can use *)

+ 1 - 3
src/context/common.ml

@@ -1053,8 +1053,6 @@ let allow_package ctx s =
 	with Not_found ->
 	with Not_found ->
 		()
 		()
 
 
-let abort ?(depth = 0) msg p = raise (Error.Fatal_error (Error.make_error ~depth (Custom msg) p))
-
 let platform ctx p = ctx.platform = p
 let platform ctx p = ctx.platform = p
 
 
 let platform_name_macro com =
 let platform_name_macro com =
@@ -1208,7 +1206,7 @@ let to_utf8 str p =
 	let ccount = ref 0 in
 	let ccount = ref 0 in
 	UTF8.iter (fun c ->
 	UTF8.iter (fun c ->
 		let c = UCharExt.code c in
 		let c = UCharExt.code c in
-		if (c >= 0xD800 && c <= 0xDFFF) || c >= 0x110000 then abort "Invalid unicode char" p;
+		if (c >= 0xD800 && c <= 0xDFFF) || c >= 0x110000 then Error.abort "Invalid unicode char" p;
 		incr ccount;
 		incr ccount;
 		if c > 0x10000 then incr ccount;
 		if c > 0x10000 then incr ccount;
 	) u8;
 	) u8;

+ 2 - 2
src/context/display/displayPath.ml

@@ -83,7 +83,7 @@ module TypePathHandler = struct
 	let complete_type_path com p =
 	let complete_type_path com p =
 		let packs, modules = read_type_path com p in
 		let packs, modules = read_type_path com p in
 		if packs = [] && modules = [] then
 		if packs = [] && modules = [] then
-			(abort ("No modules found in " ^ String.concat "." p) null_pos)
+			(Error.abort ("No modules found in " ^ String.concat "." p) null_pos)
 		else
 		else
 			let packs = List.map (fun n -> make_ci_package (p,n) []) packs in
 			let packs = List.map (fun n -> make_ci_package (p,n) []) packs in
 			let modules = List.map (fun n -> make_ci_module (p,n)) modules in
 			let modules = List.map (fun n -> make_ci_module (p,n)) modules in
@@ -158,7 +158,7 @@ module TypePathHandler = struct
 			in
 			in
 			Some fields
 			Some fields
 		with _ ->
 		with _ ->
-			abort ("Could not load module " ^ (s_type_path (p,c))) null_pos
+			Error.abort ("Could not load module " ^ (s_type_path (p,c))) null_pos
 end
 end
 
 
 let resolve_position_by_path ctx path p =
 let resolve_position_by_path ctx path p =

+ 2 - 0
src/core/error.ml

@@ -51,6 +51,8 @@ let rec recurse_error ?(depth = 0) cb err =
 exception Fatal_error of error
 exception Fatal_error of error
 exception Error of error
 exception Error of error
 
 
+let abort ?(depth = 0) msg p = raise (Fatal_error (make_error ~depth (Custom msg) p))
+
 let string_source t = match follow t with
 let string_source t = match follow t with
 	| TInst(c,tl) -> PMap.foldi (fun s _ acc -> s :: acc) (TClass.get_all_fields c tl) []
 	| TInst(c,tl) -> PMap.foldi (fun s _ acc -> s :: acc) (TClass.get_all_fields c tl) []
 	| TAnon a -> PMap.fold (fun cf acc -> cf.cf_name :: acc) a.a_fields []
 	| TAnon a -> PMap.fold (fun cf acc -> cf.cf_name :: acc) a.a_fields []

+ 1 - 1
src/filters/ES6Ctors.ml

@@ -84,7 +84,7 @@ let rewrite_ctors com =
 		let rec mark_needs_ctor_skipping cl =
 		let rec mark_needs_ctor_skipping cl =
 			(* for non haxe-generated extern classes we can't generate any valid code, so just fail *)
 			(* for non haxe-generated extern classes we can't generate any valid code, so just fail *)
 			if (has_class_flag cl CExtern) && not (Meta.has Meta.HxGen cl.cl_meta) then begin
 			if (has_class_flag cl CExtern) && not (Meta.has Meta.HxGen cl.cl_meta) then begin
-				abort "Must call `super()` constructor before accessing `this` in classes derived from an extern class with constructor" p_this_access;
+				Error.abort "Must call `super()` constructor before accessing `this` in classes derived from an extern class with constructor" p_this_access;
 			end;
 			end;
 			try
 			try
 				Hashtbl.find needs_ctor_skipping cl.cl_path
 				Hashtbl.find needs_ctor_skipping cl.cl_path

+ 1 - 0
src/generators/gencpp.ml

@@ -19,6 +19,7 @@
 open Extlib_leftovers
 open Extlib_leftovers
 open Ast
 open Ast
 open Type
 open Type
+open Error
 open Common
 open Common
 open Globals
 open Globals
 
 

+ 3 - 3
src/generators/gencs.ml

@@ -1798,7 +1798,7 @@ let generate con =
 					let code, code_pos =
 					let code, code_pos =
 						match code.eexpr with
 						match code.eexpr with
 						| TConst (TString s) -> s, code.epos
 						| TConst (TString s) -> s, code.epos
-						| _ -> abort "The `code` argument for cs.Syntax.code must be a string constant" code.epos
+						| _ -> Error.abort "The `code` argument for cs.Syntax.code must be a string constant" code.epos
 					in
 					in
 					begin
 					begin
 						let rec reveal_expr expr =
 						let rec reveal_expr expr =
@@ -1820,11 +1820,11 @@ let generate con =
 					let code =
 					let code =
 						match code.eexpr with
 						match code.eexpr with
 						| TConst (TString s) -> s
 						| TConst (TString s) -> s
-						| _ -> abort "The `code` argument for cs.Syntax.plainCode must be a string constant" code.epos
+						| _ -> Error.abort "The `code` argument for cs.Syntax.plainCode must be a string constant" code.epos
 					in
 					in
 					write w (String.concat "\n" (ExtString.String.nsplit code "\r\n"))
 					write w (String.concat "\n" (ExtString.String.nsplit code "\r\n"))
 				| _ ->
 				| _ ->
-					abort (Printf.sprintf "Unknown cs.Syntax method `%s` with %d arguments" meth (List.length args)) pos
+					Error.abort (Printf.sprintf "Unknown cs.Syntax method `%s` with %d arguments" meth (List.length args)) pos
 			and do_call w e el =
 			and do_call w e el =
 				let params, el = extract_tparams [] el in
 				let params, el = extract_tparams [] el in
 				let params = List.rev params in
 				let params = List.rev params in

+ 1 - 0
src/generators/genhl.ml

@@ -23,6 +23,7 @@ open Extlib_leftovers
 open Globals
 open Globals
 open Ast
 open Ast
 open Type
 open Type
+open Error
 open Common
 open Common
 open Hlcode
 open Hlcode
 
 

+ 1 - 0
src/generators/genjs.ml

@@ -20,6 +20,7 @@ open Extlib_leftovers
 open Globals
 open Globals
 open Ast
 open Ast
 open Type
 open Type
+open Error
 open Common
 open Common
 open JsSourcemap
 open JsSourcemap
 
 

+ 3 - 3
src/generators/genneko.ml

@@ -170,7 +170,7 @@ let gen_constant ctx pe c =
 			if (h land 128 = 0) <> (h land 64 = 0) then raise Exit;
 			if (h land 128 = 0) <> (h land 64 = 0) then raise Exit;
 			int p (Int32.to_int i)
 			int p (Int32.to_int i)
 		with _ ->
 		with _ ->
-			if ctx.version < 2 then abort "This integer is too big to be compiled to a Neko 31-bit integer. Please use a Float instead" pe;
+			if ctx.version < 2 then Error.abort "This integer is too big to be compiled to a Neko 31-bit integer. Please use a Float instead" pe;
 			(EConst (Int32 i),p))
 			(EConst (Int32 i),p))
 	| TFloat f -> (EConst (Float (Texpr.replace_separators f "")),p)
 	| TFloat f -> (EConst (Float (Texpr.replace_separators f "")),p)
 	| TString s -> call p (field p (ident p "String") "new") [gen_big_string ctx p s]
 	| TString s -> call p (field p (ident p "String") "new") [gen_big_string ctx p s]
@@ -237,7 +237,7 @@ and gen_expr ctx e =
 		(match follow e.etype with
 		(match follow e.etype with
 		| TFun (args,_) ->
 		| TFun (args,_) ->
 			let n = List.length args in
 			let n = List.length args in
-			if n > 5 then abort "Cannot create closure with more than 5 arguments" e.epos;
+			if n > 5 then Error.abort "Cannot create closure with more than 5 arguments" e.epos;
 			let tmp = ident p "@tmp" in
 			let tmp = ident p "@tmp" in
 			EBlock [
 			EBlock [
 				(EVars ["@tmp", Some (gen_expr ctx e2); "@fun", Some (field p tmp f.cf_name)] , p);
 				(EVars ["@tmp", Some (gen_expr ctx e2); "@fun", Some (field p tmp f.cf_name)] , p);
@@ -798,7 +798,7 @@ let generate com =
 				else
 				else
 					loop (p + 1)
 					loop (p + 1)
 			in
 			in
-			abort msg (loop 0)
+			Error.abort msg (loop 0)
 	end;
 	end;
 	let command cmd args = try com.run_command_args cmd args with _ -> -1 in
 	let command cmd args = try com.run_command_args cmd args with _ -> -1 in
 	let neko_file = (try Filename.chop_extension com.file with _ -> com.file) ^ ".neko" in
 	let neko_file = (try Filename.chop_extension com.file with _ -> com.file) ^ ".neko" in

+ 1 - 0
src/generators/genpy.ml

@@ -19,6 +19,7 @@
 open Extlib_leftovers
 open Extlib_leftovers
 open Globals
 open Globals
 open Ast
 open Ast
+open Error
 open Type
 open Type
 open Common
 open Common
 open Texpr.Builder
 open Texpr.Builder

+ 1 - 0
src/generators/genswf.ml

@@ -20,6 +20,7 @@ open Swf
 open As3hl
 open As3hl
 open ExtString
 open ExtString
 open Type
 open Type
+open Error
 open Common
 open Common
 open Ast
 open Ast
 open Globals
 open Globals

+ 1 - 0
src/generators/genswf9.ml

@@ -20,6 +20,7 @@ open Extlib_leftovers
 open Globals
 open Globals
 open Ast
 open Ast
 open Type
 open Type
+open Error
 open As3
 open As3
 open As3hl
 open As3hl
 open Common
 open Common

+ 1 - 1
src/generators/hlinterp.ml

@@ -2209,7 +2209,7 @@ let check code macros =
 					Globals.pmin = low;
 					Globals.pmin = low;
 					Globals.pmax = low + (dline lsr 20);
 					Globals.pmax = low + (dline lsr 20);
 				} in
 				} in
-				Common.abort msg pos
+				Error.abort msg pos
 			end else
 			end else
 				failwith (Printf.sprintf "\n%s:%d: %s" file dline msg)
 				failwith (Printf.sprintf "\n%s:%d: %s" file dline msg)
 		in
 		in

+ 1 - 1
src/optimization/analyzerTypes.ml

@@ -218,7 +218,7 @@ module BasicBlock = struct
 		bb
 		bb
 
 
 	let in_scope bb bb' = match bb'.bb_scopes with
 	let in_scope bb bb' = match bb'.bb_scopes with
-		| [] -> abort (Printf.sprintf "Scope-less block (kind: %s)" (s_block_kind bb'.bb_kind)) bb'.bb_pos
+		| [] -> Error.abort (Printf.sprintf "Scope-less block (kind: %s)" (s_block_kind bb'.bb_kind)) bb'.bb_pos
 		| scope :: _ -> List.mem scope bb.bb_scopes
 		| scope :: _ -> List.mem scope bb.bb_scopes
 
 
 	let terminator_map f term = match term with
 	let terminator_map f term = match term with