Browse Source

Fixed another case of a default arg assigned through an implicit ctor.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/256/merge
Dimitar Dobrev 10 years ago
parent
commit
144b9546de
  1. 18
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  2. 1
      tests/CSharp/CSharp.Tests.cs
  3. 8
      tests/CSharp/CSharp.cpp
  4. 6
      tests/CSharp/CSharp.h

18
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -73,6 +73,11 @@ namespace CppSharp.Passes @@ -73,6 +73,11 @@ namespace CppSharp.Passes
if (defaultConstruct != false)
return defaultConstruct;
return CheckForSimpleExpressions(expression, ref result, desugared);
}
private bool CheckForSimpleExpressions(Expression expression, ref string result, Type desugared)
{
return CheckFloatSyntax(desugared, expression, ref result) ||
CheckForBinaryOperator(desugared, expression, ref result) ||
CheckForEnumValue(desugared, expression, ref result) ||
@ -106,7 +111,7 @@ namespace CppSharp.Passes @@ -106,7 +111,7 @@ namespace CppSharp.Passes
return true;
}
private bool? CheckForDefaultConstruct(Type desugared, Statement statement,
private bool? CheckForDefaultConstruct(Type desugared, Expression expression,
ref string result)
{
var type = desugared.GetFinalPointee() ?? desugared;
@ -115,7 +120,7 @@ namespace CppSharp.Passes @@ -115,7 +120,7 @@ namespace CppSharp.Passes
if (!type.TryGetClass(out decl))
return false;
var ctor = statement as CXXConstructExpr;
var ctor = expression as CXXConstructExpr;
TypeMap typeMap;
@ -147,12 +152,15 @@ namespace CppSharp.Passes @@ -147,12 +152,15 @@ namespace CppSharp.Passes
}
if (ctor == null)
{
CheckForSimpleExpressions(expression, ref result, desugared);
return decl.IsValueType ? (bool?) false : null;
}
var method = (Method) statement.Declaration;
var method = (Method) expression.Declaration;
var expressionSupported = decl.IsValueType && method.Parameters.Count == 0;
if (statement.String.Contains('('))
if (expression.String.Contains('('))
{
var argsBuilder = new StringBuilder("new ");
argsBuilder.Append(typePrinterResult);
@ -177,7 +185,7 @@ namespace CppSharp.Passes @@ -177,7 +185,7 @@ namespace CppSharp.Passes
var paramType = method.Parameters[0].Type.SkipPointerRefs().Desugar();
Enumeration @enum;
if (paramType.TryGetEnum(out @enum))
result = TranslateEnumExpression(method, paramType, statement.String);
result = TranslateEnumExpression(method, paramType, expression.String);
}
}
return expressionSupported ? true : (bool?) null;

1
tests/CSharp/CSharp.Tests.cs

@ -189,6 +189,7 @@ public class CSharpTests : GeneratorTestFixture @@ -189,6 +189,7 @@ public class CSharpTests : GeneratorTestFixture
methodsWithDefaultValues.DefaultImplicitCtorInt();
methodsWithDefaultValues.DefaultImplicitCtorChar();
methodsWithDefaultValues.DefaultImplicitCtorFoo();
methodsWithDefaultValues.DefaultImplicitCtorEnum();
methodsWithDefaultValues.DefaultIntWithLongExpression();
methodsWithDefaultValues.DefaultRefTypeEnumImplicitCtor();
methodsWithDefaultValues.Rotate4x4Matrix(0, 0, 0);

8
tests/CSharp/CSharp.cpp

@ -181,6 +181,10 @@ ForceCreationOfInterface::ForceCreationOfInterface() @@ -181,6 +181,10 @@ ForceCreationOfInterface::ForceCreationOfInterface()
{
}
Baz::Baz(Bar::Items item)
{
}
int Baz::takesQux(const Qux& qux)
{
return qux.farAwayFunc();
@ -463,6 +467,10 @@ void MethodsWithDefaultValues::defaultImplicitCtorFoo(Quux arg) @@ -463,6 +467,10 @@ void MethodsWithDefaultValues::defaultImplicitCtorFoo(Quux arg)
{
}
void MethodsWithDefaultValues::defaultImplicitCtorEnum(Baz arg)
{
}
void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i)
{
}

6
tests/CSharp/CSharp.h

@ -98,6 +98,7 @@ public: @@ -98,6 +98,7 @@ public:
class NestedDerived : public NestedBase1, public NestedBase2 {};
Baz();
Baz(Bar::Items item);
int P;
@ -358,6 +359,11 @@ public: @@ -358,6 +359,11 @@ public:
void defaultImplicitCtorInt(Quux arg = 0);
void defaultImplicitCtorChar(Quux arg = 'a');
void defaultImplicitCtorFoo(Quux arg = Foo());
// this looks the same test as 'defaultRefTypeEnumImplicitCtor' two lines below
// however, Clang considers them different
// 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 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