Permalink
Browse files

Fixed the generated C# for increment and decrement operators.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Aug 11, 2017
1 parent 910304b commit e0816d9dc62e955c3f8676a83720a7c1574404c4
@@ -51,7 +51,7 @@ public static Method GetBaseMethod(this Class @class, Method @override)
if (baseMethod != null)
return baseMethod;
return baseClass.Methods.FirstOrDefault(m => @override.CanOverride(m));
return baseClass.Methods.FirstOrDefault(@override.CanOverride);
}
public static Property GetBaseProperty(this Class @class, Property @override,
@@ -222,7 +222,13 @@ static bool IsValidOperatorOverload(Method @operator)
// Only prefix operators can be overloaded
case CXXOperatorKind.PlusPlus:
case CXXOperatorKind.MinusMinus:
return @operator.Parameters.Count == 0;
Class @class;
var returnType = @operator.OriginalReturnType.Type.Desugar();
returnType = (returnType.GetFinalPointee() ?? returnType).Desugar();
return returnType.TryGetClass(out @class) &&
@class.GetNonIgnoredRootBase() ==
((Class) @operator.Namespace).GetNonIgnoredRootBase() &&
@operator.Parameters.Count == 0;
// Bitwise shift operators can only be overloaded if the second parameter is int
case CXXOperatorKind.LessLess:
@@ -1023,6 +1023,16 @@ public void TestFuncWithTypedefedFuncPtrAsParam()
Assert.That(CSharp.CSharp.FuncWithTypedefedFuncPtrAsParam(function), Is.EqualTo(5));
}
[Test]
public void TestIncrement()
{
var bar = new Bar();
bar.Index = 5;
bar++;
Assert.That(bar.Index, Is.EqualTo(6));
bar.Dispose();
}
private class OverrideVirtualTemplate : VirtualTemplate<int>
{
public override int Function
@@ -75,6 +75,16 @@ int Foo::getGetPropertyCall()
return 1;
}
int Foo::operator ++()
{
return 5;
}
int Foo::operator --()
{
return 4;
}
const Foo& Bar::operator[](int i) const
{
return m_foo;
@@ -194,10 +204,20 @@ const Bar& Bar::operator ++()
Bar Bar::operator ++(int i)
{
Bar bar = *this;
index++;
bar.index++;
return bar;
}
int Bar::getIndex()
{
return index;
}
void Bar::setIndex(int value)
{
index = value;
}
ForceCreationOfInterface::ForceCreationOfInterface()
{
}
@@ -29,6 +29,9 @@ class DLL_API Foo
static int propertyCall();
static int getGetPropertyCall();
int operator ++();
int operator --();
protected:
int P;
TemplateInAnotherUnit<int> templateInAnotherUnit;
@@ -82,13 +85,15 @@ class DLL_API Bar : public Qux
Bar operator++(int i);
void* arrayOfPrimitivePointers[1];
Foo foos[4];
int getIndex();
void setIndex(int value);
private:
int index;
Foo m_foo;
};
Bar::Bar() {}
Bar::Bar() : index(0) {}
class DLL_API ForceCreationOfInterface : public Foo, public Bar
{

0 comments on commit e0816d9

Please sign in to comment.