浏览代码

[haxe/java] unit tests compliance update

Caue Waneck 13 年之前
父节点
当前提交
c3a7af07d5
共有 6 个文件被更改,包括 55 次插入3 次删除
  1. 48 0
      gencommon.ml
  2. 2 0
      gencs.ml
  3. 1 0
      std/cs/_std/Std.hx
  4. 1 1
      std/haxe/Resource.hx
  5. 1 0
      std/java/_std/Std.hx
  6. 2 2
      tests/unit/TestCSharp.hx

+ 48 - 0
gencommon.ml

@@ -9280,6 +9280,54 @@ struct
   
 end;;
 
+(* ******************************************* *)
+(* OverrideFix *)
+(* ******************************************* *)
+
+(*
+  
+  When DCE is on, sometimes a field is marked as override when it 
+  really doesn't override anything. This module filter will take care of this.
+  
+  dependencies:
+    No dependencies
+  
+*)
+
+module OverrideFix =
+struct
+
+  let name = "override_fix"
+  
+  let priority = solve_deps name []
+  
+  let default_implementation gen =
+    let rec run e =
+      match e.eexpr with 
+        | _ -> Type.map_expr run e
+    in
+    run
+  
+  let configure gen =
+    let map md =  
+      match md with
+        | TClassDecl cl ->
+          cl.cl_overrides <- List.filter (fun s ->
+            let rec loop cl =
+              match cl.cl_super with
+                | Some (cl,_) when PMap.mem s cl.cl_fields -> true
+                | Some (cl,_) -> loop cl
+                | None -> false
+            in
+            loop cl
+          ) cl.cl_overrides;
+          Some md
+        | _ -> Some md
+    in
+    gen.gmodule_filters#add ~name:name ~priority:(PCustom priority) map
+  
+end;;
+
 (*
 (* ******************************************* *)
 (* Example *)

+ 2 - 0
gencs.ml

@@ -1586,6 +1586,8 @@ let configure gen =
   );
   
   IteratorsInterface.configure gen (fun e -> e);
+
+  OverrideFix.configure gen;
   
   ClosuresToClass.configure gen (ClosuresToClass.default_implementation closure_t (get_cl (get_type gen (["haxe";"lang"],"Function")) ));
   

+ 1 - 0
std/cs/_std/Std.hx

@@ -238,6 +238,7 @@ import cs.internal.Exceptions;
 	}
 
 	public static function random( x : Int ) : Int {
+		if (x <= 0) return 0;
 		return untyped Math.rand.Next(x);
 	}
 

+ 1 - 1
std/haxe/Resource.hx

@@ -35,7 +35,7 @@ class Resource {
 	#if cs
 	static var paths : Hash<String>;
 	
-	private static function getPaths():Hash<String>
+	#if cs @:keep #end private static function getPaths():Hash<String>
 	{
 		if (paths != null)
 			return paths;

+ 1 - 0
std/java/_std/Std.hx

@@ -241,6 +241,7 @@ import java.internal.Exceptions;
 	}
 
 	public static function random( x : Int ) : Int {
+		if (x <= 0) return 0;
 		return Std.int(Math.random() * x);
 	}
 

+ 2 - 2
tests/unit/TestCSharp.hx

@@ -23,7 +23,7 @@ class TestCSharp extends Test
 		refTest(i);
 		eq(i, 20);
 		
-		var cl = new HxClass();
+		var cl:NativeClass = new HxClass();
 		cl.refTest(i);
 		eq(i, 80);
 	}
@@ -34,7 +34,7 @@ class TestCSharp extends Test
 		outTest(i, 10);
 		eq(i, 20);
 		
-		var cl = new HxClass();
+		var cl:NativeClass = new HxClass();
 		cl.outTest(i, 10);
 		eq(i, 40);
 	}