[010/203] Split out eval_op_ternop

Message ID 20210101214723.1784144-11-tom@tromey.com
State Superseded
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Jan. 1, 2021, 9:44 p.m.
This splits TERNOP_SLICE into a new function for future use.

gdb/ChangeLog
2021-01-01  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_ternop): New function.
	(evaluate_subexp_standard): Use it.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    | 24 +++++++++++++++++-------
 2 files changed, 22 insertions(+), 7 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index f2507f25f44..f4af89bf928 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1309,6 +1309,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,
@@ -1564,13 +1578,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: