-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate StackAllocations automatically.
- Loading branch information
Showing
9 changed files
with
395 additions
and
24 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
22 changes: 22 additions & 0 deletions
22
...est/MetadataTests.VerifyDictCollectionMetadata#StackAllocationRegistrations.g.verified.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,22 @@ | ||
//HintName: StackAllocationRegistrations.g.cs | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
[CompilerGenerated] | ||
static file class StackAllocationRegistrations | ||
{ | ||
[ModuleInitializer] | ||
internal static unsafe void Register4BTDB() | ||
{ | ||
BTDB.Serialization.ReflectionMetadata.RegisterStackAllocator(typeof(int), &Allocate1); | ||
static void Allocate1(ref byte ctx, ref nint ptr, delegate*<ref byte, void> chain) | ||
{ | ||
int value; | ||
ptr = (nint)(&value); | ||
chain(ref ctx); | ||
ptr = 0; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...rator.Test/MetadataTests.VerifyMoreCollections#StackAllocationRegistrations.g.verified.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,22 @@ | ||
//HintName: StackAllocationRegistrations.g.cs | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
[CompilerGenerated] | ||
static file class StackAllocationRegistrations | ||
{ | ||
[ModuleInitializer] | ||
internal static unsafe void Register4BTDB() | ||
{ | ||
BTDB.Serialization.ReflectionMetadata.RegisterStackAllocator(typeof(int), &Allocate1); | ||
static void Allocate1(ref byte ctx, ref nint ptr, delegate*<ref byte, void> chain) | ||
{ | ||
int value; | ||
ptr = (nint)(&value); | ||
chain(ref ctx); | ||
ptr = 0; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...t/MetadataTests.VerifyNestedCollectionMetadata#StackAllocationRegistrations.g.verified.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,22 @@ | ||
//HintName: StackAllocationRegistrations.g.cs | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
[CompilerGenerated] | ||
static file class StackAllocationRegistrations | ||
{ | ||
[ModuleInitializer] | ||
internal static unsafe void Register4BTDB() | ||
{ | ||
BTDB.Serialization.ReflectionMetadata.RegisterStackAllocator(typeof(int), &Allocate1); | ||
static void Allocate1(ref byte ctx, ref nint ptr, delegate*<ref byte, void> chain) | ||
{ | ||
int value; | ||
ptr = (nint)(&value); | ||
chain(ref ctx); | ||
ptr = 0; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ator.Test/MetadataTests.VerifyStructFromCollections#CollectionRegistrations.g.verified.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,49 @@ | ||
//HintName: CollectionRegistrations.g.cs | ||
// <auto-generated/> | ||
#nullable enable | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
[CompilerGenerated] | ||
static file class CollectionRegistrations | ||
{ | ||
[ModuleInitializer] | ||
internal static void Register4BTDB() | ||
{ | ||
BTDB.Serialization.ReflectionMetadata.RegisterCollection(new() | ||
{ | ||
Type = typeof(global::System.Collections.Generic.IDictionary<int, (string, string)>), | ||
ElementKeyType = typeof(int), | ||
ElementValueType = typeof((string, string)), | ||
Creator = &Create1, | ||
AdderKeyValue = &Add1 | ||
}); | ||
|
||
static object Create1(uint capacity) | ||
{ | ||
return new global::System.Collections.Generic.Dictionary<int, (string, string)>((int)capacity); | ||
} | ||
|
||
static void Add1(object c, ref byte key, ref byte value) | ||
{ | ||
Unsafe.As<global::System.Collections.Generic.Dictionary<int, (string, string)>>(c).Add(Unsafe.As<byte, int>(ref key), Unsafe.As<byte, (string, string)>(ref value)); | ||
} | ||
|
||
BTDB.Serialization.ReflectionMetadata.RegisterCollection(new() | ||
{ | ||
Type = typeof(global::System.Collections.Generic.ISet<(string, int)>), | ||
ElementKeyType = typeof((string, int)), | ||
Creator = &Create2, | ||
Adder = &Add2 | ||
}); | ||
|
||
static object Create2(uint capacity) | ||
{ | ||
return new global::System.Collections.Generic.HashSet<(string, int)>((int)capacity); | ||
} | ||
|
||
static void Add2(object c, ref byte value) | ||
{ | ||
Unsafe.As<global::System.Collections.Generic.HashSet<(string, int)>>(c).Add(Unsafe.As<byte, (string, int)>(ref value)); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...Test/MetadataTests.VerifyStructFromCollections#StackAllocationRegistrations.g.verified.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,40 @@ | ||
//HintName: StackAllocationRegistrations.g.cs | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
[CompilerGenerated] | ||
static file class StackAllocationRegistrations | ||
{ | ||
[ModuleInitializer] | ||
internal static unsafe void Register4BTDB() | ||
{ | ||
BTDB.Serialization.ReflectionMetadata.RegisterStackAllocator(typeof(int), &Allocate1); | ||
static void Allocate1(ref byte ctx, ref nint ptr, delegate*<ref byte, void> chain) | ||
{ | ||
int value; | ||
ptr = (nint)(&value); | ||
chain(ref ctx); | ||
ptr = 0; | ||
} | ||
|
||
BTDB.Serialization.ReflectionMetadata.RegisterStackAllocator(typeof((string, string)), &Allocate2); | ||
static void Allocate2(ref byte ctx, ref nint ptr, delegate*<ref byte, void> chain) | ||
{ | ||
(string, string) value; | ||
ptr = (nint)(&value); | ||
chain(ref ctx); | ||
ptr = 0; | ||
} | ||
|
||
BTDB.Serialization.ReflectionMetadata.RegisterStackAllocator(typeof((string, int)), &Allocate3); | ||
static void Allocate3(ref byte ctx, ref nint ptr, delegate*<ref byte, void> chain) | ||
{ | ||
(string, int) value; | ||
ptr = (nint)(&value); | ||
chain(ref ctx); | ||
ptr = 0; | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...nerator.Test/MetadataTests.VerifyStructFromCollections#TestNamespace.Person.g.verified.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,61 @@ | ||
//HintName: TestNamespace.Person.g.cs | ||
// <auto-generated/> | ||
#pragma warning disable 612,618 | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace TestNamespace; | ||
|
||
[CompilerGenerated] | ||
static file class PersonRegistration | ||
{ | ||
[UnsafeAccessor(UnsafeAccessorKind.Constructor)] | ||
extern static global::TestNamespace.Person Creator(); | ||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<Name>k__BackingField")] | ||
extern static ref string Field1(global::TestNamespace.Person @this); | ||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<Id2Names>k__BackingField")] | ||
extern static ref global::System.Collections.Generic.IDictionary<int, (string, string)> Field2(global::TestNamespace.Person @this); | ||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<NameSet2>k__BackingField")] | ||
extern static ref global::System.Collections.Generic.ISet<(string, int)> Field3(global::TestNamespace.Person @this); | ||
[ModuleInitializer] | ||
internal static unsafe void Register4BTDB() | ||
{ | ||
global::BTDB.IOC.IContainer.RegisterFactory(typeof(global::TestNamespace.Person), (container, ctx) => | ||
{ | ||
return (container2, ctx2) => | ||
{ | ||
var res = new global::TestNamespace.Person(); | ||
return res; | ||
}; | ||
}); | ||
var metadata = new global::BTDB.Serialization.ClassMetadata(); | ||
metadata.Name = "Person"; | ||
metadata.Type = typeof(global::TestNamespace.Person); | ||
metadata.Namespace = "TestNamespace"; | ||
metadata.Implements = []; | ||
metadata.Creator = &Creator; | ||
var dummy = Unsafe.As<global::TestNamespace.Person>(metadata); | ||
metadata.Fields = new[] | ||
{ | ||
new global::BTDB.Serialization.FieldMetadata | ||
{ | ||
Name = "Name", | ||
Type = typeof(string), | ||
ByteOffset = global::BTDB.Serialization.RawData.CalcOffset(dummy, ref Field1(dummy)), | ||
}, | ||
new global::BTDB.Serialization.FieldMetadata | ||
{ | ||
Name = "Id2Names", | ||
Type = typeof(global::System.Collections.Generic.IDictionary<int, (string, string)>), | ||
ByteOffset = global::BTDB.Serialization.RawData.CalcOffset(dummy, ref Field2(dummy)), | ||
}, | ||
new global::BTDB.Serialization.FieldMetadata | ||
{ | ||
Name = "NameSet2", | ||
Type = typeof(global::System.Collections.Generic.ISet<(string, int)>), | ||
ByteOffset = global::BTDB.Serialization.RawData.CalcOffset(dummy, ref Field3(dummy)), | ||
}, | ||
}; | ||
global::BTDB.Serialization.ReflectionMetadata.Register(metadata); | ||
} | ||
} |
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
Oops, something went wrong.