Browse Source

Overhaul type printer and marshal contexts design and implementation.

The goal is to simplify the design and get rid of useless type printer contexts inside type printers.
pull/829/head
Joao Matos 9 years ago
parent
commit
38cb8e1dbe
  1. 29
      src/AST/ITypePrinter.cs
  2. 16
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  3. 28
      src/Generator/Generators/CSharp/CSharpSources.cs
  4. 103
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  5. 15
      src/Generator/Generators/Marshal.cs
  6. 40
      src/Generator/Generators/TypePrinter.cs
  7. 3
      src/Generator/Passes/GenerateSymbolsPass.cs
  8. 25
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  9. 20
      src/Generator/Types/Std/Stdlib.cs
  10. 4
      src/Generator/Types/TypeMap.cs
  11. 14
      tests/CSharp/CSharp.cs
  12. 4
      tests/Common/Common.cs

29
src/AST/ITypePrinter.cs

@ -12,16 +12,32 @@ namespace CppSharp.AST @@ -12,16 +12,32 @@ namespace CppSharp.AST
Managed
}
public abstract class TypePrinterContext
public enum MarshalKind
{
protected TypePrinterContext()
Unknown,
NativeField,
GenericDelegate,
DefaultExpression,
VTableReturnValue,
Variable
}
public class TypePrinterContext
{
public TypePrinterContextKind Kind;
public MarshalKind MarshalKind;
public Declaration Declaration;
public Parameter Parameter;
public Type Type;
public TypePrinterContext() : this(TypePrinterContextKind.Normal)
{
Kind = TypePrinterContextKind.Normal;
}
protected TypePrinterContext(TypePrinterContextKind kind)
public TypePrinterContext(TypePrinterContextKind kind)
{
Kind = kind;
MarshalKind = MarshalKind.Unknown;
}
public string GetTemplateParameterList()
@ -58,11 +74,6 @@ namespace CppSharp.AST @@ -58,11 +74,6 @@ namespace CppSharp.AST
return string.Join(", ", paramsList);
}
public TypePrinterContextKind Kind;
public Declaration Declaration;
public Parameter Parameter;
public Type Type;
}
public interface ITypePrinter

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

