فهرست منبع

pass typer context and position to `find_array_access`

Simon Krajewski 11 سال پیش
والد
کامیت
f8c3828458
3فایلهای تغییر یافته به همراه9 افزوده شده و 9 حذف شده
  1. 1 1
      optimizer.ml
  2. 3 3
      typecore.ml
  3. 5 5
      typer.ml

+ 1 - 1
optimizer.ml

@@ -682,7 +682,7 @@ let rec optimize_for_loop ctx i e1 e2 p =
 			end;
 			begin try
 				(* first try: do we have an @:arrayAccess getter field? *)
-				let cf,_,r = find_array_access a tl ctx.com.basic.tint None p in
+				let cf,_,r = find_array_access ctx a tl ctx.com.basic.tint None p in
 				let get_next e_base e_index t p =
 					make_static_call ctx c cf (apply_params a.a_params tl) [e_base;e_index] r p
 				in

+ 3 - 3
typecore.ml

@@ -393,7 +393,7 @@ let create_fake_module ctx file =
 	Hashtbl.replace ctx.g.modules mdep.m_path mdep;
 	mdep
 
-let find_array_access_raise a pl t1 t2o =
+let find_array_access_raise ctx a pl t1 t2o p =
 	let is_set = t2o <> None in
 	let ta = apply_params a.a_params pl a.a_this in
 	let rec loop cfl = match cfl with
@@ -423,8 +423,8 @@ let find_array_access_raise a pl t1 t2o =
 	in
 	loop a.a_array
 
-let find_array_access a tl t1 t2o p =
-	try find_array_access_raise a tl t1 t2o
+let find_array_access ctx a tl t1 t2o p =
+	try find_array_access_raise ctx a tl t1 t2o p
 	with Not_found -> match t2o with
 		| None ->
 			error (Printf.sprintf "No @:arrayAccess function accepts argument of %s" (s_type (print_context()) t1)) p

+ 5 - 5
typer.ml

@@ -1796,7 +1796,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 			let e2 = Codegen.AbstractCast.cast_or_unify ctx t e2 p in
 			make_call ctx (mk (TField (e,quick_field_dynamic e.etype ("set_" ^ cf.cf_name))) (tfun [t] t) p) [e2] t p
 		| AKAccess(a,tl,c,ebase,ekey) ->
-			let cf,tf,r = find_array_access a tl ekey.etype (Some e2.etype) p in
+			let cf,tf,r = find_array_access ctx a tl ekey.etype (Some e2.etype) p in
 			begin match cf.cf_expr with
 				| None ->
 					let ea = mk (TArray(ebase,ekey)) r p in
@@ -1871,7 +1871,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 			else
 				e_call
 		| AKAccess(a,tl,c,ebase,ekey) ->
-			let cf_get,tf_get,r_get = find_array_access a tl ekey.etype None p in
+			let cf_get,tf_get,r_get = find_array_access ctx a tl ekey.etype None p in
 			(* bind complex keys to a variable so they do not make it into the output twice *)
 			let ekey,l = match Optimizer.make_constant_expression ctx ekey with
 				| Some e -> e, fun () -> None
@@ -1885,7 +1885,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 			let ast_call = (EMeta((Meta.PrivateAccess,[],pos ast_call),ast_call),pos ast_call) in
 			let eget = type_binop ctx op ast_call e2 true with_type p in
 			unify ctx eget.etype r_get p;
-			let cf_set,tf_set,r_set = find_array_access a tl ekey.etype (Some eget.etype) p in
+			let cf_set,tf_set,r_set = find_array_access ctx a tl ekey.etype (Some eget.etype) p in
 			let et = type_module_type ctx (TClassDecl c) None p in
 			begin match cf_set.cf_expr,cf_get.cf_expr with
 				| None,None ->
@@ -2272,7 +2272,7 @@ and type_unop ctx op flag e p =
 		| AKNo s ->
 			error ("The field or identifier " ^ s ^ " is not accessible for " ^ (if set then "writing" else "reading")) p
 		| AKAccess(a,tl,c,ebase,ekey) ->
-			let cf,tf,r = find_array_access a tl ekey.etype None p in
+			let cf,tf,r = find_array_access ctx a tl ekey.etype None p in
 			let e = match cf.cf_expr with
 				| None ->
 					mk (TArray(ebase,ekey)) r p
@@ -2547,7 +2547,7 @@ and type_access ctx e p mode =
 				AKAccess (a,pl,c,e1,e2)
 			| _ ->
 				has_abstract_array_access := true;
-				let cf,tf,r = find_array_access a pl e2.etype None p in
+				let cf,tf,r = find_array_access ctx a pl e2.etype None p in
 				let e = match cf.cf_expr with
 					| None ->
 						mk (TArray(e1,e2)) r p