Browse Source

moved add_final_return to global config

Nicolas Cannasse 13 years ago
parent
commit
68076df65c
2 changed files with 16 additions and 5 deletions
  1. 12 0
      common.ml
  2. 4 5
      optimizer.ml

+ 12 - 0
common.ml

@@ -84,6 +84,8 @@ type platform_config = {
 	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;
+	(** add a final return to methods not having one already - prevent some compiler warnings *)
+	pf_add_final_return : bool;
 }
 
 type context = {
@@ -149,6 +151,7 @@ let default_config =
 		pf_can_init_member = (fun _ -> true);
 		pf_capture_policy = CPNone;
 		pf_pad_nulls = false;
+		pf_add_final_return = false;
 	}
 
 let get_config com =
@@ -166,6 +169,7 @@ let get_config com =
 			pf_can_init_member = (fun _ -> true);
 			pf_capture_policy = CPLoopVars;
 			pf_pad_nulls = false;
+			pf_add_final_return = false;
 		}
 	| Js ->
 		{
@@ -177,6 +181,7 @@ let get_config com =
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPLoopVars;
 			pf_pad_nulls = false;
+			pf_add_final_return = false;
 		}
 	| Neko ->
 		{
@@ -188,6 +193,7 @@ let get_config com =
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPNone;
 			pf_pad_nulls = true;
+			pf_add_final_return = false;
 		}
 	| Flash when defined "as3" ->
 		{
@@ -199,6 +205,7 @@ let get_config com =
 			pf_can_init_member = (fun _ -> true);
 			pf_capture_policy = CPLoopVars;
 			pf_pad_nulls = false;
+			pf_add_final_return = true;
 		}
 	| Flash ->
 		{
@@ -210,6 +217,7 @@ let get_config com =
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPLoopVars;
 			pf_pad_nulls = false;
+			pf_add_final_return = false;
 		}
 	| Php ->
 		{
@@ -226,6 +234,7 @@ let get_config com =
 			);
 			pf_capture_policy = CPNone;
 			pf_pad_nulls = true;
+			pf_add_final_return = false;
 		}
 	| Cpp ->
 		{
@@ -237,6 +246,7 @@ let get_config com =
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPWrapRef;
 			pf_pad_nulls = true;
+			pf_add_final_return = true;
 		}
 	| Cs ->
 		{
@@ -248,6 +258,7 @@ let get_config com =
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPWrapRef;
 			pf_pad_nulls = true;
+			pf_add_final_return = false;
 		}
 	| Java ->
 		{
@@ -259,6 +270,7 @@ let get_config com =
 			pf_can_init_member = (fun _ -> false);
 			pf_capture_policy = CPWrapRef;
 			pf_pad_nulls = true;
+			pf_add_final_return = false;
 		}
 
 let create v args =

+ 4 - 5
optimizer.ml

@@ -619,11 +619,10 @@ let sanitize_expr com e =
 		let e2 = complex e2 in
 		{ e with eexpr = TFor (v,e1,e2) }
 	| TFunction f ->
-		let f = (match com.platform, follow f.tf_type with
-			| _, TEnum ({ e_path = [],"Void" },[]) -> f
-			| Flash , t when Common.defined com "as3" -> { f with tf_expr = add_final_return f.tf_expr t }
-			| Cpp, t -> { f with tf_expr = add_final_return f.tf_expr t }
-			| _ -> f
+		let f = (match follow f.tf_type with
+			| TEnum ({ e_path = [],"Void" },[]) -> f
+			| t ->
+				if com.config.pf_add_final_return then { f with tf_expr = add_final_return f.tf_expr t } else f
 		) in
 		let f = (match f.tf_expr.eexpr with
 			| TBlock _ -> f