]>
Commit | Line | Data |
---|---|---|
72d0a711 TT |
1 | /* Definitions for C 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 C_EXP_H | |
21 | #define C_EXP_H | |
22 | ||
23 | #include "expop.h" | |
06dc61b9 | 24 | #include "objc-lang.h" |
72d0a711 | 25 | |
09db3700 TT |
26 | extern struct value *eval_op_objc_selector (struct type *expect_type, |
27 | struct expression *exp, | |
28 | enum noside noside, | |
29 | const char *sel); | |
e9677704 | 30 | extern struct value *opencl_value_cast (struct type *type, struct value *arg); |
a88c3c8d TT |
31 | extern struct value *eval_opencl_assign (struct type *expect_type, |
32 | struct expression *exp, | |
33 | enum noside noside, | |
34 | enum exp_opcode op, | |
35 | struct value *arg1, | |
36 | struct value *arg2); | |
37 | extern struct value *opencl_relop (struct type *expect_type, | |
38 | struct expression *exp, | |
39 | enum noside noside, enum exp_opcode op, | |
40 | struct value *arg1, struct value *arg2); | |
2492ba36 TT |
41 | extern struct value *opencl_logical_not (struct type *expect_type, |
42 | struct expression *exp, | |
43 | enum noside noside, | |
44 | enum exp_opcode op, | |
45 | struct value *arg); | |
e9677704 | 46 | |
72d0a711 TT |
47 | namespace expr |
48 | { | |
49 | ||
50 | class c_string_operation | |
51 | : public tuple_holding_operation<enum c_string_type_values, | |
52 | std::vector<std::string>> | |
53 | { | |
54 | public: | |
55 | ||
56 | using tuple_holding_operation::tuple_holding_operation; | |
57 | ||
58 | value *evaluate (struct type *expect_type, | |
59 | struct expression *exp, | |
60 | enum noside noside) override; | |
61 | ||
62 | enum exp_opcode opcode () const override | |
63 | { return OP_STRING; } | |
64 | }; | |
65 | ||
06dc61b9 TT |
66 | class objc_nsstring_operation |
67 | : public tuple_holding_operation<std::string> | |
68 | { | |
69 | public: | |
70 | ||
71 | using tuple_holding_operation::tuple_holding_operation; | |
72 | ||
73 | value *evaluate (struct type *expect_type, | |
74 | struct expression *exp, | |
75 | enum noside noside) override | |
76 | { | |
77 | if (noside == EVAL_SKIP) | |
78 | return eval_skip_value (exp); | |
79 | const std::string &str = std::get<0> (m_storage); | |
80 | return value_nsstring (exp->gdbarch, str.c_str (), str.size () + 1); | |
81 | } | |
82 | ||
83 | enum exp_opcode opcode () const override | |
84 | { return OP_OBJC_NSSTRING; } | |
85 | }; | |
86 | ||
09db3700 TT |
87 | class objc_selector_operation |
88 | : public tuple_holding_operation<std::string> | |
89 | { | |
90 | public: | |
91 | ||
92 | using tuple_holding_operation::tuple_holding_operation; | |
93 | ||
94 | value *evaluate (struct type *expect_type, | |
95 | struct expression *exp, | |
96 | enum noside noside) override | |
97 | { | |
98 | if (noside == EVAL_SKIP) | |
99 | return eval_skip_value (exp); | |
100 | return eval_op_objc_selector (expect_type, exp, noside, | |
101 | std::get<0> (m_storage).c_str ()); | |
102 | } | |
103 | ||
104 | enum exp_opcode opcode () const override | |
105 | { return OP_OBJC_SELECTOR; } | |
106 | }; | |
107 | ||
085734dd TT |
108 | /* An Objective C message call. */ |
109 | class objc_msgcall_operation | |
110 | : public tuple_holding_operation<CORE_ADDR, operation_up, | |
111 | std::vector<operation_up>> | |
112 | { | |
113 | public: | |
114 | ||
115 | using tuple_holding_operation::tuple_holding_operation; | |
116 | ||
117 | value *evaluate (struct type *expect_type, | |
118 | struct expression *exp, | |
119 | enum noside noside) override; | |
120 | ||
121 | enum exp_opcode opcode () const override | |
122 | { return OP_OBJC_MSGCALL; } | |
123 | }; | |
124 | ||
e9677704 TT |
125 | using opencl_cast_type_operation = cxx_cast_operation<UNOP_CAST_TYPE, |
126 | opencl_value_cast>; | |
127 | ||
a88c3c8d TT |
128 | /* Binary operations, as needed for OpenCL. */ |
129 | template<enum exp_opcode OP, binary_ftype FUNC, | |
130 | typename BASE = maybe_constant_operation<operation_up, operation_up>> | |
131 | class opencl_binop_operation | |
132 | : public BASE | |
133 | { | |
134 | public: | |
135 | ||
136 | using BASE::BASE; | |
137 | ||
138 | value *evaluate (struct type *expect_type, | |
139 | struct expression *exp, | |
140 | enum noside noside) override | |
141 | { | |
142 | value *lhs | |
143 | = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside); | |
144 | value *rhs | |
145 | = std::get<1> (this->m_storage)->evaluate (value_type (lhs), exp, | |
146 | noside); | |
147 | return FUNC (expect_type, exp, noside, OP, lhs, rhs); | |
148 | } | |
149 | ||
150 | enum exp_opcode opcode () const override | |
151 | { return OP; } | |
152 | }; | |
153 | ||
154 | using opencl_assign_operation = opencl_binop_operation<BINOP_ASSIGN, | |
155 | eval_opencl_assign, | |
156 | assign_operation>; | |
157 | using opencl_equal_operation = opencl_binop_operation<BINOP_EQUAL, | |
158 | opencl_relop>; | |
159 | using opencl_notequal_operation = opencl_binop_operation<BINOP_NOTEQUAL, | |
160 | opencl_relop>; | |
161 | using opencl_less_operation = opencl_binop_operation<BINOP_LESS, | |
162 | opencl_relop>; | |
163 | using opencl_gtr_operation = opencl_binop_operation<BINOP_GTR, | |
164 | opencl_relop>; | |
165 | using opencl_geq_operation = opencl_binop_operation<BINOP_GEQ, | |
166 | opencl_relop>; | |
167 | using opencl_leq_operation = opencl_binop_operation<BINOP_LEQ, | |
168 | opencl_relop>; | |
169 | ||
2492ba36 TT |
170 | using opencl_not_operation = unop_operation<UNOP_LOGICAL_NOT, |
171 | opencl_logical_not>; | |
172 | ||
33b79214 TT |
173 | /* STRUCTOP_STRUCT implementation for OpenCL. */ |
174 | class opencl_structop_operation | |
175 | : public structop_base_operation | |
176 | { | |
177 | public: | |
178 | ||
179 | using structop_base_operation::structop_base_operation; | |
180 | ||
181 | value *evaluate (struct type *expect_type, | |
182 | struct expression *exp, | |
183 | enum noside noside) override; | |
184 | ||
185 | enum exp_opcode opcode () const override | |
186 | { return STRUCTOP_STRUCT; } | |
187 | }; | |
188 | ||
944fd3b8 TT |
189 | /* This handles the "&&" and "||" operations for OpenCL. */ |
190 | class opencl_logical_binop_operation | |
191 | : public tuple_holding_operation<enum exp_opcode, | |
192 | operation_up, operation_up> | |
193 | { | |
194 | public: | |
195 | ||
196 | using tuple_holding_operation::tuple_holding_operation; | |
197 | ||
198 | value *evaluate (struct type *expect_type, | |
199 | struct expression *exp, | |
200 | enum noside noside) override; | |
201 | ||
202 | enum exp_opcode opcode () const override | |
203 | { return std::get<0> (m_storage); } | |
204 | }; | |
205 | ||
72d0a711 TT |
206 | }/* namespace expr */ |
207 | ||
208 | #endif /* C_EXP_H */ |