Implement OpenCL binary operations
[deliverable/binutils-gdb.git] / gdb / c-exp.h
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"
24 #include "objc-lang.h"
25
26 extern struct value *eval_op_objc_selector (struct type *expect_type,
27 struct expression *exp,
28 enum noside noside,
29 const char *sel);
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,
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);
41
42 namespace expr
43 {
44
45 class c_string_operation
46 : public tuple_holding_operation<enum c_string_type_values,
47 std::vector<std::string>>
48 {
49 public:
50
51 using tuple_holding_operation::tuple_holding_operation;
52
53 value *evaluate (struct type *expect_type,
54 struct expression *exp,
55 enum noside noside) override;
56
57 enum exp_opcode opcode () const override
58 { return OP_STRING; }
59 };
60
61 class objc_nsstring_operation
62 : public tuple_holding_operation<std::string>
63 {
64 public:
65
66 using tuple_holding_operation::tuple_holding_operation;
67
68 value *evaluate (struct type *expect_type,
69 struct expression *exp,
70 enum noside noside) override
71 {
72 if (noside == EVAL_SKIP)
73 return eval_skip_value (exp);
74 const std::string &str = std::get<0> (m_storage);
75 return value_nsstring (exp->gdbarch, str.c_str (), str.size () + 1);
76 }
77
78 enum exp_opcode opcode () const override
79 { return OP_OBJC_NSSTRING; }
80 };
81
82 class objc_selector_operation
83 : public tuple_holding_operation<std::string>
84 {
85 public:
86
87 using tuple_holding_operation::tuple_holding_operation;
88
89 value *evaluate (struct type *expect_type,
90 struct expression *exp,
91 enum noside noside) override
92 {
93 if (noside == EVAL_SKIP)
94 return eval_skip_value (exp);
95 return eval_op_objc_selector (expect_type, exp, noside,
96 std::get<0> (m_storage).c_str ());
97 }
98
99 enum exp_opcode opcode () const override
100 { return OP_OBJC_SELECTOR; }
101 };
102
103 /* An Objective C message call. */
104 class objc_msgcall_operation
105 : public tuple_holding_operation<CORE_ADDR, operation_up,
106 std::vector<operation_up>>
107 {
108 public:
109
110 using tuple_holding_operation::tuple_holding_operation;
111
112 value *evaluate (struct type *expect_type,
113 struct expression *exp,
114 enum noside noside) override;
115
116 enum exp_opcode opcode () const override
117 { return OP_OBJC_MSGCALL; }
118 };
119
120 using opencl_cast_type_operation = cxx_cast_operation<UNOP_CAST_TYPE,
121 opencl_value_cast>;
122
123 /* Binary operations, as needed for OpenCL. */
124 template<enum exp_opcode OP, binary_ftype FUNC,
125 typename BASE = maybe_constant_operation<operation_up, operation_up>>
126 class opencl_binop_operation
127 : public BASE
128 {
129 public:
130
131 using BASE::BASE;
132
133 value *evaluate (struct type *expect_type,
134 struct expression *exp,
135 enum noside noside) override
136 {
137 value *lhs
138 = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside);
139 value *rhs
140 = std::get<1> (this->m_storage)->evaluate (value_type (lhs), exp,
141 noside);
142 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
143 }
144
145 enum exp_opcode opcode () const override
146 { return OP; }
147 };
148
149 using opencl_assign_operation = opencl_binop_operation<BINOP_ASSIGN,
150 eval_opencl_assign,
151 assign_operation>;
152 using opencl_equal_operation = opencl_binop_operation<BINOP_EQUAL,
153 opencl_relop>;
154 using opencl_notequal_operation = opencl_binop_operation<BINOP_NOTEQUAL,
155 opencl_relop>;
156 using opencl_less_operation = opencl_binop_operation<BINOP_LESS,
157 opencl_relop>;
158 using opencl_gtr_operation = opencl_binop_operation<BINOP_GTR,
159 opencl_relop>;
160 using opencl_geq_operation = opencl_binop_operation<BINOP_GEQ,
161 opencl_relop>;
162 using opencl_leq_operation = opencl_binop_operation<BINOP_LEQ,
163 opencl_relop>;
164
165 }/* namespace expr */
166
167 #endif /* C_EXP_H */
This page took 0.033845 seconds and 5 git commands to generate.