From: Tom Tromey Date: Mon, 8 Mar 2021 14:27:57 +0000 (-0700) Subject: Split out eval_op_f_abs X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cc05c68ee0d7903a2f21588b5d5b93d69fa5c1d1;p=binutils-gdb.git Split out eval_op_f_abs This splits UNOP_ABS into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey * f-lang.c (eval_op_f_abs): New function. (evaluate_subexp_f): Use it. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9bafa322e8f..058b0738540 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-03-08 Tom Tromey + + * f-lang.c (eval_op_f_abs): New function. + (evaluate_subexp_f): Use it. + 2021-03-08 Tom Tromey * eval.c (eval_op_type): New function. diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 01de51837f6..76b2f27e489 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -974,6 +974,35 @@ fortran_associated (struct gdbarch *gdbarch, const language_defn *lang, } +/* A helper function for UNOP_ABS. */ + +static struct value * +eval_op_f_abs (struct type *expect_type, struct expression *exp, + enum noside noside, + struct value *arg1) +{ + if (noside == EVAL_SKIP) + return eval_skip_value (exp); + struct type *type = value_type (arg1); + switch (type->code ()) + { + case TYPE_CODE_FLT: + { + double d + = fabs (target_float_to_host_double (value_contents (arg1), + value_type (arg1))); + return value_from_host_double (type, d); + } + case TYPE_CODE_INT: + { + LONGEST l = value_as_long (arg1); + l = llabs (l); + return value_from_longest (type, l); + } + } + error (_("ABS of type %s not supported"), TYPE_SAFE_NAME (type)); +} + /* Special expression evaluation cases for Fortran. */ static struct value * @@ -997,26 +1026,7 @@ evaluate_subexp_f (struct type *expect_type, struct expression *exp, case UNOP_ABS: arg1 = evaluate_subexp (nullptr, exp, pos, noside); - if (noside == EVAL_SKIP) - return eval_skip_value (exp); - type = value_type (arg1); - switch (type->code ()) - { - case TYPE_CODE_FLT: - { - double d - = fabs (target_float_to_host_double (value_contents (arg1), - value_type (arg1))); - return value_from_host_double (type, d); - } - case TYPE_CODE_INT: - { - LONGEST l = value_as_long (arg1); - l = llabs (l); - return value_from_longest (type, l); - } - } - error (_("ABS of type %s not supported"), TYPE_SAFE_NAME (type)); + return eval_op_f_abs (expect_type, exp, noside, arg1); case BINOP_MOD: arg1 = evaluate_subexp (nullptr, exp, pos, noside);