瀏覽代碼

add `name_pos` to `mk_field` (closes #5605)

Simon Krajewski 9 年之前
父節點
當前提交
41c4c9f627

+ 2 - 2
src/generators/codegen.ml

@@ -142,12 +142,12 @@ let add_property_field com c =
 	| [] -> ()
 	| [] -> ()
 	| _ ->
 	| _ ->
 		let fields,values = List.fold_left (fun (fields,values) (n,v) ->
 		let fields,values = List.fold_left (fun (fields,values) (n,v) ->
-			let cf = mk_field n com.basic.tstring p in
+			let cf = mk_field n com.basic.tstring p null_pos in
 			PMap.add n cf fields,(n, ExprBuilder.make_string com v p) :: values
 			PMap.add n cf fields,(n, ExprBuilder.make_string com v p) :: values
 		) (PMap.empty,[]) props in
 		) (PMap.empty,[]) props in
 		let t = mk_anon fields in
 		let t = mk_anon fields in
 		let e = mk (TObjectDecl values) t p in
 		let e = mk (TObjectDecl values) t p in
-		let cf = mk_field "__properties__" t p in
+		let cf = mk_field "__properties__" t p null_pos in
 		cf.cf_expr <- Some e;
 		cf.cf_expr <- Some e;
 		c.cl_statics <- PMap.add cf.cf_name cf c.cl_statics;
 		c.cl_statics <- PMap.add cf.cf_name cf c.cl_statics;
 		c.cl_ordered_statics <- cf :: c.cl_ordered_statics
 		c.cl_ordered_statics <- cf :: c.cl_ordered_statics

+ 1 - 1
src/optimization/dce.ml

@@ -609,7 +609,7 @@ let run com main full =
 			begin match c.cl_init with
 			begin match c.cl_init with
 				| Some e when keep_class || Meta.has Meta.KeepInit c.cl_meta ->
 				| Some e when keep_class || Meta.has Meta.KeepInit c.cl_meta ->
 					(* create a fake field to deal with our internal logic (issue #3286) *)
 					(* create a fake field to deal with our internal logic (issue #3286) *)
-					let cf = mk_field "__init__" e.etype e.epos in
+					let cf = mk_field "__init__" e.etype e.epos null_pos in
 					cf.cf_expr <- Some e;
 					cf.cf_expr <- Some e;
 					loop true cf
 					loop true cf
 				| _ ->
 				| _ ->

+ 4 - 4
src/optimization/filters.ml

@@ -790,7 +790,7 @@ let add_rtti ctx t =
 	in
 	in
 	match t with
 	match t with
 	| TClassDecl c when has_rtti c && not (PMap.mem "__rtti" c.cl_statics) ->
 	| TClassDecl c when has_rtti c && not (PMap.mem "__rtti" c.cl_statics) ->
-		let f = mk_field "__rtti" ctx.t.tstring c.cl_pos in
+		let f = mk_field "__rtti" ctx.t.tstring c.cl_pos null_pos in
 		let str = Genxml.gen_type_string ctx.com t in
 		let str = Genxml.gen_type_string ctx.com t in
 		f.cf_expr <- Some (mk (TConst (TString str)) f.cf_type c.cl_pos);
 		f.cf_expr <- Some (mk (TConst (TString str)) f.cf_type c.cl_pos);
 		c.cl_ordered_statics <- f :: c.cl_ordered_statics;
 		c.cl_ordered_statics <- f :: c.cl_ordered_statics;
@@ -858,7 +858,7 @@ let add_field_inits ctx t =
 					tf_type = ctx.com.basic.tvoid;
 					tf_type = ctx.com.basic.tvoid;
 					tf_expr = mk (TBlock el) ctx.com.basic.tvoid c.cl_pos;
 					tf_expr = mk (TBlock el) ctx.com.basic.tvoid c.cl_pos;
 				}) ct c.cl_pos in
 				}) ct c.cl_pos in
-				let ctor = mk_field "new" ct c.cl_pos in
+				let ctor = mk_field "new" ct c.cl_pos null_pos in
 				ctor.cf_kind <- Method MethNormal;
 				ctor.cf_kind <- Method MethNormal;
 				{ ctor with cf_expr = Some ce }
 				{ ctor with cf_expr = Some ce }
 			| Some cf ->
 			| Some cf ->
@@ -895,7 +895,7 @@ let add_meta_field ctx t = match t with
 		| None -> ()
 		| None -> ()
 		| Some e ->
 		| Some e ->
 			add_feature ctx.com "has_metadata";
 			add_feature ctx.com "has_metadata";
-			let f = mk_field "__meta__" t_dynamic c.cl_pos in
+			let f = mk_field "__meta__" t_dynamic c.cl_pos null_pos in
 			f.cf_expr <- Some e;
 			f.cf_expr <- Some e;
 			let can_deal_with_interface_metadata () = match ctx.com.platform with
 			let can_deal_with_interface_metadata () = match ctx.com.platform with
 				| Flash when Common.defined ctx.com Define.As3 -> false
 				| Flash when Common.defined ctx.com Define.As3 -> false
@@ -906,7 +906,7 @@ let add_meta_field ctx t = match t with
 				(* borrowed from gencommon, but I did wash my hands afterwards *)
 				(* borrowed from gencommon, but I did wash my hands afterwards *)
 				let path = fst c.cl_path,snd c.cl_path ^ "_HxMeta" in
 				let path = fst c.cl_path,snd c.cl_path ^ "_HxMeta" in
 				let ncls = mk_class c.cl_module path c.cl_pos null_pos in
 				let ncls = mk_class c.cl_module path c.cl_pos null_pos in
-				let cf = mk_field "__meta__" e.etype e.epos in
+				let cf = mk_field "__meta__" e.etype e.epos null_pos in
 				cf.cf_expr <- Some e;
 				cf.cf_expr <- Some e;
 				ncls.cl_statics <- PMap.add "__meta__" cf ncls.cl_statics;
 				ncls.cl_statics <- PMap.add "__meta__" cf ncls.cl_statics;
 				ncls.cl_ordered_statics <- cf :: ncls.cl_ordered_statics;
 				ncls.cl_ordered_statics <- cf :: ncls.cl_ordered_statics;

+ 1 - 1
src/optimization/optimizer.ml

@@ -1313,7 +1313,7 @@ let rec reduce_loop ctx e =
 		| None -> reduce_expr ctx e
 		| None -> reduce_expr ctx e
 		| Some e -> reduce_loop ctx e)
 		| Some e -> reduce_loop ctx e)
 	| TCall ({ eexpr = TFunction func } as ef,el) ->
 	| TCall ({ eexpr = TFunction func } as ef,el) ->
