Implement Ada min and max operations
[deliverable/binutils-gdb.git] / gdb / f-exp.h
CommitLineData
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
25extern 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);
30extern 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);
35extern 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);
40extern 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);
45extern 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);
50extern 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);
55extern 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
60extern 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);
65extern 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
71extern 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
TT
76
77namespace expr
78{
79
80using fortran_abs_operation = unop_operation<UNOP_ABS, eval_op_f_abs>;
81using fortran_ceil_operation = unop_operation<UNOP_FORTRAN_CEILING,
82 eval_op_f_ceil>;
83using fortran_floor_operation = unop_operation<UNOP_FORTRAN_FLOOR,
84 eval_op_f_floor>;
85using fortran_kind_operation = unop_operation<UNOP_FORTRAN_KIND,
86 eval_op_f_kind>;
f403a4e4
TT
87using fortran_allocated_operation = unop_operation<UNOP_FORTRAN_ALLOCATED,
88 eval_op_f_allocated>;
9dcd3e29
TT
89
90using fortran_mod_operation = binop_operation<BINOP_MOD, eval_op_f_mod>;
91using fortran_modulo_operation = binop_operation<BINOP_FORTRAN_MODULO,
92 eval_op_f_modulo>;
eb4c9271
TT
93using fortran_associated_1arg = unop_operation<FORTRAN_ASSOCIATED,
94 eval_op_f_associated>;
95using fortran_associated_2arg = binop_operation<FORTRAN_ASSOCIATED,
96 eval_op_f_associated>;
9dcd3e29
TT
97
98/* The Fortran "complex" operation. */
99class fortran_cmplx_operation
100 : public tuple_holding_operation<operation_up, operation_up>
101{
102public:
103
104 using tuple_holding_operation::tuple_holding_operation;
105
106 value *evaluate (struct type *expect_type,
107 struct expression *exp,
108 enum noside noside) override
109 {
110 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
111 value *arg2 = std::get<1> (m_storage)->evaluate (value_type (arg1),
112 exp, noside);
113 return eval_op_f_cmplx (expect_type, exp, noside, BINOP_FORTRAN_CMPLX,
114 arg1, arg2);
115 }
116
117 enum exp_opcode opcode () const override
118 { return BINOP_FORTRAN_CMPLX; }
119};
120
2f98abe1
TT
121/* OP_RANGE for Fortran. */
122class fortran_range_operation
123 : public tuple_holding_operation<enum range_flag, operation_up, operation_up,
124 operation_up>
125{
126public:
127
128 using tuple_holding_operation::tuple_holding_operation;
129
130 value *evaluate (struct type *expect_type,
131 struct expression *exp,
132 enum noside noside) override
133 {
134 error (_("ranges not allowed in this context"));
135 }
136
137 range_flag get_flags () const
138 {
139 return std::get<0> (m_storage);
140 }
141
142 value *evaluate0 (struct expression *exp, enum noside noside) const
143 {
144 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
145 }
146
147 value *evaluate1 (struct expression *exp, enum noside noside) const
148 {
149 return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
150 }
151
152 value *evaluate2 (struct expression *exp, enum noside noside) const
153 {
154 return std::get<3> (m_storage)->evaluate (nullptr, exp, noside);
155 }
156
157 enum exp_opcode opcode () const override
158 { return OP_RANGE; }
159};
160
161/* In F77, functions, substring ops and array subscript operations
162 cannot be disambiguated at parse time. This operation handles
163 both, deciding which do to at evaluation time. */
164class fortran_undetermined
165 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
166{
167public:
168
169 using tuple_holding_operation::tuple_holding_operation;
170
171 value *evaluate (struct type *expect_type,
172 struct expression *exp,
173 enum noside noside) override;
174
175 enum exp_opcode opcode () const override
176 { return OP_F77_UNDETERMINED_ARGLIST; }
177
178private:
179
180 value *value_subarray (value *array, struct expression *exp,
181 enum noside noside);
182};
183
58a76c72
TT
184/* Single-argument form of Fortran ubound/lbound intrinsics. */
185class fortran_bound_1arg
186 : public tuple_holding_operation<exp_opcode, operation_up>
187{
188public:
189
190 using tuple_holding_operation::tuple_holding_operation;
191
192 value *evaluate (struct type *expect_type,
193 struct expression *exp,
194 enum noside noside) override;
195
196 enum exp_opcode opcode () const override
197 { return std::get<0> (m_storage); }
198};
199
200/* Two-argument form of Fortran ubound/lbound intrinsics. */
201class fortran_bound_2arg
202 : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
203{
204public:
205
206 using tuple_holding_operation::tuple_holding_operation;
207
208 value *evaluate (struct type *expect_type,
209 struct expression *exp,
210 enum noside noside) override;
211
212 enum exp_opcode opcode () const override
213 { return std::get<0> (m_storage); }
214};
215
9dcd3e29
TT
216} /* namespace expr */
217
218#endif /* FORTRAN_EXP_H */
This page took 0.030805 seconds and 4 git commands to generate.