aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:27:59 -0700
commitf960a6176a3185a013db507c29d99d8c92eb21b9 (patch)
tree1cca3bba5070a10cf9fe446cf49d639d5a483acc
parent5c2f201e8d6cd3e4d9526d9d2833fa0cbaa93e67 (diff)
downloadbinutils-f960a6176a3185a013db507c29d99d8c92eb21b9.zip
binutils-f960a6176a3185a013db507c29d99d8c92eb21b9.tar.gz
binutils-f960a6176a3185a013db507c29d99d8c92eb21b9.tar.bz2
Split out eval_op_ternop
This splits TERNOP_SLICE into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * eval.c (eval_op_ternop): New function. (evaluate_subexp_standard): Use it.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/eval.c24
2 files changed, 22 insertions, 7 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7211862..b9b1c3f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * eval.c (eval_op_ternop): New function.
+ (evaluate_subexp_standard): Use it.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* eval.c (eval_op_concat): New function.
(evaluate_subexp_standard): Use it.
diff --git a/gdb/eval.c b/gdb/eval.c
index 3fc4422..afc79b2 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1324,6 +1324,20 @@ eval_op_concat (struct type *expect_type, struct expression *exp,
return value_concat (arg1, arg2);
}
+/* A helper function for TERNOP_SLICE. */
+
+static struct value *
+eval_op_ternop (struct type *expect_type, struct expression *exp,
+ enum noside noside,
+ struct value *array, struct value *low, struct value *upper)
+{
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+ int lowbound = value_as_long (low);
+ int upperbound = value_as_long (upper);
+ return value_slice (array, lowbound, upperbound - lowbound + 1);
+}
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
@@ -1579,13 +1593,9 @@ evaluate_subexp_standard (struct type *expect_type,
case TERNOP_SLICE:
{
struct value *array = evaluate_subexp (nullptr, exp, pos, noside);
- int lowbound
- = value_as_long (evaluate_subexp (nullptr, exp, pos, noside));
- int upper = value_as_long (evaluate_subexp (nullptr, exp, pos, noside));
-
- if (noside == EVAL_SKIP)
- return eval_skip_value (exp);
- return value_slice (array, lowbound, upper - lowbound + 1);
+ struct value *low = evaluate_subexp (nullptr, exp, pos, noside);
+ struct value *upper = evaluate_subexp (nullptr, exp, pos, noside);
+ return eval_op_ternop (expect_type, exp, noside, array, low, upper);
}
case TERNOP_COND: