Browse Source

[java/cs] Java unit tests compiling again

Caue Waneck 12 years ago
parent
commit
5c0179bb4d

+ 42 - 0
gencommon.ml

@@ -9469,6 +9469,48 @@ struct
 
 end;;
 
+(* ******************************************* *)
+(* AbstractImplementationFix *)
+(* ******************************************* *)
+
+(*
+
+  This module filter will map the compiler created classes from abstract
+  implementations to valid haxe code, as needed by gencommon
+
+  dependencies:
+    No dependencies
+
+*)
+
+module AbstractImplementationFix =
+struct
+
+  let name = "abstract_implementation_fix"
+
+  let priority = solve_deps name []
+
+  let default_implementation gen =
+    let rec run md =
+      match md with
+        | TClassDecl ({ cl_kind = KAbstractImpl a } as c) ->
+            List.iter (function
+              | cf when Meta.has Meta.Impl cf.cf_meta ->
+                  (* add type parameters to all implementation functions *)
+                  cf.cf_params <- cf.cf_params @ (List.filter (fun (s,_) -> not (List.exists (fun (s2,_) -> s = s2) cf.cf_params)) a.a_types)
+              | _ -> ()
+            ) c.cl_ordered_statics;
+            Some md
+        | _ -> Some md
+    in
+    run
+
+  let configure gen =
+    let map = default_implementation gen in
+    gen.gmodule_filters#add ~name:name ~priority:(PCustom priority) map
+
+end;;
+
 (*
 (* ******************************************* *)
 (* Example *)

+ 10 - 3
genjava.ml

@@ -749,6 +749,8 @@ let configure gen =
   let rec real_type t =
     let t = gen.gfollow#run_f t in
     match t with
+      | TAbstract ({ a_impl = Some _ } as a, pl) ->
+        real_type (Codegen.get_underlying_type a pl)
       | TInst( { cl_path = (["haxe"], "Int32") }, [] ) -> gen.gcon.basic.tint
       | TInst( { cl_path = (["haxe"], "Int64") }, [] ) -> ti64
       | TAbstract( { a_path = ([], "Class") }, p  )
@@ -1419,7 +1421,12 @@ let configure gen =
         print w "%s %s%s %s %s %s" (visibility) v_n (String.concat " " modifiers) params (if is_new then "" else rett_s cf.cf_pos (run_follow gen ret_type)) (change_field name);
 
         (* <T>(string arg1, object arg2) with T : object *)
-        print w "(%s)" (String.concat ", " (List.map (fun (name, _, t) -> sprintf "%s %s" (t_s cf.cf_pos (run_follow gen t)) (change_id name)) args));
+        (match cf.cf_expr with
+          | Some { eexpr = TFunction tf } ->
+              print w "(%s)" (String.concat ", " (List.map (fun (var,_) -> sprintf "%s %s" (t_s cf.cf_pos (run_follow gen var.v_type)) (change_id var.v_name)) tf.tf_args))
+          | _ ->
+              print w "(%s)" (String.concat ", " (List.map (fun (name, _, t) -> sprintf "%s %s" (t_s cf.cf_pos (run_follow gen t)) (change_id name)) args))
+        );
         if is_interface then
           write w ";"
         else begin
@@ -1658,6 +1665,8 @@ let configure gen =
 
   StubClosureImpl.configure gen (StubClosureImpl.default_implementation gen float_cl 10 (fun e _ _ -> e));*)
 
+  AbstractImplementationFix.configure gen;
+
   IteratorsInterface.configure gen (fun e -> e);
 
   ClosuresToClass.configure gen (ClosuresToClass.default_implementation closure_t (get_cl (get_type gen (["haxe";"lang"],"Function")) ));
@@ -2009,8 +2018,6 @@ let configure gen =
 
   TypeParams.RenameTypeParameters.run gen;
 
-  (*Codegen.dump_types gen.gcon;*)
-
   let t = Common.timer "code generation" in
 
 	generate_modules_t gen "java" "src" change_path module_gen;

