Skip to content

Commit

Permalink
move abort to Error
Browse files Browse the repository at this point in the history
no reason to depend on common.ml just for that
  • Loading branch information
Simn committed Jan 8, 2024
1 parent 091b1a2 commit e674663
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/codegen/gencommon/gencommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ let run_filters gen =

reorder_modules gen;
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 *)
Expand Down
4 changes: 1 addition & 3 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,6 @@ let allow_package ctx s =
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_name_macro com =
Expand Down Expand Up @@ -1208,7 +1206,7 @@ let to_utf8 str p =
let ccount = ref 0 in
UTF8.iter (fun c ->
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;
if c > 0x10000 then incr ccount;
) u8;
Expand Down
4 changes: 2 additions & 2 deletions src/context/display/displayPath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module TypePathHandler = struct
let complete_type_path com p =
let packs, modules = read_type_path com p in
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
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
Expand Down Expand Up @@ -158,7 +158,7 @@ module TypePathHandler = struct
in
Some fields
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

let resolve_position_by_path ctx path p =
Expand Down
2 changes: 2 additions & 0 deletions src/core/error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ let rec recurse_error ?(depth = 0) cb err =
exception Fatal_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
| 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 []
Expand Down
2 changes: 1 addition & 1 deletion src/filters/ES6Ctors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ let rewrite_ctors com =
let rec mark_needs_ctor_skipping cl =
(* 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
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;
try
Hashtbl.find needs_ctor_skipping cl.cl_path
Expand Down
1 change: 1 addition & 0 deletions src/generators/gencpp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
open Extlib_leftovers
open Ast
open Type
open Error
open Common
open Globals

Expand Down
6 changes: 3 additions & 3 deletions src/generators/gencs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ let generate con =
let code, code_pos =
match code.eexpr with
| 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
begin
let rec reveal_expr expr =
Expand All @@ -1820,11 +1820,11 @@ let generate con =
let code =
match code.eexpr with
| 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
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 =
let params, el = extract_tparams [] el in
let params = List.rev params in
Expand Down
1 change: 1 addition & 0 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ open Extlib_leftovers
open Globals
open Ast
open Type
open Error
open Common
open Hlcode

Expand Down
1 change: 1 addition & 0 deletions src/generators/genjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ open Extlib_leftovers
open Globals
open Ast
open Type
open Error
open Common
open JsSourcemap

Expand Down
6 changes: 3 additions & 3 deletions src/generators/genneko.ml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ let gen_constant ctx pe c =
if (h land 128 = 0) <> (h land 64 = 0) then raise Exit;
int p (Int32.to_int i)
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))
| 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]
Expand Down Expand Up @@ -237,7 +237,7 @@ and gen_expr ctx e =
(match follow e.etype with
| TFun (args,_) ->
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
EBlock [
(EVars ["@tmp", Some (gen_expr ctx e2); "@fun", Some (field p tmp f.cf_name)] , p);
Expand Down Expand Up @@ -798,7 +798,7 @@ let generate com =
else
loop (p + 1)
in
abort msg (loop 0)
Error.abort msg (loop 0)
end;
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
Expand Down
1 change: 1 addition & 0 deletions src/generators/genpy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
open Extlib_leftovers
open Globals
open Ast
open Error
open Type
open Common
open Texpr.Builder
Expand Down
1 change: 1 addition & 0 deletions src/generators/genswf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ open Swf
open As3hl
open ExtString
open Type
open Error
open Common
open Ast
open Globals
Expand Down
1 change: 1 addition & 0 deletions src/generators/genswf9.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ open Extlib_leftovers
open Globals
open Ast
open Type
open Error
open As3
open As3hl
open Common
Expand Down
2 changes: 1 addition & 1 deletion src/generators/hlinterp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2209,7 +2209,7 @@ let check code macros =
Globals.pmin = low;
Globals.pmax = low + (dline lsr 20);
} in
Common.abort msg pos
Error.abort msg pos
end else
failwith (Printf.sprintf "\n%s:%d: %s" file dline msg)
in
Expand Down
2 changes: 1 addition & 1 deletion src/optimization/analyzerTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ module BasicBlock = struct
bb

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

let terminator_map f term = match term with
Expand Down

0 comments on commit e674663

Please sign in to comment.