aboutsummaryrefslogtreecommitdiff
path: root/gdb
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:26 -0700
commit6fab435953629ec50e2c367a0fbe305e4e5abf3f (patch)
treef392b67237130fa83e6b99751075e9fe2c39c1d6 /gdb
parent9dcd3e295774f93ec0cdcd687481c98e2d5e606c (diff)
downloadgdb-6fab435953629ec50e2c367a0fbe305e4e5abf3f.zip
gdb-6fab435953629ec50e2c367a0fbe305e4e5abf3f.tar.gz
gdb-6fab435953629ec50e2c367a0fbe305e4e5abf3f.tar.bz2
Implement some Rust operations
This implements some straightforward Rust operations, using existing template classes. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * rust-lang.c (eval_op_rust_complement, eval_op_rust_array): No longer static. Add "opcode" parameter. (rust_evaluate_subexp): Update. * rust-exp.h: New file.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/rust-exp.h47
-rw-r--r--gdb/rust-lang.c14
3 files changed, 63 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 918a8fc..06be5b9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * rust-lang.c (eval_op_rust_complement, eval_op_rust_array): No
+ longer static. Add "opcode" parameter.
+ (rust_evaluate_subexp): Update.
+ * rust-exp.h: New file.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* f-lang.c (eval_op_f_abs, eval_op_f_mod, eval_op_f_ceil)
(eval_op_f_floor, eval_op_f_modulo, eval_op_f_cmplx)
(eval_op_f_kind): No longer static. Add "opcode" parameter.
diff --git a/gdb/rust-exp.h b/gdb/rust-exp.h
new file mode 100644
index 0000000..cce1fd9
--- /dev/null
+++ b/gdb/rust-exp.h
@@ -0,0 +1,47 @@
+/* Definitions for Rust expressions
+
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef RUST_EXP_H
+#define RUST_EXP_H
+
+#include "expop.h"
+
+extern struct value *eval_op_rust_complement (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ enum exp_opcode opcode,
+ struct value *value);
+extern struct value *eval_op_rust_array (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ enum exp_opcode opcode,
+ struct value *ncopies,
+ struct value *elt);
+
+namespace expr
+{
+
+using rust_unop_compl_operation = unop_operation<UNOP_COMPLEMENT,
+ eval_op_rust_complement>;
+using rust_array_operation = binop_operation<OP_RUST_ARRAY,
+ eval_op_rust_array>;
+
+} /* namespace expr */
+
+#endif /* RUST_EXP_H */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 3b86382..63ea21b 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -39,6 +39,7 @@
#include <vector>
#include "cli/cli-style.h"
#include "parser-defs.h"
+#include "rust-exp.h"
/* See rust-lang.h. */
@@ -1339,9 +1340,10 @@ eval_op_rust_ind (struct type *expect_type, struct expression *exp,
/* A helper function for UNOP_COMPLEMENT. */
-static struct value *
+struct value *
eval_op_rust_complement (struct type *expect_type, struct expression *exp,
enum noside noside,
+ enum exp_opcode opcode,
struct value *value)
{
if (noside == EVAL_SKIP)
@@ -1356,9 +1358,10 @@ eval_op_rust_complement (struct type *expect_type, struct expression *exp,
/* A helper function for OP_ARRAY. */
-static struct value *
+struct value *
eval_op_rust_array (struct type *expect_type, struct expression *exp,
enum noside noside,
+ enum exp_opcode opcode,
struct value *elt, struct value *ncopies)
{
int copies = value_as_long (ncopies);
@@ -1505,8 +1508,9 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
int *pos, enum noside noside)
{
struct value *result;
+ enum exp_opcode op = exp->elts[*pos].opcode;
- switch (exp->elts[*pos].opcode)
+ switch (op)
{
case UNOP_IND:
{
@@ -1528,7 +1532,7 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
++*pos;
value = evaluate_subexp (nullptr, exp, pos, noside);
- result = eval_op_rust_complement (expect_type, exp, noside, value);
+ result = eval_op_rust_complement (expect_type, exp, noside, op, value);
}
break;
@@ -1621,7 +1625,7 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
elt = rust_evaluate_subexp (NULL, exp, pos, noside);
ncopies = rust_evaluate_subexp (NULL, exp, pos, noside);
- return eval_op_rust_array (expect_type, exp, noside, elt, ncopies);
+ return eval_op_rust_array (expect_type, exp, noside, op, elt, ncopies);
}
break;