Implement function calls for Ada
[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 extern struct value *ada_val_atr (enum noside noside, struct type *type,
73 struct value *arg);
74 extern struct value *ada_binop_exp (struct type *expect_type,
75 struct expression *exp,
76 enum noside noside, enum exp_opcode op,
77 struct value *arg1, struct value *arg2);
78
79 namespace expr
80 {
81
82 /* In Ada, some generic operations must be wrapped with a handler that
83 handles some Ada-specific type conversions. */
84 class ada_wrapped_operation
85 : public tuple_holding_operation<operation_up>
86 {
87 public:
88
89 using tuple_holding_operation::tuple_holding_operation;
90
91 value *evaluate (struct type *expect_type,
92 struct expression *exp,
93 enum noside noside) override;
94
95 enum exp_opcode opcode () const override
96 { return std::get<0> (m_storage)->opcode (); }
97 };
98
99 /* An Ada string constant. */
100 class ada_string_operation
101 : public string_operation
102 {
103 public:
104
105 using string_operation::string_operation;
106
107 value *evaluate (struct type *expect_type,
108 struct expression *exp,
109 enum noside noside) override;
110 };
111
112 /* The Ada TYPE'(EXP) construct. */
113 class ada_qual_operation
114 : public tuple_holding_operation<operation_up, struct type *>
115 {
116 public:
117
118 using tuple_holding_operation::tuple_holding_operation;
119
120 value *evaluate (struct type *expect_type,
121 struct expression *exp,
122 enum noside noside) override;
123
124 enum exp_opcode opcode () const override
125 { return UNOP_QUAL; }
126 };
127
128 /* Ternary in-range operator. */
129 class ada_ternop_range_operation
130 : public tuple_holding_operation<operation_up, operation_up, operation_up>
131 {
132 public:
133
134 using tuple_holding_operation::tuple_holding_operation;
135
136 value *evaluate (struct type *expect_type,
137 struct expression *exp,
138 enum noside noside) override;
139
140 enum exp_opcode opcode () const override
141 { return TERNOP_IN_RANGE; }
142 };
143
144 using ada_neg_operation = unop_operation<UNOP_NEG, ada_unop_neg>;
145 using ada_atr_tag_operation = unop_operation<OP_ATR_TAG, ada_atr_tag>;
146 using ada_atr_size_operation = unop_operation<OP_ATR_SIZE, ada_atr_size>;
147 using ada_abs_operation = unop_operation<UNOP_ABS, ada_abs>;
148 using ada_pos_operation = unop_operation<OP_ATR_POS, ada_pos_atr>;
149
150 /* The in-range operation, given a type. */
151 class ada_unop_range_operation
152 : public tuple_holding_operation<operation_up, struct type *>
153 {
154 public:
155
156 using tuple_holding_operation::tuple_holding_operation;
157
158 value *evaluate (struct type *expect_type,
159 struct expression *exp,
160 enum noside noside) override
161 {
162 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
163 return ada_unop_in_range (expect_type, exp, noside, UNOP_IN_RANGE,
164 val, std::get<1> (m_storage));
165 }
166
167 enum exp_opcode opcode () const override
168 { return UNOP_IN_RANGE; }
169 };
170
171 /* The Ada + and - operators. */
172 class ada_binop_addsub_operation
173 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
174 {
175 public:
176
177 using tuple_holding_operation::tuple_holding_operation;
178
179 value *evaluate (struct type *expect_type,
180 struct expression *exp,
181 enum noside noside) override;
182
183 enum exp_opcode opcode () const override
184 { return std::get<0> (m_storage); }
185 };
186
187 using ada_binop_mul_operation = binop_operation<BINOP_MUL, ada_mult_binop>;
188 using ada_binop_div_operation = binop_operation<BINOP_DIV, ada_mult_binop>;
189 using ada_binop_rem_operation = binop_operation<BINOP_REM, ada_mult_binop>;
190 using ada_binop_mod_operation = binop_operation<BINOP_MOD, ada_mult_binop>;
191
192 using ada_binop_min_operation = binop_operation<OP_ATR_MIN, ada_binop_minmax>;
193 using ada_binop_max_operation = binop_operation<OP_ATR_MAX, ada_binop_minmax>;
194
195 using ada_binop_exp_operation = binop_operation<BINOP_EXP, ada_binop_exp>;
196
197 /* Implement the equal and not-equal operations for Ada. */
198 class ada_binop_equal_operation
199 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
200 {
201 public:
202
203 using tuple_holding_operation::tuple_holding_operation;
204
205 value *evaluate (struct type *expect_type,
206 struct expression *exp,
207 enum noside noside) override
208 {
209 value *arg1 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
210 value *arg2 = std::get<2> (m_storage)->evaluate (value_type (arg1),
211 exp, noside);
212 return ada_equal_binop (expect_type, exp, noside, std::get<0> (m_storage),
213 arg1, arg2);
214 }
215
216 enum exp_opcode opcode () const override
217 { return std::get<0> (m_storage); }
218 };
219
220 /* Bitwise operators for Ada. */
221 template<enum exp_opcode OP>
222 class ada_bitwise_operation
223 : public maybe_constant_operation<operation_up, operation_up>
224 {
225 public:
226
227 using maybe_constant_operation::maybe_constant_operation;
228
229 value *evaluate (struct type *expect_type,
230 struct expression *exp,
231 enum noside noside) override
232 {
233 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
234 value *rhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
235 value *result = eval_op_binary (expect_type, exp, noside, OP, lhs, rhs);
236 return value_cast (value_type (lhs), result);
237 }
238
239 enum exp_opcode opcode () const override
240 { return OP; }
241 };
242
243 using ada_bitwise_and_operation = ada_bitwise_operation<BINOP_BITWISE_AND>;
244 using ada_bitwise_ior_operation = ada_bitwise_operation<BINOP_BITWISE_IOR>;
245 using ada_bitwise_xor_operation = ada_bitwise_operation<BINOP_BITWISE_XOR>;
246
247 /* Ada array- or string-slice operation. */
248 class ada_ternop_slice_operation
249 : public maybe_constant_operation<operation_up, operation_up, operation_up>
250 {
251 public:
252
253 using maybe_constant_operation::maybe_constant_operation;
254
255 value *evaluate (struct type *expect_type,
256 struct expression *exp,
257 enum noside noside) override
258 {
259 value *array = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
260 value *low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
261 value *high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
262 return ada_ternop_slice (exp, noside, array, low, high);
263 }
264
265 enum exp_opcode opcode () const override
266 { return TERNOP_SLICE; }
267 };
268
269 /* Implement BINOP_IN_BOUNDS for Ada. */
270 class ada_binop_in_bounds_operation
271 : public maybe_constant_operation<operation_up, operation_up, int>
272 {
273 public:
274
275 using maybe_constant_operation::maybe_constant_operation;
276
277 value *evaluate (struct type *expect_type,
278 struct expression *exp,
279 enum noside noside) override
280 {
281 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
282 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
283 return ada_binop_in_bounds (exp, noside, arg1, arg2,
284 std::get<2> (m_storage));
285 }
286
287 enum exp_opcode opcode () const override
288 { return BINOP_IN_BOUNDS; }
289 };
290
291 /* Implement several unary Ada OP_ATR_* operations. */
292 class ada_unop_atr_operation
293 : public maybe_constant_operation<operation_up, enum exp_opcode, int>
294 {
295 public:
296
297 using maybe_constant_operation::maybe_constant_operation;
298
299 value *evaluate (struct type *expect_type,
300 struct expression *exp,
301 enum noside noside) override;
302
303 enum exp_opcode opcode () const override
304 { return std::get<1> (m_storage); }
305 };
306
307 /* Variant of var_value_operation for Ada. */
308 class ada_var_value_operation
309 : public var_value_operation
310 {
311 public:
312
313 using var_value_operation::var_value_operation;
314
315 value *evaluate (struct type *expect_type,
316 struct expression *exp,
317 enum noside noside) override;
318
319 value *evaluate_for_cast (struct type *expect_type,
320 struct expression *exp,
321 enum noside noside) override;
322
323 symbol *get_symbol () const
324 { return std::get<0> (m_storage); }
325
326 protected:
327
328 using operation::do_generate_ax;
329 };
330
331 /* Variant of var_msym_value_operation for Ada. */
332 class ada_var_msym_value_operation
333 : public var_msym_value_operation
334 {
335 public:
336
337 using var_msym_value_operation::var_msym_value_operation;
338
339 value *evaluate_for_cast (struct type *expect_type,
340 struct expression *exp,
341 enum noside noside) override;
342
343 protected:
344
345 using operation::do_generate_ax;
346 };
347
348 /* Implement the Ada 'val attribute. */
349 class ada_atr_val_operation
350 : public tuple_holding_operation<struct type *, operation_up>
351 {
352 public:
353
354 using tuple_holding_operation::tuple_holding_operation;
355
356 value *evaluate (struct type *expect_type,
357 struct expression *exp,
358 enum noside noside) override;
359
360 enum exp_opcode opcode () const override
361 { return OP_ATR_VAL; }
362 };
363
364 /* The indirection operator for Ada. */
365 class ada_unop_ind_operation
366 : public unop_ind_base_operation
367 {
368 public:
369
370 using unop_ind_base_operation::unop_ind_base_operation;
371
372 value *evaluate (struct type *expect_type,
373 struct expression *exp,
374 enum noside noside) override;
375 };
376
377 /* Implement STRUCTOP_STRUCT for Ada. */
378 class ada_structop_operation
379 : public structop_base_operation
380 {
381 public:
382
383 using structop_base_operation::structop_base_operation;
384
385 value *evaluate (struct type *expect_type,
386 struct expression *exp,
387 enum noside noside) override;
388
389 enum exp_opcode opcode () const override
390 { return STRUCTOP_STRUCT; }
391 };
392
393 /* Function calls for Ada. */
394 class ada_funcall_operation
395 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
396 {
397 public:
398
399 using tuple_holding_operation::tuple_holding_operation;
400
401 value *evaluate (struct type *expect_type,
402 struct expression *exp,
403 enum noside noside) override;
404
405 enum exp_opcode opcode () const override
406 { return OP_FUNCALL; }
407 };
408
409 } /* namespace expr */
410
411 #endif /* ADA_EXP_H */
This page took 0.039148 seconds and 5 git commands to generate.