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

move some functions out of the rec chain of doom

Simon Krajewski 9 лет назад
Родитель
Сommit
4c32ba13d9
1 измененных файлов с 47 добавлено и 46 удалено
  1. 47 46
      typer.ml

+ 47 - 46
typer.ml

@@ -1935,6 +1935,53 @@ let call_to_string ctx c e =
 	let cf = PMap.find "toString" c.cl_statics in
 	make_call ctx (mk (TField(et,FStatic(c,cf))) cf.cf_type e.epos) [e] ctx.t.tstring e.epos
 
+
+let get_next_stored_typed_expr_id =
+	let uid = ref 0 in
+	(fun() -> incr uid; !uid)
+
+let get_stored_typed_expr com id =
+	let vars = Hashtbl.create 0 in
+	let copy_var v =
+		let v2 = alloc_var v.v_name v.v_type in
+		v2.v_meta <- v.v_meta;
+		Hashtbl.add vars v.v_id v2;
+		v2;
+	in
+	let rec build_expr e =
+		match e.eexpr with
+		| TVar (v,eo) ->
+			let v2 = copy_var v in
+			{e with eexpr = TVar(v2, Option.map build_expr eo)}
+		| TFor (v,e1,e2) ->
+			let v2 = copy_var v in
+			{e with eexpr = TFor(v2, build_expr e1, build_expr e2)}
+		| TTry (e1,cl) ->
+			let cl = List.map (fun (v,e) ->
+				let v2 = copy_var v in
+				v2, build_expr e
+			) cl in
+			{e with eexpr = TTry(build_expr e1, cl)}
+		| TFunction f ->
+			let args = List.map (fun (v,c) -> copy_var v, c) f.tf_args in
+			let f = {
+				tf_args = args;
+				tf_type = f.tf_type;
+				tf_expr = build_expr f.tf_expr;
+			} in
+			{e with eexpr = TFunction f}
+		| TLocal v ->
+			(try
+				let v2 = Hashtbl.find vars v.v_id in
+				{e with eexpr = TLocal v2}
+			with _ ->
+				e)
+		| _ ->
+			map_expr build_expr e
+	in
+	let e = PMap.find id com.stored_typed_exprs in
+	build_expr e
+
 let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 	match op with
 	| OpAssign ->
@@ -3809,52 +3856,6 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		ctx.meta <- old;
 		e
 
-and get_next_stored_typed_expr_id =
-	let uid = ref 0 in
-	(fun() -> incr uid; !uid)
-
-and get_stored_typed_expr com id =
-	let vars = Hashtbl.create 0 in
-	let copy_var v =
-		let v2 = alloc_var v.v_name v.v_type in
-		v2.v_meta <- v.v_meta;
-		Hashtbl.add vars v.v_id v2;
-		v2;
-	in
-	let rec build_expr e =
-		match e.eexpr with
-		| TVar (v,eo) ->
-			let v2 = copy_var v in
-			{e with eexpr = TVar(v2, Option.map build_expr eo)}
-		| TFor (v,e1,e2) ->
-			let v2 = copy_var v in
-			{e with eexpr = TFor(v2, build_expr e1, build_expr e2)}
-		| TTry (e1,cl) ->
-			let cl = List.map (fun (v,e) ->
-				let v2 = copy_var v in
-				v2, build_expr e
-			) cl in
-			{e with eexpr = TTry(build_expr e1, cl)}
-		| TFunction f ->
-			let args = List.map (fun (v,c) -> copy_var v, c) f.tf_args in
-			let f = {
-				tf_args = args;
-				tf_type = f.tf_type;
-				tf_expr = build_expr f.tf_expr;
-			} in
-			{e with eexpr = TFunction f}
-		| TLocal v ->
-			(try
-				let v2 = Hashtbl.find vars v.v_id in
-				{e with eexpr = TLocal v2}
-			with _ ->
-				e)
-		| _ ->
-			map_expr build_expr e
-	in
-	let e = PMap.find id com.stored_typed_exprs in
-	build_expr e
-
 and handle_display ctx e_ast iscall with_type p =
 	let old = ctx.in_display in
 	ctx.in_display <- true;