Browse Source

split Abstract module and move underlying type handling to type.ml

Simon Krajewski 11 years ago
parent
commit
ad1e1f818f
14 changed files with 118 additions and 112 deletions
  1. 5 46
      codegen.ml
  2. 3 3
      dce.ml
  3. 3 3
      filters.ml
  4. 1 1
      genas3.ml
  5. 3 3
      gencommon.ml
  6. 7 7
      gencpp.ml
  7. 4 4
      gencs.ml
  8. 2 2
      genjava.ml
  9. 1 1
      genphp.ml
  10. 3 3
      genpy.ml
  11. 1 1
      genswf9.ml
  12. 5 5
      matcher.ml
  13. 47 0
      type.ml
  14. 33 33
      typer.ml

+ 5 - 46
codegen.ml

@@ -647,50 +647,9 @@ let promote_abstract_parameters ctx t = match t with
 (* -------------------------------------------------------------------------- *)
 (* ABSTRACT CASTS *)
 
-module Abstract = struct
-
-	let find_to ab pl b =
-		if follow b == t_dynamic then
-			List.find (fun (t,_) -> follow t == t_dynamic) ab.a_to
-		else
-			List.find (Type.unify_to_field ab pl b) ab.a_to
-
-	let find_from ab pl a b =
-		if follow a == t_dynamic then
-			List.find (fun (t,_) -> follow t == t_dynamic) ab.a_from
-		else
-			List.find (Type.unify_from_field ab pl a b) ab.a_from
+module AbstractCast = struct
 
 	let cast_stack = ref []
-	let underlying_type_stack = ref []
-
-	let rec get_underlying_type a pl =
-		let maybe_recurse t =
-			underlying_type_stack := a :: !underlying_type_stack;
-			let t = match follow t with
-				| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
-					if List.mem a !underlying_type_stack then begin
-						let s = String.concat " -> " (List.map (fun a -> s_type_path a.a_path) (List.rev (a :: !underlying_type_stack))) in
-						(* technically this should be done at type declaration level *)
-						error ("Abstract chain detected: " ^ s) a.a_pos
-					end;
-					get_underlying_type a tl
-				| _ ->
-					t
-			in
-			underlying_type_stack := List.tl !underlying_type_stack;
-			t
-		in
-		try
-			if not (Meta.has Meta.MultiType a.a_meta) then raise Not_found;
-			let m = mk_mono() in
-			let _ = find_to a pl m in
-			maybe_recurse (follow m)
-		with Not_found ->
-			if Meta.has Meta.CoreType a.a_meta then
-				t_dynamic
-			else
-				maybe_recurse (apply_params a.a_params pl a.a_this)
 
 	let make_static_call ctx c cf a pl args t p =
 		make_static_call ctx c cf (apply_params a.a_params pl) args t p
@@ -729,14 +688,14 @@ module Abstract = struct
 		else try
 			begin match follow eright.etype with
 				| TAbstract(a,tl) ->
-					find a tl (fun () -> find_to a tl tleft)
+					find a tl (fun () -> Abstract.find_to a tl tleft)
 				| _ ->
 					raise Not_found
 			end
 		with Not_found -> try
 			begin match follow tleft with
 				| TAbstract(a,tl) ->
-					find a tl (fun () -> find_from a tl eright.etype tleft)
+					find a tl (fun () -> Abstract.find_from a tl eright.etype tleft)
 				| _ ->
 					raise Not_found
 			end
@@ -781,7 +740,7 @@ module Abstract = struct
 		in
 		let _,cfo =
 			try
-				find_to a tl m
+				Abstract.find_to a tl m
 			with Not_found ->
 				let at = apply_params a.a_params pl a.a_this in
 				let st = s_type (print_context()) at in
@@ -819,7 +778,7 @@ module Abstract = struct
 						| TField(e2,fa) ->
 							begin match follow e2.etype with
 								| TAbstract(a,pl) when Meta.has Meta.MultiType a.a_meta ->
-									let m = get_underlying_type a pl in
+									let m = Abstract.get_underlying_type a pl in
 									let fname = field_name fa in
 									let el = List.map (loop ctx) el in
 									begin try

+ 3 - 3
dce.ml

@@ -162,7 +162,7 @@ and mark_t dce p t =
 			List.iter (mark_t dce p) pl
 		| TAbstract(a,pl) when Meta.has Meta.MultiType a.a_meta ->
 			begin try
-				mark_t dce p (snd (Codegen.Abstract.find_multitype_specialization dce.com a pl p))
+				mark_t dce p (snd (Codegen.AbstractCast.find_multitype_specialization dce.com a pl p))
 			with Typecore.Error _ ->
 				()
 			end
@@ -170,7 +170,7 @@ and mark_t dce p t =
 			mark_abstract dce a;
 			List.iter (mark_t dce p) pl;
 			if not (Meta.has Meta.CoreType a.a_meta) then
