Browse Source

Merge 38bc0e4d7b into e093f713b9

pull/1788/merge
Stefan 2 months ago committed by GitHub
parent
commit
195187e72d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 31
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 4
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  4. 8
      src/Generator/Generators/ITypePrinter.cs
  5. 1
      src/Generator/Generators/Marshal.cs
  6. 11
      src/Generator/Generators/TypePrinter.cs
  7. 3
      src/Generator/Passes/ValidateOperatorsPass.cs

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

@ -826,10 +826,14 @@ namespace CppSharp.Generators.CSharp
Context.Parameter = new Parameter Context.Parameter = new Parameter
{ {
Name = Context.ArgName, Name = Context.ArgName,
QualifiedType = field.QualifiedType QualifiedType = field.QualifiedType,
}; };
return field.Type.Visit(this, field.QualifiedType.Qualifiers); Context.Field = field;
var ret = field.Type.Visit(this, field.QualifiedType.Qualifiers);
Context.Field = null;
return ret;
} }
public override bool VisitProperty(Property property) public override bool VisitProperty(Property property)
@ -843,7 +847,11 @@ namespace CppSharp.Generators.CSharp
QualifiedType = property.QualifiedType QualifiedType = property.QualifiedType
}; };
return base.VisitProperty(property); Context.Property = property;
var ret = base.VisitProperty(property);
Context.Property = null;
return ret;
} }
public override bool VisitEnumDecl(Enumeration @enum) public override bool VisitEnumDecl(Enumeration @enum)

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

@ -694,11 +694,12 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
private IEnumerable<string> GatherInternalParams(Function function, out TypePrinterResult retType) private IEnumerable<string> GatherInternalParams(Function function, out TypePrinterResult retType)
{ {
TypePrinter.PushContext(TypePrinterContextKind.Native); TypePrinter.PushContext(TypePrinterContextKind.Native);
retType = function.ReturnType.Visit(TypePrinter); retType = function.ReturnType.Visit(TypePrinter);
TypePrinter.Function = function;
var @params = function.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi).Select(p => var @params = function.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi).Select(p =>
$"{p.Visit(TypePrinter)} {p.Name}").ToList(); $"{p.Visit(TypePrinter)} {p.Name}").ToList();
TypePrinter.Function = null;
TypePrinter.PopContext(); TypePrinter.PopContext();
@ -1001,7 +1002,9 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
var actualProperty = GetActualProperty(property, @class); var actualProperty = GetActualProperty(property, @class);
if (actualProperty == null) if (actualProperty == null)
{ {
TypePrinter.Property = property;
WriteLine($@"throw new MissingMethodException(""Method {property.Name} missing from explicit specialization {@class.Visit(TypePrinter)}."");"); WriteLine($@"throw new MissingMethodException(""Method {property.Name} missing from explicit specialization {@class.Visit(TypePrinter)}."");");
TypePrinter.Property = null;
return false; return false;
} }
property = actualProperty; property = actualProperty;
@ -1048,7 +1051,8 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
{ {
Parameter = param, Parameter = param,
ArgName = param.Name, ArgName = param.Name,
ReturnVarName = returnVar ReturnVarName = returnVar,
Field = field,
}; };
ctx.PushMarshalKind(MarshalKind.NativeField); ctx.PushMarshalKind(MarshalKind.NativeField);
@ -1147,7 +1151,8 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
ParameterIndex = function.Parameters.Count( ParameterIndex = function.Parameters.Count(
p => p.Kind != ParameterKind.IndirectReturnType), p => p.Kind != ParameterKind.IndirectReturnType),
ReturnType = new QualifiedType(type), ReturnType = new QualifiedType(type),
ArgName = "value" ArgName = "value",
Function = function,
}; };
var marshal = new CSharpMarshalManagedToNativePrinter(ctx); var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
type.Visit(marshal); type.Visit(marshal);
@ -1287,7 +1292,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
var ctx = new CSharpMarshalContext(Context, CurrentIndentation) var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{ {
ArgName = var.Name, ArgName = var.Name,
ReturnType = var.QualifiedType ReturnType = var.QualifiedType,
}; };
ctx.PushMarshalKind(MarshalKind.ReturnVariableArray); ctx.PushMarshalKind(MarshalKind.ReturnVariableArray);
@ -1338,7 +1343,9 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
var actualProperty = GetActualProperty(property, @class); var actualProperty = GetActualProperty(property, @class);
if (actualProperty == null) if (actualProperty == null)
{ {
TypePrinter.Property = property;
WriteLine($@"throw new MissingMethodException(""Method {property.Name} missing from explicit specialization {@class.Visit(TypePrinter)}."");"); WriteLine($@"throw new MissingMethodException(""Method {property.Name} missing from explicit specialization {@class.Visit(TypePrinter)}."");");
TypePrinter.Property = null;
return false; return false;
} }
QualifiedType type = default; QualifiedType type = default;
@ -1410,7 +1417,8 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
{ {
ArgName = field.Name, ArgName = field.Name,
ReturnVarName = returnVar, ReturnVarName = returnVar,
ReturnType = returnType ReturnType = returnType,
Field = field,
}; };
ctx.PushMarshalKind(MarshalKind.NativeField); ctx.PushMarshalKind(MarshalKind.NativeField);
@ -1555,7 +1563,9 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
} }
GenerateDeclarationCommon(prop); GenerateDeclarationCommon(prop);
TypePrinter.Property = prop;
var printedType = prop.Type.Visit(TypePrinter); var printedType = prop.Type.Visit(TypePrinter);
TypePrinter.Property = null;
if (prop.ExplicitInterfaceImpl == null) if (prop.ExplicitInterfaceImpl == null)
{ {
Write(Helpers.GetAccess(prop.Access)); Write(Helpers.GetAccess(prop.Access));
@ -1931,7 +1941,8 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
ReturnType = param.QualifiedType, ReturnType = param.QualifiedType,
ReturnVarName = param.Name, ReturnVarName = param.Name,
ParameterIndex = i, ParameterIndex = i,
Parameter = param Parameter = param,
Function = method,
}; };
ctx.PushMarshalKind(MarshalKind.GenericDelegate); ctx.PushMarshalKind(MarshalKind.GenericDelegate);
@ -2076,7 +2087,9 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
using (WriteBlock($"private static {retType} {vTableMethodDelegateName}Hook({string.Join(", ", @params)})")) using (WriteBlock($"private static {retType} {vTableMethodDelegateName}Hook({string.Join(", ", @params)})"))
{ {
TypePrinter.Function = method;
WriteLine($@"var {Helpers.TargetIdentifier} = {@class.Visit(TypePrinter)}.__GetInstance({Helpers.InstanceField});"); WriteLine($@"var {Helpers.TargetIdentifier} = {@class.Visit(TypePrinter)}.__GetInstance({Helpers.InstanceField});");
TypePrinter.Function = null;
GenerateVTableManagedCall(method); GenerateVTableManagedCall(method);
} }
@ -2772,12 +2785,16 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
m => m.InstantiatedFrom == (method.OriginalFunction ?? method)); m => m.InstantiatedFrom == (method.OriginalFunction ?? method));
if (specializedMethod == null) if (specializedMethod == null)
{ {
TypePrinter.Function = method;
WriteLine($@"throw new MissingMethodException(""Method {method.Name} missing from explicit specialization {@class.Visit(TypePrinter)}."");"); WriteLine($@"throw new MissingMethodException(""Method {method.Name} missing from explicit specialization {@class.Visit(TypePrinter)}."");");
TypePrinter.Function = null;
return false; return false;
} }
if (specializedMethod.Ignore) if (specializedMethod.Ignore)
{ {
TypePrinter.Function = method;
WriteLine($@"throw new MissingMethodException(""Method {method.Name} ignored in specialization {@class.Visit(TypePrinter)}."");"); WriteLine($@"throw new MissingMethodException(""Method {method.Name} ignored in specialization {@class.Visit(TypePrinter)}."");");
TypePrinter.Function = null;
return false; return false;
} }
@ -2987,6 +3004,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
parameter.Type.IsPrimitiveTypeConvertibleToRef() ? parameter.Type.IsPrimitiveTypeConvertibleToRef() ?
"ref *" : string.Empty, "ref *" : string.Empty,
parameter.Name); parameter.Name);
TypePrinter.Function = method;
var printedType = method.ConversionType.Visit(TypePrinter); var printedType = method.ConversionType.Visit(TypePrinter);
if (@interface != null) if (@interface != null)
{ {
@ -2995,6 +3013,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
} }
else else
WriteLine($"return new {printedType}({paramName});"); WriteLine($"return new {printedType}({paramName});");
TypePrinter.Function = null;
} }
else else
{ {

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

@ -267,7 +267,7 @@ namespace CppSharp.Generators.CSharp
Kind = ContextKind, Kind = ContextKind,
MarshalKind = MarshalKind, MarshalKind = MarshalKind,
Type = typedef, Type = typedef,
Parameter = Parameter Parameter = Parameter,
}; };
return typeMap.SignatureType(typePrinterContext).ToString(); return typeMap.SignatureType(typePrinterContext).ToString();
@ -698,7 +698,9 @@ $"[{Context.TargetInfo.LongDoubleWidth}]");
public override TypePrinterResult VisitFieldDecl(Field field) public override TypePrinterResult VisitFieldDecl(Field field)
{ {
PushMarshalKind(MarshalKind.NativeField); PushMarshalKind(MarshalKind.NativeField);
Field = field;
var fieldTypePrinted = field.QualifiedType.Visit(this); var fieldTypePrinted = field.QualifiedType.Visit(this);
Field = null;
PopMarshalKind(); PopMarshalKind();
var returnTypePrinter = new TypePrinterResult(); var returnTypePrinter = new TypePrinterResult();

8
src/Generator/Generators/ITypePrinter.cs

@ -36,6 +36,14 @@ namespace CppSharp.AST
public MarshalKind MarshalKind; public MarshalKind MarshalKind;
public Declaration Declaration; public Declaration Declaration;
public Parameter Parameter; public Parameter Parameter;
public Property Property;
private Field field;
public Field Field
{
get => field ?? Property.Field;
set => field = value;
}
public Method Method;
public Type Type; public Type Type;
public TypePrinterContext() : this(TypePrinterContextKind.Normal) public TypePrinterContext() : this(TypePrinterContextKind.Normal)

1
src/Generator/Generators/Marshal.cs

@ -29,7 +29,6 @@ namespace CppSharp.Generators
public string ArgName { get; set; } public string ArgName { get; set; }
public int ParameterIndex { get; set; } public int ParameterIndex { get; set; }
public Function Function { get; set; }
public uint Indentation { get; } public uint Indentation { get; }
} }

11
src/Generator/Generators/TypePrinter.cs

@ -86,6 +86,17 @@ namespace CppSharp.Generators
public Parameter Parameter; public Parameter Parameter;
private Field field;
public Field Field
{
get => field ?? Property.Field;
set => field = value;
}
public Property Property;
public Function Function;
#region Dummy implementations #region Dummy implementations
public virtual string ToString(CppSharp.AST.Type type) public virtual string ToString(CppSharp.AST.Type type)

3
src/Generator/Passes/ValidateOperatorsPass.cs

@ -96,7 +96,8 @@ namespace CppSharp.Passes
new TypePrinterContext new TypePrinterContext
{ {
Parameter = parameter, Parameter = parameter,
Type = type Type = type,
Method = @operator,
}); });
var cilType = mappedTo as CILType; var cilType = mappedTo as CILType;
if (cilType?.Type == typeof(int)) if (cilType?.Type == typeof(int))

Loading…
Cancel
Save