From 304d673bf70bf63e6d607cd415c9389b53a9a06a Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Thu, 11 Apr 2019 01:11:58 +0300 Subject: [PATCH] Add a generic pointer to resolve ambiguity Signed-off-by: Dimitar Dobrev --- build/Tests.lua | 3 +-- .../Generators/CSharp/CSharpTypePrinter.cs | 10 +++++++--- src/Runtime/Pointer.cs | 13 +++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 src/Runtime/Pointer.cs diff --git a/build/Tests.lua b/build/Tests.lua index 3208a0f8..8929fd6e 100644 --- a/build/Tests.lua +++ b/build/Tests.lua @@ -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" diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 050f0af1..8dc19a0d 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -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) diff --git a/src/Runtime/Pointer.cs b/src/Runtime/Pointer.cs new file mode 100644 index 00000000..2afed527 --- /dev/null +++ b/src/Runtime/Pointer.cs @@ -0,0 +1,13 @@ +using System; + +namespace CppSharp.Runtime +{ + public class Pointer + { + public Pointer(IntPtr ptr) => this.ptr = ptr; + + public static implicit operator IntPtr(Pointer pointer) => pointer.ptr; + + private readonly IntPtr ptr; + } +}