1 /* Definitions for Ada expressions
3 Copyright (C) 2020 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
25 extern struct value
*ada_unop_neg (struct type
*expect_type
,
26 struct expression
*exp
,
27 enum noside noside
, enum exp_opcode op
,
29 extern struct value
*ada_atr_tag (struct type
*expect_type
,
30 struct expression
*exp
,
31 enum noside noside
, enum exp_opcode op
,
33 extern struct value
*ada_atr_size (struct type
*expect_type
,
34 struct expression
*exp
,
35 enum noside noside
, enum exp_opcode op
,
37 extern struct value
*ada_abs (struct type
*expect_type
,
38 struct expression
*exp
,
39 enum noside noside
, enum exp_opcode op
,
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
,
56 struct value
*low_bound_val
,
57 struct value
*high_bound_val
);
58 extern struct value
*ada_binop_in_bounds (struct expression
*exp
,
63 extern struct value
*ada_binop_minmax (struct type
*expect_type
,
64 struct expression
*exp
,
65 enum noside noside
, enum exp_opcode op
,
72 /* In Ada, some generic operations must be wrapped with a handler that
73 handles some Ada-specific type conversions. */
74 class ada_wrapped_operation
75 : public tuple_holding_operation
<operation_up
>
79 using tuple_holding_operation::tuple_holding_operation
;
81 value
*evaluate (struct type
*expect_type
,
82 struct expression
*exp
,
83 enum noside noside
) override
;
85 enum exp_opcode
opcode () const override
86 { return std::get
<0> (m_storage
)->opcode (); }
89 /* An Ada string constant. */
90 class ada_string_operation
91 : public string_operation
95 using string_operation::string_operation
;
97 value
*evaluate (struct type
*expect_type
,
98 struct expression
*exp
,
99 enum noside noside
) override
;
102 /* The Ada TYPE'(EXP) construct. */
103 class ada_qual_operation
104 : public tuple_holding_operation
<operation_up
, struct type
*>
108 using tuple_holding_operation::tuple_holding_operation
;
110 value
*evaluate (struct type
*expect_type
,
111 struct expression
*exp
,
112 enum noside noside
) override
;
114 enum exp_opcode
opcode () const override
115 { return UNOP_QUAL
; }
118 /* Ternary in-range operator. */
119 class ada_ternop_range_operation
120 : public tuple_holding_operation
<operation_up
, operation_up
, operation_up
>
124 using tuple_holding_operation::tuple_holding_operation
;
126 value
*evaluate (struct type
*expect_type
,
127 struct expression
*exp
,
128 enum noside noside
) override
;
130 enum exp_opcode
opcode () const override
131 { return TERNOP_IN_RANGE
; }
134 using ada_neg_operation
= unop_operation
<UNOP_NEG
, ada_unop_neg
>;
135 using ada_atr_tag_operation
= unop_operation
<OP_ATR_TAG
, ada_atr_tag
>;
136 using ada_atr_size_operation
= unop_operation
<OP_ATR_SIZE
, ada_atr_size
>;
137 using ada_abs_operation
= unop_operation
<UNOP_ABS
, ada_abs
>;
139 /* The in-range operation, given a type. */
140 class ada_unop_range_operation
141 : public tuple_holding_operation
<operation_up
, struct type
*>
145 using tuple_holding_operation::tuple_holding_operation
;
147 value
*evaluate (struct type
*expect_type
,
148 struct expression
*exp
,
149 enum noside noside
) override
151 value
*val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
152 return ada_unop_in_range (expect_type
, exp
, noside
, UNOP_IN_RANGE
,
153 val
, std::get
<1> (m_storage
));
156 enum exp_opcode
opcode () const override
157 { return UNOP_IN_RANGE
; }
160 /* The Ada + and - operators. */
161 class ada_binop_addsub_operation
162 : public tuple_holding_operation
<enum exp_opcode
, operation_up
, operation_up
>
166 using tuple_holding_operation::tuple_holding_operation
;
168 value
*evaluate (struct type
*expect_type
,
169 struct expression
*exp
,
170 enum noside noside
) override
;
172 enum exp_opcode
opcode () const override
173 { return std::get
<0> (m_storage
); }
176 using ada_binop_mul_operation
= binop_operation
<BINOP_MUL
, ada_mult_binop
>;
177 using ada_binop_div_operation
= binop_operation
<BINOP_DIV
, ada_mult_binop
>;
178 using ada_binop_rem_operation
= binop_operation
<BINOP_REM
, ada_mult_binop
>;
179 using ada_binop_mod_operation
= binop_operation
<BINOP_MOD
, ada_mult_binop
>;
181 using ada_binop_min_operation
= binop_operation
<OP_ATR_MIN
, ada_binop_minmax
>;
182 using ada_binop_max_operation
= binop_operation
<OP_ATR_MAX
, ada_binop_minmax
>;
184 /* Implement the equal and not-equal operations for Ada. */
185 class ada_binop_equal_operation
186 : public tuple_holding_operation
<enum exp_opcode
, operation_up
, operation_up
>
190 using tuple_holding_operation::tuple_holding_operation
;
192 value
*evaluate (struct type
*expect_type
,
193 struct expression
*exp
,
194 enum noside noside
) override
196 value
*arg1
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
197 value
*arg2
= std::get
<2> (m_storage
)->evaluate (value_type (arg1
),
199 return ada_equal_binop (expect_type
, exp
, noside
, std::get
<0> (m_storage
),
203 enum exp_opcode
opcode () const override
204 { return std::get
<0> (m_storage
); }
207 /* Bitwise operators for Ada. */
208 template<enum exp_opcode OP
>
209 class ada_bitwise_operation
210 : public maybe_constant_operation
<operation_up
, operation_up
>
214 using maybe_constant_operation::maybe_constant_operation
;
216 value
*evaluate (struct type
*expect_type
,
217 struct expression
*exp
,
218 enum noside noside
) override
220 value
*lhs
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
221 value
*rhs
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
222 value
*result
= eval_op_binary (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
223 return value_cast (value_type (lhs
), result
);
226 enum exp_opcode
opcode () const override
230 using ada_bitwise_and_operation
= ada_bitwise_operation
<BINOP_BITWISE_AND
>;
231 using ada_bitwise_ior_operation
= ada_bitwise_operation
<BINOP_BITWISE_IOR
>;
232 using ada_bitwise_xor_operation
= ada_bitwise_operation
<BINOP_BITWISE_XOR
>;
234 /* Ada array- or string-slice operation. */
235 class ada_ternop_slice_operation
236 : public maybe_constant_operation
<operation_up
, operation_up
, operation_up
>
240 using maybe_constant_operation::maybe_constant_operation
;
242 value
*evaluate (struct type
*expect_type
,
243 struct expression
*exp
,
244 enum noside noside
) override
246 value
*array
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
247 value
*low
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
248 value
*high
= std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
249 return ada_ternop_slice (exp
, noside
, array
, low
, high
);
252 enum exp_opcode
opcode () const override
253 { return TERNOP_SLICE
; }
256 /* Implement BINOP_IN_BOUNDS for Ada. */
257 class ada_binop_in_bounds_operation
258 : public maybe_constant_operation
<operation_up
, operation_up
, int>
262 using maybe_constant_operation::maybe_constant_operation
;
264 value
*evaluate (struct type
*expect_type
,
265 struct expression
*exp
,
266 enum noside noside
) override
268 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
269 value
*arg2
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
270 return ada_binop_in_bounds (exp
, noside
, arg1
, arg2
,
271 std::get
<2> (m_storage
));
274 enum exp_opcode
opcode () const override
275 { return BINOP_IN_BOUNDS
; }
278 /* Implement several unary Ada OP_ATR_* operations. */
279 class ada_unop_atr_operation
280 : public maybe_constant_operation
<operation_up
, enum exp_opcode
, int>
284 using maybe_constant_operation::maybe_constant_operation
;
286 value
*evaluate (struct type
*expect_type
,
287 struct expression
*exp
,
288 enum noside noside
) override
;
290 enum exp_opcode
opcode () const override
291 { return std::get
<1> (m_storage
); }
294 /* Variant of var_value_operation for Ada. */
295 class ada_var_value_operation
296 : public var_value_operation
300 using var_value_operation::var_value_operation
;
302 value
*evaluate (struct type
*expect_type
,
303 struct expression
*exp
,
304 enum noside noside
) override
;
306 value
*evaluate_for_cast (struct type
*expect_type
,
307 struct expression
*exp
,
308 enum noside noside
) override
;
312 using operation::do_generate_ax
;
315 /* Variant of var_msym_value_operation for Ada. */
316 class ada_var_msym_value_operation
317 : public var_msym_value_operation
321 using var_msym_value_operation::var_msym_value_operation
;
323 value
*evaluate_for_cast (struct type
*expect_type
,
324 struct expression
*exp
,
325 enum noside noside
) override
;
329 using operation::do_generate_ax
;
332 } /* namespace expr */
334 #endif /* ADA_EXP_H */