Pārlūkot izejas kodu

[java/cs] More cast-related fixes/cleanups:

 * only generate toBool/toFloat/toInt/toLong if the subject being cast is dynamic
 * fix Std.is(StdTypes.Int64)
Cauê Waneck 9 gadi atpakaļ
vecāks
revīzija
a915af9538
4 mainītis faili ar 24 papildinājumiem un 17 dzēšanām
  1. 6 4
      src/generators/gencs.ml
  2. 8 3
      src/generators/genjava.ml
  3. 7 7
      std/cs/StdTypes.hx
  4. 3 3
      std/java/StdTypes.hx

+ 6 - 4
src/generators/gencs.ml

@@ -181,6 +181,8 @@ let rec change_md = function
 		change_md (t_to_md a.a_this)
 	| TClassDecl( { cl_kind = KAbstractImpl ({ a_this = TInst(impl,_) } as a) }) when Meta.has Meta.Delegate a.a_meta ->
 		TClassDecl impl
+	| TClassDecl( { cl_kind = KAbstractImpl (a) }) when Meta.has Meta.CoreType a.a_meta ->
+		TAbstractDecl a
 	| md -> md
 
 (* ******************************************* *)
@@ -481,7 +483,7 @@ struct
 							{ e with eexpr = TNew(boxed_ptr,[],[expr]) }
 						| Some e ->
 							run e)
-				| TCast(expr, _) when is_bool e.etype && not (is_exactly_bool gen expr.etype) ->
+				| TCast(expr, _) when is_bool e.etype && is_dynamic gen expr.etype ->
 					{
 						eexpr = TCall(
 							mk_static_field_access_infer runtime_cl "toBool" expr.epos [],
@@ -490,7 +492,7 @@ struct
 						etype = basic.tbool;
 						epos = e.epos
 					}
-				| TCast(expr, _) when is_int_float gen e.etype && not (is_cs_basic_type (gen.greal_type expr.etype)) && ( Common.defined gen.gcon Define.EraseGenerics || not (is_null e.etype) ) && name() <> "haxe.lang.Runtime" ->
+				| TCast(expr, _) when is_int_float gen e.etype && is_dynamic gen expr.etype && ( Common.defined gen.gcon Define.EraseGenerics || not (is_null e.etype) ) && name() <> "haxe.lang.Runtime" ->
 					let needs_cast = match gen.gfollow#run_f e.etype with
 						| TInst _ -> false
 						| _ -> true
@@ -509,7 +511,7 @@ struct
 
 					if needs_cast then mk_cast e.etype ret else ret
 
-				| TCast(expr, _) when Common.defined gen.gcon Define.EraseGenerics && like_i64 e.etype && not (like_i64 expr.etype) ->
+				| TCast(expr, _) when Common.defined gen.gcon Define.EraseGenerics && like_i64 e.etype && is_dynamic gen expr.etype && name() <> "haxe.lang.Runtime" ->
 					{
 						eexpr = TCall(
 							mk_static_field_access_infer runtime_cl "toLong" expr.epos [],
@@ -1387,7 +1389,7 @@ let configure gen =
 				| TField (e, s) ->
 					expr_s w e; write w "."; write_field w (field_name s)
 				| TTypeExpr mt ->
-					(match mt with
+					(match change_md mt with
 						| TClassDecl { cl_path = (["haxe"], "Int64") } -> write w ("global::" ^ module_s mt)
 						| TClassDecl { cl_path = (["haxe"], "Int32") } -> write w ("global::" ^ module_s mt)
 						| TClassDecl cl -> write w (t_s (TInst(cl, List.map (fun _ -> t_empty) cl.cl_params)));

+ 8 - 3
src/generators/genjava.ml

@@ -71,6 +71,11 @@ let rec t_has_type_param t = match follow t with
 	| TFun(f,ret) -> t_has_type_param ret || List.exists (fun (_,_,t) -> t_has_type_param t) f
 	| _ -> false
 
+let is_dynamic gen t =
+	match follow (gen.greal_type t) with
+		| TDynamic _ -> true
+		| _ -> false
+
 let is_type_param t = match follow t with
 	| TInst({ cl_kind = KTypeParameter _ }, _) -> true
 	| _ -> false
@@ -611,7 +616,7 @@ struct
 				(* 	(* let unboxed_type gen t tbyte tshort tchar tfloat = match follow t with *) *)
 				(* 	run { e with etype = unboxed_type gen e.etype tbyte tshort tchar tsingle } *)
 
-				| TCast(expr, _) when is_bool e.etype ->
+				| TCast(expr, _) when is_bool e.etype && is_dynamic gen expr.etype ->
 					{
 						eexpr = TCall(
 							mk_static_field_access_infer runtime_cl "toBool" expr.epos [],
@@ -621,7 +626,7 @@ struct
 						epos = e.epos
 					}
 
-				| TCast(expr, _) when is_int_float gen e.etype && not (is_int_float gen expr.etype) ->
+				| TCast(expr, _) when is_int_float gen e.etype && is_dynamic gen expr.etype ->
 					let needs_cast = match gen.gfollow#run_f e.etype with
 						| TInst _ -> false
 						| _ -> true
@@ -648,7 +653,7 @@ struct
 						| _ -> true
 					in
 					if need_second_cast then { e with eexpr = TCast(mk_cast (follow e.etype) (run expr), c) }  else Type.map_expr run e*)
-				| TCast(expr, _) when like_i64 e.etype && not (like_i64 expr.etype) ->
+				| TCast(expr, _) when like_i64 e.etype && is_dynamic gen expr.etype ->
 					{
 						eexpr = TCall(
 							mk_static_field_access_infer runtime_cl "toLong" expr.epos [],

+ 7 - 7
std/cs/StdTypes.hx

@@ -21,12 +21,12 @@
  */
 package cs;
 
-@:notNull @:runtimeValue @:coreType abstract Int8 to Int {}
-@:notNull @:runtimeValue @:coreType abstract Int16 to Int {}
-@:notNull @:runtimeValue @:coreType abstract Char16 from Int {}
-@:notNull @:runtimeValue @:coreType abstract UInt8 to Int from Int {}
-@:notNull @:runtimeValue @:coreType abstract UInt16 to Int {}
-@:notNull @:runtimeValue @:coreType abstract Int64 from Int from Float
+@:notNull @:runtimeValue @:coreType extern abstract Int8 to Int {}
+@:notNull @:runtimeValue @:coreType extern abstract Int16 to Int {}
+@:notNull @:runtimeValue @:coreType extern abstract Char16 from Int {}
+@:notNull @:runtimeValue @:coreType extern abstract UInt8 to Int from Int {}
+@:notNull @:runtimeValue @:coreType extern abstract UInt16 to Int {}
+@:notNull @:runtimeValue @:coreType extern abstract Int64 from Int from Float
 {
 	@:op(A+B) public static function addI(lhs:Int64, rhs:Int):Int64;
 	@:op(A+B) public static function add(lhs:Int64, rhs:Int64):Int64;
@@ -62,7 +62,7 @@ package cs;
 	@:op(--A) public static function preDecrement(t:Int64):Int64;
 	@:op(A--) public static function postDecrement(t:Int64):Int64;
 }
-@:notNull @:runtimeValue @:coreType abstract UInt64 from Int from Int64 from Float from haxe.Int64
+@:notNull @:runtimeValue @:coreType extern abstract UInt64 from Int from Int64 from Float from haxe.Int64
 {
 	@:op(A+B) public static function addI(lhs:UInt64, rhs:Int):UInt64;
 	@:op(A+B) public static function add(lhs:UInt64, rhs:UInt64):UInt64;

+ 3 - 3
std/java/StdTypes.hx

@@ -21,9 +21,9 @@
  */
 package java;
 
-@:notNull @:runtimeValue @:coreType abstract Int8 from Int {}
-@:notNull @:runtimeValue @:coreType abstract Int16 from Int {}
-@:notNull @:runtimeValue @:coreType abstract Char16 from Int {}
+@:notNull @:runtimeValue @:coreType extern abstract Int8 from Int {}
+@:notNull @:runtimeValue @:coreType extern abstract Int16 from Int {}
+@:notNull @:runtimeValue @:coreType extern abstract Char16 from Int {}
 @:notNull @:runtimeValue @:coreType extern abstract Int64 from Int from Float
 {
 	@:op(A+B) public static function addI(lhs:Int64, rhs:Int):Int64;