From e430f6f8dcf51ae9c881152ba0b33ee70dd1b497 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 3 Jul 2019 03:00:42 +0300 Subject: [PATCH] Fix regressed indexers in templates with non-trivial ctors Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpMarshal.cs | 3 ++- .../Generators/CSharp/CSharpSources.cs | 22 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index dd54a28b..164bb5ba 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -711,7 +711,8 @@ namespace CppSharp.Generators.CSharp Context.Parameter.Name}"", ""Cannot be null because it is passed by value."");"); var realClass = @class.OriginalClass ?? @class; var qualifiedIdentifier = typePrinter.PrintNative(realClass); - Context.Return.Write($"*({qualifiedIdentifier}*) {paramInstance}"); + Context.ArgumentPrefix.Write($"*({qualifiedIdentifier}*) "); + Context.Return.Write(paramInstance); return; } diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index ffaee542..759ca8ab 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -876,7 +876,8 @@ namespace CppSharp.Generators.CSharp if (ctx.HasCodeBlock) Indent(); - WriteLine($"*{ptr} = {marshal.Context.Return};", marshal.Context.Return); + WriteLine($@"*{ptr} = {marshal.Context.ArgumentPrefix}{ + marshal.Context.Return};", marshal.Context.Return); if (ctx.HasCodeBlock) UnindentAndWriteCloseBrace(); @@ -974,7 +975,7 @@ namespace CppSharp.Generators.CSharp Write("(object) "); } } - WriteLine($"{marshal.Context.Return};"); + WriteLine($"{marshal.Context.ArgumentPrefix}{marshal.Context.Return};"); } if ((arrayType != null && @class.IsValueType) || ctx.HasCodeBlock) @@ -1049,7 +1050,7 @@ namespace CppSharp.Generators.CSharp GetInstanceParam(function)}, {paramMarshal.Context.ArgumentPrefix}{paramMarshal.Name})"; if (type.IsPrimitiveType()) { - WriteLine($"*{call} = {marshal.Context.Return};"); + WriteLine($"*{call} = {marshal.Context.ArgumentPrefix}{marshal.Context.Return};"); } else { @@ -1057,13 +1058,13 @@ namespace CppSharp.Generators.CSharp if (type.TryGetClass(out @class) && @class.HasNonTrivialCopyConstructor) { Method cctor = @class.Methods.First(c => c.IsCopyConstructor); - WriteLine($@"{@class.Visit(TypePrinter)}.{Helpers.InternalStruct}.{ - GetFunctionNativeIdentifier(cctor)}({call}, { - ctx.Parameter.Name}.{Helpers.InstanceIdentifier});"); + WriteLine($@"{TypePrinter.PrintNative(type)}.{ + GetFunctionNativeIdentifier(cctor)}({call}, {marshal.Context.Return});"); } else { - WriteLine($"*({TypePrinter.PrintNative(type)}*) {call} = {marshal.Context.Return};"); + WriteLine($@"*({TypePrinter.PrintNative(type)}*) {call} = { + marshal.Context.ArgumentPrefix}{marshal.Context.Return};"); } } } @@ -1790,13 +1791,12 @@ namespace CppSharp.Generators.CSharp if (method.HasIndirectReturnTypeParameter) { var retParam = method.Parameters.First(p => p.Kind == ParameterKind.IndirectReturnType); - WriteLine("*({0}*) {1} = {2};", - TypePrinter.PrintNative(method.OriginalReturnType), - retParam.Name, marshal.Context.Return); + WriteLine($@"*({TypePrinter.PrintNative(method.OriginalReturnType)}*) { + retParam.Name} = {marshal.Context.ArgumentPrefix}{marshal.Context.Return};"); } else { - WriteLine("return {0};", marshal.Context.Return); + WriteLine($"return {marshal.Context.ArgumentPrefix}{marshal.Context.Return};"); } }