+\f
+
+namespace expr
+{
+
+void
+operation::generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ if (constant_p ())
+ {
+ struct value *v = evaluate (nullptr, exp, EVAL_AVOID_SIDE_EFFECTS);
+ ax_const_l (ax, value_as_long (v));
+ value->kind = axs_rvalue;
+ value->type = check_typedef (value_type (v));
+ }
+ else
+ {
+ do_generate_ax (exp, ax, value, cast_type);
+ if (cast_type != nullptr)
+ gen_cast (ax, value, cast_type);
+ }
+}
+
+void
+scope_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ struct type *type = std::get<0> (m_storage);
+ const std::string &name = std::get<1> (m_storage);
+ int found = gen_aggregate_elt_ref (ax, value, type, name.c_str ());
+ if (!found)
+ error (_("There is no field named %s"), name.c_str ());
+}
+
+void
+long_const_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ gen_int_literal (ax, value, std::get<1> (m_storage),
+ std::get<0> (m_storage));
+}
+
+void
+var_msym_value_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ const bound_minimal_symbol &b = std::get<0> (m_storage);
+ gen_msym_var_ref (ax, value, b.minsym, b.objfile);
+
+ if (value->type->code () == TYPE_CODE_ERROR)
+ {
+ if (cast_type == nullptr)
+ error_unknown_type (b.minsym->linkage_name ());
+ value->type = cast_type;
+ }
+}
+
+void
+register_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ const char *name = std::get<0> (m_storage).c_str ();
+ int len = std::get<0> (m_storage).size ();
+ int reg;
+
+ reg = user_reg_map_name_to_regnum (ax->gdbarch, name, len);
+ if (reg == -1)
+ internal_error (__FILE__, __LINE__,
+ _("Register $%s not available"), name);
+ /* No support for tracing user registers yet. */
+ if (reg >= gdbarch_num_cooked_regs (ax->gdbarch))
+ error (_("'%s' is a user-register; "
+ "GDB cannot yet trace user-register contents."),
+ name);
+ value->kind = axs_lvalue_register;
+ value->u.reg = reg;
+ value->type = register_type (ax->gdbarch, reg);
+}
+
+void
+internalvar_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ struct internalvar *var = std::get<0> (m_storage);
+ const char *name = internalvar_name (var);
+ struct trace_state_variable *tsv;
+
+ tsv = find_trace_state_variable (name);
+ if (tsv)
+ {
+ ax_tsv (ax, aop_getv, tsv->number);
+ if (ax->tracing)
+ ax_tsv (ax, aop_tracev, tsv->number);
+ /* Trace state variables are always 64-bit integers. */
+ value->kind = axs_rvalue;
+ value->type = builtin_type (ax->gdbarch)->builtin_long_long;
+ }
+ else if (! compile_internalvar_to_ax (var, ax, value))
+ error (_("$%s is not a trace state variable; GDB agent "
+ "expressions cannot use convenience variables."), name);
+}
+
+void
+ternop_cond_operation::do_generate_ax (struct expression *exp,
+ struct agent_expr *ax,
+ struct axs_value *value,
+ struct type *cast_type)
+{
+ struct axs_value value1, value2, value3;
+ int if1, end;
+
+ std::get<0> (m_storage)->generate_ax (exp, ax, &value1);
+ gen_usual_unary (ax, &value1);
+ /* For (A ? B : C), it's easiest to generate subexpression
+ bytecodes in order, but if_goto jumps on true, so we invert
+ the sense of A. Then we can do B by dropping through, and
+ jump to do C. */
+ gen_logical_not (ax, &value1, builtin_type (ax->gdbarch)->builtin_int);
+ if1 = ax_goto (ax, aop_if_goto);
+ std::get<1> (m_storage)->generate_ax (exp, ax, &value2);
+ gen_usual_unary (ax, &value2);
+ end = ax_goto (ax, aop_goto);
+ ax_label (ax, if1, ax->len);
+ std::get<2> (m_storage)->generate_ax (exp, ax, &value3);
+ gen_usual_unary (ax, &value3);
+ ax_label (ax, end, ax->len);
+ /* This is arbitrary - what if B and C are incompatible types? */
+ value->type = value2.type;
+ value->kind = value2.kind;
+}
+