aboutsummaryrefslogtreecommitdiff
path: root/gdb/expop.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:23 -0700
commit40786782896deaf8f97f8dc62b85d9facb30fc8a (patch)
tree48e89cc17999476dc3b3864afcf76ef7715dd608 /gdb/expop.h
parent44b675c89b9d4e22ab60f51416b47634df2a3774 (diff)
downloadgdb-40786782896deaf8f97f8dc62b85d9facb30fc8a.zip
gdb-40786782896deaf8f97f8dc62b85d9facb30fc8a.tar.gz
gdb-40786782896deaf8f97f8dc62b85d9facb30fc8a.tar.bz2
Introduce assign_operation
This adds class assign_operation, which implements BINOP_ASSIGN. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expop.h (class assign_operation): New. * ax-gdb.c (assign_operation::do_generate_ax): New method.
Diffstat (limited to 'gdb/expop.h')
-rw-r--r--gdb/expop.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/gdb/expop.h b/gdb/expop.h
index b196de5..0f22365 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -1757,6 +1757,49 @@ public:
{ return TYPE_INSTANCE; }
};
+/* The assignment operator. */
+class assign_operation
+ : public tuple_holding_operation<operation_up, operation_up>
+{
+public:
+
+ using tuple_holding_operation::tuple_holding_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override
+ {
+ value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+ /* Special-case assignments where the left-hand-side is a
+ convenience variable -- in these, don't bother setting an
+ expected type. This avoids a weird case where re-assigning a
+ string or array to an internal variable could error with "Too
+ many array elements". */
+ struct type *xtype = (VALUE_LVAL (lhs) == lval_internalvar
+ ? nullptr
+ : value_type (lhs));
+ value *rhs = std::get<1> (m_storage)->evaluate (xtype, exp, noside);
+
+ if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
+ return lhs;
+ if (binop_user_defined_p (BINOP_ASSIGN, lhs, rhs))
+ return value_x_binop (lhs, rhs, BINOP_ASSIGN, OP_NULL, noside);
+ else
+ return value_assign (lhs, rhs);
+ }
+
+ enum exp_opcode opcode () const override
+ { return BINOP_ASSIGN; }
+
+protected:
+
+ void do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+ override;
+};
+
} /* namespace expr */
#endif /* EXPOP_H */