Skip to content

Commit b693082

Browse files
authored
[3.0] Miscellaneous generator improvements (#2359)
* Add a Utf8String helper type, and transform string constants to use it * Move bakery functionality into a mod separate from SupportedApiProfiles * Rename GetTypeDeclaration to BakeMember * Cache the result of function pointer loading * Fix vulnerability? * Recognise some #define enums, improve pfn type gen, update SDL, more fixes * Update ClangSharp (with no changes!!!!1111!1!!!111 🎉) * Commit cache files too * Fix playground compilation error
1 parent ab7b9a3 commit b693082

File tree

212 files changed

+62700
-28459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+62700
-28459
lines changed

.silktouch/0afb5dc84012c2fa.stout

154 KB
Binary file not shown.

.silktouch/c8c046b328b09d23.stout

0 Bytes
Binary file not shown.

.silktouch/f634eee0bf239a81.stout

-150 KB
Binary file not shown.

eng/silktouch/sdl/SDL3/generate.rsp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ SDL_SIZE_MAX
77
SDL_memcpy
88
SDL_memmove
99
SDL_memset
10+
SDL_BeginThreadFunction
11+
SDL_EndThreadFunction
1012
--file
1113
sdl-SDL.h
1214
--methodClassName

eng/submodules/sdl

Submodule sdl updated 1514 files

generator.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"ExtractNestedTyping",
4444
"TransformHandles",
4545
"TransformFunctions",
46+
"TransformProperties",
4647
"PrettifyNames",
4748
"AddVTables"
4849
],
@@ -71,6 +72,7 @@
7172
"AddIncludes",
7273
"ClangScraper",
7374
"AddApiProfiles",
75+
"BakeSourceSets",
7476
"MixKhronosData",
7577
"AddOpaqueStructs",
7678
"TransformFunctions",
@@ -88,29 +90,33 @@
8890
"Profiles": [
8991
{
9092
"Profile": "gl",
91-
"SourceSubdirectory": "glcompat",
92-
"BakedOutputSubdirectory": "gl"
93+
"SourceSubdirectory": "glcompat"
9394
},
9495
{
9596
"Profile": "glcore",
9697
"SourceSubdirectory": "glcore",
97-
"BakedOutputSubdirectory": "gl",
9898
"MinVersion": "3.2"
9999
},
100100
{
101101
"Profile": "gles1",
102102
"SourceSubdirectory": "gles1",
103-
"BakedOutputSubdirectory": "gl",
104103
"MaxVersion": "2.0"
105104
},
106105
{
107106
"Profile": "gles2",
108107
"SourceSubdirectory": "gles2",
109-
"BakedOutputSubdirectory": "gl",
110108
"MinVersion": "2.0"
111109
}
112110
]
113111
},
112+
"BakeSourceSets": {
113+
"SourceSets": {
114+
"glcompat": "gl",
115+
"glcore": "gl",
116+
"gles1": "gl",
117+
"gles2": "gl"
118+
}
119+
},
114120
"AddOpaqueStructs": {
115121
"Names": [
116122
"GLsync"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.InteropServices;
5+
6+
namespace Silk.NET.Core;
7+
8+
/// <summary>
9+
/// Represents a target type for UTF-8 string literals.
10+
/// </summary>
11+
/// <param name="bytes">The UTF-8 bytes.</param>
12+
public readonly ref struct Utf8String(ReadOnlySpan<byte> bytes)
13+
{
14+
/// <summary>
15+
/// Gets the UTF-8 byte representation of this string.
16+
/// </summary>
17+
public ReadOnlySpan<byte> Bytes { get; } = bytes;
18+
19+
/// <summary>
20+
/// Converts this string to a <see cref="Ref{T}"/>.
21+
/// </summary>
22+
/// <param name="str">The string.</param>
23+
/// <returns>The ref.</returns>
24+
public static implicit operator Ref<byte>(Utf8String str) => str.Bytes;
25+
26+
/// <summary>
27+
/// Converts this string to a <see cref="Ref{T}"/>.
28+
/// </summary>
29+
/// <param name="str">The string.</param>
30+
/// <returns>The ref.</returns>
31+
public static implicit operator Ref<sbyte>(Utf8String str) => (ReadOnlySpan<sbyte>)str;
32+
33+
/// <summary>
34+
/// Converts this string to a <see cref="ReadOnlySpan{T}"/>.
35+
/// </summary>
36+
/// <param name="str">The string.</param>
37+
/// <returns>The span.</returns>
38+
public static implicit operator ReadOnlySpan<byte>(Utf8String str) => str.Bytes;
39+
40+
/// <summary>
41+
/// Converts this string to a <see cref="Ref{T}"/>.
42+
/// </summary>
43+
/// <param name="str">The string.</param>
44+
/// <returns>The span.</returns>
45+
public static implicit operator ReadOnlySpan<sbyte>(Utf8String str) =>
46+
MemoryMarshal.Cast<byte, sbyte>(str);
47+
48+
// TODO add ptr casts once we have an analyzer for e.g. [KnownImmovable]
49+
50+
/// <summary>
51+
/// Converts this string to a <see cref="Ref"/>.
52+
/// </summary>
53+
/// <param name="str">The string.</param>
54+
/// <returns>The ref.</returns>
55+
public static implicit operator Ref(Utf8String str) => (Ref<byte>)str.Bytes;
56+
57+
/// <summary>
58+
/// Converts this string to a <see cref="string"/>.
59+
/// </summary>
60+
/// <param name="str">The string.</param>
61+
/// <returns>The string.</returns>
62+
public static implicit operator string(Utf8String str) => str.ToString();
63+
64+
/// <summary>
65+
/// Converts the given UTF-8 bytes to a <see cref="Utf8String"/>.
66+
/// </summary>
67+
/// <param name="bytes">The bytes.</param>
68+
/// <returns>The string.</returns>
69+
public static implicit operator Utf8String(ReadOnlySpan<byte> bytes) => new(bytes);
70+
71+
/// <summary>
72+
/// Converts the given UTF-8 bytes to a <see cref="Utf8String"/>.
73+
/// </summary>
74+
/// <param name="bytes">The bytes.</param>
75+
/// <returns>The string.</returns>
76+
public static implicit operator Utf8String(ReadOnlySpan<sbyte> bytes) =>
77+
MemoryMarshal.Cast<sbyte, byte>(bytes);
78+
79+
/// <inheritdoc />
80+
public override string ToString() => (string)(Ref<byte>)this;
81+
}

sources/Core/Core/Pointers/Ref.generic.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,21 @@ public ref T this[nuint index]
132132
public static bool operator !=(NullPtr lh, Ref<T> rh) => (Ref<T>)lh != rh;
133133

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

141+
/// <summary>
142+
/// Creates a <see cref="Ref{T}"/> from a readonly span.
143+
/// </summary>
144+
/// <param name="span">The span to create the ref from.</param>
145+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
146+
// TODO const correctness analyzers
147+
public static implicit operator Ref<T>(ReadOnlySpan<T> span) =>
148+
new(ref Unsafe.AsRef(in span.GetPinnableReference()));
149+
141150
/// <summary>
142151
/// Creates a <see cref="Ref{T}"/> from a byte reference
143152
/// </summary>

0 commit comments

Comments
 (0)