1 /* Definitions for Fortran expressions
3 Copyright (C) 2020, 2021 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
*eval_op_f_abs (struct type
*expect_type
,
26 struct expression
*exp
,
28 enum exp_opcode opcode
,
30 extern struct value
*eval_op_f_mod (struct type
*expect_type
,
31 struct expression
*exp
,
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
,
38 enum exp_opcode opcode
,
40 extern struct value
*eval_op_f_floor (struct type
*expect_type
,
41 struct expression
*exp
,
43 enum exp_opcode opcode
,
45 extern struct value
*eval_op_f_modulo (struct type
*expect_type
,
46 struct expression
*exp
,
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
,
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
,
58 enum exp_opcode opcode
,
60 extern struct value
*eval_op_f_associated (struct type
*expect_type
,
61 struct expression
*exp
,
63 enum exp_opcode opcode
,
65 extern struct value
*eval_op_f_associated (struct type
*expect_type
,
66 struct expression
*exp
,
68 enum exp_opcode opcode
,
71 extern struct value
* eval_op_f_allocated (struct type
*expect_type
,
72 struct expression
*exp
,
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
82 extern struct value
*eval_op_f_rank (struct type
*expect_type
,
83 struct expression
*exp
,
88 /* Implement expression evaluation for Fortran's SIZE keyword. For
89 EXPECT_TYPE, EXP, and NOSIDE see expression::evaluate (in
90 expression.h). OP will always for FORTRAN_ARRAY_SIZE. ARG1 is the
91 value passed to SIZE if it is only passed a single argument. For the
92 two argument form see the overload of this function below. */
94 extern struct value
*eval_op_f_array_size (struct type
*expect_type
,
95 struct expression
*exp
,
97 enum exp_opcode opcode
,
100 /* An overload of EVAL_OP_F_ARRAY_SIZE above, this version takes two
101 arguments, representing the two values passed to Fortran's SIZE
104 extern struct value
*eval_op_f_array_size (struct type
*expect_type
,
105 struct expression
*exp
,
107 enum exp_opcode opcode
,
111 /* Implement the evaluation of Fortran's SHAPE keyword. EXPECTED_TYPE,
112 EXP, and NOSIDE are as for expression::evaluate (see expression.h). OP
113 will always be UNOP_FORTRAN_SHAPE, and ARG1 is the argument being passed
114 to the expression. */
116 extern struct value
*eval_op_f_array_shape (struct type
*expect_type
,
117 struct expression
*exp
,
125 using fortran_abs_operation
= unop_operation
<UNOP_ABS
, eval_op_f_abs
>;
126 using fortran_ceil_operation
= unop_operation
<UNOP_FORTRAN_CEILING
,
128 using fortran_floor_operation
= unop_operation
<UNOP_FORTRAN_FLOOR
,
130 using fortran_kind_operation
= unop_operation
<UNOP_FORTRAN_KIND
,
132 using fortran_allocated_operation
= unop_operation
<UNOP_FORTRAN_ALLOCATED
,
133 eval_op_f_allocated
>;
135 using fortran_mod_operation
= binop_operation
<BINOP_MOD
, eval_op_f_mod
>;
136 using fortran_modulo_operation
= binop_operation
<BINOP_FORTRAN_MODULO
,
138 using fortran_associated_1arg
= unop_operation
<FORTRAN_ASSOCIATED
,
139 eval_op_f_associated
>;
140 using fortran_associated_2arg
= binop_operation
<FORTRAN_ASSOCIATED
,
141 eval_op_f_associated
>;
142 using fortran_rank_operation
= unop_operation
<UNOP_FORTRAN_RANK
,
144 using fortran_array_size_1arg
= unop_operation
<FORTRAN_ARRAY_SIZE
,
145 eval_op_f_array_size
>;
146 using fortran_array_size_2arg
= binop_operation
<FORTRAN_ARRAY_SIZE
,
147 eval_op_f_array_size
>;
148 using fortran_array_shape_operation
= unop_operation
<UNOP_FORTRAN_SHAPE
,
149 eval_op_f_array_shape
>;
151 /* The Fortran "complex" operation. */
152 class fortran_cmplx_operation
153 : public tuple_holding_operation
<operation_up
, operation_up
>
157 using tuple_holding_operation::tuple_holding_operation
;
159 value
*evaluate (struct type
*expect_type
,
160 struct expression
*exp
,
161 enum noside noside
) override
163 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
164 value
*arg2
= std::get
<1> (m_storage
)->evaluate (value_type (arg1
),
166 return eval_op_f_cmplx (expect_type
, exp
, noside
, BINOP_FORTRAN_CMPLX
,
170 enum exp_opcode
opcode () const override
171 { return BINOP_FORTRAN_CMPLX
; }
174 /* OP_RANGE for Fortran. */
175 class fortran_range_operation
176 : public tuple_holding_operation
<enum range_flag
, operation_up
, operation_up
,
181 using tuple_holding_operation::tuple_holding_operation
;
183 value
*evaluate (struct type
*expect_type
,
184 struct expression
*exp
,
185 enum noside noside
) override
187 error (_("ranges not allowed in this context"));
190 range_flag
get_flags () const
192 return std::get
<0> (m_storage
);
195 value
*evaluate0 (struct expression
*exp
, enum noside noside
) const
197 return std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
200 value
*evaluate1 (struct expression
*exp
, enum noside noside
) const
202 return std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
205 value
*evaluate2 (struct expression
*exp
, enum noside noside
) const
207 return std::get
<3> (m_storage
)->evaluate (nullptr, exp
, noside
);
210 enum exp_opcode
opcode () const override
214 /* In F77, functions, substring ops and array subscript operations
215 cannot be disambiguated at parse time. This operation handles
216 both, deciding which do to at evaluation time. */
217 class fortran_undetermined
218 : public tuple_holding_operation
<operation_up
, std::vector
<operation_up
>>
222 using tuple_holding_operation::tuple_holding_operation
;
224 value
*evaluate (struct type
*expect_type
,
225 struct expression
*exp
,
226 enum noside noside
) override
;
228 enum exp_opcode
opcode () const override
229 { return OP_F77_UNDETERMINED_ARGLIST
; }
233 value
*value_subarray (value
*array
, struct expression
*exp
,
237 /* Single-argument form of Fortran ubound/lbound intrinsics. */
238 class fortran_bound_1arg
239 : public tuple_holding_operation
<exp_opcode
, operation_up
>
243 using tuple_holding_operation::tuple_holding_operation
;
245 value
*evaluate (struct type
*expect_type
,
246 struct expression
*exp
,
247 enum noside noside
) override
;
249 enum exp_opcode
opcode () const override
250 { return std::get
<0> (m_storage
); }
253 /* Two-argument form of Fortran ubound/lbound intrinsics. */
254 class fortran_bound_2arg
255 : public tuple_holding_operation
<exp_opcode
, operation_up
, operation_up
>
259 using tuple_holding_operation::tuple_holding_operation
;
261 value
*evaluate (struct type
*expect_type
,
262 struct expression
*exp
,
263 enum noside noside
) override
;
265 enum exp_opcode
opcode () const override
266 { return std::get
<0> (m_storage
); }
269 } /* namespace expr */
271 #endif /* FORTRAN_EXP_H */