-
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.
Merge pull request #1126 from gircore/fix-1098
Differentiate between Long and CLong
- Loading branch information
Showing
69 changed files
with
1,153 additions
and
307 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
25 changes: 25 additions & 0 deletions
25
src/Generation/Generator/Renderer/Internal/Field/Converter/CLong.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 @@ | ||
namespace Generator.Renderer.Internal.Field; | ||
|
||
internal class CLong : FieldConverter | ||
{ | ||
public bool Supports(GirModel.Field field) | ||
{ | ||
return field.AnyTypeOrCallback.TryPickT0(out var anyType, out _) && anyType.Is<GirModel.CLong>(); | ||
} | ||
|
||
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) | ||
{ | ||
return field.IsPointer | ||
? Model.Type.Pointer | ||
: "CLong"; | ||
} | ||
} |
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
src/Generation/Generator/Renderer/Internal/Field/Converter/UnsignedCLong.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 @@ | ||
namespace Generator.Renderer.Internal.Field; | ||
|
||
internal class UnsignedCLong : FieldConverter | ||
{ | ||
public bool Supports(GirModel.Field field) | ||
{ | ||
return field.AnyTypeOrCallback.TryPickT0(out var anyType, out _) && anyType.Is<GirModel.UnsignedCLong>(); | ||
} | ||
|
||
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) | ||
{ | ||
return field.IsPointer | ||
? Model.Type.Pointer | ||
: "CULong"; | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/Generation/Generator/Renderer/Internal/Parameter/Converter/CLong.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,44 @@ | ||
using System; | ||
|
||
namespace Generator.Renderer.Internal.Parameter; | ||
|
||
internal class CLong : ParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType anyType) | ||
{ | ||
return anyType.Is<GirModel.CLong>(); | ||
} | ||
|
||
public RenderableParameter Convert(GirModel.Parameter parameter) | ||
{ | ||
// If the parameter is both nullable and optional this implies a parameter type like 'int **' and possibly | ||
// ownership transfer (this combination does not currently occur for any functions). | ||
if (parameter is { Nullable: true, Optional: true }) | ||
throw new System.NotImplementedException($"{parameter.AnyTypeOrVarArgs} - Long value type with nullable=true and optional=true not yet supported"); | ||
|
||
// Nullable-only parameters likely have incorrect annotations and should be marked optional instead. | ||
if (parameter.Nullable) | ||
Log.Information($"Long value type '{parameter.Name}' with nullable=true is likely an incorrect annotation"); | ||
|
||
// The caller-allocates flag is not meaningful for primitive types (https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/446) | ||
if (parameter.CallerAllocates) | ||
Log.Information($"Long value type '{parameter.Name}' with caller-allocates=true is an incorrect annotation"); | ||
|
||
return new RenderableParameter( | ||
Attribute: string.Empty, | ||
Direction: GetDirection(parameter), | ||
NullableTypeName: "CLong", | ||
Name: Model.Parameter.GetName(parameter) | ||
); | ||
} | ||
|
||
private static string GetDirection(GirModel.Parameter parameter) => parameter switch | ||
{ | ||
// - Optional inout and out types are just exposed as non-nullable ref / out parameters which the user can ignore if desired. | ||
{ Direction: GirModel.Direction.In, IsPointer: true } => ParameterDirection.Ref(), | ||
{ Direction: GirModel.Direction.InOut } => ParameterDirection.Ref(), | ||
{ Direction: GirModel.Direction.Out } => ParameterDirection.Out(), | ||
{ Direction: GirModel.Direction.In } => ParameterDirection.In(), | ||
_ => throw new Exception($"Can't figure out direction for internal long value type parameter {parameter}.") | ||
}; | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/Generation/Generator/Renderer/Internal/Parameter/Converter/UnsignedCLong.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,44 @@ | ||
using System; | ||
|
||
namespace Generator.Renderer.Internal.Parameter; | ||
|
||
internal class UnsignedCLong : ParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType anyType) | ||
{ | ||
return anyType.Is<GirModel.UnsignedCLong>(); | ||
} | ||
|
||
public RenderableParameter Convert(GirModel.Parameter parameter) | ||
{ | ||
// If the parameter is both nullable and optional this implies a parameter type like 'int **' and possibly | ||
// ownership transfer (this combination does not currently occur for any functions). | ||
if (parameter is { Nullable: true, Optional: true }) | ||
throw new System.NotImplementedException($"{parameter.AnyTypeOrVarArgs} - Unsigned long value type with nullable=true and optional=true not yet supported"); | ||
|
||
// Nullable-only parameters likely have incorrect annotations and should be marked optional instead. | ||
if (parameter.Nullable) | ||
Log.Information($"Unsigned long value type '{parameter.Name}' with nullable=true is likely an incorrect annotation"); | ||
|
||
// The caller-allocates flag is not meaningful for primitive types (https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/446) | ||
if (parameter.CallerAllocates) | ||
Log.Information($"Unsigned long value type '{parameter.Name}' with caller-allocates=true is an incorrect annotation"); | ||
|
||
return new RenderableParameter( | ||
Attribute: string.Empty, | ||
Direction: GetDirection(parameter), | ||
NullableTypeName: "CULong", | ||
Name: Model.Parameter.GetName(parameter) | ||
); | ||
} | ||
|
||
private static string GetDirection(GirModel.Parameter parameter) => parameter switch | ||
{ | ||
// - Optional inout and out types are just exposed as non-nullable ref / out parameters which the user can ignore if desired. | ||
{ Direction: GirModel.Direction.In, IsPointer: true } => ParameterDirection.Ref(), | ||
{ Direction: GirModel.Direction.InOut } => ParameterDirection.Ref(), | ||
{ Direction: GirModel.Direction.Out } => ParameterDirection.Out(), | ||
{ Direction: GirModel.Direction.In } => ParameterDirection.In(), | ||
_ => throw new Exception($"Can't figure out direction for internal unsigned long value type parameter {parameter}.") | ||
}; | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/Generation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/CLong.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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Renderer.Internal.ParameterToManagedExpressions; | ||
|
||
internal class CLong : ToManagedParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType type) | ||
=> type.Is<GirModel.CLong>(); | ||
|
||
public void Initialize(ParameterToManagedData parameterData, IEnumerable<ParameterToManagedData> parameters) | ||
{ | ||
switch (parameterData.Parameter) | ||
{ | ||
case { Direction: GirModel.Direction.In, IsPointer: false }: | ||
Direct(parameterData); | ||
break; | ||
default: | ||
throw new NotImplementedException($"This kind of internal long value type (pointed: {parameterData.Parameter.IsPointer}, direction: {parameterData.Parameter.Direction} can't be converted to managed currently."); | ||
} | ||
} | ||
|
||
private static void Direct(ParameterToManagedData parameterData) | ||
{ | ||
var variableName = Model.Parameter.GetName(parameterData.Parameter); | ||
|
||
parameterData.SetSignatureName(() => variableName); | ||
parameterData.SetCallName(() => $"{variableName}.Value"); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...ation/Generator/Renderer/Internal/ParameterToManagedExpression/Converter/UnsignedCLong.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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Renderer.Internal.ParameterToManagedExpressions; | ||
|
||
internal class UnsignedCLong : ToManagedParameterConverter | ||
{ | ||
public bool Supports(GirModel.AnyType type) | ||
=> type.Is<GirModel.UnsignedCLong>(); | ||
|
||
public void Initialize(ParameterToManagedData parameterData, IEnumerable<ParameterToManagedData> parameters) | ||
{ | ||
switch (parameterData.Parameter) | ||
{ | ||
case { Direction: GirModel.Direction.In, IsPointer: false }: | ||
Direct(parameterData); | ||
break; | ||
default: | ||
throw new NotImplementedException($"This kind of internal unsigned long value type (pointed: {parameterData.Parameter.IsPointer}, direction: {parameterData.Parameter.Direction} can't be converted to managed currently."); | ||
} | ||
} | ||
|
||
private static void Direct(ParameterToManagedData parameterData) | ||
{ | ||
var variableName = Model.Parameter.GetName(parameterData.Parameter); | ||
|
||
parameterData.SetSignatureName(() => variableName); | ||
parameterData.SetCallName(() => $"{variableName}.Value"); | ||
} | ||
} |
Oops, something went wrong.