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
private string OverloadParamNameWithDefValue(Parameter p, ref int index) private string OverloadParamNameWithDefValue(Parameter p, ref int index)
{ {
Class @class;
return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue
? "ref param" + index++ ? "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) private void GenerateOverloadCall(Function function)
@ -2221,6 +2223,14 @@ namespace CppSharp.Generators.CSharp
WriteLine("{0} param{1} = {2};", pointeeType, j++, WriteLine("{0} param{1} = {2};", pointeeType, j++,
primitiveType == PrimitiveType.Bool ? "false" : "0"); 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); GenerateManagedCall(function);

8
tests/CSharp/CSharp.cpp

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

2
tests/CSharp/CSharp.h

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

Loading…
Cancel
Save