Browse Source

remove duplicated path_s functions, use Ast.s_type_path instead

Dan Korostelev 9 years ago
parent
commit
51e41731e9
4 changed files with 23 additions and 29 deletions
  1. 4 7
      src/generators/gencommon.ml
  2. 12 12
      src/generators/gencs.ml
  3. 6 6
      src/generators/genjava.ml
  4. 1 4
      src/macro/interp.ml

+ 4 - 7
src/generators/gencommon.ml

@@ -204,9 +204,6 @@ let anon_class t =
 					| _ -> None)
 			| _ -> None
 
-let path_s path =
-	match path with | ([], s) -> s | (p, s) -> (String.concat "." (fst path)) ^ "." ^ (snd path)
-
  let rec t_to_md t = match t with
 	| TInst (cl,_) -> TClassDecl cl
 	| TEnum (e,_) -> TEnumDecl e
@@ -222,9 +219,9 @@ let path_s path =
 	| TMono r -> (match !r with | Some t -> t_to_md t | None -> assert false)
 	| _ -> assert false
 
-let get_cl mt = match mt with | TClassDecl cl -> cl | _ -> failwith (Printf.sprintf "Unexpected module type (class expected) for %s: %s" (path_s (t_path mt)) (s_module_type_kind mt))
+let get_cl mt = match mt with | TClassDecl cl -> cl | _ -> failwith (Printf.sprintf "Unexpected module type (class expected) for %s: %s" (s_type_path (t_path mt)) (s_module_type_kind mt))
 
-let get_abstract mt = match mt with | TAbstractDecl a -> a | _ -> failwith (Printf.sprintf "Unexpected module type (abstract expected) for %s: %s" (path_s (t_path mt)) (s_module_type_kind mt))
+let get_abstract mt = match mt with | TAbstractDecl a -> a | _ -> failwith (Printf.sprintf "Unexpected module type (abstract expected) for %s: %s" (s_type_path (t_path mt)) (s_module_type_kind mt))
 
 let get_tdef mt = match mt with | TTypeDecl t -> t | _ -> assert false
 
@@ -249,7 +246,7 @@ let mk_static_field_access_infer cl field pos params =
 	try
 		let cf = (PMap.find field cl.cl_statics) in
 		{ eexpr = TField(mk_classtype_access cl pos, FStatic(cl, cf)); etype = (if params = [] then cf.cf_type else apply_params cf.cf_params params cf.cf_type); epos = pos }
-	with | Not_found -> failwith ("Cannot find field " ^ field ^ " in type " ^ (path_s cl.cl_path))
+	with | Not_found -> failwith ("Cannot find field " ^ field ^ " in type " ^ (s_type_path cl.cl_path))
 
 let mk_static_field_access cl field fieldt pos =
 	{ (mk_static_field_access_infer cl field pos []) with etype = fieldt }
@@ -6697,7 +6694,7 @@ struct
 						| _ ->
 							gen.gcon.warning (debug_type et) e.epos;
 							(match gen.gcurrent_class with
-								| Some cl -> print_endline (path_s cl.cl_path)
+								| Some cl -> print_endline (s_type_path cl.cl_path)
 								| _ -> ());
 							assert false
 					in

+ 12 - 12
src/generators/gencs.ml

@@ -221,7 +221,7 @@ struct
 
 		let is_var = alloc_var "__is__" t_dynamic in
 		let name () = match gen.gcurrent_class with
-			| Some cl -> path_s cl.cl_path
+			| Some cl -> s_type_path cl.cl_path
 			| _ -> ""
 		in
 
@@ -424,7 +424,7 @@ struct
 
 		let is_cl t = match gen.greal_type t with | TInst ( { cl_path = (["System"], "Type") }, [] ) -> true | _ -> false in
 		let name () = match gen.gcurrent_class with
-			| Some cl -> path_s cl.cl_path
+			| Some cl -> s_type_path cl.cl_path
 			| _ -> ""
 		in
 
@@ -817,7 +817,7 @@ let configure gen =
 	let rec field_is_hxgeneric e = match e.eexpr with
 		| TParenthesis e | TMeta(_,e) -> field_is_hxgeneric e
 		| TField(_, (FStatic(cl,_) | FInstance(cl,_,_)) ) ->
