Quellcode durchsuchen

more separation

Simon Krajewski vor 3 Jahren
Ursprung
Commit
3b95f63922

+ 4 - 5
src/context/abstractCast.ml

@@ -123,8 +123,7 @@ let prepare_array_access_field ctx a pl cf p =
 		) monos cf.cf_params;
 	in
 	let get_ta() =
-		let ta = apply_params a.a_params pl a.a_this in
-		if has_class_field_flag cf CfImpl then ta
+		if has_class_field_flag cf CfImpl then apply_params a.a_params pl a.a_this
 		else TAbstract(a,pl)
 	in
 	map,check_constraints,get_ta
@@ -147,9 +146,9 @@ let find_array_read_access_raise ctx a pl e1 p =
 				end
 			| _ -> loop cfl
 	in
-	loop a.a_array
+	loop a.a_array_read
 
-let find_array_write_access_raise ctx a pl e1 e2  p =
+let find_array_write_access_raise ctx a pl e1 e2 p =
 	let rec loop cfl =
 		match cfl with
 		| [] -> raise Not_found
@@ -168,7 +167,7 @@ let find_array_write_access_raise ctx a pl e1 e2  p =
 				end
 			| _ -> loop cfl
 	in
-	loop a.a_array
+	loop a.a_array_write
 
 let find_array_read_access ctx a tl e1 p =
 	try

+ 1 - 1
src/core/json/genjson.ml

@@ -688,7 +688,7 @@ let generate_abstract ctx a =
 		"unops",jlist generate_unop a.a_unops;
 		"from",generate_casts a.a_from_field a.a_from;
 		"to",generate_casts a.a_to_field a.a_to;
-		"array",jlist (classfield_ref ctx) a.a_array;
+		"array",jlist (classfield_ref ctx) (a.a_array_read @ a.a_array_write);
 		"read",jopt (classfield_ref ctx) a.a_read;
 		"write",jopt (classfield_ref ctx) a.a_write;
 	]

+ 2 - 1
src/core/tFunctions.ml

@@ -223,7 +223,8 @@ let null_abstract = {
 	a_from_field = [];
 	a_to = [];
 	a_to_field = [];
-	a_array = [];
+	a_array_read = [];
+	a_array_write = [];
 	a_read = None;
 	a_write = None;
 	a_call = None;

+ 2 - 1
src/core/tPrinting.ml

@@ -606,7 +606,8 @@ module Printer = struct
 			"a_to",s_list ", " s_type_kind a.a_to;
 			"a_from_field",s_list ", " (fun (t,cf) -> Printf.sprintf "%s: %s" (s_type_kind t) cf.cf_name) a.a_from_field;
 			"a_to_field",s_list ", " (fun (t,cf) -> Printf.sprintf "%s: %s" (s_type_kind t) cf.cf_name) a.a_to_field;
-			"a_array",s_list ", " (fun cf -> cf.cf_name) a.a_array;
+			"a_array_read",s_list ", " (fun cf -> cf.cf_name) a.a_array_read;
+			"a_array_write",s_list ", " (fun cf -> cf.cf_name) a.a_array_write;
 			"a_read",s_opt (fun cf -> cf.cf_name) a.a_read;
 			"a_write",s_opt (fun cf -> cf.cf_name) a.a_write;
 		]

+ 2 - 1
src/core/tType.ml

@@ -336,7 +336,8 @@ and tabstract = {
 	mutable a_from_field : (t * tclass_field) list;
 	mutable a_to : t list;
 	mutable a_to_field : (t * tclass_field) list;
-	mutable a_array : tclass_field list;
+	mutable a_array_read : tclass_field list;
+	mutable a_array_write : tclass_field list;
 	mutable a_read : tclass_field option;
 	mutable a_write : tclass_field option;
 	mutable a_call : tclass_field option;

+ 1 - 1
src/macro/macroApi.ml

@@ -930,7 +930,7 @@ and encode_tabstract a =
 		"unops", encode_array (List.map (fun (op,postfix,cf) -> encode_obj [ "op",encode_unop op; "postFix",vbool (match postfix with Postfix -> true | Prefix -> false); "field",encode_cfield cf]) a.a_unops);
 		"from", encode_array ((List.map (fun t -> encode_obj [ "t",encode_type t; "field",vnull]) a.a_from) @ (List.map (fun (t,cf) -> encode_obj [ "t",encode_type t; "field",encode_cfield cf]) a.a_from_field));
 		"to", encode_array ((List.map (fun t -> encode_obj [ "t",encode_type t; "field",vnull]) a.a_to) @ (List.map (fun (t,cf) -> encode_obj [ "t",encode_type t; "field",encode_cfield cf]) a.a_to_field));
-		"array", encode_array (List.map encode_cfield a.a_array);
+		"array", encode_array (List.map encode_cfield (a.a_array_read @ a.a_array_write));
 		"resolve", (match a.a_read with None -> vnull | Some cf -> encode_cfref cf);
 		"resolveWrite", (match a.a_write with None -> vnull | Some cf -> encode_cfref cf)
 	]

