Browse Source

[cs] inner classes support

Cauê Waneck 11 years ago
parent
commit
eb84d6603d
3 changed files with 87 additions and 41 deletions
  1. 5 4
      gencs.ml
  2. 78 33
      tests/unit/TestCSharp.hx
  3. 4 4
      tests/unit/native_cs/src/haxe/test/Base.cs

+ 5 - 4
gencs.ml

@@ -632,7 +632,7 @@ let configure gen =
   let change_id name = try
   let change_id name = try
 			Hashtbl.find reserved name
 			Hashtbl.find reserved name
 		with | Not_found ->
 		with | Not_found ->
-      name
+      String.concat "." (String.nsplit name "#")
 	in
 	in
 
 
   let change_ns md = if no_root then
   let change_ns md = if no_root then
@@ -2585,16 +2585,17 @@ let add_cs = function
 	| "haxe" :: ns -> "haxe" :: ns
 	| "haxe" :: ns -> "haxe" :: ns
 	| "std" :: ns -> "std" :: ns
 	| "std" :: ns -> "std" :: ns
 	| "cs" :: ns -> "cs" :: ns
 	| "cs" :: ns -> "cs" :: ns
-	| ns -> "cs" :: ns
+  | "system" :: ns -> "cs" :: "system" :: ns
+	| ns -> ns
 
 
 let netpath_to_hx std = function
 let netpath_to_hx std = function
 	| [],[], cl -> [], cl
 	| [],[], cl -> [], cl
 	| ns,[], cl ->
 	| ns,[], cl ->
 		let ns = (List.map String.lowercase ns) in
 		let ns = (List.map String.lowercase ns) in
-		(if std then add_cs ns else ns), cl
+		add_cs ns, cl
 	| ns,(nhd :: ntl as nested), cl ->
 	| ns,(nhd :: ntl as nested), cl ->
 		let ns = (List.map String.lowercase ns) @ [nhd] in
 		let ns = (List.map String.lowercase ns) @ [nhd] in
-		(if std then add_cs ns else ns), String.concat "_" nested ^ "_" ^ cl
+		add_cs ns, String.concat "_" nested ^ "_" ^ cl
 
 
 let lookup_ilclass std com ilpath =
 let lookup_ilclass std com ilpath =
   let path = netpath_to_hx std ilpath in
   let path = netpath_to_hx std ilpath in

+ 78 - 33
tests/unit/TestCSharp.hx

@@ -1,9 +1,54 @@
 package unit;
 package unit;