+ 4 - 4
std/cs/Boot.hx

@@ -29,15 +29,15 @@ import cs.internal.Iterator;
 import cs.internal.Null;
 import cs.internal.StringExt;
 import cs.StdTypes;
-import Hash;
+import StringMap;
 import Reflect;
 
-class Boot 
+class Boot
 {
 
 	@:keep public static function init():Void
 	{
 		cs.Lib.applyCultureChanges();
 	}
-	
-}
+
+}

+ 2 - 2
std/cs/_std/haxe/Int64.hx

@@ -21,8 +21,8 @@
  */
 package haxe;
 using haxe.Int64;
-@:notNull @:runtimeValue private abstract NativeInt64 => Int, <= Int {}
-@:notNull @:runtimeValue private abstract NativeUInt64 => Int, <= Int {}
+@:coreType @:notNull @:runtimeValue private abstract NativeInt64 from Int to Int {}
+@:coreType @:notNull @:runtimeValue private abstract NativeUInt64 from Int to Int {}
 
 @:coreApi
 @:nativeGen class Int64

+ 3 - 3
std/cs/system/collections/IDictionary.hx

@@ -25,7 +25,7 @@ package cs.system.collections;
 {
 	var IsFixedSize(default, null):Bool;
 	var IsReadOnly(default, null):Bool;
-	
+
 	function Add(key:Dynamic, value:Dynamic):Void;
 	function Clear():Void;
 	function Contains(key:Dynamic):Bool;
@@ -33,8 +33,8 @@ package cs.system.collections;
 	function GetEnumerator():IDictionaryEnumerator;
 }
 
-@:native('System.Collections.IDictionaryEnumerator') extern interface IDictionaryEnumerator implements IEnumerator
+@:native('System.Collections.IDictionaryEnumerator') extern interface IDictionaryEnumerator extends IEnumerator
 {
 	var Key(default, null):Dynamic;
 	var Value(default, null):Dynamic;
-}
+}

+ 3 - 1
std/java/_std/Type.hx

@@ -66,6 +66,7 @@
 	}
 
 	public static function getClassName( c : Class<Dynamic> ) : String untyped {
+		var c : java.lang.Class<Dynamic> = c;
 		var name:String = c.getName();
 		if (name.startsWith("haxe.root."))
 			return name.substr(10);
@@ -82,7 +83,8 @@
 	}
 
 	public static function getEnumName( e : Enum<Dynamic> ) : String untyped {
-		var ret:String = e.getName();
+		var c : java.lang.Class<Dynamic> = e;
+		var ret:String = c.getName();
 		if (ret.startsWith("haxe.root."))
 			return ret.substr(10);
 		else if (ret == "boolean" || ret == "java.lang.Boolean")

+ 5 - 1
tests/unit/unitstd/Type.unit.hx

@@ -1,7 +1,11 @@
 // getClass
 Type.getClass("foo") == String;
 Type.getClass(new C()) == C;
+
+//Issue #1485
+#if !(java || cs)
 Type.getClass([]) == Array;
+#end
 Type.getClass(Float) == null;
 Type.getClass(null) == null;
 Type.getClass(Int) == null;
@@ -151,4 +155,4 @@ Type.enumIndex(MultipleArgs(1, "foo")) == 3;
 
 // allEnums
 Type.allEnums(E) == [NoArgs];
-Type.allEnums(haxe.macro.Expr.ExprDef) == [EBreak, EContinue];
+Type.allEnums(haxe.macro.Expr.ExprDef) == [EBreak, EContinue];

+ 3 - 1
tests/unit/unitstd/haxe/Http.unit.hx

@@ -1,3 +1,4 @@
+#if !(java || cs)
 var http1 = new haxe.Http("_");
 var r = "";
 http1.onStatus = function(_) r = "status";
@@ -14,4 +15,5 @@ r == "error";
 #end
 #if !flash
 exc(function() haxe.Http.requestUrl("_"));
-#end
+#end
+#end