Bläddra i källkod

[typer] move some things around

Simon Krajewski 5 år sedan
förälder
incheckning
e4dec61ddd
4 ändrade filer med 42 tillägg och 43 borttagningar
  1. 36 36
      src/typing/calls.ml
  2. 6 5
      src/typing/forLoop.ml
  3. 0 1
      src/typing/typer.ml
  4. 0 1
      src/typing/typerBase.ml

+ 36 - 36
src/typing/calls.ml

@@ -102,42 +102,6 @@ let mk_array_set_call ctx (cf,tf,r,e1,e2o) c ebase p =
 			let ef = mk (TField(et,(FStatic(c,cf)))) tf p in
 			make_call ctx ef [ebase;e1;evalue] r p
 
-let rec needs_temp_var e =
-	match e.eexpr with
-	| TLocal _ | TTypeExpr _ | TConst _ -> false
-	| TField (e, _) | TParenthesis e -> needs_temp_var e
-	| _ -> true
-
-let call_to_string ctx ?(resume=false) e =
-	let gen_to_string e =
-		(* Ignore visibility of the toString field. *)
-		ctx.meta <- (Meta.PrivateAccess,[],e.epos) :: ctx.meta;
-		let acc = type_field (TypeFieldConfig.create resume) ctx e "toString" e.epos (MCall []) (WithType.with_type ctx.t.tstring) in
-		ctx.meta <- List.tl ctx.meta;
-		!build_call_ref ctx acc [] (WithType.with_type ctx.t.tstring) e.epos
-	in
-	if ctx.com.config.pf_static && not (is_nullable e.etype) then
-		gen_to_string e
-	else begin (* generate `if(e == null) 'null' else e.toString()` *)
-		let string_null = mk (TConst (TString "null")) ctx.t.tstring e.epos in
-		if needs_temp_var e then
-			let tmp = alloc_var VGenerated "tmp" e.etype e.epos in
-			let tmp_local = mk (TLocal tmp) tmp.v_type tmp.v_pos in
-			let check_null = mk (TBinop (OpEq, tmp_local, mk (TConst TNull) tmp.v_type tmp.v_pos)) ctx.t.tbool e.epos in
-			{
-				eexpr = TBlock([
-					mk (TVar (tmp, Some e)) tmp.v_type tmp.v_pos;
-					mk (TIf (check_null, string_null, Some (gen_to_string tmp_local))) ctx.t.tstring tmp.v_pos;
-
-				]);
-				etype = ctx.t.tstring;
-				epos = e.epos;
-			}
-		else
-			let check_null = mk (TBinop (OpEq, e, mk (TConst TNull) e.etype e.epos)) ctx.t.tbool e.epos in
-			mk (TIf (check_null, string_null, Some (gen_to_string e))) ctx.t.tstring e.epos
-	end
-
 let rec unify_call_args' ctx el args r callp inline force_inline =
 	let in_call_args = ctx.in_call_args in
 	ctx.in_call_args <- true;
@@ -856,6 +820,42 @@ let build_call ?(mode=MGet) ctx acc el (with_type:WithType.t) p =
 	| AKExpr e ->
 		dispatch#expr_call e el
 
+let rec needs_temp_var e =
+	match e.eexpr with
+	| TLocal _ | TTypeExpr _ | TConst _ -> false
+	| TField (e, _) | TParenthesis e -> needs_temp_var e
+	| _ -> true
+
+let call_to_string ctx ?(resume=false) e =
+	let gen_to_string e =
+		(* Ignore visibility of the toString field. *)
+		ctx.meta <- (Meta.PrivateAccess,[],e.epos) :: ctx.meta;
+		let acc = type_field (TypeFieldConfig.create resume) ctx e "toString" e.epos (MCall []) (WithType.with_type ctx.t.tstring) in
+		ctx.meta <- List.tl ctx.meta;
+		build_call ctx acc [] (WithType.with_type ctx.t.tstring) e.epos
+	in
+	if ctx.com.config.pf_static && not (is_nullable e.etype) then
+		gen_to_string e
+	else begin (* generate `if(e == null) 'null' else e.toString()` *)
+		let string_null = mk (TConst (TString "null")) ctx.t.tstring e.epos in
+		if needs_temp_var e then
+			let tmp = alloc_var VGenerated "tmp" e.etype e.epos in
+			let tmp_local = mk (TLocal tmp) tmp.v_type tmp.v_pos in
+			let check_null = mk (TBinop (OpEq, tmp_local, mk (TConst TNull) tmp.v_type tmp.v_pos)) ctx.t.tbool e.epos in
+			{
+				eexpr = TBlock([
+					mk (TVar (tmp, Some e)) tmp.v_type tmp.v_pos;
+					mk (TIf (check_null, string_null, Some (gen_to_string tmp_local))) ctx.t.tstring tmp.v_pos;
+
+				]);
+				etype = ctx.t.tstring;
+				epos = e.epos;
+			}
+		else
+			let check_null = mk (TBinop (OpEq, e, mk (TConst TNull) e.etype e.epos)) ctx.t.tbool e.epos in
+			mk (TIf (check_null, string_null, Some (gen_to_string e))) ctx.t.tstring e.epos
+	end
+
 let type_bind ctx (e : texpr) (args,ret) params p =
 	let vexpr v = mk (TLocal v) v.v_type p in
 	let acount = ref 0 in

