/* Perform arithmetic and other operations on values, for GDB.
- Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
- 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free
- Software Foundation, Inc.
+ Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
+ 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
+ Free Software Foundation, Inc.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
#include "defs.h"
#include "value.h"
return v;
}
\f
-/* Check to see if either argument is a structure. This is called so
- we know whether to go ahead with the normal binop or look for a
- user defined function instead.
+/* Check to see if either argument is a structure, or a reference to
+ one. This is called so we know whether to go ahead with the normal
+ binop or look for a user defined function instead.
For now, we do not overload the `=' operator. */
struct type *type1, *type2;
if (op == BINOP_ASSIGN || op == BINOP_CONCAT)
return 0;
+
type1 = check_typedef (value_type (arg1));
+ if (TYPE_CODE (type1) == TYPE_CODE_REF)
+ type1 = check_typedef (TYPE_TARGET_TYPE (type1));
+
type2 = check_typedef (value_type (arg2));
+ if (TYPE_CODE (type2) == TYPE_CODE_REF)
+ type2 = check_typedef (TYPE_TARGET_TYPE (type2));
+
return (TYPE_CODE (type1) == TYPE_CODE_STRUCT
- || TYPE_CODE (type2) == TYPE_CODE_STRUCT
- || (TYPE_CODE (type1) == TYPE_CODE_REF
- && TYPE_CODE (TYPE_TARGET_TYPE (type1)) == TYPE_CODE_STRUCT)
- || (TYPE_CODE (type2) == TYPE_CODE_REF
- && TYPE_CODE (TYPE_TARGET_TYPE (type2)) == TYPE_CODE_STRUCT));
+ || TYPE_CODE (type2) == TYPE_CODE_STRUCT);
}
/* Check to see if argument is a structure. This is called so
v = v1 / v2;
break;
- case BINOP_EXP:
- v = pow (v1, v2);
- if (errno)
- error (_("Cannot perform exponentiation: %s"), safe_strerror (errno));
- break;
+ case BINOP_EXP:
+ errno = 0;
+ v = pow (v1, v2);
+ if (errno)
+ error (_("Cannot perform exponentiation: %s"), safe_strerror (errno));
+ break;
default:
error (_("Integer-only operation on floating point number."));
/* If either arg was long double, make sure that value is also long
double. */
- if (TYPE_LENGTH (type1) * 8 > TARGET_DOUBLE_BIT
- || TYPE_LENGTH (type2) * 8 > TARGET_DOUBLE_BIT)
+ if (TYPE_LENGTH (type1) * 8 > gdbarch_double_bit (current_gdbarch)
+ || TYPE_LENGTH (type2) * 8 > gdbarch_double_bit (current_gdbarch))
val = allocate_value (builtin_type_long_double);
else
val = allocate_value (builtin_type_double);
Use the signedness of the operand with the greater length.
If both operands are of equal length, use unsigned operation
if one of the operands is unsigned. */
- if (promoted_len1 > promoted_len2)
+ if (op == BINOP_RSH || op == BINOP_LSH)
+ {
+ /* In case of the shift operators the type of the result only
+ depends on the type of the left operand. */
+ unsigned_operation = is_unsigned1;
+ result_len = promoted_len1;
+ }
+ else if (promoted_len1 > promoted_len2)
{
unsigned_operation = is_unsigned1;
result_len = promoted_len1;
v = v1 / v2;
break;
- case BINOP_EXP:
- v = pow (v1, v2);
- if (errno)
- error (_("Cannot perform exponentiation: %s"), safe_strerror (errno));
- break;
+ case BINOP_EXP:
+ errno = 0;
+ v = pow (v1, v2);
+ if (errno)
+ error (_("Cannot perform exponentiation: %s"), safe_strerror (errno));
+ break;
case BINOP_REM:
v = v1 % v2;
/* Can't just call init_type because we wouldn't know what
name to give the type. */
val = allocate_value
- (result_len > TARGET_LONG_BIT / HOST_CHAR_BIT
+ (result_len > gdbarch_long_bit (current_gdbarch) / HOST_CHAR_BIT
? builtin_type_unsigned_long_long
: builtin_type_unsigned_long);
store_unsigned_integer (value_contents_raw (val),
error (_("Division by zero"));
break;
- case BINOP_EXP:
- v = pow (v1, v2);
- if (errno)
- error (_("Cannot perform exponentiation: %s"), safe_strerror (errno));
+ case BINOP_EXP:
+ errno = 0;
+ v = pow (v1, v2);
+ if (errno)
+ error (_("Cannot perform exponentiation: %s"), safe_strerror (errno));
break;
case BINOP_REM:
/* Can't just call init_type because we wouldn't know what
name to give the type. */
val = allocate_value
- (result_len > TARGET_LONG_BIT / HOST_CHAR_BIT
+ (result_len > gdbarch_long_bit (current_gdbarch) / HOST_CHAR_BIT
? builtin_type_long_long
: builtin_type_long);
store_signed_integer (value_contents_raw (val),
BINOP_EQUAL)));
else if ((code1 == TYPE_CODE_FLT || is_int1)
&& (code2 == TYPE_CODE_FLT || is_int2))
- return value_as_double (arg1) == value_as_double (arg2);
+ {
+ /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
+ `long double' values are returned in static storage (m68k). */
+ DOUBLEST d = value_as_double (arg1);
+ return d == value_as_double (arg2);
+ }
/* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
is bigger. */
BINOP_LESS)));
else if ((code1 == TYPE_CODE_FLT || is_int1)
&& (code2 == TYPE_CODE_FLT || is_int2))
- return value_as_double (arg1) < value_as_double (arg2);
+ {
+ /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
+ `long double' values are returned in static storage (m68k). */
+ DOUBLEST d = value_as_double (arg1);
+ return d < value_as_double (arg2);
+ }
else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
return value_as_address (arg1) < value_as_address (arg2);