]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce add_operation
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:19 +0000 (07:28 -0700)
This adds class add_operation, which implements BINOP_ADD.

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

* expop.h (class add_operation): New.
* eval.c (eval_op_add): No longer static.  Remove "op" parameter.
(evaluate_subexp_standard): Update.

gdb/ChangeLog
gdb/eval.c
gdb/expop.h

index 59cdff7ad81d45cc9b750cf534cc06615a915941..5fece77c5eac1f3e11f1c01844ed9b70fb453056 100644 (file)
@@ -1,3 +1,9 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class add_operation): New.
+       * eval.c (eval_op_add): No longer static.  Remove "op" parameter.
+       (evaluate_subexp_standard): Update.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class concat_operation): New.
index b78fa3b4c8a755713951dfe9e06f694967a077b5..cba5bcce332ee9dcf52a18cfd39bad8127da2b4f 100644 (file)
@@ -1459,15 +1459,15 @@ eval_op_member (struct type *expect_type, struct expression *exp,
 
 /* A helper function for BINOP_ADD.  */
 
-static struct value *
+struct value *
 eval_op_add (struct type *expect_type, struct expression *exp,
-            enum noside noside, enum exp_opcode op,
+            enum noside noside,
             struct value *arg1, struct value *arg2)
 {
   if (noside == EVAL_SKIP)
     return eval_skip_value (exp);
-  if (binop_user_defined_p (op, arg1, arg2))
-    return value_x_binop (arg1, arg2, op, OP_NULL, noside);
+  if (binop_user_defined_p (BINOP_ADD, arg1, arg2))
+    return value_x_binop (arg1, arg2, BINOP_ADD, OP_NULL, noside);
   else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
           && is_integral_or_integral_reference (value_type (arg2)))
     return value_ptradd (arg1, value_as_long (arg2));
@@ -2822,7 +2822,7 @@ evaluate_subexp_standard (struct type *expect_type,
     case BINOP_ADD:
       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
-      return eval_op_add (expect_type, exp, noside, op, arg1, arg2);
+      return eval_op_add (expect_type, exp, noside, arg1, arg2);
 
     case BINOP_SUB:
       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
index 16ee30d8d100d6b3c696daaa11258daa1a7a8bad..492d7babd4959fbae9f0a6cd2e7f348d10adc00a 100644 (file)
@@ -88,6 +88,10 @@ extern struct value *eval_op_concat (struct type *expect_type,
                                     struct expression *exp,
                                     enum noside noside,
                                     struct value *arg1, struct value *arg2);
+extern struct value *eval_op_add (struct type *expect_type,
+                                 struct expression *exp,
+                                 enum noside noside,
+                                 struct value *arg1, struct value *arg2);
 
 namespace expr
 {
@@ -961,6 +965,42 @@ public:
   { return BINOP_CONCAT; }
 };
 
+class add_operation
+  : public maybe_constant_operation<operation_up, operation_up>
+{
+public:
+
+  using maybe_constant_operation::maybe_constant_operation;
+
+  value *evaluate (struct type *expect_type,
+                  struct expression *exp,
+                  enum noside noside) override
+  {
+    value *lhs
+      = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
+    value *rhs
+      = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
+    return eval_op_add (expect_type, exp, noside, lhs, rhs);
+  }
+
+  enum exp_opcode opcode () const override
+  { return BINOP_ADD; }
+
+protected:
+
+  void do_generate_ax (struct expression *exp,
+                      struct agent_expr *ax,
+                      struct axs_value *value,
+                      struct type *cast_type)
+    override
+  {
+    gen_expr_binop (exp, BINOP_ADD,
+                   std::get<0> (this->m_storage).get (),
+                   std::get<1> (this->m_storage).get (),
+                   ax, value);
+  }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */