Browse Source

Fixed the generated code when a default argument uses a constant.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/658/head
Dimitar Dobrev 9 years ago
parent
commit
6dadab3796
  1. 4
      src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs
  2. 3
      tests/CSharp/CSharp.Tests.cs
  3. 8
      tests/CSharp/CSharp.cpp
  4. 5
      tests/CSharp/CSharp.h

4
src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs

@ -60,6 +60,10 @@ namespace CppSharp.Generators.CSharp @@ -60,6 +60,10 @@ namespace CppSharp.Generators.CSharp
default:
return new CSharpExpressionPrinterResult { Value = expr.String };
}
case StatementClass.DeclarationReference:
if (expr.Declaration is Variable)
return new CSharpExpressionPrinterResult { Value = expr.Declaration.Name };
goto default;
default:
return new CSharpExpressionPrinterResult { Value = expr.String };
}

3
tests/CSharp/CSharp.Tests.cs

@ -6,7 +6,7 @@ using CppSharp.Utils; @@ -6,7 +6,7 @@ using CppSharp.Utils;
using CSharp;
using NUnit.Framework;
public class CSharpTests : GeneratorTestFixture
public unsafe class CSharpTests : GeneratorTestFixture
{
public class ExtendsWrapper : TestOverrideFromSecondaryBase
{
@ -210,6 +210,7 @@ public class CSharpTests : GeneratorTestFixture @@ -210,6 +210,7 @@ public class CSharpTests : GeneratorTestFixture
methodsWithDefaultValues.DefaultWithFunctionCall();
methodsWithDefaultValues.DefaultWithPropertyCall();
methodsWithDefaultValues.DefaultWithGetPropertyCall();
methodsWithDefaultValues.DefaultWithStringConstant();
}
}

8
tests/CSharp/CSharp.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#include "CSharp.h"
Foo::Foo()
Foo::Foo(char* name)
{
A = 10;
P = 50;
@ -381,6 +381,8 @@ MethodsWithDefaultValues::QMargins::QMargins(int left, int top, int right, int b @@ -381,6 +381,8 @@ MethodsWithDefaultValues::QMargins::QMargins(int left, int top, int right, int b
{
}
char* MethodsWithDefaultValues::stringConstant = "test";
MethodsWithDefaultValues::MethodsWithDefaultValues(Foo foo)
{
m_foo = foo;
@ -535,6 +537,10 @@ void MethodsWithDefaultValues::defaultWithGetPropertyCall(int f) @@ -535,6 +537,10 @@ void MethodsWithDefaultValues::defaultWithGetPropertyCall(int f)
{
}
void MethodsWithDefaultValues::defaultWithStringConstant(const Foo& arg)
{
}
int MethodsWithDefaultValues::getA()
{
return m_foo.A;

5
tests/CSharp/CSharp.h

@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
class DLL_API Foo
{
public:
Foo();
Foo(char* name = 0);
Foo(int a, int p = 0);
int method();
int operator[](int i) const;
@ -340,6 +340,8 @@ public: @@ -340,6 +340,8 @@ public:
QMargins(int left, int top, int right, int bottom);
};
static char* stringConstant;
MethodsWithDefaultValues(Foo foo = Foo());
MethodsWithDefaultValues(int a);
MethodsWithDefaultValues(double d, QList<QColor> list = QList<QColor>());
@ -382,6 +384,7 @@ public: @@ -382,6 +384,7 @@ public:
void defaultWithFunctionCall(int f = Foo::makeFunctionCall());
void defaultWithPropertyCall(int f = Foo::propertyCall());
void defaultWithGetPropertyCall(int f = Foo::getGetPropertyCall());
void defaultWithStringConstant(const Foo& arg = Foo(stringConstant));
int getA();
private:
Foo m_foo;

Loading…
Cancel
Save