Browse Source

Added conversion operators for ctors with default params.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/547/head
Dimitar Dobrev 10 years ago
parent
commit
4e37adf4b7
  1. 21
      src/Generator/Passes/ConstructorToConversionOperatorPass.cs
  2. 9
      tests/CSharpTemp/CSharpTemp.Tests.cs
  3. 6
      tests/CSharpTemp/CSharpTemp.cpp
  4. 3
      tests/CSharpTemp/CSharpTemp.h

21
src/Generator/Passes/ConstructorToConversionOperatorPass.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using CppSharp.AST;
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
namespace CppSharp.Passes
@ -12,9 +13,25 @@ namespace CppSharp.Passes @@ -12,9 +13,25 @@ namespace CppSharp.Passes
public override bool VisitMethodDecl(Method method)
{
if (AlreadyVisited(method) || !method.IsGenerated || !method.IsConstructor ||
method.IsCopyConstructor || method.Parameters.Count != 1)
method.IsCopyConstructor)
return false;
var @params = method.Parameters.Where(p => p.Kind == ParameterKind.Regular).ToList();
if (@params.Count == 0)
return false;
if (Driver.Options.GenerateDefaultValuesForArguments)
{
var nonDefaultParams = @params.Count(p => p.DefaultArgument == null);
if (nonDefaultParams > 1)
return false;
}
else
{
if (@params.Count != 1)
return false;
}
var parameter = method.Parameters[0];
// TODO: disable implicit operators for C++/CLI because they seem not to be support parameters
if (!Driver.Options.IsCSharpGenerator)

9
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -433,4 +433,13 @@ public class CSharpTempTests : GeneratorTestFixture @@ -433,4 +433,13 @@ public class CSharpTempTests : GeneratorTestFixture
ITestParamToInterfacePassBaseTwo interfaceTypePtr;
obj.FuncTryInterfaceTypePtrOut(out interfaceTypePtr);
}
[Test]
public void TestConversionForCtorWithDefaultParams()
{
using (Foo foo = 15)
{
Assert.That(foo.A, Is.EqualTo(15));
}
}
}

6
tests/CSharpTemp/CSharpTemp.cpp

@ -6,6 +6,12 @@ Foo::Foo() @@ -6,6 +6,12 @@ Foo::Foo()
P = 50;
}
Foo::Foo(int a, int p)
{
A = a;
P = p;
}
int Foo::method()
{
return 1;

3
tests/CSharpTemp/CSharpTemp.h

@ -5,6 +5,7 @@ class DLL_API Foo @@ -5,6 +5,7 @@ class DLL_API Foo
{
public:
Foo();
Foo(int a, int p = 0);
int method();
int operator[](int i) const;
int operator[](unsigned int i);
@ -706,4 +707,4 @@ class DLL_API TestOutTypeInterfaces @@ -706,4 +707,4 @@ class DLL_API TestOutTypeInterfaces
public:
void funcTryInterfaceTypePtrOut(CS_OUT TestParamToInterfacePassBaseTwo* classTry);
void funcTryInterfaceTypeOut(CS_OUT TestParamToInterfacePassBaseTwo classTry);
};
};

Loading…
Cancel
Save