Browse Source

reactivate null checker code, but disable it by default

Simon Krajewski 10 years ago
parent
commit
0c5bf3926f
1 changed files with 22 additions and 21 deletions
  1. 22 21
      analyzer.ml

+ 22 - 21
analyzer.ml

@@ -765,6 +765,8 @@ module Ssa = struct
 		| TLocal v ->
 			begin try eval_cond ctx (get_var_value v)
 			with Not_found -> [] end
+		| TParenthesis e1 | TMeta(_,e1) | TCast(e1,None) ->
+			eval_cond ctx e1
 		| _ ->
 			[]
 
@@ -776,37 +778,36 @@ module Ssa = struct
 			ctx.var_conds <- IntMap.add v.v_id [cond] ctx.var_conds
 		end
 
-(* 	let apply_cond ctx = function
-		| Equal({v_extra = Some(_,Some {eexpr = TLocal v})} as v0,e1) ->
-			let v' = assign_var ctx v (mk_loc v0 e1.epos) e1.epos in
+	let apply_cond ctx = function
+		| Equal(v,e1) ->
+			let v' = assign_var ctx (get_origin_var v) (mk_loc v e1.epos) e1.epos in
 			append_cond ctx v' (Equal(v',e1)) e1.epos
-		| NotEqual({v_extra = Some(_,Some {eexpr = TLocal v})} as v0,e1) ->
-			let v' = assign_var ctx v (mk_loc v0 e1.epos) e1.epos in
+		| NotEqual(v,e1) ->
+			let v' = assign_var ctx (get_origin_var v) (mk_loc v e1.epos) e1.epos in
 			append_cond ctx v' (NotEqual(v',e1)) e1.epos
-		| _ -> ()
 
 	let apply_not_null_cond ctx v p =
-		apply_cond ctx (NotEqual(v,(mk (TConst TNull) t_dynamic p))) *)
+		apply_cond ctx (NotEqual(v,(mk (TConst TNull) t_dynamic p)))
 
 	let apply com e =
 		let rec handle_if ctx f econd eif eelse =
 			let econd = loop ctx econd in
-			(* let cond = eval_cond ctx econd in *)
+			let cond = eval_cond ctx econd in
 			let join = mk_join_node() in
 			let close = branch ctx eif.epos in
-			(* List.iter (apply_cond ctx) cond; *)
+			List.iter (apply_cond ctx) cond;
 			let eif = loop ctx eif in
 			close join;
 			let eelse = match eelse with
 				| None ->
-					(* let cond = invert_conds cond in *)
-					(* List.iter (apply_cond ctx) cond; *)
+					let cond = invert_conds cond in
+					List.iter (apply_cond ctx) cond;
 					add_branch join ctx.cur_data e.epos;
 					None
 				| Some e ->
 					let close = branch ctx e.epos in
-					(* let cond = invert_conds cond in *)
-					(* List.iter (apply_cond ctx) cond; *)
+					let cond = invert_conds cond in
+					List.iter (apply_cond ctx) cond;
 					let eelse = loop ctx e in
 					close join;
 					Some eelse
@@ -843,15 +844,15 @@ module Ssa = struct
 				let close = branch ctx e.epos in
 				List.iter (fun (v,co) ->
 					declare_var ctx v e.epos;
-(* 					match co with
+					match co with
 						| Some TNull when (match v.v_type with TType({t_path=["haxe"],"PosInfos"},_) -> false | _ -> true) -> ()
-						| _ -> apply_not_null_cond ctx v e.epos *)
+						| _ -> apply_not_null_cond ctx v e.epos
 				) tf.tf_args;
 				let e' = loop ctx tf.tf_expr in
 				close (mk_join_node());
 				{e with eexpr = TFunction {tf with tf_expr = e'}}
 			(* var modifications *)
-			| TBinop(OpAssign,({eexpr = TLocal v} as e1),e2) when v.v_name <> "this" ->
+			| TBinop(OpAssign,({eexpr = TLocal v} as e1),e2) ->
 				let e2 = loop ctx e2 in
 				let _ = assign_var ctx v e2 e1.epos in
 				{e with eexpr = TBinop(OpAssign,e1,e2)}
@@ -912,7 +913,7 @@ module Ssa = struct
 				e
 			| TFor(v,e1,ebody) ->
 				declare_var ctx v e.epos;
-				(* apply_not_null_cond ctx v e1.epos; *)
+				apply_not_null_cond ctx v e1.epos;
 				let v' = IntMap.find v.v_id ctx.cur_data.nd_var_map in
 				let e1 = loop ctx e1 in
 				let ebody = handle_loop_body ctx ebody in
@@ -928,7 +929,7 @@ module Ssa = struct
 				close_join_node ctx join_ex e.epos;
 				let catches = List.map (fun (v,e) ->
 					declare_var ctx v e.epos;
-					(* apply_not_null_cond ctx v e.epos; *)
+					apply_not_null_cond ctx v e.epos;
 					let close = branch ctx e.epos in
 					let e = loop ctx e in
 					close join_bottom;
@@ -1131,7 +1132,7 @@ module ConstPropagation = struct
 				e'
 			else
 				e
- 		| TEnumParameter(e1,ef,i) ->
+		| TEnumParameter(e1,ef,i) ->
 			let ev = value ssa true e1 in
 			begin try
 				value ssa force (semi_awkward_enum_value ssa ev i)
@@ -1550,7 +1551,7 @@ module Config = struct
 			ssa_apply = true;
 			const_propagation = not (Common.raw_defined com "analyzer-no-const-propagation");
 			check_has_effect = (Common.raw_defined com "analyzer-check-has-effect");
-			check = not (Common.raw_defined com "analyzer-no-check");
+			check = (Common.raw_defined com "analyzer-check-null");
 			local_dce = not (Common.raw_defined com "analyzer-no-local-dce") && not (Common.defined com Define.As3);
 			ssa_unapply = not (Common.raw_defined com "analyzer-no-ssa-unapply");
 			simplifier_unapply = not (Common.raw_defined com "analyzer-no-simplify-unapply");
@@ -1609,7 +1610,7 @@ module Run = struct
 					if config.check_has_effect then EffectChecker.run com is_var_expression e;
 					let e,ssa = with_timer "analyzer-ssa-apply" (fun () -> Ssa.apply com e) in
 					let e = if config.const_propagation then with_timer "analyzer-const-propagation" (fun () -> ConstPropagation.apply ssa e) else e in
-					(* let e = if config.check then with_timer "analyzer-checker" (fun () -> Checker.apply ssa e) else e in *)
+					let e = if config.check then with_timer "analyzer-checker" (fun () -> Checker.apply ssa e) else e in
 					let e = if config.local_dce && config.analyzer_use && not has_unbound && not is_var_expression then with_timer "analyzer-local-dce" (fun () -> LocalDce.apply e) else e in
 					let e = if config.ssa_unapply then with_timer "analyzer-ssa-unapply" (fun () -> Ssa.unapply com e) else e in
 					List.iter (fun f -> f()) ssa.Ssa.cleanup;