-		let cf = mk_field "" ef.etype e.epos in
+		let cf = mk_field "" ef.etype e.epos null_pos in
 		let ethis = mk (TConst TThis) t_dynamic e.epos in
 		let ethis = mk (TConst TThis) t_dynamic e.epos in
 		let rt = (match follow ef.etype with TFun (_,rt) -> rt | _ -> assert false) in
 		let rt = (match follow ef.etype with TFun (_,rt) -> rt | _ -> assert false) in
 		let inl = (try type_inline ctx cf func ethis el rt None e.epos ~self_calling_closure:true false with Error (Custom _,_) -> None) in
 		let inl = (try type_inline ctx cf func ethis el rt None e.epos ~self_calling_closure:true false with Error (Custom _,_) -> None) in

+ 3 - 3
src/typing/type.ml

@@ -398,11 +398,11 @@ let module_extra file sign time kind =
 	}
 	}
 
 
 
 
-let mk_field name t p = {
+let mk_field name t p name_pos = {
 	cf_name = name;
 	cf_name = name;
 	cf_type = t;
 	cf_type = t;
 	cf_pos = p;
 	cf_pos = p;
-	cf_name_pos = p;
+	cf_name_pos = name_pos;
 	cf_doc = None;
 	cf_doc = None;
 	cf_meta = [];
 	cf_meta = [];
 	cf_public = true;
 	cf_public = true;
@@ -424,7 +424,7 @@ let null_class =
 	c.cl_private <- true;
 	c.cl_private <- true;
 	c
 	c
 
 
-let null_field = mk_field "" t_dynamic Ast.null_pos
+let null_field = mk_field "" t_dynamic Ast.null_pos Ast.null_pos
 
 
 let null_abstract = {
 let null_abstract = {
 	a_path = ([],"");
 	a_path = ([],"");

+ 3 - 3
src/typing/typeload.ml

@@ -1339,7 +1339,7 @@ let add_constructor ctx c force_constructor p =
 			tf_type = ctx.t.tvoid;
 			tf_type = ctx.t.tvoid;
 			tf_expr = mk (TBlock []) ctx.t.tvoid p;
 			tf_expr = mk (TBlock []) ctx.t.tvoid p;
 		}) (tfun [] ctx.t.tvoid) p in
 		}) (tfun [] ctx.t.tvoid) p in
-		let cf = mk_field "new" constr.etype p in
+		let cf = mk_field "new" constr.etype p null_pos in
 		cf.cf_expr <- Some constr;
 		cf.cf_expr <- Some constr;
 		cf.cf_type <- constr.etype;
 		cf.cf_type <- constr.etype;
 		cf.cf_meta <- [Meta.CompilerGenerated,[],null_pos];
 		cf.cf_meta <- [Meta.CompilerGenerated,[],null_pos];
