Pārlūkot izejas kodu

moved opt args null padding to global config

Nicolas Cannasse 13 gadi atpakaļ
vecāks
revīzija
d8482986b2
3 mainītis faili ar 19 papildinājumiem un 6 dzēšanām
  1. 12 0
      common.ml
  2. 1 1
      typeload.ml
  3. 6 5
      typer.ml

+ 12 - 0
common.ml

@@ -82,6 +82,8 @@ type platform_config = {
 	pf_can_init_member : tclass_field -> bool;
 	(** captured variables handling (see before) *)
 	pf_capture_policy : capture_policy;
+	(** when calling a method with optional args, do we replace the missing args with "null" constants *)
+	pf_pad_nulls : bool;
 }
 
 type context = {
@@ -146,6 +148,7 @@ let default_config =
 		pf_unique_locals = false;
 		pf_can_init_member = (fun _ -> true);
 		pf_capture_policy = CPNone;
+		pf_pad_nulls = false;
 	}
 
 let get_config com =
@@ -162,6 +165,7 @@ let get_config com =
 			pf_unique_locals = false;
 			pf_can_init_member = (fun _ -> true);
 			pf_capture_policy = CPLoopVars;
+			pf_pad_nulls = false;
 		}
 	| Js ->
 		{
@@ -172,6 +176,7 @@ let get_config com =
 			pf_unique_locals = false;
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPLoopVars;
+			pf_pad_nulls = false;
 		}
 	| Neko ->
 		{
@@ -182,6 +187,7 @@ let get_config com =
 			pf_unique_locals = false;
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPNone;
+			pf_pad_nulls = true;
 		}
 	| Flash when defined "as3" ->
 		{
@@ -192,6 +198,7 @@ let get_config com =
 			pf_unique_locals = true;
 			pf_can_init_member = (fun _ -> true);
 			pf_capture_policy = CPLoopVars;
+			pf_pad_nulls = false;
 		}
 	| Flash ->
 		{
@@ -202,6 +209,7 @@ let get_config com =
 			pf_unique_locals = false;
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPLoopVars;
+			pf_pad_nulls = false;
 		}
 	| Php ->
 		{
@@ -217,6 +225,7 @@ let get_config com =
 				| _ -> true 
 			);
 			pf_capture_policy = CPNone;
+			pf_pad_nulls = true;
 		}
 	| Cpp ->
 		{
@@ -227,6 +236,7 @@ let get_config com =
 			pf_unique_locals = false;
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPWrapRef;
+			pf_pad_nulls = true;
 		}
 	| Cs ->
 		{
@@ -237,6 +247,7 @@ let get_config com =
 			pf_unique_locals = true;
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPWrapRef;
+			pf_pad_nulls = true;
 		}
 	| Java ->
 		{
@@ -247,6 +258,7 @@ let get_config com =
 			pf_unique_locals = false;
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPWrapRef;
+			pf_pad_nulls = true;
 		}
 
 let create v args =

+ 1 - 1
typeload.ml

@@ -1258,7 +1258,7 @@ let init_class ctx c p herits fields =
 								into the inherited constructor when it's not necessary for the platform
 							*)
 							match ctx.com.platform, def with
-							| (Php | Js | Neko | Flash8), Some _ -> v, (Some TNull)
+							| _, Some _ when not ctx.com.config.pf_static -> v, (Some TNull)
 							| Flash, Some (TString _) -> v, (Some TNull)
 							| Cpp, Some (TString _) -> v, def
 							| Cpp, Some _ -> { v with v_type = ctx.t.tnull v.v_type }, (Some TNull)

+ 6 - 5
typer.ml

@@ -334,7 +334,7 @@ let rec unify_call_params ctx cf el args r p inline =
 	let rec loop acc l l2 skip =
 		match l , l2 with
 		| [] , [] ->
-			if not (inline && ctx.g.doinline) && (match ctx.com.platform with Flash8 | Flash | Js -> true | _ -> false) then
+			if not (inline && ctx.g.doinline) && not ctx.com.config.pf_pad_nulls then
 				List.rev (no_opt acc), (TFun(args,r))
 			else
 				List.rev (List.map fst acc), (TFun(args,r))
@@ -853,12 +853,13 @@ let type_callback ctx e params p =
 		| [], [] -> given_args,missing_args,ordered_args
 		| [], _ -> error "Too many callback arguments" p
 		| (n,o,t) :: args , [] when o ->
-			let a = match ctx.com.platform with
-				| _ when is_pos_infos t ->
+			let a = if is_pos_infos t then
 					let infos = mk_infos ctx p [] in
 					ordered_args @ [type_expr ctx infos true]
-				| Neko | Php -> (ordered_args @ [(mk (TConst TNull) t_dynamic p)])
-				| _ -> ordered_args
+				else if ctx.com.config.pf_pad_nulls then
+					(ordered_args @ [(mk (TConst TNull) t_dynamic p)])
+				else 
+					ordered_args
 			in
 			loop args [] given_args missing_args a
 		| (n,o,t) :: _ , (EConst(Ident "_"),p) :: _ when ctx.com.platform = Flash && o && not (is_nullable t) ->