Browse Source

[cs] Support fields on Ref<> and Out<>

Cauê Waneck 11 years ago
parent
commit
c35f26956f
2 changed files with 20 additions and 2 deletions
  1. 10 2
      gencs.ml
  2. 10 0
      tests/unit/TestCSharp.hx

+ 10 - 2
gencs.ml

@@ -987,6 +987,14 @@ let configure gen =
       | _ -> gen.gcon.error ("This function argument " ^ explain ^ " must be a local variable.") e.epos; e
   in
 
+  let rec ensure_refout e explain =
+    match e.eexpr with
+      | TField _ | TLocal _ -> e
+      | TCast(e,_)
+      | TParenthesis e | TMeta(_,e) -> ensure_refout e explain
+      | _ -> gen.gcon.error ("This function argument " ^ explain ^ " must be a local variable.") e.epos; e
+  in
+
   let is_pointer t = match follow t with
     | TInst({ cl_path = (["cs"], "Pointer") }, _)
     | TAbstract ({ a_path = (["cs"], "Pointer") },_) ->
@@ -1463,12 +1471,12 @@ let configure gen =
             (match real_type t with
               | TType({ t_path = (["cs"], "Ref") }, _)
               | TAbstract ({ a_path = (["cs"], "Ref") },_) ->
-                let e = ensure_local e "of type cs.Ref" in
+                let e = ensure_refout e "of type cs.Ref" in
                 write w "ref ";
                 expr_s w e
               | TType({ t_path = (["cs"], "Out") }, _)
               | TAbstract ({ a_path = (["cs"], "Out") },_) ->
-                let e = ensure_local e "of type cs.Out" in
+                let e = ensure_refout e "of type cs.Out" in
                 write w "out ";
                 expr_s w e
               | _ ->

+ 10 - 0
tests/unit/TestCSharp.hx

@@ -174,6 +174,10 @@ class TestCSharp extends Test
 		var cl:NativeClass = new HxClass();
 		cl.refTest(i);
 		eq(i, 80);
+
+		cl.test = 100;
+		cl.refTest(cl.test);
+		eq(cl.test,400);
 	}
 
 	public function testOut()
@@ -185,6 +189,10 @@ class TestCSharp extends Test
 		var cl:NativeClass = new HxClass();
 		cl.outTest(i, 10);
 		eq(i, 40);
+
+		cl.test = 20;
+		cl.outTest(cl.test, 10);
+		eq(cl.test,40);
 	}
 
 	public function testChecked()
@@ -288,6 +296,7 @@ class TestCSharp extends Test
 
 @:nativeGen private class NativeClass
 {
+	public var test:Int;
 	public function outTest(out:cs.Out<Int>, x:Int):Void
 	{
 		out = x * 2;
@@ -304,6 +313,7 @@ typedef StringWithDescription = String;
 
 private class HxClass extends NativeClass
 {
+
 	public function new()
 	{