+ 6 - 5
src/typing/forLoop.ml

@@ -5,6 +5,7 @@ open Common
 open Typecore
 open TyperBase
 open Fields
+open Calls
 open Error
 open Texpr.Builder
 
@@ -103,7 +104,7 @@ module IterationKind = struct
 					after()
 			in
 			let try_acc acc =
-				let acc_expr = !build_call_ref ctx acc [] WithType.value e.epos in
+				let acc_expr = build_call ctx acc [] WithType.value e.epos in
 				try
 					unify_raise ctx acc_expr.etype t acc_expr.epos;
 					acc_expr
@@ -239,8 +240,8 @@ module IterationKind = struct
 					| _, AKExpr({ eexpr = TField(_, FDynamic _)}) -> raise Not_found
 					| _ -> ()
 				);
-				let e_next = !build_call_ref ctx acc_next [] WithType.value e.epos in
-				let e_hasNext = !build_call_ref ctx acc_hasNext [] WithType.value e.epos in
+				let e_next = build_call ctx acc_next [] WithType.value e.epos in
+				let e_hasNext = build_call ctx acc_hasNext [] WithType.value e.epos in
 				IteratorAbstract(v_tmp,e_next,e_hasNext),e,e_next.etype
 			with Not_found ->
 				(try try_forward_array_iterator ()
@@ -508,8 +509,8 @@ let type_for_loop ctx handle_display it e2 p =
 		let e1,pt = IterationKind.check_iterator ctx "keyValueIterator" e1 e1.epos in
 		let vtmp = gen_local ctx e1.etype e1.epos in
 		let etmp = make_local vtmp vtmp.v_pos in
-		let ehasnext = !build_call_ref ctx (type_field_default_cfg ctx etmp "hasNext" etmp.epos (MCall []) (WithType.with_type ctx.t.tbool)) [] WithType.value etmp.epos in
-		let enext = !build_call_ref ctx (type_field_default_cfg ctx etmp "next" etmp.epos (MCall []) WithType.value (* WITHTYPETODO *)) [] WithType.value etmp.epos in
+		let ehasnext = build_call ctx (type_field_default_cfg ctx etmp "hasNext" etmp.epos (MCall []) (WithType.with_type ctx.t.tbool)) [] WithType.value etmp.epos in
+		let enext = build_call ctx (type_field_default_cfg ctx etmp "next" etmp.epos (MCall []) WithType.value (* WITHTYPETODO *)) [] WithType.value etmp.epos in
 		let v = gen_local ctx pt e1.epos in
 		let ev = make_local v v.v_pos in
 		let ekey = Calls.acc_get ctx (type_field_default_cfg ctx ev "key" ev.epos MGet WithType.value) ev.epos in

+ 0 - 1
src/typing/typer.ml

@@ -2882,6 +2882,5 @@ let rec create com =
 unify_min_ref := unify_min;
 unify_min_for_type_source_ref := unify_min_for_type_source;
 make_call_ref := make_call;
-build_call_ref := build_call;
 type_call_target_ref := type_call_target;
 type_block_ref := type_block

+ 0 - 1
src/typing/typerBase.ml

@@ -55,7 +55,6 @@ type object_decl_kind =
 	| ODKWithClass of tclass * tparams
 	| ODKPlain
 
-let build_call_ref : (typer -> access_kind -> expr list -> WithType.t -> pos -> texpr) ref = ref (fun _ _ _ _ _ -> die "" __LOC__)
 let type_call_target_ref : (typer -> expr -> expr list -> WithType.t -> bool -> pos -> access_kind) ref = ref (fun _ _ _ _ _ -> die "" __LOC__)
 
 let relative_path ctx file =