|
|
@ -305,7 +305,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
Context.Return.Write("({0} == nullptr) ? nullptr : gcnew ", |
|
|
|
Context.Return.Write("({0} == nullptr) ? nullptr : gcnew ", |
|
|
|
instance); |
|
|
|
instance); |
|
|
|
|
|
|
|
|
|
|
|
Context.Return.Write("{0}(", QualifiedIdentifier(@class)); |
|
|
|
Context.Return.Write("::{0}(", QualifiedIdentifier(@class)); |
|
|
|
Context.Return.Write("(::{0}*)", @class.QualifiedOriginalName); |
|
|
|
Context.Return.Write("(::{0}*)", @class.QualifiedOriginalName); |
|
|
|
Context.Return.Write("{0}{1})", instance, ownNativeInstance ? ", true" : ""); |
|
|
|
Context.Return.Write("{0}{1})", instance, ownNativeInstance ? ", true" : ""); |
|
|
|
} |
|
|
|
} |
|
|
@ -433,39 +433,42 @@ namespace CppSharp.Generators.CLI |
|
|
|
case ArrayType.ArraySize.Constant: |
|
|
|
case ArrayType.ArraySize.Constant: |
|
|
|
if (string.IsNullOrEmpty(Context.ReturnVarName)) |
|
|
|
if (string.IsNullOrEmpty(Context.ReturnVarName)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const string pinnedPtr = "__pinnedPtr"; |
|
|
|
string arrayPtrRet = $"__{Context.ParameterIndex}ArrayPtr"; |
|
|
|
Context.Before.WriteLine("cli::pin_ptr<{0}> {1} = &{2}[0];", |
|
|
|
Context.Before.WriteLine($"{array.Type} {arrayPtrRet}[{array.Size}];"); |
|
|
|
array.Type, pinnedPtr, Context.Parameter.Name); |
|
|
|
|
|
|
|
const string arrayPtr = "__arrayPtr"; |
|
|
|
Context.ReturnVarName = arrayPtrRet; |
|
|
|
Context.Before.WriteLine("{0}* {1} = {2};", array.Type, arrayPtr, pinnedPtr); |
|
|
|
|
|
|
|
Context.Return.Write("({0} (&)[{1}]) {2}", array.Type, array.Size, arrayPtr); |
|
|
|
Context.Return.Write(arrayPtrRet); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
bool isPointerToPrimitive = array.Type.IsPointerToPrimitiveType(PrimitiveType.Void); |
|
|
|
|
|
|
|
bool isPrimitive = array.Type.IsPrimitiveType(); |
|
|
|
|
|
|
|
var supportBefore = Context.Before; |
|
|
|
|
|
|
|
supportBefore.WriteLine("if ({0} != nullptr)", Context.Parameter.Name); |
|
|
|
|
|
|
|
supportBefore.WriteOpenBraceAndIndent(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
supportBefore.WriteLine($"if ({Context.Parameter.Name}->Length != {array.Size})"); |
|
|
|
|
|
|
|
supportBefore.WriteOpenBraceAndIndent(); |
|
|
|
|
|
|
|
supportBefore.WriteLine($"throw gcnew System::InvalidOperationException(\"Source array size must equal destination array size.\");"); |
|
|
|
|
|
|
|
supportBefore.UnindentAndWriteCloseBrace(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string nativeVal = string.Empty; |
|
|
|
|
|
|
|
if (isPointerToPrimitive) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
nativeVal = ".ToPointer()"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (!isPrimitive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool isPointerToPrimitive = array.Type.IsPointerToPrimitiveType(PrimitiveType.Void); |
|
|
|
nativeVal = "->NativePtr"; |
|
|
|
bool isPrimitive = array.Type.IsPrimitiveType(); |
|
|
|
|
|
|
|
var supportBefore = Context.Before; |
|
|
|
|
|
|
|
supportBefore.WriteLine("if ({0} != nullptr)", Context.ArgName); |
|
|
|
|
|
|
|
supportBefore.WriteOpenBraceAndIndent(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string nativeVal = string.Empty; |
|
|
|
|
|
|
|
if (isPointerToPrimitive) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
nativeVal = ".ToPointer()"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (!isPrimitive) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
nativeVal = "->NativePtr"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
supportBefore.WriteLine("for (int i = 0; i < {0}; i++)", array.Size); |
|
|
|
|
|
|
|
supportBefore.WriteLineIndent("{0}[i] = {1}{2}[i]{3};", |
|
|
|
|
|
|
|
Context.ReturnVarName, |
|
|
|
|
|
|
|
isPointerToPrimitive || isPrimitive ? string.Empty : "*", |
|
|
|
|
|
|
|
Context.ArgName, |
|
|
|
|
|
|
|
nativeVal); |
|
|
|
|
|
|
|
supportBefore.UnindentAndWriteCloseBrace(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
supportBefore.WriteLine("for (int i = 0; i < {0}; i++)", array.Size); |
|
|
|
|
|
|
|
supportBefore.WriteLineIndent("{0}[i] = {1}{2}[i]{3};", |
|
|
|
|
|
|
|
Context.ReturnVarName, |
|
|
|
|
|
|
|
isPointerToPrimitive || isPrimitive ? string.Empty : "*", |
|
|
|
|
|
|
|
Context.Parameter.Name, |
|
|
|
|
|
|
|
nativeVal); |
|
|
|
|
|
|
|
supportBefore.UnindentAndWriteCloseBrace(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
Context.Return.Write("null"); |
|
|
|
Context.Return.Write("null"); |
|
|
@ -778,7 +781,8 @@ namespace CppSharp.Generators.CLI |
|
|
|
{ |
|
|
|
{ |
|
|
|
ArgName = fieldRef, |
|
|
|
ArgName = fieldRef, |
|
|
|
ParameterIndex = Context.ParameterIndex++, |
|
|
|
ParameterIndex = Context.ParameterIndex++, |
|
|
|
MarshalVarPrefix = Context.MarshalVarPrefix |
|
|
|
MarshalVarPrefix = Context.MarshalVarPrefix, |
|
|
|
|
|
|
|
ReturnVarName = $"{marshalVar}.{property.Field.OriginalName}" |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var marshal = new CLIMarshalManagedToNativePrinter(marshalCtx); |
|
|
|
var marshal = new CLIMarshalManagedToNativePrinter(marshalCtx); |
|
|
@ -789,23 +793,26 @@ namespace CppSharp.Generators.CLI |
|
|
|
if (!string.IsNullOrWhiteSpace(marshal.Context.Before)) |
|
|
|
if (!string.IsNullOrWhiteSpace(marshal.Context.Before)) |
|
|
|
Context.Before.Write(marshal.Context.Before); |
|
|
|
Context.Before.Write(marshal.Context.Before); |
|
|
|
|
|
|
|
|
|
|
|
Type type; |
|
|
|
if (!string.IsNullOrWhiteSpace(marshal.Context.Return)) |
|
|
|
Class @class; |
|
|
|
|
|
|
|
var isRef = property.Type.IsPointerTo(out type) && |
|
|
|
|
|
|
|
!(type.TryGetClass(out @class) && @class.IsValueType) && |
|
|
|
|
|
|
|
!type.IsPrimitiveType(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isRef) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Context.Before.WriteLine("if ({0} != nullptr)", fieldRef); |
|
|
|
Type type; |
|
|
|
Context.Before.Indent(); |
|
|
|
Class @class; |
|
|
|
} |
|
|
|
var isRef = property.Type.IsPointerTo(out type) && |
|
|
|
|
|
|
|
!(type.TryGetClass(out @class) && @class.IsValueType) && |
|
|
|
|
|
|
|
!type.IsPrimitiveType(); |
|
|
|
|
|
|
|
|
|
|
|
Context.Before.WriteLine("{0}.{1} = {2};", marshalVar, |
|
|
|
if (isRef) |
|
|
|
property.Field.OriginalName, marshal.Context.Return); |
|
|
|
{ |
|
|
|
|
|
|
|
Context.Before.WriteLine("if ({0} != nullptr)", fieldRef); |
|
|
|
|
|
|
|
Context.Before.Indent(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isRef) |
|
|
|
Context.Before.WriteLine("{0}.{1} = {2};", marshalVar, |
|
|
|
Context.Before.Unindent(); |
|
|
|
property.Field.OriginalName, marshal.Context.Return); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isRef) |
|
|
|
|
|
|
|
Context.Before.Unindent(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override bool VisitFieldDecl(Field field) |
|
|
|
public override bool VisitFieldDecl(Field field) |
|
|
|