Browse Source

Fixed the generated C# for const/non-const overloads with > 1 param.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1170/head
Dimitar Dobrev 6 years ago
parent
commit
b966bd6798
  1. 80
      src/Generator/Passes/CheckAmbiguousFunctions.cs
  2. 1
      tests/Common/Common.Tests.cs
  3. 8
      tests/Common/Common.cpp
  4. 2
      tests/Common/Common.h

80
src/Generator/Passes/CheckAmbiguousFunctions.cs

@ -54,7 +54,7 @@ namespace CppSharp.Passes @@ -54,7 +54,7 @@ namespace CppSharp.Passes
if (CheckConstnessForAmbiguity(function, overload) ||
CheckDefaultParametersForAmbiguity(function, overload) ||
CheckSingleParameterPointerConstnessForAmbiguity(function, overload))
CheckParametersPointerConstnessForAmbiguity(function, overload))
{
function.IsAmbiguous = true;
overload.IsAmbiguous = true;
@ -186,67 +186,57 @@ namespace CppSharp.Passes @@ -186,67 +186,57 @@ namespace CppSharp.Passes
return false;
}
private static bool CheckSingleParameterPointerConstnessForAmbiguity(
private static bool CheckParametersPointerConstnessForAmbiguity(
Function function, Function overload)
{
var functionParams = function.Parameters.Where(
p => p.Kind == ParameterKind.Regular).ToList();
// It's difficult to handle this case for more than one parameter.
// For example, if we have:
//
// void f(float&, const int&);
// void f(const float&, int&);
//
// What should we do? Generate both? Generate the first one encountered?
// Generate the one with the least amount of "complex" parameters?
// So let's just start with the simplest case for the time being.
if (functionParams.Count != 1)
return false;
var overloadParams = overload.Parameters.Where(
p => p.Kind == ParameterKind.Regular).ToList();
if (overloadParams.Count != 1)
if (functionParams.Count != overloadParams.Count)
return false;
var parameterFunction = functionParams[0];
var parameterOverload = overloadParams[0];
for (int i = 0; i < functionParams.Count; i++)
{
var parameterFunction = functionParams[i];
var parameterOverload = overloadParams[i];
var pointerParamFunction = parameterFunction.Type.Desugar() as PointerType;
var pointerParamOverload = parameterOverload.Type.Desugar() as PointerType;
var pointerParamFunction = parameterFunction.Type.Desugar() as PointerType;
var pointerParamOverload = parameterOverload.Type.Desugar() as PointerType;
if (pointerParamFunction == null || pointerParamOverload == null)
return false;
if (pointerParamFunction == null || pointerParamOverload == null)
continue;
if (!pointerParamFunction.GetPointee().Equals(pointerParamOverload.GetPointee()))
return false;
if (!pointerParamFunction.GetPointee().Equals(pointerParamOverload.GetPointee()))
continue;
if (parameterFunction.IsConst && !parameterOverload.IsConst)
{
function.ExplicitlyIgnore();
return true;
}
if (parameterFunction.IsConst && !parameterOverload.IsConst)
{
function.ExplicitlyIgnore();
return true;
}
if (parameterOverload.IsConst && !parameterFunction.IsConst)
{
overload.ExplicitlyIgnore();
return true;
}
if (parameterOverload.IsConst && !parameterFunction.IsConst)
{
overload.ExplicitlyIgnore();
return true;
}
if (pointerParamFunction.Modifier == PointerType.TypeModifier.RVReference &&
pointerParamOverload.Modifier != PointerType.TypeModifier.RVReference)
{
function.ExplicitlyIgnore();
return true;
}
if (pointerParamFunction.Modifier == PointerType.TypeModifier.RVReference &&
pointerParamOverload.Modifier != PointerType.TypeModifier.RVReference)
{
function.ExplicitlyIgnore();
return true;
}
if (pointerParamFunction.Modifier != PointerType.TypeModifier.RVReference &&
pointerParamOverload.Modifier == PointerType.TypeModifier.RVReference)
{
overload.ExplicitlyIgnore();
return true;
if (pointerParamFunction.Modifier != PointerType.TypeModifier.RVReference &&
pointerParamOverload.Modifier == PointerType.TypeModifier.RVReference)
{
overload.ExplicitlyIgnore();
return true;
}
}
return false;

1
tests/Common/Common.Tests.cs

@ -59,6 +59,7 @@ public class CommonTests : GeneratorTestFixture @@ -59,6 +59,7 @@ public class CommonTests : GeneratorTestFixture
Common.IntegerOverload(0);
Common.IntegerOverload((uint) 0);
Common.TakeVoidStarStar(null);
Common.OverloadPointer(IntPtr.Zero, 1);
using (new DerivedFromSecondaryBaseWithIgnoredVirtualMethod()) { }
#pragma warning restore 0168

8
tests/Common/Common.cpp

@ -1014,3 +1014,11 @@ void takeReferenceToVoidStar(const void*& p) @@ -1014,3 +1014,11 @@ void takeReferenceToVoidStar(const void*& p)
void takeVoidStarStar(void** p)
{
}
void overloadPointer(void* p, int i)
{
}
void overloadPointer(const void* p, int i)
{
}

2
tests/Common/Common.h

@ -1482,3 +1482,5 @@ DLL_API void integerOverload(long i); @@ -1482,3 +1482,5 @@ DLL_API void integerOverload(long i);
DLL_API void integerOverload(unsigned long i);
DLL_API void takeReferenceToVoidStar(const void*& p);
DLL_API void takeVoidStarStar(void** p);
DLL_API void overloadPointer(void* p, int i = 0);
DLL_API void overloadPointer(const void* p, int i = 0);

Loading…
Cancel
Save