-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
873 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Generator.Model; | ||
|
||
internal static class PlatformStringArray | ||
{ | ||
public static string GetInternalOwnedHandleName() => "GLib.Internal.PlatformStringArrayNullTerminatedOwnedHandle"; | ||
public static string GetInternalUnownedHandleName() => "GLib.Internal.PlatformStringArrayNullTerminatedUnownedHandle"; | ||
public static string GetInternalContainerHandleName() => "GLib.Internal.PlatformStringArrayNullTerminatedContainerHandle"; | ||
public static string GetInternalHandleName() => "GLib.Internal.PlatformStringArrayNullTerminatedHandle"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Generator.Model; | ||
|
||
internal static class Utf8StringArray | ||
{ | ||
public static string GetInternalOwnedHandleName() => "GLib.Internal.Utf8StringArrayNullTerminatedOwnedHandle"; | ||
public static string GetInternalUnownedHandleName() => "GLib.Internal.Utf8StringArrayNullTerminatedUnownedHandle"; | ||
public static string GetInternalContainerHandleName() => "GLib.Internal.Utf8StringArrayNullTerminatedContainerHandle"; | ||
public static string GetInternalHandleName() => "GLib.Internal.Utf8StringArrayNullTerminatedHandle"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Generation/Generator/Renderer/Internal/Parameter/Converter/PlatformStringArray.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
|
||
namespace Generator.Renderer.Internal.Parameter; | ||
|
||
internal class PlatformStringArray : ParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType anyType) | ||
{ | ||
return anyType.IsArray<GirModel.PlatformString>(); | ||
} | ||
|
||
public RenderableParameter Convert(GirModel.Parameter parameter) | ||
{ | ||
return new RenderableParameter( | ||
Attribute: string.Empty, | ||
Direction: GetAttribute(parameter), | ||
NullableTypeName: GetNullableTypeName(parameter), | ||
Name: Model.Parameter.GetName(parameter) | ||
); | ||
} | ||
|
||
private static string GetNullableTypeName(GirModel.Parameter parameter) | ||
{ | ||
return parameter switch | ||
{ | ||
{ Transfer: GirModel.Transfer.None, AnyTypeOrVarArgs.AsT0.AsT1.Length: null } => Model.PlatformStringArray.GetInternalHandleName(), | ||
{ Transfer: GirModel.Transfer.Full, AnyTypeOrVarArgs.AsT0.AsT1.Length: null } => Model.PlatformStringArray.GetInternalUnownedHandleName(), | ||
{ Transfer: GirModel.Transfer.Container, AnyTypeOrVarArgs.AsT0.AsT1.Length: null } => throw new Exception("Transfer container not supported for utf8 string arrays"), | ||
{ AnyTypeOrVarArgs.AsT0.AsT1.Length: not null} => Model.ArrayType.GetName(parameter.AnyTypeOrVarArgs.AsT0.AsT1), | ||
_ => throw new Exception("Can't detect typename for utf8 string array") | ||
}; | ||
} | ||
|
||
private static string GetAttribute(GirModel.Parameter parameter) | ||
{ | ||
return parameter.AnyTypeOrVarArgs.AsT0.AsT1.Length switch | ||
{ | ||
null => string.Empty, | ||
{ } l => MarshalAs.UnmanagedLpArray(sizeParamIndex: l) | ||
}; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...Generation/Generator/Renderer/Internal/Parameter/Converter/PlatformStringArrayCallback.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Generator.Renderer.Internal.Parameter; | ||
|
||
internal class PlatformStringArrayCallback : ParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType anyType) | ||
{ | ||
return anyType.IsArray<GirModel.PlatformString>(); | ||
} | ||
|
||
public RenderableParameter Convert(GirModel.Parameter parameter) | ||
{ | ||
return new RenderableParameter( | ||
Attribute: GetAttribute(parameter), | ||
Direction: string.Empty, | ||
NullableTypeName: GetNullableTypeName(parameter), | ||
Name: Model.Parameter.GetName(parameter) | ||
); | ||
} | ||
|
||
private static string GetNullableTypeName(GirModel.Parameter parameter) | ||
{ | ||
return parameter switch | ||
{ | ||
// Arrays of string which do not transfer ownership and have no length index can not be marshalled automatically | ||
{ Transfer: GirModel.Transfer.None, AnyTypeOrVarArgs.AsT0.AsT1.Length: null } => Model.Type.Pointer, | ||
_ => Model.ArrayType.GetName(parameter.AnyTypeOrVarArgs.AsT0.AsT1) | ||
}; | ||
} | ||
|
||
private static string GetAttribute(GirModel.Parameter parameter) | ||
{ | ||
return parameter.AnyTypeOrVarArgs.AsT0.AsT1.Length switch | ||
{ | ||
null => string.Empty, | ||
{ } l => MarshalAs.UnmanagedLpArray(sizeParamIndex: l) | ||
}; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Generation/Generator/Renderer/Internal/Parameter/Converter/Utf8StringArray.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
|
||
namespace Generator.Renderer.Internal.Parameter; | ||
|
||
internal class Utf8StringArray : ParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType anyType) | ||
{ | ||
return anyType.IsArray<GirModel.Utf8String>(); | ||
} | ||
|
||
public RenderableParameter Convert(GirModel.Parameter parameter) | ||
{ | ||
return new RenderableParameter( | ||
Attribute: string.Empty, | ||
Direction: GetAttribute(parameter), | ||
NullableTypeName: GetNullableTypeName(parameter), | ||
Name: Model.Parameter.GetName(parameter) | ||
); | ||
} | ||
|
||
private static string GetNullableTypeName(GirModel.Parameter parameter) | ||
{ | ||
return parameter switch | ||
{ | ||
{ Transfer: GirModel.Transfer.None, AnyTypeOrVarArgs.AsT0.AsT1.Length: null } => Model.Utf8StringArray.GetInternalHandleName(), | ||
{ Transfer: GirModel.Transfer.Full, AnyTypeOrVarArgs.AsT0.AsT1.Length: null } => Model.Utf8StringArray.GetInternalUnownedHandleName(), | ||
{ Transfer: GirModel.Transfer.Container, AnyTypeOrVarArgs.AsT0.AsT1.Length: null } => throw new Exception("Transfer container not supported for utf8 string arrays"), | ||
{ AnyTypeOrVarArgs.AsT0.AsT1.Length: not null} => Model.ArrayType.GetName(parameter.AnyTypeOrVarArgs.AsT0.AsT1), | ||
_ => throw new Exception("Can't detect typename for utf8 string array") | ||
}; | ||
} | ||
|
||
private static string GetAttribute(GirModel.Parameter parameter) | ||
{ | ||
return parameter.AnyTypeOrVarArgs.AsT0.AsT1.Length switch | ||
{ | ||
null => string.Empty, | ||
{ } l => MarshalAs.UnmanagedLpArray(sizeParamIndex: l) | ||
}; | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ternal/Parameter/Converter/StringArray.cs → ...eter/Converter/Utf8StringArrayCallback.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...Generator/Renderer/Internal/ParameterToManagedExpression/Converter/PlatformStringArray.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Renderer.Internal.ParameterToManagedExpressions; | ||
|
||
internal class PlatformStringArray : ToManagedParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType type) | ||
=> type.IsArray<GirModel.PlatformString>(); | ||
|
||
public void Initialize(ParameterToManagedData parameterData, IEnumerable<ParameterToManagedData> parameters) | ||
{ | ||
var arrayType = parameterData.Parameter.AnyTypeOrVarArgs.AsT0.AsT1; | ||
if (arrayType.Length is null) | ||
NullTerminatedArray(parameterData); | ||
else | ||
SizeBasedArray(parameterData); | ||
} | ||
|
||
private static void NullTerminatedArray(ParameterToManagedData parameterData) | ||
{ | ||
var signatureName = Model.Parameter.GetName(parameterData.Parameter); | ||
var callName = Model.Parameter.GetConvertedName(parameterData.Parameter); | ||
|
||
var handleExpression = parameterData.Parameter switch | ||
{ | ||
{ Transfer: GirModel.Transfer.None } => $"new {Model.PlatformStringArray.GetInternalUnownedHandleName()}({signatureName}).ConvertToStringArray()", | ||
{ Transfer: GirModel.Transfer.Full } => $"new {Model.PlatformStringArray.GetInternalOwnedHandleName()}({signatureName}).ConvertToStringArray()", | ||
_ => throw new Exception("Unknown transfer type for platform string array to managed expression") | ||
}; | ||
|
||
parameterData.SetSignatureName(signatureName); | ||
parameterData.SetExpression($"var {callName} = {handleExpression};"); | ||
parameterData.SetCallName(callName); | ||
} | ||
|
||
private static void SizeBasedArray(ParameterToManagedData parameterData) | ||
{ | ||
var variableName = Model.Parameter.GetName(parameterData.Parameter); | ||
|
||
parameterData.SetSignatureName(variableName); | ||
parameterData.SetCallName(variableName); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
...eration/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/StringArray.cs
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
...ion/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/Utf8StringArray.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Renderer.Internal.ParameterToManagedExpressions; | ||
|
||
internal class Utf8StringArray : ToManagedParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType type) | ||
=> type.IsArray<GirModel.Utf8String>(); | ||
|
||
public void Initialize(ParameterToManagedData parameterData, IEnumerable<ParameterToManagedData> parameters) | ||
{ | ||
var arrayType = parameterData.Parameter.AnyTypeOrVarArgs.AsT0.AsT1; | ||
if (arrayType.Length is null) | ||
NullTerminatedArray(parameterData); | ||
else | ||
SizeBasedArray(parameterData); | ||
} | ||
|
||
private static void NullTerminatedArray(ParameterToManagedData parameterData) | ||
{ | ||
var signatureName = Model.Parameter.GetName(parameterData.Parameter); | ||
var callName = Model.Parameter.GetConvertedName(parameterData.Parameter); | ||
|
||
var handleExpression = parameterData.Parameter switch | ||
{ | ||
{ Transfer: GirModel.Transfer.None } => $"new {Model.Utf8StringArray.GetInternalUnownedHandleName()}({signatureName}).ConvertToStringArray()", | ||
{ Transfer: GirModel.Transfer.Full } => $"new {Model.Utf8StringArray.GetInternalOwnedHandleName()}({signatureName}).ConvertToStringArray()", | ||
_ => throw new Exception("Unknown transfer type for utf8 string array to managed expression") | ||
}; | ||
|
||
parameterData.SetSignatureName(signatureName); | ||
parameterData.SetExpression($"var {callName} = {handleExpression};"); | ||
parameterData.SetCallName(callName); | ||
} | ||
|
||
private static void SizeBasedArray(ParameterToManagedData parameterData) | ||
{ | ||
var variableName = Model.Parameter.GetName(parameterData.Parameter); | ||
|
||
parameterData.SetSignatureName(variableName); | ||
parameterData.SetCallName(variableName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Generation/Generator/Renderer/Internal/ReturnType/Converter/PlatformStringArray.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
|
||
namespace Generator.Renderer.Internal.ReturnType; | ||
|
||
internal class PlatformStringArray : ReturnTypeConverter | ||
{ | ||
public bool Supports(GirModel.ReturnType returnType) | ||
{ | ||
return returnType.AnyType.IsArray<GirModel.PlatformString>(); | ||
} | ||
|
||
public RenderableReturnType Convert(GirModel.ReturnType returnType) | ||
{ | ||
var arrayType = returnType.AnyType.AsT1; | ||
|
||
var nullableTypeName = arrayType.Length is null | ||
? NullTerminatedArray(returnType) | ||
: SizeBasedArray(); | ||
|
||
return new RenderableReturnType(nullableTypeName); | ||
} | ||
|
||
private static string NullTerminatedArray(GirModel.ReturnType returnType) | ||
{ | ||
return returnType switch | ||
{ | ||
{ Transfer: GirModel.Transfer.Full } => Model.PlatformStringArray.GetInternalOwnedHandleName(), | ||
{ Transfer: GirModel.Transfer.None } => Model.PlatformStringArray.GetInternalUnownedHandleName(), | ||
{ Transfer: GirModel.Transfer.Container } => Model.PlatformStringArray.GetInternalContainerHandleName(), | ||
_ => throw new Exception("Unknown transfer type for platform string array return value") | ||
}; | ||
} | ||
|
||
private static string SizeBasedArray() | ||
{ | ||
return "string[]"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...eration/Generator/Renderer/Internal/ReturnType/Converter/PlatformStringArrayInCallback.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Generator.Renderer.Internal.ReturnType; | ||
|
||
internal class PlatformStringArrayInCallback : ReturnTypeConverter | ||
{ | ||
public bool Supports(GirModel.ReturnType returnType) | ||
{ | ||
return returnType.AnyType.IsArray<GirModel.PlatformString>(); | ||
} | ||
|
||
public RenderableReturnType Convert(GirModel.ReturnType returnType) | ||
{ | ||
var arrayType = returnType.AnyType.AsT1; | ||
var isMarshalAble = returnType.Transfer != GirModel.Transfer.None || arrayType.Length != null; | ||
var nullableTypeName = isMarshalAble | ||
? Model.ArrayType.GetName(arrayType) | ||
: Model.Type.Pointer; | ||
|
||
return new RenderableReturnType(nullableTypeName); | ||
} | ||
} |
Oops, something went wrong.