-				mark_t dce p (Codegen.Abstract.get_underlying_type a pl)
+				mark_t dce p (Abstract.get_underlying_type a pl)
 		| TLazy _ | TDynamic _ | TAnon _ | TType _ | TMono _ -> ()
 		end;
 		dce.t_stack <- List.tl dce.t_stack
@@ -227,7 +227,7 @@ let rec to_string dce t = match t with
 		if Meta.has Meta.CoreType a.a_meta then
 			field dce c "toString" false
 		else
-			to_string dce (Codegen.Abstract.get_underlying_type a tl)
+			to_string dce (Abstract.get_underlying_type a tl)
 	| TMono r ->
 		(match !r with
 		| Some t -> to_string dce t

+ 3 - 3
filters.ml

@@ -1107,9 +1107,9 @@ let run_expression_filters ctx filters t =
 		let process_field f =
 			match f.cf_expr with
 			| Some e when not (is_removable_field ctx f) ->
-				Codegen.Abstract.cast_stack := f :: !Codegen.Abstract.cast_stack;
+				Codegen.AbstractCast.cast_stack := f :: !Codegen.AbstractCast.cast_stack;
 				f.cf_expr <- Some (run e);
-				Codegen.Abstract.cast_stack := List.tl !Codegen.Abstract.cast_stack;
+				Codegen.AbstractCast.cast_stack := List.tl !Codegen.AbstractCast.cast_stack;
 			| _ -> ()
 		in
 		List.iter process_field c.cl_ordered_fields;
@@ -1149,7 +1149,7 @@ let run com tctx main =
 	(* PASS 1: general expression filters *)
  	let filters = [
  		Codegen.UnificationCallback.run (check_unification com);
-		Codegen.Abstract.handle_abstract_casts tctx;
+		Codegen.AbstractCast.handle_abstract_casts tctx;
 		blockify_ast;
 		(match com.platform with
 			| Cpp | Flash8 -> (fun e ->

+ 1 - 1
genas3.ml

@@ -235,7 +235,7 @@ let rec type_str ctx t p =
 	| TEnum _ | TInst _ when List.memq t ctx.local_types ->
 		"*"
 	| TAbstract ({ a_impl = Some _ } as a,pl) ->
-		type_str ctx (Codegen.Abstract.get_underlying_type a pl) p
+		type_str ctx (Abstract.get_underlying_type a pl) p
 	| TAbstract (a,_) ->
 		(match a.a_path with
 		| [], "Void" -> "void"

+ 3 - 3
gencommon.ml

@@ -3005,7 +3005,7 @@ struct
 			| TDynamic t ->
 				(match t with | TDynamic _ -> acc | _ -> get_type_params acc t)
 			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
-					get_type_params acc ( Codegen.Abstract.get_underlying_type a pl)
+					get_type_params acc ( Abstract.get_underlying_type a pl)
 			| TAnon a ->
 				PMap.fold (fun cf acc -> get_type_params acc cf.cf_type) a.a_fields acc
 			| TType(_, [])
@@ -5924,7 +5924,7 @@ struct
 	(* this is a workaround for issue #1743, as FInstance() is returning the incorrect classfield *)
 	let rec clean_t t = match follow t with
 		| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
-			clean_t (Codegen.Abstract.get_underlying_type a tl)
+			clean_t (Abstract.get_underlying_type a tl)
 		| t -> t
 
 	let select_overload gen applied_f overloads types params =
@@ -6326,7 +6326,7 @@ struct
 					let arr_etype = match follow arr.etype with
 					| (TInst _ as t) -> t
 					| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
-						follow (Codegen.Abstract.get_underlying_type a pl)
+						follow (Abstract.get_underlying_type a pl)
 					| t -> t in
 					let idx = match gen.greal_type idx.etype with
 					| TAbstract({ a_path = [],"Int" },_) -> run idx

+ 7 - 7
gencpp.ml

@@ -32,7 +32,7 @@ let unsupported p = error "This expression cannot be generated to Cpp" p
 *)
 let rec follow t = match Type.follow t with
    | TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
-      follow (Codegen.Abstract.get_underlying_type a tl)
+      follow (Abstract.get_underlying_type a tl)
    | t ->
       t
 
@@ -626,7 +626,7 @@ and type_string_suff suffix haxe_type =
    | TDynamic haxe_type -> "Dynamic" ^ suffix
    | TLazy func -> type_string_suff suffix ((!func)())
    | TAbstract (abs,pl) when abs.a_impl <> None ->
-      type_string_suff suffix (Codegen.Abstract.get_underlying_type abs pl)
+      type_string_suff suffix (Abstract.get_underlying_type abs pl)
    | TAbstract (abs,pl) ->
       "::" ^ (join_class_path_remap abs.a_path "::") ^ suffix
    )
@@ -1761,7 +1761,7 @@ and gen_expression ctx retval expression =
          | real_type -> gen_array_cast cast_name real_type call
          )
       | TAbstract (abs,pl) when abs.a_impl <> None ->
-         check_array_element_cast (Codegen.Abstract.get_underlying_type abs pl) cast_name call
+         check_array_element_cast (Abstract.get_underlying_type abs pl) cast_name call
       | _ -> ()
    in
    let rec check_array_cast array_type =
@@ -1774,7 +1774,7 @@ and gen_expression ctx retval expression =
          else
             gen_array_cast ".StaticCast" (type_string array_type) "()"
       | TAbstract (abs,pl) when abs.a_impl <> None ->
-         check_array_cast (Codegen.Abstract.get_underlying_type abs pl)
+         check_array_cast (Abstract.get_underlying_type abs pl)
       | _ -> ()
    in
 
@@ -4186,7 +4186,7 @@ let rec s_type t =
    | TInst (c,tl) -> Ast.s_type_path c.cl_path ^ s_type_params tl
    | TType (t,tl) -> Ast.s_type_path t.t_path ^ s_type_params tl
    | TAbstract (abs,pl) when abs.a_impl <> None ->
-      s_type (Codegen.Abstract.get_underlying_type abs pl);
+      s_type (Abstract.get_underlying_type abs pl);
    | TAbstract (a,tl) -> Ast.s_type_path a.a_path ^ s_type_params tl
    | TFun ([],t) -> "Void -> " ^ s_fun t false
    | TFun (l,t) ->
@@ -4390,7 +4390,7 @@ let rec script_type_string haxe_type =
          | _ -> "Array.Object"
          )
      | TAbstract (abs,pl) when abs.a_impl <> None ->
-         script_type_string  (Codegen.Abstract.get_underlying_type abs pl);
+         script_type_string  (Abstract.get_underlying_type abs pl);
      | _ ->
          type_string_suff "" haxe_type
 ;;
@@ -4499,7 +4499,7 @@ class script_writer common_ctx ctx filename =
             | _ -> ArrayObject
             )
       | TAbstract (abs,pl) when abs.a_impl <> None ->
-            this#get_array_type  (Codegen.Abstract.get_underlying_type abs pl);
+            this#get_array_type  (Abstract.get_underlying_type abs pl);
       | _ -> ArrayNone;
 
    method pushReturn inType =

+ 4 - 4
gencs.ml

@@ -49,7 +49,7 @@ let rec is_cs_basic_type t =
 		| TAbstract _ when like_float t ->
 			true
 		| TAbstract(a,pl) when not (Meta.has Meta.CoreType a.a_meta) ->
-			is_cs_basic_type (Codegen.Abstract.get_underlying_type a pl)
+			is_cs_basic_type (Abstract.get_underlying_type a pl)
 		| TEnum(e, _) when not (Meta.has Meta.Class e.e_meta) -> true
 		| TInst(cl, _) when Meta.has Meta.Struct cl.cl_meta -> true
 		| _ -> false
@@ -738,7 +738,7 @@ let configure gen =
 			| TAbstract ({ a_path = [],"Single" },[]) -> Some t
 			| TType ({ t_path = [],"Null" },[_]) -> Some t
 			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
-					Some (gen.gfollow#run_f ( Codegen.Abstract.get_underlying_type a pl) )
+					Some (gen.gfollow#run_f ( Abstract.get_underlying_type a pl) )
 			| TAbstract( { a_path = ([], "EnumValue") }, _	)
 			| TInst( { cl_path = ([], "EnumValue") }, _  ) -> Some t_dynamic
 			| _ -> None);
@@ -769,7 +769,7 @@ let configure gen =
 		let t = gen.gfollow#run_f t in
 		let ret = match t with
 			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
-				real_type (Codegen.Abstract.get_underlying_type a pl)
+				real_type (Abstract.get_underlying_type a pl)
 			| TInst( { cl_path = (["haxe"], "Int32") }, [] ) -> gen.gcon.basic.tint
 			| TInst( { cl_path = (["haxe"], "Int64") }, [] ) -> ti64
 			| TAbstract( { a_path = [],"Class" }, _ )
@@ -922,7 +922,7 @@ let configure gen =
 					| _ -> "object")
 			| TDynamic _ -> "object"
 			| TAbstract(a,pl) when not (Meta.has Meta.CoreType a.a_meta) ->
-				t_s (Codegen.Abstract.get_underlying_type a pl)
+				t_s (Abstract.get_underlying_type a pl)
 			(* No Lazy type nor Function type made. That's because function types will be at this point be converted into other types *)
 			| _ -> if !strict_mode then begin trace ("[ !TypeError " ^ (Type.s_type (Type.print_context()) t) ^ " ]"); assert false end else "[ !TypeError " ^ (Type.s_type (Type.print_context()) t) ^ " ]"
 

+ 2 - 2
genjava.ml

@@ -867,7 +867,7 @@ let configure gen =
 			| TAbstract ({ a_path = [],"Single" },[])
 			| TType ({ t_path = [],"Null" },[_]) -> Some t
 			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
-					Some (gen.gfollow#run_f ( Codegen.Abstract.get_underlying_type a pl) )
+					Some (gen.gfollow#run_f ( Abstract.get_underlying_type a pl) )
 			| TAbstract( { a_path = ([], "EnumValue") }, _ )
 			| TInst( { cl_path = ([], "EnumValue") }, _  ) -> Some t_dynamic
 			| _ -> None);
@@ -892,7 +892,7 @@ let configure gen =
 		let t = gen.gfollow#run_f t in
 		match t with
 			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
-				real_type (Codegen.Abstract.get_underlying_type a pl)
+				real_type (Abstract.get_underlying_type a pl)
 			| TInst( { cl_path = (["haxe"], "Int32") }, [] ) -> gen.gcon.basic.tint
 			| TInst( { cl_path = (["haxe"], "Int64") }, [] ) -> ti64
 			| TAbstract( { a_path = ([], "Class") }, p	)

+ 1 - 1
genphp.ml

@@ -208,7 +208,7 @@ let rec is_string_type t =
 	   (match !(a.a_status) with
 	   | Statics ({cl_path = ([], "String")}) -> true
 	   | _ -> false)
-	| TAbstract (a,pl) -> is_string_type (Codegen.Abstract.get_underlying_type a pl)
+	| TAbstract (a,pl) -> is_string_type (Abstract.get_underlying_type a pl)
 	| _ -> false
 
 let is_string_expr e = is_string_type e.etype

+ 3 - 3
genpy.ml

@@ -976,15 +976,15 @@ module Printer = struct
 		)
 
 	let is_underlying_string t = match follow t with
-		| TAbstract(a,tl) -> (is_type1 "" "String")(Codegen.Abstract.get_underlying_type a tl)
+		| TAbstract(a,tl) -> (is_type1 "" "String")(Abstract.get_underlying_type a tl)
 		| _ -> false
 	let is_underlying_array t = match follow t with
-		| TAbstract(a,tl) -> (is_type1 "" "list")(Codegen.Abstract.get_underlying_type a tl)
+		| TAbstract(a,tl) -> (is_type1 "" "list")(Abstract.get_underlying_type a tl)
 		| _ -> false
 
 	let rec is_anon_or_dynamic t = match follow t with
 		| TAbstract(a,tl) ->
-			is_anon_or_dynamic (Codegen.Abstract.get_underlying_type a tl)
+			is_anon_or_dynamic (Abstract.get_underlying_type a tl)
 		| TAnon _ | TDynamic _ -> true
 		| _ -> false
 

+ 1 - 1
genswf9.ml

@@ -106,7 +106,7 @@ type context = {
 
 let rec follow t = match Type.follow t with
 	| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
-		follow (Codegen.Abstract.get_underlying_type a tl)
+		follow (Abstract.get_underlying_type a tl)
 	| t ->
 		t
 

+ 5 - 5
matcher.ml

@@ -203,7 +203,7 @@ let mk_subs st con =
 		let rec loop t = match follow t with
 			| TEnum(_,pl) -> pl
 			| TAbstract({a_path = [],"EnumValue"},[]) -> []
-			| TAbstract(a,pl) -> loop (Codegen.Abstract.get_underlying_type a pl)
+			| TAbstract(a,pl) -> loop (Abstract.get_underlying_type a pl)
 			| _ -> []
 		in
 		let pl = loop con.c_type in
@@ -812,7 +812,7 @@ let rec all_ctors mctx t =
 				| _ -> ()
 		) c.cl_ordered_statics;
 		h,false
-	| TAbstract(a,pl) when not (Meta.has Meta.CoreType a.a_meta) -> all_ctors mctx (Codegen.Abstract.get_underlying_type a pl)
+	| TAbstract(a,pl) when not (Meta.has Meta.CoreType a.a_meta) -> all_ctors mctx (Abstract.get_underlying_type a pl)
 	| TInst({cl_path=[],"String"},_)
 	| TInst({cl_path=[],"Array"},_) ->
 		h,true
@@ -1020,7 +1020,7 @@ let convert_switch mctx st cases loop =
 	let e = match follow st.st_type with
 	| TEnum(_) ->
 		wrap_exhaustive (mk_index_call())
-	| TAbstract(a,pl) when (match Codegen.Abstract.get_underlying_type a pl with TEnum(_) -> true | _ -> false) ->
+	| TAbstract(a,pl) when (match Abstract.get_underlying_type a pl with TEnum(_) -> true | _ -> false) ->
 		wrap_exhaustive (mk_index_call())
 	| TInst({cl_path = [],"Array"},_) as t ->
 		mk (TField (e_st,quick_field t "length")) ctx.t.tint p
@@ -1257,10 +1257,10 @@ let match_expr ctx e cases def with_type p =
 				match with_type with
 				| WithType t ->
 					unify ctx e.etype t e.epos;
-					Codegen.Abstract.check_cast ctx t e e.epos;
+					Codegen.AbstractCast.check_cast ctx t e e.epos;
 				| WithTypeResume t ->
 					(try unify_raise ctx e.etype t e.epos with Error (Unify l,p) -> raise (Typer.WithTypeError (l,p)));
-					Codegen.Abstract.check_cast ctx t e e.epos
+					Codegen.AbstractCast.check_cast ctx t e e.epos
 				| _ -> e
 		in
 		(* type case guard *)

+ 47 - 0
type.ml

@@ -1591,6 +1591,53 @@ and unify_with_access t1 f2 =
 	(* read/write *)
 	| _ -> type_eq EqBothDynamic t1 f2.cf_type
 
+module Abstract = struct
+	open Ast
+
+	let find_to ab pl b =
+		if follow b == t_dynamic then
+			List.find (fun (t,_) -> follow t == t_dynamic) ab.a_to
+		else
+			List.find (unify_to_field ab pl b) ab.a_to
+
+	let find_from ab pl a b =
+		if follow a == t_dynamic then
+			List.find (fun (t,_) -> follow t == t_dynamic) ab.a_from
+		else
+			List.find (unify_from_field ab pl a b) ab.a_from
+
+	let underlying_type_stack = ref []
+
+	let rec get_underlying_type a pl =
+		let maybe_recurse t =
+			underlying_type_stack := a :: !underlying_type_stack;
+			let t = match follow t with
+				| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
+					if List.mem a !underlying_type_stack then begin
+						(* let s = String.concat " -> " (List.map (fun a -> s_type_path a.a_path) (List.rev (a :: !underlying_type_stack))) in *)
+						(* technically this should be done at type declaration level *)
+						(* error ("Abstract chain detected: " ^ s) a.a_pos *)
+						assert false
+					end;
+					get_underlying_type a tl
+				| _ ->
+					t
+			in
+			underlying_type_stack := List.tl !underlying_type_stack;
+			t
+		in
+		try
+			if not (Meta.has Meta.MultiType a.a_meta) then raise Not_found;
+			let m = mk_mono() in
+			let _ = find_to a pl m in
+			maybe_recurse (follow m)
+		with Not_found ->
+			if Meta.has Meta.CoreType a.a_meta then
+				t_dynamic
+			else
+				maybe_recurse (apply_params a.a_params pl a.a_this)
+end
+
 (* ======= Mapping and iterating ======= *)
 
 let iter_dt f dt = match dt with

+ 33 - 33
typer.ml

@@ -760,7 +760,7 @@ let rec unify_call_args ctx ?(overloads=None) cf el args r p inline =
 							with Error (Unify ul,p) ->
 								raise (Error (Stack (Unify ul,Custom ("For rest function argument '" ^ name ^ "'")), p))
 							end;
-							process ((Codegen.Abstract.check_cast ctx t e p,false) :: acc) rest
+							process ((Codegen.AbstractCast.check_cast ctx t e p,false) :: acc) rest
 					in
 					loop (process acc l) [] [] skip false
 				| _ ->
@@ -778,7 +778,7 @@ let rec unify_call_args ctx ?(overloads=None) cf el args r p inline =
 			try
 				let e = type_expr ctx ee (WithTypeResume t) in
 				(try unify_raise ctx e.etype t e.epos with Error (Unify l,p) -> raise (WithTypeError (l,p)));
-				loop ((Codegen.Abstract.check_cast ctx t e p,false) :: acc) l l2 skip check_rest
+				loop ((Codegen.AbstractCast.check_cast ctx t e p,false) :: acc) l l2 skip check_rest
 			with
 				WithTypeError (ul,p) ->
 					if opt then
@@ -1676,7 +1676,7 @@ let type_generic_function ctx (e,cf) el ?(using_param=None) with_type p =
 	let args,ret = match t,using_param with
 		| TFun((_,_,ta) :: args,ret),Some e ->
 			let ta = if not (Meta.has Meta.Impl cf.cf_meta) then ta
-			else match follow ta with TAbstract(a,tl) -> Codegen.Abstract.get_underlying_type a tl | _ -> assert false
+			else match follow ta with TAbstract(a,tl) -> Abstract.get_underlying_type a tl | _ -> assert false
 			in
 			(* manually unify first argument *)
 			unify ctx e.etype ta p;
@@ -1764,7 +1764,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 		let e1 = type_access ctx (fst e1) (snd e1) MSet in
 		let tt = (match e1 with AKNo _ | AKInline _ | AKUsing _ | AKMacro _ | AKAccess _ -> Value | AKSet(_,t,_) -> WithType t | AKExpr e -> WithType e.etype) in
 		let e2 = type_expr ctx e2 tt in
-		let e2 = match tt with WithType t -> Codegen.Abstract.check_cast ctx t e2 p | _ -> e2 in
+		let e2 = match tt with WithType t -> Codegen.AbstractCast.check_cast ctx t e2 p | _ -> e2 in
 		(match e1 with
 		| AKNo s -> error ("Cannot access field or identifier " ^ s ^ " for writing") p
 		| AKExpr e1  ->
@@ -1923,7 +1923,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 				let acc = (match acc.eexpr with TField (e,FClosure (Some c,f)) -> { acc with eexpr = TField (e,FInstance (c,f)) } | _ -> acc) in
 				make_call ctx acc [e] ctx.t.tstring e.epos
 			| KAbstract (a,tl) ->
-				loop (Codegen.Abstract.get_underlying_type a tl)
+				loop (Abstract.get_underlying_type a tl)
 		in
 		loop e.etype
 	in
@@ -2032,10 +2032,10 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 			unify_raise ctx e1.etype e2.etype p;
 			(* we only have to check one type here, because unification fails if one is Void and the other is not *)
 			(match follow e2.etype with TAbstract({a_path=[],"Void"},_) -> error "Cannot compare Void" p | _ -> ());
-			Codegen.Abstract.check_cast ctx e2.etype e1 p,e2
+			Codegen.AbstractCast.check_cast ctx e2.etype e1 p,e2
 		with Error (Unify _,_) ->
 			unify ctx e2.etype e1.etype p;
-			e1,Codegen.Abstract.check_cast ctx e1.etype e2 p
+			e1,Codegen.AbstractCast.check_cast ctx e1.etype e2 p
 		in
 		mk_op e1 e2 ctx.t.tbool
 	| OpGt
@@ -2104,7 +2104,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 						begin try
 							begin
 								if impl then
-									type_eq EqStrict (Codegen.Abstract.get_underlying_type a pl) t1
+									type_eq EqStrict (Abstract.get_underlying_type a pl) t1
 								else
 									type_eq EqStrict (TAbstract(a,pl)) t1;
 							end;
@@ -2147,7 +2147,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 				unify_raise ctx e.etype r p
 			with Error (Unify _,_) ->
 				match follow r with
-					| TAbstract(a,tl) when type_iseq (Codegen.Abstract.get_underlying_type a tl) e.etype ->
+					| TAbstract(a,tl) when type_iseq (Abstract.get_underlying_type a tl) e.etype ->
 						()
 					| _ ->
 						error ("The result of this operation (" ^ (s_type (print_context()) e.etype) ^ ") is not compatible with declared return type " ^ (s_type (print_context()) r)) p;
@@ -2158,7 +2158,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 	try (match follow e1.etype with
 		| TAbstract ({a_impl = Some c} as a,pl) ->
 			let f,t2,r,assign,_ = find_overload a pl c e2.etype true in
-			let e2 = Codegen.Abstract.check_cast ctx t2 e2 e2.epos in
+			let e2 = Codegen.AbstractCast.check_cast ctx t2 e2 e2.epos in
 			begin match f.cf_expr with
 				| None ->
 					let e2 = match follow e2.etype with TAbstract(a,pl) -> {e2 with etype = apply_params a.a_params pl a.a_this} | _ -> e2 in
@@ -2171,17 +2171,17 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 	with Not_found -> try (match follow e2.etype with
 		| TAbstract ({a_impl = Some c} as a,pl) ->
 			let f,t2,r,assign,commutative = find_overload a pl c e1.etype false in
-			(* let e1,e2 = if commutative then  else e1,Codegen.Abstract.check_cast ctx t2 e2 e2.epos in *)
+			(* let e1,e2 = if commutative then  else e1,Codegen.AbstractCast.check_cast ctx t2 e2 e2.epos in *)
 			let e1,e2,init = if not commutative then
-				e1,Codegen.Abstract.check_cast ctx t2 e2 e2.epos,None
+				e1,Codegen.AbstractCast.check_cast ctx t2 e2 e2.epos,None
 			else if not (Optimizer.has_side_effect e1) && not (Optimizer.has_side_effect e2) then
-				e2,Codegen.Abstract.check_cast ctx t2 e1 e1.epos,None
+				e2,Codegen.AbstractCast.check_cast ctx t2 e1 e1.epos,None
 			else begin
 				let v1,v2 = gen_local ctx e1.etype, gen_local ctx e2.etype in
 				let mk_var v e =
 					mk (TVar(v,Some e)) ctx.t.tvoid e.epos,mk (TLocal v) e.etype e.epos
 				in
-				let v1 = mk_var v1 (Codegen.Abstract.check_cast ctx t2 e1 e1.epos) in
+				let v1 = mk_var v1 (Codegen.AbstractCast.check_cast ctx t2 e1 e1.epos) in
 				let v2 = mk_var v2 e2 in
 				snd v2,snd v1,Some(fst v1,fst v2)
 			end in
@@ -2582,7 +2582,7 @@ and type_vars ctx vl p in_block =
 				| Some e ->
 					let e = type_expr ctx e (WithType t) in
 					unify ctx e.etype t p;
-					Some (Codegen.Abstract.check_cast ctx t e p)
+					Some (Codegen.AbstractCast.check_cast ctx t e p)
 			) in
 			if v.[0] = '$' && ctx.com.display = DMNone then error "Variables names starting with a dollar are not allowed" p;
 			add_local ctx v t, e
@@ -2791,7 +2791,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			(match follow t with
 			| TAnon a when not (PMap.is_empty a.a_fields) -> Some a
 			| TAbstract (a,tl) when not (Meta.has Meta.CoreType a.a_meta) && List.exists (fun (_,cfo) -> cfo = None) a.a_from ->
-				begin match follow (Codegen.Abstract.get_underlying_type a tl) with
+				begin match follow (Abstract.get_underlying_type a tl) with
 					| TAnon a when not (PMap.is_empty a.a_fields) -> Some a
 					| _ -> None
 				end
@@ -2824,7 +2824,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 				let e = try
 					let t = (PMap.find n a.a_fields).cf_type in
 					let e = type_expr ctx e (match with_type with WithTypeResume _ -> WithTypeResume t | _ -> WithType t) in
-					let e = Codegen.Abstract.check_cast ctx t e p in
+					let e = Codegen.AbstractCast.check_cast ctx t e p in
 					unify ctx e.etype t e.epos;
 					(try type_eq EqStrict e.etype t; e with Unify_error _ -> mk (TCast (e,None)) t e.epos)
 				with Not_found ->
@@ -2967,7 +2967,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 				(match with_type with
 				| WithTypeResume _ -> (try unify_raise ctx e.etype t e.epos with Error (Unify l,p) -> raise (WithTypeError (l,p)))
 				| _ -> unify ctx e.etype t e.epos);
-				Codegen.Abstract.check_cast ctx t e p
+				Codegen.AbstractCast.check_cast ctx t e p
 			) el in
 			mk (TArrayDecl el) (ctx.t.tarray t) p)
 	| EVars vl ->
@@ -2996,7 +2996,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 				| _ ->
 					(try
 						unify_raise ctx e1.etype t e1.epos;
-						Codegen.Abstract.check_cast ctx t e1 p
+						Codegen.AbstractCast.check_cast ctx t e1 p
 					with Error (Unify _,_) ->
 						let acc = build_call ctx (type_field ctx e1 "iterator" e1.epos MCall) [] Value e1.epos in
 						try
@@ -3039,7 +3039,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 	| EIf (e,e1,e2) ->
 		let e = type_expr ctx e Value in
 		unify ctx e.etype ctx.t.tbool e.epos;
-		let e = Codegen.Abstract.check_cast ctx ctx.t.tbool e p in
+		let e = Codegen.AbstractCast.check_cast ctx ctx.t.tbool e p in
 		let e1 = type_expr ctx e1 with_type in
 		(match e2 with
 		| None ->
@@ -3058,8 +3058,8 @@ and type_expr ctx (e,p) (with_type:with_type) =
 						| WithTypeResume _ -> raise (WithTypeError (l,p))
 						| _ -> display_error ctx (error_msg (Unify l)) p
 					end;
-					let e1 = Codegen.Abstract.check_cast ctx t e1 e1.epos in
-					let e2 = Codegen.Abstract.check_cast ctx t e2 e2.epos in
+					let e1 = Codegen.AbstractCast.check_cast ctx t e1 e1.epos in
+					let e2 = Codegen.AbstractCast.check_cast ctx t e2 e2.epos in
 					e1,e2,t
 			in
 			mk (TIf (e,e1,Some e2)) t p)
@@ -3067,7 +3067,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		let old_loop = ctx.in_loop in
 		let cond = type_expr ctx cond Value in
 		unify ctx cond.etype ctx.t.tbool cond.epos;
-		let cond = Codegen.Abstract.check_cast ctx ctx.t.tbool cond p in
+		let cond = Codegen.AbstractCast.check_cast ctx ctx.t.tbool cond p in
 		ctx.in_loop <- true;
 		let e = type_expr ctx e NoValue in
 		ctx.in_loop <- old_loop;
@@ -3079,7 +3079,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		ctx.in_loop <- old_loop;
 		let cond = type_expr ctx cond Value in
 		unify ctx cond.etype ctx.t.tbool cond.epos;
-		let cond = Codegen.Abstract.check_cast ctx ctx.t.tbool cond p in
+		let cond = Codegen.AbstractCast.check_cast ctx ctx.t.tbool cond p in
 		mk (TWhile (cond,e,DoWhile)) ctx.t.tvoid p
 	| ESwitch (e1,cases,def) ->
 		begin try
@@ -3101,7 +3101,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			| Some e ->
 				let e = type_expr ctx e (WithType ctx.ret) in
 				unify ctx e.etype ctx.ret e.epos;
-				let e = Codegen.Abstract.check_cast ctx ctx.ret e p in
+				let e = Codegen.AbstractCast.check_cast ctx ctx.ret e p in
 				Some e , e.etype
 		) in
 		mk (TReturn e) t_dynamic p
@@ -3150,7 +3150,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 					| x :: _ , _ -> x
 					| [] , name -> name),t
 				| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
-					loop (Codegen.Abstract.get_underlying_type a tl)
+					loop (Abstract.get_underlying_type a tl)
 				| TDynamic _ -> "",t
 				| _ -> error "Catch type must be a class, an enum or Dynamic" (pos e)
 			in
@@ -3310,7 +3310,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 						| _ -> unify ctx rt tr p
 					end
 				| TAbstract(a,tl) ->
-					loop (Codegen.Abstract.get_underlying_type a tl)
+					loop (Abstract.get_underlying_type a tl)
 				| _ -> ())
 			in
 			loop t
@@ -3399,7 +3399,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 				) params;
 				TAbstractDecl a
 			| TAbstract (a,params) ->
