initial nativestring and nativearray marshalling
Some checks failed
Build Android / Game (Android, Release ARM64) (push) Has been cancelled
Build iOS / Game (iOS, Release ARM64) (push) Has been cancelled
Build Linux / Editor (Linux, Development x64) (push) Has been cancelled
Build Linux / Game (Linux, Release x64) (push) Has been cancelled
Build macOS / Editor (Mac, Development ARM64) (push) Has been cancelled
Build macOS / Game (Mac, Release ARM64) (push) Has been cancelled
Build Windows / Editor (Windows, Development x64) (push) Has been cancelled
Build Windows / Game (Windows, Release x64) (push) Has been cancelled
Cooker / Cook (Mac) (push) Has been cancelled
Tests / Tests (Linux) (push) Has been cancelled
Tests / Tests (Windows) (push) Has been cancelled
Some checks failed
Build Android / Game (Android, Release ARM64) (push) Has been cancelled
Build iOS / Game (iOS, Release ARM64) (push) Has been cancelled
Build Linux / Editor (Linux, Development x64) (push) Has been cancelled
Build Linux / Game (Linux, Release x64) (push) Has been cancelled
Build macOS / Editor (Mac, Development ARM64) (push) Has been cancelled
Build macOS / Game (Mac, Release ARM64) (push) Has been cancelled
Build Windows / Editor (Windows, Development x64) (push) Has been cancelled
Build Windows / Game (Windows, Release x64) (push) Has been cancelled
Cooker / Cook (Mac) (push) Has been cancelled
Tests / Tests (Linux) (push) Has been cancelled
Tests / Tests (Windows) (push) Has been cancelled
This commit is contained in:
@@ -166,13 +166,20 @@ namespace Flax.Build.Bindings
|
||||
if (typeInfo.IsPtr)
|
||||
return false;
|
||||
|
||||
#if USE_NETCORE
|
||||
//if (typeInfo.IsString)
|
||||
// return true;
|
||||
if (typeInfo.Type == "String" || typeInfo.Type == "StringView")
|
||||
return false;//true;
|
||||
if (typeInfo.Type == "StringAnsi" || typeInfo.Type == "StringAnsiView")
|
||||
return false;
|
||||
//if (typeInfo.IsString)
|
||||
// return false;
|
||||
#else
|
||||
// Skip for strings
|
||||
if ((typeInfo.Type == "String" || typeInfo.Type == "StringView" || typeInfo.Type == "StringAnsi" || typeInfo.Type == "StringAnsiView") && typeInfo.GenericArgs == null)
|
||||
return false;
|
||||
|
||||
// Skip for collections
|
||||
if ((typeInfo.Type == "Array" || typeInfo.Type == "Span" || typeInfo.Type == "DataContainer" || typeInfo.Type == "Dictionary" || typeInfo.Type == "HashSet") && typeInfo.GenericArgs != null)
|
||||
if (typeInfo.IsString)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
// Skip for special types
|
||||
if (typeInfo.GenericArgs == null)
|
||||
@@ -192,6 +199,10 @@ namespace Flax.Build.Bindings
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip for collections
|
||||
if ((typeInfo.IsArrayOrSpan || typeInfo.Type == "Dictionary" || typeInfo.Type == "HashSet") && typeInfo.GenericArgs != null)
|
||||
return false;
|
||||
|
||||
// Find API type info
|
||||
var apiType = FindApiTypeInfo(buildData, typeInfo, caller);
|
||||
if (apiType != null)
|
||||
@@ -213,7 +224,7 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
|
||||
// True for references
|
||||
if (typeInfo.IsRef)
|
||||
if (typeInfo.IsRef && !typeInfo.IsConst)
|
||||
return true;
|
||||
|
||||
// Force for in-build types
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
//#define AUTO_DOC_TOOLTIPS
|
||||
//#define MARSHALLER_FULL_NAME
|
||||
|
||||
#pragma warning disable CS1717
|
||||
#pragma warning disable CS0162
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -592,13 +595,17 @@ namespace Flax.Build.Bindings
|
||||
|
||||
private static void GenerateCSharpWrapperFunction(BuildData buildData, StringBuilder contents, string indent, ApiTypeInfo caller, FunctionInfo functionInfo)
|
||||
{
|
||||
if (functionInfo.Glue.LibraryEntryPoint == "FlaxEngine.Engine::Internal_GetCommandLine")
|
||||
indent = indent;
|
||||
string returnValueType;
|
||||
if (UsePassByReference(buildData, functionInfo.ReturnType, caller))
|
||||
if (!functionInfo.ReturnType.IsString && UsePassByReference(buildData, functionInfo.ReturnType, caller))
|
||||
{
|
||||
returnValueType = "void";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (functionInfo.ReturnType.IsString && functionInfo.ReturnType.IsRef)
|
||||
indent = indent;
|
||||
var apiType = FindApiTypeInfo(buildData, functionInfo.ReturnType, caller);
|
||||
if (apiType != null && apiType.MarshalAs != null)
|
||||
returnValueType = GenerateCSharpNativeToManaged(buildData, apiType.MarshalAs, caller, true);
|
||||
@@ -690,15 +697,33 @@ namespace Flax.Build.Bindings
|
||||
//Log.Warning($"unknown type: '{parameterInfo.Type.GenericArgs[0].Type}'");
|
||||
break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(unmanagedType))
|
||||
/*if (!string.IsNullOrEmpty(unmanagedType))
|
||||
{
|
||||
string arraySubType = "";
|
||||
if (unmanagedType != "Any")
|
||||
arraySubType = $"ArraySubType = UnmanagedType.{unmanagedType}, ";
|
||||
returnMarshalType = $"MarshalAs(UnmanagedType.LPArray, {arraySubType}SizeParamIndex = {(!functionInfo.IsStatic ? 1 : 0) + functionInfo.Parameters.Count + (functionInfo.Glue.CustomParameters.FindIndex(x => x.Name == $"__returnCount"))})";
|
||||
}*/
|
||||
if (!string.IsNullOrEmpty(unmanagedType))
|
||||
{
|
||||
returnMarshalType = "/*marshahh1*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<,>), CountElementName = nameof(__returnCount))";
|
||||
}
|
||||
else if (genericType == "String" || genericType == "StringView")
|
||||
{
|
||||
returnMarshalType = $"/*marsh2c*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<string, NativeString>), CountElementName = \"__returnCount\")";
|
||||
if (genericType == "StringView")
|
||||
returnMarshalType += $"] [return: MarshalUsing(typeof(FlaxEngine.Interop.StringViewMarshaller), ElementIndirectionDepth = 1)";
|
||||
}
|
||||
else if (genericType == "StringAnsi")
|
||||
{
|
||||
returnMarshalType = $"/*marsh2d*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<string, NativeStringAnsi>), CountElementName = \"__returnCount\")";
|
||||
returnMarshalType += $"] [return: MarshalUsing(typeof(FlaxEngine.Interop.StringAnsiMarshaller), ElementIndirectionDepth = 1)";
|
||||
}
|
||||
else if (genericType == "StringAnsiView")
|
||||
{
|
||||
returnMarshalType = $"/*marsh2d*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<string, NativeStringAnsi>), CountElementName = \"__returnCount\")";
|
||||
returnMarshalType += $"] [return: MarshalUsing(typeof(FlaxEngine.Interop.StringAnsiViewMarshaller), ElementIndirectionDepth = 1)";
|
||||
}
|
||||
else if (genericType == "String" || genericType == "StringAnsi" || genericType == "StringView")
|
||||
returnMarshalType = $"/*marsh2c*/MarshalUsing(typeof(FlaxEngine.Interop.BoxedArrayMarshaller<string, IntPtr>), CountElementName = \"__returnCount\")";
|
||||
else if (elementApiType?.IsValueType ?? true)
|
||||
returnMarshalType = $"/*marsh2a*/MarshalUsing(typeof(FlaxEngine.Interop.BoxedArrayMarshaller<,>), CountElementName = \"__returnCount\")";
|
||||
else
|
||||
@@ -718,6 +743,12 @@ namespace Flax.Build.Bindings
|
||||
// Boolean arrays does not support custom marshalling for some unknown reason
|
||||
returnMarshalType = $"MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = {functionInfo.Parameters.Count + (functionInfo.Glue.CustomParameters?.Count ?? 0)})";
|
||||
}
|
||||
else if (functionInfo.ReturnType.Type == "StringView")
|
||||
returnMarshalType = $"MarshalUsing(typeof(FlaxEngine.Interop.StringViewMarshaller))";
|
||||
else if (functionInfo.ReturnType.Type == "StringAnsi")
|
||||
returnMarshalType = $"MarshalUsing(typeof(FlaxEngine.Interop.StringAnsiMarshaller))";
|
||||
else if (functionInfo.ReturnType.Type == "StringAnsiView")
|
||||
returnMarshalType = $"MarshalUsing(typeof(FlaxEngine.Interop.StringAnsiViewMarshaller))";
|
||||
#endif
|
||||
#if !USE_NETCORE
|
||||
contents.AppendLine().Append(indent).Append("[MethodImpl(MethodImplOptions.InternalCall)]");
|
||||
@@ -824,13 +855,32 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
if (!string.IsNullOrEmpty(unmanagedType))
|
||||
{
|
||||
string arraySubType = "";
|
||||
/*string arraySubType = "";
|
||||
if (unmanagedType != "Any")
|
||||
arraySubType = $"ArraySubType = UnmanagedType.{unmanagedType}, ";
|
||||
parameterMarshalType = $"MarshalAs(UnmanagedType.LPArray, {arraySubType}SizeParamIndex = {(!functionInfo.IsStatic ? 1 : 0) + functionInfo.Parameters.Count + (functionInfo.Glue.CustomParameters.FindIndex(x => x.Name == $"__{parameterInfo.Name}Count"))})";
|
||||
*/
|
||||
parameterMarshalType = $"/*marshaaafa1a*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<,>), CountElementName = \"__{parameterInfo.Name}Count\")";
|
||||
if (genericType == "bool")
|
||||
parameterMarshalType += $", MarshalUsing(typeof(FlaxEngine.Interop.BooleanMarshaller), ElementIndirectionDepth = 1)";
|
||||
}
|
||||
else if (genericType == "String" || genericType == "StringView")
|
||||
{
|
||||
parameterMarshalType = $"/*marsh5c*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<string, NativeString>), CountElementName = \"__{parameterInfo.Name}Count\")";
|
||||
if (genericType == "StringView")
|
||||
parameterMarshalType += $", MarshalUsing(typeof(FlaxEngine.Interop.StringViewMarshaller), ElementIndirectionDepth = 1)";
|
||||
}
|
||||
else if (genericType == "StringAnsi")
|
||||
{
|
||||
parameterMarshalType = $"/*marsh5d*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<string, NativeStringAnsi>), CountElementName = \"__{parameterInfo.Name}Count\")";
|
||||
//if ((!parameterInfo.IsOut && !parameterInfo.IsRef))
|
||||
parameterMarshalType += $", MarshalUsing(typeof(FlaxEngine.Interop.StringAnsiMarshaller), ElementIndirectionDepth = 1)";
|
||||
}
|
||||
else if (genericType == "StringAnsiView")
|
||||
{
|
||||
parameterMarshalType = $"/*marsh5d*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<string, NativeStringAnsi>), CountElementName = \"__{parameterInfo.Name}Count\")";
|
||||
parameterMarshalType += $", MarshalUsing(typeof(FlaxEngine.Interop.StringAnsiViewMarshaller), ElementIndirectionDepth = 1)";
|
||||
}
|
||||
else if (genericType == "String" || genericType == "StringAnsi" || genericType == "StringView")
|
||||
parameterMarshalType = $"/*marsh5c*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<string, IntPtr>), CountElementName = \"__{parameterInfo.Name}Count\")";
|
||||
else if (elementApiType.IsValueType)
|
||||
{
|
||||
var nativeName = parameterInfo.Type.GetFullNameNative(buildData, caller);
|
||||
@@ -862,6 +912,12 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
parameterMarshalType = $"/*marsh6*/MarshalUsing(typeof(FlaxEngine.Interop.NativeArrayMarshaller<,>))";
|
||||
}
|
||||
else if (parameterInfo.Type.Type == "StringView")
|
||||
parameterMarshalType = $"MarshalUsing(typeof(FlaxEngine.Interop.StringViewMarshaller))";
|
||||
else if (parameterInfo.Type.Type == "StringAnsi")
|
||||
parameterMarshalType = $"MarshalUsing(typeof(FlaxEngine.Interop.StringAnsiMarshaller))";
|
||||
else if (parameterInfo.Type.Type == "StringAnsiView")
|
||||
parameterMarshalType = $"MarshalUsing(typeof(FlaxEngine.Interop.StringAnsiViewMarshaller))";
|
||||
|
||||
if (!string.IsNullOrEmpty(parameterMarshalType))
|
||||
contents.Append($"[{parameterMarshalType}] ");
|
||||
@@ -1885,7 +1941,7 @@ namespace Flax.Build.Bindings
|
||||
else if (marshalType.Type == "Version")
|
||||
type = "IntPtr";
|
||||
else if (type == "string")
|
||||
type = "IntPtr";
|
||||
type = "NativeString";
|
||||
else if (type == "bool")
|
||||
type = "byte";
|
||||
else if (marshalType.Type == "Variant")
|
||||
@@ -1982,10 +2038,10 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
else if (originalType == "string")
|
||||
{
|
||||
toManagedContent.AppendLine($"ManagedString.ToManaged(unmanaged.{fieldInfo.Name});");
|
||||
toNativeContent.AppendLine($"ManagedString.ToNative(managed.{fieldInfo.Name});");
|
||||
freeContents.AppendLine($"ManagedString.Free(unmanaged.{fieldInfo.Name});");
|
||||
freeContents2.AppendLine($"ManagedString.Free(unmanaged.{fieldInfo.Name});");
|
||||
toManagedContent.AppendLine($"{unmanagedField}.ToString();");
|
||||
toNativeContent.AppendLine($"new NativeString({managedField});");
|
||||
freeContents.AppendLine($"{unmanagedField}.Free();/*hfmm1*/");
|
||||
freeContents2.AppendLine($"{unmanagedField}.Free();/*hfmm2*/");
|
||||
}
|
||||
else if (originalType == "bool")
|
||||
{
|
||||
@@ -2074,8 +2130,8 @@ namespace Flax.Build.Bindings
|
||||
public {{marshalNativeType}} ToUnmanaged() { unmanaged = {{marshallerFullName}}.ToNative(managed); return unmanaged; }
|
||||
public void FromUnmanaged({{marshalNativeType}} unmanaged)
|
||||
{
|
||||
if (!unmanaged.Equals(this.unmanaged))
|
||||
{{marshallerName}}.Free(this.unmanaged); // Release temporary handles before replacing them with permanent handles
|
||||
//if (!unmanaged.Equals(this.unmanaged))
|
||||
// {{marshallerName}}.Free(this.unmanaged); // Release temporary handles before replacing them with permanent handles
|
||||
this.unmanaged = unmanaged;
|
||||
}
|
||||
public {{marshalManagedType}} ToManaged() { managed = {{marshallerFullName}}.ToManaged(unmanaged); return managed; }
|
||||
|
||||
@@ -7,6 +7,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using BuildData = Flax.Build.Builder.BuildData;
|
||||
|
||||
#pragma warning disable CS1717
|
||||
#pragma warning disable CS0162
|
||||
|
||||
namespace Flax.Build.Bindings
|
||||
{
|
||||
[Flags]
|
||||
@@ -48,6 +51,7 @@ namespace Flax.Build.Bindings
|
||||
private static readonly string[] CppParamsThatNeedConversionWrappers = new string[64];
|
||||
private static readonly string[] CppParamsThatNeedConversionTypes = new string[64];
|
||||
private static readonly string[] CppParamsWrappersCache = new string[64];
|
||||
private static readonly string[] CppParamsManagedTypes = new string[64];
|
||||
public static readonly List<KeyValuePair<string, string>> CppInternalCalls = new List<KeyValuePair<string, string>>();
|
||||
public static readonly List<ApiTypeInfo> CppUsedNonPodTypes = new List<ApiTypeInfo>();
|
||||
private static readonly List<ApiTypeInfo> CppUsedNonPodTypesList = new List<ApiTypeInfo>();
|
||||
@@ -154,18 +158,41 @@ namespace Flax.Build.Bindings
|
||||
if (!string.IsNullOrEmpty(nativeToManaged))
|
||||
{
|
||||
result = string.Format(nativeToManaged, paramName);
|
||||
if ((managedTypeAsNative[managedTypeAsNative.Length - 1] == '*' || managedTypeAsNative.StartsWith("NativeArray<")) && !isRef)
|
||||
if ((managedTypeAsNative[managedTypeAsNative.Length - 1] == '*' /*|| managedTypeAsNative.StartsWith("NativeArray<")*/) && !isRef)
|
||||
{
|
||||
// Pass pointer value
|
||||
contents.Append($" //GenerateCppWrapperNativeToManagedParam {paramName} Pass pointer value").AppendLine();
|
||||
}
|
||||
/*else if (!isRef)
|
||||
{
|
||||
// Pass reference as a pointer
|
||||
|
||||
contents.Append($" //GenerateCppWrapperNativeToManagedParam {paramName} Pass reference as a pointer").AppendLine();
|
||||
result = '&' + result;
|
||||
}*/
|
||||
else
|
||||
{
|
||||
// Pass as pointer to local variable converted for managed runtime
|
||||
if (paramType.IsPtr)
|
||||
result = string.Format(nativeToManaged, '*' + paramName);
|
||||
contents.Append($" // localvar1 {managedTypeAsNative}, {paramType.ToString()}").AppendLine();
|
||||
contents.Append($" auto __param_orig_{paramName} = {result};").AppendLine();
|
||||
contents.Append($" auto __param_{paramName} = __param_orig_{paramName};").AppendLine();
|
||||
var origType = paramType.ToString();
|
||||
contents.Append($" // localvar1 {managedTypeAsNative}, {origType}, isRef: {isRef}, typeIsRef: {paramType.IsRef}").AppendLine();
|
||||
|
||||
if (isRef)
|
||||
{
|
||||
if (origType == managedTypeAsNative)
|
||||
contents.Append($" auto& __param_orig_{paramName} = {result};").AppendLine();
|
||||
else
|
||||
contents.Append($" auto __param_orig_{paramName} = {result};").AppendLine();
|
||||
contents.Append($" auto __param_{paramName} = __param_orig_{paramName};").AppendLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (origType == managedTypeAsNative)
|
||||
contents.Append($" auto& __param_{paramName} = {result};").AppendLine();
|
||||
else
|
||||
contents.Append($" auto __param_{paramName} = {result};").AppendLine();
|
||||
}
|
||||
result = $"&__param_{paramName}";
|
||||
formattingFlags.SetFlag(ParameterFormattingFlags.NeedLocalVariable, true);
|
||||
}
|
||||
@@ -535,12 +562,31 @@ namespace Flax.Build.Bindings
|
||||
|
||||
switch (typeInfo.Type)
|
||||
{
|
||||
#if USE_NETCORE
|
||||
case "String":
|
||||
case "StringView":
|
||||
type = "String";
|
||||
//return "/*hh6hh*/(MString*)&{0}";
|
||||
return "/*hh6hh*/{0}";
|
||||
case "StringAnsi":
|
||||
case "StringAnsiView":
|
||||
if (functionInfo?.UniqueName == "CoverageTest1ByRef")
|
||||
typeInfo = typeInfo;
|
||||
//type = typeInfo.Type + "/*cvcv2*/";//"StringAnsi";
|
||||
type = "String";
|
||||
//return "/*hh6hh*/(MString*)&{0}";
|
||||
//return $"/*hh7hh*/MUtils::ToNativeString({{0}})";
|
||||
if (typeInfo.Type == "StringAnsiView")
|
||||
return "/*hh7hha*/String({0})";
|
||||
return "/*hh7hh*/String({0})";
|
||||
#else
|
||||
case "String":
|
||||
case "StringView":
|
||||
case "StringAnsi":
|
||||
case "StringAnsiView":
|
||||
type = "MString*";
|
||||
return "MUtils::ToString({0})";
|
||||
#endif
|
||||
case "Variant":
|
||||
type = "MObject*";
|
||||
return "MUtils::BoxVariant({0})";
|
||||
@@ -658,7 +704,7 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
if (CppNativeArrayAsParameter)
|
||||
{
|
||||
type = nativeName + $"*/*wahho2 pod:{pod}*/";
|
||||
type = nativeName;
|
||||
//type = $"NativeArray<{arrayApiType.FullNameNative}>/*tahho*/";
|
||||
//if (arrayTypeInfo.Type == "bool")
|
||||
// return "MUtils::ToBoolArray({0})/*bahho*/";
|
||||
@@ -666,12 +712,12 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
else if (arrayTypeInfo.IsObjectRef || (arrayApiType != null && arrayApiType.IsScriptingObject))
|
||||
{
|
||||
type = $"NativeArray<MObject*>/*wahho5 object*/";
|
||||
type = $"NativeArray<MObject*>";
|
||||
return $"MUtils::ToManagedArrayWrapperPointer<{nativeName}>({converter})/*sahho3a*/";
|
||||
}
|
||||
else if (arrayApiType != null && arrayApiType.IsScriptingObject)
|
||||
{
|
||||
type = $"NativeArray<{nativeInternalName}*>/*wahho3 class pod:{pod}*/";
|
||||
type = $"NativeArray<{nativeInternalName}*>";
|
||||
//type = $"NativeArray<{arrayApiType.FullNameNative}>/*tahho*/";
|
||||
//if (arrayTypeInfo.Type == "bool")
|
||||
// return "MUtils::ToBoolArray({0})/*bahho*/";
|
||||
@@ -686,7 +732,7 @@ namespace Flax.Build.Bindings
|
||||
else
|
||||
{
|
||||
// Storage type should be wrapped
|
||||
type = $"NativeArray<{nativeInternalName}>/*wahho1 pod:{pod}*/";
|
||||
type = $"NativeArray<{nativeInternalName}>";
|
||||
//type = nativeName + "*/*wahho1: {caller?.Name}*/";
|
||||
if (nativeName == nativeInternalName)
|
||||
return $"MUtils::ToManagedArrayWrapperCopy<{nativeName}>({converter})/*sahho2a*/";
|
||||
@@ -741,7 +787,14 @@ namespace Flax.Build.Bindings
|
||||
CppReferencesFiles.Add(apiType.File);
|
||||
|
||||
if (apiType.MarshalAs != null)
|
||||
return GenerateCppWrapperNativeToManaged(buildData, apiType.MarshalAs, caller, out type, functionInfo);
|
||||
{
|
||||
var ret = GenerateCppWrapperNativeToManaged(buildData, apiType.MarshalAs, caller, out type, functionInfo);
|
||||
//if (apiType.MarshalAs.Type == "JsonAsset")
|
||||
return ret;
|
||||
//return $"({apiType.MarshalAs}){ret}";
|
||||
}
|
||||
//return $"({apiType.MarshalAs}){GenerateCppWrapperNativeToManaged(buildData, apiType.MarshalAs, caller, out type, functionInfo)}";
|
||||
//return GenerateCppWrapperNativeToManaged(buildData, apiType.MarshalAs, caller, out type, functionInfo);
|
||||
|
||||
// Scripting Object
|
||||
if (apiType.IsScriptingObject)
|
||||
@@ -823,6 +876,25 @@ namespace Flax.Build.Bindings
|
||||
|
||||
switch (typeInfo.Type)
|
||||
{
|
||||
#if USE_NETCORE
|
||||
case "String":
|
||||
if (functionInfo?.UniqueName == "CoverageTest1ByRef")
|
||||
typeInfo = typeInfo;
|
||||
type = "String";
|
||||
return "{0}/*vcvc3a*/";
|
||||
case "StringView":
|
||||
type = "StringView";
|
||||
return "{0}/*vcvc4a*/";
|
||||
case "StringAnsi":
|
||||
type = "StringAnsi";
|
||||
//return $"{typeInfo.Type}({{0}})/*vcvc6a*/";
|
||||
//return $"(StringAnsi{(typeInfo.IsRef ? "*" : "")}){{0}}/*vcvc6a*/";
|
||||
return $"{{0}}/*vcvc6a*/";
|
||||
case "StringAnsiView":
|
||||
type = "StringAnsiView";
|
||||
//return $"{typeInfo.Type}(StringAnsi({{0}}))/*vcvc5a*/";
|
||||
return $"(StringAnsi){{0}}/*vcvc5a*/";
|
||||
#else
|
||||
case "String":
|
||||
type = "MString*";
|
||||
return "String(MUtils::ToString({0}))";
|
||||
@@ -833,6 +905,7 @@ namespace Flax.Build.Bindings
|
||||
case "StringAnsiView":
|
||||
type = "MString*";
|
||||
return "MUtils::ToStringAnsi({0})";
|
||||
#endif
|
||||
case "Variant":
|
||||
type = "MObject*";
|
||||
return "MUtils::UnboxVariant({0})";
|
||||
@@ -920,7 +993,7 @@ namespace Flax.Build.Bindings
|
||||
type = $"NativeArray<{nativeInternalName}>";
|
||||
result = $"Array<{genericArgs}>(/*({nativeName}*)*/{converter}, {{1}})/*456valuetype {arrayTypeInfo.Type}*/";
|
||||
}
|
||||
else if (nativeName == "String" || nativeName == "StringAnsi" || nativeName == "StringView")
|
||||
else if (nativeName == "String" || nativeName == "StringAnsi" || nativeName == "StringView" || nativeName == "StringAnsiView")
|
||||
{
|
||||
//result += "/*234stringy*/";
|
||||
}
|
||||
@@ -980,7 +1053,7 @@ namespace Flax.Build.Bindings
|
||||
var nativeName = arrayApiType.FullNameNative;
|
||||
if (typeInfo.GenericArgs[0].IsConst)
|
||||
nativeName = "const " + nativeName;
|
||||
return $"Span<{nativeName}>({{0}}, {{1}})/*spantag */";
|
||||
return $"Span<{nativeName}>({{0}}, {{1}})";
|
||||
}
|
||||
|
||||
return "MUtils::ToSpan<" + typeInfo.GenericArgs[0] + ">({0})";
|
||||
@@ -1013,7 +1086,7 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
#if USE_NETCORE
|
||||
//formattingFlags.SetFlag(FormattingFlags.NeedLocalVariable, true);
|
||||
type = "byte*";
|
||||
type = "NativeArray<byte>";
|
||||
return "BytesContainer({0}, {1})";
|
||||
#else
|
||||
formattingFlags.SetFlag(FormattingFlags.NeedLocalVariable, true);
|
||||
@@ -1040,7 +1113,12 @@ namespace Flax.Build.Bindings
|
||||
if (apiType != null)
|
||||
{
|
||||
if (apiType.MarshalAs != null)
|
||||
return GenerateCppWrapperManagedToNative(buildData, apiType.MarshalAs, caller, functionInfo, generatorFlags, out type, out apiType, out formattingFlags);
|
||||
{
|
||||
var ret = GenerateCppWrapperManagedToNative(buildData, apiType.MarshalAs, caller, functionInfo, generatorFlags, out type, out apiType, out formattingFlags);
|
||||
if (string.IsNullOrEmpty(ret))
|
||||
return ret;
|
||||
return $"({type}){ret}";
|
||||
}
|
||||
|
||||
// Scripting Object (for non-pod types converting only, other API converts managed to unmanaged object in C# wrapper code)
|
||||
if (CppNonPodTypesConvertingGeneration && apiType.IsScriptingObject && typeInfo.IsPtr)
|
||||
@@ -1210,14 +1288,16 @@ namespace Flax.Build.Bindings
|
||||
callerName = callerName;
|
||||
if (functionInfo.UniqueName == "CoverageTest4")
|
||||
callerName = callerName;
|
||||
if (functionInfo.UniqueName == "SetFallbackFonts")
|
||||
if (functionInfo.UniqueName == "GetWaitTimeSelector")
|
||||
callerName = callerName;
|
||||
if (functionInfo.ReturnType.IsString)
|
||||
callerName = callerName;
|
||||
|
||||
|
||||
// Setup function binding glue to ensure that wrapper method signature matches for C++ and C#
|
||||
functionInfo.Glue = new FunctionInfo.GlueInfo
|
||||
{
|
||||
UseReferenceForResult = UsePassByReference(buildData, functionInfo.ReturnType, caller),
|
||||
//"why can't we pass string as constref in return (or any other types?)"
|
||||
UseReferenceForResult = !functionInfo.ReturnType.IsString && UsePassByReference(buildData, functionInfo.ReturnType, caller),
|
||||
CustomParameters = new List<FunctionInfo.ParameterInfo>(),
|
||||
};
|
||||
var returnType = functionInfo.ReturnType;
|
||||
@@ -1225,6 +1305,7 @@ namespace Flax.Build.Bindings
|
||||
if (returnApiType != null && returnApiType.MarshalAs != null)
|
||||
returnType = returnApiType.MarshalAs;
|
||||
|
||||
// Setup additional glue parameters and conversion for return type
|
||||
bool returnTypeIsContainer = false;
|
||||
//CppNativeArrayAsParameter = true;
|
||||
var returnValueConvert = GenerateCppWrapperNativeToManaged(buildData, functionInfo.ReturnType, caller, out var returnValueType, functionInfo);
|
||||
@@ -1273,6 +1354,7 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
#endif
|
||||
|
||||
// Start of function definition
|
||||
var prevIndent = " ";
|
||||
var indent = " ";
|
||||
contents.Append(prevIndent);
|
||||
@@ -1309,6 +1391,7 @@ namespace Flax.Build.Bindings
|
||||
#endif
|
||||
CppInternalCalls.Add(new KeyValuePair<string, string>(functionInfo.UniqueName, functionInfo.UniqueName));
|
||||
|
||||
// "This" parameter
|
||||
var separator = false;
|
||||
var signatureStart = contents.Length;
|
||||
if (!functionInfo.IsStatic)
|
||||
@@ -1317,6 +1400,7 @@ namespace Flax.Build.Bindings
|
||||
separator = true;
|
||||
}
|
||||
|
||||
// Setup function parameter list
|
||||
var useInlinedReturn = true;
|
||||
for (var i = 0; i < functionInfo.Parameters.Count; i++)
|
||||
{
|
||||
@@ -1338,7 +1422,7 @@ namespace Flax.Build.Bindings
|
||||
|
||||
CppParamsThatNeedConversion[i] = false;
|
||||
//CppNativeArrayAsParameter = true;
|
||||
CppParamsWrappersCache[i] = GenerateCppWrapperManagedToNative(buildData, parameterInfo.Type, caller, functionInfo, genFlags, out var managedType, out var apiType, out CppParamsFormattingFlags[i]);
|
||||
CppParamsWrappersCache[i] = GenerateCppWrapperManagedToNative(buildData, parameterInfo.Type, caller, functionInfo, genFlags, out CppParamsManagedTypes[i], out var apiType, out CppParamsFormattingFlags[i]);
|
||||
//CppNativeArrayAsParameter = false;
|
||||
|
||||
if (functionInfo.UniqueName.StartsWith("Set") && !functionInfo.Name.StartsWith("Set"))
|
||||
@@ -1352,9 +1436,9 @@ namespace Flax.Build.Bindings
|
||||
// Out parameters that need additional converting will be converted at the native side (eg. object reference)
|
||||
var isOutWithManagedConverter = parameterInfo.IsOut && !string.IsNullOrEmpty(GenerateCSharpManagedToNativeConverter(buildData, parameterInfo.Type, caller));
|
||||
if (isOutWithManagedConverter)
|
||||
managedType = "MObject*";
|
||||
CppParamsManagedTypes[i] = "MObject*";
|
||||
|
||||
contents.Append(managedType);
|
||||
contents.Append(CppParamsManagedTypes[i]);
|
||||
if (parameterInfo.IsRef || parameterInfo.IsOut || UsePassByReference(buildData, parameterInfo.Type, caller))
|
||||
contents.Append('*');
|
||||
contents.Append(' ');
|
||||
@@ -1372,15 +1456,26 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
convertOutputParameter = true;
|
||||
}
|
||||
// Arrays, Scripting Objects, Dictionaries and other types that need to be converted into managed format if used as output parameter
|
||||
else if (!apiType.IsPod)
|
||||
{
|
||||
convertOutputParameter = true;
|
||||
}
|
||||
else if (apiType.Name == "Variant")
|
||||
{
|
||||
convertOutputParameter = true;
|
||||
}
|
||||
// Arrays, Scripting Objects, Dictionaries and other types that need to be converted into managed format if used as output parameter
|
||||
else if (!apiType.IsPod)
|
||||
{
|
||||
#if USE_NETCORE
|
||||
if (parameterInfo.Type.IsString)
|
||||
{
|
||||
// StringAnsi requires conversion
|
||||
convertOutputParameter = CppParamsManagedTypes[i] != parameterInfo.Type.Type;
|
||||
}
|
||||
else
|
||||
//if (!parameterInfo.Type.IsString /*&& !parameterInfo.Type.IsArrayOrSpan*/)
|
||||
#endif
|
||||
{
|
||||
convertOutputParameter = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// BytesContainer
|
||||
else if (parameterInfo.Type.Type == "BytesContainer" && parameterInfo.Type.GenericArgs == null)
|
||||
@@ -1414,7 +1509,6 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
for (var i = 0; i < functionInfo.Glue.CustomParameters.Count; i++)
|
||||
{
|
||||
var parameterInfo = functionInfo.Glue.CustomParameters[i];
|
||||
@@ -1442,6 +1536,8 @@ namespace Flax.Build.Bindings
|
||||
prevIndent = null;
|
||||
indent = " ";
|
||||
}
|
||||
|
||||
// Function body
|
||||
contents.AppendLine();
|
||||
contents.Append(prevIndent).AppendLine("{");
|
||||
#if USE_NETCORE
|
||||
@@ -1451,19 +1547,6 @@ namespace Flax.Build.Bindings
|
||||
if (!functionInfo.IsStatic)
|
||||
contents.Append(indent).AppendLine("if (__obj == nullptr) DebugLog::ThrowNullReference();");
|
||||
|
||||
string callBegin = indent;
|
||||
if (functionInfo.Glue.UseReferenceForResult)
|
||||
{
|
||||
callBegin += "*__resultAsRef = ";
|
||||
}
|
||||
else if (!returnType.IsVoid)
|
||||
{
|
||||
if (useInlinedReturn)
|
||||
callBegin += "return ";
|
||||
else
|
||||
callBegin += "auto __result = ";
|
||||
}
|
||||
|
||||
#if USE_NETCORE
|
||||
string callReturnCount = "";
|
||||
if (returnTypeIsContainer)
|
||||
@@ -1583,9 +1666,16 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
// Non-const lvalue reference parameters needs to be passed via temporary value
|
||||
if (parameterInfo.IsOut || parameterInfo.IsRef)
|
||||
contents.Append(indent).AppendFormat("{2}& {0}Temp = {1}; // non-const lvalue1", parameterInfo.Name, param, parameterInfo.Type.ToString(false)).AppendLine();
|
||||
{
|
||||
if (parameterInfo.Type.IsString)
|
||||
contents.Append(indent).AppendFormat("{2}& {0}Temp = *{1}; // non-const lvalue1string", parameterInfo.Name, param, parameterInfo.Type.ToString(false)).AppendLine();
|
||||
else
|
||||
contents.Append(indent).AppendFormat("{2}& {0}Temp = {1}; // non-const lvalue1b", parameterInfo.Name, param, parameterInfo.Type.ToString(false)).AppendLine();
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(CppParamsWrappersCache[i]))
|
||||
contents.Append(indent).AppendFormat("{2}& {0}Temp = {1}; // non-const lvalue2", parameterInfo.Name, param, parameterInfo.Type.ToString(false)).AppendLine();
|
||||
else
|
||||
contents.Append(indent).AppendFormat("{2} {0}Temp = {1}; // non-const lvalue1", parameterInfo.Name, param, parameterInfo.Type.ToString(false)).AppendLine();
|
||||
contents.Append(indent).AppendFormat("{2} {0}Temp = {1}; // non-const lvalue3", parameterInfo.Name, param, parameterInfo.Type.ToString(false)).AppendLine();
|
||||
callParams += parameterInfo.Name;
|
||||
callParams += "Temp";
|
||||
}
|
||||
@@ -1595,6 +1685,19 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
}
|
||||
|
||||
// Handle return value and conversion here if we have no ref/out parameters
|
||||
string callBegin = indent;
|
||||
if (functionInfo.Glue.UseReferenceForResult)
|
||||
{
|
||||
callBegin += "*__resultAsRef = ";
|
||||
}
|
||||
else if (!returnType.IsVoid)
|
||||
{
|
||||
if (useInlinedReturn)
|
||||
callBegin += "return ";
|
||||
else
|
||||
callBegin += "auto __result = ";
|
||||
}
|
||||
#if USE_NETCORE
|
||||
if (!string.IsNullOrEmpty(callReturnCount))
|
||||
{
|
||||
@@ -1710,7 +1813,8 @@ namespace Flax.Build.Bindings
|
||||
#endif
|
||||
{
|
||||
contents.Append(indent).Append($"// isgigs2").AppendLine();
|
||||
contents.Append(indent).AppendFormat("MCore::GC::WriteRef({0}, (MObject*){1});", parameterInfo.Name, value).AppendLine();
|
||||
contents.Append(indent).AppendFormat("*{0} = {1};", parameterInfo.Name, value).AppendLine();
|
||||
//contents.Append(indent).AppendFormat("MCore::GC::WriteRef({0}, (MObject*){1});", parameterInfo.Name, value).AppendLine();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -1718,7 +1822,11 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
// Structure that has reference to managed objects requries copy relevant for GC barriers (on Mono)
|
||||
CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MClass.h");
|
||||
#if USE_NETCORE
|
||||
contents.Append(indent).AppendFormat("*{0} = {1}; /*xcic666*/", parameterInfo.Name, value).AppendLine();
|
||||
#else
|
||||
contents.Append(indent).AppendFormat("{{ auto __temp = {1}; MCore::GC::WriteValue({0}, &__temp, 1, {2}::TypeInitializer.GetClass()); }}", parameterInfo.Name, value, apiType.FullNameNative).AppendLine();
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1970,7 +2078,7 @@ namespace Flax.Build.Bindings
|
||||
for (var i = 0; i < functionInfo.Parameters.Count; i++)
|
||||
{
|
||||
var parameterInfo = functionInfo.Parameters[i];
|
||||
var paramIsRef = parameterInfo.IsRef || parameterInfo.IsOut;
|
||||
var paramIsRef = (parameterInfo.IsRef || parameterInfo.IsOut) /*&& !parameterInfo.IsConst*/;
|
||||
var paramValue = GenerateCppWrapperNativeToManagedParam(buildData, contents, parameterInfo.Type, parameterInfo.Name, classInfo, paramIsRef, out CppParamsFormattingFlags[i]);
|
||||
contents.Append($" params[{i}] = {paramValue};").AppendLine();
|
||||
}
|
||||
@@ -1989,6 +2097,7 @@ namespace Flax.Build.Bindings
|
||||
// Direct value convert
|
||||
var paramName = CppParamsFormattingFlags[i].HasFlag(ParameterFormattingFlags.NeedLocalVariable) ? $"__param_{parameterInfo.Name}" : $"params[{i}]";
|
||||
var managedToNative = GenerateCppWrapperManagedToNative(buildData, parameterInfo.Type, classInfo, null, ParameterGeneratorFlags.None, out var managedType, out var apiType, out _);
|
||||
var nativeToManaged = GenerateCppWrapperNativeToManaged(buildData, parameterInfo.Type, classInfo, out var managedTypeAsNative, null);
|
||||
var passAsParamPtr = managedType.EndsWith("*") || true;
|
||||
var useLocalVarPointer = !CppParamsFormattingFlags[i].HasFlag(ParameterFormattingFlags.NeedLocalVariable);
|
||||
var paramValue = useLocalVarPointer ? $"*({managedType}{(passAsParamPtr ? "" : "*")}*)&{paramName}" : paramName;
|
||||
@@ -2000,7 +2109,11 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
else if (!passAsParamPtr)
|
||||
paramValue = '*' + paramValue;
|
||||
contents.Append($" {parameterInfo.Name} = {paramValue};").AppendLine();
|
||||
|
||||
if (!string.IsNullOrEmpty(managedTypeAsNative) && managedTypeAsNative != managedType)
|
||||
contents.Append($" {parameterInfo.Name} = ({managedType}){paramValue}; // managedTypeAsNative:{managedTypeAsNative}, managedToNative:{managedToNative} managedType:{managedType}, type:{parameterInfo.Type.ToString()}").AppendLine();
|
||||
else
|
||||
contents.Append($" {parameterInfo.Name} = {paramValue}; // managedTypeAsNative:{managedTypeAsNative}, managedToNative:{managedToNative} managedType:{managedType}, type:{parameterInfo.Type.ToString()}").AppendLine();
|
||||
|
||||
// Release temporary GCHandles
|
||||
/*if (passAsParamPtr)
|
||||
@@ -2050,7 +2163,11 @@ namespace Flax.Build.Bindings
|
||||
|
||||
//var ispod = parameterInfo.Type.IsPod(buildData, apiType);
|
||||
//contents.Append($" // {parameterInfo.Type.Type} is pod: {ispod}||{apiType.IsPod}, valuetype: {apiType.IsValueType}, classtype: {apiType.IsClass} // doerp1").AppendLine();
|
||||
if (useThunk || !paramIsValueType)
|
||||
if (parameterInfo.Type.IsString)
|
||||
{
|
||||
contents.Append($" //durr2string").AppendLine();
|
||||
}
|
||||
else if (useThunk || !paramIsValueType)
|
||||
{
|
||||
contents.Append($" MUtils::FreeManaged<{parameterInfo.Type.Type}>((MObject*)__param_{parameterInfo.Name}); // darr1").AppendLine();
|
||||
// Release the original handle
|
||||
@@ -2059,8 +2176,7 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
else if (paramIsValueType)
|
||||
{
|
||||
contents.Append($" //durr2").AppendLine();
|
||||
|
||||
contents.Append($" //durr2value").AppendLine();
|
||||
}
|
||||
else if (CppParamsThatNeedConversion[i])
|
||||
{
|
||||
@@ -2082,7 +2198,7 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
if (parameterInfo.Type.Type.ToLower().Contains("string"))
|
||||
apiType = apiType;
|
||||
contents.Append($" MUtils::FreeManaged<{parameterInfo.Type.Type}>((MObject*)params[{i}]); //asdf1d").AppendLine();
|
||||
contents.Append($" //MUtils::FreeManaged<{parameterInfo.Type.Type}>((MObject*)params[{i}]); //asdf1d").AppendLine();
|
||||
}
|
||||
else if (useThunk)//if (apiType != null)
|
||||
{
|
||||
@@ -2101,7 +2217,7 @@ namespace Flax.Build.Bindings
|
||||
if (useThunk)
|
||||
contents.Append($" MUtils::FreeManagedArray<byte>((MArray*)params[{i}]); //fgfgh8").AppendLine();
|
||||
else
|
||||
contents.Append($" MCore::GC::FreeMemory(__param_{parameterInfo.Name}.data, true); //fgfghdf8").AppendLine();
|
||||
contents.Append($" MCore::GC::FreeMemory(__param_{parameterInfo.Name}.data, false); //fgfghdf8").AppendLine();
|
||||
//contents.Append($" MUtils::FreeManagedArray<byte>((MArray*)params[{i}]); //fgfgh8").AppendLine();
|
||||
}
|
||||
else if (paramIsRef)
|
||||
@@ -2117,7 +2233,7 @@ namespace Flax.Build.Bindings
|
||||
|
||||
//var isPod = parameterInfo.Type.GenericArgs.Count > 0 ? parameterInfo.Type.GenericArgs[0].IsPod(buildData, apiType) : false;
|
||||
contents.Append($" // {parameterInfo.Type} is pod: {elementApiType?.IsPod}, valuetype: {paramIsValueType}, classtype: {apiType.IsClass} // huah").AppendLine();
|
||||
if (useThunk /*|| CppParamsThatNeedConversion[i]*/ || genericType == "String" || genericType == "StringAnsi" || genericType == "StringView")
|
||||
if (useThunk /*|| CppParamsThatNeedConversion[i]*/ || genericType == "String" || genericType == "StringAnsi" || genericType == "StringView" || genericType == "StringAnsiView")
|
||||
{
|
||||
contents.Append($" MUtils::FreeManagedArray<{genericType}>(__param_{parameterInfo.Name}); //fgfgh3").AppendLine();
|
||||
|
||||
@@ -2131,20 +2247,22 @@ namespace Flax.Build.Bindings
|
||||
}*/
|
||||
else// if (CppParamsThatNeedConversion[i])
|
||||
{
|
||||
contents.Append($" MCore::GC::FreeMemory(__param_{parameterInfo.Name}.data, true); //jfgfgh7").AppendLine();
|
||||
//contents.Append($" MCore::GC::FreeMemory(__param_{parameterInfo.Name}.data, false); //jfgfgh7").AppendLine();
|
||||
contents.Append($" MUtils::FreeManagedArray<{genericType}>((MArray*)params[{i}]); //jfgfgh7").AppendLine();
|
||||
|
||||
// Release the original handle
|
||||
contents.Append($" if (__param_orig_{parameterInfo.Name}.data != __param_{parameterInfo.Name}.data)").AppendLine();
|
||||
contents.Append($" MCore::GC::FreeMemory(__param_orig_{parameterInfo.Name}.data, true); //fgfgh8").AppendLine();
|
||||
contents.Append($" MUtils::FreeManagedArray<{genericType}>((MArray*)&__param_orig_{parameterInfo.Name}); //jfgfgh7b").AppendLine();
|
||||
//contents.Append($" MCore::GC::FreeMemory(__param_orig_{parameterInfo.Name}.data, false); //fgfgh8").AppendLine();
|
||||
}
|
||||
}
|
||||
else if (elementApiType?.IsPod ?? false)
|
||||
{
|
||||
var genericType = parameterInfo.Type.GenericArgs[0].ToString(false);
|
||||
if (CppParamsFormattingFlags[i].HasFlag(ParameterFormattingFlags.NeedLocalVariable))
|
||||
contents.Append($" MCore::GC::FreeMemory(__param_{parameterInfo.Name}.data, true); //kfgfgh7a").AppendLine();
|
||||
contents.Append($" MCore::GC::FreeMemory(__param_{parameterInfo.Name}.data, false); //kfgfgh7a").AppendLine();
|
||||
else
|
||||
contents.Append($" MCore::GC::FreeMemory(params[{i}], true); //kfgfgh7b").AppendLine();
|
||||
contents.Append($" MCore::GC::FreeMemory(params[{i}], false); //kfgfgh7b").AppendLine();
|
||||
}
|
||||
else if (apiType != null && !apiType.IsInBuild)
|
||||
{
|
||||
@@ -3522,6 +3640,9 @@ namespace Flax.Build.Bindings
|
||||
// Get the full typename with nested parent prefix
|
||||
var fullName = apiType.FullNameNative;
|
||||
|
||||
if (wrapperName == "TestStructManaged")
|
||||
wrapperName = wrapperName;
|
||||
|
||||
if (structureInfo != null)
|
||||
{
|
||||
// Generate managed type memory layout
|
||||
@@ -3558,7 +3679,7 @@ namespace Flax.Build.Bindings
|
||||
header.AppendLine("namespace {");
|
||||
header.AppendFormat("{0} ToManaged(const {1}& value);", wrapperName, fullName).AppendLine();
|
||||
header.AppendFormat("{1} ToNative(const {0}& value);", wrapperName, fullName).AppendLine();
|
||||
header.AppendFormat("void FreeManaged(const {0}& value);", wrapperName).AppendLine();
|
||||
header.AppendFormat("void FreeManaged({0}& value);", wrapperName).AppendLine();
|
||||
header.AppendLine("}");
|
||||
|
||||
// Generate MConverter for a structure
|
||||
@@ -3623,7 +3744,7 @@ namespace Flax.Build.Bindings
|
||||
//header.AppendFormat(" auto managed = MCore::Object::Unbox(data);", wrapperName).AppendLine();
|
||||
//header.AppendFormat(" ::FreeManaged(*reinterpret_cast<{0}*>(managed));", wrapperName).AppendLine();
|
||||
header.Append(" MCore::Array::Free(array);").AppendLine();
|
||||
header.Append(" MCore::GCHandle::Free(*(MGCHandle*)&array);").AppendLine();
|
||||
//header.Append(" MCore::GCHandle::Free(*(MGCHandle*)&array);").AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
header.Append('}').Append(';').AppendLine();
|
||||
@@ -3637,14 +3758,14 @@ namespace Flax.Build.Bindings
|
||||
header.Append(" {").AppendLine();
|
||||
//header.AppendFormat(" result = ToNative(*reinterpret_cast<{0}*>(MCore::Object::Unbox(data)));", wrapperName).AppendLine();
|
||||
//header.Append(" PLATFORM_DEBUG_BREAK;").AppendLine();
|
||||
header.Append(" result = ::ToManaged(data);").AppendLine();
|
||||
header.Append($" new(&result) {wrapperName}(MoveTemp(::ToManaged(data)));").AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
header.AppendFormat(" DLLEXPORT USED void ToNative({0}& result, const {1}& data) const", fullName, wrapperName).AppendLine();
|
||||
header.Append(" {").AppendLine();
|
||||
//header.AppendFormat(" result = ToNative(*reinterpret_cast<{0}*>(MCore::Object::Unbox(data)));", wrapperName).AppendLine();
|
||||
//header.Append(" PLATFORM_DEBUG_BREAK;").AppendLine();
|
||||
header.Append(" result = ::ToNative(data);").AppendLine();
|
||||
header.Append($" new(&result) {fullName}(MoveTemp(::ToNative(data)));").AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
header.Append('}').Append(';').AppendLine();
|
||||
@@ -3725,7 +3846,7 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
var arrayElementType = fieldInfo.Type.GenericArgs != null ? FindApiTypeInfo(buildData, fieldInfo.Type.GenericArgs[0], apiType) : null;
|
||||
var ispod = (arrayElementType?.IsPod.ToString() ?? "null");
|
||||
header.Append($" // pluh: {fieldInfo.Type.Type}, {fieldType?.FullNameNative}, {fieldType?.Name}, {fieldTypeName}, {ispod}").AppendLine();
|
||||
header.Append($" // pluh: {fieldInfo.Type.Type}, FullNameNative:{fieldType?.FullNameNative}, Name:{fieldType?.Name}, ManagedToNativeType:{fieldTypeName}, pod:{ispod}").AppendLine();
|
||||
//if (fieldInfo.Type.IsArrayOrSpan && (arrayElementType?.IsValueType ?? false))
|
||||
{
|
||||
header.AppendFormat(" result.{0} = {1}; /*kaek1 */", fieldInfo.Name, string.Format(wrapper, $"value.{fieldInfo.Name}", $"value.{fieldInfo.Name}.length")).AppendLine();
|
||||
@@ -3747,7 +3868,7 @@ namespace Flax.Build.Bindings
|
||||
|
||||
// Generate release function for temporary managed handles
|
||||
header.AppendLine();
|
||||
header.AppendFormat("void FreeManaged(const {0}& value)", wrapperName).AppendLine();
|
||||
header.AppendFormat("void FreeManaged({0}& value)", wrapperName).AppendLine();
|
||||
header.Append('{').AppendLine();
|
||||
for (var i = 0; i < fields.Count; i++)
|
||||
{
|
||||
@@ -3759,7 +3880,15 @@ namespace Flax.Build.Bindings
|
||||
var wrapper = GenerateCppWrapperManagedToNative(buildData, fieldInfo.Type, apiType, null, ParameterGeneratorFlags.None, out var managedType, out var fieldApiType, out _);
|
||||
CppNonPodTypesConvertingGeneration = false;
|
||||
|
||||
if (fieldInfo.Type.IsArray)
|
||||
if (fieldInfo.Type.IsString || (fieldApiType?.MarshalAs?.IsString ?? false))
|
||||
{
|
||||
#if USE_NETCORE
|
||||
header.Append($" value.{fieldInfo.Name}.Clear(); // HUU1").AppendLine();
|
||||
#else
|
||||
header.Append($" MCore::String::Free(value.{fieldInfo.Name});").AppendLine();
|
||||
#endif
|
||||
}
|
||||
else if (fieldInfo.Type.IsArray)
|
||||
{
|
||||
//header.Append($" fixed_array_type = fixed_array_type; // {fieldInfo.Name} ({managedType}) is fixed array").AppendLine();
|
||||
}
|
||||
@@ -3784,7 +3913,11 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
|
||||
}
|
||||
#if USE_NETCORE
|
||||
header.Append($" value.{fieldInfo.Name}.Clear(); // Haa1").AppendLine();
|
||||
#else
|
||||
header.Append($" MCore::String::Free(value.{fieldInfo.Name});").AppendLine();
|
||||
#endif
|
||||
}
|
||||
else if (fieldInfo.Type.Type == "Span")
|
||||
{
|
||||
@@ -3817,18 +3950,20 @@ namespace Flax.Build.Bindings
|
||||
{
|
||||
if (fieldApiType.IsClass)
|
||||
{
|
||||
|
||||
header.Append($" // a class").AppendLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
header.Append($" ::FreeManaged(value.{fieldInfo.Name}); // asdfggg588").AppendLine();
|
||||
header.Append($" ::FreeManaged(value.{fieldInfo.Name}); // asdfggg588 not class").AppendLine();
|
||||
//header.Append($" unhandled_type = unhandled_type; // {fieldInfo.Name} ({managedType}) should be cleaned? // asdfggg588").AppendLine();
|
||||
}
|
||||
/*
|
||||
header.Append($" auto __param{fieldInfo.Name}_handle = *(MGCHandle*)&value.{fieldInfo.Name};").AppendLine();
|
||||
//header.Append($" ASSERT((((unsigned long long)__param{fieldInfo.Name}_handle & 0xC000000000000000) >> 62) == 0); // asdf3").AppendLine();
|
||||
header.Append($" if ((((unsigned long long)__param{fieldInfo.Name}_handle & 0xC000000000000000) >> 62) != 0) // asdf3").AppendLine();
|
||||
header.Append($" if ((((unsigned long long)__param{fieldInfo.Name}_handle & 0xC000000000000000) >> 62) != 0) // asdf3 type:{fieldInfo.Type}, api:{fieldApiType?.Name}").AppendLine();
|
||||
header.Append($" __param{fieldInfo.Name}_handle = __param{fieldInfo.Name}_handle;").AppendLine();
|
||||
header.Append($" MCore::GCHandle::Free(__param{fieldInfo.Name}_handle);").AppendLine();
|
||||
*/
|
||||
}
|
||||
else if (fieldApiType.IsPod)
|
||||
{
|
||||
@@ -3864,14 +3999,19 @@ namespace Flax.Build.Bindings
|
||||
var fieldInfo = fields[i];
|
||||
if (fieldInfo.IsStatic || fieldInfo.IsConstexpr)
|
||||
continue;
|
||||
|
||||
if (fullName == "LocalizedString")
|
||||
fieldInfo = fieldInfo;
|
||||
var fieldType = FindApiTypeInfo(buildData, fieldInfo.Type, apiType);
|
||||
if (fieldInfo == null || fieldType.IsValueType) // TODO: support any value type (eg. by boxing)
|
||||
throw new Exception($"Not supported field {fieldInfo.Type} {fieldInfo.Name} in class {classInfo.Name}.");
|
||||
|
||||
var wrapper = GenerateCppWrapperNativeToManaged(buildData, fieldInfo.Type, apiType, out var type, null);
|
||||
var value = string.IsNullOrEmpty(wrapper) ? "data." + fieldInfo.Name : string.Format(wrapper, "data." + fieldInfo.Name);
|
||||
header.AppendFormat(" klass->GetField(\"{0}\")->SetValue(obj, {1});", fieldInfo.Name, value).AppendLine();
|
||||
if (!fieldInfo.Type.IsPtr)
|
||||
header.AppendFormat(" klass->GetField(\"{0}\")->SetValue(obj, (void*)&{1}); //gigigi1no", fieldInfo.Name, value).AppendLine();
|
||||
else
|
||||
header.AppendFormat(" klass->GetField(\"{0}\")->SetValue(obj, {1}); //gigigi1ptr", fieldInfo.Name, value).AppendLine();
|
||||
|
||||
}
|
||||
header.Append(" return obj;").AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
@@ -3892,6 +4032,9 @@ namespace Flax.Build.Bindings
|
||||
if (fieldInfo.IsStatic || fieldInfo.IsConstexpr)
|
||||
continue;
|
||||
|
||||
if (fullName == "LocalizedString")
|
||||
fieldInfo = fieldInfo;
|
||||
|
||||
CppNonPodTypesConvertingGeneration = true;
|
||||
var wrapper = GenerateCppWrapperManagedToNative(buildData, fieldInfo.Type, apiType, null, ParameterGeneratorFlags.None, out var type, out _, out _);
|
||||
CppNonPodTypesConvertingGeneration = false;
|
||||
@@ -3899,8 +4042,16 @@ namespace Flax.Build.Bindings
|
||||
CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MField.h");
|
||||
|
||||
header.AppendFormat(" klass->GetField(\"{0}\")->GetValue(obj, &v);", fieldInfo.Name).AppendLine();
|
||||
var value = $"({type})v";
|
||||
header.AppendFormat(" result.{0} = {1};", fieldInfo.Name, string.IsNullOrEmpty(wrapper) ? value : string.Format(wrapper, value)).AppendLine();
|
||||
if (type == "String" || type == "String*")
|
||||
{
|
||||
var value = fieldInfo.Type.IsPtr ? $"*({type}*)v" : $"*({type}*)v";
|
||||
header.AppendFormat(" result.{0} = {1};", fieldInfo.Name, string.IsNullOrEmpty(wrapper) ? value : string.Format(wrapper, value)).AppendLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = fieldInfo.Type.IsPtr ? $"({type})v" : $"({type}*)&v";
|
||||
header.AppendFormat(" result.{0} = {1};", fieldInfo.Name, string.IsNullOrEmpty(wrapper) ? value : string.Format(wrapper, value)).AppendLine();
|
||||
}
|
||||
}
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
@@ -3956,7 +4107,7 @@ namespace Flax.Build.Bindings
|
||||
//header.AppendFormat(" auto managed = MCore::Object::Unbox(data);", wrapperName).AppendLine();
|
||||
//header.AppendFormat(" ::FreeManaged(*reinterpret_cast<{0}*>(managed));", wrapperName).AppendLine();
|
||||
header.Append(" MCore::Array::Free(array);").AppendLine();
|
||||
header.Append(" MCore::GCHandle::Free(*(MGCHandle*)&array);").AppendLine();
|
||||
//header.Append(" MCore::GCHandle::Free(*(MGCHandle*)&array);").AppendLine();
|
||||
header.Append(" }").AppendLine();
|
||||
|
||||
header.Append('}').Append(';').AppendLine();
|
||||
|
||||
@@ -55,6 +55,11 @@ namespace Flax.Build.Bindings
|
||||
/// </summary>
|
||||
public bool IsArrayOrSpan => Type is "Array" or "Span" or "DataContainer" or "BytesContainer";
|
||||
|
||||
/// <summary>
|
||||
/// Is this a string type.
|
||||
/// </summary>
|
||||
public bool IsString => Type is "String" or "StringView" or "StringAnsi" or "StringAnsiView" && GenericArgs == null;
|
||||
|
||||
public TypeInfo()
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user