-
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
65 changed files
with
1,876 additions
and
223 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/Generation/Generator/Generator/Internal/TypedRecord.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 TypedRecord : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public TypedRecord(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record obj) | ||
{ | ||
if (!Record.IsTyped(obj)) | ||
return; | ||
|
||
var source = Renderer.Internal.TypedRecord.Render(obj); | ||
var codeUnit = new CodeUnit( | ||
Project: Namespace.GetCanonicalName(obj.Namespace), | ||
Name: obj.Name, | ||
Source: source, | ||
IsInternal: true | ||
); | ||
|
||
_publisher.Publish(codeUnit); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Generation/Generator/Generator/Internal/TypedRecordData.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 TypedRecordData : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public TypedRecordData(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record obj) | ||
{ | ||
if (!Record.IsTyped(obj)) | ||
return; | ||
|
||
var source = Renderer.Internal.TypedRecordData.Render(obj); | ||
var codeUnit = new CodeUnit( | ||
Project: Namespace.GetCanonicalName(obj.Namespace), | ||
Name: Model.TypedRecord.GetDataName(obj), | ||
Source: source, | ||
IsInternal: true | ||
); | ||
|
||
_publisher.Publish(codeUnit); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Generation/Generator/Generator/Internal/TypedRecordDelegates.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,33 @@ | ||
using System.Linq; | ||
using Generator.Model; | ||
|
||
namespace Generator.Generator.Internal; | ||
|
||
internal class TypedRecordDelegates : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public TypedRecordDelegates(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record record) | ||
{ | ||
if (!Record.IsTyped(record)) | ||
return; | ||
|
||
if (!record.Fields.Any(field => field.AnyTypeOrCallback.IsT1)) | ||
return; | ||
|
||
var source = Renderer.Internal.TypedRecordDelegates.Render(record); | ||
var codeUnit = new CodeUnit( | ||
Project: Namespace.GetCanonicalName(record.Namespace), | ||
Name: $"{Model.TypedRecord.GetDataName(record)}.Delegates", | ||
Source: source, | ||
IsInternal: true | ||
); | ||
|
||
_publisher.Publish(codeUnit); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Generation/Generator/Generator/Internal/TypedRecordHandle.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 TypedRecordHandle : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public TypedRecordHandle(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record obj) | ||
{ | ||
if (!Record.IsTyped(obj)) | ||
return; | ||
|
||
var source = Renderer.Internal.TypedRecordHandle.Render(obj); | ||
var codeUnit = new CodeUnit( | ||
Project: Namespace.GetCanonicalName(obj.Namespace), | ||
Name: Model.TypedRecord.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Generator.Public; | ||
|
||
internal class TypedRecord : Generator<GirModel.Record> | ||
{ | ||
private readonly Publisher _publisher; | ||
|
||
public TypedRecord(Publisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
public void Generate(GirModel.Record record) | ||
{ | ||
if (!Record.IsTyped(record)) | ||
return; | ||
|
||
var source = Renderer.Public.TypedRecord.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,80 @@ | ||
using System.Linq; | ||
|
||
namespace Generator.Model; | ||
|
||
internal static class TypedRecord | ||
{ | ||
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 GetFullyQuallifiedHandle(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"; | ||
|
||
public static string GetDataName(GirModel.Record record) | ||
=> $"{Type.GetName(record)}Data"; | ||
|
||
public static string GetFullyQuallifiedDataName(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetDataName(record)}"; | ||
|
||
public static string GetInternalArrayHandle(GirModel.Record record) | ||
{ | ||
var prefix = $"{Type.GetName(record)}Array"; | ||
if (record.Namespace.Records.Select(x => x.Name).Contains(prefix)) | ||
prefix += "2"; | ||
|
||
return $"{prefix}Handle"; | ||
} | ||
|
||
public static string GetFullyQuallifiedArrayHandle(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalArrayHandle(record)}"; | ||
|
||
public static string GetInternalArrayOwnedHandle(GirModel.Record record) | ||
{ | ||
var prefix = $"{Type.GetName(record)}Array"; | ||
if (record.Namespace.Records.Select(x => x.Name).Contains(prefix)) | ||
prefix += "2"; | ||
|
||
return $"{prefix}OwnedHandle"; | ||
} | ||
|
||
public static string GetFullyQuallifiedArrayOwnedHandle(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalArrayOwnedHandle(record)}"; | ||
|
||
public static string GetInternalArrayUnownedHandle(GirModel.Record record) | ||
{ | ||
var prefix = $"{Type.GetName(record)}Array"; | ||
if (record.Namespace.Records.Select(x => x.Name).Contains(prefix)) | ||
prefix += "2"; | ||
return $"{prefix}UnownedHandle"; | ||
} | ||
|
||
public static string GetFullyQuallifiedArrayUnownedHandle(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalArrayUnownedHandle(record)}"; | ||
|
||
public static string GetFullyQuallifiedArrayNullHandle(GirModel.Record record) | ||
=> $"{Namespace.GetInternalName(record.Namespace)}.{GetInternalArrayUnownedHandle(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
18 changes: 18 additions & 0 deletions
18
src/Generation/Generator/Renderer/Internal/Field/Converter/OpaqueTypedRecord.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,18 @@ | ||
namespace Generator.Renderer.Internal.Field; | ||
|
||
internal class OpaqueTypedRecord : FieldConverter | ||
{ | ||
public bool Supports(GirModel.Field field) | ||
{ | ||
return field.AnyTypeOrCallback.TryPickT0(out var anyType, out _) && anyType.Is<GirModel.Record>(out var record) && Model.Record.IsOpaqueTyped(record); | ||
} | ||
|
||
public RenderableField Convert(GirModel.Field field) | ||
{ | ||
return new RenderableField( | ||
Name: Model.Field.GetName(field), | ||
Attribute: null, | ||
NullableTypeName: Model.Type.Pointer | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Generation/Generator/Renderer/Internal/Field/Converter/OpaqueUntypedRecord.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,18 @@ | ||
namespace Generator.Renderer.Internal.Field; | ||
|
||
internal class OpaqueUntypedRecord : FieldConverter | ||
{ | ||
public bool Supports(GirModel.Field field) | ||
{ | ||
return field.AnyTypeOrCallback.TryPickT0(out var anyType, out _) && anyType.Is<GirModel.Record>(out var record) && Model.Record.IsOpaqueUntyped(record); | ||
} | ||
|
||
public RenderableField Convert(GirModel.Field field) | ||
{ | ||
return new RenderableField( | ||
Name: Model.Field.GetName(field), | ||
Attribute: null, | ||
NullableTypeName: Model.Type.Pointer | ||
); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/Generation/Generator/Renderer/Internal/Field/Converter/TypedRecord.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,28 @@ | ||
using Generator.Model; | ||
|
||
namespace Generator.Renderer.Internal.Field; | ||
|
||
internal class TypedRecord : FieldConverter | ||
{ | ||
public bool Supports(GirModel.Field field) | ||
{ | ||
return field.AnyTypeOrCallback.TryPickT0(out var anyType, out _) && anyType.Is<GirModel.Record>(out var record) && Model.Record.IsTyped(record); | ||
} | ||
|
||
public RenderableField Convert(GirModel.Field field) | ||
{ | ||
return new RenderableField( | ||
Name: Model.Field.GetName(field), | ||
Attribute: null, | ||
NullableTypeName: GetNullableTypeName(field) | ||
); | ||
} | ||
|
||
private static string GetNullableTypeName(GirModel.Field field) | ||
{ | ||
var type = (GirModel.Record) field.AnyTypeOrCallback.AsT0.AsT0; | ||
return field.IsPointer | ||
? Type.Pointer | ||
: Model.Record.GetFullyQualifiedInternalStructName(type); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Generation/Generator/Renderer/Internal/Field/Converter/TypedRecordArray.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,33 @@ | ||
namespace Generator.Renderer.Internal.Field; | ||
|
||
internal class TypedRecordArray : FieldConverter | ||
{ | ||
public bool Supports(GirModel.Field field) | ||
{ | ||
return field.AnyTypeOrCallback.TryPickT0(out var anyType, out _) && anyType.IsArray<GirModel.Record>(out var record) && Model.Record.IsTyped(record);; | ||
} | ||
|
||
public RenderableField Convert(GirModel.Field field) | ||
{ | ||
return new RenderableField( | ||
Name: Model.Field.GetName(field), | ||
Attribute: GetAttribute(field), | ||
NullableTypeName: GetNullableTypeName(field) | ||
); | ||
} | ||
|
||
private static string? GetAttribute(GirModel.Field field) | ||
{ | ||
var arrayType = field.AnyTypeOrCallback.AsT0.AsT1; | ||
return arrayType.FixedSize is not null | ||
? MarshalAs.UnmanagedByValArray(sizeConst: arrayType.FixedSize.Value) | ||
: null; | ||
} | ||
|
||
private static string GetNullableTypeName(GirModel.Field field) | ||
{ | ||
var arrayType = field.AnyTypeOrCallback.AsT0.AsT1; | ||
var type = (GirModel.Record) arrayType.AnyType.AsT0; | ||
return Model.Record.GetFullyQualifiedInternalStructName(type) + "[]"; | ||
} | ||
} |
Oops, something went wrong.