Commit | Line | Data |
---|---|---|
9dcd3e29 TT |
1 | /* Definitions for Fortran expressions |
2 | ||
f403a4e4 | 3 | Copyright (C) 2020, 2021 Free Software Foundation, Inc. |
9dcd3e29 TT |
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 FORTRAN_EXP_H | |
21 | #define FORTRAN_EXP_H | |
22 | ||
23 | #include "expop.h" | |
24 | ||
25 | extern struct value *eval_op_f_abs (struct type *expect_type, | |
26 | struct expression *exp, | |
27 | enum noside noside, | |
28 | enum exp_opcode opcode, | |
29 | struct value *arg1); | |
30 | extern struct value *eval_op_f_mod (struct type *expect_type, | |
31 | struct expression *exp, | |
32 | enum noside noside, | |
33 | enum exp_opcode opcode, | |
34 | struct value *arg1, struct value *arg2); | |
35 | extern struct value *eval_op_f_ceil (struct type *expect_type, | |
36 | struct expression *exp, | |
37 | enum noside noside, | |
38 | enum exp_opcode opcode, | |
39 | struct value *arg1); | |
40 | extern struct value *eval_op_f_floor (struct type *expect_type, | |
41 | struct expression *exp, | |
42 | enum noside noside, | |
43 | enum exp_opcode opcode, | |
44 | struct value *arg1); | |
45 | extern struct value *eval_op_f_modulo (struct type *expect_type, | |
46 | struct expression *exp, | |
47 | enum noside noside, | |
48 | enum exp_opcode opcode, | |
49 | struct value *arg1, struct value *arg2); | |
50 | extern struct value *eval_op_f_cmplx (struct type *expect_type, | |
51 | struct expression *exp, | |
52 | enum noside noside, | |
53 | enum exp_opcode opcode, | |
54 | struct value *arg1, struct value *arg2); | |
55 | extern struct value *eval_op_f_kind (struct type *expect_type, | |
56 | struct expression *exp, | |
57 | enum noside noside, | |
58 | enum exp_opcode opcode, | |
59 | struct value *arg1); | |
eb4c9271 TT |
60 | extern struct value *eval_op_f_associated (struct type *expect_type, |
61 | struct expression *exp, | |
62 | enum noside noside, | |
63 | enum exp_opcode opcode, | |
64 | struct value *arg1); | |
65 | extern struct value *eval_op_f_associated (struct type *expect_type, | |
66 | struct expression *exp, | |
67 | enum noside noside, | |
68 | enum exp_opcode opcode, | |
69 | struct value *arg1, | |
70 | struct value *arg2); | |
f403a4e4 TT |
71 | extern struct value * eval_op_f_allocated (struct type *expect_type, |
72 | struct expression *exp, | |
73 | enum noside noside, | |
74 | enum exp_opcode op, | |
75 | struct value *arg1); | |
9dcd3e29 | 76 | |
e14816a8 AB |
77 | /* Implement the evaluation of UNOP_FORTRAN_RANK. EXPECTED_TYPE, EXP, and |
78 | NOSIDE are as for expression::evaluate (see expression.h). OP will | |
79 | always be UNOP_FORTRAN_RANK, and ARG1 is the argument being passed to | |
80 | the expression. */ | |
81 | ||
82 | extern struct value *eval_op_f_rank (struct type *expect_type, | |
83 | struct expression *exp, | |
84 | enum noside noside, | |
85 | enum exp_opcode op, | |
86 | struct value *arg1); | |
87 | ||
9dcd3e29 TT |
88 | namespace expr |
89 | { | |
90 | ||
91 | using fortran_abs_operation = unop_operation<UNOP_ABS, eval_op_f_abs>; | |
92 | using fortran_ceil_operation = unop_operation<UNOP_FORTRAN_CEILING, | |
93 | eval_op_f_ceil>; | |
94 | using fortran_floor_operation = unop_operation<UNOP_FORTRAN_FLOOR, | |
95 | eval_op_f_floor>; | |
96 | using fortran_kind_operation = unop_operation<UNOP_FORTRAN_KIND, | |
97 | eval_op_f_kind>; | |
f403a4e4 TT |
98 | using fortran_allocated_operation = unop_operation<UNOP_FORTRAN_ALLOCATED, |
99 | eval_op_f_allocated>; | |
9dcd3e29 TT |
100 | |
101 | using fortran_mod_operation = binop_operation<BINOP_MOD, eval_op_f_mod>; | |
102 | using fortran_modulo_operation = binop_operation<BINOP_FORTRAN_MODULO, | |
103 | eval_op_f_modulo>; | |
eb4c9271 TT |
104 | using fortran_associated_1arg = unop_operation<FORTRAN_ASSOCIATED, |
105 | eval_op_f_associated>; | |
106 | using fortran_associated_2arg = binop_operation<FORTRAN_ASSOCIATED, | |
107 | eval_op_f_associated>; | |
e14816a8 AB |
108 | using fortran_rank_operation = unop_operation<UNOP_FORTRAN_RANK, |
109 | eval_op_f_rank>; | |
9dcd3e29 TT |
110 | |
111 | /* The Fortran "complex" operation. */ | |
112 | class fortran_cmplx_operation | |
113 | : public tuple_holding_operation<operation_up, operation_up> | |
114 | { | |
115 | public: | |
116 | ||
117 | using tuple_holding_operation::tuple_holding_operation; | |
118 | ||
119 | value *evaluate (struct type *expect_type, | |
120 | struct expression *exp, | |
121 | enum noside noside) override | |
122 | { | |
123 | value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); | |
124 | value *arg2 = std::get<1> (m_storage)->evaluate (value_type (arg1), | |
125 | exp, noside); | |
126 | return eval_op_f_cmplx (expect_type, exp, noside, BINOP_FORTRAN_CMPLX, | |
127 | arg1, arg2); | |
128 | } | |
129 | ||
130 | enum exp_opcode opcode () const override | |
131 | { return BINOP_FORTRAN_CMPLX; } | |
132 | }; | |
133 | ||
2f98abe1 TT |
134 | /* OP_RANGE for Fortran. */ |
135 | class fortran_range_operation | |
136 | : public tuple_holding_operation<enum range_flag, operation_up, operation_up, | |
137 | operation_up> | |
138 | { | |
139 | public: | |
140 | ||
141 | using tuple_holding_operation::tuple_holding_operation; | |
142 | ||
143 | value *evaluate (struct type *expect_type, | |
144 | struct expression *exp, | |
145 | enum noside noside) override | |
146 | { | |
147 | error (_("ranges not allowed in this context")); | |
148 | } | |
149 | ||
150 | range_flag get_flags () const | |
151 | { | |
152 | return std::get<0> (m_storage); | |
153 | } | |
154 | ||
155 | value *evaluate0 (struct expression *exp, enum noside noside) const | |
156 | { | |
157 | return std::get<1> (m_storage)->evaluate (nullptr, exp, noside); | |
158 | } | |
159 | ||
160 | value *evaluate1 (struct expression *exp, enum noside noside) const | |
161 | { | |
162 | return std::get<2> (m_storage)->evaluate (nullptr, exp, noside); | |
163 | } | |
164 | ||
165 | value *evaluate2 (struct expression *exp, enum noside noside) const | |
166 | { | |
167 | return std::get<3> (m_storage)->evaluate (nullptr, exp, noside); | |
168 | } | |
169 | ||
170 | enum exp_opcode opcode () const override | |
171 | { return OP_RANGE; } | |
172 | }; | |
173 | ||
174 | /* In F77, functions, substring ops and array subscript operations | |
175 | cannot be disambiguated at parse time. This operation handles | |
176 | both, deciding which do to at evaluation time. */ | |
177 | class fortran_undetermined | |
178 | : public tuple_holding_operation<operation_up, std::vector<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 | enum exp_opcode opcode () const override | |
189 | { return OP_F77_UNDETERMINED_ARGLIST; } | |
190 | ||
191 | private: | |
192 | ||
193 | value *value_subarray (value *array, struct expression *exp, | |
194 | enum noside noside); | |
195 | }; | |
196 | ||
58a76c72 TT |
197 | /* Single-argument form of Fortran ubound/lbound intrinsics. */ |
198 | class fortran_bound_1arg | |
199 | : public tuple_holding_operation<exp_opcode, 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 | enum exp_opcode opcode () const override | |
210 | { return std::get<0> (m_storage); } | |
211 | }; | |
212 | ||
213 | /* Two-argument form of Fortran ubound/lbound intrinsics. */ | |
214 | class fortran_bound_2arg | |
215 | : public tuple_holding_operation<exp_opcode, operation_up, operation_up> | |
216 | { | |
217 | public: | |
218 | ||
219 | using tuple_holding_operation::tuple_holding_operation; | |
220 | ||
221 | value *evaluate (struct type *expect_type, | |
222 | struct expression *exp, | |
223 | enum noside noside) override; | |
224 | ||
225 | enum exp_opcode opcode () const override | |
226 | { return std::get<0> (m_storage); } | |
227 | }; | |
228 | ||
9dcd3e29 TT |
229 | } /* namespace expr */ |
230 | ||
231 | #endif /* FORTRAN_EXP_H */ |