From 301f0ecf99facbe3fd62ccefbc69a3dd3acc7235 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Mon, 4 Feb 2008 00:23:05 +0000 Subject: * eval.c (evaluate_subexp_standard): Fix type of result of mixed integer/float division operations when EVAL_AVOID_SIDE_EFFECTS. * valops.c (value_one): New function. * value.h (value_one): Declare. Fix argument promotion for binary arithmetic ops for C. * valarith.c (unop_result_type): New fn. (binop_result_type): New fn. (value_binop): Move result type computation to binop_result_type. (value_pos, value_neg, value_complement): Move result type computation to unop_result_type. * gdb.base/whatis-exp.exp: Fix expected result of whatis x+y, x-y, x*y. --- gdb/valops.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'gdb/valops.c') diff --git a/gdb/valops.c b/gdb/valops.c index d4a0a9a..69ebb15 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -471,6 +471,40 @@ value_zero (struct type *type, enum lval_type lv) return val; } +/* Create a value of numeric type TYPE that is one, and return it. */ + +struct value * +value_one (struct type *type, enum lval_type lv) +{ + struct type *type1 = check_typedef (type); + struct value *val = NULL; /* avoid -Wall warning */ + + if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT) + { + struct value *int_one = value_from_longest (builtin_type_int, 1); + struct value *val; + gdb_byte v[16]; + + decimal_from_integral (int_one, v, TYPE_LENGTH (builtin_type_int)); + val = value_from_decfloat (type, v); + } + else if (TYPE_CODE (type1) == TYPE_CODE_FLT) + { + val = value_from_double (type, (DOUBLEST) 1); + } + else if (is_integral_type (type1)) + { + val = value_from_longest (type, (LONGEST) 1); + } + else + { + error (_("Not a numeric type.")); + } + + VALUE_LVAL (val) = lv; + return val; +} + /* Return a value with type TYPE located at ADDR. Call value_at only if the data needs to be fetched immediately; -- cgit v1.1