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