Split out eval_op_repeat
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:28:02 +0000 (07:28 -0700)
This splits BINOP_REPEAT into a new function for future use.

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

* eval.c (eval_op_repeat): New function.
(evaluate_subexp_standard): Use it.

gdb/ChangeLog
gdb/eval.c

index 6cc372978af155fe01b2e433a382f0bf88c963af..1da2a5c7570bc0d13aa55f48e6a2ea9dbd23813d 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * eval.c (eval_op_repeat): New function.
+       (evaluate_subexp_standard): Use it.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * eval.c (eval_op_leq): New function.
index 4e02bc0c88b70156a9406b170f2fed117b23150b..4ac323e4078017a2970e1257a97e09d9325af3f8 100644 (file)
@@ -1729,6 +1729,28 @@ eval_op_leq (struct type *expect_type, struct expression *exp,
     }
 }
 
+/* A helper function for BINOP_REPEAT.  */
+
+static struct value *
+eval_op_repeat (struct type *expect_type, struct expression *exp,
+               enum noside noside,
+               struct value *arg1, struct value *arg2)
+{
+  if (noside == EVAL_SKIP)
+    return eval_skip_value (exp);
+  struct type *type = check_typedef (value_type (arg2));
+  if (type->code () != TYPE_CODE_INT
+      && type->code () != TYPE_CODE_ENUM)
+    error (_("Non-integral right operand for \"@\" operator."));
+  if (noside == EVAL_AVOID_SIDE_EFFECTS)
+    {
+      return allocate_repeat_value (value_type (arg1),
+                                   longest_to_int (value_as_long (arg2)));
+    }
+  else
+    return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
                          struct expression *exp, int *pos,
@@ -2570,19 +2592,7 @@ evaluate_subexp_standard (struct type *expect_type,
     case BINOP_REPEAT:
       arg1 = evaluate_subexp (nullptr, exp, pos, noside);
       arg2 = evaluate_subexp (nullptr, exp, pos, noside);
-      if (noside == EVAL_SKIP)
-       return eval_skip_value (exp);
-      type = check_typedef (value_type (arg2));
-      if (type->code () != TYPE_CODE_INT
-         && type->code () != TYPE_CODE_ENUM)
-       error (_("Non-integral right operand for \"@\" operator."));
-      if (noside == EVAL_AVOID_SIDE_EFFECTS)
-       {
-         return allocate_repeat_value (value_type (arg1),
-                                    longest_to_int (value_as_long (arg2)));
-       }
-      else
-       return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
+      return eval_op_repeat (expect_type, exp, noside, arg1, arg2);
 
     case BINOP_COMMA:
       evaluate_subexp (nullptr, exp, pos, noside);