1 /* Definitions for C expressions
3 Copyright (C) 2020-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
24 #include "objc-lang.h"
26 extern struct value
*eval_op_objc_selector (struct type
*expect_type
,
27 struct expression
*exp
,
30 extern struct value
*opencl_value_cast (struct type
*type
, struct value
*arg
);
31 extern struct value
*eval_opencl_assign (struct type
*expect_type
,
32 struct expression
*exp
,
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
);
41 extern struct value
*opencl_logical_not (struct type
*expect_type
,
42 struct expression
*exp
,
50 class c_string_operation
51 : public tuple_holding_operation
<enum c_string_type_values
,
52 std::vector
<std::string
>>
56 using tuple_holding_operation::tuple_holding_operation
;
58 value
*evaluate (struct type
*expect_type
,
59 struct expression
*exp
,
60 enum noside noside
) override
;
62 enum exp_opcode
opcode () const override
66 class objc_nsstring_operation
67 : public tuple_holding_operation
<std::string
>
71 using tuple_holding_operation::tuple_holding_operation
;
73 value
*evaluate (struct type
*expect_type
,
74 struct expression
*exp
,
75 enum noside noside
) override
77 const std::string
&str
= std::get
<0> (m_storage
);
78 return value_nsstring (exp
->gdbarch
, str
.c_str (), str
.size () + 1);
81 enum exp_opcode
opcode () const override
82 { return OP_OBJC_NSSTRING
; }
85 class objc_selector_operation
86 : public tuple_holding_operation
<std::string
>
90 using tuple_holding_operation::tuple_holding_operation
;
92 value
*evaluate (struct type
*expect_type
,
93 struct expression
*exp
,
94 enum noside noside
) override
96 return eval_op_objc_selector (expect_type
, exp
, noside
,
97 std::get
<0> (m_storage
).c_str ());
100 enum exp_opcode
opcode () const override
101 { return OP_OBJC_SELECTOR
; }
104 /* An Objective C message call. */
105 class objc_msgcall_operation
106 : public tuple_holding_operation
<CORE_ADDR
, operation_up
,
107 std::vector
<operation_up
>>
111 using tuple_holding_operation::tuple_holding_operation
;
113 value
*evaluate (struct type
*expect_type
,
114 struct expression
*exp
,
115 enum noside noside
) override
;
117 enum exp_opcode
opcode () const override
118 { return OP_OBJC_MSGCALL
; }
121 using opencl_cast_type_operation
= cxx_cast_operation
<UNOP_CAST_TYPE
,
124 /* Binary operations, as needed for OpenCL. */
125 template<enum exp_opcode OP
, binary_ftype FUNC
,
126 typename BASE
= maybe_constant_operation
<operation_up
, operation_up
>>
127 class opencl_binop_operation
134 value
*evaluate (struct type
*expect_type
,
135 struct expression
*exp
,
136 enum noside noside
) override
139 = std::get
<0> (this->m_storage
)->evaluate (nullptr, exp
, noside
);
141 = std::get
<1> (this->m_storage
)->evaluate (value_type (lhs
), exp
,
143 return FUNC (expect_type
, exp
, noside
, OP
, lhs
, rhs
);
146 enum exp_opcode
opcode () const override
150 using opencl_assign_operation
= opencl_binop_operation
<BINOP_ASSIGN
,
153 using opencl_equal_operation
= opencl_binop_operation
<BINOP_EQUAL
,
155 using opencl_notequal_operation
= opencl_binop_operation
<BINOP_NOTEQUAL
,
157 using opencl_less_operation
= opencl_binop_operation
<BINOP_LESS
,
159 using opencl_gtr_operation
= opencl_binop_operation
<BINOP_GTR
,
161 using opencl_geq_operation
= opencl_binop_operation
<BINOP_GEQ
,
163 using opencl_leq_operation
= opencl_binop_operation
<BINOP_LEQ
,
166 using opencl_not_operation
= unop_operation
<UNOP_LOGICAL_NOT
,
169 /* STRUCTOP_STRUCT implementation for OpenCL. */
170 class opencl_structop_operation
171 : public structop_base_operation
175 using structop_base_operation::structop_base_operation
;
177 value
*evaluate (struct type
*expect_type
,
178 struct expression
*exp
,
179 enum noside noside
) override
;
181 enum exp_opcode
opcode () const override
182 { return STRUCTOP_STRUCT
; }
185 /* This handles the "&&" and "||" operations for OpenCL. */
186 class opencl_logical_binop_operation
187 : public tuple_holding_operation
<enum exp_opcode
,
188 operation_up
, operation_up
>
192 using tuple_holding_operation::tuple_holding_operation
;
194 value
*evaluate (struct type
*expect_type
,
195 struct expression
*exp
,
196 enum noside noside
) override
;
198 enum exp_opcode
opcode () const override
199 { return std::get
<0> (m_storage
); }
202 /* The ?: ternary operator for OpenCL. */
203 class opencl_ternop_cond_operation
204 : public tuple_holding_operation
<operation_up
, operation_up
, operation_up
>
208 using tuple_holding_operation::tuple_holding_operation
;
210 value
*evaluate (struct type
*expect_type
,
211 struct expression
*exp
,
212 enum noside noside
) override
;
214 enum exp_opcode
opcode () const override
215 { return TERNOP_COND
; }
218 }/* namespace expr */