aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2008-02-04 00:23:05 +0000
committerDoug Evans <dje@google.com>2008-02-04 00:23:05 +0000
commit301f0ecf99facbe3fd62ccefbc69a3dd3acc7235 (patch)
tree412062f600c084e692c054aed6b904527f6eac46 /gdb/valops.c
parente44a2c9c3dd1e12fd2707c6407d3763fa8acae17 (diff)
downloadgdb-301f0ecf99facbe3fd62ccefbc69a3dd3acc7235.zip
gdb-301f0ecf99facbe3fd62ccefbc69a3dd3acc7235.tar.gz
gdb-301f0ecf99facbe3fd62ccefbc69a3dd3acc7235.tar.bz2
* 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.
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c34
1 files changed, 34 insertions, 0 deletions
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;