Prechádzať zdrojové kódy

[js] [flash] add `pf_reserved_type_paths`, give warning for `[],"Object"` (closes #3634)

Simon Krajewski 10 rokov pred
rodič
commit
87aea095ff
2 zmenil súbory, kde vykonal 19 pridanie a 0 odobranie
  1. 13 0
      common.ml
  2. 6 0
      filters.ml

+ 13 - 0
common.ml

@@ -96,6 +96,8 @@ type platform_config = {
 	pf_pattern_matching : bool;
 	(** can the platform use default values for non-nullable arguments *)
 	pf_can_skip_non_nullable_argument : bool;
+	(** type paths that are reserved on the platform *)
+	pf_reserved_type_paths : path list;
 }
 
 type display_mode =
@@ -533,6 +535,7 @@ let default_config =
 		pf_overload = false;
 		pf_pattern_matching = false;
 		pf_can_skip_non_nullable_argument = true;
+		pf_reserved_type_paths = [];
 	}
 
 let get_config com =
@@ -553,6 +556,7 @@ let get_config com =
 			pf_overload = false;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = true;
+			pf_reserved_type_paths = [];
 		}
 	| Js ->
 		{
@@ -567,6 +571,7 @@ let get_config com =
 			pf_overload = false;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = true;
+			pf_reserved_type_paths = [([],"Object")];
 		}
 	| Neko ->
 		{
@@ -581,6 +586,7 @@ let get_config com =
 			pf_overload = false;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = true;
+			pf_reserved_type_paths = [];
 		}
 	| Flash when defined Define.As3 ->
 		{
@@ -595,6 +601,7 @@ let get_config com =
 			pf_overload = false;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = false;
+			pf_reserved_type_paths = [];
 		}
 	| Flash ->
 		{
@@ -609,6 +616,7 @@ let get_config com =
 			pf_overload = false;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = false;
+			pf_reserved_type_paths = [([],"Object")];
 		}
 	| Php ->
 		{
@@ -623,6 +631,7 @@ let get_config com =
 			pf_overload = false;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = true;
+			pf_reserved_type_paths = [];
 		}
 	| Cpp ->
 		{
@@ -637,6 +646,7 @@ let get_config com =
 			pf_overload = false;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = true;
+			pf_reserved_type_paths = [];
 		}
 	| Cs ->
 		{
@@ -651,6 +661,7 @@ let get_config com =
 			pf_overload = true;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = true;
+			pf_reserved_type_paths = [];
 		}
 	| Java ->
 		{
@@ -665,6 +676,7 @@ let get_config com =
 			pf_overload = true;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = true;
+			pf_reserved_type_paths = [];
 		}
 	| Python ->
 		{
@@ -679,6 +691,7 @@ let get_config com =
 			pf_overload = false;
 			pf_pattern_matching = false;
 			pf_can_skip_non_nullable_argument = true;
+			pf_reserved_type_paths = [];
 		}
 
 let memory_marker = [|Unix.time()|]

+ 6 - 0
filters.ml

@@ -977,6 +977,11 @@ let commit_features ctx t =
 		Common.add_feature ctx.com k;
 	) m.m_extra.m_features
 
+let check_reserved_type_paths ctx t =
+	let m = t_infos t in
+	if List.mem m.mt_path ctx.com.config.pf_reserved_type_paths then
+		ctx.com.warning ("Type path " ^ (s_type_path m.mt_path) ^ " is reserved on this target") m.mt_pos
+
 (* PASS 3 end *)
 
 let run_expression_filters ctx filters t =
@@ -1139,5 +1144,6 @@ let run com tctx main =
 		check_void_field;
 		(match com.platform with | Cpp -> promote_first_interface_to_super | _ -> (fun _ _ -> ()) );
 		commit_features;
+		(if com.config.pf_reserved_type_paths <> [] then check_reserved_type_paths else (fun _ _ -> ()));
 	] in
 	List.iter (fun t -> List.iter (fun f -> f tctx t) type_filters) com.types