Browse Source

Changed `CSharpTypePrinter.IntPtrType` to be a getter property.

pull/1177/head
Joao Matos 6 years ago committed by João Matos
parent
commit
850dcfaf67
  1. 10
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 8
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 2
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  4. 10
      src/Generator/Types/Std/Stdlib.cs

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

@ -98,7 +98,7 @@ namespace CppSharp.Generators.CSharp @@ -98,7 +98,7 @@ namespace CppSharp.Generators.CSharp
else
supportBefore.WriteLineIndent(
$@"{value}[i] = {finalArrayType}.{Helpers.CreateInstanceIdentifier}(({
CSharpTypePrinter.IntPtrType}) {Context.ReturnVarName}[i]);");
typePrinter.IntPtrType}) {Context.ReturnVarName}[i]);");
}
else
{
@ -313,7 +313,7 @@ namespace CppSharp.Generators.CSharp @@ -313,7 +313,7 @@ namespace CppSharp.Generators.CSharp
if (finalType.IsDependent)
Context.Return.Write($"({param.ReplacedParameter.Parameter.Name}) (object) ");
if (param.Replacement.Type.Desugar().IsPointerToPrimitiveType())
Context.Return.Write($"({CSharpTypePrinter.IntPtrType}) ");
Context.Return.Write($"({typePrinter.IntPtrType}) ");
return base.VisitTemplateParameterSubstitutionType(param, quals);
}
@ -385,7 +385,7 @@ namespace CppSharp.Generators.CSharp @@ -385,7 +385,7 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteOpenBraceAndIndent();
string element = Generator.GeneratedIdentifier("element");
Context.Before.WriteLine($"var {element} = {Context.ReturnVarName}[i];");
var intPtrZero = $"{CSharpTypePrinter.IntPtrType}.Zero";
var intPtrZero = $"{typePrinter.IntPtrType}.Zero";
Context.Before.WriteLine($@"{intermediateArray}[i] = {element} == {
intPtrZero} ? null : {intermediateArrayType}.{
Helpers.CreateInstanceIdentifier}({element});");
@ -626,7 +626,7 @@ namespace CppSharp.Generators.CSharp @@ -626,7 +626,7 @@ namespace CppSharp.Generators.CSharp
{
Context.Return.Write($"({replacement}) ");
if (replacement.IsPointerToPrimitiveType())
Context.Return.Write($"({CSharpTypePrinter.IntPtrType}) ");
Context.Return.Write($"({typePrinter.IntPtrType}) ");
Context.Return.Write("(object) ");
}
return base.VisitTemplateParameterSubstitutionType(param, quals);
@ -822,7 +822,7 @@ namespace CppSharp.Generators.CSharp @@ -822,7 +822,7 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteLine($"var {element} = {Context.Parameter.Name}[i];");
if (elementType.IsAddress())
{
var intPtrZero = $"{CSharpTypePrinter.IntPtrType}.Zero";
var intPtrZero = $"{typePrinter.IntPtrType}.Zero";
Context.Before.WriteLine($@"{intermediateArray}[i] = ReferenceEquals({
element}, null) ? {intPtrZero} : {element}.{Helpers.InstanceIdentifier};");
}

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

@ -420,7 +420,7 @@ namespace CppSharp.Generators.CSharp @@ -420,7 +420,7 @@ namespace CppSharp.Generators.CSharp
else
{
WriteLine("public {0} {1} {{ get; protected set; }}",
CSharpTypePrinter.IntPtrType, Helpers.InstanceIdentifier);
TypePrinter.IntPtrType, Helpers.InstanceIdentifier);
PopBlock(NewLineKind.BeforeNextBlock);
@ -942,7 +942,7 @@ namespace CppSharp.Generators.CSharp @@ -942,7 +942,7 @@ namespace CppSharp.Generators.CSharp
Type pointee = type.GetFinalPointee();
if (pointee.IsPrimitiveType())
{
Write($"({CSharpTypePrinter.IntPtrType}) ");
Write($"({TypePrinter.IntPtrType}) ");
var templateSubstitution = pointee.Desugar(false) as TemplateParameterSubstitutionType;
if (templateSubstitution != null)
Write("(object) ");
@ -1137,7 +1137,7 @@ namespace CppSharp.Generators.CSharp @@ -1137,7 +1137,7 @@ namespace CppSharp.Generators.CSharp
else
ctx.ReturnVarName = $@"{elementType}.{
Helpers.CreateInstanceIdentifier}(new {
CSharpTypePrinter.IntPtrType}({ptr}))";
TypePrinter.IntPtrType}({ptr}))";
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
var.QualifiedType.Visit(marshal);
@ -1202,7 +1202,7 @@ namespace CppSharp.Generators.CSharp @@ -1202,7 +1202,7 @@ namespace CppSharp.Generators.CSharp
Class typeClass;
if (field.Type.TryGetClass(out typeClass) && !typeClass.IsValueType &&
!ASTUtils.IsMappedToPrimitive(Context.TypeMaps, field.Type))
returnVar = $"new {CSharpTypePrinter.IntPtrType}(&{returnVar})";
returnVar = $"new {TypePrinter.IntPtrType}(&{returnVar})";
}
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)

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

@ -13,7 +13,7 @@ namespace CppSharp.Generators.CSharp @@ -13,7 +13,7 @@ namespace CppSharp.Generators.CSharp
{
public class CSharpTypePrinter : TypePrinter
{
public const string IntPtrType = "global::System.IntPtr";
public string IntPtrType => "global::System.IntPtr";
public BindingContext Context { get; set; }

10
src/Generator/Types/Std/Stdlib.cs

@ -149,12 +149,18 @@ namespace CppSharp.Types.Std @@ -149,12 +149,18 @@ namespace CppSharp.Types.Std
return new CILType(typeof(string));
if (ctx.Parameter == null || ctx.Parameter.Name == Helpers.ReturnIdentifier)
return new CustomType(CSharpTypePrinter.IntPtrType);
{
var typePrinter = new CSharpTypePrinter(Context);
return new CustomType(typePrinter.IntPtrType);
}
if (Context.Options.Encoding == Encoding.ASCII)
return new CustomType("[MarshalAs(UnmanagedType.LPStr)] string");
if (Context.Options.Encoding == Encoding.Unicode ||
Context.Options.Encoding == Encoding.BigEndianUnicode)
return new CustomType("[MarshalAs(UnmanagedType.LPWStr)] string");
throw new System.NotSupportedException(
$"{Context.Options.Encoding.EncodingName} is not supported yet.");
}
@ -287,7 +293,7 @@ namespace CppSharp.Types.Std @@ -287,7 +293,7 @@ namespace CppSharp.Types.Std
{
ctx.Return.Write($@"{qualifiedBasicString}Extensions.{
Helpers.InternalStruct}.{assign.Name}(new {
CSharpTypePrinter.IntPtrType}(&{
typePrinter.IntPtrType}(&{
ctx.ReturnVarName}), {ctx.Parameter.Name})");
ctx.ReturnVarName = string.Empty;
}

Loading…
Cancel
Save