mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-26 13:56:22 +08:00
Split out eval_op_rust_array
This splits OP_ARRAY into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * rust-lang.c (eval_op_rust_array): New function. (rust_evaluate_subexp): Use it.
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* rust-lang.c (eval_op_rust_array): New function.
|
||||||
|
(rust_evaluate_subexp): Use it.
|
||||||
|
|
||||||
2021-03-08 Tom Tromey <tom@tromey.com>
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* rust-lang.c (eval_op_rust_complement): New function.
|
* rust-lang.c (eval_op_rust_complement): New function.
|
||||||
|
@ -1354,6 +1354,34 @@ eval_op_rust_complement (struct type *expect_type, struct expression *exp,
|
|||||||
return value_complement (value);
|
return value_complement (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A helper function for OP_ARRAY. */
|
||||||
|
|
||||||
|
static struct value *
|
||||||
|
eval_op_rust_array (struct type *expect_type, struct expression *exp,
|
||||||
|
enum noside noside,
|
||||||
|
struct value *elt, struct value *ncopies)
|
||||||
|
{
|
||||||
|
int copies = value_as_long (ncopies);
|
||||||
|
if (copies < 0)
|
||||||
|
error (_("Array with negative number of elements"));
|
||||||
|
|
||||||
|
if (noside == EVAL_NORMAL)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
std::vector<struct value *> eltvec (copies);
|
||||||
|
|
||||||
|
for (i = 0; i < copies; ++i)
|
||||||
|
eltvec[i] = elt;
|
||||||
|
return value_array (0, copies - 1, eltvec.data ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct type *arraytype
|
||||||
|
= lookup_array_range_type (value_type (elt), 0, copies - 1);
|
||||||
|
return allocate_value (arraytype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* evaluate_exp implementation for Rust. */
|
/* evaluate_exp implementation for Rust. */
|
||||||
|
|
||||||
static struct value *
|
static struct value *
|
||||||
@ -1472,31 +1500,12 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
|
|||||||
case OP_RUST_ARRAY:
|
case OP_RUST_ARRAY:
|
||||||
{
|
{
|
||||||
(*pos)++;
|
(*pos)++;
|
||||||
int copies;
|
|
||||||
struct value *elt;
|
struct value *elt;
|
||||||
struct value *ncopies;
|
struct value *ncopies;
|
||||||
|
|
||||||
elt = rust_evaluate_subexp (NULL, exp, pos, noside);
|
elt = rust_evaluate_subexp (NULL, exp, pos, noside);
|
||||||
ncopies = rust_evaluate_subexp (NULL, exp, pos, noside);
|
ncopies = rust_evaluate_subexp (NULL, exp, pos, noside);
|
||||||
copies = value_as_long (ncopies);
|
return eval_op_rust_array (expect_type, exp, noside, elt, ncopies);
|
||||||
if (copies < 0)
|
|
||||||
error (_("Array with negative number of elements"));
|
|
||||||
|
|
||||||
if (noside == EVAL_NORMAL)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
std::vector<struct value *> eltvec (copies);
|
|
||||||
|
|
||||||
for (i = 0; i < copies; ++i)
|
|
||||||
eltvec[i] = elt;
|
|
||||||
result = value_array (0, copies - 1, eltvec.data ());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
struct type *arraytype
|
|
||||||
= lookup_array_range_type (value_type (elt), 0, copies - 1);
|
|
||||||
result = allocate_value (arraytype);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user