+
Skip to content

Refactor internal return type renderer #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Generation/Generator/Model/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public static bool SupportsAccessorGetMethod(GirModel.Property property, [NotNul

getter = property.Getter;
var getterType = property.Getter.ReturnType
.Map(RenderableReturnTypeFactory.Create)
.NullableTypeName;
.Map(ReturnTypeRenderer.Render);

return GetNullableTypeName(property) == getterType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static string Render(GirModel.Callback callback)
{
try
{
return $"public delegate {ReturnType.RenderForCallback(callback.ReturnType)} {Model.Callback.GetInternalDelegateName(callback)}({CallbackParameters.Render(callback.Parameters)});";
return $"public delegate {ReturnTypeRendererCallback.Render(callback.ReturnType)} {Model.Callback.GetInternalDelegateName(callback)}({CallbackParameters.Render(callback.Parameters)});";
}
catch (System.Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace {Namespace.GetInternalName(callback.Namespace)}
{{
// AUTOGENERATED FILE - DO NOT MODIFY

public delegate {ReturnType.RenderForCallback(callback.ReturnType)} {callback.Name}({CallbackParameters.Render(callback.Parameters)});
public delegate {ReturnTypeRendererCallback.Render(callback.ReturnType)} {callback.Name}({CallbackParameters.Render(callback.Parameters)});
}}";
}
}
2 changes: 1 addition & 1 deletion src/Generation/Generator/Renderer/Internal/Constructors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static string Render(GirModel.Constructor? constructor)
{DocComments.Render(constructor.ReturnType)}
{VersionAttribute.Render(constructor.Version)}
[DllImport(ImportResolver.Library, EntryPoint = ""{constructor.CIdentifier}"")]
public static extern {ReturnType.Render(constructor.ReturnType)} {Constructor.GetName(constructor)}({Parameters.Render(constructor.Parameters)}{Error.Render(constructor)});";
public static extern {ReturnTypeRenderer.Render(constructor.ReturnType)} {Constructor.GetName(constructor)}({Parameters.Render(constructor.Parameters)}{Error.Render(constructor)});";
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Generation/Generator/Renderer/Internal/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static string Render(GirModel.Function? function)
{PlatformSupportAttribute.Render(function as GirModel.PlatformDependent)}
{VersionAttribute.Render(function.Version)}
[DllImport(ImportResolver.Library, EntryPoint = ""{function.CIdentifier}"")]
public static extern {ReturnType.Render(function.ReturnType)} {Function.GetName(function)}({Parameters.Render(function.Parameters)}{Error.Render(function)});";
public static extern {ReturnTypeRenderer.Render(function.ReturnType)} {Function.GetName(function)}({Parameters.Render(function.Parameters)}{Error.Render(function)});";
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Generation/Generator/Renderer/Internal/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static string Render(GirModel.Method? method)
{DocComments.Render(method.ReturnType)}
{VersionAttribute.Render(method.Version)}
[DllImport(ImportResolver.Library, EntryPoint = ""{method.CIdentifier}"")]
public static extern {ReturnType.Render(method.ReturnType)} {Method.GetInternalName(method)}({InstanceParameters.Render(method.InstanceParameter)}{separator}{Parameters.Render(method.Parameters)}{Error.Render(method)});";
public static extern {ReturnTypeRenderer.Render(method.ReturnType)} {Method.GetInternalName(method)}({InstanceParameters.Render(method.InstanceParameter)}{separator}{Parameters.Render(method.Parameters)}{Error.Render(method)});";
}
catch (Exception e)
{
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class ArrayClass : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.IsArray<GirModel.Class>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
return new RenderableReturnType(Model.Type.PointerArray);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class ArrayPrimitiveValueType : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.IsArray<GirModel.PrimitiveValueType>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
return new RenderableReturnType(Model.ArrayType.GetName(returnType.AnyType.AsT1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Generator.Model;

namespace Generator.Renderer.Internal.ReturnType;

internal class ArrayRecord : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.IsArray<GirModel.Record>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
//Internal arrays of records (SafeHandles) are not supported by the runtime and must be converted via an IntPtr[]
return new RenderableReturnType(Type.PointerArray);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class ArrayString : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.IsArray<GirModel.String>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
var arrayType = returnType.AnyType.AsT1;
var isMarshalAble = returnType.Transfer != GirModel.Transfer.None || arrayType.Length != null;
var nullableTypeName = isMarshalAble
? Model.ArrayType.GetName(arrayType)
: Model.Type.Pointer;

return new RenderableReturnType(nullableTypeName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class Bitfield : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.Bitfield>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
var type = (GirModel.Bitfield) returnType.AnyType.AsT0;
return new RenderableReturnType(Model.ComplexType.GetFullyQualified(type));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class Class : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.Class>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
var nullableTypeName = returnType.IsPointer
? Model.Type.Pointer
: Model.Type.GetName(returnType.AnyType.AsT0);

return new RenderableReturnType(nullableTypeName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class Enumeration : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.Enumeration>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
var type = (GirModel.Enumeration) returnType.AnyType.AsT0;
return new RenderableReturnType(Model.ComplexType.GetFullyQualified(type));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Generator.Model;

namespace Generator.Renderer.Internal.ReturnType;

internal class Interface : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.Interface>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
var nullableTypeName = returnType.IsPointer
? Type.Pointer
: Type.GetName(returnType.AnyType.AsT0);

return new RenderableReturnType(nullableTypeName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class PlatformString : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.PlatformString>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
var nullableTypeName = returnType switch
{
{ Nullable: true, Transfer: GirModel.Transfer.None } => Model.PlatformString.GetInternalNullableUnownedHandleName(),
{ Nullable: false, Transfer: GirModel.Transfer.None } => Model.PlatformString.GetInternalNonNullableUnownedHandleName(),
{ Nullable: true, Transfer: GirModel.Transfer.Full } => Model.PlatformString.GetInternalNullableOwnedHandleName(),
_ => Model.PlatformString.GetInternalNonNullableOwnedHandleName(),
};

return new RenderableReturnType(nullableTypeName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Generator.Model;

namespace Generator.Renderer.Internal.ReturnType;

internal class PlatformStringInCallback : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.PlatformString>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
// This must be IntPtr since SafeHandle's cannot be returned from managed to unmanaged.
return new RenderableReturnType(Type.Pointer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Generator.Model;

namespace Generator.Renderer.Internal.ReturnType;

internal class Pointer : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.Pointer>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
return new RenderableReturnType(Type.Pointer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class PrimitiveValueType : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.PrimitiveValueType>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
var nullableTypeName = returnType.IsPointer
? Model.Type.Pointer
: Model.Type.GetName(returnType.AnyType.AsT0);

return new RenderableReturnType(nullableTypeName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Generator.Renderer.Internal.ReturnType;

internal class Record : ReturnTypeConverter
{
public bool Supports(GirModel.ReturnType returnType)
{
return returnType.AnyType.Is<GirModel.Record>();
}

public RenderableReturnType Convert(GirModel.ReturnType returnType)
{
var type = (GirModel.Record) returnType.AnyType.AsT0;

var nullableTypeName = !returnType.IsPointer
? Model.Record.GetFullyQualifiedInternalStructName(type)
: returnType.Transfer == GirModel.Transfer.None
? Model.Record.GetFullyQualifiedInternalUnownedHandle(type)
: Model.Record.GetFullyQualifiedInternalOwnedHandle(type);

return new RenderableReturnType(nullableTypeName);
}
}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载