Split out eval_op_ternop
authorTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:57 +0000 (07:27 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:59 +0000 (07:27 -0700)
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.

gdb/ChangeLog
gdb/eval.c

index 72118628e31b6c0c5492eb22ee3c61a86ddb2f9b..b9b1c3f4664498a469070151d41d3e433a28717e 100644 (file)
@@ -1,3 +1,8 @@
+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.
index 3fc4422b9ba6eda8829dbe85d9cc56d3c65f53cc..afc79b2f8c47ff0fad957861a66fad5e3663292e 100644 (file)
@@ -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: