Browse Source

Wrapped copy constructors.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/203/head
Dimitar Dobrev 12 years ago
parent
commit
fee1809ca5
  1. 2
      src/Generator/AST/Utils.cs
  2. 15
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 14
      tests/Basic/Basic.Tests.cs
  4. 6
      tests/Basic/Basic.cpp
  5. 1
      tests/Basic/Basic.h
  6. 4
      tests/CSharpTemp/CSharpTemp.Tests.cs

2
src/Generator/AST/Utils.cs

@ -25,7 +25,7 @@ namespace CppSharp.AST @@ -25,7 +25,7 @@ namespace CppSharp.AST
if (@class != null && @class.IsValueType && isEmptyCtor)
return true;
if (method.IsCopyConstructor || method.IsMoveConstructor)
if (method.IsMoveConstructor)
return true;
if (method.IsDestructor)

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

@ -2159,8 +2159,19 @@ namespace CppSharp.Generators.CSharp @@ -2159,8 +2159,19 @@ namespace CppSharp.Generators.CSharp
WriteLine("{0} = Marshal.AllocHGlobal({1});", Helpers.InstanceIdentifier,
@class.Layout.Size);
if (!method.IsDefaultConstructor || @class.HasNonTrivialDefaultConstructor)
GenerateInternalFunctionCall(method);
if (method.IsCopyConstructor)
{
if (@class.HasNonTrivialCopyConstructor)
GenerateInternalFunctionCall(method);
else
WriteLine("*(({0}.Internal*) __Instance) = *(({0}.Internal*) {1}.__Instance);",
@class.Name, method.Parameters[0].Name);
}
else
{
if (!method.IsDefaultConstructor || @class.HasNonTrivialDefaultConstructor)
GenerateInternalFunctionCall(method);
}
GenerateVTableClassSetupCall(@class);
}

14
tests/Basic/Basic.Tests.cs

@ -193,5 +193,19 @@ public class BasicTests : GeneratorTestFixture @@ -193,5 +193,19 @@ public class BasicTests : GeneratorTestFixture
public void TestChar16()
{
}
[Test]
public void TestCopyConstructor()
{
Foo foo = new Foo { A = 5, B = 5.5f };
var copyFoo = new Foo(foo);
Assert.That(foo.A, Is.EqualTo(copyFoo.A));
Assert.That(foo.B, Is.EqualTo(copyFoo.B));
Bar bar = new Bar { A = 10, B = 5 };
var copyBar = new Bar(bar);
Assert.That(bar.A, Is.EqualTo(copyBar.A));
Assert.That(bar.B, Is.EqualTo(copyBar.B));
}
}

6
tests/Basic/Basic.cpp

@ -27,6 +27,12 @@ Bar::Bar() @@ -27,6 +27,12 @@ Bar::Bar()
{
}
Bar::Bar(const Bar& bar)
{
A = bar.A;
B = bar.B;
}
Bar::Item Bar::RetItem1()
{
return Bar::Item1;

1
tests/Basic/Basic.h

@ -28,6 +28,7 @@ struct DLL_API Bar @@ -28,6 +28,7 @@ struct DLL_API Bar
};
Bar();
Bar(const Bar& bar);
Item RetItem1();
int A;
float B;

4
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -34,7 +34,7 @@ public class CSharpTempTests : GeneratorTestFixture @@ -34,7 +34,7 @@ public class CSharpTempTests : GeneratorTestFixture
[Test]
public void TestFixedArrays()
{
Qux qux = new Qux(null);
Qux qux = new Qux((Foo) null);
var array = new[] { 1, 2, 3 };
qux.Array = array;
for (int i = 0; i < qux.Array.Length; i++)
@ -64,7 +64,7 @@ public class CSharpTempTests : GeneratorTestFixture @@ -64,7 +64,7 @@ public class CSharpTempTests : GeneratorTestFixture
Assert.That(proprietor.Value, Is.EqualTo(20));
proprietor.Prop = 50;
Assert.That(proprietor.Prop, Is.EqualTo(50));
var p = new P(null);
var p = new P((IQux) null);
p.Value = 20;
Assert.That(p.Value, Is.EqualTo(30));
p.Prop = 50;

Loading…
Cancel
Save