-				loop (Codegen.Abstract.get_underlying_type a params)
+				loop (Abstract.get_underlying_type a params)
 			| _ ->
 				error "Cast type must be a class or an enum" p
 		in
@@ -3418,7 +3418,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 	| ECheckType (e,t) ->
 		let t = Typeload.load_complex_type ctx p t in
 		let e = type_expr ctx e (WithType t) in
-		let e = Codegen.Abstract.check_cast ctx t e p in
+		let e = Codegen.AbstractCast.check_cast ctx t e p in
 		unify ctx e.etype t e.epos;
 		if e.etype == t then e else mk (TCast (e,None)) t p
 	| EMeta (m,e1) ->
@@ -3806,7 +3806,7 @@ and build_call ctx acc el (with_type:with_type) p =
 					unify ctx tthis t1 eparam.epos;
 					let ef = prepare_using_field ef in
 					begin match unify_call_args ctx (Some (TInst(cl,[]),ef)) el args r p (ef.cf_kind = Method MethInline) with
-					| el,TFun(args,r) -> el,args,r,(if is_abstract_impl_call then eparam else Codegen.Abstract.check_cast ctx t1 eparam eparam.epos)
+					| el,TFun(args,r) -> el,args,r,(if is_abstract_impl_call then eparam else Codegen.AbstractCast.check_cast ctx t1 eparam eparam.epos)
 					| _ -> assert false
 					end
 				| _ -> assert false
