1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-18 00:07:21 +00:00

Last fix was wrong

git-svn-id: svn://svn.cc65.org/cc65/trunk@1999 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-03-04 11:02:11 +00:00
parent c008e555b2
commit 0ae6ab57ae

View File

@ -144,27 +144,20 @@ int TypeCast (ExprDesc* lval)
unsigned OldBits = OldSize * 8;
unsigned NewBits = NewSize * 8;
/* Remember if the old value was negative */
int Negative = (lval->ConstVal & (0x01UL << (OldBits-1))) != 0UL;
/* Check if the new datatype will have a smaller range */
/* Check if the new datatype will have a smaller range. If it
* has a larger range, things are ok, since the value is
* internally already represented by a long.
*/
if (NewBits <= OldBits) {
/* Cut the value to the new size */
lval->ConstVal &= (0xFFFFFFFFUL >> (32 - NewBits));
/* If the new type is signed and negative, sign extend the
* value
*/
if (Negative && !IsSignUnsigned (NewType)) {
lval->ConstVal |= ((~0L) << NewBits);
}
} else {
/* Sign extend the value if needed */
if (Negative && !IsSignUnsigned (OldType) && !IsSignUnsigned (NewType)) {
lval->ConstVal |= ((~0L) << OldBits);
/* If the new type is signed, sign extend the value */
if (!IsSignUnsigned (NewType)) {
if (lval->ConstVal & (0x01UL << (NewBits-1))) {
lval->ConstVal |= ((~0L) << NewBits);
}
}
}