Browse Source

fixed opt Null params in flash9

Nicolas Cannasse 18 years ago
parent
commit
f46febafa1
4 changed files with 46 additions and 12 deletions
  1. 12 1
      genxml.ml
  2. 1 1
      std/StringBuf.hx
  3. 1 1
      std/StringTools.hx
  4. 32 9
      typer.ml

+ 12 - 1
genxml.ml

@@ -48,13 +48,24 @@ let gen_doc_opt d =
 let gen_arg_name (name,opt,_) =
 let gen_arg_name (name,opt,_) =
 	(if opt then "?" else "") ^ name
 	(if opt then "?" else "") ^ name
 
 
+let rec follow_param t =
+	match t with
+	| TMono r ->
+		(match !r with
+		| Some t -> follow_param t
+		| _ -> t)
+	| TType ({ t_path = [],"Null" } as t,tl) ->
+		follow_param (apply_params t.t_types tl t.t_type)
+	| _ ->
+		t
+
 let rec gen_type t =
 let rec gen_type t =
 	match t with
 	match t with
 	| TMono m -> (match !m with None -> tag "unknown" | Some t -> gen_type t)
 	| TMono m -> (match !m with None -> tag "unknown" | Some t -> gen_type t)
 	| TEnum (e,params) -> node "e" [gen_path e.e_path e.e_private] (List.map gen_type params)
 	| TEnum (e,params) -> node "e" [gen_path e.e_path e.e_private] (List.map gen_type params)
 	| TInst (c,params) -> node "c" [gen_path c.cl_path c.cl_private] (List.map gen_type params)
 	| TInst (c,params) -> node "c" [gen_path c.cl_path c.cl_private] (List.map gen_type params)
 	| TType (t,params) -> node "t" [gen_path t.t_path t.t_private] (List.map gen_type params)
 	| TType (t,params) -> node "t" [gen_path t.t_path t.t_private] (List.map gen_type params)
-	| TFun (args,r) -> node "f" ["a",String.concat ":" (List.map gen_arg_name args)] (List.map gen_type (List.map (fun (_,_,t) -> t) args @ [r]))
+	| TFun (args,r) -> node "f" ["a",String.concat ":" (List.map gen_arg_name args)] (List.map gen_type (List.map (fun (_,opt,t) -> if opt then follow_param t else t) args @ [r]))
 	| TAnon a -> node "a" [] (pmap (fun f -> node f.cf_name [] [gen_type f.cf_type]) a.a_fields)
 	| TAnon a -> node "a" [] (pmap (fun f -> node f.cf_name [] [gen_type f.cf_type]) a.a_fields)
 	| TDynamic t2 -> node "d" [] (if t == t2 then [] else [gen_type t2])
 	| TDynamic t2 -> node "d" [] (if t == t2 then [] else [gen_type t2])
 	| TLazy f -> gen_type (!f())
 	| TLazy f -> gen_type (!f())

+ 1 - 1
std/StringBuf.hx

