Browse Source

unified handling of `-D no-deprecation-warnings`

Aleksandr Kuzmenko 5 years ago
parent
commit
17d29d28cc

+ 1 - 2
src/compiler/haxe.ml

@@ -609,8 +609,7 @@ let filter ctx tctx display_file_dot_path =
 			mctx.Typecore.com.Common.modules <- modules
 	end;
 	DisplayOutput.process_global_display_mode com tctx;
-	if not (Common.defined com Define.NoDeprecationWarnings) then
-		DeprecationCheck.run com;
+	DeprecationCheck.run com;
 	Filters.run com tctx main;
 	t()
 

+ 28 - 1
src/context/display/deprecationCheck.ml

@@ -94,4 +94,31 @@ let run com =
 			curclass := null_class;
 		| _ ->
 			()
-	) com.types
+	) com.types
+
+let if_enabled ?(force=false) com fn =
+	if force || not (defined com Define.NoDeprecationWarnings) then fn()
+
+let warn_deprecation ?(force=false) com s p_usage = if_enabled ~force com (fun() -> warn_deprecation com s p_usage)
+
+let print_deprecation_message ?(force=false) com meta s p_usage = if_enabled ~force com (fun() -> print_deprecation_message com meta s p_usage)
+
+let check_meta ?(force=false) com meta s p_usage = if_enabled ~force com (fun() -> check_meta com meta s p_usage)
+
+let check_cf ?(force=false) com cf p = if_enabled ~force com (fun() -> check_cf com cf p)
+
+let check_class ?(force=false) com c p = if_enabled ~force com (fun() -> check_class com c p)
+
+let check_enum ?(force=false) com en p = if_enabled ~force com (fun() -> check_enum com en p)
+
+let check_ef ?(force=false) com ef p = if_enabled ~force com (fun() -> check_ef com ef p)
+
+let check_typedef ?(force=false) com t p = if_enabled ~force com (fun() -> check_typedef com t p)
+
+let check_module_type ?(force=false) com mt p = if_enabled ~force com (fun() -> check_module_type com mt p)
+
+let run_on_expr ?(force=false) com e = if_enabled ~force com (fun() -> run_on_expr com e)
+
+let run_on_field ?(force=false) com cf = if_enabled ~force com (fun() -> run_on_field com cf)
+
+let run ?(force=false) com = if_enabled ~force com (fun() -> run com)

+ 1 - 1
src/context/display/diagnostics.ml

@@ -96,7 +96,7 @@ let prepare_field dctx com cf = match cf.cf_expr with
 	| Some e ->
 		find_unused_variables dctx e;
 		check_other_things com e;
-		DeprecationCheck.run_on_expr com e
+		DeprecationCheck.run_on_expr ~force:true com e
 
 let prepare com =
 	let dctx = {

+ 4 - 5
src/generators/genjs.ml

@@ -365,8 +365,7 @@ let gen_constant ctx p = function
 	| TThis -> spr ctx (this ctx)
 	| TSuper -> assert (ctx.es_version >= 6); spr ctx "super"
 
-let print_deprecation_message com msg p =
-	com.warning msg p
+let print_deprecation_message = DeprecationCheck.warn_deprecation
 
 let is_code_injection_function e =
 	match e.eexpr with
@@ -408,7 +407,7 @@ let rec gen_call ctx e el in_value =
 		print_deprecation_message ctx.com "__new__ is deprecated, use js.Syntax.construct instead" e.epos;
 		gen_syntax ctx "construct" args e.epos
 	| TIdent "__js__", args ->
-		(* TODO: add deprecation warning when we figure out what to do with purity here *)
+		print_deprecation_message ctx.com "__js__ is deprecated, use js.Syntax.code instead" e.epos;
 		gen_syntax ctx "code" args e.epos
 	| TIdent "__instanceof__",  args ->
 		print_deprecation_message ctx.com "__instanceof__ is deprecated, use js.Syntax.instanceof instead" e.epos;
@@ -1648,14 +1647,14 @@ let generate com =
 				) c.cl_ordered_statics
 			| _ -> ()
 		) com.types;
-		!r 
+		!r
 	end in
 	let anyExposed = exposed <> [] in
 	let exposedObject = { os_name = ""; os_fields = [] } in
 	let toplevelExposed = ref [] in
 	if anyExposed then begin
 		let exportMap = Hashtbl.create 0 in
