-
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
67 changed files
with
589 additions
and
125 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/Generation/Generator/Generator/Internal/OpaqueRecord.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,32 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Generator.Internal; | ||
|
||
internal class OpaqueRecord : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public OpaqueRecord(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record obj) | ||
{ | ||
if (!obj.Opaque) | ||
return; | ||
|
||
if (obj.TypeFunction is null) | ||
return; | ||
|
||
var source = Renderer.Internal.OpaqueRecord.Render(obj); | ||
var codeUnit = new CodeUnit( | ||
Project: Namespace.GetCanonicalName(obj.Namespace), | ||
Name: obj.Name, | ||
Source: source, | ||
IsInternal: true | ||
); | ||
|
||
_publisher.Publish(codeUnit); | ||
} | ||
} |
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
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
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
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,32 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Generator.Public; | ||
|
||
internal class OpaqueRecord : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public OpaqueRecord(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record record) | ||
{ | ||
if (!record.Opaque) | ||
return; | ||
|
||
if (record.TypeFunction is null) | ||
return; | ||
|
||
var source = Renderer.Public.OpaqueRecord.Render(record); | ||
var codeUnit = new CodeUnit( | ||
Project: Namespace.GetCanonicalName(record.Namespace), | ||
Name: Record.GetPublicClassName(record), | ||
Source: source, | ||
IsInternal: false | ||
); | ||
|
||
_publisher.Publish(codeUnit); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Generator.Model; | ||
|
||
internal static class OpaqueRecord | ||
{ | ||
public static string GetBoxedHandle(GirModel.Record record) | ||
=> $"GLib.Internal.BoxedHandle<{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}>"; | ||
|
||
public static string GetOwnedBoxedHandle(GirModel.Record record) | ||
=> $"GLib.Internal.OwnedBoxedHandle<{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}>"; | ||
|
||
public static string GetInitiallyUnownedBoxedHandle(GirModel.Record record) | ||
=> $"GLib.Internal.InitiallyUnownedBoxedHandle<{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}>"; | ||
|
||
public static string GetNullBoxedHandle(GirModel.Record record) | ||
=> $"GLib.Internal.BoxedHandle<{Namespace.GetInternalName(record.Namespace)}.{Type.GetName(record)}>.NullHandle"; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/Generation/Generator/Renderer/Internal/InstanceParameter/Converter/OpaqueRecord.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,19 @@ | ||
namespace Generator.Renderer.Internal.InstanceParameter; | ||
|
||
internal class OpaqueRecord : InstanceParameterConverter | ||
{ | ||
public bool Supports(GirModel.Type type) | ||
{ | ||
return type is GirModel.Record { Opaque: true, TypeFunction: not null } ; | ||
} | ||
|
||
public RenderableInstanceParameter Convert(GirModel.InstanceParameter instanceParameter) | ||
{ | ||
var type = (GirModel.Record) instanceParameter.Type; | ||
|
||
return new RenderableInstanceParameter( | ||
Name: Model.InstanceParameter.GetName(instanceParameter), | ||
NullableTypeName: Model.OpaqueRecord.GetBoxedHandle(type) | ||
); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/Generation/Generator/Renderer/Internal/OpaqueRecord.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,37 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Renderer.Internal; | ||
|
||
internal static class OpaqueRecord | ||
{ | ||
public static string Render(GirModel.Record record) | ||
{ | ||
return $@" | ||
using System; | ||
using GObject; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
#nullable enable | ||
namespace {Namespace.GetInternalName(record.Namespace)}; | ||
// AUTOGENERATED FILE - DO NOT MODIFY | ||
{PlatformSupportAttribute.Render(record as GirModel.PlatformDependent)} | ||
public partial class {record.Name} {RenderNativeGTypeProvider(record)} | ||
{{ | ||
{Functions.Render(record.TypeFunction)} | ||
{Functions.Render(record.Functions)} | ||
{Methods.Render(record.Methods)} | ||
{Constructors.Render(record.Constructors)} | ||
}}"; | ||
} | ||
|
||
private static string RenderNativeGTypeProvider(GirModel.Record record) | ||
{ | ||
return record.TypeFunction is not null | ||
? ": GLib.Internal.NativeGTypeProvider" | ||
: string.Empty; | ||
} | ||
} |
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/Parameter/Converter/OpaqueRecord.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 OpaqueRecord : ParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType anyType) | ||
{ | ||
return anyType.Is<GirModel.Record>(out var record) && record is { Opaque: true, TypeFunction: not null }; | ||
} | ||
|
||
public RenderableParameter Convert(GirModel.Parameter parameter) | ||
{ | ||
return new RenderableParameter( | ||
Attribute: string.Empty, | ||
Direction: GetDirection(parameter), | ||
NullableTypeName: GetNullableTypeName(parameter), | ||
Name: Model.Parameter.GetName(parameter) | ||
); | ||
} | ||
|
||
//Native records are represented as SafeHandles and are not nullable | ||
private static string GetNullableTypeName(GirModel.Parameter parameter) | ||
{ | ||
var type = (GirModel.Record) parameter.AnyTypeOrVarArgs.AsT0.AsT0; | ||
return parameter switch | ||
{ | ||
{ Direction: GirModel.Direction.In, Transfer: GirModel.Transfer.None } => Model.OpaqueRecord.GetBoxedHandle(type) + Nullable.Render(parameter), | ||
_ => throw new System.Exception($"Can't detect parameter type: CallerAllocates={parameter.CallerAllocates} Direction={parameter.Direction} Transfer={parameter.Transfer}") | ||
}; | ||
} | ||
|
||
private static string GetDirection(GirModel.Parameter parameter) => parameter switch | ||
{ | ||
{ Direction: GirModel.Direction.InOut } => ParameterDirection.In(), | ||
{ Direction: GirModel.Direction.Out, CallerAllocates: true } => ParameterDirection.In(), | ||
{ Direction: GirModel.Direction.Out } => ParameterDirection.Out(), | ||
_ => ParameterDirection.In() | ||
}; | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Generation/Generator/Renderer/Internal/Parameter/Converter/OpaqueRecordArray.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,37 @@ | ||
using System; | ||
|
||
namespace Generator.Renderer.Internal.Parameter; | ||
|
||
internal class OpaqueRecordArray : ParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType anyType) | ||
{ | ||
return anyType.IsArray<GirModel.Record>(out var record) && record is { Opaque: true, TypeFunction: not null }; | ||
; | ||
} | ||
|
||
public RenderableParameter Convert(GirModel.Parameter parameter) | ||
{ | ||
if (!parameter.AnyTypeOrVarArgs.AsT0.AsT1.IsPointer) | ||
{ | ||
var record = (GirModel.Record) parameter.AnyTypeOrVarArgs.AsT0.AsT1.AnyType.AsT0; | ||
throw new Exception($"Unpointed opaque record array of type {record.Name} not yet supported"); | ||
} | ||
|
||
return new RenderableParameter( | ||
Attribute: GetAttribute(parameter), | ||
Direction: string.Empty, | ||
NullableTypeName: Model.Type.PointerArray, | ||
Name: Model.Parameter.GetName(parameter) | ||
); | ||
} | ||
|
||
private static string GetAttribute(GirModel.Parameter parameter) | ||
{ | ||
return parameter.AnyTypeOrVarArgs.AsT0.AsT1.Length switch | ||
{ | ||
{ } length => MarshalAs.UnmanagedLpArray(sizeParamIndex: length), | ||
_ => string.Empty, | ||
}; | ||
} | ||
} |
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
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
Oops, something went wrong.