@@ -1373,7 +1373,7 @@ let check_struct_init_constructor ctx c p = match c.cl_constructor with
 			tf_expr = mk (TBlock el) ctx.t.tvoid p
 			tf_expr = mk (TBlock el) ctx.t.tvoid p
 		} in
 		} in
 		let e = mk (TFunction tf) (TFun(tl,ctx.t.tvoid)) p in
 		let e = mk (TFunction tf) (TFun(tl,ctx.t.tvoid)) p in
-		let cf = mk_field "new" e.etype p in
+		let cf = mk_field "new" e.etype p null_pos in
 		cf.cf_expr <- Some e;
 		cf.cf_expr <- Some e;
 		cf.cf_type <- e.etype;
 		cf.cf_type <- e.etype;
 		cf.cf_meta <- [Meta.CompilerGenerated,[],null_pos];
 		cf.cf_meta <- [Meta.CompilerGenerated,[],null_pos];
@@ -2685,7 +2685,7 @@ module ClassInitializer = struct
 				| Not_found ->
 				| Not_found ->
 					if req_name <> None then display_error ctx (name ^ ": Custom property accessor is no longer supported, please use get/set") p else
 					if req_name <> None then display_error ctx (name ^ ": Custom property accessor is no longer supported, please use get/set") p else
 					if c.cl_interface then begin
 					if c.cl_interface then begin
-						let cf = mk_field m t p in
+						let cf = mk_field m t p null_pos in
 						cf.cf_meta <- [Meta.CompilerGenerated,[],null_pos];
 						cf.cf_meta <- [Meta.CompilerGenerated,[],null_pos];
 						cf.cf_kind <- Method MethNormal;
 						cf.cf_kind <- Method MethNormal;
 						c.cl_fields <- PMap.add cf.cf_name cf c.cl_fields;
 						c.cl_fields <- PMap.add cf.cf_name cf c.cl_fields;

+ 9 - 9
src/typing/typer.ml

@@ -625,7 +625,7 @@ let rec unify_min_raise ctx (el:texpr list) : t =
 			) PMap.empty el in
 			) PMap.empty el in
 			let fields = PMap.foldi (fun n el acc ->
 			let fields = PMap.foldi (fun n el acc ->
 				let t = try unify_min_raise ctx el with Error (Unify _, _) -> raise Not_found in
 				let t = try unify_min_raise ctx el with Error (Unify _, _) -> raise Not_found in
-				PMap.add n (mk_field n t (List.hd el).epos) acc
+				PMap.add n (mk_field n t (List.hd el).epos null_pos) acc
 			) fields PMap.empty in
 			) fields PMap.empty in
 			TAnon { a_fields = fields; a_status = ref Closed }
 			TAnon { a_fields = fields; a_status = ref Closed }
 		with Not_found ->
 		with Not_found ->
@@ -1375,7 +1375,7 @@ let rec type_ident_raise ctx i p mode =
 					| MCall ->
 					| MCall ->
 						(* create a fake class with a fake field to emulate inlining *)
 						(* create a fake class with a fake field to emulate inlining *)
 						let c = mk_class ctx.m.curmod (["local"],v.v_name) e.epos null_pos in
 						let c = mk_class ctx.m.curmod (["local"],v.v_name) e.epos null_pos in
-						let cf = { (mk_field v.v_name v.v_type e.epos) with cf_params = params; cf_expr = Some e; cf_kind = Method MethInline } in
+						let cf = { (mk_field v.v_name v.v_type e.epos null_pos) with cf_params = params; cf_expr = Some e; cf_kind = Method MethInline } in
 						c.cl_extern <- true;
 						c.cl_extern <- true;
 						c.cl_fields <- PMap.add cf.cf_name cf PMap.empty;
 						c.cl_fields <- PMap.add cf.cf_name cf PMap.empty;
 						AKInline (mk (TConst TNull) (TInst (c,[])) p, cf, FInstance(c,[],cf), t)
 						AKInline (mk (TConst TNull) (TInst (c,[])) p, cf, FInstance(c,[],cf), t)
@@ -1908,7 +1908,7 @@ let unify_int ctx e k =
 			in
 			in
 			cf2
 			cf2
 		with Not_found ->
 		with Not_found ->
-			let cf2 = mk_field name (map_monos cf.cf_type) cf.cf_pos in
+			let cf2 = mk_field name (map_monos cf.cf_type) cf.cf_pos cf.cf_name_pos in
 			if stat then begin
 			if stat then begin
 				c.cl_statics <- PMap.add name cf2 c.cl_statics;
 				c.cl_statics <- PMap.add name cf2 c.cl_statics;
 				c.cl_ordered_statics <- cf2 :: c.cl_ordered_statics
 				c.cl_ordered_statics <- cf2 :: c.cl_ordered_statics
@@ -3068,7 +3068,7 @@ and type_object_decl ctx fl with_type p =
 	let type_fields field_map =
 	let type_fields field_map =
 		let fields = ref PMap.empty in
 		let fields = ref PMap.empty in
 		let extra_fields = ref [] in
 		let extra_fields = ref [] in