-		List.iter (fun path -> 
+		List.iter (fun path ->
 			let parts = ExtString.String.nsplit path "." in
 			let rec loop p pre =
 				match p with

+ 2 - 2
src/generators/genphp7.ml

@@ -1625,8 +1625,8 @@ class code_writer (ctx:php_generator_context) hx_type_path php_name =
 				| TCall (_, [arg]) when is_native_struct_array_cast expr && is_object_declaration arg ->
 					(match (reveal_expr arg).eexpr with TObjectDecl fields -> self#write_assoc_array_decl fields | _ -> fail self#pos __POS__)
 				| TCall ({ eexpr = TIdent name}, args) when is_magic expr ->
-					if not (defined ctx.pgc_common Define.NoDeprecationWarnings) then
-						ctx.pgc_common.warning ("untyped " ^ name ^ " is deprecated. Use php.Syntax instead.") self#pos;
+					let msg = "untyped " ^ name ^ " is deprecated. Use php.Syntax instead." in
+					DeprecationCheck.warn_deprecation ctx.pgc_common msg self#pos;
 					self#write_expr_magic name args
 				| TCall ({ eexpr = TField (expr, access) }, args) when is_string expr -> self#write_expr_call_string expr access args
 				| TCall (expr, args) when is_syntax_extern expr -> self#write_expr_call_syntax_extern expr args

+ 1 - 2
src/typing/macroContext.ml

@@ -534,8 +534,7 @@ let load_macro' ctx display cpath f p =
 			| _ -> error "Macro should be called on a class" p
 		) in
 		api.MacroApi.current_macro_module <- (fun() -> mloaded);
-		if not (Common.defined ctx.com Define.NoDeprecationWarnings) then
-			DeprecationCheck.check_cf mctx.com meth p;
+		DeprecationCheck.check_cf mctx.com meth p;
 		let meth = (match follow meth.cf_type with TFun (args,ret) -> (args,ret,cl,meth),mloaded | _ -> error "Macro call should be a method" p) in
 		restore();
 		if not ctx.in_macro then flush_macro_context mint ctx;

+ 2 - 4
src/typing/matcher.ml

@@ -209,10 +209,8 @@ module Pattern = struct
 				v
 		in
 		let con_enum en ef p =
-			if not (Common.defined ctx.com Define.NoDeprecationWarnings) then begin
-				DeprecationCheck.check_enum pctx.ctx.com en p;
-				DeprecationCheck.check_ef pctx.ctx.com ef p;
-			end;
+			DeprecationCheck.check_enum pctx.ctx.com en p;
+			DeprecationCheck.check_ef pctx.ctx.com ef p;
 			ConEnum(en,ef),p
 		in
 		let con_static c cf p = ConStatic(c,cf),p in

+ 4 - 4
src/typing/typeload.ml

@@ -210,7 +210,7 @@ let load_type_def ctx p t =
 
 	(* The type name is the module name or the module sub-type name *)
 	let tname = (match t.tsub with None -> t.tname | Some n -> n) in
-	
+
 	try
 		(* If there's a sub-type, there's no reason to look in our module or its imports *)
 		if t.tsub <> None then raise Not_found;
@@ -311,8 +311,8 @@ let rec load_instance' ctx (t,p) allow_no_params =
 			| TClassDecl {cl_kind = KGeneric} -> true,false
 			| TClassDecl {cl_kind = KGenericBuild _} -> false,true
 			| TTypeDecl td ->
-				if not (Common.defined ctx.com Define.NoDeprecationWarnings) then
-					begin try
+				DeprecationCheck.if_enabled ctx.com (fun() ->
+					try
 						let msg = match Meta.get Meta.Deprecated td.t_meta with
 							| _,[EConst(String(s,_)),_],_ -> s
 							| _ -> "This typedef is deprecated in favor of " ^ (s_type (print_context()) td.t_type)
@@ -320,7 +320,7 @@ let rec load_instance' ctx (t,p) allow_no_params =
 						DeprecationCheck.warn_deprecation ctx.com msg p
 					with Not_found ->
 						()
-					end;
+				);
 				false,false
 			| _ -> false,false
 		in

+ 1 - 2
src/typing/typerBase.ml

@@ -123,8 +123,7 @@ let rec type_module_type ctx t tparams p =
 		mk (TTypeExpr (TEnumDecl e)) (TType (e.e_type,types)) p
 	| TTypeDecl s ->
 		let t = apply_params s.t_params (List.map (fun _ -> mk_mono()) s.t_params) s.t_type in
-		if not (Common.defined ctx.com Define.NoDeprecationWarnings) then
-			DeprecationCheck.check_typedef ctx.com s p;
+		DeprecationCheck.check_typedef ctx.com s p;
 		(match follow t with
 		| TEnum (e,params) ->
 			type_module_type ctx (TEnumDecl e) (Some params) p