-
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
26 changed files
with
262 additions
and
52 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/Generation/Generator/Generator/Internal/OpaqueRecordHandle.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 OpaqueRecordHandle : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public OpaqueRecordHandle(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record obj) | ||
{ | ||
if (!obj.Opaque) | ||
return; | ||
|
||
if (obj.TypeFunction is null) | ||
return; | ||
|
||
var source = Renderer.Internal.OpaqueRecordHandle.Render(obj); | ||
var codeUnit = new CodeUnit( | ||
Project: Namespace.GetCanonicalName(obj.Namespace), | ||
Name: Model.OpaqueRecord.GetInternalHandle(obj), | ||
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
67 changes: 67 additions & 0 deletions
67
src/Generation/Generator/Renderer/Internal/OpaqueRecordHandle.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,67 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Renderer.Internal; | ||
|
||
internal static class OpaqueRecordHandle | ||
{ | ||
public static string Render(GirModel.Record record) | ||
{ | ||
var typeName = Model.OpaqueRecord.GetInternalHandle(record); | ||
var initiallyUnownedHandleTypeName = Model.OpaqueRecord.GetInternalInitiallyUnownedHandle(record); | ||
var ownedHandleTypeName = Model.OpaqueRecord.GetInternalOwnedHandle(record); | ||
var nullHandleTypeName = Model.OpaqueRecord.GetInternalNullHandle(record); | ||
var getGType = Model.OpaqueRecord.GetFullyQualifiedInternalClassName(record) + ".GetGType()"; | ||
|
||
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 {typeName} : SafeHandle | ||
{{ | ||
public sealed override bool IsInvalid => handle == IntPtr.Zero; | ||
protected {typeName}(bool ownsHandle) : base(IntPtr.Zero, ownsHandle) {{ }} | ||
protected override bool ReleaseHandle() | ||
{{ | ||
GLib.Internal.Functions.BoxedFree({getGType}, handle); | ||
return true; | ||
}} | ||
public {typeName} Copy() | ||
{{ | ||
var ptr = GLib.Internal.Functions.BoxedCopy({getGType}, handle); | ||
var obj = new {typeName}(true); | ||
obj.SetHandle(ptr); | ||
return obj; | ||
}} | ||
}} | ||
public class {initiallyUnownedHandleTypeName} : {typeName} | ||
{{ | ||
//Constructor for PInvoke | ||
private {initiallyUnownedHandleTypeName}() : base(false) {{ }} | ||
}} | ||
public class {ownedHandleTypeName} : {typeName} | ||
{{ | ||
//Constructor for PInvoke | ||
private {ownedHandleTypeName}() : base(true) {{ }} | ||
}} | ||
public class {nullHandleTypeName} : {typeName} | ||
{{ | ||
public static {nullHandleTypeName} Instance = new (); | ||
private {nullHandleTypeName}() : base(false) {{ }} | ||
}}"; | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
...ration/Generator/Renderer/Internal/ParameterToManagedExpression/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,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Renderer.Internal.ParameterToManagedExpressions; | ||
|
||
internal class OpaqueRecord : ToManagedParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType type) | ||
=> type.Is<GirModel.Record>(out var record) && record is { Opaque: true, TypeFunction: not null }; | ||
|
||
public void Initialize(ParameterToManagedData parameterData, IEnumerable<ParameterToManagedData> parameters) | ||
{ | ||
if (parameterData.Parameter.Direction != GirModel.Direction.In) | ||
throw new NotImplementedException($"{parameterData.Parameter.AnyTypeOrVarArgs}: opaque record with direction != in not yet supported"); | ||
|
||
var record = (GirModel.Record) parameterData.Parameter.AnyTypeOrVarArgs.AsT0.AsT0; | ||
var variableName = Model.Parameter.GetConvertedName(parameterData.Parameter); | ||
|
||
var signatureName = Model.Parameter.GetName(parameterData.Parameter); | ||
|
||
parameterData.SetSignatureName(signatureName); | ||
parameterData.SetExpression($"var {variableName} = new {Model.OpaqueRecord.GetFullyQualifiedPublicClassName(record)}({signatureName});"); | ||
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
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/ReturnType/Converter/OpaqueRecordCallback.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 @@ | ||
using GirModel; | ||
|
||
namespace Generator.Renderer.Internal.ReturnType; | ||
|
||
internal class OpaqueRecordCallback : ReturnTypeConverter | ||
{ | ||
public bool Supports(GirModel.ReturnType returnType) | ||
{ | ||
return returnType.AnyType.Is<GirModel.Record>(out var record) && record is { Opaque: true, TypeFunction: not null }; | ||
} | ||
|
||
public RenderableReturnType Convert(GirModel.ReturnType returnType) | ||
{ | ||
var type = (GirModel.Record) returnType.AnyType.AsT0; | ||
var typeName = Model.OpaqueRecord.GetFullyQuallifiedInternalHandle(type); | ||
|
||
return new RenderableReturnType(typeName + Nullable.Render(returnType)); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
...ration/Generator/Renderer/Internal/ReturnTypeToNativeExpression/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,12 @@ | ||
using GirModel; | ||
|
||
namespace Generator.Renderer.Internal.ReturnTypeToNativeExpressions; | ||
|
||
internal class OpaqueRecord : ReturnTypeConverter | ||
{ | ||
public bool Supports(AnyType type) | ||
=> type.Is<GirModel.Record>(out var record) && record is { Opaque: true, TypeFunction: not null }; | ||
|
||
public string GetString(GirModel.ReturnType returnType, string fromVariableName) | ||
=> fromVariableName + ".Handle"; | ||
} |
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
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.