zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Casting to/from BigInteger doesn't work correctly

Open Mi-La opened this issue 7 years ago • 5 comments

Expressions don't propagate correctly the information whether BigInteger is used within the expression. We should keep the information even when the exact value can be evaluated.

Example:

const uint64 CONST_U64 = 10;
const uint8 CONST_U8 = CONST_U64;

In the example CONST_U64 has to keep information that needs BigInteger, because it has a BigInteger type in java. Therefore in the definition of CONST_U8, the BigInteger CONST_U64 has to be correclty casted to byte.

Note that there are more use-cases, e.g. definition of enum items, and all the use-cases have to be reviewed.

Mi-La avatar Dec 10 '18 12:12 Mi-La

Another use case:

enum uint64 TestEnum
{
    ONE, TWO, THREE
};

struct Test
{
    uint64 field1;
    uint32 field2 : field2 < field1;
    uint8 field3 : field3 < valueof(TestEnum.ONE);
};

mikir avatar Jun 10 '20 09:06 mikir

Another use case:

struct Test
{
    uint32 field32;
    uint64 field64;
    bit<field32 + field64> bitField;
};

Mi-La avatar Dec 21 '21 13:12 Mi-La

Another issue, alignment doesn't generate correct big integer expression.


struct Test
{
align(Const - 2):
    string text;
};

Mi-La avatar Jan 03 '22 10:01 Mi-La

Another issue:

const uint64 Constant = 2;
choice TestChoice(uint64 param) on (param + 2)
{
    case 2 + Constant:
        string field;
};

Mi-La avatar Jan 03 '22 16:01 Mi-La