Bladeren bron

changed local_using to tclass list

Simon Krajewski 13 jaren geleden
bovenliggende
commit
d84113722d
3 gewijzigde bestanden met toevoegingen van 50 en 46 verwijderingen
  1. 1 1
      typecore.ml
  2. 12 3
      typeload.ml
  3. 37 42
      typer.ml

+ 1 - 1
typecore.ml

@@ -71,7 +71,7 @@ and typer = {
 	(* per-module *)
 	current : module_def;
 	mutable local_types : module_type list;
-	mutable local_using : module_type list;
+	mutable local_using : tclass list;
 	(* per-class *)
 	mutable curclass : tclass;
 	mutable tthis : t;

+ 12 - 3
typeload.ml

@@ -1285,7 +1285,7 @@ let init_class ctx c p herits fields =
 	delay ctx (fun() -> add_constructor c);
 	List.rev fl
 
-let resolve_typedef ctx t =
+let resolve_typedef t =
 	match t with
 	| TClassDecl _ | TEnumDecl _ -> t
 	| TTypeDecl td ->
@@ -1404,6 +1404,15 @@ let type_module ctx m file tdecls loadp =
 		let s = List.find (fun d -> match d with TTypeDecl { t_path = _ , n } -> n = name | _ -> false) m.m_types in
 		match s with TTypeDecl s -> s | _ -> assert false
 	in
+	let filter_classes types =
+		let rec loop acc types = match List.rev types with
+			| t :: l ->
+				(match resolve_typedef t with TClassDecl c -> loop (c :: acc) l | _ -> loop acc l)
+			| [] ->
+				acc
+		in
+		loop [] types
+	in
 	(* here is an additional PASS 1 phase, which handle the type parameters declaration, with lazy contraints *)
 	List.iter (fun (d,p) ->
 		match d with
@@ -1436,11 +1445,11 @@ let type_module ctx m file tdecls loadp =
 			| None ->
 				let md = ctx.g.do_load_module ctx (t.tpackage,t.tname) p in
 				let types = List.filter (fun t -> not (t_infos t).mt_private) md.m_types in
-				ctx.local_using <- ctx.local_using @ (List.map (resolve_typedef ctx) types);
+				ctx.local_using <- ctx.local_using @ (filter_classes types);
 				ctx.local_types <- ctx.local_types @ types
 			| Some _ ->
 				let t = load_type_def ctx p t in
-				ctx.local_using<- ctx.local_using @ [resolve_typedef ctx t];
+				ctx.local_using <- ctx.local_using @ (filter_classes [t]);
 				ctx.local_types <- ctx.local_types @ [t])
 		| EClass d ->
 			let c = get_class d.d_name in

+ 37 - 42
typer.ml

@@ -589,29 +589,27 @@ let field_access ctx mode f t e p =
 let using_field ctx mode e i p =
 	if mode = MSet then raise Not_found;
 	let rec loop = function
-		| [] ->
-			raise Not_found
-		| TEnumDecl _ :: l | TTypeDecl _ :: l ->
+	| [] ->
+		raise Not_found
+	| c :: l ->
+		try
+			let f = PMap.find i c.cl_statics in
+			let t = field_type ctx c [] f p in
+			(match follow t with
+			| TFun ((_,_,t0) :: args,r) ->
+				let t0 = (try match t0 with
+				| TType({t_path=["haxe";"macro"], ("ExprOf"|"ExprRequire")}, [t]) ->
+					(try unify_raise ctx e.etype t p with Error (Unify _,_) -> raise Not_found); t;
+				| _ -> raise Not_found
+				with Not_found ->
+					(try unify_raise ctx e.etype t0 p with Error (Unify _,_) -> raise Not_found); t0) in
+				if follow e.etype == t_dynamic && follow t0 != t_dynamic then raise Not_found;
+				if has_meta ":noUsing" f.cf_meta then raise Not_found;
+				let et = type_module_type ctx (TClassDecl c) None p in
+				AKUsing (mk (TField (et,i)) t p,c,f,e)
+			| _ -> raise Not_found)
+		with Not_found ->
 			loop l
-		| TClassDecl c :: l ->
-			try
-				let f = PMap.find i c.cl_statics in
-				let t = field_type ctx c [] f p in
-				(match follow t with
-				| TFun ((_,_,t0) :: args,r) ->
-					let t0 = (try match t0 with
-					| TType({t_path=["haxe";"macro"], ("ExprOf"|"ExprRequire")}, [t]) ->
-						(try unify_raise ctx e.etype t p with Error (Unify _,_) -> raise Not_found); t;
-					| _ -> raise Not_found
-					with Not_found ->
-						(try unify_raise ctx e.etype t0 p with Error (Unify _,_) -> raise Not_found); t0) in
-					if follow e.etype == t_dynamic && follow t0 != t_dynamic then raise Not_found;
-					if has_meta ":noUsing" f.cf_meta then raise Not_found;
-					let et = type_module_type ctx (TClassDecl c) None p in
-					AKUsing (mk (TField (et,i)) t p,c,f,e)
-				| _ -> raise Not_found)
-			with Not_found ->
-				loop l
 	in
 	loop ctx.local_using
 
@@ -2152,27 +2150,24 @@ and type_expr ctx ?(need_val=true) (e,p) =
 		*)
 		let rec loop acc = function
 			| [] -> acc
-			| x :: l ->
+			| c :: l ->
 				let acc = ref (loop acc l) in
-				(match x with
-				| TClassDecl c ->
-					let rec dup t = Type.map dup t in
-					List.iter (fun f ->
-						if not (has_meta ":noUsing" f.cf_meta) then
-						let f = { f with cf_type = opt_type f.cf_type } in
-						match follow (field_type ctx c [] f p) with
-						| TFun((_,_,TType({t_path=["haxe";"macro"], ("ExprOf"|"ExprRequire")}, [t])) :: args, ret)
-						| TFun ((_,_,t) :: args, ret) when (try unify_raise ctx (dup e.etype) t e.epos; true with Error (Unify _,_) -> false) ->
-							if not (can_access ctx.curclass c f true) || follow e.etype == t_dynamic && follow t != t_dynamic then
-								()
-							else begin
-								let f = prepare_using_field f in
-								let f = { f with cf_params = []; cf_public = true } in
-								acc := PMap.add f.cf_name f (!acc)
-							end
-						| _ -> ()
-					) c.cl_ordered_statics
-				| _ -> ());
+				let rec dup t = Type.map dup t in
+				List.iter (fun f ->
+					if not (has_meta ":noUsing" f.cf_meta) then
+					let f = { f with cf_type = opt_type f.cf_type } in
+					match follow (field_type ctx c [] f p) with
+					| TFun((_,_,TType({t_path=["haxe";"macro"], ("ExprOf"|"ExprRequire")}, [t])) :: args, ret)
+					| TFun ((_,_,t) :: args, ret) when (try unify_raise ctx (dup e.etype) t e.epos; true with Error (Unify _,_) -> false) ->
+						if not (can_access ctx.curclass c f true) || follow e.etype == t_dynamic && follow t != t_dynamic then
+							()
+						else begin
+							let f = prepare_using_field f in
+							let f = { f with cf_params = []; cf_public = true } in
+							acc := PMap.add f.cf_name f (!acc)
+						end
+					| _ -> ()
+				) c.cl_ordered_statics;
 				!acc
 		in
 		let use_methods = loop PMap.empty ctx.local_using in