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

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

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

2
tests/CSharp/CSharp.Tests.cs

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

Loading…
Cancel
Save