-
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.
Primitive value type alias: Support returning arrays
- Loading branch information
Showing
51 changed files
with
468 additions
and
192 deletions.
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
...neration/Generator/Renderer/Internal/ReturnType/Converter/PrimitiveValueTypeAliasArray.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,20 @@ | ||
using System; | ||
using Type = Generator.Model.Type; | ||
|
||
namespace Generator.Renderer.Internal.ReturnType; | ||
|
||
internal class PrimitiveValueTypeAliasArray : ReturnTypeConverter | ||
{ | ||
public bool Supports(GirModel.ReturnType returnType) | ||
{ | ||
return returnType.AnyType.IsArrayAlias<GirModel.PrimitiveValueType>(); | ||
} | ||
|
||
public RenderableReturnType Convert(GirModel.ReturnType returnType) | ||
{ | ||
if (!returnType.IsPointer) | ||
throw new NotImplementedException("Only primitive value types alias arrays which are pointer based are supported."); | ||
|
||
return new RenderableReturnType(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
8 changes: 8 additions & 0 deletions
8
src/Generation/Generator/Renderer/Public/CallableExpressions/CallableData.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,8 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Renderer.Public; | ||
|
||
public record CallableData( | ||
ReturnTypeToManagedData ReturnTypeToManagedData, | ||
IReadOnlyCollection<ParameterToNativeData> ParameterToNativeDatas | ||
); |
12 changes: 12 additions & 0 deletions
12
src/Generation/Generator/Renderer/Public/CallableExpressions/CallableExpressions.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 @@ | ||
namespace Generator.Renderer.Public; | ||
|
||
public class CallableExpressions | ||
{ | ||
public static CallableData Initialize(GirModel.Callable callable) | ||
{ | ||
var parameters = ParameterToNativeExpression.Initialize(callable.Parameters); | ||
var returnType = ReturnTypeToManagedExpression.Initialize(callable.ReturnType, parameters); | ||
|
||
return new CallableData(returnType, parameters); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...Generation/Generator/Renderer/Public/ReturnType/Converter/PrimitiveValueTypeAliasArray.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 @@ | ||
using System; | ||
|
||
namespace Generator.Renderer.Public.ReturnType; | ||
|
||
internal class PrimitiveValueTypeAliasArray : ReturnTypeConverter | ||
{ | ||
public RenderableReturnType Create(GirModel.ReturnType returnType) | ||
{ | ||
if (!returnType.IsPointer) | ||
throw new NotImplementedException("Only primitive value types alias arrays which are pointer based are supported."); | ||
|
||
var alias = (GirModel.Alias) returnType.AnyType.AsT1.AnyType.AsT0; | ||
return new RenderableReturnType($"{Model.Namespace.GetPublicName(alias.Namespace)}.{Model.ArrayType.GetName(returnType.AnyType.AsT1)}"); | ||
} | ||
|
||
public bool Supports(GirModel.ReturnType returnType) | ||
=> returnType.AnyType.IsArrayAlias<GirModel.PrimitiveValueType>(); | ||
} |
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
32 changes: 18 additions & 14 deletions
32
...n/Generator/Renderer/Public/ReturnTypeToManagedExpression/Converter/ForeignTypedRecord.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 |
---|---|---|
@@ -1,28 +1,32 @@ | ||
using System; | ||
using GirModel; | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Renderer.Public.ReturnTypeToManagedExpressions; | ||
|
||
internal class ForeignTypedRecord : ReturnTypeConverter | ||
{ | ||
public bool Supports(AnyType type) | ||
public bool Supports(GirModel.AnyType type) | ||
=> type.Is<GirModel.Record>(out var record) && Model.Record.IsForeignTyped(record); | ||
|
||
public string GetString(GirModel.ReturnType returnType, string fromVariableName) | ||
public void Initialize(ReturnTypeToManagedData data, IEnumerable<ParameterToNativeData> _) | ||
{ | ||
var record = (GirModel.Record) returnType.AnyType.AsT0; | ||
|
||
var handleExpression = returnType switch | ||
data.SetExpression(fromVariableName => | ||
{ | ||
{ Transfer: Transfer.Full } => fromVariableName, | ||
{ Transfer: Transfer.None } => $"{fromVariableName}.OwnedCopy()", | ||
_ => throw new NotImplementedException("Unknown transfer type") | ||
}; | ||
var returnType = data.ReturnType; | ||
var record = (GirModel.Record) returnType.AnyType.AsT0; | ||
|
||
var handleExpression = returnType switch | ||
{ | ||
{ Transfer: GirModel.Transfer.Full } => fromVariableName, | ||
{ Transfer: GirModel.Transfer.None } => $"{fromVariableName}.OwnedCopy()", | ||
_ => throw new NotImplementedException("Unknown transfer type") | ||
}; | ||
|
||
var createNewInstance = $"new {Model.ComplexType.GetFullyQualified(record)}({handleExpression})"; | ||
var createNewInstance = $"new {Model.ComplexType.GetFullyQualified(record)}({handleExpression})"; | ||
|
||
return returnType.Nullable | ||
? $"{fromVariableName}.IsInvalid ? null : {createNewInstance}" | ||
: createNewInstance; | ||
return returnType.Nullable | ||
? $"{fromVariableName}.IsInvalid ? null : {createNewInstance}" | ||
: createNewInstance; | ||
}); | ||
} | ||
} |
Oops, something went wrong.