瀏覽代碼

[gencommon] remove some code duplication

Dan Korostelev 8 年之前
父節點
當前提交
06ce815ba8
共有 2 個文件被更改,包括 7 次插入32 次删除
  1. 3 19
      src/generators/gencommon/castDetect.ml
  2. 4 13
      src/generators/gencommon/reflectionCFs.ml

+ 3 - 19
src/generators/gencommon/castDetect.ml

@@ -28,7 +28,6 @@ open Gencommon
 (* Casts detection v2 *)
 (* ******************************************* *)
 (*
-
 	Will detect implicit casts and add TCast for them. Since everything is already followed by follow_all, typedefs are considered a new type altogether
 
 	Types shouldn't be cast if:
@@ -47,29 +46,19 @@ open Gencommon
 
 *)
 let name = "cast_detect_2"
-
 let priority = solve_deps name [DBefore TypeParams.priority; DBefore ExpressionUnwrap.priority]
 
 (* ******************************************* *)
 (* ReturnCast *)
 (* ******************************************* *)
-
 (*
-
 	Cast detection for return types can't be done at CastDetect time, since we need an
 	unwrapped expression to make sure we catch all return cast detections. So this module
 	is specifically to deal with that, and is configured automatically by CastDetect
-
-	dependencies:
-
-
 *)
-
 module ReturnCast =
 struct
-
 	let name = "return_cast"
-
 	let priority = solve_deps name [DAfter priority; DAfter ExpressionUnwrap.priority]
 
 	let default_implementation gen =
@@ -131,13 +120,8 @@ struct
 	let configure gen =
 		let map e = Some(default_implementation gen e) in
 		gen.gsyntax_filters#add ~name:name ~priority:(PCustom priority) map
-
 end;;
 
-let get_args t = match follow t with
-	| TFun(args,ret) -> args,ret
-	| _ -> trace (debug_type t); assert false
-
 (*
 	Since this function is applied under native-context only, the type paraters will already be changed
 *)
@@ -829,14 +813,14 @@ let handle_type_parameter gen e e1 ef ~clean_ef ~overloads_cast_to_base f elist
 		(match en.e_params with
 			(*
 			| [] ->
-				let args, ret = get_args (efield.ef_type) in
+				let args, ret = get_fun (efield.ef_type) in
 				let ef = { ef with eexpr = TTypeExpr( TEnumDecl en ); etype = TEnum(en, []) } in
 				handle_cast gen { ecall with eexpr = TCall({ e1 with eexpr = TField(ef, FEnum(en, efield)) }, List.map2 (fun param (_,_,t) -> handle_cast gen param (gen.greal_type t) (gen.greal_type param.etype)) elist args) } (gen.greal_type ecall.etype) (gen.greal_type ret)
 		*)
 			| _ ->
 				let pt = match e with | None -> real_type | Some _ -> snd (get_fun e1.etype) in
 				let _params = match follow pt with | TEnum(_, p) -> p | _ -> gen.gcon.warning (debug_expr e1) e1.epos; assert false in
-				let args, ret = get_args efield.ef_type in
+				let args, ret = get_fun efield.ef_type in
 				let actual_t = TFun(List.map (fun (n,o,t) -> (n,o,gen.greal_type t)) args, gen.greal_type ret) in
 				(*
 					because of differences on how <Dynamic> is handled on the platforms, this is a hack to be able to
@@ -846,7 +830,7 @@ let handle_type_parameter gen e e1 ef ~clean_ef ~overloads_cast_to_base f elist
 				let t = apply_params en.e_params (gen.greal_type_param (TEnumDecl en) cf_params) actual_t in
 				let t = apply_params efield.ef_params (List.map (fun _ -> t_dynamic) efield.ef_params) t in
 
-				let args, ret = get_args t in
+				let args, ret = get_fun t in
 
 				let elist = List.map2 (fun param (_,_,t) -> handle_cast gen (param) (gen.greal_type t) (gen.greal_type param.etype)) elist args in
 				let e1 = { e1 with eexpr = TField({ ef with eexpr = TTypeExpr( TEnumDecl en ); etype = TEnum(en, _params) }, FEnum(en, efield) ) } in

+ 4 - 13
src/generators/gencommon/reflectionCFs.ml

@@ -575,10 +575,6 @@ let is_override cl = match cl.cl_super with
 	| Some (cl, _) when is_hxgen (TClassDecl cl) -> true
 	| _ -> false
 
-let get_args t = match follow t with
-	| TFun(args,ret) -> args,ret
-	| _ -> assert false
-
 (* WARNING: this will only work if overloading contructors is possible on target language *)
 let implement_dynamic_object_ctor ctx cl =
 	let rec is_side_effects_free e =
@@ -968,7 +964,7 @@ let implement_get_set ctx cl =
 
 		let this = { eexpr = TConst TThis; etype = TInst(cl, List.map snd cl.cl_params); epos = pos } in
 		let mk_this_call_raw name fun_t params =
-			{ eexpr = TCall( { (mk_field_access gen this name pos) with etype = fun_t; }, params ); etype = snd (get_args fun_t); epos = pos }
+			{ eexpr = TCall( { (mk_field_access gen this name pos) with etype = fun_t; }, params ); etype = snd (get_fun fun_t); epos = pos }
 		in
 
 		let fun_type = ref (TFun([], basic.tvoid)) in
@@ -1310,7 +1306,7 @@ let implement_invokeField ctx ~slow_invoke cl =
 	let apply_object cf = apply_params cf.cf_params (List.map (fun _ -> t_dynamic) cf.cf_params) cf.cf_type in
 
 	let mk_this_call_raw name fun_t params =
-		{ eexpr = TCall( { (mk_field_access gen this name pos) with etype = fun_t }, params ); etype = snd (get_args fun_t); epos = pos }
+		{ eexpr = TCall( { (mk_field_access gen this name pos) with etype = fun_t }, params ); etype = snd (get_fun fun_t); epos = pos }
 	in
 
 	let mk_this_call cf params =
@@ -1321,12 +1317,7 @@ let implement_invokeField ctx ~slow_invoke cl =
 		(* e.g. function getArray<T : SomeType>(t:T):Array<T>; after infer_params, *)
 		(* T will be inferred as SomeType, but the returned type will still be typed *)
 		(* as Array<Dynamic> *)
-		let args, ret = get_args t in
-		let ret = match follow ret with
-			| TAbstract ({ a_path = ([], "Void") },[]) -> ret
-			| _ -> ret
-		in
-		mk_this_call_raw cf.cf_name (TFun(args, ret)) params
+		mk_this_call_raw cf.cf_name t params
 	in
 
 	let extends_hxobject = extends_hxobject cl in
@@ -1358,7 +1349,7 @@ let implement_invokeField ctx ~slow_invoke cl =
 						let ret = { eexpr = TArray(dyn_arg_local, ExprBuilder.make_int ctx.rcf_gen.gcon !i pos); etype = t_dynamic; epos = pos } in
 						incr i;
 						ret
-					) (fst (get_args (cf.cf_type))))
+					) (fst (get_fun (cf.cf_type))))
 				)
 			)
 		in