-			(* print_endline ("is_hxgeneric " ^ path_s cl.cl_path ^ " : " ^ string_of_bool (is_hxgeneric (TClassDecl cl))); *)
+			(* print_endline ("is_hxgeneric " ^ s_type_path cl.cl_path ^ " : " ^ string_of_bool (is_hxgeneric (TClassDecl cl))); *)
 			is_hxgeneric (TClassDecl cl)
 		| _ -> true
 	in
@@ -863,10 +863,10 @@ let configure gen =
 		let path = (t_infos md).mt_path in
 		match path with
 			| ([], "String") -> "string", params
-			| ([], "Null") -> path_s (change_ns md ["haxe"; "lang"], change_clname "Null"), params
+			| ([], "Null") -> s_type_path (change_ns md ["haxe"; "lang"], change_clname "Null"), params
 			| (ns,clname) ->
 				let ns, params = change_ns_params md params ns in
-				path_s (ns, change_clname clname), params
+				s_type_path (ns, change_clname clname), params
 	in
 
 	let module_s md =
@@ -2044,7 +2044,7 @@ let configure gen =
 			| "new" -> snd cl.cl_path, true, false
 			| name when String.contains name '.' ->
 				let fn_name, path = parse_explicit_iface name in
-				(path_s path) ^ "." ^ fn_name, false, true
+				(s_type_path path) ^ "." ^ fn_name, false, true
 			| name -> try
 				let binop = PMap.find name binops_names in
 				"operator " ^ s_binop binop, false, false
@@ -3342,7 +3342,7 @@ let configure gen =
 	if not (Common.defined gen.gcon Define.KeepOldOutput) then
 		clean_files (gen.gcon.file ^ "/src") !out_files gen.gcon.verbose;
 
-	dump_descriptor gen ("hxcs_build.txt") path_s module_s;
+	dump_descriptor gen ("hxcs_build.txt") s_type_path module_s;
 	if ( not (Common.defined gen.gcon Define.NoCompilation) ) then begin
 		let old_dir = Sys.getcwd() in
 		Sys.chdir gen.gcon.file;
@@ -3379,7 +3379,7 @@ let generate con =
 		List.iter (fun cf -> gen.gbase_class_fields <- PMap.add cf.cf_name cf gen.gbase_class_fields) basic_fns;
 		configure gen
 	with | TypeNotFound path ->
-		con.error ("Error. Module '" ^ (path_s path) ^ "' is required and was not included in build.")	Ast.null_pos);
+		con.error ("Error. Module '" ^ (s_type_path path) ^ "' is required and was not included in build.")	Ast.null_pos);
 	debug_mode := false
 
 (* -net-lib implementation *)
@@ -3527,7 +3527,7 @@ let rec convert_signature ctx p = function
 	| _ -> mk_type_path ctx ([],[], "Dynamic") []
 
 let ilpath_s = function
-	| ns,[], name -> path_s (ns,name)
+	| ns,[], name -> s_type_path (ns,name)
 	| [],nested,name -> String.concat "." nested ^ "." ^ name
 	| ns, nested, name -> String.concat "." ns ^ "." ^ String.concat "." nested ^ "." ^ name
 
@@ -4452,7 +4452,7 @@ let add_net_lib com file std =
 			Hashtbl.iter (fun _ td ->
 				let path = IlMetaTools.get_path (TypeDef td) in
 				if PMap.mem "net_loader_debug" com.defines then
-					Printf.printf "found %s\n" (path_s (netpath_to_hx path));
+					Printf.printf "found %s\n" (s_type_path (netpath_to_hx path));
 				Hashtbl.replace com.net_path_map (netpath_to_hx path) path;
 				Hashtbl.replace meta.il_typedefs path td
 			) il_typedefs;
@@ -4484,12 +4484,12 @@ let add_net_lib com file std =
 	in
 
 	let build path =
