Browse Source

Add a generic pointer to resolve ambiguity

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1204/head
Dimitar Dobrev 6 years ago
parent
commit
304d673bf7
  1. 3
      build/Tests.lua
  2. 10
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  3. 13
      src/Runtime/Pointer.cs

3
build/Tests.lua

@ -185,11 +185,10 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix) @@ -185,11 +185,10 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
files { name .. ".Tests.cs" }
vpaths { ["*"] = "*" }
links { name .. ".CSharp", "CppSharp.Generator.Tests" }
links { name .. ".CSharp", "CppSharp.Generator.Tests", "CppSharp.Runtime" }
dependson { name .. ".Native" }
LinkNUnit()
links { "CppSharp.Runtime" }
filter { "action:netcore" }
dotnetframework "netcoreapp2.0"

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

@ -561,9 +561,13 @@ namespace CppSharp.Generators.CSharp @@ -561,9 +561,13 @@ namespace CppSharp.Generators.CSharp
if (a.Type.Type == null)
return a.Integral.ToString(CultureInfo.InvariantCulture);
var type = a.Type.Type.Desugar();
return type.IsPointerToPrimitiveType() && !type.IsConstCharString() ?
IntPtrType : type.IsPrimitiveType(PrimitiveType.Void) ? "object" :
type.Visit(this).Type;
PrimitiveType pointee;
if (type.IsPointerToPrimitiveType(out pointee) && !type.IsConstCharString())
{
return $@"CppSharp.Runtime.Pointer<{(pointee == PrimitiveType.Void ? IntPtrType :
VisitPrimitiveType(pointee, new TypeQualifiers()).Type)}>";
}
return (type.IsPrimitiveType(PrimitiveType.Void)) ? "object" : type.Visit(this).Type;
}
public override TypePrinterResult VisitParameterDecl(Parameter parameter)

13
src/Runtime/Pointer.cs

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
using System;
namespace CppSharp.Runtime
{
public class Pointer<T>
{
public Pointer(IntPtr ptr) => this.ptr = ptr;
public static implicit operator IntPtr(Pointer<T> pointer) => pointer.ptr;
private readonly IntPtr ptr;
}
}
Loading…
Cancel
Save