aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-lang.c
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:08 -0700
commit051042333d9d7e2622f3825d5cf532676787dd1c (patch)
tree0ffdf3084848754b16efe922c86a871e27f421dd /gdb/rust-lang.c
parent6fa9831f89a3c788f4ea1ab6d1e2543dabfc0f8e (diff)
downloadgdb-051042333d9d7e2622f3825d5cf532676787dd1c.zip
gdb-051042333d9d7e2622f3825d5cf532676787dd1c.tar.gz
gdb-051042333d9d7e2622f3825d5cf532676787dd1c.tar.bz2
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.
Diffstat (limited to 'gdb/rust-lang.c')
-rw-r--r--gdb/rust-lang.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 449f14c..2653db3 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1354,6 +1354,34 @@ eval_op_rust_complement (struct type *expect_type, struct expression *exp,
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. */
static struct value *
@@ -1472,31 +1500,12 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
case OP_RUST_ARRAY:
{
(*pos)++;
- int copies;
struct value *elt;
struct value *ncopies;
elt = rust_evaluate_subexp (NULL, exp, pos, noside);
ncopies = rust_evaluate_subexp (NULL, exp, pos, noside);
- 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;
- 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);
- }
+ return eval_op_rust_array (expect_type, exp, noside, elt, ncopies);
}
break;