Remove OP_UNUSED_LAST
[deliverable/binutils-gdb.git] / gdb / expression.h
1 /* Definitions for expressions stored in reversed prefix form, for GDB.
2
3 Copyright (C) 1986-2021 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 #if !defined (EXPRESSION_H)
21 #define EXPRESSION_H 1
22
23 #include "gdbtypes.h"
24
25 /* While parsing expressions we need to track the innermost lexical block
26 that we encounter. In some situations we need to track the innermost
27 block just for symbols, and in other situations we want to track the
28 innermost block for symbols and registers. These flags are used by the
29 innermost block tracker to control which blocks we consider for the
30 innermost block. These flags can be combined together as needed. */
31
32 enum innermost_block_tracker_type
33 {
34 /* Track the innermost block for symbols within an expression. */
35 INNERMOST_BLOCK_FOR_SYMBOLS = (1 << 0),
36
37 /* Track the innermost block for registers within an expression. */
38 INNERMOST_BLOCK_FOR_REGISTERS = (1 << 1)
39 };
40 DEF_ENUM_FLAGS_TYPE (enum innermost_block_tracker_type,
41 innermost_block_tracker_types);
42
43 enum exp_opcode : uint8_t
44 {
45 #define OP(name) name ,
46
47 #include "std-operator.def"
48
49 #undef OP
50 };
51
52 /* Values of NOSIDE argument to eval_subexp. */
53
54 enum noside
55 {
56 EVAL_NORMAL,
57 EVAL_SKIP, /* Only effect is to increment pos.
58 Return type information where
59 possible. */
60 EVAL_AVOID_SIDE_EFFECTS /* Don't modify any variables or
61 call any functions. The value
62 returned will have the correct
63 type, and will have an
64 approximately correct lvalue
65 type (inaccuracy: anything that is
66 listed as being in a register in
67 the function in which it was
68 declared will be lval_register).
69 Ideally this would not even read
70 target memory, but currently it
71 does in many situations. */
72 };
73
74 struct expression;
75 struct agent_expr;
76 struct axs_value;
77 struct type;
78 struct ui_file;
79
80 namespace expr
81 {
82
83 class operation;
84 typedef std::unique_ptr<operation> operation_up;
85
86 /* Base class for an operation. An operation is a single component of
87 an expression. */
88
89 class operation
90 {
91 protected:
92
93 operation () = default;
94 DISABLE_COPY_AND_ASSIGN (operation);
95
96 public:
97
98 virtual ~operation () = default;
99
100 /* Evaluate this operation. */
101 virtual value *evaluate (struct type *expect_type,
102 struct expression *exp,
103 enum noside noside) = 0;
104
105 /* Evaluate this operation in a context where C-like coercion is
106 needed. */
107 virtual value *evaluate_with_coercion (struct expression *exp,
108 enum noside noside)
109 {
110 return evaluate (nullptr, exp, noside);
111 }
112
113 /* Evaluate this expression in the context of a cast to
114 EXPECT_TYPE. */
115 virtual value *evaluate_for_cast (struct type *expect_type,
116 struct expression *exp,
117 enum noside noside);
118
119 /* Evaluate this expression in the context of a sizeof
120 operation. */
121 virtual value *evaluate_for_sizeof (struct expression *exp,
122 enum noside noside);
123
124 /* Evaluate this expression in the context of an address-of
125 operation. Must return the address. */
126 virtual value *evaluate_for_address (struct expression *exp,
127 enum noside noside);
128
129 /* Evaluate a function call, with this object as the callee.
130 EXPECT_TYPE, EXP, and NOSIDE have the same meaning as in
131 'evaluate'. ARGS holds the operations that should be evaluated
132 to get the arguments to the call. */
133 virtual value *evaluate_funcall (struct type *expect_type,
134 struct expression *exp,
135 enum noside noside,
136 const std::vector<operation_up> &args)
137 {
138 /* Defer to the helper overload. */
139 return evaluate_funcall (expect_type, exp, noside, nullptr, args);
140 }
141
142 /* True if this is a constant expression. */
143 virtual bool constant_p () const
144 { return false; }
145
146 /* Return true if this operation uses OBJFILE (and will become
147 dangling when OBJFILE is unloaded), otherwise return false.
148 OBJFILE must not be a separate debug info file. */
149 virtual bool uses_objfile (struct objfile *objfile) const
150 { return false; }
151
152 /* Generate agent expression bytecodes for this operation. */
153 void generate_ax (struct expression *exp, struct agent_expr *ax,
154 struct axs_value *value,
155 struct type *cast_type = nullptr);
156
157 /* Return the opcode that is implemented by this operation. */
158 virtual enum exp_opcode opcode () const = 0;
159
160 /* Print this operation to STREAM. */
161 virtual void dump (struct ui_file *stream, int depth) const = 0;
162
163 /* Call to indicate that this is the outermost operation in the
164 expression. This should almost never be overridden. */
165 virtual void set_outermost () { }
166
167 protected:
168
169 /* A helper overload that wraps evaluate_subexp_do_call. */
170 value *evaluate_funcall (struct type *expect_type,
171 struct expression *exp,
172 enum noside noside,
173 const char *function_name,
174 const std::vector<operation_up> &args);
175
176 /* Called by generate_ax to do the work for this particular
177 operation. */
178 virtual void do_generate_ax (struct expression *exp,
179 struct agent_expr *ax,
180 struct axs_value *value,
181 struct type *cast_type)
182 {
183 error (_("Cannot translate to agent expression"));
184 }
185 };
186
187 /* A helper function for creating an operation_up, given a type. */
188 template<typename T, typename... Arg>
189 operation_up
190 make_operation (Arg... args)
191 {
192 return operation_up (new T (std::forward<Arg> (args)...));
193 }
194
195 }
196
197 struct expression
198 {
199 expression (const struct language_defn *, struct gdbarch *);
200 ~expression ();
201 DISABLE_COPY_AND_ASSIGN (expression);
202
203 /* Return the opcode for the outermost sub-expression of this
204 expression. */
205 enum exp_opcode first_opcode () const
206 {
207 return op->opcode ();
208 }
209
210 /* Evaluate the expression. EXPECT_TYPE is the context type of the
211 expression; normally this should be nullptr. NOSIDE controls how
212 evaluation is performed. */
213 struct value *evaluate (struct type *expect_type, enum noside noside);
214
215 /* Language it was entered in. */
216 const struct language_defn *language_defn;
217 /* Architecture it was parsed in. */
218 struct gdbarch *gdbarch;
219 expr::operation_up op;
220 };
221
222 typedef std::unique_ptr<expression> expression_up;
223
224 /* From parse.c */
225
226 class innermost_block_tracker;
227 extern expression_up parse_expression (const char *,
228 innermost_block_tracker * = nullptr,
229 bool void_context_p = false);
230
231 extern expression_up parse_expression_with_language (const char *string,
232 enum language lang);
233
234 extern struct type *parse_expression_for_completion
235 (const char *, gdb::unique_xmalloc_ptr<char> *, enum type_code *);
236
237 class innermost_block_tracker;
238 extern expression_up parse_exp_1 (const char **, CORE_ADDR pc,
239 const struct block *, int,
240 innermost_block_tracker * = nullptr);
241
242 /* From eval.c */
243
244 /* Evaluate a function call. The function to be called is in CALLEE and
245 the arguments passed to the function are in ARGVEC.
246 FUNCTION_NAME is the name of the function, if known.
247 DEFAULT_RETURN_TYPE is used as the function's return type if the return
248 type is unknown. */
249
250 extern struct value *evaluate_subexp_do_call (expression *exp,
251 enum noside noside,
252 value *callee,
253 gdb::array_view<value *> argvec,
254 const char *function_name,
255 type *default_return_type);
256
257 /* From expprint.c */
258
259 extern const char *op_name (enum exp_opcode opcode);
260
261 extern void dump_prefix_expression (struct expression *, struct ui_file *);
262
263 /* In an OP_RANGE expression, either bound could be empty, indicating
264 that its value is by default that of the corresponding bound of the
265 array or string. Also, the upper end of the range can be exclusive
266 or inclusive. So we have six sorts of subrange. This enumeration
267 type is to identify this. */
268
269 enum range_flag : unsigned
270 {
271 /* This is a standard range. Both the lower and upper bounds are
272 defined, and the bounds are inclusive. */
273 RANGE_STANDARD = 0,
274
275 /* The low bound was not given. */
276 RANGE_LOW_BOUND_DEFAULT = 1 << 0,
277
278 /* The high bound was not given. */
279 RANGE_HIGH_BOUND_DEFAULT = 1 << 1,
280
281 /* The high bound of this range is exclusive. */
282 RANGE_HIGH_BOUND_EXCLUSIVE = 1 << 2,
283
284 /* The range has a stride. */
285 RANGE_HAS_STRIDE = 1 << 3,
286 };
287
288 DEF_ENUM_FLAGS_TYPE (enum range_flag, range_flags);
289
290 #endif /* !defined (EXPRESSION_H) */
This page took 0.035343 seconds and 5 git commands to generate.