Skip to content

Remove problematic implicit in overloads #673

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
Nov 5, 2021
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
Binary file modified build/cache/gl.json.gz
Binary file not shown.
Binary file modified build/cache/glcore.json.gz
Binary file not shown.
Binary file modified build/cache/gles2.json.gz
Binary file not shown.
123 changes: 123 additions & 0 deletions generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,47 @@
"Buffer": "BufferKind"
},
"namespace": "Silk.NET.OpenGL",
"overloadExclusions": {
"RefOverloader": [
"glBinormalPointerEXT",
"glColorPointer",
"glColorPointerEXT",
"glEdgeFlagPointer",
"glFogCoordPointer",
"glFogCoordPointerEXT",
"glIndexPointer",
"glIndexPointerEXT",
"glInterleavedArrays",
"glMatrixIndexPointerARB",
"glMatrixIndexPointerOES",
"glNormalPointer",
"glNormalPointerEXT",
"glPointSizePointerOES",
"glSecondaryColorPointer",
"glSecondaryColorPointerEXT",
"glTangentPointerEXT",
"glTexCoordPointer",
"glTexCoordPointerEXT",
"glTexCoordPointer",
"glVariantPointerEXT",
"glVertexAttribIPointer",
"glVertexAttribIPointerEXT",
"glVertexAttribLPointer",
"glVertexAttribLPointerEXT",
"glVertexAttribPointer",
"glVertexAttribPointerARB",
"glVertexAttribPointerNV",
"glVertexPointer",
"glVertexPointerEXT",
"glVertexWeightPointerEXT",
"glWeightPointerARB",
"glWeightPointerOES",
"glElementPointerAPPLE",
"glElementPointerATI",
"glMultiTexCoordPointerEXT",
"glPointSizePointerOES"
]
},
"extensionsNamespace": "Silk.NET.OpenGL.Extensions",
"typeMaps": [
{
Expand Down Expand Up @@ -73,6 +114,47 @@
},
"namespace": "Silk.NET.OpenGL.Legacy",
"extensionsNamespace": "Silk.NET.OpenGL.Legacy.Extensions",
"overloadExclusions": {
"RefOverloader": [
"glBinormalPointerEXT",
"glColorPointer",
"glColorPointerEXT",
"glEdgeFlagPointer",
"glFogCoordPointer",
"glFogCoordPointerEXT",
"glIndexPointer",
"glIndexPointerEXT",
"glInterleavedArrays",
"glMatrixIndexPointerARB",
"glMatrixIndexPointerOES",
"glNormalPointer",
"glNormalPointerEXT",
"glPointSizePointerOES",
"glSecondaryColorPointer",
"glSecondaryColorPointerEXT",
"glTangentPointerEXT",
"glTexCoordPointer",
"glTexCoordPointerEXT",
"glTexCoordPointer",
"glVariantPointerEXT",
"glVertexAttribIPointer",
"glVertexAttribIPointerEXT",
"glVertexAttribLPointer",
"glVertexAttribLPointerEXT",
"glVertexAttribPointer",
"glVertexAttribPointerARB",
"glVertexAttribPointerNV",
"glVertexPointer",
"glVertexPointerEXT",
"glVertexWeightPointerEXT",
"glWeightPointerARB",
"glWeightPointerOES",
"glElementPointerAPPLE",
"glElementPointerATI",
"glMultiTexCoordPointerEXT",
"glPointSizePointerOES"
]
},
"typeMaps": [
{
"$include.glTypeMap": "build/gl_typemap.json"
Expand Down Expand Up @@ -114,6 +196,47 @@
},
"namespace": "Silk.NET.OpenGLES",
"extensionsNamespace": "Silk.NET.OpenGLES.Extensions",
"overloadExclusions": {
"RefOverloader": [
"glBinormalPointerEXT",
"glColorPointer",
"glColorPointerEXT",
"glEdgeFlagPointer",
"glFogCoordPointer",
"glFogCoordPointerEXT",
"glIndexPointer",
"glIndexPointerEXT",
"glInterleavedArrays",
"glMatrixIndexPointerARB",
"glMatrixIndexPointerOES",
"glNormalPointer",
"glNormalPointerEXT",
"glPointSizePointerOES",
"glSecondaryColorPointer",
"glSecondaryColorPointerEXT",
"glTangentPointerEXT",
"glTexCoordPointer",
"glTexCoordPointerEXT",
"glTexCoordPointer",
"glVariantPointerEXT",
"glVertexAttribIPointer",
"glVertexAttribIPointerEXT",
"glVertexAttribLPointer",
"glVertexAttribLPointerEXT",
"glVertexAttribPointer",
"glVertexAttribPointerARB",
"glVertexAttribPointerNV",
"glVertexPointer",
"glVertexPointerEXT",
"glVertexWeightPointerEXT",
"glWeightPointerARB",
"glWeightPointerOES",
"glElementPointerAPPLE",
"glElementPointerATI",
"glMultiTexCoordPointerEXT",
"glPointSizePointerOES"
]
},
"typeMaps": [
{
"$include.glTypeMap": "build/gl_typemap.json"
Expand Down
8 changes: 4 additions & 4 deletions src/Core/Silk.NET.BuildTools/Baking/ProfileBakery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class ProfileBakery
/// Bakes APIs together given the <see cref="ProfileBakeryInformation" />, and outputs the baked
/// profile to the given folder.
/// </summary>
public static Profile Bake(string name, IReadOnlyList<Profile> impl)
public static Profile Bake(string name, IReadOnlyList<Profile> impl, in BindTask task)
{
// create the profile
var profile = new Profile
Expand Down Expand Up @@ -56,7 +56,7 @@ public static Profile Bake(string name, IReadOnlyList<Profile> impl)
Console.WriteLine("Profile Bakery: Stirring them until they form a nice paste...");
MergeAll(profile); // note: the key of the Interfaces dictionary is changed here, so don't rely on it herein
Console.WriteLine("Profile Bakery: Adding a bit of flavouring...");
Vary(profile);
Vary(profile, task.OverloaderExclusions);
Console.WriteLine("Profile Bakery: Putting it in the oven until it turns a nice golden colour...");
CheckForDuplicates(profile);
TypeMapper.MapEnums(profile); // we need to map the enums to make sure they are correct for their extension.
Expand Down Expand Up @@ -86,7 +86,7 @@ private static Dictionary<string, Project> FuseProjects(IEnumerable<KeyValuePair
return ret;
}

private static void Vary(Profile profile)
private static void Vary(Profile profile, Dictionary<string,string[]>? overloaderExclusions)
{
foreach (var project in profile.Projects.Values)
{
Expand All @@ -95,7 +95,7 @@ private static void Vary(Profile profile)
foreach (var @interface in @class.NativeApis.Values)
{
@interface.Functions = Overloader.GetWithVariants
(@interface.Functions, profile.Projects["Core"])
(@interface.Functions, profile.Projects["Core"], overloaderExclusions)
.ToList();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Silk.NET.BuildTools/Bind/ClassWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static void WriteMixedModeClasses(this Project project, Profile profile,
sw.WriteLine();
}

foreach (var overload in Overloader.GetOverloads(allFunctions, profile.Projects["Core"]))
foreach (var overload in Overloader.GetOverloads(allFunctions, profile.Projects["Core"], task.Task.OverloaderExclusions))
{
var sw2u = overload.Signature.Kind == SignatureKind.PotentiallyConflictingOverload
? swOverloads ??= CreateOverloadsFile(folder, @class.ClassName, false)
Expand Down Expand Up @@ -377,7 +377,7 @@ public static void WriteMixedModeClasses(this Project project, Profile profile,
sw.WriteLine();
}

foreach (var overload in Overloader.GetOverloads(i.Functions, profile.Projects["Core"]))
foreach (var overload in Overloader.GetOverloads(i.Functions, profile.Projects["Core"], task.Task.OverloaderExclusions))
{
var sw2u = overload.Signature.Kind == SignatureKind.PotentiallyConflictingOverload
? swOverloads ??= CreateOverloadsFile(folder, name, true)
Expand Down
1 change: 1 addition & 0 deletions src/Core/Silk.NET.BuildTools/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public struct BindTask
[JsonProperty("output")] public OutputOptions OutputOpts { get; set; }
[JsonProperty("prefix")] public string FunctionPrefix { get; set; }
[JsonProperty("namespace")] public string Namespace { get; set; }
[JsonProperty("overloadExclusions")] public Dictionary<string, string[]>? OverloaderExclusions { get; set; }
[JsonProperty("extensionsNamespace")] public string ExtensionsNamespace { get; set; }
[JsonProperty("nameContainer")] public NameContainer NameContainer { get; set; }
[JsonProperty("typeMaps")] public List<Dictionary<string, string>> TypeMaps { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Silk.NET.BuildTools/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static void RunTask(BindTask task, Stopwatch? sw)
}

profile = ProfileBakery.Bake
(task.Name, profiles.Where(x => task.BakeryOpts.Include.Contains(x.Name)).ToList());
(task.Name, profiles.Where(x => task.BakeryOpts.Include.Contains(x.Name)).ToList(), in task);

PreprocessorMixin.AddDirectives(profile, task.OutputOpts.ConditionalFunctions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static IEnumerable<ImplementedFunction> GetOverloads
(
Function original,
Project core,
params IComplexFunctionOverloader[] overloaders
IEnumerable<IComplexFunctionOverloader> overloaders
)
{
foreach (var overloader in overloaders)
Expand Down
32 changes: 27 additions & 5 deletions src/Core/Silk.NET.BuildTools/Overloading/Overloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,23 @@ public static class Overloader
new ImplicitCountSpanOverloader()
};

private static IEnumerable<T> Filter<T>
(
this IEnumerable<T> elements,
Function function,
Dictionary<string, string[]>? overloadExcludedFunctions
) => elements.Where
(
x => !(overloadExcludedFunctions?.TryGetValue(x.GetType().Name, out var v) ?? false) ||
!v.Contains(function.NativeName)
);

public static IEnumerable<Function> GetWithVariants(IEnumerable<Function> functions, Project core)
public static IEnumerable<Function> GetWithVariants
(
IEnumerable<Function> functions,
Project core,
Dictionary<string, string[]>? overloadExcludedFunctions
)
{
var enumerable = functions;
foreach (var overloaders in ParameterOverloaders)
Expand All @@ -51,7 +66,8 @@ public static IEnumerable<Function> GetWithVariants(IEnumerable<Function> functi

foreach (var overload in enumerable)
{
foreach (var final in SimpleReturnOverloader.GetWithOverloads(overload, core, ReturnOverloaders))
foreach (var final in SimpleReturnOverloader.GetWithOverloads
(overload, core, ReturnOverloaders.Filter(overload, overloadExcludedFunctions)))
{
yield return final;
}
Expand All @@ -61,15 +77,21 @@ IEnumerable<Function> Get(IEnumerable<Function> functions, ISimpleParameterOverl
{
foreach (var function in functions)
{
foreach (var overload in SimpleParameterOverloader.GetWithOverloads(function, core, overloaders))
foreach (var overload in SimpleParameterOverloader.GetWithOverloads
(function, core, overloaders.Filter(function, overloadExcludedFunctions)))
{
yield return overload;
}
}
}
}

public static IEnumerable<ImplementedFunction> GetOverloads(IEnumerable<Function> allFunctions, Project core)
public static IEnumerable<ImplementedFunction> GetOverloads
(
IEnumerable<Function> allFunctions,
Project core,
Dictionary<string, string[]>? overloadExcludedFunctions
)
{
return Get().RemoveDuplicates(CheckDuplicate);

Expand All @@ -81,7 +103,7 @@ IEnumerable<ImplementedFunction> Get()
foreach (var function in allFunctions)
{
foreach (var overload in ComplexFunctionOverloader.GetOverloads
(function, core, FunctionOverloaders))
(function, core, FunctionOverloaders.Filter(function, overloadExcludedFunctions)))
{
yield return overload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IEnumerable<Function> GetWithOverloads
(
Function original,
Project core,
params ISimpleParameterOverloader[] overloaders
IEnumerable<ISimpleParameterOverloader> overloaders
)
{
if (original.Parameters.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class SimpleReturnOverloader
/// <returns>An enumerable containing the original function signature and all overloads.</returns>
public static IEnumerable<Function> GetWithOverloads(Function original,
Project core,
params ISimpleReturnOverloader[] overloaders)
IEnumerable<ISimpleReturnOverloader> overloaders)
{
yield return original;
foreach (var overloader in overloaders)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,9 @@ public unsafe partial class ArbVertexAttrib64bit : NativeExtension<GL>
[NativeApi(EntryPoint = "glVertexAttribLPointer")]
public unsafe partial void VertexAttribLPointer([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] ARB type, [Flow(FlowDirection.In)] uint stride, [Count(Parameter = "size"), Flow(FlowDirection.In)] void* pointer);

[NativeApi(EntryPoint = "glVertexAttribLPointer")]
public partial void VertexAttribLPointer<T0>([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] ARB type, [Flow(FlowDirection.In)] uint stride, [Count(Parameter = "size"), Flow(FlowDirection.In)] in T0 pointer) where T0 : unmanaged;

[NativeApi(EntryPoint = "glVertexAttribLPointer")]
public unsafe partial void VertexAttribLPointer([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] VertexAttribLType type, [Flow(FlowDirection.In)] uint stride, [Count(Parameter = "size"), Flow(FlowDirection.In)] void* pointer);

[NativeApi(EntryPoint = "glVertexAttribLPointer")]
public partial void VertexAttribLPointer<T0>([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] VertexAttribLType type, [Flow(FlowDirection.In)] uint stride, [Count(Parameter = "size"), Flow(FlowDirection.In)] in T0 pointer) where T0 : unmanaged;

public unsafe void VertexAttribLPointer<T0>([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] ARB type, [Flow(FlowDirection.In)] uint stride, [Count(Parameter = "size"), Flow(FlowDirection.In)] ReadOnlySpan<T0> pointer) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
VertexAttribLPointer(index, (int) (pointer.Length * Unsafe.SizeOf<T0>()), type, stride, in pointer.GetPinnableReference());
}

public unsafe void VertexAttribLPointer<T0>([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] VertexAttribLType type, [Flow(FlowDirection.In)] uint stride, [Count(Parameter = "size"), Flow(FlowDirection.In)] ReadOnlySpan<T0> pointer) where T0 : unmanaged
{
// ImplicitCountSpanOverloader
VertexAttribLPointer(index, (int) (pointer.Length * Unsafe.SizeOf<T0>()), type, stride, in pointer.GetPinnableReference());
}

public ArbVertexAttrib64bit(INativeContext ctx)
: base(ctx)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ public static unsafe void VertexAttribL4(this ArbVertexAttrib64bit thisApi, [Flo
thisApi.VertexAttribL4(index, in v.GetPinnableReference());
}

public static unsafe void VertexAttribLPointer<T0>(this ArbVertexAttrib64bit thisApi, [Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] ARB type, [Flow(FlowDirection.In)] uint stride, [Count(Parameter = "size"), Flow(FlowDirection.In)] ReadOnlySpan<T0> pointer) where T0 : unmanaged
{
// SpanOverloader
thisApi.VertexAttribLPointer(index, size, type, stride, in pointer.GetPinnableReference());
}

public static unsafe void VertexAttribLPointer<T0>(this ArbVertexAttrib64bit thisApi, [Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] VertexAttribLType type, [Flow(FlowDirection.In)] uint stride, [Count(Parameter = "size"), Flow(FlowDirection.In)] ReadOnlySpan<T0> pointer) where T0 : unmanaged
{
// SpanOverloader
thisApi.VertexAttribLPointer(index, size, type, stride, in pointer.GetPinnableReference());
}

}
}

Loading