Browse Source

Merge pull request #268 from tomspilman/outenum

Fixed Out And InOut Enum Parameters
pull/208/head
João Matos 12 years ago
parent
commit
3d39b62589
  1. 9
      src/Generator/Generators/CLI/CLITypePrinter.cs
  2. 4
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  3. 8
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  4. 21
      tests/Basic/Basic.Tests.cs
  5. 10
      tests/Basic/Basic.cpp
  6. 2
      tests/Basic/Basic.cs
  7. 3
      tests/Basic/Basic.h

9
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -107,6 +107,8 @@ namespace CppSharp.Generators.CLI @@ -107,6 +107,8 @@ namespace CppSharp.Generators.CLI
var str = string.Empty;
if(param.Usage == ParameterUsage.Out)
str += "[System::Runtime::InteropServices::Out] ";
else if (param.Usage == ParameterUsage.InOut)
str += "[System::Runtime::InteropServices::In, System::Runtime::InteropServices::Out] ";
str += type;
@ -164,6 +166,13 @@ namespace CppSharp.Generators.CLI @@ -164,6 +166,13 @@ namespace CppSharp.Generators.CLI
if (pointee.TryGetEnum(out @enum))
{
var typeName = @enum.Visit(this);
// Skip one indirection if passed by reference
var param = Context.Parameter;
if (param != null && (param.IsOut || param.IsInOut)
&& pointee == finalPointee)
return string.Format("{0}", typeName);
return string.Format("{0}*", typeName);
}

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

@ -149,7 +149,7 @@ namespace CppSharp.Generators.CSharp @@ -149,7 +149,7 @@ namespace CppSharp.Generators.CSharp
}
PrimitiveType primitive;
if (pointee.IsPrimitiveType(out primitive))
if (pointee.IsPrimitiveType(out primitive) || pointee.IsEnumType())
{
var param = Context.Parameter;
if (param != null && (param.IsOut || param.IsInOut))
@ -462,7 +462,7 @@ namespace CppSharp.Generators.CSharp @@ -462,7 +462,7 @@ namespace CppSharp.Generators.CSharp
}
PrimitiveType primitive;
if (pointee.IsPrimitiveType(out primitive))
if (pointee.IsPrimitiveType(out primitive) || pointee.IsEnumType())
{
var param = Context.Parameter;

8
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -232,7 +232,13 @@ namespace CppSharp.Generators.CSharp @@ -232,7 +232,13 @@ namespace CppSharp.Generators.CSharp
Enumeration @enum;
if (desugared.TryGetEnum(out @enum))
{
return @enum.Name + "*";
// Skip one indirection if passed by reference
var param = Context.Parameter;
if (isManagedContext && param != null && (param.IsOut || param.IsInOut)
&& pointee == finalPointee)
return pointee.Visit(this, quals);
return pointee.Visit(this, quals) + "*";
}
Class @class;

21
tests/Basic/Basic.Tests.cs

@ -77,7 +77,6 @@ public class BasicTests : GeneratorTestFixture @@ -77,7 +77,6 @@ public class BasicTests : GeneratorTestFixture
Assert.That(f, Is.EqualTo(10.0f));
}
[Test]
public void TestPrimitiveInOutParameters()
{
var hello = new Hello();
@ -97,6 +96,26 @@ public class BasicTests : GeneratorTestFixture @@ -97,6 +96,26 @@ public class BasicTests : GeneratorTestFixture
Assert.That(i, Is.EqualTo(20));
}
[Test]
public void TestEnumOut()
{
var hello = new Hello();
Enum e;
hello.EnumOut((int)Enum.C, out e);
Assert.That(e, Is.EqualTo(Enum.C));
}
[Test]
public void TestEnumOutRef()
{
var hello = new Hello();
Enum e;
hello.EnumOutRef((int)Enum.C, out e);
Assert.That(e, Is.EqualTo(Enum.C));
}
[Test]
public void TestNullRef()
{

10
tests/Basic/Basic.cpp

@ -181,6 +181,16 @@ bool Hello::TestPrimitiveInOutRef(CS_IN_OUT int& i) @@ -181,6 +181,16 @@ bool Hello::TestPrimitiveInOutRef(CS_IN_OUT int& i)
return true;
}
void Hello::EnumOut(int value, CS_OUT Enum* e)
{
*e = (Enum)value;
}
void Hello::EnumOutRef(int value, CS_OUT Enum& e)
{
e = (Enum)value;
}
int unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int))
{
return ret.A;

2
tests/Basic/Basic.cs

@ -33,6 +33,8 @@ namespace CppSharp.Tests @@ -33,6 +33,8 @@ namespace CppSharp.Tests
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);
}
public static void Main(string[] args)

3
tests/Basic/Basic.h

@ -126,6 +126,9 @@ public: @@ -126,6 +126,9 @@ public:
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);
};
class DLL_API AbstractFoo

Loading…
Cancel
Save