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
default: default:
return new CSharpExpressionPrinterResult { Value = expr.String }; return new CSharpExpressionPrinterResult { Value = expr.String };
} }
case StatementClass.DeclarationReference:
if (expr.Declaration is Variable)
return new CSharpExpressionPrinterResult { Value = expr.Declaration.Name };
goto default;
default: default:
return new CSharpExpressionPrinterResult { Value = expr.String }; return new CSharpExpressionPrinterResult { Value = expr.String };
} }

3
tests/CSharp/CSharp.Tests.cs

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

8
tests/CSharp/CSharp.cpp

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

5
tests/CSharp/CSharp.h

@ -5,7 +5,7 @@
class DLL_API Foo class DLL_API Foo
{ {
public: public:
Foo(); Foo(char* name = 0);
Foo(int a, int p = 0); Foo(int a, int p = 0);
int method(); int method();
int operator[](int i) const; int operator[](int i) const;
@ -340,6 +340,8 @@ public:
QMargins(int left, int top, int right, int bottom); QMargins(int left, int top, int right, int bottom);
}; };
static char* stringConstant;
MethodsWithDefaultValues(Foo foo = Foo()); MethodsWithDefaultValues(Foo foo = Foo());
MethodsWithDefaultValues(int a); MethodsWithDefaultValues(int a);
MethodsWithDefaultValues(double d, QList<QColor> list = QList<QColor>()); MethodsWithDefaultValues(double d, QList<QColor> list = QList<QColor>());
@ -382,6 +384,7 @@ 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));
int getA(); int getA();
private: private:
Foo m_foo; Foo m_foo;

Loading…
Cancel
Save