Introduce classes for Fortran bound intrinsics
[deliverable/binutils-gdb.git] / gdb / f-exp.h
1 /* Definitions for Fortran 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 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);
60
61 namespace expr
62 {
63
64 using fortran_abs_operation = unop_operation<UNOP_ABS, eval_op_f_abs>;
65 using fortran_ceil_operation = unop_operation<UNOP_FORTRAN_CEILING,
66 eval_op_f_ceil>;
67 using fortran_floor_operation = unop_operation<UNOP_FORTRAN_FLOOR,
68 eval_op_f_floor>;
69 using fortran_kind_operation = unop_operation<UNOP_FORTRAN_KIND,
70 eval_op_f_kind>;
71
72 using fortran_mod_operation = binop_operation<BINOP_MOD, eval_op_f_mod>;
73 using fortran_modulo_operation = binop_operation<BINOP_FORTRAN_MODULO,
74 eval_op_f_modulo>;
75
76 /* The Fortran "complex" operation. */
77 class fortran_cmplx_operation
78 : public tuple_holding_operation<operation_up, operation_up>
79 {
80 public:
81
82 using tuple_holding_operation::tuple_holding_operation;
83
84 value *evaluate (struct type *expect_type,
85 struct expression *exp,
86 enum noside noside) override
87 {
88 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
89 value *arg2 = std::get<1> (m_storage)->evaluate (value_type (arg1),
90 exp, noside);
91 return eval_op_f_cmplx (expect_type, exp, noside, BINOP_FORTRAN_CMPLX,
92 arg1, arg2);
93 }
94
95 enum exp_opcode opcode () const override
96 { return BINOP_FORTRAN_CMPLX; }
97 };
98
99 /* OP_RANGE for Fortran. */
100 class fortran_range_operation
101 : public tuple_holding_operation<enum range_flag, operation_up, operation_up,
102 operation_up>
103 {
104 public:
105
106 using tuple_holding_operation::tuple_holding_operation;
107
108 value *evaluate (struct type *expect_type,
109 struct expression *exp,
110 enum noside noside) override
111 {
112 error (_("ranges not allowed in this context"));
113 }
114
115 range_flag get_flags () const
116 {
117 return std::get<0> (m_storage);
118 }
119
120 value *evaluate0 (struct expression *exp, enum noside noside) const
121 {
122 return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
123 }
124
125 value *evaluate1 (struct expression *exp, enum noside noside) const
126 {
127 return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
128 }
129
130 value *evaluate2 (struct expression *exp, enum noside noside) const
131 {
132 return std::get<3> (m_storage)->evaluate (nullptr, exp, noside);
133 }
134
135 enum exp_opcode opcode () const override
136 { return OP_RANGE; }
137 };
138
139 /* In F77, functions, substring ops and array subscript operations
140 cannot be disambiguated at parse time. This operation handles
141 both, deciding which do to at evaluation time. */
142 class fortran_undetermined
143 : public tuple_holding_operation<operation_up, std::vector<operation_up>>
144 {
145 public:
146
147 using tuple_holding_operation::tuple_holding_operation;
148
149 value *evaluate (struct type *expect_type,
150 struct expression *exp,
151 enum noside noside) override;
152
153 enum exp_opcode opcode () const override
154 { return OP_F77_UNDETERMINED_ARGLIST; }
155
156 private:
157
158 value *value_subarray (value *array, struct expression *exp,
159 enum noside noside);
160 };
161
162 /* Single-argument form of Fortran ubound/lbound intrinsics. */
163 class fortran_bound_1arg
164 : public tuple_holding_operation<exp_opcode, operation_up>
165 {
166 public:
167
168 using tuple_holding_operation::tuple_holding_operation;
169
170 value *evaluate (struct type *expect_type,
171 struct expression *exp,
172 enum noside noside) override;
173
174 enum exp_opcode opcode () const override
175 { return std::get<0> (m_storage); }
176 };
177
178 /* Two-argument form of Fortran ubound/lbound intrinsics. */
179 class fortran_bound_2arg
180 : public tuple_holding_operation<exp_opcode, operation_up, operation_up>
181 {
182 public:
183
184 using tuple_holding_operation::tuple_holding_operation;
185
186 value *evaluate (struct type *expect_type,
187 struct expression *exp,
188 enum noside noside) override;
189
190 enum exp_opcode opcode () const override
191 { return std::get<0> (m_storage); }
192 };
193
194 } /* namespace expr */
195
196 #endif /* FORTRAN_EXP_H */
This page took 0.033871 seconds and 5 git commands to generate.