Introduce rust_aggregate_operation
This adds class rust_aggregate_operation, which implements OP_AGGREGATE for Rust. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * rust-lang.c (rust_aggregate_operation::evaluate): New method. * rust-exp.h (class rust_aggregate_operation): New.
This commit is contained in:
parent
e4407a202d
commit
5947d337d6
3 changed files with 81 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* rust-lang.c (rust_aggregate_operation::evaluate): New method.
|
||||||
|
* rust-exp.h (class rust_aggregate_operation): New.
|
||||||
|
|
||||||
2021-03-08 Tom Tromey <tom@tromey.com>
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* rust-lang.c (eval_op_rust_struct_anon, eval_op_rust_structop):
|
* rust-lang.c (eval_op_rust_struct_anon, eval_op_rust_structop):
|
||||||
|
|
|
@ -207,6 +207,24 @@ public:
|
||||||
{ return STRUCTOP_STRUCT; }
|
{ return STRUCTOP_STRUCT; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Rust aggregate initialization. */
|
||||||
|
class rust_aggregate_operation
|
||||||
|
: public tuple_holding_operation<struct type *, operation_up,
|
||||||
|
std::vector<std::pair<std::string,
|
||||||
|
operation_up>>>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using tuple_holding_operation::tuple_holding_operation;
|
||||||
|
|
||||||
|
value *evaluate (struct type *expect_type,
|
||||||
|
struct expression *exp,
|
||||||
|
enum noside noside) override;
|
||||||
|
|
||||||
|
enum exp_opcode opcode () const override
|
||||||
|
{ return OP_AGGREGATE; }
|
||||||
|
};
|
||||||
|
|
||||||
} /* namespace expr */
|
} /* namespace expr */
|
||||||
|
|
||||||
#endif /* RUST_EXP_H */
|
#endif /* RUST_EXP_H */
|
||||||
|
|
|
@ -1700,6 +1700,64 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace expr
|
||||||
|
{
|
||||||
|
|
||||||
|
value *
|
||||||
|
rust_aggregate_operation::evaluate (struct type *expect_type,
|
||||||
|
struct expression *exp,
|
||||||
|
enum noside noside)
|
||||||
|
{
|
||||||
|
struct type *type = std::get<0> (m_storage);
|
||||||
|
CORE_ADDR addr = 0;
|
||||||
|
struct value *addrval = NULL;
|
||||||
|
value *result;
|
||||||
|
|
||||||
|
if (noside == EVAL_NORMAL)
|
||||||
|
{
|
||||||
|
addrval = value_allocate_space_in_inferior (TYPE_LENGTH (type));
|
||||||
|
addr = value_as_long (addrval);
|
||||||
|
result = value_at_lazy (type, addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::get<1> (m_storage) != nullptr)
|
||||||
|
{
|
||||||
|
struct value *init = std::get<1> (m_storage)->evaluate (nullptr, exp,
|
||||||
|
noside);
|
||||||
|
|
||||||
|
if (noside == EVAL_NORMAL)
|
||||||
|
{
|
||||||
|
/* This isn't quite right but will do for the time
|
||||||
|
being, seeing that we can't implement the Copy
|
||||||
|
trait anyway. */
|
||||||
|
value_assign (result, init);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &item : std::get<2> (m_storage))
|
||||||
|
{
|
||||||
|
value *val = item.second->evaluate (nullptr, exp, noside);
|
||||||
|
if (noside == EVAL_NORMAL)
|
||||||
|
{
|
||||||
|
const char *fieldname = item.first.c_str ();
|
||||||
|
value *field = value_struct_elt (&result, nullptr, fieldname,
|
||||||
|
nullptr, "structure");
|
||||||
|
value_assign (field, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (noside == EVAL_SKIP)
|
||||||
|
result = value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
|
||||||
|
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
||||||
|
result = allocate_value (type);
|
||||||
|
else
|
||||||
|
result = value_at_lazy (type, addr);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* operator_length implementation for Rust. */
|
/* operator_length implementation for Rust. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue