2
0
Эх сурвалжийг харах

fix overload handling again

Simon Krajewski 1 жил өмнө
parent
commit
411c725d7b

+ 1 - 14
src/compiler/hxb/hxbReader.ml

@@ -2,7 +2,6 @@ open Globals
 open Ast
 open Type
 open HxbData
-open HxbShared
 open HxbReaderApi
 
 (* Debug utils *)
@@ -1505,7 +1504,6 @@ class hxb_reader
 
 	method read_cfr =
 		let l = read_uleb128 ch in
-		let instance_overload_cache = Hashtbl.create 0 in
 		let a = Array.init l (fun i ->
 			let c = self#read_class_ref in
 			begin try
@@ -1547,18 +1545,7 @@ class hxb_reader
 					| [] ->
 						raise (HxbFailure (Printf.sprintf "Bad overload depth for %s on %s: %i" cf.cf_name (s_type_path c.cl_path) depth))
 				in
-				let cfl = match kind with
-					| CfrStatic | CfrConstructor ->
-						(cf :: cf.cf_overloads)
-					| CfrMember ->
-						let key = (c.cl_path,cf.cf_name) in
-						try
-							Hashtbl.find instance_overload_cache key
-						with Not_found ->
-							let l = get_instance_overloads c cf.cf_name in
-							Hashtbl.add instance_overload_cache key l;
-							l
-				in
+				let cfl = cf :: cf.cf_overloads in
 				loop depth cfl
 			in
 			let depth = read_uleb128 ch in

+ 0 - 24
src/compiler/hxb/hxbShared.ml

@@ -1,24 +0,0 @@
-open Type
-
-let get_instance_overloads c name =
-	let acc = DynArray.create () in
-	let rec loop c =
-		ignore(c.cl_build());
-		begin try
-			let cf = PMap.find name c.cl_fields in
-			List.iter (DynArray.add acc) (cf :: cf.cf_overloads);
-		with Not_found ->
-			()
-		end;
-		if has_class_flag c CInterface then
-			List.iter (fun (c,_) ->
-				loop c
-			) c.cl_implements
-		else match c.cl_super with
-			| Some(c,_) ->
-				loop c
-			| None ->
-				()
-	in
-	loop c;
-	DynArray.to_list acc

+ 46 - 18
src/compiler/hxb/hxbWriter.ml

@@ -3,7 +3,6 @@ open Ast
 open Type
 open HxbData
 open Tanon_identification
-open HxbShared
 
 (* Debug utils *)
 let no_color = false
@@ -969,32 +968,61 @@ class hxb_writer
 		let index = try
 			class_fields#get cf
 		with Not_found ->
-			let cf_base = find_field c cf.cf_name kind in
-			let depth,cf =
+			let find_overload c cf_base =
 				let rec loop depth cfl = match cfl with
 					| cf' :: cfl ->
 						if cf' == cf then
-							depth,cf
+							Some(c,depth)
 						else
 							loop (depth + 1) cfl
 					| [] ->
-						print_endline (Printf.sprintf "Could not resolve %s overload for %s on %s" (s_class_field_ref_kind kind) cf.cf_name (s_type_path c.cl_path));
-						0,cf
-				in
-				let cfl = match kind with
-					| CfrStatic | CfrConstructor ->
-						(cf_base :: cf_base.cf_overloads)
-					| CfrMember ->
-						let key = (c.cl_path,cf_base.cf_name) in
-						try
-							Hashtbl.find instance_overload_cache key
-						with Not_found ->
-							let l = get_instance_overloads c cf_base.cf_name in
-							Hashtbl.add instance_overload_cache key l;
-							l
+						None
 				in
+				let cfl = cf_base :: cf_base.cf_overloads in
 				loop 0 cfl
 			in
+			let find_overload c =
+				try
+					find_overload c (find_field c cf.cf_name kind)
+				with Not_found ->
+					None
+			in
+			let r = match kind with
+				| CfrStatic | CfrConstructor ->
+					find_overload c;
+				| CfrMember ->
+					(* For member overloads we need to find the correct class, which is a mess. *)
+					let rec loop c = match find_overload c with
+						| Some _ as r ->
+							r
+						| None ->
+							if has_class_flag c CInterface then
+								let rec loopi l = match l with
+									| [] ->
+										None
+									| (c,_) :: l ->
+										match loop c with
+										| Some _ as r ->
+											r
+										| None ->
+											loopi l
+								in
+								loopi c.cl_implements
+							else match c.cl_super with
+								| Some(c,_) ->
+									loop c
+								| None ->
+									None
+					in
+					loop c;
+			in
+			let c,depth = match r with
+				| None ->
+					print_endline (Printf.sprintf "Could not resolve %s overload for %s on %s" (s_class_field_ref_kind kind) cf.cf_name (s_type_path c.cl_path));
+					c,0
+				| Some(c,depth) ->
+					c,depth
+			in
 			class_fields#add cf (c,kind,depth)
 		in
 		IOChunk.write_uleb128 chunk.io index