Browse Source

Fixed the wrapping for default values of non-const pointers.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/719/head
Dimitar Dobrev 9 years ago
parent
commit
54f6d2c306
  1. 22
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  2. 4
      tests/CSharp/CSharp.cpp
  3. 1
      tests/CSharp/CSharp.h

22
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -45,7 +45,7 @@ namespace CppSharp.Passes @@ -45,7 +45,7 @@ namespace CppSharp.Passes
foreach (var parameter in function.Parameters.Where(p => p.DefaultArgument != null))
{
var result = parameter.DefaultArgument.String;
if (PrintExpression(parameter.Type, parameter.DefaultArgument, ref result) == null)
if (PrintExpression(function, parameter.Type, parameter.DefaultArgument, ref result) == null)
overloadIndices.Add(function.Parameters.IndexOf(parameter));
if (string.IsNullOrEmpty(result))
{
@ -62,17 +62,27 @@ namespace CppSharp.Passes @@ -62,17 +62,27 @@ namespace CppSharp.Passes
return true;
}
private bool? PrintExpression(Type type, Expression expression, ref string result)
private bool? PrintExpression(Function function, Type type, Expression expression, ref string result)
{
var desugared = type.Desugar();
// constants are obtained through dynamic calls at present so they are not compile-time values in target languages
if (expression.Declaration is Variable ||
(!Options.MarshalCharAsManagedChar &&
desugared.IsPrimitiveType(PrimitiveType.UChar)) ||
type.IsPrimitiveTypeConvertibleToRef())
desugared.IsPrimitiveType(PrimitiveType.UChar)))
return null;
if (desugared.IsPrimitiveTypeConvertibleToRef())
{
var method = function as Method;
if (method != null && method.IsConstructor)
{
result = string.Empty;
return false;
}
return null;
}
if (CheckForDefaultPointer(desugared, ref result))
return true;
@ -186,8 +196,8 @@ namespace CppSharp.Passes @@ -186,8 +196,8 @@ namespace CppSharp.Passes
{
var argument = ctor.Arguments[i];
var argResult = argument.String;
expressionSupported &= PrintExpression(method.Parameters[i].Type.Desugar(),
argument, ref argResult) ?? false;
expressionSupported &= PrintExpression(method,
method.Parameters[i].Type.Desugar(), argument, ref argResult) ?? false;
argsBuilder.Append(argResult);
if (i < ctor.Arguments.Count - 1)
argsBuilder.Append(", ");

4
tests/CSharp/CSharp.cpp

@ -473,6 +473,10 @@ MethodsWithDefaultValues::MethodsWithDefaultValues(int a) @@ -473,6 +473,10 @@ MethodsWithDefaultValues::MethodsWithDefaultValues(int a)
m_foo.A = a;
}
MethodsWithDefaultValues::MethodsWithDefaultValues(float a, int* b)
{
}
MethodsWithDefaultValues::MethodsWithDefaultValues(double d, QList<QColor> list)
{
}

1
tests/CSharp/CSharp.h

@ -387,6 +387,7 @@ public: @@ -387,6 +387,7 @@ public:
MethodsWithDefaultValues(Foo foo = Foo());
MethodsWithDefaultValues(int a);
MethodsWithDefaultValues(float a, int* b = 0);
MethodsWithDefaultValues(double d, QList<QColor> list = QList<QColor>());
MethodsWithDefaultValues(QRect* pointer, float f = 1, int i = std::numeric_limits<double>::infinity());
void defaultPointer(Foo* ptr = 0);

Loading…
Cancel
Save