mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 22:34:09 +02:00
Fixed static bitfields
This commit is contained in:
parent
df604e6657
commit
3c74588e10
2 changed files with 12 additions and 9 deletions
|
@ -147,6 +147,9 @@ namespace System
|
||||||
str.Append("public ");
|
str.Append("public ");
|
||||||
else if (mProtection == .Protected)
|
else if (mProtection == .Protected)
|
||||||
str.Append("protected ");
|
str.Append("protected ");
|
||||||
|
if (fieldInfo.IsStatic)
|
||||||
|
str.Append("static ");
|
||||||
|
bool wantsMut = fieldInfo.Owner.IsStruct && !fieldInfo.IsStatic;
|
||||||
|
|
||||||
void TypeStr(String str, Type t)
|
void TypeStr(String str, Type t)
|
||||||
{
|
{
|
||||||
|
@ -205,14 +208,14 @@ namespace System
|
||||||
{
|
{
|
||||||
if (pass == 0)
|
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
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
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))
|
if ((pass == 0) && (rangeCheckMin) && (rangeCheckMax))
|
||||||
str.AppendF($"\t\tRuntime.Assert((value >= {minVal}) && (value <= {maxVal}));\n");
|
str.AppendF($"\t\tRuntime.Assert((value >= {minVal}) && (value <= {maxVal}));\n");
|
||||||
else if ((pass == 0) && (rangeCheckMin))
|
else if ((pass == 0) && (rangeCheckMin))
|
||||||
|
|
|
@ -22,29 +22,29 @@ namespace Tests
|
||||||
[Bitfield<uint8>(.Public, .BitsRev(8), "F")]
|
[Bitfield<uint8>(.Public, .BitsRev(8), "F")]
|
||||||
[Bitfield<uint8>(.Public, .ValueRangeRev(0..<256), "G")]
|
[Bitfield<uint8>(.Public, .ValueRangeRev(0..<256), "G")]
|
||||||
[Bitfield<uint8>(.Public, .BitsAt(8, 0), "H")]
|
[Bitfield<uint8>(.Public, .BitsAt(8, 0), "H")]
|
||||||
public int32 mVal2;
|
public static int32 sVal2;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
static void TestBasics()
|
static void TestBasics()
|
||||||
{
|
{
|
||||||
Test.Assert(sizeof(StructA) == 8);
|
Test.Assert(sizeof(StructA) == 4);
|
||||||
StructA sa = .();
|
StructA sa = .();
|
||||||
sa.A = 0x12;
|
sa.A = 0x12;
|
||||||
sa.B = 7;
|
sa.B = 7;
|
||||||
sa.C = .C;
|
sa.C = .C;
|
||||||
sa.D = 9;
|
sa.D = 9;
|
||||||
sa.E = 0x22;
|
StructA.E = 0x22;
|
||||||
sa.F = 0x33;
|
StructA.F = 0x33;
|
||||||
sa.G = 0x44;
|
StructA.G = 0x44;
|
||||||
sa.H = 0x55;
|
StructA.H = 0x55;
|
||||||
Test.Assert(sa.A == 0x12);
|
Test.Assert(sa.A == 0x12);
|
||||||
Test.Assert(sa.B == 7);
|
Test.Assert(sa.B == 7);
|
||||||
Test.Assert(sa.C == .C);
|
Test.Assert(sa.C == .C);
|
||||||
Test.Assert(sa.D == 9);
|
Test.Assert(sa.D == 9);
|
||||||
|
|
||||||
Test.Assert(sa.mVal == 0x0025FF12);
|
Test.Assert(sa.mVal == 0x0025FF12);
|
||||||
Test.Assert(sa.mVal2 == 0x22334455);
|
Test.Assert(StructA.sVal2 == 0x22334455);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue