Introduce ada_ternop_slice
[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
59 namespace expr
60 {
61
62 /* In Ada, some generic operations must be wrapped with a handler that
63 handles some Ada-specific type conversions. */
64 class ada_wrapped_operation
65 : public tuple_holding_operation<operation_up>
66 {
67 public:
68
69 using tuple_holding_operation::tuple_holding_operation;
70
71 value *evaluate (struct type *expect_type,
72 struct expression *exp,
73 enum noside noside) override;
74
75 enum exp_opcode opcode () const override
76 { return std::get<0> (m_storage)->opcode (); }
77 };
78
79 /* An Ada string constant. */
80 class ada_string_operation
81 : public string_operation
82 {
83 public:
84
85 using string_operation::string_operation;
86
87 value *evaluate (struct type *expect_type,
88 struct expression *exp,
89 enum noside noside) override;
90 };
91
92 /* The Ada TYPE'(EXP) construct. */
93 class ada_qual_operation
94 : public tuple_holding_operation<operation_up, struct type *>
95 {
96 public:
97
98 using tuple_holding_operation::tuple_holding_operation;
99
100 value *evaluate (struct type *expect_type,
101 struct expression *exp,
102 enum noside noside) override;
103
104 enum exp_opcode opcode () const override
105 { return UNOP_QUAL; }
106 };
107
108 /* Ternary in-range operator. */
109 class ada_ternop_range_operation
110 : public tuple_holding_operation<operation_up, operation_up, operation_up>
111 {
112 public:
113
114 using tuple_holding_operation::tuple_holding_operation;
115
116 value *evaluate (struct type *expect_type,
117 struct expression *exp,
118 enum noside noside) override;
119
120 enum exp_opcode opcode () const override
121 { return TERNOP_IN_RANGE; }
122 };
123
124 using ada_neg_operation = unop_operation<UNOP_NEG, ada_unop_neg>;
125 using ada_atr_tag_operation = unop_operation<OP_ATR_TAG, ada_atr_tag>;
126 using ada_atr_size_operation = unop_operation<OP_ATR_SIZE, ada_atr_size>;
127 using ada_abs_operation = unop_operation<UNOP_ABS, ada_abs>;
128
129 /* The in-range operation, given a type. */
130 class ada_unop_range_operation
131 : public tuple_holding_operation<operation_up, struct type *>
132 {
133 public:
134
135 using tuple_holding_operation::tuple_holding_operation;
136
137 value *evaluate (struct type *expect_type,
138 struct expression *exp,
139 enum noside noside) override
140 {
141 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
142 return ada_unop_in_range (expect_type, exp, noside, UNOP_IN_RANGE,
143 val, std::get<1> (m_storage));
144 }
145
146 enum exp_opcode opcode () const override
147 { return UNOP_IN_RANGE; }
148 };
149
150 /* The Ada + and - operators. */
151 class ada_binop_addsub_operation
152 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
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 enum exp_opcode opcode () const override
163 { return std::get<0> (m_storage); }
164 };
165
166 using ada_binop_mul_operation = binop_operation<BINOP_MUL, ada_mult_binop>;
167 using ada_binop_div_operation = binop_operation<BINOP_DIV, ada_mult_binop>;
168 using ada_binop_rem_operation = binop_operation<BINOP_REM, ada_mult_binop>;
169 using ada_binop_mod_operation = binop_operation<BINOP_MOD, ada_mult_binop>;
170
171 /* Implement the equal and not-equal operations for Ada. */
172 class ada_binop_equal_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 value *arg1 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
184 value *arg2 = std::get<2> (m_storage)->evaluate (value_type (arg1),
185 exp, noside);
186 return ada_equal_binop (expect_type, exp, noside, std::get<0> (m_storage),
187 arg1, arg2);
188 }
189
190 enum exp_opcode opcode () const override
191 { return std::get<0> (m_storage); }
192 };
193
194 /* Bitwise operators for Ada. */
195 template<enum exp_opcode OP>
196 class ada_bitwise_operation
197 : public maybe_constant_operation<operation_up, operation_up>
198 {
199 public:
200
201 using maybe_constant_operation::maybe_constant_operation;
202
203 value *evaluate (struct type *expect_type,
204 struct expression *exp,
205 enum noside noside) override
206 {
207 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
208 value *rhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
209 value *result = eval_op_binary (expect_type, exp, noside, OP, lhs, rhs);
210 return value_cast (value_type (lhs), result);
211 }
212
213 enum exp_opcode opcode () const override
214 { return OP; }
215 };
216
217 using ada_bitwise_and_operation = ada_bitwise_operation<BINOP_BITWISE_AND>;
218 using ada_bitwise_ior_operation = ada_bitwise_operation<BINOP_BITWISE_IOR>;
219 using ada_bitwise_xor_operation = ada_bitwise_operation<BINOP_BITWISE_XOR>;
220
221 /* Ada array- or string-slice operation. */
222 class ada_ternop_slice_operation
223 : public maybe_constant_operation<operation_up, 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 *array = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
234 value *low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
235 value *high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
236 return ada_ternop_slice (exp, noside, array, low, high);
237 }
238
239 enum exp_opcode opcode () const override
240 { return TERNOP_SLICE; }
241 };
242
243 } /* namespace expr */
244
245 #endif /* ADA_EXP_H */
This page took 0.034743 seconds and 5 git commands to generate.