3091323c89e3d3acd57dda45f0252e56802c2f4e
[binutils-gdb.git] / gdb / ada-exp.h
1 /* Definitions for Ada 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 ADA_EXP_H
21 #define ADA_EXP_H
22
23 #include "expop.h"
24
25 extern struct value *ada_unop_neg (struct type *expect_type,
26 struct expression *exp,
27 enum noside noside, enum exp_opcode op,
28 struct value *arg1);
29 extern struct value *ada_atr_tag (struct type *expect_type,
30 struct expression *exp,
31 enum noside noside, enum exp_opcode op,
32 struct value *arg1);
33 extern struct value *ada_atr_size (struct type *expect_type,
34 struct expression *exp,
35 enum noside noside, enum exp_opcode op,
36 struct value *arg1);
37 extern struct value *ada_abs (struct type *expect_type,
38 struct expression *exp,
39 enum noside noside, enum exp_opcode op,
40 struct value *arg1);
41 extern struct value *ada_unop_in_range (struct type *expect_type,
42 struct expression *exp,
43 enum noside noside, enum exp_opcode op,
44 struct value *arg1, struct type *type);
45 extern struct value *ada_mult_binop (struct type *expect_type,
46 struct expression *exp,
47 enum noside noside, enum exp_opcode op,
48 struct value *arg1, struct value *arg2);
49 extern struct value *ada_equal_binop (struct type *expect_type,
50 struct expression *exp,
51 enum noside noside, enum exp_opcode op,
52 struct value *arg1, struct value *arg2);
53
54 namespace expr
55 {
56
57 /* In Ada, some generic operations must be wrapped with a handler that
58 handles some Ada-specific type conversions. */
59 class ada_wrapped_operation
60 : public tuple_holding_operation<operation_up>
61 {
62 public:
63
64 using tuple_holding_operation::tuple_holding_operation;
65
66 value *evaluate (struct type *expect_type,
67 struct expression *exp,
68 enum noside noside) override;
69
70 enum exp_opcode opcode () const override
71 { return std::get<0> (m_storage)->opcode (); }
72 };
73
74 /* An Ada string constant. */
75 class ada_string_operation
76 : public string_operation
77 {
78 public:
79
80 using string_operation::string_operation;
81
82 value *evaluate (struct type *expect_type,
83 struct expression *exp,
84 enum noside noside) override;
85 };
86
87 /* The Ada TYPE'(EXP) construct. */
88 class ada_qual_operation
89 : public tuple_holding_operation<operation_up, struct type *>
90 {
91 public:
92
93 using tuple_holding_operation::tuple_holding_operation;
94
95 value *evaluate (struct type *expect_type,
96 struct expression *exp,
97 enum noside noside) override;
98
99 enum exp_opcode opcode () const override
100 { return UNOP_QUAL; }
101 };
102
103 /* Ternary in-range operator. */
104 class ada_ternop_range_operation
105 : public tuple_holding_operation<operation_up, operation_up, operation_up>
106 {
107 public:
108
109 using tuple_holding_operation::tuple_holding_operation;
110
111 value *evaluate (struct type *expect_type,
112 struct expression *exp,
113 enum noside noside) override;
114
115 enum exp_opcode opcode () const override
116 { return TERNOP_IN_RANGE; }
117 };
118
119 using ada_neg_operation = unop_operation<UNOP_NEG, ada_unop_neg>;
120 using ada_atr_tag_operation = unop_operation<OP_ATR_TAG, ada_atr_tag>;
121 using ada_atr_size_operation = unop_operation<OP_ATR_SIZE, ada_atr_size>;
122 using ada_abs_operation = unop_operation<UNOP_ABS, ada_abs>;
123
124 /* The in-range operation, given a type. */
125 class ada_unop_range_operation
126 : public tuple_holding_operation<operation_up, struct type *>
127 {
128 public:
129
130 using tuple_holding_operation::tuple_holding_operation;
131
132 value *evaluate (struct type *expect_type,
133 struct expression *exp,
134 enum noside noside) override
135 {
136 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
137 return ada_unop_in_range (expect_type, exp, noside, UNOP_IN_RANGE,
138 val, std::get<1> (m_storage));
139 }
140
141 enum exp_opcode opcode () const override
142 { return UNOP_IN_RANGE; }
143 };
144
145 /* The Ada + and - operators. */
146 class ada_binop_addsub_operation
147 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
148 {
149 public:
150
151 using tuple_holding_operation::tuple_holding_operation;
152
153 value *evaluate (struct type *expect_type,
154 struct expression *exp,
155 enum noside noside) override;
156
157 enum exp_opcode opcode () const override
158 { return std::get<0> (m_storage); }
159 };
160
161 using ada_binop_mul_operation = binop_operation<BINOP_MUL, ada_mult_binop>;
162 using ada_binop_div_operation = binop_operation<BINOP_DIV, ada_mult_binop>;
163 using ada_binop_rem_operation = binop_operation<BINOP_REM, ada_mult_binop>;
164 using ada_binop_mod_operation = binop_operation<BINOP_MOD, ada_mult_binop>;
165
166 /* Implement the equal and not-equal operations for Ada. */
167 class ada_binop_equal_operation
168 : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
169 {
170 public:
171
172 using tuple_holding_operation::tuple_holding_operation;
173
174 value *evaluate (struct type *expect_type,
175 struct expression *exp,
176 enum noside noside) override
177 {
178 value *arg1 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
179 value *arg2 = std::get<2> (m_storage)->evaluate (value_type (arg1),
180 exp, noside);
181 return ada_equal_binop (expect_type, exp, noside, std::get<0> (m_storage),
182 arg1, arg2);
183 }
184
185 enum exp_opcode opcode () const override
186 { return std::get<0> (m_storage); }
187 };
188
189 } /* namespace expr */
190
191 #endif /* ADA_EXP_H */