@ -13,14 +13,10 @@ namespace CppSharp.Generators.CSharp @@ -13,14 +13,10 @@ namespace CppSharp.Generators.CSharp
public CSharpMarshalContext(BindingContext context)
: base(context)
{
Kind = MarshalKind.Unknown;
ArgumentPrefix = new TextGenerator();
Cleanup = new TextGenerator();
}
public MarshalKind Kind { get; set; }
public QualifiedType FullType;
public TextGenerator ArgumentPrefix { get; private set; }
public TextGenerator Cleanup { get; private set; }
public bool HasCodeBlock { get; set; }
@ -221,7 +217,7 @@ namespace CppSharp.Generators.CSharp @@ -221,7 +217,7 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.Char16:
return false;
case PrimitiveType.Bool:
if (Context.Kind == MarshalKind.NativeField)
if (Context.MarshalKind == MarshalKind.NativeField)
{
// returned structs must be blittable and bool isn't
Context.Return.Write("{0} != 0", Context.ReturnVarName);
@ -496,7 +492,7 @@ namespace CppSharp.Generators.CSharp @@ -496,7 +492,7 @@ namespace CppSharp.Generators.CSharp
var pointee = pointer.Pointee.Desugar();
if (Context.Function != null && pointer.IsPrimitiveTypeConvertibleToRef() &&
Context.Kind != MarshalKind.VTableReturnValue)
Context.MarshalKind != MarshalKind.VTableReturnValue)
{
var refParamPtr = string.Format("__refParamPtr{0}", Context.ParameterIndex);
var templateSubstitution = pointer.Pointee as TemplateParameterSubstitutionType;
@ -602,9 +598,9 @@ namespace CppSharp.Generators.CSharp @@ -602,9 +598,9 @@ namespace CppSharp.Generators.CSharp
Context.Return.Write(string.Format("({0}) ", pointer.Visit(typePrinter)));
typePrinter.PopContext();
}
if (marshalAsString && (Context.Kind == MarshalKind.NativeField ||
Context.Kind == MarshalKind.VTableReturnValue ||
Context.Kind == MarshalKind.Variable))
if (marshalAsString && (Context.MarshalKind == MarshalKind.NativeField ||
Context.MarshalKind == MarshalKind.VTableReturnValue ||
Context.MarshalKind == MarshalKind.Variable))
Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
else
Context.Return.Write(Context.Parameter.Name);
@ -649,7 +645,7 @@ namespace CppSharp.Generators.CSharp @@ -649,7 +645,7 @@ namespace CppSharp.Generators.CSharp
case PrimitiveType.Char16:
return false;
case PrimitiveType.Bool:
if (Context.Kind == MarshalKind.NativeField)
if (Context.MarshalKind == MarshalKind.NativeField)
{
// returned structs must be blittable and bool isn't
Context.Return.Write("(byte) ({0} ? 1 : 0)", Context.Parameter.Name);

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@ -766,10 +766,9 @@ namespace CppSharp.Generators.CSharp @@ -766,10 +766,9 @@ namespace CppSharp.Generators.CSharp
{
Parameter = param,
ArgName = param.Name,
ReturnType = new QualifiedType(var.Type)
};
ctx.Kind = MarshalKind.Variable;
ctx.ReturnType = new QualifiedType(var.Type);
ctx.PushMarshalKind(MarshalKind.Variable);
var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
decl.CSharpMarshalToNative(marshal);
@ -829,7 +828,8 @@ namespace CppSharp.Generators.CSharp @@ -829,7 +828,8 @@ namespace CppSharp.Generators.CSharp
Parameter = param,
ArgName = param.Name,
};
ctx.Kind = MarshalKind.NativeField;
ctx.PushMarshalKind(MarshalKind.NativeField);
var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
ctx.Declaration = field;
@ -1067,7 +1067,6 @@ namespace CppSharp.Generators.CSharp @@ -1067,7 +1067,6 @@ namespace CppSharp.Generators.CSharp
TypePrinter.PushContext(TypePrinterContextKind.Native);
var ctx = new CSharpMarshalContext(Context)
{
Kind = MarshalKind.NativeField,
ArgName = field.Name,
Declaration = field,
ReturnVarName = $@"{(@class.IsValueType ? Helpers.InstanceField :
@ -1075,6 +1074,8 @@ namespace CppSharp.Generators.CSharp @@ -1075,6 +1074,8 @@ namespace CppSharp.Generators.CSharp
(@class.IsValueType ? "." : "->")}{SafeIdentifier(name)}",
ReturnType = field.QualifiedType
};
ctx.PushMarshalKind(MarshalKind.NativeField);
TypePrinter.PopContext();
var arrayType = field.Type as ArrayType;
@ -1586,8 +1587,8 @@ namespace CppSharp.Generators.CSharp @@ -1586,8 +1587,8 @@ namespace CppSharp.Generators.CSharp
ArgName = Helpers.ReturnIdentifier,
Parameter = param,
Function = method,
Kind = MarshalKind.VTableReturnValue
};
ctx.PushMarshalKind(MarshalKind.VTableReturnValue);
var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
method.OriginalReturnType.Visit(marshal);
@ -2611,12 +2612,15 @@ namespace CppSharp.Generators.CSharp @@ -2611,12 +2612,15 @@ namespace CppSharp.Generators.CSharp
else
{
if (string.IsNullOrWhiteSpace(construct))
WriteLine("{0} {1};",
typeMap.CSharpSignature(new CSharpTypePrinterContext
{
Type = indirectRetType.Type.Desugar()
}),
{
var typePrinterContext = new TypePrinterContext
{
Type = indirectRetType.Type.Desugar()
};
WriteLine("{0} {1};", typeMap.CSharpSignature(typePrinterContext),
Helpers.ReturnIdentifier);
}
else
WriteLine("var {0} = {1};", construct);
}

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

@ -10,26 +10,10 @@ using System.Text; @@ -10,26 +10,10 @@ using System.Text;
namespace CppSharp.Generators.CSharp
{
public class CSharpTypePrinterContext : TypePrinterContext
{
public TypePrinterContextKind CSharpKind;
public MarshalKind MarshalKind;
public QualifiedType FullType;
}
public class CSharpTypePrinter : TypePrinter
{
public const string IntPtrType = "global::System.IntPtr";
private readonly Stack<TypePrinterContextKind> contexts;
private readonly Stack<MarshalKind> marshalKinds;
public TypePrinterContextKind ContextKind => contexts.Peek();
public MarshalKind MarshalKind => marshalKinds.Peek();
public CSharpTypePrinterContext TypePrinterContext;
public BindingContext Context { get; set; }
public DriverOptions Options => Context.Options;
@ -38,28 +22,8 @@ namespace CppSharp.Generators.CSharp @@ -38,28 +22,8 @@ namespace CppSharp.Generators.CSharp
public CSharpTypePrinter(BindingContext context)
{
Context = context;
contexts = new Stack<TypePrinterContextKind>();
marshalKinds = new Stack<MarshalKind>();
PushContext(TypePrinterContextKind.Managed);
PushMarshalKind(MarshalKind.Unknown);
TypePrinterContext = new CSharpTypePrinterContext();
}
public void PushContext(TypePrinterContextKind contextKind)
{
contexts.Push(contextKind);
}
public TypePrinterContextKind PopContext() => contexts.Pop();
public void PushMarshalKind(MarshalKind marshalKind)
{
marshalKinds.Push(marshalKind);
}
public MarshalKind PopMarshalKind() => marshalKinds.Pop();
public override TypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals)
{
if (tag.Declaration == null)
@ -69,11 +33,15 @@ namespace CppSharp.Generators.CSharp @@ -69,11 +33,15 @@ namespace CppSharp.Generators.CSharp
if (TypeMapDatabase.FindTypeMap(tag.Declaration, out typeMap))
{
typeMap.Type = tag;
TypePrinterContext.CSharpKind = ContextKind;
TypePrinterContext.MarshalKind = MarshalKind;
TypePrinterContext.Type = tag;
string type = typeMap.CSharpSignature(TypePrinterContext);
var typePrinterContext = new TypePrinterContext()
{
Kind = Kind,
MarshalKind = MarshalKind,
Type = tag
};
string type = typeMap.CSharpSignature(typePrinterContext);
if (!string.IsNullOrEmpty(type))
{
return new TypePrinterResult
@ -106,7 +74,7 @@ namespace CppSharp.Generators.CSharp @@ -106,7 +74,7 @@ namespace CppSharp.Generators.CSharp
return string.Format("{0}", array.Type.Visit(this, quals));
}
if (TypePrinterContext.Parameter != null)
if (Parameter != null)
return string.Format("global::System.IntPtr");
Enumeration @enum;
@ -243,7 +211,7 @@ namespace CppSharp.Generators.CSharp @@ -243,7 +211,7 @@ namespace CppSharp.Generators.CSharp
{
if (isManagedContext || MarshalKind == MarshalKind.GenericDelegate)
return "string";
if (TypePrinterContext.Parameter == null || TypePrinterContext.Parameter.Name == Helpers.ReturnIdentifier)
if (Parameter == null || Parameter.Name == Helpers.ReturnIdentifier)
return IntPtrType;
if (Options.Encoding == Encoding.ASCII)
return string.Format("[MarshalAs(UnmanagedType.LPStr)] string");
@ -267,8 +235,7 @@ namespace CppSharp.Generators.CSharp @@ -267,8 +235,7 @@ namespace CppSharp.Generators.CSharp
if (finalPointee.IsPrimitiveType())
{
// Skip one indirection if passed by reference
var param = TypePrinterContext.Parameter;
bool isRefParam = param != null && (param.IsOut || param.IsInOut);
bool isRefParam = Parameter != null && (Parameter.IsOut || Parameter.IsInOut);
if (isManagedContext && isRefParam)
return pointer.QualifiedPointee.Visit(this);
@ -291,8 +258,7 @@ namespace CppSharp.Generators.CSharp @@ -291,8 +258,7 @@ namespace CppSharp.Generators.CSharp
if (desugared.TryGetEnum(out @enum))
{
// Skip one indirection if passed by reference
var param = TypePrinterContext.Parameter;
if (isManagedContext && param != null && (param.IsOut || param.IsInOut)
if (isManagedContext && Parameter != null && (Parameter.IsOut || Parameter.IsInOut)
&& pointee == finalPointee)
return pointer.QualifiedPointee.Visit(this);
@ -301,7 +267,7 @@ namespace CppSharp.Generators.CSharp @@ -301,7 +267,7 @@ namespace CppSharp.Generators.CSharp
Class @class;
if ((desugared.IsDependent || desugared.TryGetClass(out @class) ||
(desugared is ArrayType && TypePrinterContext.Parameter != null))
(desugared is ArrayType && Parameter != null))
&& ContextKind == TypePrinterContextKind.Native)
{
return IntPtrType;
@ -337,11 +303,15 @@ namespace CppSharp.Generators.CSharp @@ -337,11 +303,15 @@ namespace CppSharp.Generators.CSharp
if (TypeMapDatabase.FindTypeMap(decl, out typeMap))
{
typeMap.Type = typedef;
TypePrinterContext.CSharpKind = ContextKind;
TypePrinterContext.MarshalKind = MarshalKind;
TypePrinterContext.Type = typedef;
string type = typeMap.CSharpSignature(TypePrinterContext);
var typePrinterContext = new TypePrinterContext
{
Kind = ContextKind,
MarshalKind = MarshalKind,
Type = typedef
};
string type = typeMap.CSharpSignature(typePrinterContext);
if (!string.IsNullOrEmpty(type))
{
return new TypePrinterResult
@ -388,11 +358,15 @@ namespace CppSharp.Generators.CSharp @@ -388,11 +358,15 @@ namespace CppSharp.Generators.CSharp
typeMap.Declaration = decl;
typeMap.Type = template;
TypePrinterContext.Type = template;
TypePrinterContext.CSharpKind = ContextKind;
TypePrinterContext.MarshalKind = MarshalKind;
var type = GetCSharpSignature(typeMap);
var typePrinterContext = new TypePrinterContext
{
Type = template,
Kind = ContextKind,
MarshalKind = MarshalKind
};
var type = typeMap.CSharpSignature(typePrinterContext);
if (!string.IsNullOrEmpty(type))
{
return new TypePrinterResult
@ -413,13 +387,6 @@ namespace CppSharp.Generators.CSharp @@ -413,13 +387,6 @@ namespace CppSharp.Generators.CSharp
return string.Empty;
}
private string GetCSharpSignature(TypeMap typeMap)
{
TypePrinterContext.CSharpKind = ContextKind;
TypePrinterContext.MarshalKind = MarshalKind;
return typeMap.CSharpSignature(TypePrinterContext);
}
public override TypePrinterResult VisitTemplateParameterType(
TemplateParameterType param, TypeQualifiers quals)
{
@ -612,9 +579,9 @@ namespace CppSharp.Generators.CSharp @@ -612,9 +579,9 @@ namespace CppSharp.Generators.CSharp
if (parameter.Kind == ParameterKind.IndirectReturnType)
return IntPtrType;
TypePrinterContext.Parameter = parameter;
Parameter = parameter;
var ret = paramType.Visit(this);
TypePrinterContext.Parameter = null;
Parameter = null;
return ret;
}
@ -698,11 +665,11 @@ namespace CppSharp.Generators.CSharp @@ -698,11 +665,11 @@ namespace CppSharp.Generators.CSharp
p => ContextKind == TypePrinterContextKind.Native ||
(p.Kind != ParameterKind.IndirectReturnType && !p.Ignore)))
{
TypePrinterContext.Parameter = param;
Parameter = param;
args.Add(VisitParameter(param, hasNames).Type);
}
TypePrinterContext.Parameter = null;
Parameter = null;
return string.Join(", ", args);
}
@ -782,7 +749,7 @@ namespace CppSharp.Generators.CSharp @@ -782,7 +749,7 @@ namespace CppSharp.Generators.CSharp
public static TypePrinterResult CSharpType(this QualifiedType type,
CSharpTypePrinter printer)
{
printer.TypePrinterContext.FullType = type;
printer.FullType = type;
return type.Visit(printer);
}
@ -798,7 +765,7 @@ namespace CppSharp.Generators.CSharp @@ -798,7 +765,7 @@ namespace CppSharp.Generators.CSharp
if (decl is ITypedDecl)
{
var type = (decl as ITypedDecl).QualifiedType;
printer.TypePrinterContext.FullType = type;
printer.FullType = type;
}
return decl.Visit(printer);

15
src/Generator/Generators/Marshal.cs

@ -2,17 +2,7 @@ @@ -2,17 +2,7 @@
namespace CppSharp.Generators
{
public enum MarshalKind
{
Unknown,
NativeField,
GenericDelegate,
DefaultExpression,
VTableReturnValue,
Variable
}
public class MarshalContext
public class MarshalContext : TypePrinter
{
public MarshalContext(BindingContext context)
{
@ -29,13 +19,10 @@ namespace CppSharp.Generators @@ -29,13 +19,10 @@ namespace CppSharp.Generators
public TextGenerator SupportBefore { get; private set; }
public TextGenerator Return { get; private set; }
public Declaration Declaration { get; set; }
public string ReturnVarName { get; set; }
public QualifiedType ReturnType { get; set; }
public string ArgName { get; set; }
public Parameter Parameter { get; set; }
public int ParameterIndex { get; set; }
public Function Function { get; set; }

40
src/Generator/Generators/TypePrinter.cs

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
using CppSharp.AST;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Types;
using System;
using System.Collections.Generic;
using System.Linq;
namespace CppSharp.Generators
{
@ -22,6 +24,42 @@ namespace CppSharp.Generators @@ -22,6 +24,42 @@ namespace CppSharp.Generators
public class TypePrinter : ITypePrinter<TypePrinterResult>,
IDeclVisitor<TypePrinterResult>
{
private readonly Stack<TypePrinterContextKind> contexts;
private readonly Stack<MarshalKind> marshalKinds;
public TypePrinterContextKind ContextKind => contexts.Peek();
public TypePrinterContextKind Kind => ContextKind;
public MarshalKind MarshalKind => marshalKinds.Peek();
public TypePrinter()
{
contexts = new Stack<TypePrinterContextKind>();
marshalKinds = new Stack<MarshalKind>();
PushContext(TypePrinterContextKind.Managed);
PushMarshalKind(MarshalKind.Unknown);
}
public void PushContext(TypePrinterContextKind contextKind)
{
contexts.Push(contextKind);
}
public TypePrinterContextKind PopContext() => contexts.Pop();
public void PushMarshalKind(MarshalKind marshalKind)
{
marshalKinds.Push(marshalKind);
}
public MarshalKind PopMarshalKind() => marshalKinds.Pop();
public Declaration Declaration;
public Parameter Parameter;
public CppSharp.AST.Type Type;
public QualifiedType FullType;
#region Dummy implementations
public virtual string ToString(CppSharp.AST.Type type)

3
src/Generator/Passes/GenerateSymbolsPass.cs

@ -119,7 +119,8 @@ namespace CppSharp.Passes @@ -119,7 +119,8 @@ namespace CppSharp.Passes
TypeMap typeMap;
if (Context.TypeMaps.FindTypeMap(specialization, out typeMap))
{
var mappedTo = typeMap.CSharpSignatureType(new CSharpTypePrinterContext { Type = type });
var typePrinterContext = new TypePrinterContext { Type = type };
var mappedTo = typeMap.CSharpSignatureType(typePrinterContext);
mappedTo = mappedTo.Desugar();
mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo);
if (mappedTo.IsPrimitiveType() || mappedTo.IsPointerToPrimitiveType() || mappedTo.IsEnum())

25
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -148,15 +148,24 @@ namespace CppSharp.Passes @@ -148,15 +148,24 @@ namespace CppSharp.Passes
var ctor = expression as CXXConstructExpr;
TypeMap typeMap;
var typePrinter = new CSharpTypePrinter(Context);
typePrinter.PushMarshalKind(MarshalKind.DefaultExpression);
var typePrinterResult = type.Visit(typePrinter).Type;
TypeMap typeMap;
if (TypeMaps.FindTypeMap(decl, type, out typeMap))
{
var typeInSignature = typeMap.CSharpSignatureType(
typePrinter.TypePrinterContext).SkipPointerRefs().Desugar();
var typePrinterContext = new TypePrinterContext()
{
Kind = typePrinter.Kind,
MarshalKind = typePrinter.MarshalKind,
Type = type
};
var typeInSignature = typeMap.CSharpSignatureType(typePrinterContext)
.SkipPointerRefs().Desugar();
Enumeration @enum;
if (typeInSignature.TryGetEnum(out @enum))
{
@ -259,11 +268,15 @@ namespace CppSharp.Passes @@ -259,11 +268,15 @@ namespace CppSharp.Passes
HasSingleZeroArgExpression(function)) &&
TypeMaps.FindTypeMap(desugared, out typeMap))
{
var typeInSignature = typeMap.CSharpSignatureType(new CSharpTypePrinterContext
var typePrinterContext = new TypePrinterContext
{
MarshalKind = MarshalKind.DefaultExpression,
Type = desugared
}).SkipPointerRefs().Desugar();
};
var typeInSignature = typeMap.CSharpSignatureType(typePrinterContext)
.SkipPointerRefs().Desugar();
Enumeration @enum;
if (typeInSignature.TryGetEnum(out @enum))
return "0";

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
@ -16,7 +16,7 @@ namespace CppSharp.Types.Std @@ -16,7 +16,7 @@ namespace CppSharp.Types.Std
return "va_list";
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
return "va_list";
}
@ -47,9 +47,9 @@ namespace CppSharp.Types.Std @@ -47,9 +47,9 @@ namespace CppSharp.Types.Std
ctx.ReturnVarName);
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
if (ctx.CSharpKind == TypePrinterContextKind.Managed)
if (ctx.Kind == TypePrinterContextKind.Managed)
return "string";
ClassTemplateSpecialization basicString = GetBasicString(ctx.Type);
var typePrinter = new CSharpTypePrinter(null);
@ -148,7 +148,7 @@ namespace CppSharp.Types.Std @@ -148,7 +148,7 @@ namespace CppSharp.Types.Std
ctx.ReturnVarName);
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
return "string";
}
@ -292,9 +292,9 @@ namespace CppSharp.Types.Std @@ -292,9 +292,9 @@ namespace CppSharp.Types.Std
ctx.Return.Write(tmpVarName);
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
if (ctx.CSharpKind == TypePrinterContextKind.Native)
if (ctx.Kind == TypePrinterContextKind.Native)
return "Std.Vector";
return string.Format("Std.Vector<{0}>", ctx.GetTemplateParameterList());
@ -338,9 +338,9 @@ namespace CppSharp.Types.Std @@ -338,9 +338,9 @@ namespace CppSharp.Types.Std
throw new System.NotImplementedException();
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
if (ctx.CSharpKind == TypePrinterContextKind.Native)
if (ctx.Kind == TypePrinterContextKind.Native)
return "Std.Map";
var type = Type as TemplateSpecializationType;
@ -420,7 +420,7 @@ namespace CppSharp.Types.Std @@ -420,7 +420,7 @@ namespace CppSharp.Types.Std
[TypeMap("FILE", GeneratorKind = GeneratorKind.CSharp)]
public class FILE : TypeMap
{
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
return CSharpTypePrinter.IntPtrType;
}

4
src/Generator/Types/TypeMap.cs

@ -57,12 +57,12 @@ namespace CppSharp.Types @@ -57,12 +57,12 @@ namespace CppSharp.Types
#region C# backend
public virtual Type CSharpSignatureType(CSharpTypePrinterContext ctx)
public virtual Type CSharpSignatureType(TypePrinterContext ctx)
{
return new CILType(typeof(object));
}
public virtual string CSharpSignature(CSharpTypePrinterContext ctx)
public virtual string CSharpSignature(TypePrinterContext ctx)
{
throw new NotImplementedException();
}

14
tests/CSharp/CSharp.cs

@ -76,12 +76,12 @@ namespace CppSharp.Tests @@ -76,12 +76,12 @@ namespace CppSharp.Tests
return string.Empty;
}
public override Type CSharpSignatureType(CSharpTypePrinterContext ctx)
public override Type CSharpSignatureType(TypePrinterContext ctx)
{
return GetEnumType(ctx.Type);
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
return CSharpSignatureType(ctx).ToString();
}
@ -129,12 +129,12 @@ namespace CppSharp.Tests @@ -129,12 +129,12 @@ namespace CppSharp.Tests
return string.Empty;
}
public override Type CSharpSignatureType(CSharpTypePrinterContext ctx)
public override Type CSharpSignatureType(TypePrinterContext ctx)
{
return new TagType(new Enumeration());
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
return "Flags";
}
@ -165,9 +165,9 @@ namespace CppSharp.Tests @@ -165,9 +165,9 @@ namespace CppSharp.Tests
}
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
if (ctx.CSharpKind == TypePrinterContextKind.Native)
if (ctx.Kind == TypePrinterContextKind.Native)
return string.Format("QList.{0}{1}", Helpers.InternalStruct,
Type.IsAddress() ? "*" : string.Empty);
@ -191,7 +191,7 @@ namespace CppSharp.Tests @@ -191,7 +191,7 @@ namespace CppSharp.Tests
[TypeMap("TypeMappedWithOperator")]
public class TypeMappedWithOperator : TypeMap
{
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
// doesn't matter, we just need it to compile
return "int";

4
tests/Common/Common.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Generators.CLI;
@ -27,7 +27,7 @@ namespace CppSharp.Tests @@ -27,7 +27,7 @@ namespace CppSharp.Tests
ctx.Return.Write("::TypeMappedIndex()");
}
public override string CSharpSignature(CSharpTypePrinterContext ctx)
public override string CSharpSignature(TypePrinterContext ctx)
{
return "ushort";
}

Loading…
Cancel
Save