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