Browse Source

Extract ""global::System.IntPtr"" into a constant for re-use in the marshaller.

pull/621/merge
João Matos 10 years ago
parent
commit
021189b49c
  1. 18
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs

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

@ -41,6 +41,8 @@ namespace CppSharp.Generators.CSharp
public class CSharpTypePrinter : ITypePrinter<CSharpTypePrinterResult>, public class CSharpTypePrinter : ITypePrinter<CSharpTypePrinterResult>,
IDeclVisitor<CSharpTypePrinterResult> IDeclVisitor<CSharpTypePrinterResult>
{ {
public static string IntPtrType = "global::System.IntPtr";
private readonly Driver driver; private readonly Driver driver;
private readonly Stack<CSharpTypePrinterContextKind> contexts; private readonly Stack<CSharpTypePrinterContextKind> contexts;
@ -180,7 +182,7 @@ namespace CppSharp.Generators.CSharp
PopMarshalKind(); PopMarshalKind();
if (ContextKind != CSharpTypePrinterContextKind.Managed) if (ContextKind != CSharpTypePrinterContextKind.Managed)
return "global::System.IntPtr"; return IntPtrType;
if (returnType.Type.IsPrimitiveType(PrimitiveType.Void)) if (returnType.Type.IsPrimitiveType(PrimitiveType.Void))
{ {
@ -243,7 +245,7 @@ namespace CppSharp.Generators.CSharp
var isManagedContext = ContextKind == CSharpTypePrinterContextKind.Managed; var isManagedContext = ContextKind == CSharpTypePrinterContextKind.Managed;
if (allowStrings && IsConstCharString(pointer)) if (allowStrings && IsConstCharString(pointer))
return isManagedContext ? "string" : "global::System.IntPtr"; return isManagedContext ? "string" : IntPtrType;
var desugared = pointee.Desugar(); var desugared = pointee.Desugar();
@ -273,7 +275,7 @@ namespace CppSharp.Generators.CSharp
var result = pointee.Visit(this, quals); var result = pointee.Visit(this, quals);
allowStrings = true; allowStrings = true;
return !isRefParam && result.Type == "global::System.IntPtr" ? "void**" : result + "*"; return !isRefParam && result.Type == IntPtrType ? "void**" : result + "*";
} }
Enumeration @enum; Enumeration @enum;
@ -293,7 +295,7 @@ namespace CppSharp.Generators.CSharp
(desugared is ArrayType && Context.Parameter != null)) (desugared is ArrayType && Context.Parameter != null))
&& ContextKind == CSharpTypePrinterContextKind.Native) && ContextKind == CSharpTypePrinterContextKind.Native)
{ {
return "global::System.IntPtr"; return IntPtrType;
} }
return pointee.Visit(this, quals); return pointee.Visit(this, quals);
@ -308,7 +310,7 @@ namespace CppSharp.Generators.CSharp
// TODO: Non-function member pointer types are tricky to support. // TODO: Non-function member pointer types are tricky to support.
// Re-visit this. // Re-visit this.
return "global::System.IntPtr"; return IntPtrType;
} }
public CSharpTypePrinterResult VisitBuiltinType(BuiltinType builtin, public CSharpTypePrinterResult VisitBuiltinType(BuiltinType builtin,
@ -345,7 +347,7 @@ namespace CppSharp.Generators.CSharp
if (decl.Type.IsPointerTo(out func)) if (decl.Type.IsPointerTo(out func))
{ {
if (ContextKind == CSharpTypePrinterContextKind.Native) if (ContextKind == CSharpTypePrinterContextKind.Native)
return "global::System.IntPtr"; return IntPtrType;
// TODO: Use SafeIdentifier() // TODO: Use SafeIdentifier()
return VisitDeclaration(decl); return VisitDeclaration(decl);
} }
@ -528,7 +530,7 @@ namespace CppSharp.Generators.CSharp
return GetIntString(primitive, driver.TargetInfo); return GetIntString(primitive, driver.TargetInfo);
case PrimitiveType.Float: return "float"; case PrimitiveType.Float: return "float";
case PrimitiveType.Double: return "double"; case PrimitiveType.Double: return "double";
case PrimitiveType.IntPtr: return "global::System.IntPtr"; case PrimitiveType.IntPtr: return IntPtrType;
case PrimitiveType.UIntPtr: return "global::System.UIntPtr"; case PrimitiveType.UIntPtr: return "global::System.UIntPtr";
case PrimitiveType.Null: return "void*"; case PrimitiveType.Null: return "void*";
} }
@ -576,7 +578,7 @@ namespace CppSharp.Generators.CSharp
var paramType = parameter.Type; var paramType = parameter.Type;
if (parameter.Kind == ParameterKind.IndirectReturnType) if (parameter.Kind == ParameterKind.IndirectReturnType)
return "global::System.IntPtr"; return IntPtrType;
Context.Parameter = parameter; Context.Parameter = parameter;
var ret = paramType.Visit(this); var ret = paramType.Visit(this);

Loading…
Cancel
Save