Browse Source

Simplify code by not specially handling void**

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1641/head
Dimitar Dobrev 4 years ago
parent
commit
0d84877068
  1. 9
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 8
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  3. 2
      tests/CSharp/CSharp.Tests.cs

9
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -184,11 +184,6 @@ namespace CppSharp.Generators.CSharp
if (new QualifiedType(pointer, quals).IsConstRefToPrimitive()) if (new QualifiedType(pointer, quals).IsConstRefToPrimitive())
{ {
if (finalPointee.IsPrimitiveType(PrimitiveType.Void))
{
Context.Return.Write($"new {typePrinter.IntPtrType}(*{Context.ReturnVarName})");
return true;
}
Context.Return.Write("*"); Context.Return.Write("*");
if (Context.MarshalKind == MarshalKind.NativeField) if (Context.MarshalKind == MarshalKind.NativeField)
Context.Return.Write($"({pointer.QualifiedPointee.Visit(typePrinter)}*) "); Context.Return.Write($"({pointer.QualifiedPointee.Visit(typePrinter)}*) ");
@ -612,9 +607,7 @@ namespace CppSharp.Generators.CSharp
{ {
var local = Generator.GeneratedIdentifier($@"{ var local = Generator.GeneratedIdentifier($@"{
param.Name}{Context.ParameterIndex}"); param.Name}{Context.ParameterIndex}");
string cast = isVoid ? $@"({pointee.Visit( Context.Before.WriteLine($"var {local} = {Context.Return};");
new CppTypePrinter(Context.Context) { PrintTypeQualifiers = false })}) " : string.Empty;
Context.Before.WriteLine($"var {local} = {cast}{Context.Return};");
Context.Return.StringBuilder.Clear(); Context.Return.StringBuilder.Clear();
Context.Return.Write(local); Context.Return.Write(local);
} }

8
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -191,8 +191,7 @@ namespace CppSharp.Generators.CSharp
// * Any pointer type. // * Any pointer type.
// * Any user-defined struct type that contains fields of unmanaged types only. // * Any user-defined struct type that contains fields of unmanaged types only.
var finalPointee = (pointee.GetFinalPointee() ?? pointee).Desugar(); var finalPointee = (pointee.GetFinalPointee() ?? pointee).Desugar();
Enumeration @enum; if (finalPointee.IsPrimitiveType() || finalPointee.IsEnum())
if (finalPointee.IsPrimitiveType() || finalPointee.TryGetEnum(out @enum))
{ {
// Skip one indirection if passed by reference // Skip one indirection if passed by reference
bool isRefParam = Parameter != null && (Parameter.IsOut || Parameter.IsInOut); bool isRefParam = Parameter != null && (Parameter.IsOut || Parameter.IsInOut);
@ -212,11 +211,10 @@ namespace CppSharp.Generators.CSharp
allowStrings = true; allowStrings = true;
string @ref = Parameter != null && Parameter.IsIndirect ? string.Empty : "*"; string @ref = Parameter != null && Parameter.IsIndirect ? string.Empty : "*";
return !isRefParam && result.Type == this.IntPtrType ? "void**" : result + @ref; return result + @ref;
} }
Class @class; if ((pointee.IsDependent || pointee.IsClass())
if ((pointee.IsDependent || pointee.TryGetClass(out @class))
&& ContextKind == TypePrinterContextKind.Native) && ContextKind == TypePrinterContextKind.Native)
{ {
return IntPtrType; return IntPtrType;

2
tests/CSharp/CSharp.Tests.cs

@ -1691,7 +1691,7 @@ public unsafe class CSharpTests
public void TestRValueReferenceToPointer() public void TestRValueReferenceToPointer()
{ {
int value = 5; int value = 5;
IntPtr intPtr = CSharp.CSharp.RValueReferenceToPointer((void**) &value); IntPtr intPtr = CSharp.CSharp.RValueReferenceToPointer((IntPtr*) &value);
Assert.That((int) intPtr, Is.EqualTo(value)); Assert.That((int) intPtr, Is.EqualTo(value));
} }

Loading…
Cancel
Save