-
Notifications
You must be signed in to change notification settings - Fork 30
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
19 changed files
with
250 additions
and
24 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/Generation/Generator/Generator/Internal/ForeignUntypedRecordHandle.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,29 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Generator.Internal; | ||
|
||
internal class ForeignUntypedRecordHandle : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public ForeignUntypedRecordHandle(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record obj) | ||
{ | ||
if (!Record.IsForeignUntyped(obj)) | ||
return; | ||
|
||
var source = Renderer.Internal.ForeignUntypedRecordHandle.Render(obj); | ||
var codeUnit = new CodeUnit( | ||
Project: Namespace.GetCanonicalName(obj.Namespace), | ||
Name: Model.ForeignTypedRecord.GetInternalHandle(obj), | ||
Source: source, | ||
IsInternal: true | ||
); | ||
|
||
_publisher.Publish(codeUnit); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Generation/Generator/Generator/Public/ForeignUntypedRecord.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,29 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Generator.Public; | ||
|
||
internal class ForeignUntypedRecord : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public ForeignUntypedRecord(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record record) | ||
{ | ||
if (!Record.IsForeignUntyped(record)) | ||
return; | ||
|
||
var source = Renderer.Public.ForeignUntypedRecord.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Generator.Model; | ||
|
||
internal static class ForeignUntypedRecord | ||
{ | ||
public static string GetPublicClassName(GirModel.Record record) | ||
=> record.Name; | ||
|
||
public static string GetFullyQualifiedPublicClassName(GirModel.Record record) | ||
=> Namespace.GetPublicName(record.Namespace) + "." + GetPublicClassName(record); | ||
|
||
public static string GetFullyQualifiedInternalClassName(GirModel.Record record) | ||
=> Namespace.GetInternalName(record.Namespace) + "." + record.Name; | ||
|
||
public static string GetInternalHandle(GirModel.Record record) | ||
=> $"{Type.GetName(record)}Handle"; | ||
|
||
public static string GetInternalOwnedHandle(GirModel.Record record) | ||
=> $"{Type.GetName(record)}OwnedHandle"; | ||
|
||
public static string GetInternalUnownedHandle(GirModel.Record record) | ||
=> $"{Type.GetName(record)}UnownedHandle"; | ||
|
||
public static string GetFullyQuallifiedInternalHandle(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalHandle(record)}"; | ||
|
||
public static string GetFullyQuallifiedOwnedHandle(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalOwnedHandle(record)}"; | ||
|
||
public static string GetFullyQuallifiedUnownedHandle(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalUnownedHandle(record)}"; | ||
|
||
public static string GetFullyQuallifiedNullHandle(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalUnownedHandle(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
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
74 changes: 74 additions & 0 deletions
74
src/Generation/Generator/Renderer/Internal/ForeignUntypedRecordHandle.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,74 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Renderer.Internal; | ||
|
||
internal static class ForeignUntypedRecordHandle | ||
{ | ||
public static string Render(GirModel.Record record) | ||
{ | ||
var typeName = Model.ForeignUntypedRecord.GetInternalHandle(record); | ||
var unownedHandleTypeName = Model.ForeignUntypedRecord.GetInternalUnownedHandle(record); | ||
var ownedHandleTypeName = Model.ForeignUntypedRecord.GetInternalOwnedHandle(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 abstract class {typeName} : SafeHandle | ||
{{ | ||
public sealed override bool IsInvalid => handle == IntPtr.Zero; | ||
protected {typeName}(bool ownsHandle) : base(IntPtr.Zero, ownsHandle) {{ }} | ||
}} | ||
public class {unownedHandleTypeName} : {typeName} | ||
{{ | ||
private static {unownedHandleTypeName}? nullHandle; | ||
public static {unownedHandleTypeName} NullHandle => nullHandle ??= new {unownedHandleTypeName}(); | ||
/// <summary> | ||
/// Creates a new instance of {unownedHandleTypeName}. Used automatically by PInvoke. | ||
/// </summary> | ||
internal {unownedHandleTypeName}() : base(false) {{ }} | ||
/// <summary> | ||
/// Creates a new instance of {unownedHandleTypeName}. Assumes that the given pointer is unowned by the runtime. | ||
/// </summary> | ||
public {unownedHandleTypeName}(IntPtr ptr) : base(false) | ||
{{ | ||
SetHandle(ptr); | ||
}} | ||
protected override bool ReleaseHandle() | ||
{{ | ||
throw new System.Exception(""UnownedHandle must not be freed""); | ||
}} | ||
}} | ||
public partial class {ownedHandleTypeName} : {typeName} | ||
{{ | ||
/// <summary> | ||
/// Creates a new instance of {ownedHandleTypeName}. Used automatically by PInvoke. | ||
/// </summary> | ||
internal {ownedHandleTypeName}() : base(true) {{ }} | ||
/// <summary> | ||
/// Creates a new instance of {ownedHandleTypeName}. Assumes that the given pointer is owned by the runtime. | ||
/// </summary> | ||
public {ownedHandleTypeName}(IntPtr ptr) : base(true) | ||
{{ | ||
SetHandle(ptr); | ||
}} | ||
protected override partial bool ReleaseHandle(); | ||
}}"; | ||
} | ||
} |
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/Public/ForeignUntypedRecord.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; | ||
using System.Linq; | ||
using Generator.Model; | ||
|
||
namespace Generator.Renderer.Public; | ||
|
||
internal static class ForeignUntypedRecord | ||
{ | ||
public static string Render(GirModel.Record record) | ||
{ | ||
var name = Model.ForeignUntypedRecord.GetPublicClassName(record); | ||
var internalHandleName = Model.ForeignUntypedRecord.GetFullyQuallifiedOwnedHandle(record); | ||
|
||
return $@" | ||
using System; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
#nullable enable | ||
namespace {Namespace.GetPublicName(record.Namespace)}; | ||
// AUTOGENERATED FILE - DO NOT MODIFY | ||
{PlatformSupportAttribute.Render(record as GirModel.PlatformDependent)} | ||
public partial class {name} | ||
{{ | ||
public {internalHandleName} Handle {{ get; }} | ||
public {name}({internalHandleName} handle) | ||
{{ | ||
Handle = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
namespace Cairo.Internal; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
public partial class MatrixOwnedHandle : MatrixHandle | ||
namespace Cairo.Internal; | ||
|
||
public partial class MatrixOwnedHandle | ||
{ | ||
public static MatrixOwnedHandle Create() | ||
{ | ||
var size = Marshal.SizeOf<MatrixData>(); | ||
var ptr = GLib.Functions.Malloc((nuint) size); | ||
|
||
var str = new MatrixData(); | ||
Marshal.StructureToPtr(str, ptr, false); | ||
|
||
return new MatrixOwnedHandle(ptr); | ||
} | ||
|
||
protected override partial bool ReleaseHandle() | ||
{ | ||
// There isn't any cleanup method for Cairo.Matrix. These are always | ||
// allocated and owned by the caller (i.e. MatrixManagedHandle) | ||
throw new System.Exception("Can't free native handle of type \"cairo.Internal.MatrixOwnedHandle\"."); | ||
GLib.Functions.Free(handle); | ||
return true; | ||
} | ||
} |
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