1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Fixed static bitfields

This commit is contained in:
Brian Fiete 2022-02-11 09:44:41 -05:00
parent df604e6657
commit 3c74588e10
2 changed files with 12 additions and 9 deletions

View file

@ -147,6 +147,9 @@ namespace System
str.Append("public ");
else if (mProtection == .Protected)
str.Append("protected ");
if (fieldInfo.IsStatic)
str.Append("static ");
bool wantsMut = fieldInfo.Owner.IsStruct && !fieldInfo.IsStatic;
void TypeStr(String str, Type t)
{
@ -205,14 +208,14 @@ namespace System
{
if (pass == 0)
{
str.AppendF($"\t[Inline]\n\tset{(fieldInfo.Owner.IsStruct ? " mut" : "")}\n\t{{\n");
str.AppendF($"\t[Inline]\n\tset{(wantsMut ? " mut" : "")}\n\t{{\n");
}
else
break;
}
else
{
str.AppendF($"\t[Inline, {((pass == 0) ? "Checked" : "Unchecked")}]\n\tset{(fieldInfo.Owner.IsStruct ? " mut" : "")}\n\t{{\n");
str.AppendF($"\t[Inline, {((pass == 0) ? "Checked" : "Unchecked")}]\n\tset{(wantsMut ? " mut" : "")}\n\t{{\n");
if ((pass == 0) && (rangeCheckMin) && (rangeCheckMax))
str.AppendF($"\t\tRuntime.Assert((value >= {minVal}) && (value <= {maxVal}));\n");
else if ((pass == 0) && (rangeCheckMin))

View file

@ -22,29 +22,29 @@ namespace Tests
[Bitfield<uint8>(.Public, .BitsRev(8), "F")]
[Bitfield<uint8>(.Public, .ValueRangeRev(0..<256), "G")]
[Bitfield<uint8>(.Public, .BitsAt(8, 0), "H")]
public int32 mVal2;
public static int32 sVal2;
}
[Test]
static void TestBasics()
{
Test.Assert(sizeof(StructA) == 8);
Test.Assert(sizeof(StructA) == 4);
StructA sa = .();
sa.A = 0x12;
sa.B = 7;
sa.C = .C;
sa.D = 9;
sa.E = 0x22;
sa.F = 0x33;
sa.G = 0x44;
sa.H = 0x55;
StructA.E = 0x22;
StructA.F = 0x33;
StructA.G = 0x44;
StructA.H = 0x55;
Test.Assert(sa.A == 0x12);
Test.Assert(sa.B == 7);
Test.Assert(sa.C == .C);
Test.Assert(sa.D == 9);
Test.Assert(sa.mVal == 0x0025FF12);
Test.Assert(sa.mVal2 == 0x22334455);
Test.Assert(StructA.sVal2 == 0x22334455);
}
}
}