GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/gdb/expression.h
Go to the documentation of this file.
1/* Definitions for expressions stored in reversed prefix form, for GDB.
2
3 Copyright (C) 1986-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#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
33{
34 /* Track the innermost block for symbols within an expression. */
36
37 /* Track the innermost block for registers within an expression. */
39};
41 innermost_block_tracker_types);
42
43enum 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
55 {
57 EVAL_AVOID_SIDE_EFFECTS /* Don't modify any variables or
58 call any functions. The value
59 returned will have the correct
60 type, and will have an
61 approximately correct lvalue
62 type (inaccuracy: anything that is
63 listed as being in a register in
64 the function in which it was
65 declared will be lval_register).
66 Ideally this would not even read
67 target memory, but currently it
68 does in many situations. */
69 };
70
71struct expression;
72struct agent_expr;
73struct axs_value;
74struct type;
75struct ui_file;
76
77namespace expr
78{
79
80class operation;
81typedef std::unique_ptr<operation> operation_up;
82
83/* Base class for an operation. An operation is a single component of
84 an expression. */
85
87{
88protected:
89
90 operation () = default;
92
93public:
94
95 virtual ~operation () = default;
96
97 /* Evaluate this operation. */
98 virtual value *evaluate (struct type *expect_type,
99 struct expression *exp,
100 enum noside noside) = 0;
101
102 /* Evaluate this operation in a context where C-like coercion is
103 needed. */
105 enum noside noside)
106 {
107 return evaluate (nullptr, exp, noside);
108 }
109
110 /* Evaluate this expression in the context of a cast to
111 EXPECT_TYPE. */
112 virtual value *evaluate_for_cast (struct type *expect_type,
113 struct expression *exp,
114 enum noside noside);
115
116 /* Evaluate this expression in the context of a sizeof
117 operation. */
118 virtual value *evaluate_for_sizeof (struct expression *exp,
119 enum noside noside);
120
121 /* Evaluate this expression in the context of an address-of
122 operation. Must return the address. */
123 virtual value *evaluate_for_address (struct expression *exp,
124 enum noside noside);
125
126 /* Evaluate a function call, with this object as the callee.
127 EXPECT_TYPE, EXP, and NOSIDE have the same meaning as in
128 'evaluate'. ARGS holds the operations that should be evaluated
129 to get the arguments to the call. */
130 virtual value *evaluate_funcall (struct type *expect_type,
131 struct expression *exp,
132 enum noside noside,
133 const std::vector<operation_up> &args)
134 {
135 /* Defer to the helper overload. */
136 return evaluate_funcall (expect_type, exp, noside, nullptr, args);
137 }
138
139 /* True if this is a constant expression. */
140 virtual bool constant_p () const
141 { return false; }
142
143 /* Return true if this operation uses OBJFILE (and will become
144 dangling when OBJFILE is unloaded), otherwise return false.
145 OBJFILE must not be a separate debug info file. */
146 virtual bool uses_objfile (struct objfile *objfile) const
147 { return false; }
148
149 /* Generate agent expression bytecodes for this operation. */
150 void generate_ax (struct expression *exp, struct agent_expr *ax,
151 struct axs_value *value,
152 struct type *cast_type = nullptr);
153
154 /* Return the opcode that is implemented by this operation. */
155 virtual enum exp_opcode opcode () const = 0;
156
157 /* Print this operation to STREAM. */
158 virtual void dump (struct ui_file *stream, int depth) const = 0;
159
160 /* Call to indicate that this is the outermost operation in the
161 expression. This should almost never be overridden. */
162 virtual void set_outermost () { }
163
164protected:
165
166 /* A helper overload that wraps evaluate_subexp_do_call. */
167 value *evaluate_funcall (struct type *expect_type,
168 struct expression *exp,
169 enum noside noside,
170 const char *function_name,
171 const std::vector<operation_up> &args);
172
173 /* Called by generate_ax to do the work for this particular
174 operation. */
175 virtual void do_generate_ax (struct expression *exp,
176 struct agent_expr *ax,
177 struct axs_value *value,
178 struct type *cast_type)
179 {
180 error (_("Cannot translate to agent expression"));
181 }
182};
183
184/* A helper function for creating an operation_up, given a type. */
185template<typename T, typename... Arg>
187make_operation (Arg... args)
188{
189 return operation_up (new T (std::forward<Arg> (args)...));
190}
191
192}
193
195{
196 expression (const struct language_defn *lang, struct gdbarch *arch)
197 : language_defn (lang),
198 gdbarch (arch)
199 {
200 }
201
203
204 /* Return the opcode for the outermost sub-expression of this
205 expression. */
207 {
208 return op->opcode ();
209 }
210
211 /* Dump the expression to STREAM. */
212 void dump (struct ui_file *stream)
213 {
214 op->dump (stream, 0);
215 }
216
217 /* Evaluate the expression. EXPECT_TYPE is the context type of the
218 expression; normally this should be nullptr. NOSIDE controls how
219 evaluation is performed. */
220 struct value *evaluate (struct type *expect_type, enum noside noside);
221
222 /* Language it was entered in. */
224 /* Architecture it was parsed in. */
227};
228
229typedef std::unique_ptr<expression> expression_up;
230
231/* From parse.c */
232
234extern expression_up parse_expression (const char *,
235 innermost_block_tracker * = nullptr,
236 bool void_context_p = false);
237
238extern expression_up parse_expression_with_language (const char *string,
239 enum language lang);
240
241
243
244/* Base class for expression completion. An instance of this
245 represents a completion request from the parser. */
247{
248 /* Perform this object's completion. EXP is the expression in which
249 the completion occurs. TRACKER is the tracker to update with the
250 results. Return true if completion was possible (even if no
251 completions were found), false to fall back to ordinary
252 expression completion (i.e., symbol names). */
253 virtual bool complete (struct expression *exp,
254 completion_tracker &tracker) = 0;
255
256 virtual ~expr_completion_base () = default;
257};
258
260 (const char *, std::unique_ptr<expr_completion_base> *completer);
261
263extern expression_up parse_exp_1 (const char **, CORE_ADDR pc,
264 const struct block *, int,
265 innermost_block_tracker * = nullptr);
266
267/* From eval.c */
268
269/* Evaluate a function call. The function to be called is in CALLEE and
270 the arguments passed to the function are in ARGVEC.
271 FUNCTION_NAME is the name of the function, if known.
272 DEFAULT_RETURN_TYPE is used as the function's return type if the return
273 type is unknown. */
274
275extern struct value *evaluate_subexp_do_call (expression *exp,
276 enum noside noside,
277 value *callee,
278 gdb::array_view<value *> argvec,
279 const char *function_name,
280 type *default_return_type);
281
282/* From expprint.c */
283
284extern const char *op_name (enum exp_opcode opcode);
285
286/* In an OP_RANGE expression, either bound could be empty, indicating
287 that its value is by default that of the corresponding bound of the
288 array or string. Also, the upper end of the range can be exclusive
289 or inclusive. So we have six sorts of subrange. This enumeration
290 type is to identify this. */
291
292enum range_flag : unsigned
293{
294 /* This is a standard range. Both the lower and upper bounds are
295 defined, and the bounds are inclusive. */
297
298 /* The low bound was not given. */
300
301 /* The high bound was not given. */
303
304 /* The high bound of this range is exclusive. */
306
307 /* The range has a stride. */
309};
310
311DEF_ENUM_FLAGS_TYPE (enum range_flag, range_flags);
312
313#endif /* !defined (EXPRESSION_H) */
virtual ~operation()=default
virtual value * evaluate_for_address(struct expression *exp, enum noside noside)
Definition: eval.c:2605
virtual value * evaluate_funcall(struct type *expect_type, struct expression *exp, enum noside noside, const std::vector< operation_up > &args)
Definition: expression.h:130
virtual void do_generate_ax(struct expression *exp, struct agent_expr *ax, struct axs_value *value, struct type *cast_type)
Definition: expression.h:175
virtual void set_outermost()
Definition: expression.h:162
virtual bool uses_objfile(struct objfile *objfile) const
Definition: expression.h:146
virtual value * evaluate_with_coercion(struct expression *exp, enum noside noside)
Definition: expression.h:104
virtual bool constant_p() const
Definition: expression.h:140
operation()=default
virtual value * evaluate_for_sizeof(struct expression *exp, enum noside noside)
Definition: eval.c:2740
void generate_ax(struct expression *exp, struct agent_expr *ax, struct axs_value *value, struct type *cast_type=nullptr)
Definition: ax-gdb.c:1578
virtual void dump(struct ui_file *stream, int depth) const =0
DISABLE_COPY_AND_ASSIGN(operation)
virtual value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside)=0
virtual enum exp_opcode opcode() const =0
virtual value * evaluate_for_cast(struct type *expect_type, struct expression *exp, enum noside noside)
Definition: eval.c:2596
language
Definition: defs.h:211
std::unique_ptr< expression > expression_up
Definition: expression.h:229
expression_up parse_exp_1(const char **, CORE_ADDR pc, const struct block *, int, innermost_block_tracker *=nullptr)
Definition: parse.c:424
expression_up parse_expression_with_language(const char *string, enum language lang)
Definition: parse.c:561
const char * op_name(enum exp_opcode opcode)
Definition: expprint.c:43
exp_opcode
Definition: expression.h:44
innermost_block_tracker_type
Definition: expression.h:33
@ INNERMOST_BLOCK_FOR_REGISTERS
Definition: expression.h:38
@ INNERMOST_BLOCK_FOR_SYMBOLS
Definition: expression.h:35
expression_up parse_expression_for_completion(const char *, std::unique_ptr< expr_completion_base > *completer)
Definition: parse.c:579
DEF_ENUM_FLAGS_TYPE(enum innermost_block_tracker_type, innermost_block_tracker_types)
struct value * evaluate_subexp_do_call(expression *exp, enum noside noside, value *callee, gdb::array_view< value * > argvec, const char *function_name, type *default_return_type)
Definition: eval.c:608
noside
Definition: expression.h:55
@ EVAL_NORMAL
Definition: expression.h:56
@ EVAL_AVOID_SIDE_EFFECTS
Definition: expression.h:57
range_flag
Definition: expression.h:293
@ RANGE_LOW_BOUND_DEFAULT
Definition: expression.h:299
@ RANGE_HIGH_BOUND_EXCLUSIVE
Definition: expression.h:305
@ RANGE_HIGH_BOUND_DEFAULT
Definition: expression.h:302
@ RANGE_STANDARD
Definition: expression.h:296
@ RANGE_HAS_STRIDE
Definition: expression.h:308
expression_up parse_expression(const char *, innermost_block_tracker *=nullptr, bool void_context_p=false)
Definition: parse.c:546
Definition: ada-exp.h:80
operation_up make_operation(Arg... args)
Definition: expression.h:187
std::unique_ptr< operation > operation_up
Definition: expression.h:81
Definition: 1.cc:26
Definition: ax.h:82
Definition: block.h:109
virtual bool complete(struct expression *exp, completion_tracker &tracker)=0
virtual ~expr_completion_base()=default
const struct language_defn * language_defn
Definition: expression.h:223
struct value * evaluate(struct type *expect_type, enum noside noside)
Definition: eval.c:93
expression(const struct language_defn *lang, struct gdbarch *arch)
Definition: expression.h:196
void dump(struct ui_file *stream)
Definition: expression.h:212
expr::operation_up op
Definition: expression.h:226
DISABLE_COPY_AND_ASSIGN(expression)
enum exp_opcode first_opcode() const
Definition: expression.h:206
struct gdbarch * gdbarch
Definition: expression.h:225
Definition: gdbtypes.h:922
Definition: value.c:181