Browse Source

Added param to interface pass for Operator functions and a test.

pull/495/head
Abhinav Tripathi 10 years ago
parent
commit
33cb87ad65
  1. 17
      src/Generator/Passes/ParamTypeToInterfacePass.cs
  2. 16
      tests/CSharpTemp/CSharpTemp.Tests.cs
  3. 46
      tests/CSharpTemp/CSharpTemp.cpp
  4. 24
      tests/CSharpTemp/CSharpTemp.h

17
src/Generator/Passes/ParamTypeToInterfacePass.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
@ -7,20 +8,22 @@ namespace CppSharp.Passes @@ -7,20 +8,22 @@ namespace CppSharp.Passes
{
public override bool VisitFunctionDecl(Function function)
{
if (!function.IsOperator)
if (!function.IsOperator || function.Parameters.Count > 1)
ChangeToInterfaceType(function.OriginalReturnType);
if (function.OperatorKind != CXXOperatorKind.Conversion &&
function.OperatorKind != CXXOperatorKind.ExplicitConversion)
{
ChangeToInterfaceType(function.ReturnType);
foreach (Parameter parameter in function.Parameters)
{
foreach (var parameter in function.Parameters.Where(p => p.Kind != ParameterKind.OperatorParameter))
ChangeToInterfaceType(parameter.QualifiedType);
}
}
return base.VisitFunctionDecl(function);
}
private static void ChangeToInterfaceType(QualifiedType type)
{
var tagType = type.Type.GetFinalPointee() as TagType;
var tagType = (type.Type.GetFinalPointee() ?? type.Type) as TagType;
if (tagType != null)
{
var @class = tagType.Declaration as Class;

16
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -261,4 +261,20 @@ public class CSharpTempTests : GeneratorTestFixture @@ -261,4 +261,20 @@ public class CSharpTempTests : GeneratorTestFixture
}
}
}
[Test]
public void TestParamTypeToInterfacePass()
{
var baseClass = new TestParamToInterfacePassBaseTwo();
baseClass++;
Assert.AreEqual(baseClass.M, 1);
ITestParamToInterfacePassBaseTwo baseInterface = new TestParamToInterfacePassBaseTwo();
var dervClass = new TestParamToInterfacePass();
dervClass.AddM(baseClass);
Assert.AreEqual(dervClass.M, 1);
dervClass = new TestParamToInterfacePass(dervClass + baseClass);
Assert.AreEqual(dervClass.M, 2);
dervClass = new TestParamToInterfacePass(dervClass + baseInterface);
Assert.AreEqual(dervClass.M, 2);
}
}

46
tests/CSharpTemp/CSharpTemp.cpp

@ -507,3 +507,49 @@ void TestOverrideFromSecondaryBase::VirtualMember() @@ -507,3 +507,49 @@ void TestOverrideFromSecondaryBase::VirtualMember()
void TestOverrideFromSecondaryBase::setProperty(int value)
{
}
int TestParamToInterfacePassBaseTwo::getM()
{
return m;
}
void TestParamToInterfacePassBaseTwo::setM(int n)
{
m = n;
}
const TestParamToInterfacePassBaseTwo& TestParamToInterfacePassBaseTwo::operator++()
{
++m;
return *this;
}
TestParamToInterfacePassBaseTwo::TestParamToInterfacePassBaseTwo()
{
m = 0;
}
TestParamToInterfacePassBaseTwo::TestParamToInterfacePassBaseTwo(int n)
{
m = n;
}
TestParamToInterfacePassBaseTwo TestParamToInterfacePass::addM(TestParamToInterfacePassBaseTwo b)
{
this->setM(this->getM() + b.getM());
return *this;
}
TestParamToInterfacePassBaseTwo TestParamToInterfacePass::operator+(TestParamToInterfacePassBaseTwo b)
{
return TestParamToInterfacePassBaseTwo(this->getM() + b.getM());
}
TestParamToInterfacePass::TestParamToInterfacePass(TestParamToInterfacePassBaseTwo b)
{
this->setM(b.getM());
}
TestParamToInterfacePass::TestParamToInterfacePass() : TestParamToInterfacePassBaseOne(), TestParamToInterfacePassBaseTwo()
{
}

24
tests/CSharpTemp/CSharpTemp.h

@ -509,3 +509,27 @@ public: @@ -509,3 +509,27 @@ public:
void VirtualMember();
void setProperty(int value);
};
class DLL_API TestParamToInterfacePassBaseOne
{
};
class DLL_API TestParamToInterfacePassBaseTwo
{
int m;
public:
int getM();
void setM(int n);
const TestParamToInterfacePassBaseTwo& operator++();
TestParamToInterfacePassBaseTwo();
TestParamToInterfacePassBaseTwo(int n);
};
class DLL_API TestParamToInterfacePass : public TestParamToInterfacePassBaseOne, public TestParamToInterfacePassBaseTwo
{
public:
TestParamToInterfacePassBaseTwo addM(TestParamToInterfacePassBaseTwo b);
TestParamToInterfacePassBaseTwo operator+(TestParamToInterfacePassBaseTwo b);
TestParamToInterfacePass(TestParamToInterfacePassBaseTwo b);
TestParamToInterfacePass();
};

Loading…
Cancel
Save