Browse Source

Fixed the generation of constructor overloads synthetised because of default arguments.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/345/head
Dimitar Dobrev 11 years ago
parent
commit
2894999696
  1. 29
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 4
      tests/CSharpTemp/CSharpTemp.cpp
  3. 1
      tests/CSharpTemp/CSharpTemp.h

29
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -2072,6 +2072,16 @@ namespace CppSharp.Generators.CSharp @@ -2072,6 +2072,16 @@ namespace CppSharp.Generators.CSharp
Write(")");
if (method.SynthKind == FunctionSynthKind.DefaultValueOverload && method.IsConstructor &&
!(Driver.Options.GenerateAbstractImpls && method.IsPure))
{
Write(" : this({0})",
string.Join(", ",
method.Parameters.Where(
p => p.Kind == ParameterKind.Regular).Select(
p => p.GenerationKind == GenerationKind.None ? p.DefaultArgument.String : p.Name)));
}
if (Driver.Options.GenerateAbstractImpls && method.IsPure)
{
Write(";");
@ -2090,14 +2100,17 @@ namespace CppSharp.Generators.CSharp @@ -2090,14 +2100,17 @@ namespace CppSharp.Generators.CSharp
if (method.SynthKind == FunctionSynthKind.DefaultValueOverload)
{
Type type = method.OriginalReturnType.Type;
WriteLine("{0}{1}({2});",
type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : "return ",
method.Name,
string.Join(", ",
method.Parameters.Where(
p => p.Kind == ParameterKind.Regular).Select(
p => p.GenerationKind == GenerationKind.None ? p.DefaultArgument.String : p.Name)));
if (!method.IsConstructor)
{
Type type = method.OriginalReturnType.Type;
this.WriteLine("{0}{1}({2});",
type.IsPrimitiveType(PrimitiveType.Void) ? string.Empty : "return ",
method.Name,
string.Join(", ",
method.Parameters.Where(
p => p.Kind == ParameterKind.Regular).Select(
p => p.GenerationKind == GenerationKind.None ? p.DefaultArgument.String : p.Name)));
}
goto SkipImpl;
}

4
tests/CSharpTemp/CSharpTemp.cpp

@ -237,6 +237,10 @@ QGenericArgument::QGenericArgument(const char *name) @@ -237,6 +237,10 @@ QGenericArgument::QGenericArgument(const char *name)
_name = name;
}
MethodsWithDefaultValues::MethodsWithDefaultValues(Foo foo)
{
}
void MethodsWithDefaultValues::defaultPointer(Foo *ptr)
{
}

1
tests/CSharpTemp/CSharpTemp.h

@ -216,6 +216,7 @@ private: @@ -216,6 +216,7 @@ private:
class DLL_API MethodsWithDefaultValues
{
public:
MethodsWithDefaultValues(Foo foo = Foo());
void defaultPointer(Foo* ptr = 0);
void defaultValueType(ValueType bar = ValueType());
void defaultChar(char c = 'a');

Loading…
Cancel
Save