Introduce ada_pos_operation
[deliverable/binutils-gdb.git] / gdb / ada-exp.h
1 /* Definitions for Ada 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 ADA_EXP_H
21 #define ADA_EXP_H
22
23 #include "expop.h"
24
25 extern struct value *ada_unop_neg (struct type *expect_type,
26 struct expression *exp,
27 enum noside noside, enum exp_opcode op,
28 struct value *arg1);
29 extern struct value *ada_atr_tag (struct type *expect_type,
30 struct expression *exp,
31 enum noside noside, enum exp_opcode op,
32 struct value *arg1);
33 extern struct value *ada_atr_size (struct type *expect_type,
34 struct expression *exp,
35 enum noside noside, enum exp_opcode op,
36 struct value *arg1);
37 extern struct value *ada_abs (struct type *expect_type,
38 struct expression *exp,
39 enum noside noside, enum exp_opcode op,
40 struct value *arg1);
41 extern struct value *ada_unop_in_range (struct type *expect_type,
42 struct expression *exp,
43 enum noside noside, enum exp_opcode op,
44 struct value *arg1, struct type *type);
45 extern struct value *ada_mult_binop (struct type *expect_type,
46 struct expression *exp,
47 enum noside noside, enum exp_opcode op,
48 struct value *arg1, struct value *arg2);
49 extern struct value *ada_equal_binop (struct type *expect_type,
50 struct expression *exp,
51 enum noside noside, enum exp_opcode op,
52 struct value *arg1, struct value *arg2);
53 extern struct value *ada_ternop_slice (struct expression *exp,
54 enum noside noside,
55 struct value *array,
56 struct value *low_bound_val,
57 struct value *high_bound_val);
58 extern struct value *ada_binop_in_bounds (struct expression *exp,
59 enum noside noside,
60 struct value *arg1,
61 struct value *arg2,
62 int n);
63 extern struct value *ada_binop_minmax (struct type *expect_type,
64 struct expression *exp,
65 enum noside noside, enum exp_opcode op,
66 struct value *arg1,
67 struct value *arg2);
68 extern struct value *ada_pos_atr (struct type *expect_type,
69 struct expression *exp,
70 enum noside noside, enum exp_opcode op,
71 struct value *arg);
72
73 namespace expr
74 {
75
76 /* In Ada, some generic operations must be wrapped with a handler that
77 handles some Ada-specific type conversions. */
78 class ada_wrapped_operation
79 : public tuple_holding_operation<operation_up>
80 {
81 public:
82
83 using tuple_holding_operation::tuple_holding_operation;
84
85 value *evaluate (struct type *expect_type,
86 struct expression *exp,
87 enum noside noside) override;
88
89 enum exp_opcode opcode () const override
90 { return std::get<0> (m_storage)->opcode (); }
91 };
92
93 /* An Ada string constant. */
94 class ada_string_operation
95 : public string_operation
96 {
97 public:
98
99 using string_operation::string_operation;
100
101 value *evaluate (struct type *expect_type,
102 struct expression *exp,
103 enum noside noside) override;
104 };
105
106 /* The Ada TYPE'(EXP) construct. */
107 class ada_qual_operation
108 : public tuple_holding_operation<operation_up, struct type *>
109 {
110 public:
111
112 using tuple_holding_operation::tuple_holding_operation;
113
114 value *evaluate (struct type *expect_type,
115 struct expression *exp,
116 enum noside noside) override;
117
118 enum exp_opcode opcode () const override
119 { return UNOP_QUAL; }
120 };
121
122 /* Ternary in-range operator. */
123 class ada_ternop_range_operation
124 : public tuple_holding_operation<operation_up, operation_up, operation_up>
125 {
126 public:
127
128 using tuple_holding_operation::tuple_holding_operation;
129
130 value *evaluate (struct type *expect_type,
131 struct expression *exp,
132 enum noside noside) override;
133
134 enum exp_opcode opcode () const override
135 { return TERNOP_IN_RANGE; }
136 };
137
138 using ada_neg_operation = unop_operation<UNOP_NEG, ada_unop_neg>;
139 using ada_atr_tag_operation = unop_operation<OP_ATR_TAG, ada_atr_tag>;
140 using ada_atr_size_operation = unop_operation<OP_ATR_SIZE, ada_atr_size>;
141 using ada_abs_operation = unop_operation<UNOP_ABS, ada_abs>;
142 using ada_pos_operation = unop_operation<OP_ATR_POS, ada_pos_atr>;
143
144 /* The in-range operation, given a type. */
145 class ada_unop_range_operation
146 : public tuple_holding_operation<operation_up, struct type *>
147 {
148 public:
149
150 using tuple_holding_operation::tuple_holding_operation;
151
152 value *evaluate (struct type *expect_type,
153 struct expression *exp,
154 enum noside noside) override
155 {
156 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
157 return ada_unop_in_range (expect_type, exp, noside, UNOP_IN_RANGE,
158 val, std::get<1> (m_storage));
159 }
160
161 enum exp_opcode opcode () const override
162 { return UNOP_IN_RANGE; }
163 };
164
165 /* The Ada + and - operators. */
166 class ada_binop_addsub_operation
167 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
168 {
169 public:
170
171 using tuple_holding_operation::tuple_holding_operation;
172
173 value *evaluate (struct type *expect_type,
174 struct expression *exp,
175 enum noside noside) override;
176
177 enum exp_opcode opcode () const override
178 { return std::get<0> (m_storage); }
179 };
180
181 using ada_binop_mul_operation = binop_operation<BINOP_MUL, ada_mult_binop>;
182 using ada_binop_div_operation = binop_operation<BINOP_DIV, ada_mult_binop>;
183 using ada_binop_rem_operation = binop_operation<BINOP_REM, ada_mult_binop>;
184 using ada_binop_mod_operation = binop_operation<BINOP_MOD, ada_mult_binop>;
185
186 using ada_binop_min_operation = binop_operation<OP_ATR_MIN, ada_binop_minmax>;
187 using ada_binop_max_operation = binop_operation<OP_ATR_MAX, ada_binop_minmax>;
188
189 /* Implement the equal and not-equal operations for Ada. */
190 class ada_binop_equal_operation
191 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
192 {
193 public:
194
195 using tuple_holding_operation::tuple_holding_operation;
196
197 value *evaluate (struct type *expect_type,
198 struct expression *exp,
199 enum noside noside) override
200 {
201 value *arg1 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
202 value *arg2 = std::get<2> (m_storage)->evaluate (value_type (arg1),
203 exp, noside);
204 return ada_equal_binop (expect_type, exp, noside, std::get<0> (m_storage),
205 arg1, arg2);
206 }
207
208 enum exp_opcode opcode () const override
209 { return std::get<0> (m_storage); }
210 };
211
212 /* Bitwise operators for Ada. */
213 template<enum exp_opcode OP>
214 class ada_bitwise_operation
215 : public maybe_constant_operation<operation_up, operation_up>
216 {
217 public:
218
219 using maybe_constant_operation::maybe_constant_operation;
220
221 value *evaluate (struct type *expect_type,
222 struct expression *exp,
223 enum noside noside) override
224 {
225 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
226 value *rhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
227 value *result = eval_op_binary (expect_type, exp, noside, OP, lhs, rhs);
228 return value_cast (value_type (lhs), result);
229 }
230
231 enum exp_opcode opcode () const override
232 { return OP; }
233 };
234
235 using ada_bitwise_and_operation = ada_bitwise_operation<BINOP_BITWISE_AND>;
236 using ada_bitwise_ior_operation = ada_bitwise_operation<BINOP_BITWISE_IOR>;
237 using ada_bitwise_xor_operation = ada_bitwise_operation<BINOP_BITWISE_XOR>;
238
239 /* Ada array- or string-slice operation. */
240 class ada_ternop_slice_operation
241 : public maybe_constant_operation<operation_up, operation_up, operation_up>
242 {
243 public:
244
245 using maybe_constant_operation::maybe_constant_operation;
246
247 value *evaluate (struct type *expect_type,
248 struct expression *exp,
249 enum noside noside) override
250 {
251 value *array = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
252 value *low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
253 value *high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
254 return ada_ternop_slice (exp, noside, array, low, high);
255 }
256
257 enum exp_opcode opcode () const override
258 { return TERNOP_SLICE; }
259 };
260
261 /* Implement BINOP_IN_BOUNDS for Ada. */
262 class ada_binop_in_bounds_operation
263 : public maybe_constant_operation<operation_up, operation_up, int>
264 {
265 public:
266
267 using maybe_constant_operation::maybe_constant_operation;
268
269 value *evaluate (struct type *expect_type,
270 struct expression *exp,
271 enum noside noside) override
272 {
273 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
274 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
275 return ada_binop_in_bounds (exp, noside, arg1, arg2,
276 std::get<2> (m_storage));
277 }
278
279 enum exp_opcode opcode () const override
280 { return BINOP_IN_BOUNDS; }
281 };
282
283 /* Implement several unary Ada OP_ATR_* operations. */
284 class ada_unop_atr_operation
285 : public maybe_constant_operation<operation_up, enum exp_opcode, int>
286 {
287 public:
288
289 using maybe_constant_operation::maybe_constant_operation;
290
291 value *evaluate (struct type *expect_type,
292 struct expression *exp,
293 enum noside noside) override;
294
295 enum exp_opcode opcode () const override
296 { return std::get<1> (m_storage); }
297 };
298
299 /* Variant of var_value_operation for Ada. */
300 class ada_var_value_operation
301 : public var_value_operation
302 {
303 public:
304
305 using var_value_operation::var_value_operation;
306
307 value *evaluate (struct type *expect_type,
308 struct expression *exp,
309 enum noside noside) override;
310
311 value *evaluate_for_cast (struct type *expect_type,
312 struct expression *exp,
313 enum noside noside) override;
314
315 protected:
316
317 using operation::do_generate_ax;
318 };
319
320 /* Variant of var_msym_value_operation for Ada. */
321 class ada_var_msym_value_operation
322 : public var_msym_value_operation
323 {
324 public:
325
326 using var_msym_value_operation::var_msym_value_operation;
327
328 value *evaluate_for_cast (struct type *expect_type,
329 struct expression *exp,
330 enum noside noside) override;
331
332 protected:
333
334 using operation::do_generate_ax;
335 };
336
337 } /* namespace expr */
338
339 #endif /* ADA_EXP_H */
This page took 0.037464 seconds and 5 git commands to generate.