Просмотр исходного кода

[analyzer] move some things around so we can use `is_removable_field` in the analyzer

Simon Krajewski 10 лет назад
Родитель
Сommit
11ed845f2a
3 измененных файлов с 19 добавлено и 17 удалено
  1. 8 6
      analyzer.ml
  2. 7 0
      codegen.ml
  3. 4 11
      filters.ml

+ 8 - 6
analyzer.ml

@@ -1,6 +1,7 @@
 open Ast
 open Type
 open Common
+open Typecore
 
 module IntMap = Map.Make(struct type t = int let compare a b = a - b end)
 
@@ -1283,7 +1284,7 @@ let update_config_from_meta config meta =
 			config
 	) config meta
 
-let run_expression_filters com config t =
+let run_expression_filters ctx config t =
 	match t with
 	| TClassDecl c when (has_analyzer_option c.cl_meta flag_ignore) ->
 		()
@@ -1295,9 +1296,9 @@ let run_expression_filters com config t =
 				| _ -> false
 			in
 			match cf.cf_expr with
-			| Some e when not (has_analyzer_option cf.cf_meta flag_ignore) && not (Meta.has Meta.Extern cf.cf_meta) (* TODO: use is_removable_field *) ->
+			| Some e when not (has_analyzer_option cf.cf_meta flag_ignore) && not (Codegen.is_removable_field ctx cf) ->
 				let config = update_config_from_meta config cf.cf_meta in
-				cf.cf_expr <- Some (run_ssa com config is_var_expression e);
+				cf.cf_expr <- Some (run_ssa ctx.com config is_var_expression e);
 			| _ -> ()
 		in
 		List.iter process_field c.cl_ordered_fields;
@@ -1309,12 +1310,13 @@ let run_expression_filters com config t =
 		| None -> ()
 		| Some e ->
 			(* never optimize init expressions (too messy) *)
-			c.cl_init <- Some (run_ssa com {config with analyzer_use = false} false e));
+			c.cl_init <- Some (run_ssa ctx.com {config with analyzer_use = false} false e));
 	| TEnumDecl _ -> ()
 	| TTypeDecl _ -> ()
 	| TAbstractDecl _ -> ()
 
-let apply com =
+let apply ctx =
+	let com = ctx.com in
 	let config = {
 		analyzer_use = true;
 		simplifier_apply = true;
@@ -1326,4 +1328,4 @@ let apply com =
 		ssa_unapply = not (Common.raw_defined com "analyzer-no-ssa-unapply");
 		simplifier_unapply = not (Common.raw_defined com "analyzer-no-simplify-unapply");
 	} in
-	List.iter (run_expression_filters com config) com.types
+	List.iter (run_expression_filters ctx config) com.types

+ 7 - 0
codegen.ml

@@ -114,6 +114,13 @@ let add_property_field com c =
 		c.cl_statics <- PMap.add cf.cf_name cf c.cl_statics;
 		c.cl_ordered_statics <- cf :: c.cl_ordered_statics
 
+let is_removable_field ctx f =
+	Meta.has Meta.Extern f.cf_meta || Meta.has Meta.Generic f.cf_meta
+	|| (match f.cf_kind with
+		| Var {v_read = AccRequire (s,_)} -> true
+		| Method MethMacro -> not ctx.in_macro
+		| _ -> false)
+
 (* -------------------------------------------------------------------------- *)
 (* REMOTING PROXYS *)
 

+ 4 - 11
filters.ml

@@ -738,23 +738,16 @@ let remove_generic_base ctx t = match t with
 
 (* Removes extern and macro fields, also checks for Void fields *)
 
-let is_removable_field ctx f =
-	Meta.has Meta.Extern f.cf_meta || Meta.has Meta.Generic f.cf_meta
-	|| (match f.cf_kind with
-		| Var {v_read = AccRequire (s,_)} -> true
-		| Method MethMacro -> not ctx.in_macro
-		| _ -> false)
-
 let remove_extern_fields ctx t = match t with
 	| TClassDecl c ->
 		if not (Common.defined ctx.com Define.DocGen) then begin
 			c.cl_ordered_fields <- List.filter (fun f ->
-				let b = is_removable_field ctx f in
+				let b = Codegen.is_removable_field ctx f in
 				if b then c.cl_fields <- PMap.remove f.cf_name c.cl_fields;
 				not b
 			) c.cl_ordered_fields;
 			c.cl_ordered_statics <- List.filter (fun f ->
-				let b = is_removable_field ctx f in
+				let b = Codegen.is_removable_field ctx f in
 				if b then c.cl_statics <- PMap.remove f.cf_name c.cl_statics;
 				not b
 			) c.cl_ordered_statics;
@@ -976,7 +969,7 @@ let run_expression_filters ctx filters t =
 		ctx.curclass <- c;
 		let process_field f =
 			match f.cf_expr with
-			| Some e when not (is_removable_field ctx f) ->
+			| Some e when not (Codegen.is_removable_field ctx f) ->
 				Codegen.AbstractCast.cast_stack := f :: !Codegen.AbstractCast.cast_stack;
 				f.cf_expr <- Some (run e);
 				Codegen.AbstractCast.cast_stack := List.tl !Codegen.AbstractCast.cast_stack;
@@ -1043,7 +1036,7 @@ let run com tctx main =
 			captured_vars com;
 		] in
 		List.iter (post_process tctx filters) com.types;
-		Analyzer.apply com;
+		Analyzer.apply tctx;
 		post_process_end();
 		iter_expressions com [verify_ast];
 		List.iter (fun f -> f()) (List.rev com.filters);