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

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

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

gdb/ChangeLog
gdb/eval.c

index 7835dd6fc79d9d18abb2e5780dee155a921ca581..3a6f893d2c56a56ea7c89702bbdbfb9e0ceddfcd 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * eval.c (eval_op_postinc): New function.
+       (evaluate_subexp_standard): Use it.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * eval.c (eval_op_predec): New file.
index a95894696455954287fb817d05d6109a0db65a57..6913278340724220b0c08d93f2c18ca19a34335d 100644 (file)
@@ -1971,6 +1971,40 @@ eval_op_predec (struct type *expect_type, struct expression *exp,
     }
 }
 
+/* A helper function for UNOP_POSTINCREMENT.  */
+
+static struct value *
+eval_op_postinc (struct type *expect_type, struct expression *exp,
+                enum noside noside, enum exp_opcode op,
+                struct value *arg1)
+{
+  if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
+    return arg1;
+  else if (unop_user_defined_p (op, arg1))
+    {
+      return value_x_unop (arg1, op, noside);
+    }
+  else
+    {
+      struct value *arg3 = value_non_lval (arg1);
+      struct value *arg2;
+
+      if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
+       arg2 = value_ptradd (arg1, 1);
+      else
+       {
+         struct value *tmp = arg1;
+
+         arg2 = value_one (value_type (arg1));
+         binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
+         arg2 = value_binop (tmp, arg2, BINOP_ADD);
+       }
+
+      value_assign (arg1, arg2);
+      return arg3;
+    }
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
                          struct expression *exp, int *pos,
@@ -2913,30 +2947,7 @@ evaluate_subexp_standard (struct type *expect_type,
 
     case UNOP_POSTINCREMENT:
       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
-      if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
-       return arg1;
-      else if (unop_user_defined_p (op, arg1))
-       {
-         return value_x_unop (arg1, op, noside);
-       }
-      else
-       {
-         arg3 = value_non_lval (arg1);
-
-         if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
-           arg2 = value_ptradd (arg1, 1);
-         else
-           {
-             struct value *tmp = arg1;
-
-             arg2 = value_one (value_type (arg1));
-             binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
-             arg2 = value_binop (tmp, arg2, BINOP_ADD);
-           }
-
-         value_assign (arg1, arg2);
-         return arg3;
-       }
+      return eval_op_postinc (expect_type, exp, noside, op, arg1);
 
     case UNOP_POSTDECREMENT:
       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
This page took 0.03188 seconds and 4 git commands to generate.