Browse Source

Merge branch 'master' into outenum

pull/268/head
Tom Spilman 11 years ago
parent
commit
2912d6601b
  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. 19
      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 @@ -1067,7 +1067,10 @@ namespace CppSharp.Generators.CLI
var typePrinter = new CppTypePrinter(Driver.TypeDatabase);
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
{

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

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

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

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

19
tests/Basic/Basic.Tests.cs

@ -77,6 +77,25 @@ public class BasicTests : GeneratorTestFixture @@ -77,6 +77,25 @@ public class BasicTests : GeneratorTestFixture
Assert.That(f, Is.EqualTo(10.0f));
}
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]
public void TestEnumOut()
{

12
tests/Basic/Basic.cpp

@ -169,6 +169,18 @@ bool Hello::TestPrimitiveOutRef(CS_OUT float& f) @@ -169,6 +169,18 @@ bool Hello::TestPrimitiveOutRef(CS_OUT float& f)
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;
}
void Hello::EnumOut(int value, CS_OUT Enum* e)
{
*e = (Enum)value;

2
tests/Basic/Basic.cs

@ -31,6 +31,8 @@ namespace CppSharp.Tests @@ -31,6 +31,8 @@ namespace CppSharp.Tests
ctx.SetClassAsValueType("Bar2");
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOut", 1, ParameterUsage.Out);
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOutRef", 1, ParameterUsage.Out);
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveInOut", 1, ParameterUsage.InOut);
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveInOutRef", 1, ParameterUsage.InOut);
ctx.SetMethodParameterUsage("Hello", "EnumOut", 2, ParameterUsage.Out);
ctx.SetMethodParameterUsage("Hello", "EnumOutRef", 2, ParameterUsage.Out);
}

3
tests/Basic/Basic.h

@ -124,6 +124,9 @@ public: @@ -124,6 +124,9 @@ public:
bool TestPrimitiveOut(CS_OUT float* f);
bool TestPrimitiveOutRef(CS_OUT float& f);
bool TestPrimitiveInOut(CS_IN_OUT int* i);
bool TestPrimitiveInOutRef(CS_IN_OUT int& i);
void EnumOut(int value, CS_OUT Enum* e);
void EnumOutRef(int value, CS_OUT Enum& e);
};

3
tests/Tests.h

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