Skip to content
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

[3.0] Miscellaneous generator improvements #2359

Open
wants to merge 10 commits into
base: develop/3.0
Choose a base branch
from
Binary file added .silktouch/0afb5dc84012c2fa.stout
Binary file not shown.
Binary file modified .silktouch/c8c046b328b09d23.stout
Binary file not shown.
Binary file removed .silktouch/f634eee0bf239a81.stout
Binary file not shown.
2 changes: 2 additions & 0 deletions eng/silktouch/sdl/SDL3/generate.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SDL_SIZE_MAX
SDL_memcpy
SDL_memmove
SDL_memset
SDL_BeginThreadFunction
SDL_EndThreadFunction
--file
sdl-SDL.h
--methodClassName
Expand Down
2 changes: 1 addition & 1 deletion eng/submodules/sdl
Submodule sdl updated 1514 files
16 changes: 11 additions & 5 deletions generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"ExtractNestedTyping",
"TransformHandles",
"TransformFunctions",
"TransformProperties",
"PrettifyNames",
"AddVTables"
],
Expand Down Expand Up @@ -71,6 +72,7 @@
"AddIncludes",
"ClangScraper",
"AddApiProfiles",
"BakeSourceSets",
"MixKhronosData",
"AddOpaqueStructs",
"TransformFunctions",
Expand All @@ -88,29 +90,33 @@
"Profiles": [
{
"Profile": "gl",
"SourceSubdirectory": "glcompat",
"BakedOutputSubdirectory": "gl"
"SourceSubdirectory": "glcompat"
},
{
"Profile": "glcore",
"SourceSubdirectory": "glcore",
"BakedOutputSubdirectory": "gl",
"MinVersion": "3.2"
},
{
"Profile": "gles1",
"SourceSubdirectory": "gles1",
"BakedOutputSubdirectory": "gl",
"MaxVersion": "2.0"
},
{
"Profile": "gles2",
"SourceSubdirectory": "gles2",
"BakedOutputSubdirectory": "gl",
"MinVersion": "2.0"
}
]
},
"BakeSourceSets": {
"SourceSets": {
"glcompat": "gl",
"glcore": "gl",
"gles1": "gl",
"gles2": "gl"
}
},
"AddOpaqueStructs": {
"Names": [
"GLsync"
Expand Down
81 changes: 81 additions & 0 deletions sources/Core/Core/Abstractions/Utf8String.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;

namespace Silk.NET.Core;

/// <summary>
/// Represents a target type for UTF-8 string literals.
/// </summary>
/// <param name="bytes">The UTF-8 bytes.</param>
public readonly ref struct Utf8String(ReadOnlySpan<byte> bytes)
{
/// <summary>
/// Gets the UTF-8 byte representation of this string.
/// </summary>
public ReadOnlySpan<byte> Bytes { get; } = bytes;

/// <summary>
/// Converts this string to a <see cref="Ref{T}"/>.
/// </summary>
/// <param name="str">The string.</param>
/// <returns>The ref.</returns>
public static implicit operator Ref<byte>(Utf8String str) => str.Bytes;

/// <summary>
/// Converts this string to a <see cref="Ref{T}"/>.
/// </summary>
/// <param name="str">The string.</param>
/// <returns>The ref.</returns>
public static implicit operator Ref<sbyte>(Utf8String str) => (ReadOnlySpan<sbyte>)str;

/// <summary>
/// Converts this string to a <see cref="ReadOnlySpan{T}"/>.
/// </summary>
/// <param name="str">The string.</param>
/// <returns>The span.</returns>
public static implicit operator ReadOnlySpan<byte>(Utf8String str) => str.Bytes;

/// <summary>
/// Converts this string to a <see cref="Ref{T}"/>.
/// </summary>
/// <param name="str">The string.</param>
/// <returns>The span.</returns>
public static implicit operator ReadOnlySpan<sbyte>(Utf8String str) =>
MemoryMarshal.Cast<byte, sbyte>(str);

// TODO add ptr casts once we have an analyzer for e.g. [KnownImmovable]

/// <summary>
/// Converts this string to a <see cref="Ref"/>.
/// </summary>
/// <param name="str">The string.</param>
/// <returns>The ref.</returns>
public static implicit operator Ref(Utf8String str) => (Ref<byte>)str.Bytes;

/// <summary>
/// Converts this string to a <see cref="string"/>.
/// </summary>
/// <param name="str">The string.</param>
/// <returns>The string.</returns>
public static implicit operator string(Utf8String str) => str.ToString();

/// <summary>
/// Converts the given UTF-8 bytes to a <see cref="Utf8String"/>.
/// </summary>
/// <param name="bytes">The bytes.</param>
/// <returns>The string.</returns>
public static implicit operator Utf8String(ReadOnlySpan<byte> bytes) => new(bytes);

/// <summary>
/// Converts the given UTF-8 bytes to a <see cref="Utf8String"/>.
/// </summary>
/// <param name="bytes">The bytes.</param>
/// <returns>The string.</returns>
public static implicit operator Utf8String(ReadOnlySpan<sbyte> bytes) =>
MemoryMarshal.Cast<sbyte, byte>(bytes);

/// <inheritdoc />
public override string ToString() => (string)(Ref<byte>)this;
}
13 changes: 11 additions & 2 deletions sources/Core/Core/Pointers/Ref.generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,21 @@ public ref T this[nuint index]
public static bool operator !=(NullPtr lh, Ref<T> rh) => (Ref<T>)lh != rh;

/// <summary>
/// Creates a <see cref="Ref{T}"/> from a span
/// Creates a <see cref="Ref{T}"/> from a span.
/// </summary>
/// <param name="span"></param>
/// <param name="span">The span to create the ref from.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static implicit operator Ref<T>(Span<T> span) => new(ref span.GetPinnableReference());

/// <summary>
/// Creates a <see cref="Ref{T}"/> from a readonly span.
/// </summary>
/// <param name="span">The span to create the ref from.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
// TODO const correctness analyzers
public static implicit operator Ref<T>(ReadOnlySpan<T> span) =>
new(ref Unsafe.AsRef(in span.GetPinnableReference()));

/// <summary>
/// Creates a <see cref="Ref{T}"/> from a byte reference
/// </summary>
Expand Down
Loading
Loading