+ 1 - 1
src/typing/calls.ml

@@ -434,7 +434,7 @@ let array_access ctx e1 e2 mode p =
 	let has_abstract_array_access = ref false in
 	try
 		(match follow e1.etype with
-		| TAbstract ({a_impl = Some c} as a,pl) when a.a_array <> [] ->
+		| TAbstract ({a_impl = Some c} as a,pl) when a.a_array_write <> [] || a.a_array_read <> [] ->
 			begin match mode with
 			| MSet _ ->
 				(* resolve later *)

+ 2 - 1
src/typing/fields.ml

@@ -544,7 +544,8 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 			let has_special_field a =
 				List.exists (fun (_,cf) -> cf.cf_name = i) a.a_ops
 				|| List.exists (fun (_,_,cf) -> cf.cf_name = i) a.a_unops
-				|| List.exists (fun cf -> cf.cf_name = i) a.a_array
+				|| List.exists (fun cf -> cf.cf_name = i) a.a_array_read
+				|| List.exists (fun cf -> cf.cf_name = i) a.a_array_write
 			in
 			match follow t with
 			| TAnon { a_status = { contents = Statics { cl_kind = KAbstractImpl a } } }

+ 10 - 2
src/typing/typeloadFields.ml

@@ -1101,7 +1101,14 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 					a.a_to_field <- (TLazy r, cf) :: a.a_to_field
 				| ((Meta.ArrayAccess,_,_) | (Meta.Op,[(EArrayDecl _),_],_)) :: _ ->
 					if fctx.is_macro then typing_error (cf.cf_name ^ ": Macro array-access functions are not supported") p;
-					a.a_array <- cf :: a.a_array;
+					begin match follow cf.cf_type with
+					| TFun(_ :: _ :: args,_) when is_empty_or_pos_infos args ->
+						a.a_array_read <- cf :: a.a_array_read;
+					| TFun(_ :: _ :: _ :: args,_) when is_empty_or_pos_infos args ->
+						a.a_array_write <- cf :: a.a_array_write;
+					| _ ->
+						typing_error (cf.cf_name ^ ": Invalid number of arguments for array access function") p
+					end;
 					allow_no_expr();
 				| (Meta.Op,[EBinop(OpAssign,_,_),_],_) :: _ ->
 					typing_error (cf.cf_name ^ ": Assignment overloading is not supported") p;
@@ -1798,7 +1805,8 @@ let init_class ctx c p context_init herits fields =
 		a.a_from_field <- List.rev a.a_from_field;
 		a.a_ops <- List.rev a.a_ops;
 		a.a_unops <- List.rev a.a_unops;
-		a.a_array <- List.rev a.a_array;
+		a.a_array_read <- List.rev a.a_array_read;
+		a.a_array_write <- List.rev a.a_array_write;
 	| None -> ());
 	c.cl_ordered_statics <- List.rev c.cl_ordered_statics;
 	c.cl_ordered_fields <- List.rev c.cl_ordered_fields;

+ 2 - 1
src/typing/typeloadModule.ml

@@ -191,7 +191,8 @@ module ModuleLevel = struct
 					a_ops = [];
 					a_unops = [];
 					a_impl = None;
-					a_array = [];
+					a_array_read = [];
+					a_array_write = [];
 					a_this = mk_mono();
 					a_read = None;
 					a_write = None;

+ 1 - 1
src/typing/typerDisplay.ml

@@ -321,7 +321,7 @@ let rec handle_signature_display ctx e_ast with_type =
 						end
 					| _ ->
 						None
-				) a.a_array in
+				) (a.a_array_read @ a.a_array_write) in
 				raise_signatures sigs 0 0 SKArrayAccess
 			| _ ->
 				raise_signatures [] 0 0 SKArrayAccess