-		let fl = List.map (fun (n, e) ->
+		let fl = List.map (fun (n,e) ->
 			let n,is_quoted,is_valid = Parser.unquote_ident n in
 			let n,is_quoted,is_valid = Parser.unquote_ident n in
 			if PMap.mem n !fields then error ("Duplicate field in object declaration : " ^ n) p;
 			if PMap.mem n !fields then error ("Duplicate field in object declaration : " ^ n) p;
 			let e = try
 			let e = try
@@ -3083,7 +3083,7 @@ and type_object_decl ctx fl with_type p =
 			in
 			in
 			if is_valid then begin
 			if is_valid then begin
 				if String.length n > 0 && n.[0] = '$' then error "Field names starting with a dollar are not allowed" p;
 				if String.length n > 0 && n.[0] = '$' then error "Field names starting with a dollar are not allowed" p;
-				let cf = mk_field n e.etype e.epos in
+				let cf = mk_field n e.etype e.epos null_pos in (* TODO: use field pos if we have it *)
 				fields := PMap.add n cf !fields;
 				fields := PMap.add n cf !fields;
 			end;
 			end;
 			let e = if is_quoted then wrap_quoted_meta e else e in
 			let e = if is_quoted then wrap_quoted_meta e else e in
@@ -3108,7 +3108,7 @@ and type_object_decl ctx fl with_type p =
 			if PMap.mem f acc then error ("Duplicate field in object declaration : " ^ f) p;
 			if PMap.mem f acc then error ("Duplicate field in object declaration : " ^ f) p;
 			let e = type_expr ctx e Value in
 			let e = type_expr ctx e Value in
 			(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
 			(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
-			let cf = mk_field f e.etype e.epos in
+			let cf = mk_field f e.etype e.epos null_pos in
 			let e = if is_quoted then wrap_quoted_meta e else e in
 			let e = if is_quoted then wrap_quoted_meta e else e in
 			((f,e) :: l, if is_valid then begin
 			((f,e) :: l, if is_valid then begin
 				if String.length f > 0 && f.[0] = '$' then error "Field names starting with a dollar are not allowed" p;
 				if String.length f > 0 && f.[0] = '$' then error "Field names starting with a dollar are not allowed" p;
@@ -3130,7 +3130,7 @@ and type_object_decl ctx fl with_type p =
 			| _ -> assert false
 			| _ -> assert false
 		in
 		in
 		let fields = List.fold_left (fun acc (n,opt,t) ->
 		let fields = List.fold_left (fun acc (n,opt,t) ->
-			let f = mk_field n t ctor.cf_pos in
+			let f = mk_field n t ctor.cf_pos ctor.cf_name_pos in
 			if opt then f.cf_meta <- [(Meta.Optional,[],ctor.cf_pos)];
 			if opt then f.cf_meta <- [(Meta.Optional,[],ctor.cf_pos)];
 			PMap.add n f acc
 			PMap.add n f acc
 		) PMap.empty args in
 		) PMap.empty args in
@@ -4061,7 +4061,7 @@ and handle_display ctx e_ast iscall with_type =
 					a.a_fields)
 					a.a_fields)
 			| TFun (args,ret) ->
 			| TFun (args,ret) ->
 				let t = opt_args args ret in
 				let t = opt_args args ret in
-				let cf = mk_field "bind" (tfun [t] t) p in
+				let cf = mk_field "bind" (tfun [t] t) p null_pos in
 				PMap.add "bind" cf PMap.empty
 				PMap.add "bind" cf PMap.empty
 			| _ ->
 			| _ ->
 				PMap.empty
 				PMap.empty
@@ -4106,7 +4106,7 @@ and handle_display ctx e_ast iscall with_type =
 		let fields = PMap.fold (fun f acc -> PMap.add f.cf_name f acc) fields use_methods in
 		let fields = PMap.fold (fun f acc -> PMap.add f.cf_name f acc) fields use_methods in
 		let fields = match fst e_ast with
 		let fields = match fst e_ast with
 			| EConst(String s) when String.length s = 1 ->
 			| EConst(String s) when String.length s = 1 ->
-				let cf = mk_field "code" ctx.t.tint e.epos in
+				let cf = mk_field "code" ctx.t.tint e.epos null_pos in
 				cf.cf_doc <- Some "The character code of this character (inlined at compile-time).";
 				cf.cf_doc <- Some "The character code of this character (inlined at compile-time).";
 				cf.cf_kind <- Var { v_read = AccNormal; v_write = AccNever };
 				cf.cf_kind <- Var { v_read = AccNormal; v_write = AccNever };
 				PMap.add cf.cf_name cf fields
 				PMap.add cf.cf_name cf fields