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