]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/expression.h
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / expression.h
CommitLineData
bd5635a1 1/* Definitions for expressions stored in reversed prefix form, for GDB.
f91a9e05 2 Copyright 1986, 1989, 1992, 1994 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
35fcebce 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
35fcebce
PB
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
35fcebce 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
35fcebce 17along with this program; if not, write to the Free Software
cd10c7e3 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
35fcebce
PB
19
20#if !defined (EXPRESSION_H)
21#define EXPRESSION_H 1
bd5635a1 22
54bbbfb4
FF
23#ifdef __STDC__
24struct block; /* Forward declaration for prototypes */
25#endif
26
bd5635a1
RP
27/* Definitions for saved C expressions. */
28
29/* An expression is represented as a vector of union exp_element's.
30 Each exp_element is an opcode, except that some opcodes cause
31 the following exp_element to be treated as a long or double constant
32 or as a variable. The opcodes are obeyed, using a stack for temporaries.
33 The value is left on the temporary stack at the end. */
34
35/* When it is necessary to include a string,
36 it can occupy as many exp_elements as it needs.
37 We find the length of the string using strlen,
38 divide to find out how many exp_elements are used up,
39 and skip that many. Strings, like numbers, are indicated
40 by the preceding opcode. */
41
42enum exp_opcode
43{
35fcebce
PB
44 /* Used when it's necessary to pass an opcode which will be ignored,
45 or to catch uninitialized values. */
46 OP_NULL,
47
bd5635a1
RP
48/* BINOP_... operate on two values computed by following subexpressions,
49 replacing them by one result value. They take no immediate arguments. */
f91a9e05 50
bd5635a1
RP
51 BINOP_ADD, /* + */
52 BINOP_SUB, /* - */
53 BINOP_MUL, /* * */
54 BINOP_DIV, /* / */
55 BINOP_REM, /* % */
76a0ffb4 56 BINOP_MOD, /* mod (Knuth 1.2.4) */
bd5635a1
RP
57 BINOP_LSH, /* << */
58 BINOP_RSH, /* >> */
54bbbfb4
FF
59 BINOP_LOGICAL_AND, /* && */
60 BINOP_LOGICAL_OR, /* || */
61 BINOP_BITWISE_AND, /* & */
62 BINOP_BITWISE_IOR, /* | */
63 BINOP_BITWISE_XOR, /* ^ */
bd5635a1
RP
64 BINOP_EQUAL, /* == */
65 BINOP_NOTEQUAL, /* != */
66 BINOP_LESS, /* < */
67 BINOP_GTR, /* > */
68 BINOP_LEQ, /* <= */
69 BINOP_GEQ, /* >= */
70 BINOP_REPEAT, /* @ */
71 BINOP_ASSIGN, /* = */
72 BINOP_COMMA, /* , */
73 BINOP_SUBSCRIPT, /* x[y] */
74 BINOP_EXP, /* Exponentiation */
75
f91a9e05
PB
76 /* C++. */
77
bd5635a1
RP
78 BINOP_MIN, /* <? */
79 BINOP_MAX, /* >? */
80 BINOP_SCOPE, /* :: */
81
82 /* STRUCTOP_MEMBER is used for pointer-to-member constructs.
83 X . * Y translates into X STRUCTOP_MEMBER Y. */
84 STRUCTOP_MEMBER,
f91a9e05 85
bd5635a1
RP
86 /* STRUCTOP_MPTR is used for pointer-to-member constructs
87 when X is a pointer instead of an aggregate. */
88 STRUCTOP_MPTR,
f91a9e05
PB
89
90 /* end of C++. */
bd5635a1 91
35fcebce
PB
92 /* For Modula-2 integer division DIV */
93 BINOP_INTDIV,
bd5635a1
RP
94
95 BINOP_ASSIGN_MODIFY, /* +=, -=, *=, and so on.
96 The following exp_element is another opcode,
97 a BINOP_, saying how to modify.
98 Then comes another BINOP_ASSIGN_MODIFY,
99 making three exp_elements in total. */
100
f91a9e05 101 /* Modula-2 standard (binary) procedures */
35fcebce
PB
102 BINOP_VAL,
103 BINOP_INCL,
104 BINOP_EXCL,
105
f91a9e05
PB
106 /* Concatenate two operands, such as character strings or bitstrings.
107 If the first operand is a integer expression, then it means concatenate
108 the second operand with itself that many times. */
109 BINOP_CONCAT,
110
111 /* For Chill and Pascal. */
112 BINOP_IN, /* Returns 1 iff ARG1 IN ARG2. */
113
35fcebce
PB
114 /* This must be the highest BINOP_ value, for expprint.c. */
115 BINOP_END,
116
f91a9e05 117 /* Operates on three values computed by following subexpressions. */
bd5635a1
RP
118 TERNOP_COND, /* ?: */
119
f91a9e05
PB
120 /* A sub-string/sub-array. Chill syntax: OP1(OP2:OP3).
121 Return elements OP2 through OP3 of OP1. */
122 TERNOP_SLICE,
54bbbfb4 123
f91a9e05
PB
124 /* A sub-string/sub-array. Chill syntax: OP1(OP2 UP OP3).
125 Return OP3 elements of OP1, starting with element OP2. */
126 TERNOP_SLICE_COUNT,
bd5635a1 127
f91a9e05
PB
128 /* Multidimensional subscript operator, such as Modula-2 x[a,b,...].
129 The dimensionality is encoded in the operator, like the number of
130 function arguments in OP_FUNCALL, I.E. <OP><dimension><OP>.
131 The value of the first following subexpression is subscripted
132 by each of the next following subexpressions, one per dimension. */
133 MULTI_SUBSCRIPT,
bd5635a1 134
f91a9e05
PB
135 /* The OP_... series take immediate following arguments.
136 After the arguments come another OP_... (the same one)
137 so that the grouping can be recognized from the end. */
138
139 /* OP_LONG is followed by a type pointer in the next exp_element
140 and the long constant value in the following exp_element.
141 Then comes another OP_LONG.
142 Thus, the operation occupies four exp_elements. */
bd5635a1 143 OP_LONG,
f91a9e05
PB
144
145 /* OP_DOUBLE is similar but takes a double constant instead of a long. */
bd5635a1 146 OP_DOUBLE,
f91a9e05
PB
147
148 /* OP_VAR_VALUE takes one struct block * in the following element,
149 and one struct symbol * in the following exp_element, followed by
150 another OP_VAR_VALUE, making four exp_elements. If the block is
151 non-NULL, evaluate the symbol relative to the innermost frame
152 executing in that block; if the block is NULL use the selected frame. */
bd5635a1 153 OP_VAR_VALUE,
f91a9e05
PB
154
155 /* OP_LAST is followed by an integer in the next exp_element.
156 The integer is zero for the last value printed,
157 or it is the absolute number of a history element.
158 With another OP_LAST at the end, this makes three exp_elements. */
bd5635a1 159 OP_LAST,
f91a9e05
PB
160
161 /* OP_REGISTER is followed by an integer in the next exp_element.
162 This is the number of a register to fetch (as an int).
163 With another OP_REGISTER at the end, this makes three exp_elements. */
bd5635a1 164 OP_REGISTER,
f91a9e05
PB
165
166 /* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element.
167 With another OP_INTERNALVAR at the end, this makes three exp_elements. */
bd5635a1 168 OP_INTERNALVAR,
f91a9e05
PB
169
170 /* OP_FUNCALL is followed by an integer in the next exp_element.
171 The integer is the number of args to the function call.
172 That many plus one values from following subexpressions
173 are used, the first one being the function.
174 The integer is followed by a repeat of OP_FUNCALL,
175 making three exp_elements. */
bd5635a1 176 OP_FUNCALL,
f91a9e05
PB
177
178 /* This is EXACTLY like OP_FUNCALL but is semantically different.
179 In F77, array subscript expressions, substring expressions
180 and function calls are all exactly the same syntactically. They may
181 only be dismabiguated at runtime. Thus this operator, which
182 indicates that we have found something of the form <name> ( <stuff> ) */
183 OP_F77_UNDETERMINED_ARGLIST,
184
185 /* The following OP is a special one, it introduces a F77 complex
186 literal. It is followed by exactly two args that are doubles. */
ead95f8a 187 OP_COMPLEX,
f91a9e05 188
f91a9e05
PB
189 /* OP_STRING represents a string constant.
190 Its format is the same as that of a STRUCTOP, but the string
191 data is just made into a string constant when the operation
192 is executed. */
bd5635a1
RP
193 OP_STRING,
194
f91a9e05
PB
195 /* OP_BITSTRING represents a packed bitstring constant.
196 Its format is the same as that of a STRUCTOP, but the bitstring
197 data is just made into a bitstring constant when the operation
198 is executed. */
199 OP_BITSTRING,
200
201 /* OP_ARRAY creates an array constant out of the following subexpressions.
202 It is followed by two exp_elements, the first containing an integer
203 that is the lower bound of the array and the second containing another
204 integer that is the upper bound of the array. The second integer is
205 followed by a repeat of OP_ARRAY, making four exp_elements total.
206 The bounds are used to compute the number of following subexpressions
207 to consume, as well as setting the bounds in the created array constant.
208 The type of the elements is taken from the type of the first subexp,
209 and they must all match. */
210 OP_ARRAY,
211
212 /* UNOP_CAST is followed by a type pointer in the next exp_element.
213 With another UNOP_CAST at the end, this makes three exp_elements.
214 It casts the value of the following subexpression. */
bd5635a1 215 UNOP_CAST,
f91a9e05
PB
216
217 /* UNOP_MEMVAL is followed by a type pointer in the next exp_element
218 With another UNOP_MEMVAL at the end, this makes three exp_elements.
219 It casts the contents of the word addressed by the value of the
220 following subexpression. */
bd5635a1 221 UNOP_MEMVAL,
f91a9e05
PB
222
223 /* UNOP_... operate on one value from a following subexpression
224 and replace it with a result. They take no immediate arguments. */
225
bd5635a1 226 UNOP_NEG, /* Unary - */
54bbbfb4
FF
227 UNOP_LOGICAL_NOT, /* Unary ! */
228 UNOP_COMPLEMENT, /* Unary ~ */
bd5635a1
RP
229 UNOP_IND, /* Unary * */
230 UNOP_ADDR, /* Unary & */
231 UNOP_PREINCREMENT, /* ++ before an expression */
232 UNOP_POSTINCREMENT, /* ++ after an expression */
233 UNOP_PREDECREMENT, /* -- before an expression */
234 UNOP_POSTDECREMENT, /* -- after an expression */
235 UNOP_SIZEOF, /* Unary sizeof (followed by expression) */
236
35fcebce
PB
237 UNOP_PLUS, /* Unary plus */
238
239 UNOP_CAP, /* Modula-2 standard (unary) procedures */
240 UNOP_CHR,
241 UNOP_ORD,
242 UNOP_ABS,
243 UNOP_FLOAT,
244 UNOP_HIGH,
245 UNOP_MAX,
246 UNOP_MIN,
247 UNOP_ODD,
248 UNOP_TRUNC,
249
cd10c7e3
SG
250 /* Chill builtin functions. */
251 UNOP_LOWER, UNOP_UPPER, UNOP_LENGTH,
252
35fcebce
PB
253 OP_BOOL, /* Modula-2 builtin BOOLEAN type */
254 OP_M2_STRING, /* Modula-2 string constants */
255
f91a9e05
PB
256 /* STRUCTOP_... operate on a value from a following subexpression
257 by extracting a structure component specified by a string
258 that appears in the following exp_elements (as many as needed).
259 STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->".
260 They differ only in the error message given in case the value is
261 not suitable or the structure component specified is not found.
262
263 The length of the string follows the opcode, followed by
264 BYTES_TO_EXP_ELEM(length) elements containing the data of the
265 string, followed by the length again and the opcode again. */
bd5635a1 266
bd5635a1
RP
267 STRUCTOP_STRUCT,
268 STRUCTOP_PTR,
269
cd10c7e3
SG
270/* start-sanitize-gm */
271#ifdef GENERAL_MAGIC_HACKS
272 /* STRUCTOP_FIELD is for handling field access for Magic Cap dynamic objects.
273 */
274 STRUCTOP_FIELD,
275#endif /* GENERAL_MAGIC_HACKS */
276/* end-sanitize-gm */
277
f91a9e05 278 /* C++ */
bd5635a1
RP
279 /* OP_THIS is just a placeholder for the class instance variable.
280 It just comes in a tight (OP_THIS, OP_THIS) pair. */
281 OP_THIS,
282
283 /* OP_SCOPE surrounds a type name and a field name. The type
284 name is encoded as one element, but the field name stays as
285 a string, which, of course, is variable length. */
286 OP_SCOPE,
287
f91a9e05
PB
288 /* Used to represent named structure field values in brace initializers
289 (or tuples as they are called in Chill).
290 The gcc C syntax is NAME:VALUE or .NAME=VALUE, the Chill syntax is
291 .NAME:VALUE. Multiple labels (as in the Chill syntax
292 .NAME1,.NAME2:VALUE) is represented as if it were
293 .NAME1:(.NAME2:VALUE) (though that is not valid Chill syntax).
294
295 The NAME is represented as for STRUCTOP_STRUCT; VALUE follows. */
296 OP_LABELED,
297
35fcebce
PB
298 /* OP_TYPE is for parsing types, and used with the "ptype" command
299 so we can look up types that are qualified by scope, either with
300 the GDB "::" operator, or the Modula-2 '.' operator. */
cd10c7e3
SG
301 OP_TYPE,
302
303 /* An un-looked-up identifier. */
304 OP_NAME,
305
306 /* An unparsed expression. Used for Scheme (for now at least) */
307 OP_EXPRSTRING
bd5635a1
RP
308};
309
310union exp_element
311{
312 enum exp_opcode opcode;
313 struct symbol *symbol;
314 LONGEST longconst;
315 double doubleconst;
f91a9e05
PB
316 /* Really sizeof (union exp_element) characters (or less for the last
317 element of a string). */
bd5635a1
RP
318 char string;
319 struct type *type;
320 struct internalvar *internalvar;
f91a9e05 321 struct block *block;
bd5635a1
RP
322};
323
324struct expression
325{
35fcebce 326 const struct language_defn *language_defn; /* language it was entered in */
bd5635a1
RP
327 int nelts;
328 union exp_element elts[1];
329};
330
f91a9e05
PB
331/* Macros for converting between number of expression elements and bytes
332 to store that many expression elements. */
333
334#define EXP_ELEM_TO_BYTES(elements) \
335 ((elements) * sizeof (union exp_element))
336#define BYTES_TO_EXP_ELEM(bytes) \
337 (((bytes) + sizeof (union exp_element) - 1) / sizeof (union exp_element))
338
35fcebce
PB
339/* From parse.c */
340
f91a9e05 341extern struct expression *parse_expression PARAMS ((char *));
35fcebce 342
f91a9e05 343extern struct expression *parse_exp_1 PARAMS ((char **, struct block *, int));
bd5635a1
RP
344
345/* The innermost context required by the stack and register variables
346 we've encountered so far. To use this, set it to NULL, then call
35fcebce 347 parse_<whatever>, then look at it. */
bd5635a1
RP
348extern struct block *innermost_block;
349
7398958c
PB
350/* From eval.c */
351
352/* Values of NOSIDE argument to eval_subexp. */
353
354enum noside
355{
356 EVAL_NORMAL,
357 EVAL_SKIP, /* Only effect is to increment pos. */
358 EVAL_AVOID_SIDE_EFFECTS /* Don't modify any variables or
359 call any functions. The value
360 returned will have the correct
361 type, and will have an
362 approximately correct lvalue
363 type (inaccuracy: anything that is
364 listed as being in a register in
365 the function in which it was
366 declared will be lval_register). */
367};
368
369extern struct value* evaluate_subexp_standard
370PARAMS ((struct type *, struct expression *, int*, enum noside));
371
35fcebce
PB
372/* From expprint.c */
373
f91a9e05 374extern void print_expression PARAMS ((struct expression *, GDB_FILE *));
35fcebce 375
f91a9e05 376extern char *op_string PARAMS ((enum exp_opcode));
35fcebce 377
54bbbfb4
FF
378/* To enable dumping of all parsed expressions in a human readable
379 form, define DEBUG_EXPRESSIONS. This is a compile time constant
380 at the moment, since it's not clear that this feature is important
381 enough to include by default. */
382
383#ifdef DEBUG_EXPRESSIONS
f91a9e05 384extern void dump_expression PARAMS ((struct expression *, GDB_FILE *, char *));
54bbbfb4
FF
385#define DUMP_EXPRESSION(exp,file,note) dump_expression ((exp), (file), (note))
386#else
387#define DUMP_EXPRESSION(exp,file,note) /* Null expansion */
388#endif /* DEBUG_EXPRESSIONS */
389
35fcebce 390#endif /* !defined (EXPRESSION_H) */