Generator: Improve struct return types in other cases (ID2D1Bitmap::GetPixelSize)

This commit is contained in:
Amer Koleci
2022-09-20 14:35:31 +02:00
parent 1309d11476
commit 2fcf8a7e94
30 changed files with 144 additions and 46 deletions

View File

@@ -1985,8 +1985,9 @@ public static class Program
if (returnType != "void" &&
method.ReturnType.TargetKind != "Com" &&
method.ReturnType.Kind == "ApiRef" &&
!IsPrimitive(method.ReturnType) &&
!IsEnum(method.ReturnType))
!IsEnum(method.ReturnType) &&
IsStructAsReturnMarshal(method.ReturnType)
)
{
useReturnAsParameter = true;
}
@@ -2699,6 +2700,59 @@ public static class Program
return IsPrimitive(typeName);
}
private static bool IsStructAsReturnMarshal(ApiDataType dataType)
{
if (dataType.Kind != "ApiRef")
{
throw new InvalidOperationException();
}
string apiRefType = GetTypeName($"{dataType.Api}.{dataType.Name}");
if (apiRefType.EndsWith("*"))
{
apiRefType = apiRefType.Substring(0, apiRefType.Length - 1);
}
switch (apiRefType)
{
case "void":
case "bool":
case "byte":
case "sbyte":
case "int":
case "uint":
case "short":
case "ushort":
case "long":
case "ulong":
case "float":
case "double":
return false;
case "nint":
case "nuint":
case "IntPtr":
case "UIntPtr":
case "Guid":
return false;
case "Bool32":
case "HResult":
return false;
case "LargeInteger":
case "ULargeInteger":
return true;
case "Luid":
return true;
default:
return true;
}
}
private static bool IsEnum(ApiDataType dataType)
{
if (dataType.Kind == "ApiRef")