+import haxe.io.Bytes;
+import haxe.test.Base;
+import haxe.test.Base.Base_InnerClass;
+import haxe.test.TEnum;
 
 
 //C#-specific tests, like unsafe code
 //C#-specific tests, like unsafe code
 class TestCSharp extends Test
 class TestCSharp extends Test
 {
 {
-	#if cs
+#if cs
+
+	// -net-lib tests
+	function testHaxeKeywords()
+	{
+		eq(Base._inline, 42);
+		eq(Base._callback, 43);
+		eq(Base._cast, 44);
+		eq(Base._untyped, 45);
+		Base._untyped = 40;
+		eq(Base._untyped, 40);
+	}
+
+	function testTypes()
+	{
+		eq(Base.charTest(cast 10), cast 10);
+		eq(Base.byteTest(cast 10), cast 10);
+	}
+
+	function testInnerClass()
+	{
+		//-java-lib should be able to detect inner classes on import
+		var i = new Base_InnerClass();
+		eq(10,i.nameClash());
+
+		var i2 = new Base_InnerClass_InnerInnerClass();
+		t(true);
+	}
+
+	function testGenerics()
+	{
+		var jcl:cs.system.Type = cast Base_InnerClass_InnerInnerClass;
+		t(haxe.test.GenericHelper.staticTypedGeneric(jcl) != null);
+
+		var helper = new haxe.test.GenericHelper();
+
+		var val = new Base_InnerClass();
+		var g1 = new haxe.test.Generic1(val);
+		g1.complexTypeParameterOfTypeParameter(new Base_InnerClass_InnerInnerClass());
+		//if no compile-time error, we're fine!
+		t(true);
+	}
 
 
 	@:skipReflection private function refTest(i:cs.Ref<Int>):Void
 	@:skipReflection private function refTest(i:cs.Ref<Int>):Void
 	{
 	{
@@ -15,20 +60,20 @@ class TestCSharp extends Test
 		out = x * 2;
 		out = x * 2;
 	}
 	}
 
 
-    // test for https://github.com/HaxeFoundation/haxe/issues/2528
-    public function testDynObjectSetField()
-    {
-        var a:Dynamic = {};
-        a.status = 10;
-        var b:{status:Int} = a;
-        b.status = 15;
-
-        eq(a, b);
-        eq(Reflect.fields(a).length, 1);
-        eq(Reflect.fields(b).length, 1);
-        eq(a.status, 15);
-        eq(b.status, 15);
-    }
+	// test for https://github.com/HaxeFoundation/haxe/issues/2528
+	public function testDynObjectSetField()
+	{
+		var a:Dynamic = {};
+		a.status = 10;
+		var b:{status:Int} = a;
+		b.status = 15;
+
+		eq(a, b);
+		eq(Reflect.fields(a).length, 1);
+		eq(Reflect.fields(b).length, 1);
+		eq(a.status, 15);
+		eq(b.status, 15);
+	}
 
 
 	public function testRef()
 	public function testRef()
 	{
 	{
@@ -55,18 +100,18 @@ class TestCSharp extends Test
 	public function testChecked()
 	public function testChecked()
 	{
 	{
 		exc(function()
 		exc(function()
-		{
-			cs.Lib.checked({
-				var x = 1000;
-				while(true)
 				{
 				{
-					x *= x;
-				}
-			});
-		});
+					cs.Lib.checked({
+						var x = 1000;
+						while(true)
+					{
+						x *= x;
+					}
+					});
+				});
 	}
 	}
 
 
-	#if unsafe
+#if unsafe
 
 
 	@:unsafe public function testUnsafe()
 	@:unsafe public function testUnsafe()
 	{
 	{
@@ -74,18 +119,18 @@ class TestCSharp extends Test
 		cs.Lib.fixed({
 		cs.Lib.fixed({
 			var p = cs.Lib.pointerOfArray(x);
 			var p = cs.Lib.pointerOfArray(x);
 			for (i in 0...10)
 			for (i in 0...10)
-			{
-				p[0] = i;
-				p = p.add(1);
-			}
+		{
+			p[0] = i;
+			p = p.add(1);
+		}
 		});
 		});
 
 
 		cs.Lib.fixed( {
 		cs.Lib.fixed( {
 			var p = cs.Lib.pointerOfArray(x);
 			var p = cs.Lib.pointerOfArray(x);
 			for (i in 0...10)
 			for (i in 0...10)
-			{
-				eq(p[i], i);
-			}
+		{
+			eq(p[i], i);
+		}
 		});
 		});
 
 
 		var x:Int = 0;
 		var x:Int = 0;
@@ -100,7 +145,7 @@ class TestCSharp extends Test
 
 
 	}
 	}
 
 
-	#end
+#end
 
 
 	// test these because C# generator got a special filter for these expressions
 	// test these because C# generator got a special filter for these expressions
 	public function testNullConstEq()
 	public function testNullConstEq()
@@ -112,7 +157,7 @@ class TestCSharp extends Test
 		t(null != a);
 		t(null != a);
 	}
 	}
 
 
-	#end
+#end
 }
 }
 
 
 @:nativeGen private class NativeClass
 @:nativeGen private class NativeClass

+ 4 - 4
tests/unit/native_cs/src/haxe/test/Base.cs

@@ -5,10 +5,10 @@ public class Base
 {
 {
 	//some haxe-specific keywords
 	//some haxe-specific keywords
 
 
-	const int inline = 42;
+	public static readonly int inline = 42;
 	public static readonly int callback = 43;
 	public static readonly int callback = 43;
 	public static readonly int cast = 44;
 	public static readonly int cast = 44;
-	public static readonly int untyped = 45;
+	public static int untyped = 45;
 
 
 	//final + static variable = inline var in Haxe
 	//final + static variable = inline var in Haxe
 	const int inlineNumber = 42;
 	const int inlineNumber = 42;
@@ -26,7 +26,7 @@ public class Base
 		return -1;
 		return -1;
 	}
 	}
 
 
-	public int nameClash()
+	public virtual int nameClash()
 	{
 	{
 		return 1;
 		return 1;
 	}
 	}
@@ -66,7 +66,7 @@ public class Base
 			return privateField;
 			return privateField;
 		}
 		}
 
 
-		public int nameClash()
+		public override int nameClash()
 		{
 		{
 			return 10;
 			return 10;
 		}
 		}