Browse Source

Merge pull request #267 from tomspilman/inout

Fixed Ref Printing
pull/208/head
João Matos 12 years ago
parent
commit
0406a10517
  1. 5
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  2. 7
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  3. 2
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  4. 20
      tests/Basic/Basic.Tests.cs
  5. 12
      tests/Basic/Basic.cpp
  6. 2
      tests/Basic/Basic.cs
  7. 3
      tests/Basic/Basic.h
  8. 3
      tests/Tests.h

5
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -1067,7 +1067,10 @@ namespace CppSharp.Generators.CLI
var typePrinter = new CppTypePrinter(Driver.TypeDatabase); var typePrinter = new CppTypePrinter(Driver.TypeDatabase);
var type = paramType.Visit(typePrinter); var type = paramType.Visit(typePrinter);
WriteLine("{0} {1};", type, argName); if (param.IsInOut)
WriteLine("{0} {1} = {2};", type, argName, param.Name);
else
WriteLine("{0} {1};", type, argName);
} }
else else
{ {

7
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -474,9 +474,12 @@ namespace CppSharp.Generators.CSharp
{ {
var typeName = Type.TypePrinterDelegate(pointee); var typeName = Type.TypePrinterDelegate(pointee);
Context.SupportBefore.WriteLine("{0} _{1};", typeName, param.Name); if (param.IsInOut)
Context.Return.Write("&_{0}", param.Name); Context.SupportBefore.WriteLine("{0} _{1} = {1};", typeName, param.Name);
else
Context.SupportBefore.WriteLine("{0} _{1};", typeName, param.Name);
Context.Return.Write("&_{0}", param.Name);
} }
else else
Context.Return.Write(Helpers.SafeIdentifier(Context.Parameter.Name)); Context.Return.Write(Helpers.SafeIdentifier(Context.Parameter.Name));

2
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -2503,7 +2503,7 @@ namespace CppSharp.Generators.CSharp
case ParameterUsage.Out: case ParameterUsage.Out:
return "out "; return "out ";
case ParameterUsage.InOut: case ParameterUsage.InOut:
return "ref"; return "ref ";
default: default:
return string.Empty; return string.Empty;
} }

20
tests/Basic/Basic.Tests.cs

@ -77,6 +77,26 @@ public class BasicTests : GeneratorTestFixture
Assert.That(f, Is.EqualTo(10.0f)); Assert.That(f, Is.EqualTo(10.0f));
} }
[Test]
public void TestPrimitiveInOutParameters()
{
var hello = new Hello();
int i = 10;
Assert.That(hello.TestPrimitiveInOut(ref i), Is.True);
Assert.That(i, Is.EqualTo(20));
}
[Test]
public void TestPrimitiveInOutRefParameters()
{
var hello = new Hello();
int i = 10;
Assert.That(hello.TestPrimitiveInOutRef(ref i), Is.True);
Assert.That(i, Is.EqualTo(20));
}
[Test] [Test]
public void TestNullRef() public void TestNullRef()
{ {

12
tests/Basic/Basic.cpp

@ -169,6 +169,18 @@ bool Hello::TestPrimitiveOutRef(CS_OUT float& f)
return true; return true;
} }
bool Hello::TestPrimitiveInOut(CS_IN_OUT int* i)
{
*i += 10;
return true;
}
bool Hello::TestPrimitiveInOutRef(CS_IN_OUT int& i)
{
i += 10;
return true;
}
int unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int)) int unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int))
{ {
return ret.A; return ret.A;

2
tests/Basic/Basic.cs

@ -31,6 +31,8 @@ namespace CppSharp.Tests
ctx.SetClassAsValueType("Bar2"); ctx.SetClassAsValueType("Bar2");
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOut", 1, ParameterUsage.Out); ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOut", 1, ParameterUsage.Out);
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOutRef", 1, ParameterUsage.Out); ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOutRef", 1, ParameterUsage.Out);
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveInOut", 1, ParameterUsage.InOut);
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveInOutRef", 1, ParameterUsage.InOut);
} }
public static void Main(string[] args) public static void Main(string[] args)

3
tests/Basic/Basic.h

@ -123,6 +123,9 @@ public:
bool TestPrimitiveOut(CS_OUT float* f); bool TestPrimitiveOut(CS_OUT float* f);
bool TestPrimitiveOutRef(CS_OUT float& f); bool TestPrimitiveOutRef(CS_OUT float& f);
bool TestPrimitiveInOut(CS_IN_OUT int* i);
bool TestPrimitiveInOutRef(CS_IN_OUT int& i);
}; };
class DLL_API AbstractFoo class DLL_API AbstractFoo

3
tests/Tests.h

@ -22,4 +22,5 @@
#endif #endif
#endif #endif
#define CS_OUT #define CS_OUT
#define CS_IN_OUT
Loading…
Cancel
Save