1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Update leading zeros based on bitSize

#1877
This commit is contained in:
hermansimensen 2023-07-24 22:00:04 +02:00
parent 9d0f656be2
commit 2b48e54903

View file

@ -160,6 +160,9 @@ namespace System
String bTypeStr = TypeStr(.. scope .(), mBFieldType); String bTypeStr = TypeStr(.. scope .(), mBFieldType);
int mask = ((1 << mBitPos) << bitCount) - (1 << mBitPos); int mask = ((1 << mBitPos) << bitCount) - (1 << mBitPos);
String maskStr = scope .();
mask.ToString(maskStr, scope String()..AppendF("X{}", bitSize/4), null);
if ((!hasRange) && (mBFieldType.IsSigned)) if ((!hasRange) && (mBFieldType.IsSigned))
{ {
minVal = -(1<<(bitCount-1)); minVal = -(1<<(bitCount-1));
@ -178,9 +181,9 @@ namespace System
if (mBFieldType == typeof(bool)) if (mBFieldType == typeof(bool))
str.AppendF($"(({fieldInfo.Name} & {mask}) >> {mBitPos}) != 0;\n"); str.AppendF($"(({fieldInfo.Name} & {mask}) >> {mBitPos}) != 0;\n");
else if (buType.IsSigned) else if (buType.IsSigned)
str.AppendF($"(.)((int)((({fieldInfo.Name} & 0x{mask:X16}) >> {mBitPos}) ^ 0x{1 << (bitCount - 1):X}) - 0x{1 << (bitCount - 1):X});\n"); str.AppendF($"(.)((int)((({fieldInfo.Name} & 0x{maskStr}) >> {mBitPos}) ^ 0x{1 << (bitCount - 1):X}) - 0x{1 << (bitCount - 1):X});\n");
else else
str.AppendF($"(.)(({fieldInfo.Name} & 0x{mask:X16}) >> {mBitPos});\n"); str.AppendF($"(.)(({fieldInfo.Name} & 0x{maskStr}) >> {mBitPos});\n");
} }
if (mBFieldType.IsInteger) if (mBFieldType.IsInteger)
@ -222,9 +225,9 @@ namespace System
} }
if (mBFieldType == typeof(bool)) if (mBFieldType == typeof(bool))
str.AppendF($"\t\t{fieldInfo.Name} = ({fieldInfo.Name} & ({uTypeStr})~0x{mask:X16}) | (value ? 0x{mask:X16} : 0);\n"); str.AppendF($"\t\t{fieldInfo.Name} = ({fieldInfo.Name} & ({uTypeStr})~0x{maskStr}) | (value ? 0x{maskStr} : 0);\n");
else else
str.AppendF($"\t\t{fieldInfo.Name} = ({fieldInfo.Name} & ({uTypeStr})~0x{mask:X16}) | ((({uTypeStr})value << {mBitPos}) & ({uTypeStr})0x{mask:X16});\n"); str.AppendF($"\t\t{fieldInfo.Name} = ({fieldInfo.Name} & ({uTypeStr})~0x{maskStr}) | ((({uTypeStr})value << {mBitPos}) & ({uTypeStr})0x{maskStr});\n");
str.Append("\t}\n"); str.Append("\t}\n");
} }