Skip to content

Commit

Permalink
Fix generator to generate updated gir files
Browse files Browse the repository at this point in the history
  • Loading branch information
badcel committed Nov 13, 2023
1 parent f949b7b commit 6439904
Show file tree
Hide file tree
Showing 18 changed files with 484 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace {Namespace.GetInternalName(callback.Namespace)}
}
catch (Exception ex)
{
Log.Warning($"Did not generate callback delegatre '{callback.Name}': {ex.Message}");
Log.Warning($"Did not generate callback delegate '{callback.Name}': {ex.Message}");

return string.Empty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal static class CallbackParameters
new Parameter.RecordGLibPtrArray(),
new Parameter.String(),
new Parameter.Union(),
new Parameter.UnionArray(),
new Parameter.UnsignedPointer(),
new Parameter.Utf8StringArrayCallback(),
new Parameter.Void(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Generator.Renderer.Internal.Parameter;

internal class UnionArray : ParameterConverter
{
public bool Supports(GirModel.AnyType anyType)
{
return anyType.IsArray<GirModel.Union>();
}

public RenderableParameter Convert(GirModel.Parameter parameter)
{
if (parameter.AnyTypeOrVarArgs.AsT0.AsT1.IsPointer)
return PointerArray(parameter);

return DataArray(parameter);
}

private static RenderableParameter PointerArray(GirModel.Parameter parameter)
{
return new RenderableParameter(
Attribute: string.Empty,
Direction: string.Empty,
NullableTypeName: $"ref {Model.Type.Pointer}",
Name: Model.Parameter.GetName(parameter)
);
}

private static RenderableParameter DataArray(GirModel.Parameter parameter)
{
var union = (GirModel.Union) parameter.AnyTypeOrVarArgs.AsT0.AsT1.AnyType.AsT0;

return new RenderableParameter(
Attribute: string.Empty,
Direction: string.Empty,
NullableTypeName: Model.Union.GetFullyQualifiedInternalStructName(union) + "[]",
Name: Model.Parameter.GetName(parameter)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal static class Parameters
new Parameter.String(),
new Parameter.StringGLibPtrArray(),
new Parameter.Union(),
new Parameter.UnionArray(),
new Parameter.UnsignedPointer(),
new Parameter.Utf8StringArray(),
new Parameter.Void(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using GirModel;

namespace Generator.Renderer.Internal.ParameterToManagedExpressions;

Expand Down Expand Up @@ -27,12 +28,31 @@ private static void ErrorRecord(ParameterToManagedData parameterData)

private static void RegularRecord(ParameterToManagedData parameterData)
{
if (parameterData.Parameter.Direction != GirModel.Direction.In)
throw new NotImplementedException($"{parameterData.Parameter.AnyTypeOrVarArgs}: record with direction != in not yet supported");

if (!parameterData.Parameter.IsPointer)
throw new NotImplementedException($"Unpointed record parameter {parameterData.Parameter.Name} ({parameterData.Parameter.AnyTypeOrVarArgs}) can not yet be converted to managed");

switch (parameterData.Parameter.Direction)
{
case Direction.In:
InRecord(parameterData);
break;
case Direction.Out:
OutRecord(parameterData);
break;
default:
throw new NotImplementedException($"{parameterData.Parameter.AnyTypeOrVarArgs}: record with direction {parameterData.Parameter.Direction} not yet supported");
}
}

private static void OutRecord(ParameterToManagedData parameterData)
{
var parameterName = Model.Parameter.GetName(parameterData.Parameter);
parameterData.SetSignatureName(parameterName);
parameterData.SetCallName("out " + parameterName);
}

private static void InRecord(ParameterToManagedData parameterData)
{
var record = (GirModel.Record) parameterData.Parameter.AnyTypeOrVarArgs.AsT0.AsT0;
var ownedHandle = parameterData.Parameter.Transfer == GirModel.Transfer.Full;
var variableName = Model.Parameter.GetConvertedName(parameterData.Parameter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Generator.Renderer.Public.Parameter;
using System;

namespace Generator.Renderer.Public.Parameter;

internal class Record : ParameterConverter
{
Expand All @@ -8,24 +10,30 @@ public bool Supports(GirModel.AnyType anyType)
}

public ParameterTypeData Create(GirModel.Parameter parameter)
{
return parameter.Direction switch
{
GirModel.Direction.In => InRecord(parameter),
GirModel.Direction.Out => OutRecord(parameter),
_ => throw new Exception($"Unsupported record direction {parameter.Direction}")
};
}

private ParameterTypeData OutRecord(GirModel.Parameter parameter)
{
return new ParameterTypeData(
Direction: GetDirection(parameter),
NullableTypeName: GetNullableTypeName(parameter)
Direction: ParameterDirection.Out(),
NullableTypeName: Model.Type.Pointer
);
}

private static string GetNullableTypeName(GirModel.Parameter parameter)
private static ParameterTypeData InRecord(GirModel.Parameter parameter)
{
var type = (GirModel.Record) parameter.AnyTypeOrVarArgs.AsT0.AsT0;
return Model.ComplexType.GetFullyQualified(type) + Nullable.Render(parameter);

return new ParameterTypeData(
Direction: ParameterDirection.In(),
NullableTypeName: Model.ComplexType.GetFullyQualified(type) + Nullable.Render(parameter)
);
}

private static string GetDirection(GirModel.Parameter parameter) => parameter switch
{
{ Direction: GirModel.Direction.InOut } => ParameterDirection.Ref(),
{ Direction: GirModel.Direction.Out, CallerAllocates: true } => ParameterDirection.Ref(),
{ Direction: GirModel.Direction.Out } => ParameterDirection.Out(),
_ => ParameterDirection.In()
};
}
29 changes: 29 additions & 0 deletions src/Libs/Gdk-4.0/Internal/DragSurfaceSizeHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Gdk.Internal;

public partial class DragSurfaceSizeHandle
{
public partial DragSurfaceSizeOwnedHandle OwnedCopy()
{
throw new NotImplementedException();
}

public partial DragSurfaceSizeUnownedHandle UnownedCopy()
{
throw new NotImplementedException();
}
}

public partial class DragSurfaceSizeOwnedHandle
{
public static partial DragSurfaceSizeOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotImplementedException();
}

protected override partial bool ReleaseHandle()
{
throw new NotImplementedException();
}
}
29 changes: 29 additions & 0 deletions src/Libs/Gst-1.0/Internal/DebugMessageHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Gst.Internal;

public partial class DebugMessageHandle
{
public partial DebugMessageOwnedHandle OwnedCopy()
{
throw new NotImplementedException();
}

public partial DebugMessageUnownedHandle UnownedCopy()
{
throw new NotImplementedException();
}
}

public partial class DebugMessageOwnedHandle
{
public static partial DebugMessageOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotImplementedException();
}

protected override partial bool ReleaseHandle()
{
throw new NotImplementedException();
}
}
34 changes: 34 additions & 0 deletions src/Libs/Gst-1.0/Internal/PollHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Runtime.InteropServices;

namespace Gst.Internal;

public partial class PollHandle
{
public partial PollOwnedHandle OwnedCopy()
{
throw new NotImplementedException();
}

public partial PollUnownedHandle UnownedCopy()
{
throw new NotImplementedException();
}
}

public partial class PollOwnedHandle
{
[DllImport(ImportResolver.Library, EntryPoint = "gst_poll_free")]
private static extern void Free(IntPtr set);

public static partial PollOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotImplementedException();
}

protected override partial bool ReleaseHandle()
{
Free(handle);
return true;
}
}
34 changes: 34 additions & 0 deletions src/Libs/GstAudio-1.0/Internal/AudioChannelMixerHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Runtime.InteropServices;

namespace GstAudio.Internal;

public partial class AudioChannelMixerHandle
{
public partial AudioChannelMixerOwnedHandle OwnedCopy()
{
throw new NotImplementedException();
}

public partial AudioChannelMixerUnownedHandle UnownedCopy()
{
throw new NotImplementedException();
}
}

public partial class AudioChannelMixerOwnedHandle
{
[DllImport(ImportResolver.Library, EntryPoint = "gst_audio_channel_mixer_free")]
private static extern void Free(IntPtr data);

Check warning on line 23 in src/Libs/GstAudio-1.0/Internal/AudioChannelMixerHandle.cs

View workflow job for this annotation

GitHub Actions / Build (Linux)

Fix formatting
public static partial AudioChannelMixerOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotImplementedException();
}

protected override partial bool ReleaseHandle()
{
Free(handle);
return true;
}
}
34 changes: 34 additions & 0 deletions src/Libs/GstAudio-1.0/Internal/AudioQuantizeHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Runtime.InteropServices;

namespace GstAudio.Internal;

public partial class AudioQuantizeHandle
{
public partial AudioQuantizeOwnedHandle OwnedCopy()
{
throw new NotImplementedException();
}

public partial AudioQuantizeUnownedHandle UnownedCopy()
{
throw new NotImplementedException();
}
}

public partial class AudioQuantizeOwnedHandle
{
[DllImport(ImportResolver.Library, EntryPoint = "gst_audio_quantize_free")]
private static extern void Free(IntPtr data);

Check warning on line 23 in src/Libs/GstAudio-1.0/Internal/AudioQuantizeHandle.cs

View workflow job for this annotation

GitHub Actions / Build (Linux)

Fix formatting
public static partial AudioQuantizeOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotImplementedException();
}

protected override partial bool ReleaseHandle()
{
Free(handle);
return true;
}
}
34 changes: 34 additions & 0 deletions src/Libs/GstAudio-1.0/Internal/AudioResamplerHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Runtime.InteropServices;

namespace GstAudio.Internal;

public partial class AudioResamplerHandle
{
public partial AudioResamplerOwnedHandle OwnedCopy()
{
throw new NotImplementedException();
}

public partial AudioResamplerUnownedHandle UnownedCopy()
{
throw new NotImplementedException();
}
}

public partial class AudioResamplerOwnedHandle
{
[DllImport(ImportResolver.Library, EntryPoint = "gst_audio_resampler_free")]
private static extern void Free(IntPtr data);

Check warning on line 23 in src/Libs/GstAudio-1.0/Internal/AudioResamplerHandle.cs

View workflow job for this annotation

GitHub Actions / Build (Linux)

Fix formatting
public static partial AudioResamplerOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotImplementedException();
}

protected override partial bool ReleaseHandle()
{
Free(handle);
return true;
}
}
34 changes: 34 additions & 0 deletions src/Libs/GstBase-1.0/Internal/QueueArrayHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Runtime.InteropServices;

namespace GstBase.Internal;

public partial class QueueArrayHandle
{
public partial QueueArrayOwnedHandle OwnedCopy()
{
throw new NotImplementedException();
}

public partial QueueArrayUnownedHandle UnownedCopy()
{
throw new NotImplementedException();
}
}

public partial class QueueArrayOwnedHandle
{
[DllImport(ImportResolver.Library, EntryPoint = "gst_queue_array_free")]
private static extern void Free(IntPtr array);

Check warning on line 23 in src/Libs/GstBase-1.0/Internal/QueueArrayHandle.cs

View workflow job for this annotation

GitHub Actions / Build (Linux)

Fix formatting
public static partial QueueArrayOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotImplementedException();
}

protected override partial bool ReleaseHandle()
{
Free(handle);
return true;
}
}
Loading

0 comments on commit 6439904

Please sign in to comment.