Implement some Ada OP_ATR_ operations
[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
64 namespace expr
65 {
66
67 /* In Ada, some generic operations must be wrapped with a handler that
68 handles some Ada-specific type conversions. */
69 class ada_wrapped_operation
70 : public tuple_holding_operation<operation_up>
71 {
72 public:
73
74 using tuple_holding_operation::tuple_holding_operation;
75
76 value *evaluate (struct type *expect_type,
77 struct expression *exp,
78 enum noside noside) override;
79
80 enum exp_opcode opcode () const override
81 { return std::get<0> (m_storage)->opcode (); }
82 };
83
84 /* An Ada string constant. */
85 class ada_string_operation
86 : public string_operation
87 {
88 public:
89
90 using string_operation::string_operation;
91
92 value *evaluate (struct type *expect_type,
93 struct expression *exp,
94 enum noside noside) override;
95 };
96
97 /* The Ada TYPE'(EXP) construct. */
98 class ada_qual_operation
99 : public tuple_holding_operation<operation_up, struct type *>
100 {
101 public:
102
103 using tuple_holding_operation::tuple_holding_operation;
104
105 value *evaluate (struct type *expect_type,
106 struct expression *exp,
107 enum noside noside) override;
108
109 enum exp_opcode opcode () const override
110 { return UNOP_QUAL; }
111 };
112
113 /* Ternary in-range operator. */
114 class ada_ternop_range_operation
115 : public tuple_holding_operation<operation_up, operation_up, operation_up>
116 {
117 public:
118
119 using tuple_holding_operation::tuple_holding_operation;
120
121 value *evaluate (struct type *expect_type,
122 struct expression *exp,
123 enum noside noside) override;
124
125 enum exp_opcode opcode () const override
126 { return TERNOP_IN_RANGE; }
127 };
128
129 using ada_neg_operation = unop_operation<UNOP_NEG, ada_unop_neg>;
130 using ada_atr_tag_operation = unop_operation<OP_ATR_TAG, ada_atr_tag>;
131 using ada_atr_size_operation = unop_operation<OP_ATR_SIZE, ada_atr_size>;
132 using ada_abs_operation = unop_operation<UNOP_ABS, ada_abs>;
133
134 /* The in-range operation, given a type. */
135 class ada_unop_range_operation
136 : public tuple_holding_operation<operation_up, struct type *>
137 {
138 public:
139
140 using tuple_holding_operation::tuple_holding_operation;
141
142 value *evaluate (struct type *expect_type,
143 struct expression *exp,
144 enum noside noside) override
145 {
146 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
147 return ada_unop_in_range (expect_type, exp, noside, UNOP_IN_RANGE,
148 val, std::get<1> (m_storage));
149 }
150
151 enum exp_opcode opcode () const override
152 { return UNOP_IN_RANGE; }
153 };
154
155 /* The Ada + and - operators. */
156 class ada_binop_addsub_operation
157 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
158 {
159 public:
160
161 using tuple_holding_operation::tuple_holding_operation;
162
163 value *evaluate (struct type *expect_type,
164 struct expression *exp,
165 enum noside noside) override;
166
167 enum exp_opcode opcode () const override
168 { return std::get<0> (m_storage); }
169 };
170
171 using ada_binop_mul_operation = binop_operation<BINOP_MUL, ada_mult_binop>;
172 using ada_binop_div_operation = binop_operation<BINOP_DIV, ada_mult_binop>;
173 using ada_binop_rem_operation = binop_operation<BINOP_REM, ada_mult_binop>;
174 using ada_binop_mod_operation = binop_operation<BINOP_MOD, ada_mult_binop>;
175
176 /* Implement the equal and not-equal operations for Ada. */
177 class ada_binop_equal_operation
178 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
179 {
180 public:
181
182 using tuple_holding_operation::tuple_holding_operation;
183
184 value *evaluate (struct type *expect_type,
185 struct expression *exp,
186 enum noside noside) override
187 {
188 value *arg1 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
189 value *arg2 = std::get<2> (m_storage)->evaluate (value_type (arg1),
190 exp, noside);
191 return ada_equal_binop (expect_type, exp, noside, std::get<0> (m_storage),
192 arg1, arg2);
193 }
194
195 enum exp_opcode opcode () const override
196 { return std::get<0> (m_storage); }
197 };
198
199 /* Bitwise operators for Ada. */
200 template<enum exp_opcode OP>
201 class ada_bitwise_operation
202 : public maybe_constant_operation<operation_up, operation_up>
203 {
204 public:
205
206 using maybe_constant_operation::maybe_constant_operation;
207
208 value *evaluate (struct type *expect_type,
209 struct expression *exp,
210 enum noside noside) override
211 {
212 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
213 value *rhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
214 value *result = eval_op_binary (expect_type, exp, noside, OP, lhs, rhs);
215 return value_cast (value_type (lhs), result);
216 }
217
218 enum exp_opcode opcode () const override
219 { return OP; }
220 };
221
222 using ada_bitwise_and_operation = ada_bitwise_operation<BINOP_BITWISE_AND>;
223 using ada_bitwise_ior_operation = ada_bitwise_operation<BINOP_BITWISE_IOR>;
224 using ada_bitwise_xor_operation = ada_bitwise_operation<BINOP_BITWISE_XOR>;
225
226 /* Ada array- or string-slice operation. */
227 class ada_ternop_slice_operation
228 : public maybe_constant_operation<operation_up, operation_up, operation_up>
229 {
230 public:
231
232 using maybe_constant_operation::maybe_constant_operation;
233
234 value *evaluate (struct type *expect_type,
235 struct expression *exp,
236 enum noside noside) override
237 {
238 value *array = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
239 value *low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
240 value *high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
241 return ada_ternop_slice (exp, noside, array, low, high);
242 }
243
244 enum exp_opcode opcode () const override
245 { return TERNOP_SLICE; }
246 };
247
248 /* Implement BINOP_IN_BOUNDS for Ada. */
249 class ada_binop_in_bounds_operation
250 : public maybe_constant_operation<operation_up, operation_up, int>
251 {
252 public:
253
254 using maybe_constant_operation::maybe_constant_operation;
255
256 value *evaluate (struct type *expect_type,
257 struct expression *exp,
258 enum noside noside) override
259 {
260 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
261 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
262 return ada_binop_in_bounds (exp, noside, arg1, arg2,
263 std::get<2> (m_storage));
264 }
265
266 enum exp_opcode opcode () const override
267 { return BINOP_IN_BOUNDS; }
268 };
269
270 /* Implement several unary Ada OP_ATR_* operations. */
271 class ada_unop_atr_operation
272 : public maybe_constant_operation<operation_up, enum exp_opcode, int>
273 {
274 public:
275
276 using maybe_constant_operation::maybe_constant_operation;
277
278 value *evaluate (struct type *expect_type,
279 struct expression *exp,
280 enum noside noside) override;
281
282 enum exp_opcode opcode () const override
283 { return std::get<1> (m_storage); }
284 };
285
286 } /* namespace expr */
287
288 #endif /* ADA_EXP_H */
This page took 0.036902 seconds and 5 git commands to generate.