-static int typecast (ExprDesc* lval)
-/* Handle an explicit cast */
-{
- int k;
- type Type[MAXTYPELEN];
-
- /* Skip the left paren */
- NextToken ();
-
- /* Read the type */
- ParseType (Type);
-
- /* Closing paren */
- ConsumeRParen ();
-
- /* Read the expression we have to cast */
- k = hie10 (lval);
-
- /* If the expression is a function, treat it as pointer-to-function */
- if (IsTypeFunc (lval->Type)) {
- lval->Type = PointerTo (lval->Type);
- }
-
- /* Check for a constant on the right side */
- if (k == 0 && lval->Flags == E_MCONST) {
-
- /* A cast of a constant to something else. If the new type is an int,
- * be sure to handle the size extension correctly. If the new type is
- * not an int, the cast is implementation specific anyway, so leave
- * the value alone.
- */
- if (IsClassInt (Type)) {
-
- /* Get the current and new size of the value */
- unsigned OldSize = SizeOf (lval->Type);
- unsigned NewSize = SizeOf (Type);
- unsigned OldBits = OldSize * 8;
- unsigned NewBits = NewSize * 8;
-
- /* Check if the new datatype will have a smaller range */
- if (NewSize < OldSize) {
-
- /* Cut the value to the new size */
- lval->ConstVal &= (0xFFFFFFFFUL >> (32 - NewBits));
-
- /* If the new value is signed, sign extend the value */
- if (!IsSignUnsigned (Type)) {
- lval->ConstVal |= ((~0L) << NewBits);
- }
-
- } else if (NewSize > OldSize) {
-
- /* Sign extend the value if needed */
- if (!IsSignUnsigned (Type) && !IsSignUnsigned (lval->Type)) {
- if (lval->ConstVal & (0x01UL << (OldBits-1))) {
- lval->ConstVal |= ((~0L) << OldBits);
- }
- }
- }
- }
-
- } else {
-
- /* Not a constant. Be sure to ignore casts to void */
- if (!IsTypeVoid (Type)) {
-
- /* If the size does not change, leave the value alone. Otherwise,
- * we have to load the value into the primary and generate code to
- * cast the value in the primary register.
- */
- if (SizeOf (Type) != SizeOf (lval->Type)) {
-
- /* Load the value into the primary */
- exprhs (CF_NONE, k, lval);
-
- /* Mark the lhs as const to avoid a manipulation of TOS */
- g_typecast (TypeOf (Type) | CF_CONST, TypeOf (lval->Type));
-
- /* Value is now in primary */
- lval->Flags = E_MEXPR;
- k = 0;
- }
- }
- }
-
- /* In any case, use the new type */
- lval->Type = TypeDup (Type);
-
- /* Done */
- return k;
-}
-
-
-
-static int hie10 (ExprDesc* lval)