GDB (xrefs)
Loading...
Searching...
No Matches
c-exp.h
Go to the documentation of this file.
1/* Definitions for C expressions
2
3 Copyright (C) 2020-2023 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
26extern struct value *eval_op_objc_selector (struct type *expect_type,
27 struct expression *exp,
28 enum noside noside,
29 const char *sel);
30extern struct value *opencl_value_cast (struct type *type, struct value *arg);
31extern 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);
37extern 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);
41extern 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);
46
47namespace expr
48{
49
51 : public tuple_holding_operation<enum c_string_type_values,
52 std::vector<std::string>>
53{
54public:
55
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
67 : public tuple_holding_operation<std::string>
68{
69public:
70
72
73 value *evaluate (struct type *expect_type,
74 struct expression *exp,
75 enum noside noside) override
76 {
77 const std::string &str = std::get<0> (m_storage);
78 return value_nsstring (exp->gdbarch, str.c_str (), str.size () + 1);
79 }
80
81 enum exp_opcode opcode () const override
82 { return OP_OBJC_NSSTRING; }
83};
84
86 : public tuple_holding_operation<std::string>
87{
88public:
89
91
92 value *evaluate (struct type *expect_type,
93 struct expression *exp,
94 enum noside noside) override
95 {
96 return eval_op_objc_selector (expect_type, exp, noside,
97 std::get<0> (m_storage).c_str ());
98 }
99
100 enum exp_opcode opcode () const override
101 { return OP_OBJC_SELECTOR; }
102};
103
104/* An Objective C message call. */
106 : public tuple_holding_operation<CORE_ADDR, operation_up,
107 std::vector<operation_up>>
108{
109public:
110
112
113 value *evaluate (struct type *expect_type,
114 struct expression *exp,
115 enum noside noside) override;
116
117 enum exp_opcode opcode () const override
118 { return OP_OBJC_MSGCALL; }
119};
120
123
124/* Binary operations, as needed for OpenCL. */
125template<enum exp_opcode OP, binary_ftype FUNC,
128 : public BASE
129{
130public:
131
132 using BASE::BASE;
133
134 value *evaluate (struct type *expect_type,
135 struct expression *exp,
136 enum noside noside) override
137 {
138 value *lhs
139 = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside);
140 value *rhs
141 = std::get<1> (this->m_storage)->evaluate (lhs->type (), exp,
142 noside);
143 return FUNC (expect_type, exp, noside, OP, lhs, rhs);
144 }
145
146 enum exp_opcode opcode () const override
147 { return OP; }
148};
149
165
166using opencl_not_operation = unop_operation<UNOP_LOGICAL_NOT,
168
169/* STRUCTOP_STRUCT implementation for OpenCL. */
172{
173public:
174
175 using structop_base_operation::structop_base_operation;
176
177 value *evaluate (struct type *expect_type,
178 struct expression *exp,
179 enum noside noside) override;
180
181 enum exp_opcode opcode () const override
182 { return STRUCTOP_STRUCT; }
183};
184
185/* This handles the "&&" and "||" operations for OpenCL. */
187 : public tuple_holding_operation<enum exp_opcode,
188 operation_up, operation_up>
189{
190public:
191
193
194 value *evaluate (struct type *expect_type,
195 struct expression *exp,
196 enum noside noside) override;
197
198 enum exp_opcode opcode () const override
199 { return std::get<0> (m_storage); }
200};
201
202/* The ?: ternary operator for OpenCL. */
204 : public tuple_holding_operation<operation_up, operation_up, operation_up>
205{
206public:
207
209
210 value *evaluate (struct type *expect_type,
211 struct expression *exp,
212 enum noside noside) override;
213
214 enum exp_opcode opcode () const override
215 { return TERNOP_COND; }
216};
217
218}/* namespace expr */
219
220#endif /* C_EXP_H */
struct value * eval_op_objc_selector(struct type *expect_type, struct expression *exp, enum noside noside, const char *sel)
Definition eval.c:1180
struct value * opencl_value_cast(struct type *type, struct value *arg)
struct value * opencl_relop(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
struct value * opencl_logical_not(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg)
struct value * eval_opencl_assign(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
enum exp_opcode opcode() const override
Definition c-exp.h:62
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition c-lang.c:585
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2207
enum exp_opcode opcode() const override
Definition c-exp.h:117
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition c-exp.h:73
enum exp_opcode opcode() const override
Definition c-exp.h:81
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition c-exp.h:92
enum exp_opcode opcode() const override
Definition c-exp.h:100
enum exp_opcode opcode() const override
Definition c-exp.h:146
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition c-exp.h:134
enum exp_opcode opcode() const override
Definition c-exp.h:198
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
enum exp_opcode opcode() const override
Definition c-exp.h:181
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
enum exp_opcode opcode() const override
Definition c-exp.h:214
tuple_holding_operation(Arg... args)
Definition expop.h:374
#define OP(name)
exp_opcode
Definition expression.h:45
noside
Definition expression.h:56
Definition ada-exp.h:87
struct value * binary_ftype(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition expop.h:1248
struct value * value_nsstring(struct gdbarch *gdbarch, const char *ptr, int len)
Definition objc-lang.c:168
struct gdbarch * gdbarch
Definition expression.h:237
Definition value.h:130
struct type * type() const
Definition value.h:180