Browse Source

Fix for fn call when def argument is interface.

pull/600/head
Abhinav Tripathi 10 years ago
parent
commit
347d0cdbaf
  1. 12
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 8
      tests/CSharp/CSharp.cpp
  3. 2
      tests/CSharp/CSharp.h

12
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -2202,9 +2202,11 @@ namespace CppSharp.Generators.CSharp @@ -2202,9 +2202,11 @@ namespace CppSharp.Generators.CSharp
private string OverloadParamNameWithDefValue(Parameter p, ref int index)
{
Class @class;
return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue
? "ref param" + index++
: ExpressionPrinter.VisitExpression(p.DefaultArgument).Value;
: (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++
: ExpressionPrinter.VisitExpression(p.DefaultArgument).Value);
}
private void GenerateOverloadCall(Function function)
@ -2221,6 +2223,14 @@ namespace CppSharp.Generators.CSharp @@ -2221,6 +2223,14 @@ namespace CppSharp.Generators.CSharp
WriteLine("{0} param{1} = {2};", pointeeType, j++,
primitiveType == PrimitiveType.Bool ? "false" : "0");
}
Class @class;
if (parameter.Kind == ParameterKind.Regular && parameter.Ignore &&
parameter.Type.Desugar().TryGetClass(out @class) && @class.IsInterface &&
parameter.HasDefaultValue)
{
WriteLine("var param{0} = ({1}) {2};", j++, @class.OriginalClass.OriginalName,
ExpressionPrinter.VisitExpression(parameter.DefaultArgument).Value);
}
}
GenerateManagedCall(function);

8
tests/CSharp/CSharp.cpp

@ -143,6 +143,10 @@ Bar::Bar(Qux qux) @@ -143,6 +143,10 @@ Bar::Bar(Qux qux)
{
}
Bar::Bar(Items item)
{
}
int Bar::method()
{
return 2;
@ -471,6 +475,10 @@ void MethodsWithDefaultValues::defaultImplicitCtorEnum(Baz arg) @@ -471,6 +475,10 @@ void MethodsWithDefaultValues::defaultImplicitCtorEnum(Baz arg)
{
}
void MethodsWithDefaultValues::defaultImplicitCtorEnumTwo(Bar arg)
{
}
void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i)
{
}

2
tests/CSharp/CSharp.h

@ -63,6 +63,7 @@ public: @@ -63,6 +63,7 @@ public:
};
Bar();
Bar(Qux qux);
Bar(Items item);
int method();
const Foo& operator[](int i) const;
Foo& operator[](int i);
@ -364,6 +365,7 @@ public: @@ -364,6 +365,7 @@ public:
// in this case the arg is a MaterializeTemporaryExpr, in the other not
// I cannot see the difference but it's there so we need both tests
void defaultImplicitCtorEnum(Baz arg = Bar::Item1);
void defaultImplicitCtorEnumTwo(Bar arg = Bar::Items::Item1);
void defaultIntWithLongExpression(unsigned int i = DEFAULT_INT);
void defaultRefTypeEnumImplicitCtor(const QColor &fillColor = Qt::white);
void rotate4x4Matrix(float angle, float x, float y, float z = 0.0f);

Loading…
Cancel
Save