瀏覽代碼

run deprecation check in diagnostics mode (closes vshaxe/vshaxe#49)

Simon Krajewski 9 年之前
父節點
當前提交
d141af2ceb
共有 5 個文件被更改,包括 90 次插入85 次删除
  1. 87 1
      src/display/display.ml
  2. 0 81
      src/generators/codegen.ml
  3. 2 0
      src/main.ml
  4. 0 2
      src/optimization/filters.ml
  5. 1 1
      src/typing/typer.ml

+ 87 - 1
src/display/display.ml

@@ -277,6 +277,91 @@ module DocumentSymbols = struct
 		l
 end
 
+module DeprecationCheck = struct
+
+	let curclass = ref null_class
+
+	let warned_positions = Hashtbl.create 0
+
+	let print_deprecation_message com meta s p_usage =
+		let s = match meta with
+			| _,[EConst(String s),_],_ -> s
+			| _ -> Printf.sprintf "Usage of this %s is deprecated" s
+		in
+		if not (Hashtbl.mem warned_positions p_usage) then begin
+			Hashtbl.replace warned_positions p_usage true;
+			com.warning s p_usage;
+		end
+
+	let check_meta com meta s p_usage =
+		try
+			print_deprecation_message com (Meta.get Meta.Deprecated meta) s p_usage;
+		with Not_found ->
+			()
+
+	let check_cf com cf p = check_meta com cf.cf_meta "field" p
+
+	let check_class com c p = if c != !curclass then check_meta com c.cl_meta "class" p
+
+	let check_enum com en p = check_meta com en.e_meta "enum" p
+
+	let check_ef com ef p = check_meta com ef.ef_meta "enum field" p
+
+	let check_typedef com t p = check_meta com t.t_meta "typedef" p
+
+	let check_module_type com mt p = match mt with
+		| TClassDecl c -> check_class com c p
+		| TEnumDecl en -> check_enum com en p
+		| _ -> ()
+
+	let run_on_expr com e =
+		let rec expr e = match e.eexpr with
+			| TField(e1,fa) ->
+				expr e1;
+				begin match fa with
+					| FStatic(c,cf) | FInstance(c,_,cf) ->
+						check_class com c e.epos;
+						check_cf com cf e.epos
+					| FAnon cf ->
+						check_cf com cf e.epos
+					| FClosure(co,cf) ->
+						(match co with None -> () | Some (c,_) -> check_class com c e.epos);
+						check_cf com cf e.epos
+					| FEnum(en,ef) ->
+						check_enum com en e.epos;
+						check_ef com ef e.epos;
+					| _ ->
+						()
+				end
+			| TNew(c,_,el) ->
+				List.iter expr el;
+				check_class com c e.epos;
+				(match c.cl_constructor with None -> () | Some cf -> check_cf com cf e.epos)
+			| TTypeExpr(mt) | TCast(_,Some mt) ->
+				check_module_type com mt e.epos
+			| TMeta((Meta.Deprecated,_,_) as meta,e1) ->
+				print_deprecation_message com meta "field" e1.epos;
+				expr e1;
+			| _ ->
+				Type.iter expr e
+		in
+		expr e
+
+	let run_on_field com cf = match cf.cf_expr with None -> () | Some e -> run_on_expr com e
+
+	let run com =
+		List.iter (fun t -> match t with
+			| TClassDecl c ->
+				curclass := c;
+				(match c.cl_constructor with None -> () | Some cf -> run_on_field com cf);
+				(match c.cl_init with None -> () | Some e -> run_on_expr com e);
+				List.iter (run_on_field com) c.cl_ordered_statics;
+				List.iter (run_on_field com) c.cl_ordered_fields;
+			| _ ->
+				()
+		) com.types
+end
+
 module Diagnostics = struct
 	module DiagnosticsKind = struct
 		type t =
@@ -380,7 +465,8 @@ module Diagnostics = struct
 		| None -> ()
 		| Some e ->
 			find_unused_variables com e;
-			check_other_things com e
+			check_other_things com e;
+			DeprecationCheck.run_on_expr com e
 
 	let prepare com global =
 		List.iter (function

+ 0 - 81
src/generators/codegen.ml

@@ -1299,87 +1299,6 @@ module UnificationCallback = struct
 				check (Type.map_expr (run ff) e)
 end;;
 
-module DeprecationCheck = struct
-
-	let curclass = ref null_class
-
-	let warned_positions = Hashtbl.create 0
-
-	let print_deprecation_message com meta s p_usage =
-		let s = match meta with
-			| _,[EConst(String s),_],_ -> s
-			| _ -> Printf.sprintf "Usage of this %s is deprecated" s
-		in
-		if not (Hashtbl.mem warned_positions p_usage) then begin
-			Hashtbl.replace warned_positions p_usage true;
-			com.warning s p_usage;
-		end
-
-	let check_meta com meta s p_usage =
-		try
-			print_deprecation_message com (Meta.get Meta.Deprecated meta) s p_usage;
-		with Not_found ->
-			()
-
-	let check_cf com cf p = check_meta com cf.cf_meta "field" p
-
-	let check_class com c p = if c != !curclass then check_meta com c.cl_meta "class" p
-
-	let check_enum com en p = check_meta com en.e_meta "enum" p
-
-	let check_ef com ef p = check_meta com ef.ef_meta "enum field" p
-
-	let check_typedef com t p = check_meta com t.t_meta "typedef" p
-
-	let check_module_type com mt p = match mt with
-		| TClassDecl c -> check_class com c p
-		| TEnumDecl en -> check_enum com en p
-		| _ -> ()
-
-	let run com =
-		let rec expr e = match e.eexpr with
-			| TField(e1,fa) ->
-				expr e1;
-				begin match fa with
-					| FStatic(c,cf) | FInstance(c,_,cf) ->
-						check_class com c e.epos;
-						check_cf com cf e.epos
-					| FAnon cf ->
-						check_cf com cf e.epos
-					| FClosure(co,cf) ->
-						(match co with None -> () | Some (c,_) -> check_class com c e.epos);
-						check_cf com cf e.epos
-					| FEnum(en,ef) ->
-						check_enum com en e.epos;
-						check_ef com ef e.epos;
-					| _ ->
-						()
-				end
-			| TNew(c,_,el) ->
-				List.iter expr el;
-				check_class com c e.epos;
-				(match c.cl_constructor with None -> () | Some cf -> check_cf com cf e.epos)
-			| TTypeExpr(mt) | TCast(_,Some mt) ->
-				check_module_type com mt e.epos
-			| TMeta((Meta.Deprecated,_,_) as meta,e1) ->
-				print_deprecation_message com meta "field" e1.epos;
-				expr e1;
-			| _ ->
-				Type.iter expr e
-		in
-		List.iter (fun t -> match t with
-			| TClassDecl c ->
-				curclass := c;
-				let field cf = match cf.cf_expr with None -> () | Some e -> expr e in
-				(match c.cl_constructor with None -> () | Some cf -> field cf);
-				(match c.cl_init with None -> () | Some e -> expr e);
-				List.iter field c.cl_ordered_statics;
-				List.iter field c.cl_ordered_fields;
-			| _ ->
-				()
-		) com.types
-end
-
 let interpolate_code com code tl f_string f_expr p =
 	let exprs = Array.of_list tl in
 	let i = ref 0 in

+ 2 - 0
src/main.ml

@@ -821,6 +821,8 @@ try
 		com.types <- types;
 		com.modules <- modules;
 		DisplayOutput.process_global_display_mode com tctx;
+		if not (Common.defined com Define.NoDeprecationWarnings) then
+			Display.DeprecationCheck.run com;
 		Filters.run com tctx main;
 		t();
 		if ctx.has_error then raise Abort;

+ 0 - 2
src/optimization/filters.ml

@@ -1076,8 +1076,6 @@ let iter_expressions fl mt =
 		()
 
 let run com tctx main =
-	if not (Common.defined com Define.NoDeprecationWarnings) then
-		Codegen.DeprecationCheck.run com;
 	let new_types = List.filter (fun t -> not (is_cached t)) com.types in
 	(* PASS 1: general expression filters *)
 	let filters = [

+ 1 - 1
src/typing/typer.ml

@@ -795,7 +795,7 @@ let rec type_module_type ctx t tparams 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
-			Codegen.DeprecationCheck.check_typedef ctx.com s p;
+			Display.DeprecationCheck.check_typedef ctx.com s p;
 		(match follow t with
 		| TEnum (e,params) ->
 			type_module_type ctx (TEnumDecl e) (Some params) p