Browse Source

Supported constants as default values of parameters.

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

4
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -59,7 +59,9 @@ namespace CppSharp.Passes
{ {
var desugared = type.Desugar(); var desugared = type.Desugar();
if ((!Driver.Options.MarshalCharAsManagedChar && // constants are obtained through dynamic calls at present so they are not compile-time values in target languages
if (expression.Declaration is Variable ||
(!Driver.Options.MarshalCharAsManagedChar &&
desugared.IsPrimitiveType(PrimitiveType.UChar)) || desugared.IsPrimitiveType(PrimitiveType.UChar)) ||
type.IsPrimitiveTypeConvertibleToRef()) type.IsPrimitiveTypeConvertibleToRef())
return null; return null;

3
tests/CSharp/CSharp.Tests.cs

@ -211,7 +211,8 @@ public unsafe class CSharpTests : GeneratorTestFixture
methodsWithDefaultValues.DefaultWithFunctionCall(); methodsWithDefaultValues.DefaultWithFunctionCall();
methodsWithDefaultValues.DefaultWithPropertyCall(); methodsWithDefaultValues.DefaultWithPropertyCall();
methodsWithDefaultValues.DefaultWithGetPropertyCall(); methodsWithDefaultValues.DefaultWithGetPropertyCall();
methodsWithDefaultValues.DefaultWithStringConstant(); methodsWithDefaultValues.DefaultWithIndirectStringConstant();
methodsWithDefaultValues.DefaultWithDirectIntConstant();
} }
} }

7
tests/CSharp/CSharp.cpp

@ -414,6 +414,7 @@ MethodsWithDefaultValues::QMargins::QMargins(int left, int top, int right, int b
} }
char* MethodsWithDefaultValues::stringConstant = "test"; char* MethodsWithDefaultValues::stringConstant = "test";
int MethodsWithDefaultValues::intConstant = 5;
MethodsWithDefaultValues::MethodsWithDefaultValues(Foo foo) MethodsWithDefaultValues::MethodsWithDefaultValues(Foo foo)
{ {
@ -570,7 +571,11 @@ void MethodsWithDefaultValues::defaultWithGetPropertyCall(int f)
{ {
} }
void MethodsWithDefaultValues::defaultWithStringConstant(const Foo& arg) void MethodsWithDefaultValues::defaultWithIndirectStringConstant(const Foo& arg)
{
}
void MethodsWithDefaultValues::defaultWithDirectIntConstant(int arg)
{ {
} }

4
tests/CSharp/CSharp.h

@ -355,6 +355,7 @@ public:
}; };
static char* stringConstant; static char* stringConstant;
static int intConstant;
MethodsWithDefaultValues(Foo foo = Foo()); MethodsWithDefaultValues(Foo foo = Foo());
MethodsWithDefaultValues(int a); MethodsWithDefaultValues(int a);
@ -398,7 +399,8 @@ public:
void defaultWithFunctionCall(int f = Foo::makeFunctionCall()); void defaultWithFunctionCall(int f = Foo::makeFunctionCall());
void defaultWithPropertyCall(int f = Foo::propertyCall()); void defaultWithPropertyCall(int f = Foo::propertyCall());
void defaultWithGetPropertyCall(int f = Foo::getGetPropertyCall()); void defaultWithGetPropertyCall(int f = Foo::getGetPropertyCall());
void defaultWithStringConstant(const Foo& arg = Foo(stringConstant)); void defaultWithIndirectStringConstant(const Foo& arg = Foo(stringConstant));
void defaultWithDirectIntConstant(int arg = intConstant);
int getA(); int getA();
private: private:
Foo m_foo; Foo m_foo;

Loading…
Cancel
Save