@@ -58,7 +58,7 @@ class StringBuf {
 	/**
 	/**
 		Adds a part of a string to the string buffer.
 		Adds a part of a string to the string buffer.
 	**/
 	**/
-	public function addSub( s : String, pos : Int, ?len : Null<Int> ) {
+	public function addSub( s : String, pos : Int, ?len : Int ) {
 		#if neko
 		#if neko
 		__add_sub(b,untyped s.__s,pos,len);
 		__add_sub(b,untyped s.__s,pos,len);
 		#else flash9
 		#else flash9

+ 1 - 1
std/StringTools.hx

@@ -264,7 +264,7 @@ class StringTools {
 	/**
 	/**
 		Encode a number into a hexadecimal representation, with an optional number of zeros for left padding.
 		Encode a number into a hexadecimal representation, with an optional number of zeros for left padding.
 	**/
 	**/
-	public static function hex( n : Int, ?digits : Null<Int> ) {
+	public static function hex( n : Int, ?digits : Int ) {
 		var s = "";
 		var s = "";
 		var hexChars = "0123456789ABCDEF";
 		var hexChars = "0123456789ABCDEF";
 		do {
 		do {

+ 32 - 9
typer.ml

@@ -416,11 +416,6 @@ and load_type ctx p t =
 		| _ ->
 		| _ ->
 			TFun (List.map (fun t -> "",false,load_type ctx p t) args,load_type ctx p r)
 			TFun (List.map (fun t -> "",false,load_type ctx p t) args,load_type ctx p r)
 
 
-let load_type_opt ctx p t =
-	match t with
-	| None -> mk_mono()
-	| Some t -> load_type ctx p t
-
 let rec reverse_type t =
 let rec reverse_type t =
 	match t with
 	match t with
 	| TEnum (e,params) ->
 	| TEnum (e,params) ->
@@ -769,6 +764,34 @@ let rec return_flow ctx e =
 (* ---------------------------------------------------------------------- *)
 (* ---------------------------------------------------------------------- *)
 (* PASS 3 : type expression & check structure *)
 (* PASS 3 : type expression & check structure *)
 
 
+let load_type_opt ?(param=false) ctx p t =
+	match t with
+	| None ->
+		if param && ctx.flash9 then
+			let show = hide_types ctx in
+			let t = load_normal_type ctx { tpackage = []; tname = "Null"; tparams = [] } null_pos true in
+			show();
+			t
+		else
+			mk_mono()
+	| Some t ->
+		let t = load_type ctx p t in
+		if not param || not ctx.flash9 then
+			t
+		else match follow t with
+		| TInst ({ cl_path = [],"Int" },_)
+		| TInst ({ cl_path = [],"Float" },_)
+		| TEnum ({ e_path = [],"Bool" },_) ->
+			let show = hide_types ctx in
+			(match load_type_def ctx null_pos ([],"Null") with
+			| TTypeDecl td ->
+				show();
+				if List.length td.t_types <> 1 then assert false;
+				TType (td,[t])
+			| _ ->				
+				assert false)			
+		| _ -> t
+
 let type_expr_with_type ctx e t =
 let type_expr_with_type ctx e t =
 	match e with
 	match e with
 	| (EFunction _,_) ->
 	| (EFunction _,_) ->
@@ -1977,7 +2000,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 		type_unop ctx op flag e p
 		type_unop ctx op flag e p
 	| EFunction f ->
 	| EFunction f ->
 		let rt = load_type_opt ctx p f.f_type in
 		let rt = load_type_opt ctx p f.f_type in
-		let args = List.map (fun (s,opt,t) -> s , opt, load_type_opt ctx p t) f.f_args in
+		let args = List.map (fun (s,opt,t) -> s , opt, load_type_opt ~param:opt ctx p t) f.f_args in
 		(match ctx.param_type with
 		(match ctx.param_type with
 		| None -> ()
 		| None -> ()
 		| Some t ->
 		| Some t ->
@@ -2230,13 +2253,13 @@ let init_class ctx c p herits fields =
 	let is_public access =
 	let is_public access =
 		if c.cl_extern || c.cl_interface || extends_public then not (List.mem APrivate access) else List.mem APublic access
 		if c.cl_extern || c.cl_interface || extends_public then not (List.mem APrivate access) else List.mem APublic access
 	in
 	in
-	let type_opt ctx p t =
+	let type_opt ?param ctx p t =
 		match t with
 		match t with
 		| None when c.cl_extern || c.cl_interface ->
 		| None when c.cl_extern || c.cl_interface ->
 			display_error ctx "Type required for extern classes and interfaces" p;
 			display_error ctx "Type required for extern classes and interfaces" p;
 			t_dynamic
 			t_dynamic
 		| _ ->
 		| _ ->
-			load_type_opt ctx p t
+			load_type_opt ?param ctx p t
 	in
 	in
 	let rec has_field f = function
 	let rec has_field f = function
 		| None -> false
 		| None -> false
@@ -2297,7 +2320,7 @@ let init_class ctx c p herits fields =
 				type_params = params @ ctx.type_params;
 				type_params = params @ ctx.type_params;
 			} in
 			} in
 			let ret = type_opt ctx p f.f_type in
 			let ret = type_opt ctx p f.f_type in
-			let args = List.map (fun (name,opt,t) -> name , opt, type_opt ctx p t) f.f_args in
+			let args = List.map (fun (name,opt,t) -> name , opt, type_opt ~param:opt ctx p t) f.f_args in
 			let t = TFun (args,ret) in
 			let t = TFun (args,ret) in
 			let stat = List.mem AStatic access in
 			let stat = List.mem AStatic access in
 			let constr = (name = "new") in
 			let constr = (name = "new") in