gdb/testsuite: restore configure script
[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 extern struct value *rust_range (struct type *expect_type,
46 struct expression *exp,
47 enum noside noside, enum range_flag kind,
48 struct value *low, struct value *high);
49 extern struct value *eval_op_rust_struct_anon (struct type *expect_type,
50 struct expression *exp,
51 enum noside noside,
52 int field_number,
53 struct value *lhs);
54 extern struct value *eval_op_rust_structop (struct type *expect_type,
55 struct expression *exp,
56 enum noside noside,
57 struct value *lhs,
58 const char *field_name);
59
60 namespace expr
61 {
62
63 using rust_unop_compl_operation = unop_operation<UNOP_COMPLEMENT,
64 eval_op_rust_complement>;
65 using rust_array_operation = binop_operation<OP_RUST_ARRAY,
66 eval_op_rust_array>;
67
68 /* The Rust indirection operation. */
69 class rust_unop_ind_operation
70 : public unop_ind_operation
71 {
72 public:
73
74 using unop_ind_operation::unop_ind_operation;
75
76 value *evaluate (struct type *expect_type,
77 struct expression *exp,
78 enum noside noside) override
79 {
80 if (noside != EVAL_NORMAL)
81 return unop_ind_operation::evaluate (expect_type, exp, noside);
82
83 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
84 return eval_op_rust_ind (expect_type, exp, noside, UNOP_IND, arg1);
85 }
86 };
87
88 /* Subscript operator for Rust. */
89 class rust_subscript_operation
90 : public tuple_holding_operation<operation_up, operation_up>
91 {
92 public:
93
94 using tuple_holding_operation::tuple_holding_operation;
95
96 value *evaluate (struct type *expect_type,
97 struct expression *exp,
98 enum noside noside) override
99 {
100 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
101 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
102 return rust_subscript (expect_type, exp, noside, false, arg1, arg2);
103 }
104
105 value *slice (struct type *expect_type,
106 struct expression *exp,
107 enum noside noside)
108 {
109 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
110 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
111 return rust_subscript (expect_type, exp, noside, true, arg1, arg2);
112 }
113
114 enum exp_opcode opcode () const override
115 { return BINOP_SUBSCRIPT; }
116 };
117
118 class rust_unop_addr_operation
119 : public tuple_holding_operation<operation_up>
120 {
121 public:
122
123 using tuple_holding_operation::tuple_holding_operation;
124
125 value *evaluate (struct type *expect_type,
126 struct expression *exp,
127 enum noside noside) override
128 {
129 operation *oper = std::get<0> (m_storage).get ();
130 rust_subscript_operation *sub_op
131 = dynamic_cast<rust_subscript_operation *> (oper);
132 if (sub_op != nullptr)
133 return sub_op->slice (expect_type, exp, noside);
134 return oper->evaluate_for_address (exp, noside);
135 }
136
137 enum exp_opcode opcode () const override
138 { return UNOP_ADDR; }
139 };
140
141 /* The Rust range operators. */
142 class rust_range_operation
143 : public tuple_holding_operation<enum range_flag, operation_up, operation_up>
144 {
145 public:
146
147 using tuple_holding_operation::tuple_holding_operation;
148
149 value *evaluate (struct type *expect_type,
150 struct expression *exp,
151 enum noside noside) override
152 {
153 auto kind = std::get<0> (m_storage);
154 value *low = nullptr;
155 if (std::get<1> (m_storage) != nullptr)
156 low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
157 value *high = nullptr;
158 if (std::get<2> (m_storage) != nullptr)
159 high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
160 return rust_range (expect_type, exp, noside, kind, low, high);
161 }
162
163 enum exp_opcode opcode () const override
164 { return OP_RANGE; }
165 };
166
167 /* Tuple field reference (using an integer). */
168 class rust_struct_anon
169 : public tuple_holding_operation<int, operation_up>
170 {
171 public:
172
173 using tuple_holding_operation::tuple_holding_operation;
174
175 value *evaluate (struct type *expect_type,
176 struct expression *exp,
177 enum noside noside) override
178 {
179 value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
180 return eval_op_rust_struct_anon (expect_type, exp, noside,
181 std::get<0> (m_storage), lhs);
182
183 }
184
185 enum exp_opcode opcode () const override
186 { return STRUCTOP_ANONYMOUS; }
187 };
188
189 /* Structure (or union or enum) field reference. */
190 class rust_structop
191 : public structop_base_operation
192 {
193 public:
194
195 using structop_base_operation::structop_base_operation;
196
197 value *evaluate (struct type *expect_type,
198 struct expression *exp,
199 enum noside noside) override
200 {
201 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
202 return eval_op_rust_structop (expect_type, exp, noside, lhs,
203 std::get<1> (m_storage).c_str ());
204 }
205
206 value *evaluate_funcall (struct type *expect_type,
207 struct expression *exp,
208 enum noside noside,
209 const std::vector<operation_up> &args) override;
210
211 enum exp_opcode opcode () const override
212 { return STRUCTOP_STRUCT; }
213 };
214
215 /* Rust aggregate initialization. */
216 class rust_aggregate_operation
217 : public tuple_holding_operation<struct type *, operation_up,
218 std::vector<std::pair<std::string,
219 operation_up>>>
220 {
221 public:
222
223 using tuple_holding_operation::tuple_holding_operation;
224
225 value *evaluate (struct type *expect_type,
226 struct expression *exp,
227 enum noside noside) override;
228
229 enum exp_opcode opcode () const override
230 { return OP_AGGREGATE; }
231 };
232
233 } /* namespace expr */
234
235 #endif /* RUST_EXP_H */
This page took 0.036094 seconds and 4 git commands to generate.