From: Tom Tromey Date: Mon, 8 Mar 2021 14:27:57 +0000 (-0700) Subject: Introduce assign_operation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=40786782896deaf8f97f8dc62b85d9facb30fc8a;p=binutils-gdb.git Introduce assign_operation This adds class assign_operation, which implements BINOP_ASSIGN. gdb/ChangeLog 2021-03-08 Tom Tromey * expop.h (class assign_operation): New. * ax-gdb.c (assign_operation::do_generate_ax): New method. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 58ada4e3282..6bf3cbf4594 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-03-08 Tom Tromey + + * expop.h (class assign_operation): New. + * ax-gdb.c (assign_operation::do_generate_ax): New method. + 2021-03-08 Tom Tromey * expop.h (class type_instance_operation): New. diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 98edc6c0727..d8b5ed78a40 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2579,6 +2579,36 @@ op_this_operation::do_generate_ax (struct expression *exp, sym->print_name ()); } +void +assign_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + operation *subop = std::get<0> (m_storage).get (); + if (subop->opcode () != OP_INTERNALVAR) + error (_("May only assign to trace state variables")); + + internalvar_operation *ivarop + = dynamic_cast (subop); + gdb_assert (ivarop != nullptr); + + const char *name = internalvar_name (ivarop->get_internalvar ()); + struct trace_state_variable *tsv; + + std::get<1> (m_storage)->generate_ax (exp, ax, value); + tsv = find_trace_state_variable (name); + if (tsv) + { + ax_tsv (ax, aop_setv, tsv->number); + if (ax->tracing) + ax_tsv (ax, aop_tracev, tsv->number); + } + else + error (_("$%s is not a trace state variable, " + "may not assign to it"), name); +} + } /* This handles the middle-to-right-side of code generation for binary diff --git a/gdb/expop.h b/gdb/expop.h index b196de52d0b..0f223654052 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 +{ +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 */