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 @@ -826,10 +826,14 @@ namespace CppSharp.Generators.CSharp
Context.Parameter = new Parameter
{
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)
@ -843,7 +847,11 @@ namespace CppSharp.Generators.CSharp @@ -843,7 +847,11 @@ namespace CppSharp.Generators.CSharp
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)

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

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

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

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

8
src/Generator/Generators/ITypePrinter.cs

@ -36,6 +36,14 @@ namespace CppSharp.AST @@ -36,6 +36,14 @@ namespace CppSharp.AST
public MarshalKind MarshalKind;
public Declaration Declaration;
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 TypePrinterContext() : this(TypePrinterContextKind.Normal)

1
src/Generator/Generators/Marshal.cs

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

11
src/Generator/Generators/TypePrinter.cs

@ -86,6 +86,17 @@ namespace CppSharp.Generators @@ -86,6 +86,17 @@ namespace CppSharp.Generators
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
public virtual string ToString(CppSharp.AST.Type type)

3
src/Generator/Passes/ValidateOperatorsPass.cs

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

Loading…
Cancel
Save