7571009ea39552d29fffc24341e33401434136a3
[deliverable/binutils-gdb.git] / gdb / rust-exp.h
1 /* Definitions for Rust expressions
2
3 Copyright (C) 2020 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef RUST_EXP_H
21 #define RUST_EXP_H
22
23 #include "expop.h"
24
25 extern struct value *eval_op_rust_complement (struct type *expect_type,
26 struct expression *exp,
27 enum noside noside,
28 enum exp_opcode opcode,
29 struct value *value);
30 extern struct value *eval_op_rust_array (struct type *expect_type,
31 struct expression *exp,
32 enum noside noside,
33 enum exp_opcode opcode,
34 struct value *ncopies,
35 struct value *elt);
36 extern struct value *eval_op_rust_ind (struct type *expect_type,
37 struct expression *exp,
38 enum noside noside,
39 enum exp_opcode opcode,
40 struct value *value);
41 extern struct value *rust_subscript (struct type *expect_type,
42 struct expression *exp,
43 enum noside noside, bool for_addr,
44 struct value *lhs, struct value *rhs);
45
46 namespace expr
47 {
48
49 using rust_unop_compl_operation = unop_operation<UNOP_COMPLEMENT,
50 eval_op_rust_complement>;
51 using rust_array_operation = binop_operation<OP_RUST_ARRAY,
52 eval_op_rust_array>;
53
54 /* The Rust indirection operation. */
55 class rust_unop_ind_operation
56 : public unop_ind_operation
57 {
58 public:
59
60 using unop_ind_operation::unop_ind_operation;
61
62 value *evaluate (struct type *expect_type,
63 struct expression *exp,
64 enum noside noside) override
65 {
66 if (noside != EVAL_NORMAL)
67 return unop_ind_operation::evaluate (expect_type, exp, noside);
68
69 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
70 return eval_op_rust_ind (expect_type, exp, noside, UNOP_IND, arg1);
71 }
72 };
73
74 /* Subscript operator for Rust. */
75 class rust_subscript_operation
76 : public tuple_holding_operation<operation_up, operation_up>
77 {
78 public:
79
80 using tuple_holding_operation::tuple_holding_operation;
81
82 value *evaluate (struct type *expect_type,
83 struct expression *exp,
84 enum noside noside) override
85 {
86 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
87 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
88 return rust_subscript (expect_type, exp, noside, false, arg1, arg2);
89 }
90
91 value *slice (struct type *expect_type,
92 struct expression *exp,
93 enum noside noside)
94 {
95 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
96 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
97 return rust_subscript (expect_type, exp, noside, true, arg1, arg2);
98 }
99
100 enum exp_opcode opcode () const override
101 { return BINOP_SUBSCRIPT; }
102 };
103
104 class rust_unop_addr_operation
105 : public tuple_holding_operation<operation_up>
106 {
107 public:
108
109 using tuple_holding_operation::tuple_holding_operation;
110
111 value *evaluate (struct type *expect_type,
112 struct expression *exp,
113 enum noside noside) override
114 {
115 operation *oper = std::get<0> (m_storage).get ();
116 rust_subscript_operation *sub_op
117 = dynamic_cast<rust_subscript_operation *> (oper);
118 if (sub_op != nullptr)
119 return sub_op->slice (expect_type, exp, noside);
120 return oper->evaluate_for_address (exp, noside);
121 }
122
123 enum exp_opcode opcode () const override
124 { return UNOP_ADDR; }
125 };
126
127 } /* namespace expr */
128
129 #endif /* RUST_EXP_H */
This page took 0.032104 seconds and 3 git commands to generate.