Browse Source

Fixed the generated code when a default parameter of type char or wide char is assigned an int.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/681/head
Dimitar Dobrev 9 years ago
parent
commit
0ea801f7b9
  1. 15
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  2. 2
      tests/CSharp/CSharp.Tests.cs
  3. 4
      tests/CSharp/CSharp.cpp
  4. 1
      tests/CSharp/CSharp.h

15
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -84,7 +84,7 @@ namespace CppSharp.Passes @@ -84,7 +84,7 @@ namespace CppSharp.Passes
return CheckFloatSyntax(desugared, expression, ref result) ||
CheckForBinaryOperator(desugared, expression, ref result) ||
CheckForEnumValue(desugared, expression, ref result) ||
CheckForDefaultEmptyChar(desugared, expression, ref result);
CheckForDefaultChar(desugared, ref result);
}
private bool CheckForDefaultPointer(Type desugared, ref string result)
@ -306,14 +306,15 @@ namespace CppSharp.Passes @@ -306,14 +306,15 @@ namespace CppSharp.Passes
((BuiltinTypeExpression) defaultArgument).Value == 0;
}
private bool CheckForDefaultEmptyChar(Type desugared, Statement statement,
ref string result)
private bool CheckForDefaultChar(Type desugared, ref string result)
{
if (statement.String == "0" &&
Driver.Options.MarshalCharAsManagedChar &&
desugared.IsPrimitiveType(PrimitiveType.Char))
int value;
if (int.TryParse(result, out value) &&
((Driver.Options.MarshalCharAsManagedChar &&
desugared.IsPrimitiveType(PrimitiveType.Char)) ||
desugared.IsPrimitiveType(PrimitiveType.WideChar)))
{
result = "'\\0'";
result = value == 0 ? "'\\0'" : ("(char) " + result);
return true;
}

2
tests/CSharp/CSharp.Tests.cs

@ -213,6 +213,8 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -213,6 +213,8 @@ public unsafe class CSharpTests : GeneratorTestFixture
methodsWithDefaultValues.DefaultWithGetPropertyCall();
methodsWithDefaultValues.DefaultWithIndirectStringConstant();
methodsWithDefaultValues.DefaultWithDirectIntConstant();
methodsWithDefaultValues.DefaultWithEnumInLowerCasedNameSpace();
methodsWithDefaultValues.DefaultWithCharFromInt();
}
}

4
tests/CSharp/CSharp.cpp

@ -583,6 +583,10 @@ void MethodsWithDefaultValues::defaultWithEnumInLowerCasedNameSpace(lowerCaseNam @@ -583,6 +583,10 @@ void MethodsWithDefaultValues::defaultWithEnumInLowerCasedNameSpace(lowerCaseNam
{
}
void MethodsWithDefaultValues::defaultWithCharFromInt(char c)
{
}
int MethodsWithDefaultValues::getA()
{
return m_foo.A;

1
tests/CSharp/CSharp.h

@ -411,6 +411,7 @@ public: @@ -411,6 +411,7 @@ public:
void defaultWithIndirectStringConstant(const Foo& arg = Foo(stringConstant));
void defaultWithDirectIntConstant(int arg = intConstant);
void defaultWithEnumInLowerCasedNameSpace(lowerCaseNameSpace::Enum e = lowerCaseNameSpace::Enum::Item2);
void defaultWithCharFromInt(char c = 32);
int getA();
private:
Foo m_foo;

Loading…
Cancel
Save