@@ -3883,7 +3883,7 @@ and build_call ctx acc el (with_type:with_type) p =
 					let el, tfunc = unify_call_args ctx fopts el args r p false in
 					el,(match tfunc with TFun(_,r) -> r | _ -> assert false), {e with etype = tfunc})
 		| TAbstract(a,tl) when Meta.has Meta.Callable a.a_meta ->
-			loop (Codegen.Abstract.get_underlying_type a tl)
+			loop (Abstract.get_underlying_type a tl)
 		| TMono _ ->
 			let t = mk_mono() in
 			let el = List.map (fun e -> type_expr ctx e Value) el in
@@ -4404,7 +4404,7 @@ and flush_macro_context mint ctx =
 		mint
 	end else mint in
 	(* we should maybe ensure that all filters in Main are applied. Not urgent atm *)
-	let expr_filters = [Codegen.Abstract.handle_abstract_casts mctx; Filters.captured_vars mctx.com; Filters.rename_local_vars mctx.com] in
+	let expr_filters = [Codegen.AbstractCast.handle_abstract_casts mctx; Filters.captured_vars mctx.com; Filters.rename_local_vars mctx.com] in
 	let type_filters = [Filters.add_field_inits mctx] in
 	let ready = fun t ->
 		Filters.post_process mctx expr_filters t;
@@ -4821,5 +4821,5 @@ let rec create com =
 unify_min_ref := unify_min;
 make_call_ref := make_call;
 get_constructor_ref := get_constructor;
-check_abstract_cast_ref := Codegen.Abstract.check_cast;
+check_abstract_cast_ref := Codegen.AbstractCast.check_cast;
 type_module_type_ref := type_module_type;