-		let p = { pfile = !real_file ^ " @ " ^ path_s path; pmin = 0; pmax = 0; } in
+		let p = { pfile = !real_file ^ " @ " ^ s_type_path path; pmin = 0; pmax = 0; } in
 		let pack = match fst path with | ["haxe";"root"] -> [] | p -> p in
 		let cp = ref [] in
 		let rec build path = try
 			if PMap.mem "net_loader_debug" com.defines then
-				Printf.printf "looking up %s\n" (path_s path);
+				Printf.printf "looking up %s\n" (s_type_path path);
 			match lookup path with
 			| Some({csuper = Some{snorm = LClass( (["System"],[],("Delegate"|"MulticastDelegate")),_)}} as cls)
 				when List.mem SSealed cls.cflags.tdf_semantics ->

+ 6 - 6
src/generators/genjava.ml

@@ -945,7 +945,7 @@ let configure gen =
 					pack ^ "." ^ name
 			| _ -> raise Not_found
 		with Not_found -> match path with
-			| (ns,clname) -> path_s (change_ns ns, change_clname clname)
+			| (ns,clname) -> s_type_path (change_ns ns, change_clname clname)
 	in
 
 	let cl_cl = get_cl (get_type gen (["java";"lang"],"Class")) in
@@ -2565,7 +2565,7 @@ let generate con =
 
 	(try
 		configure gen
-	with | TypeNotFound path -> con.error ("Error. Module '" ^ (path_s path) ^ "' is required and was not included in build.")	Ast.null_pos);
+	with | TypeNotFound path -> con.error ("Error. Module '" ^ (s_type_path path) ^ "' is required and was not included in build.")	Ast.null_pos);
 	debug_mode := false
 
 (** Java lib *)
@@ -2614,7 +2614,7 @@ let jpath_to_hx (pack,name) = match pack, name with
 	| pack, name -> normalize_pack pack, jname_to_hx name
 
 let real_java_path ctx (pack,name) =
-	path_s (pack, name)
+	s_type_path (pack, name)
 
 let lookup_jclass com path =
 	let path = jpath_to_hx path in
@@ -2831,7 +2831,7 @@ let convert_java_enum ctx p pe =
 		List.iter (fun jsig ->
 			match convert_signature ctx p jsig with
 				| CTPath path ->
-					cff_meta := (Meta.Throws, [Ast.EConst (Ast.String (path_s (path.tpackage,path.tname))), p],p) :: !cff_meta
+					cff_meta := (Meta.Throws, [Ast.EConst (Ast.String (s_type_path (path.tpackage,path.tname))), p],p) :: !cff_meta
 				| _ -> ()
 		) field.jf_throws;
 
@@ -3132,7 +3132,7 @@ let jclass_with_params com cls params = try
 			cinterfaces = List.map (japply_params jparams) cls.cinterfaces;
 		}
 	with Invalid_argument("List.map2") ->
-		if com.verbose then prerr_endline ("Differing parameters for class: " ^ path_s cls.cpath);
+		if com.verbose then prerr_endline ("Differing parameters for class: " ^ s_type_path cls.cpath);
 		cls
 
 let is_object = function | TObject( (["java";"lang"], "Object"), [] ) -> true | _ -> false
@@ -3573,7 +3573,7 @@ let add_java_lib com file std =
 						if is_disallowed_inner then
 							None
 						else begin
-							if com.verbose then print_endline ("Parsed Java class " ^ (path_s cls.cpath));
+							if com.verbose then print_endline ("Parsed Java class " ^ (s_type_path cls.cpath));
 							let old_types = ctx.jtparams in
 							ctx.jtparams <- cls.ctypes :: ctx.jtparams;
 

+ 1 - 4
src/macro/interp.ml

@@ -1781,10 +1781,7 @@ let std_lib =
 			match com.main_class with
 			| None -> error()
 			| Some p ->
-				let path_s path =
-					match path with | ([], s) -> s | (p, s) -> (String.concat "." (fst path)) ^ "." ^ (snd path)
-				in
-				match ctx.curapi.get_type (path_s p) with
+				match ctx.curapi.get_type (Ast.s_type_path p) with
 				| Some(TInst (c, _)) ->
 					VString (Extc.get_full_path c.cl_pos.Ast.pfile)
 				| _ -> error();