]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Evaluate expressions for GDB. |
477b2425 | 2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995 |
2d67c7e9 | 3 | Free Software Foundation, Inc. |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
2ccb3837 | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
2ccb3837 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
2ccb3837 | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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 | |
2ccb3837 | 18 | along with this program; if not, write to the Free Software |
0694bce6 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 RP |
20 | |
21 | #include "defs.h" | |
2b576293 | 22 | #include "gdb_string.h" |
bd5635a1 | 23 | #include "symtab.h" |
01be6913 | 24 | #include "gdbtypes.h" |
bd5635a1 RP |
25 | #include "value.h" |
26 | #include "expression.h" | |
27 | #include "target.h" | |
2ccb3837 | 28 | #include "frame.h" |
40620258 | 29 | #include "demangle.h" |
fb6e675f | 30 | #include "language.h" /* For CAST_IS_CONVERSION */ |
477b2425 | 31 | #include "f-lang.h" /* for array bound stuff */ |
cd10c7e3 | 32 | /* start-sanitize-gm */ |
bfe8f516 FF |
33 | #ifdef GENERAL_MAGIC |
34 | #include "gmagic.h" | |
35 | #endif /* GENERAL_MAGIC */ | |
cd10c7e3 | 36 | /* end-sanitize-gm */ |
bd5635a1 | 37 | |
01be6913 PB |
38 | /* Prototypes for local functions. */ |
39 | ||
2d67c7e9 PB |
40 | static value_ptr evaluate_subexp_for_sizeof PARAMS ((struct expression *, |
41 | int *)); | |
01be6913 | 42 | |
2d67c7e9 PB |
43 | static value_ptr evaluate_subexp_for_address PARAMS ((struct expression *, |
44 | int *, enum noside)); | |
01be6913 | 45 | |
7398958c PB |
46 | #ifdef __GNUC__ |
47 | inline | |
48 | #endif | |
49 | static value_ptr | |
50 | evaluate_subexp (expect_type, exp, pos, noside) | |
51 | struct type *expect_type; | |
52 | register struct expression *exp; | |
53 | register int *pos; | |
54 | enum noside noside; | |
55 | { | |
56 | return (*exp->language_defn->evaluate_exp) (expect_type, exp, pos, noside); | |
57 | } | |
bd5635a1 RP |
58 | \f |
59 | /* Parse the string EXP as a C expression, evaluate it, | |
60 | and return the result as a number. */ | |
61 | ||
62 | CORE_ADDR | |
63 | parse_and_eval_address (exp) | |
64 | char *exp; | |
65 | { | |
2ccb3837 | 66 | struct expression *expr = parse_expression (exp); |
bd5635a1 | 67 | register CORE_ADDR addr; |
01be6913 PB |
68 | register struct cleanup *old_chain = |
69 | make_cleanup (free_current_contents, &expr); | |
bd5635a1 | 70 | |
2ccb3837 | 71 | addr = value_as_pointer (evaluate_expression (expr)); |
bd5635a1 RP |
72 | do_cleanups (old_chain); |
73 | return addr; | |
74 | } | |
75 | ||
76 | /* Like parse_and_eval_address but takes a pointer to a char * variable | |
77 | and advanced that variable across the characters parsed. */ | |
78 | ||
79 | CORE_ADDR | |
80 | parse_and_eval_address_1 (expptr) | |
81 | char **expptr; | |
82 | { | |
2ccb3837 | 83 | struct expression *expr = parse_exp_1 (expptr, (struct block *)0, 0); |
bd5635a1 | 84 | register CORE_ADDR addr; |
01be6913 PB |
85 | register struct cleanup *old_chain = |
86 | make_cleanup (free_current_contents, &expr); | |
bd5635a1 | 87 | |
2ccb3837 | 88 | addr = value_as_pointer (evaluate_expression (expr)); |
bd5635a1 RP |
89 | do_cleanups (old_chain); |
90 | return addr; | |
91 | } | |
92 | ||
2d67c7e9 | 93 | value_ptr |
bd5635a1 RP |
94 | parse_and_eval (exp) |
95 | char *exp; | |
96 | { | |
2ccb3837 | 97 | struct expression *expr = parse_expression (exp); |
2d67c7e9 | 98 | register value_ptr val; |
bd5635a1 RP |
99 | register struct cleanup *old_chain |
100 | = make_cleanup (free_current_contents, &expr); | |
101 | ||
102 | val = evaluate_expression (expr); | |
103 | do_cleanups (old_chain); | |
104 | return val; | |
105 | } | |
106 | ||
107 | /* Parse up to a comma (or to a closeparen) | |
108 | in the string EXPP as an expression, evaluate it, and return the value. | |
109 | EXPP is advanced to point to the comma. */ | |
110 | ||
2d67c7e9 | 111 | value_ptr |
bd5635a1 RP |
112 | parse_to_comma_and_eval (expp) |
113 | char **expp; | |
114 | { | |
2ccb3837 | 115 | struct expression *expr = parse_exp_1 (expp, (struct block *) 0, 1); |
2d67c7e9 | 116 | register value_ptr val; |
bd5635a1 RP |
117 | register struct cleanup *old_chain |
118 | = make_cleanup (free_current_contents, &expr); | |
119 | ||
120 | val = evaluate_expression (expr); | |
121 | do_cleanups (old_chain); | |
122 | return val; | |
123 | } | |
124 | \f | |
125 | /* Evaluate an expression in internal prefix form | |
0a5d35ed | 126 | such as is constructed by parse.y. |
bd5635a1 RP |
127 | |
128 | See expression.h for info on the format of an expression. */ | |
129 | ||
2d67c7e9 | 130 | value_ptr |
bd5635a1 RP |
131 | evaluate_expression (exp) |
132 | struct expression *exp; | |
133 | { | |
134 | int pc = 0; | |
135 | return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL); | |
136 | } | |
137 | ||
138 | /* Evaluate an expression, avoiding all memory references | |
139 | and getting a value whose type alone is correct. */ | |
140 | ||
2d67c7e9 | 141 | value_ptr |
bd5635a1 RP |
142 | evaluate_type (exp) |
143 | struct expression *exp; | |
144 | { | |
145 | int pc = 0; | |
146 | return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS); | |
147 | } | |
148 | ||
0694bce6 SC |
149 | /* If the next expression is an OP_LABELED, skips past it, |
150 | returning the label. Otherwise, does nothing and returns NULL. */ | |
dcda44a0 | 151 | |
0694bce6 SC |
152 | static char* |
153 | get_label (exp, pos) | |
dcda44a0 | 154 | register struct expression *exp; |
0694bce6 | 155 | int *pos; |
dcda44a0 | 156 | { |
dcda44a0 PB |
157 | if (exp->elts[*pos].opcode == OP_LABELED) |
158 | { | |
159 | int pc = (*pos)++; | |
160 | char *name = &exp->elts[pc + 2].string; | |
161 | int tem = longest_to_int (exp->elts[pc + 1].longconst); | |
162 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
0694bce6 | 163 | return name; |
dcda44a0 PB |
164 | } |
165 | else | |
0694bce6 SC |
166 | return NULL; |
167 | } | |
168 | ||
169 | /* This function evaluates tupes (in Chill) or brace-initializers | |
170 | (in C/C++) for structure types. */ | |
171 | ||
172 | static value_ptr | |
173 | evaluate_struct_tuple (struct_val, exp, pos, noside, nargs) | |
174 | value_ptr struct_val; | |
175 | register struct expression *exp; | |
176 | register int *pos; | |
177 | enum noside noside; | |
178 | int nargs; | |
179 | { | |
180 | struct type *struct_type = VALUE_TYPE (struct_val); | |
181 | struct type *substruct_type = struct_type; | |
182 | struct type *field_type; | |
183 | int fieldno = -1; | |
184 | int variantno = -1; | |
185 | int subfieldno = -1; | |
186 | while (--nargs >= 0) | |
dcda44a0 | 187 | { |
0694bce6 SC |
188 | int pc = *pos; |
189 | value_ptr val = NULL; | |
190 | int nlabels = 0; | |
191 | int bitpos, bitsize; | |
192 | char *addr; | |
193 | ||
194 | /* Skip past the labels, and count them. */ | |
195 | while (get_label (exp, pos) != NULL) | |
196 | nlabels++; | |
197 | ||
198 | do | |
199 | { | |
200 | char *label = get_label (exp, &pc); | |
201 | if (label) | |
202 | { | |
203 | for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); | |
204 | fieldno++) | |
205 | { | |
206 | char *field_name = TYPE_FIELD_NAME (struct_type, fieldno); | |
207 | if (field_name != NULL && STREQ (field_name, label)) | |
208 | { | |
209 | variantno = -1; | |
210 | subfieldno = fieldno; | |
211 | substruct_type = struct_type; | |
212 | goto found; | |
213 | } | |
214 | } | |
215 | for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); | |
216 | fieldno++) | |
217 | { | |
218 | char *field_name = TYPE_FIELD_NAME (struct_type, fieldno); | |
219 | field_type = TYPE_FIELD_TYPE (struct_type, fieldno); | |
220 | if ((field_name == 0 || *field_name == '\0') | |
221 | && TYPE_CODE (field_type) == TYPE_CODE_UNION) | |
222 | { | |
223 | variantno = 0; | |
224 | for (; variantno < TYPE_NFIELDS (field_type); | |
225 | variantno++) | |
226 | { | |
227 | substruct_type | |
228 | = TYPE_FIELD_TYPE (field_type, variantno); | |
229 | if (TYPE_CODE (substruct_type) == TYPE_CODE_STRUCT) | |
230 | { | |
231 | for (subfieldno = 0; | |
232 | subfieldno < TYPE_NFIELDS (substruct_type); | |
233 | subfieldno++) | |
234 | { | |
235 | if (STREQ (TYPE_FIELD_NAME (substruct_type, | |
236 | subfieldno), | |
237 | label)) | |
238 | { | |
239 | goto found; | |
240 | } | |
241 | } | |
242 | } | |
243 | } | |
244 | } | |
245 | } | |
246 | error ("there is no field named %s", label); | |
247 | found: | |
248 | ; | |
249 | } | |
250 | else | |
251 | { | |
252 | /* Unlabelled tuple element - go to next field. */ | |
253 | if (variantno >= 0) | |
254 | { | |
255 | subfieldno++; | |
256 | if (subfieldno >= TYPE_NFIELDS (substruct_type)) | |
257 | { | |
258 | variantno = -1; | |
259 | substruct_type = struct_type; | |
260 | } | |
261 | } | |
262 | if (variantno < 0) | |
263 | { | |
264 | fieldno++; | |
265 | subfieldno = fieldno; | |
266 | if (fieldno >= TYPE_NFIELDS (struct_type)) | |
267 | error ("too many initializers"); | |
268 | field_type = TYPE_FIELD_TYPE (struct_type, fieldno); | |
269 | if (TYPE_CODE (field_type) == TYPE_CODE_UNION | |
270 | && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0') | |
271 | error ("don't know which variant you want to set"); | |
272 | } | |
273 | } | |
dcda44a0 | 274 | |
0694bce6 SC |
275 | /* Here, struct_type is the type of the inner struct, |
276 | while substruct_type is the type of the inner struct. | |
277 | These are the same for normal structures, but a variant struct | |
278 | contains anonymous union fields that contain substruct fields. | |
279 | The value fieldno is the index of the top-level (normal or | |
280 | anonymous union) field in struct_field, while the value | |
281 | subfieldno is the index of the actual real (named inner) field | |
282 | in substruct_type. */ | |
283 | ||
284 | field_type = TYPE_FIELD_TYPE (substruct_type, subfieldno); | |
285 | if (val == 0) | |
286 | val = evaluate_subexp (substruct_type, exp, pos, noside); | |
287 | ||
288 | /* Now actually set the field in struct_val. */ | |
289 | ||
290 | /* Assign val to field fieldno. */ | |
291 | if (VALUE_TYPE (val) != field_type) | |
292 | val = value_cast (field_type, val); | |
293 | ||
294 | bitsize = TYPE_FIELD_BITSIZE (substruct_type, subfieldno); | |
295 | bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno); | |
296 | if (variantno >= 0) | |
297 | bitpos += TYPE_FIELD_BITPOS (substruct_type, subfieldno); | |
298 | addr = VALUE_CONTENTS (struct_val) + bitpos / 8; | |
299 | if (bitsize) | |
300 | modify_field (addr, value_as_long (val), | |
301 | bitpos % 8, bitsize); | |
302 | else | |
303 | memcpy (addr, VALUE_CONTENTS (val), | |
304 | TYPE_LENGTH (VALUE_TYPE (val))); | |
305 | } while (--nlabels > 0); | |
306 | } | |
307 | return struct_val; | |
dcda44a0 PB |
308 | } |
309 | ||
7398958c PB |
310 | value_ptr |
311 | evaluate_subexp_standard (expect_type, exp, pos, noside) | |
bd5635a1 RP |
312 | struct type *expect_type; |
313 | register struct expression *exp; | |
314 | register int *pos; | |
315 | enum noside noside; | |
316 | { | |
317 | enum exp_opcode op; | |
1500864f | 318 | int tem, tem2, tem3; |
40620258 | 319 | register int pc, pc2 = 0, oldpos; |
2d67c7e9 | 320 | register value_ptr arg1 = NULL, arg2 = NULL, arg3; |
01be6913 | 321 | struct type *type; |
bd5635a1 | 322 | int nargs; |
2d67c7e9 | 323 | value_ptr *argvec; |
2d67c7e9 PB |
324 | int upper, lower, retcode; |
325 | int code; | |
bd5635a1 | 326 | |
764adcb4 JK |
327 | /* This expect_type crap should not be used for C. C expressions do |
328 | not have any notion of expected types, never has and (goddess | |
329 | willing) never will. The C++ code uses it for some twisted | |
330 | purpose (I haven't investigated but I suspect it just the usual | |
331 | combination of Stroustrup figuring out some crazy language | |
332 | feature and Tiemann figuring out some crazier way to try to | |
333 | implement it). CHILL has the tuple stuff; I don't know enough | |
334 | about CHILL to know whether expected types is the way to do it. | |
335 | FORTRAN I don't know. */ | |
dcda44a0 PB |
336 | if (exp->language_defn->la_language != language_cplus |
337 | && exp->language_defn->la_language != language_chill) | |
22b1c54a JK |
338 | expect_type = NULL_TYPE; |
339 | ||
bd5635a1 RP |
340 | pc = (*pos)++; |
341 | op = exp->elts[pc].opcode; | |
342 | ||
343 | switch (op) | |
344 | { | |
345 | case OP_SCOPE: | |
a8a69e63 | 346 | tem = longest_to_int (exp->elts[pc + 2].longconst); |
1500864f | 347 | (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1); |
01be6913 | 348 | arg1 = value_struct_elt_for_reference (exp->elts[pc + 1].type, |
8f86a4e4 | 349 | 0, |
01be6913 | 350 | exp->elts[pc + 1].type, |
a8a69e63 | 351 | &exp->elts[pc + 3].string, |
01be6913 | 352 | expect_type); |
5f00ca54 | 353 | if (arg1 == NULL) |
a8a69e63 | 354 | error ("There is no field named %s", &exp->elts[pc + 3].string); |
5f00ca54 | 355 | return arg1; |
bd5635a1 RP |
356 | |
357 | case OP_LONG: | |
358 | (*pos) += 3; | |
2ccb3837 | 359 | return value_from_longest (exp->elts[pc + 1].type, |
a8a69e63 | 360 | exp->elts[pc + 2].longconst); |
bd5635a1 RP |
361 | |
362 | case OP_DOUBLE: | |
363 | (*pos) += 3; | |
364 | return value_from_double (exp->elts[pc + 1].type, | |
365 | exp->elts[pc + 2].doubleconst); | |
366 | ||
367 | case OP_VAR_VALUE: | |
479fdd26 | 368 | (*pos) += 3; |
bd5635a1 RP |
369 | if (noside == EVAL_SKIP) |
370 | goto nosideret; | |
371 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
372 | { | |
40620258 | 373 | struct symbol * sym = exp->elts[pc + 2].symbol; |
bd5635a1 RP |
374 | enum lval_type lv; |
375 | ||
376 | switch (SYMBOL_CLASS (sym)) | |
377 | { | |
378 | case LOC_CONST: | |
379 | case LOC_LABEL: | |
380 | case LOC_CONST_BYTES: | |
381 | lv = not_lval; | |
382 | break; | |
383 | ||
384 | case LOC_REGISTER: | |
385 | case LOC_REGPARM: | |
386 | lv = lval_register; | |
387 | break; | |
388 | ||
389 | default: | |
390 | lv = lval_memory; | |
391 | break; | |
392 | } | |
393 | ||
394 | return value_zero (SYMBOL_TYPE (sym), lv); | |
395 | } | |
396 | else | |
479fdd26 JK |
397 | return value_of_variable (exp->elts[pc + 2].symbol, |
398 | exp->elts[pc + 1].block); | |
bd5635a1 RP |
399 | |
400 | case OP_LAST: | |
401 | (*pos) += 2; | |
2ccb3837 JG |
402 | return |
403 | access_value_history (longest_to_int (exp->elts[pc + 1].longconst)); | |
bd5635a1 RP |
404 | |
405 | case OP_REGISTER: | |
406 | (*pos) += 2; | |
2ccb3837 | 407 | return value_of_register (longest_to_int (exp->elts[pc + 1].longconst)); |
bd5635a1 | 408 | |
e58de8a2 FF |
409 | case OP_BOOL: |
410 | (*pos) += 2; | |
2d67c7e9 PB |
411 | if (current_language->la_language == language_fortran) |
412 | return value_from_longest (builtin_type_f_logical_s2, | |
413 | exp->elts[pc + 1].longconst); | |
414 | else | |
415 | return value_from_longest (builtin_type_chill_bool, | |
416 | exp->elts[pc + 1].longconst); | |
e58de8a2 | 417 | |
bd5635a1 RP |
418 | case OP_INTERNALVAR: |
419 | (*pos) += 2; | |
420 | return value_of_internalvar (exp->elts[pc + 1].internalvar); | |
421 | ||
422 | case OP_STRING: | |
a8a69e63 | 423 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
1500864f | 424 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
bd5635a1 RP |
425 | if (noside == EVAL_SKIP) |
426 | goto nosideret; | |
a8a69e63 | 427 | return value_string (&exp->elts[pc + 2].string, tem); |
bd5635a1 | 428 | |
1500864f | 429 | case OP_BITSTRING: |
6d34c236 PB |
430 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
431 | (*pos) | |
432 | += 3 + BYTES_TO_EXP_ELEM ((tem + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT); | |
433 | if (noside == EVAL_SKIP) | |
434 | goto nosideret; | |
435 | return value_bitstring (&exp->elts[pc + 2].string, tem); | |
1500864f JK |
436 | break; |
437 | ||
438 | case OP_ARRAY: | |
439 | (*pos) += 3; | |
440 | tem2 = longest_to_int (exp->elts[pc + 1].longconst); | |
441 | tem3 = longest_to_int (exp->elts[pc + 2].longconst); | |
442 | nargs = tem3 - tem2 + 1; | |
2d67c7e9 PB |
443 | |
444 | if (expect_type != NULL_TYPE && noside != EVAL_SKIP | |
445 | && TYPE_CODE (expect_type) == TYPE_CODE_STRUCT) | |
446 | { | |
447 | value_ptr rec = allocate_value (expect_type); | |
f91a9e05 | 448 | memset (VALUE_CONTENTS_RAW (rec), '\0', TYPE_LENGTH (expect_type)); |
0694bce6 | 449 | return evaluate_struct_tuple (rec, exp, pos, noside, nargs); |
2d67c7e9 PB |
450 | } |
451 | ||
452 | if (expect_type != NULL_TYPE && noside != EVAL_SKIP | |
453 | && TYPE_CODE (expect_type) == TYPE_CODE_ARRAY) | |
454 | { | |
455 | struct type *range_type = TYPE_FIELD_TYPE (expect_type, 0); | |
456 | struct type *element_type = TYPE_TARGET_TYPE (expect_type); | |
457 | LONGEST low_bound = TYPE_FIELD_BITPOS (range_type, 0); | |
458 | LONGEST high_bound = TYPE_FIELD_BITPOS (range_type, 1); | |
459 | int element_size = TYPE_LENGTH (element_type); | |
f91a9e05 | 460 | value_ptr array = allocate_value (expect_type); |
2d67c7e9 PB |
461 | if (nargs != (high_bound - low_bound + 1)) |
462 | error ("wrong number of initialiers for array type"); | |
463 | for (tem = low_bound; tem <= high_bound; tem++) | |
464 | { | |
465 | value_ptr element = evaluate_subexp (element_type, | |
466 | exp, pos, noside); | |
f91a9e05 PB |
467 | if (VALUE_TYPE (element) != element_type) |
468 | element = value_cast (element_type, element); | |
469 | memcpy (VALUE_CONTENTS_RAW (array) | |
2d67c7e9 PB |
470 | + (tem - low_bound) * element_size, |
471 | VALUE_CONTENTS (element), | |
472 | element_size); | |
473 | } | |
f91a9e05 | 474 | return array; |
2d67c7e9 PB |
475 | } |
476 | ||
dcda44a0 PB |
477 | if (expect_type != NULL_TYPE && noside != EVAL_SKIP |
478 | && TYPE_CODE (expect_type) == TYPE_CODE_SET) | |
479 | { | |
480 | value_ptr set = allocate_value (expect_type); | |
481 | struct type *element_type = TYPE_INDEX_TYPE (expect_type); | |
482 | int low_bound = TYPE_LOW_BOUND (element_type); | |
483 | int high_bound = TYPE_HIGH_BOUND (element_type); | |
484 | char *valaddr = VALUE_CONTENTS_RAW (set); | |
f91a9e05 | 485 | memset (valaddr, '\0', TYPE_LENGTH (expect_type)); |
dcda44a0 PB |
486 | for (tem = 0; tem < nargs; tem++) |
487 | { | |
488 | value_ptr element_val = evaluate_subexp (element_type, | |
489 | exp, pos, noside); | |
dcda44a0 PB |
490 | LONGEST element = value_as_long (element_val); |
491 | int bit_index; | |
492 | if (element < low_bound || element > high_bound) | |
493 | error ("POWERSET tuple element out of range"); | |
494 | element -= low_bound; | |
495 | bit_index = (unsigned) element % TARGET_CHAR_BIT; | |
496 | if (BITS_BIG_ENDIAN) | |
497 | bit_index = TARGET_CHAR_BIT - 1 - bit_index; | |
498 | valaddr [(unsigned) element / TARGET_CHAR_BIT] |= 1 << bit_index; | |
499 | } | |
500 | return set; | |
501 | } | |
502 | ||
2d67c7e9 | 503 | argvec = (value_ptr *) alloca (sizeof (value_ptr) * nargs); |
1500864f JK |
504 | for (tem = 0; tem < nargs; tem++) |
505 | { | |
506 | /* Ensure that array expressions are coerced into pointer objects. */ | |
507 | argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside); | |
508 | } | |
509 | if (noside == EVAL_SKIP) | |
510 | goto nosideret; | |
2d67c7e9 | 511 | return value_array (tem2, tem3, argvec); |
1500864f | 512 | |
f91a9e05 PB |
513 | case TERNOP_SLICE: |
514 | { | |
515 | value_ptr array = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
516 | int lowbound | |
517 | = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
518 | int upper | |
519 | = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
520 | return value_slice (array, lowbound, upper - lowbound + 1); | |
521 | } | |
522 | ||
523 | case TERNOP_SLICE_COUNT: | |
524 | { | |
525 | value_ptr array = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
526 | int lowbound | |
527 | = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
528 | int length | |
529 | = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
530 | return value_slice (array, lowbound, length); | |
531 | } | |
532 | ||
bd5635a1 RP |
533 | case TERNOP_COND: |
534 | /* Skip third and second args to evaluate the first one. */ | |
535 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
e58de8a2 | 536 | if (value_logical_not (arg1)) |
bd5635a1 RP |
537 | { |
538 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
539 | return evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
540 | } | |
541 | else | |
542 | { | |
543 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
544 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
545 | return arg2; | |
546 | } | |
547 | ||
548 | case OP_FUNCALL: | |
549 | (*pos) += 2; | |
550 | op = exp->elts[*pos].opcode; | |
551 | if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR) | |
552 | { | |
2d67c7e9 | 553 | LONGEST fnptr; |
bd5635a1 | 554 | |
2ccb3837 | 555 | nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1; |
bd5635a1 RP |
556 | /* First, evaluate the structure into arg2 */ |
557 | pc2 = (*pos)++; | |
558 | ||
559 | if (noside == EVAL_SKIP) | |
560 | goto nosideret; | |
561 | ||
562 | if (op == STRUCTOP_MEMBER) | |
563 | { | |
564 | arg2 = evaluate_subexp_for_address (exp, pos, noside); | |
565 | } | |
566 | else | |
567 | { | |
568 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
569 | } | |
570 | ||
571 | /* If the function is a virtual function, then the | |
572 | aggregate value (providing the structure) plays | |
573 | its part by providing the vtable. Otherwise, | |
574 | it is just along for the ride: call the function | |
575 | directly. */ | |
576 | ||
577 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
578 | ||
2d67c7e9 | 579 | fnptr = value_as_long (arg1); |
35fcebce PB |
580 | |
581 | if (METHOD_PTR_IS_VIRTUAL(fnptr)) | |
bd5635a1 | 582 | { |
35fcebce | 583 | int fnoffset = METHOD_PTR_TO_VOFFSET(fnptr); |
bd5635a1 | 584 | struct type *basetype; |
35fcebce PB |
585 | struct type *domain_type = |
586 | TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))); | |
bd5635a1 RP |
587 | int i, j; |
588 | basetype = TYPE_TARGET_TYPE (VALUE_TYPE (arg2)); | |
35fcebce PB |
589 | if (domain_type != basetype) |
590 | arg2 = value_cast(lookup_pointer_type (domain_type), arg2); | |
591 | basetype = TYPE_VPTR_BASETYPE (domain_type); | |
bd5635a1 RP |
592 | for (i = TYPE_NFN_FIELDS (basetype) - 1; i >= 0; i--) |
593 | { | |
594 | struct fn_field *f = TYPE_FN_FIELDLIST1 (basetype, i); | |
595 | /* If one is virtual, then all are virtual. */ | |
596 | if (TYPE_FN_FIELD_VIRTUAL_P (f, 0)) | |
597 | for (j = TYPE_FN_FIELDLIST_LENGTH (basetype, i) - 1; j >= 0; --j) | |
35fcebce | 598 | if (TYPE_FN_FIELD_VOFFSET (f, j) == fnoffset) |
bd5635a1 | 599 | { |
2d67c7e9 | 600 | value_ptr temp = value_ind (arg2); |
35fcebce PB |
601 | arg1 = value_virtual_fn_field (&temp, f, j, domain_type, 0); |
602 | arg2 = value_addr (temp); | |
bd5635a1 RP |
603 | goto got_it; |
604 | } | |
605 | } | |
606 | if (i < 0) | |
35fcebce | 607 | error ("virtual function at index %d not found", fnoffset); |
bd5635a1 RP |
608 | } |
609 | else | |
610 | { | |
611 | VALUE_TYPE (arg1) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))); | |
612 | } | |
613 | got_it: | |
614 | ||
615 | /* Now, say which argument to start evaluating from */ | |
616 | tem = 2; | |
617 | } | |
618 | else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR) | |
619 | { | |
620 | /* Hair for method invocations */ | |
621 | int tem2; | |
622 | ||
2ccb3837 | 623 | nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1; |
bd5635a1 RP |
624 | /* First, evaluate the structure into arg2 */ |
625 | pc2 = (*pos)++; | |
a8a69e63 | 626 | tem2 = longest_to_int (exp->elts[pc2 + 1].longconst); |
1500864f | 627 | *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1); |
bd5635a1 RP |
628 | if (noside == EVAL_SKIP) |
629 | goto nosideret; | |
630 | ||
631 | if (op == STRUCTOP_STRUCT) | |
632 | { | |
479fdd26 JK |
633 | /* If v is a variable in a register, and the user types |
634 | v.method (), this will produce an error, because v has | |
635 | no address. | |
636 | ||
637 | A possible way around this would be to allocate a | |
638 | copy of the variable on the stack, copy in the | |
639 | contents, call the function, and copy out the | |
640 | contents. I.e. convert this from call by reference | |
641 | to call by copy-return (or whatever it's called). | |
642 | However, this does not work because it is not the | |
643 | same: the method being called could stash a copy of | |
644 | the address, and then future uses through that address | |
645 | (after the method returns) would be expected to | |
646 | use the variable itself, not some copy of it. */ | |
bd5635a1 RP |
647 | arg2 = evaluate_subexp_for_address (exp, pos, noside); |
648 | } | |
649 | else | |
650 | { | |
651 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
652 | } | |
653 | /* Now, say which argument to start evaluating from */ | |
654 | tem = 2; | |
655 | } | |
656 | else | |
657 | { | |
2ccb3837 | 658 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
bd5635a1 RP |
659 | tem = 0; |
660 | } | |
1500864f JK |
661 | /* Allocate arg vector, including space for the function to be |
662 | called in argvec[0] and a terminating NULL */ | |
2d67c7e9 | 663 | argvec = (value_ptr *) alloca (sizeof (value_ptr) * (nargs + 2)); |
bd5635a1 RP |
664 | for (; tem <= nargs; tem++) |
665 | /* Ensure that array expressions are coerced into pointer objects. */ | |
666 | argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside); | |
667 | ||
668 | /* signal end of arglist */ | |
669 | argvec[tem] = 0; | |
670 | ||
671 | if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR) | |
672 | { | |
673 | int static_memfuncp; | |
2d67c7e9 PB |
674 | value_ptr temp = arg2; |
675 | char tstr[64]; | |
bd5635a1 RP |
676 | |
677 | argvec[1] = arg2; | |
40620258 KH |
678 | argvec[0] = 0; |
679 | strcpy(tstr, &exp->elts[pc2+2].string); | |
40620258 | 680 | if (!argvec[0]) |
bd5635a1 | 681 | { |
40620258 KH |
682 | temp = arg2; |
683 | argvec[0] = | |
684 | value_struct_elt (&temp, argvec+1, tstr, | |
685 | &static_memfuncp, | |
686 | op == STRUCTOP_STRUCT | |
687 | ? "structure" : "structure pointer"); | |
bd5635a1 | 688 | } |
40620258 KH |
689 | arg2 = value_from_longest (lookup_pointer_type(VALUE_TYPE (temp)), |
690 | VALUE_ADDRESS (temp)+VALUE_OFFSET (temp)); | |
691 | argvec[1] = arg2; | |
692 | ||
bd5635a1 RP |
693 | if (static_memfuncp) |
694 | { | |
695 | argvec[1] = argvec[0]; | |
696 | nargs--; | |
697 | argvec++; | |
698 | } | |
699 | } | |
700 | else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR) | |
701 | { | |
702 | argvec[1] = arg2; | |
703 | argvec[0] = arg1; | |
704 | } | |
705 | ||
ead95f8a PB |
706 | do_call_it: |
707 | ||
bd5635a1 RP |
708 | if (noside == EVAL_SKIP) |
709 | goto nosideret; | |
710 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
711 | { | |
712 | /* If the return type doesn't look like a function type, call an | |
713 | error. This can happen if somebody tries to turn a variable into | |
714 | a function call. This is here because people often want to | |
715 | call, eg, strcmp, which gdb doesn't know is a function. If | |
716 | gdb isn't asked for it's opinion (ie. through "whatis"), | |
717 | it won't offer it. */ | |
718 | ||
719 | struct type *ftype = | |
720 | TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0])); | |
721 | ||
722 | if (ftype) | |
723 | return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0]))); | |
724 | else | |
725 | error ("Expression of type other than \"Function returning ...\" used as function"); | |
726 | } | |
e17960fb | 727 | return call_function_by_hand (argvec[0], nargs, argvec + 1); |
bd5635a1 | 728 | |
2d67c7e9 PB |
729 | case OP_F77_UNDETERMINED_ARGLIST: |
730 | ||
2d67c7e9 PB |
731 | /* Remember that in F77, functions, substring ops and |
732 | array subscript operations cannot be disambiguated | |
733 | at parse time. We have made all array subscript operations, | |
734 | substring operations as well as function calls come here | |
735 | and we now have to discover what the heck this thing actually was. | |
7398958c | 736 | If it is a function, we process just as if we got an OP_FUNCALL. */ |
2d67c7e9 | 737 | |
ead95f8a PB |
738 | nargs = longest_to_int (exp->elts[pc+1].longconst); |
739 | (*pos) += 2; | |
2d67c7e9 PB |
740 | |
741 | /* First determine the type code we are dealing with. */ | |
ead95f8a PB |
742 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
743 | code = TYPE_CODE (VALUE_TYPE (arg1)); | |
2d67c7e9 PB |
744 | |
745 | switch (code) | |
746 | { | |
ead95f8a PB |
747 | case TYPE_CODE_ARRAY: |
748 | goto multi_f77_subscript; | |
749 | ||
2d67c7e9 | 750 | case TYPE_CODE_STRING: |
ead95f8a | 751 | goto op_f77_substr; |
2d67c7e9 PB |
752 | |
753 | case TYPE_CODE_PTR: | |
754 | case TYPE_CODE_FUNC: | |
ead95f8a PB |
755 | /* It's a function call. */ |
756 | /* Allocate arg vector, including space for the function to be | |
757 | called in argvec[0] and a terminating NULL */ | |
758 | argvec = (value_ptr *) alloca (sizeof (value_ptr) * (nargs + 2)); | |
759 | argvec[0] = arg1; | |
760 | tem = 1; | |
761 | for (; tem <= nargs; tem++) | |
762 | argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside); | |
763 | argvec[tem] = 0; /* signal end of arglist */ | |
764 | goto do_call_it; | |
2d67c7e9 PB |
765 | |
766 | default: | |
767 | error ("Cannot perform substring on this type"); | |
768 | } | |
769 | ||
ead95f8a | 770 | op_f77_substr: |
2d67c7e9 PB |
771 | /* We have a substring operation on our hands here, |
772 | let us get the string we will be dealing with */ | |
773 | ||
2d67c7e9 PB |
774 | /* Now evaluate the 'from' and 'to' */ |
775 | ||
776 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
777 | ||
778 | if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT) | |
779 | error ("Substring arguments must be of type integer"); | |
780 | ||
ead95f8a PB |
781 | if (nargs < 2) |
782 | return value_subscript (arg1, arg2); | |
783 | ||
2d67c7e9 PB |
784 | arg3 = evaluate_subexp_with_coercion (exp, pos, noside); |
785 | ||
786 | if (TYPE_CODE (VALUE_TYPE (arg3)) != TYPE_CODE_INT) | |
787 | error ("Substring arguments must be of type integer"); | |
788 | ||
789 | tem2 = *((int *) VALUE_CONTENTS_RAW (arg2)); | |
790 | tem3 = *((int *) VALUE_CONTENTS_RAW (arg3)); | |
791 | ||
792 | if ((tem2 < 1) || (tem2 > tem3)) | |
793 | error ("Bad 'from' value %d on substring operation", tem2); | |
794 | ||
795 | if ((tem3 < tem2) || (tem3 > (TYPE_LENGTH (VALUE_TYPE (arg1))))) | |
796 | error ("Bad 'to' value %d on substring operation", tem3); | |
797 | ||
798 | if (noside == EVAL_SKIP) | |
799 | goto nosideret; | |
800 | ||
ead95f8a | 801 | return value_slice (arg1, tem2, tem3 - tem2 + 1); |
2d67c7e9 | 802 | |
ead95f8a | 803 | case OP_COMPLEX: |
2d67c7e9 PB |
804 | /* We have a complex number, There should be 2 floating |
805 | point numbers that compose it */ | |
806 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
807 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
808 | ||
ead95f8a | 809 | return value_literal_complex (arg1, arg2, builtin_type_f_complex_s16); |
2d67c7e9 | 810 | |
bd5635a1 | 811 | case STRUCTOP_STRUCT: |
a8a69e63 | 812 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
1500864f | 813 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
bd5635a1 RP |
814 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
815 | if (noside == EVAL_SKIP) | |
816 | goto nosideret; | |
817 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
818 | return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1), | |
a8a69e63 | 819 | &exp->elts[pc + 2].string, |
35fcebce | 820 | 0), |
bd5635a1 RP |
821 | lval_memory); |
822 | else | |
823 | { | |
2d67c7e9 PB |
824 | value_ptr temp = arg1; |
825 | return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string, | |
826 | NULL, "structure"); | |
bd5635a1 RP |
827 | } |
828 | ||
829 | case STRUCTOP_PTR: | |
a8a69e63 | 830 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
1500864f | 831 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
bd5635a1 RP |
832 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
833 | if (noside == EVAL_SKIP) | |
834 | goto nosideret; | |
835 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
1500864f | 836 | return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1), |
a8a69e63 | 837 | &exp->elts[pc + 2].string, |
35fcebce | 838 | 0), |
bd5635a1 RP |
839 | lval_memory); |
840 | else | |
841 | { | |
2d67c7e9 PB |
842 | value_ptr temp = arg1; |
843 | return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string, | |
844 | NULL, "structure pointer"); | |
bd5635a1 RP |
845 | } |
846 | ||
cd10c7e3 | 847 | /* start-sanitize-gm */ |
bfe8f516 | 848 | #ifdef GENERAL_MAGIC |
cd10c7e3 SG |
849 | case STRUCTOP_FIELD: |
850 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
851 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
852 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
853 | if (noside == EVAL_SKIP) | |
854 | goto nosideret; | |
855 | { | |
856 | CORE_ADDR object = value_as_long (arg1); | |
857 | struct type *type = type_of_object (object); | |
858 | ||
859 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
860 | return value_zero (lookup_struct_elt_type (type, | |
861 | &exp->elts[pc + 2].string, | |
862 | 0), | |
863 | lval_memory); | |
864 | else | |
865 | { | |
866 | value_ptr temp = value_from_longest (builtin_type_unsigned_long, | |
867 | baseptr_of_object (value_as_long(arg1))); | |
868 | ||
869 | VALUE_TYPE (temp) = type; | |
870 | return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string, | |
871 | NULL, "structure pointer"); | |
872 | } | |
873 | } | |
bfe8f516 | 874 | #endif /* GENERAL_MAGIC */ |
cd10c7e3 SG |
875 | /* end-sanitize-gm */ |
876 | ||
bd5635a1 RP |
877 | case STRUCTOP_MEMBER: |
878 | arg1 = evaluate_subexp_for_address (exp, pos, noside); | |
01be6913 | 879 | goto handle_pointer_to_member; |
bd5635a1 RP |
880 | case STRUCTOP_MPTR: |
881 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
01be6913 | 882 | handle_pointer_to_member: |
bd5635a1 RP |
883 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
884 | if (noside == EVAL_SKIP) | |
885 | goto nosideret; | |
01be6913 PB |
886 | if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_PTR) |
887 | goto bad_pointer_to_member; | |
888 | type = TYPE_TARGET_TYPE (VALUE_TYPE (arg2)); | |
889 | if (TYPE_CODE (type) == TYPE_CODE_METHOD) | |
890 | error ("not implemented: pointer-to-method in pointer-to-member construct"); | |
891 | if (TYPE_CODE (type) != TYPE_CODE_MEMBER) | |
892 | goto bad_pointer_to_member; | |
bd5635a1 | 893 | /* Now, convert these values to an address. */ |
01be6913 PB |
894 | arg1 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)), |
895 | arg1); | |
896 | arg3 = value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type)), | |
897 | value_as_long (arg1) + value_as_long (arg2)); | |
bd5635a1 | 898 | return value_ind (arg3); |
01be6913 PB |
899 | bad_pointer_to_member: |
900 | error("non-pointer-to-member value used in pointer-to-member construct"); | |
bd5635a1 | 901 | |
1500864f JK |
902 | case BINOP_CONCAT: |
903 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
904 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
905 | if (noside == EVAL_SKIP) | |
906 | goto nosideret; | |
907 | if (binop_user_defined_p (op, arg1, arg2)) | |
908 | return value_x_binop (arg1, arg2, op, OP_NULL); | |
909 | else | |
910 | return value_concat (arg1, arg2); | |
911 | ||
bd5635a1 RP |
912 | case BINOP_ASSIGN: |
913 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
914 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
915 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
916 | return arg1; | |
917 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 918 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
919 | else |
920 | return value_assign (arg1, arg2); | |
921 | ||
922 | case BINOP_ASSIGN_MODIFY: | |
923 | (*pos) += 2; | |
924 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
925 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
926 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
927 | return arg1; | |
928 | op = exp->elts[pc + 1].opcode; | |
929 | if (binop_user_defined_p (op, arg1, arg2)) | |
930 | return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op); | |
931 | else if (op == BINOP_ADD) | |
932 | arg2 = value_add (arg1, arg2); | |
933 | else if (op == BINOP_SUB) | |
934 | arg2 = value_sub (arg1, arg2); | |
935 | else | |
936 | arg2 = value_binop (arg1, arg2, op); | |
937 | return value_assign (arg1, arg2); | |
938 | ||
939 | case BINOP_ADD: | |
940 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
941 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
942 | if (noside == EVAL_SKIP) | |
943 | goto nosideret; | |
944 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 945 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
946 | else |
947 | return value_add (arg1, arg2); | |
948 | ||
949 | case BINOP_SUB: | |
950 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
951 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
952 | if (noside == EVAL_SKIP) | |
953 | goto nosideret; | |
954 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 955 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
956 | else |
957 | return value_sub (arg1, arg2); | |
958 | ||
959 | case BINOP_MUL: | |
960 | case BINOP_DIV: | |
961 | case BINOP_REM: | |
76a0ffb4 | 962 | case BINOP_MOD: |
bd5635a1 RP |
963 | case BINOP_LSH: |
964 | case BINOP_RSH: | |
e58de8a2 FF |
965 | case BINOP_BITWISE_AND: |
966 | case BINOP_BITWISE_IOR: | |
967 | case BINOP_BITWISE_XOR: | |
bd5635a1 RP |
968 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
969 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
970 | if (noside == EVAL_SKIP) | |
971 | goto nosideret; | |
972 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 973 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
974 | else |
975 | if (noside == EVAL_AVOID_SIDE_EFFECTS | |
76a0ffb4 | 976 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) |
bd5635a1 RP |
977 | return value_zero (VALUE_TYPE (arg1), not_lval); |
978 | else | |
979 | return value_binop (arg1, arg2, op); | |
980 | ||
badefd28 PB |
981 | case BINOP_RANGE: |
982 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
983 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
984 | if (noside == EVAL_SKIP) | |
985 | goto nosideret; | |
986 | error ("':' operator used in invalid context"); | |
987 | ||
bd5635a1 RP |
988 | case BINOP_SUBSCRIPT: |
989 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
990 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
991 | if (noside == EVAL_SKIP) | |
992 | goto nosideret; | |
993 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
35fcebce PB |
994 | { |
995 | /* If the user attempts to subscript something that has no target | |
996 | type (like a plain int variable for example), then report this | |
997 | as an error. */ | |
998 | ||
999 | type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1)); | |
1000 | if (type) | |
1001 | return value_zero (type, VALUE_LVAL (arg1)); | |
1002 | else | |
1003 | error ("cannot subscript something of type `%s'", | |
1004 | TYPE_NAME (VALUE_TYPE (arg1))); | |
1005 | } | |
bd5635a1 RP |
1006 | |
1007 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 1008 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1009 | else |
1010 | return value_subscript (arg1, arg2); | |
2d67c7e9 PB |
1011 | |
1012 | case BINOP_IN: | |
1013 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
1014 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
1015 | if (noside == EVAL_SKIP) | |
1016 | goto nosideret; | |
1017 | return value_in (arg1, arg2); | |
bd5635a1 | 1018 | |
54bbbfb4 FF |
1019 | case MULTI_SUBSCRIPT: |
1020 | (*pos) += 2; | |
1021 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
1022 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
1023 | while (nargs-- > 0) | |
1024 | { | |
1025 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
1026 | /* FIXME: EVAL_SKIP handling may not be correct. */ | |
1027 | if (noside == EVAL_SKIP) | |
1028 | { | |
1029 | if (nargs > 0) | |
1030 | { | |
1031 | continue; | |
1032 | } | |
1033 | else | |
1034 | { | |
1035 | goto nosideret; | |
1036 | } | |
1037 | } | |
1038 | /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */ | |
1039 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
1040 | { | |
1041 | /* If the user attempts to subscript something that has no target | |
1042 | type (like a plain int variable for example), then report this | |
1043 | as an error. */ | |
1044 | ||
1045 | type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1)); | |
1046 | if (type != NULL) | |
1047 | { | |
1048 | arg1 = value_zero (type, VALUE_LVAL (arg1)); | |
1049 | noside = EVAL_SKIP; | |
1050 | continue; | |
1051 | } | |
1052 | else | |
1053 | { | |
1054 | error ("cannot subscript something of type `%s'", | |
1055 | TYPE_NAME (VALUE_TYPE (arg1))); | |
1056 | } | |
1057 | } | |
1058 | ||
7398958c | 1059 | if (binop_user_defined_p (op, arg1, arg2)) |
54bbbfb4 FF |
1060 | { |
1061 | arg1 = value_x_binop (arg1, arg2, op, OP_NULL); | |
1062 | } | |
1063 | else | |
1064 | { | |
1065 | arg1 = value_subscript (arg1, arg2); | |
1066 | } | |
1067 | } | |
1068 | return (arg1); | |
1069 | ||
ead95f8a | 1070 | multi_f77_subscript: |
2d67c7e9 PB |
1071 | { |
1072 | int subscript_array[MAX_FORTRAN_DIMS+1]; /* 1-based array of | |
1073 | subscripts, max == 7 */ | |
1074 | int array_size_array[MAX_FORTRAN_DIMS+1]; | |
1075 | int ndimensions=1,i; | |
1076 | struct type *tmp_type; | |
1077 | int offset_item; /* The array offset where the item lives */ | |
2d67c7e9 | 1078 | |
2d67c7e9 PB |
1079 | if (nargs > MAX_FORTRAN_DIMS) |
1080 | error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS); | |
2d67c7e9 PB |
1081 | |
1082 | ndimensions = calc_f77_array_dims (VALUE_TYPE (arg1)); | |
1083 | ||
1084 | if (nargs != ndimensions) | |
1085 | error ("Wrong number of subscripts"); | |
1086 | ||
1087 | /* Now that we know we have a legal array subscript expression | |
1088 | let us actually find out where this element exists in the array. */ | |
1089 | ||
1090 | tmp_type = VALUE_TYPE (arg1); | |
1091 | offset_item = 0; | |
1092 | for (i = 1; i <= nargs; i++) | |
1093 | { | |
1094 | /* Evaluate each subscript, It must be a legal integer in F77 */ | |
1095 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
1096 | ||
2d67c7e9 PB |
1097 | /* Fill in the subscript and array size arrays */ |
1098 | ||
badefd28 | 1099 | subscript_array[i] = value_as_long (arg2); |
2d67c7e9 PB |
1100 | |
1101 | retcode = f77_get_dynamic_upperbound (tmp_type, &upper); | |
1102 | if (retcode == BOUND_FETCH_ERROR) | |
1103 | error ("Cannot obtain dynamic upper bound"); | |
1104 | ||
1105 | retcode = f77_get_dynamic_lowerbound (tmp_type, &lower); | |
1106 | if (retcode == BOUND_FETCH_ERROR) | |
1107 | error("Cannot obtain dynamic lower bound"); | |
1108 | ||
1109 | array_size_array[i] = upper - lower + 1; | |
1110 | ||
1111 | /* Zero-normalize subscripts so that offsetting will work. */ | |
1112 | ||
1113 | subscript_array[i] -= lower; | |
1114 | ||
1115 | /* If we are at the bottom of a multidimensional | |
1116 | array type then keep a ptr to the last ARRAY | |
1117 | type around for use when calling value_subscript() | |
1118 | below. This is done because we pretend to value_subscript | |
1119 | that we actually have a one-dimensional array | |
1120 | of base element type that we apply a simple | |
1121 | offset to. */ | |
1122 | ||
1123 | if (i < nargs) | |
1124 | tmp_type = TYPE_TARGET_TYPE (tmp_type); | |
1125 | } | |
1126 | ||
1127 | /* Now let us calculate the offset for this item */ | |
1128 | ||
1129 | offset_item = subscript_array[ndimensions]; | |
1130 | ||
1131 | for (i = ndimensions - 1; i >= 1; i--) | |
1132 | offset_item = | |
1133 | array_size_array[i] * offset_item + subscript_array[i]; | |
1134 | ||
1135 | /* Construct a value node with the value of the offset */ | |
1136 | ||
1137 | arg2 = value_from_longest (builtin_type_f_integer, offset_item); | |
1138 | ||
1139 | /* Let us now play a dirty trick: we will take arg1 | |
1140 | which is a value node pointing to the topmost level | |
1141 | of the multidimensional array-set and pretend | |
1142 | that it is actually a array of the final element | |
1143 | type, this will ensure that value_subscript() | |
1144 | returns the correct type value */ | |
1145 | ||
1146 | VALUE_TYPE (arg1) = tmp_type; | |
7398958c | 1147 | return value_ind (value_add (value_coerce_array (arg1), arg2)); |
2d67c7e9 PB |
1148 | } |
1149 | ||
e58de8a2 | 1150 | case BINOP_LOGICAL_AND: |
bd5635a1 RP |
1151 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
1152 | if (noside == EVAL_SKIP) | |
1153 | { | |
1154 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1155 | goto nosideret; | |
1156 | } | |
1157 | ||
1158 | oldpos = *pos; | |
1159 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
1160 | *pos = oldpos; | |
1161 | ||
1162 | if (binop_user_defined_p (op, arg1, arg2)) | |
1163 | { | |
1164 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
2ccb3837 | 1165 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1166 | } |
1167 | else | |
1168 | { | |
e58de8a2 | 1169 | tem = value_logical_not (arg1); |
bd5635a1 RP |
1170 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, |
1171 | (tem ? EVAL_SKIP : noside)); | |
2ccb3837 | 1172 | return value_from_longest (builtin_type_int, |
e58de8a2 | 1173 | (LONGEST) (!tem && !value_logical_not (arg2))); |
bd5635a1 RP |
1174 | } |
1175 | ||
e58de8a2 | 1176 | case BINOP_LOGICAL_OR: |
bd5635a1 RP |
1177 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
1178 | if (noside == EVAL_SKIP) | |
1179 | { | |
1180 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1181 | goto nosideret; | |
1182 | } | |
1183 | ||
1184 | oldpos = *pos; | |
1185 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
1186 | *pos = oldpos; | |
1187 | ||
1188 | if (binop_user_defined_p (op, arg1, arg2)) | |
1189 | { | |
1190 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
2ccb3837 | 1191 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1192 | } |
1193 | else | |
1194 | { | |
e58de8a2 | 1195 | tem = value_logical_not (arg1); |
bd5635a1 RP |
1196 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, |
1197 | (!tem ? EVAL_SKIP : noside)); | |
2ccb3837 | 1198 | return value_from_longest (builtin_type_int, |
e58de8a2 | 1199 | (LONGEST) (!tem || !value_logical_not (arg2))); |
bd5635a1 RP |
1200 | } |
1201 | ||
1202 | case BINOP_EQUAL: | |
1203 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1204 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1205 | if (noside == EVAL_SKIP) | |
1206 | goto nosideret; | |
1207 | if (binop_user_defined_p (op, arg1, arg2)) | |
1208 | { | |
2ccb3837 | 1209 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1210 | } |
1211 | else | |
1212 | { | |
1213 | tem = value_equal (arg1, arg2); | |
2ccb3837 | 1214 | return value_from_longest (builtin_type_int, (LONGEST) tem); |
bd5635a1 RP |
1215 | } |
1216 | ||
1217 | case BINOP_NOTEQUAL: | |
1218 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1219 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1220 | if (noside == EVAL_SKIP) | |
1221 | goto nosideret; | |
1222 | if (binop_user_defined_p (op, arg1, arg2)) | |
1223 | { | |
2ccb3837 | 1224 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1225 | } |
1226 | else | |
1227 | { | |
1228 | tem = value_equal (arg1, arg2); | |
2ccb3837 | 1229 | return value_from_longest (builtin_type_int, (LONGEST) ! tem); |
bd5635a1 RP |
1230 | } |
1231 | ||
1232 | case BINOP_LESS: | |
1233 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1234 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1235 | if (noside == EVAL_SKIP) | |
1236 | goto nosideret; | |
1237 | if (binop_user_defined_p (op, arg1, arg2)) | |
1238 | { | |
2ccb3837 | 1239 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1240 | } |
1241 | else | |
1242 | { | |
1243 | tem = value_less (arg1, arg2); | |
2ccb3837 | 1244 | return value_from_longest (builtin_type_int, (LONGEST) tem); |
bd5635a1 RP |
1245 | } |
1246 | ||
1247 | case BINOP_GTR: | |
1248 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1249 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1250 | if (noside == EVAL_SKIP) | |
1251 | goto nosideret; | |
1252 | if (binop_user_defined_p (op, arg1, arg2)) | |
1253 | { | |
2ccb3837 | 1254 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1255 | } |
1256 | else | |
1257 | { | |
1258 | tem = value_less (arg2, arg1); | |
2ccb3837 | 1259 | return value_from_longest (builtin_type_int, (LONGEST) tem); |
bd5635a1 RP |
1260 | } |
1261 | ||
1262 | case BINOP_GEQ: | |
1263 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1264 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1265 | if (noside == EVAL_SKIP) | |
1266 | goto nosideret; | |
1267 | if (binop_user_defined_p (op, arg1, arg2)) | |
1268 | { | |
2ccb3837 | 1269 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1270 | } |
1271 | else | |
1272 | { | |
8f86a4e4 JG |
1273 | tem = value_less (arg2, arg1) || value_equal (arg1, arg2); |
1274 | return value_from_longest (builtin_type_int, (LONGEST) tem); | |
bd5635a1 RP |
1275 | } |
1276 | ||
1277 | case BINOP_LEQ: | |
1278 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1279 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1280 | if (noside == EVAL_SKIP) | |
1281 | goto nosideret; | |
1282 | if (binop_user_defined_p (op, arg1, arg2)) | |
1283 | { | |
2ccb3837 | 1284 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1285 | } |
1286 | else | |
1287 | { | |
8f86a4e4 JG |
1288 | tem = value_less (arg1, arg2) || value_equal (arg1, arg2); |
1289 | return value_from_longest (builtin_type_int, (LONGEST) tem); | |
bd5635a1 RP |
1290 | } |
1291 | ||
1292 | case BINOP_REPEAT: | |
1293 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1294 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1295 | if (noside == EVAL_SKIP) | |
1296 | goto nosideret; | |
1297 | if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT) | |
1298 | error ("Non-integral right operand for \"@\" operator."); | |
1299 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
2b576293 | 1300 | { |
2b576293 C |
1301 | return allocate_repeat_value (VALUE_TYPE (arg1), |
1302 | longest_to_int (value_as_long (arg2))); | |
1303 | } | |
bd5635a1 | 1304 | else |
2ccb3837 | 1305 | return value_repeat (arg1, longest_to_int (value_as_long (arg2))); |
bd5635a1 RP |
1306 | |
1307 | case BINOP_COMMA: | |
1308 | evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1309 | return evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1310 | ||
1311 | case UNOP_NEG: | |
1312 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1313 | if (noside == EVAL_SKIP) | |
1314 | goto nosideret; | |
1315 | if (unop_user_defined_p (op, arg1)) | |
1316 | return value_x_unop (arg1, op); | |
1317 | else | |
1318 | return value_neg (arg1); | |
1319 | ||
e58de8a2 | 1320 | case UNOP_COMPLEMENT: |
5f00ca54 JK |
1321 | /* C++: check for and handle destructor names. */ |
1322 | op = exp->elts[*pos].opcode; | |
1323 | ||
bd5635a1 RP |
1324 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
1325 | if (noside == EVAL_SKIP) | |
1326 | goto nosideret; | |
e58de8a2 FF |
1327 | if (unop_user_defined_p (UNOP_COMPLEMENT, arg1)) |
1328 | return value_x_unop (arg1, UNOP_COMPLEMENT); | |
bd5635a1 | 1329 | else |
e58de8a2 | 1330 | return value_complement (arg1); |
bd5635a1 | 1331 | |
e58de8a2 | 1332 | case UNOP_LOGICAL_NOT: |
bd5635a1 RP |
1333 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
1334 | if (noside == EVAL_SKIP) | |
1335 | goto nosideret; | |
1336 | if (unop_user_defined_p (op, arg1)) | |
1337 | return value_x_unop (arg1, op); | |
1338 | else | |
2ccb3837 | 1339 | return value_from_longest (builtin_type_int, |
e58de8a2 | 1340 | (LONGEST) value_logical_not (arg1)); |
bd5635a1 RP |
1341 | |
1342 | case UNOP_IND: | |
1343 | if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR) | |
1344 | expect_type = TYPE_TARGET_TYPE (expect_type); | |
1345 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1346 | if (noside == EVAL_SKIP) | |
1347 | goto nosideret; | |
1348 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
1349 | { | |
1350 | if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR | |
1351 | || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF | |
1352 | /* In C you can dereference an array to get the 1st elt. */ | |
1353 | || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY | |
1354 | ) | |
1355 | return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)), | |
1356 | lval_memory); | |
1357 | else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT) | |
1358 | /* GDB allows dereferencing an int. */ | |
1359 | return value_zero (builtin_type_int, lval_memory); | |
1360 | else | |
1361 | error ("Attempt to take contents of a non-pointer value."); | |
1362 | } | |
1363 | return value_ind (arg1); | |
1364 | ||
1365 | case UNOP_ADDR: | |
1366 | /* C++: check for and handle pointer to members. */ | |
1367 | ||
1368 | op = exp->elts[*pos].opcode; | |
1369 | ||
1370 | if (noside == EVAL_SKIP) | |
1371 | { | |
1372 | if (op == OP_SCOPE) | |
1373 | { | |
a8a69e63 | 1374 | int temm = longest_to_int (exp->elts[pc+3].longconst); |
1500864f | 1375 | (*pos) += 3 + BYTES_TO_EXP_ELEM (temm + 1); |
bd5635a1 RP |
1376 | } |
1377 | else | |
1378 | evaluate_subexp (expect_type, exp, pos, EVAL_SKIP); | |
1379 | goto nosideret; | |
1380 | } | |
1381 | ||
01be6913 | 1382 | return evaluate_subexp_for_address (exp, pos, noside); |
bd5635a1 RP |
1383 | |
1384 | case UNOP_SIZEOF: | |
1385 | if (noside == EVAL_SKIP) | |
1386 | { | |
1387 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
1388 | goto nosideret; | |
1389 | } | |
1390 | return evaluate_subexp_for_sizeof (exp, pos); | |
1391 | ||
1392 | case UNOP_CAST: | |
1393 | (*pos) += 2; | |
2d67c7e9 PB |
1394 | type = exp->elts[pc + 1].type; |
1395 | arg1 = evaluate_subexp (type, exp, pos, noside); | |
bd5635a1 RP |
1396 | if (noside == EVAL_SKIP) |
1397 | goto nosideret; | |
2d67c7e9 PB |
1398 | if (type != VALUE_TYPE (arg1)) |
1399 | arg1 = value_cast (type, arg1); | |
1400 | return arg1; | |
bd5635a1 RP |
1401 | |
1402 | case UNOP_MEMVAL: | |
1403 | (*pos) += 2; | |
1404 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1405 | if (noside == EVAL_SKIP) | |
1406 | goto nosideret; | |
1407 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
1408 | return value_zero (exp->elts[pc + 1].type, lval_memory); | |
1409 | else | |
1410 | return value_at_lazy (exp->elts[pc + 1].type, | |
2ccb3837 | 1411 | value_as_pointer (arg1)); |
bd5635a1 RP |
1412 | |
1413 | case UNOP_PREINCREMENT: | |
1414 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1415 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
1416 | return arg1; | |
1417 | else if (unop_user_defined_p (op, arg1)) | |
1418 | { | |
1419 | return value_x_unop (arg1, op); | |
1420 | } | |
1421 | else | |
1422 | { | |
2ccb3837 | 1423 | arg2 = value_add (arg1, value_from_longest (builtin_type_char, |
bd5635a1 RP |
1424 | (LONGEST) 1)); |
1425 | return value_assign (arg1, arg2); | |
1426 | } | |
1427 | ||
1428 | case UNOP_PREDECREMENT: | |
1429 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1430 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
1431 | return arg1; | |
1432 | else if (unop_user_defined_p (op, arg1)) | |
1433 | { | |
1434 | return value_x_unop (arg1, op); | |
1435 | } | |
1436 | else | |
1437 | { | |
2ccb3837 | 1438 | arg2 = value_sub (arg1, value_from_longest (builtin_type_char, |
bd5635a1 RP |
1439 | (LONGEST) 1)); |
1440 | return value_assign (arg1, arg2); | |
1441 | } | |
1442 | ||
1443 | case UNOP_POSTINCREMENT: | |
1444 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1445 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
1446 | return arg1; | |
1447 | else if (unop_user_defined_p (op, arg1)) | |
1448 | { | |
1449 | return value_x_unop (arg1, op); | |
1450 | } | |
1451 | else | |
1452 | { | |
2ccb3837 | 1453 | arg2 = value_add (arg1, value_from_longest (builtin_type_char, |
bd5635a1 RP |
1454 | (LONGEST) 1)); |
1455 | value_assign (arg1, arg2); | |
1456 | return arg1; | |
1457 | } | |
1458 | ||
1459 | case UNOP_POSTDECREMENT: | |
1460 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1461 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
1462 | return arg1; | |
1463 | else if (unop_user_defined_p (op, arg1)) | |
1464 | { | |
1465 | return value_x_unop (arg1, op); | |
1466 | } | |
1467 | else | |
1468 | { | |
2ccb3837 | 1469 | arg2 = value_sub (arg1, value_from_longest (builtin_type_char, |
bd5635a1 RP |
1470 | (LONGEST) 1)); |
1471 | value_assign (arg1, arg2); | |
1472 | return arg1; | |
1473 | } | |
1474 | ||
1475 | case OP_THIS: | |
1476 | (*pos) += 1; | |
1477 | return value_of_this (1); | |
1478 | ||
1500864f JK |
1479 | case OP_TYPE: |
1480 | error ("Attempt to use a type name as an expression"); | |
1481 | ||
bd5635a1 | 1482 | default: |
1500864f JK |
1483 | /* Removing this case and compiling with gcc -Wall reveals that |
1484 | a lot of cases are hitting this case. Some of these should | |
1485 | probably be removed from expression.h (e.g. do we need a BINOP_SCOPE | |
1486 | and an OP_SCOPE?); others are legitimate expressions which are | |
1487 | (apparently) not fully implemented. | |
1488 | ||
1489 | If there are any cases landing here which mean a user error, | |
1490 | then they should be separate cases, with more descriptive | |
1491 | error messages. */ | |
1492 | ||
1493 | error ("\ | |
2d67c7e9 | 1494 | GDB does not (yet) know how to evaluate that kind of expression"); |
bd5635a1 RP |
1495 | } |
1496 | ||
1497 | nosideret: | |
2ccb3837 | 1498 | return value_from_longest (builtin_type_long, (LONGEST) 1); |
bd5635a1 RP |
1499 | } |
1500 | \f | |
1501 | /* Evaluate a subexpression of EXP, at index *POS, | |
1502 | and return the address of that subexpression. | |
1503 | Advance *POS over the subexpression. | |
1504 | If the subexpression isn't an lvalue, get an error. | |
1505 | NOSIDE may be EVAL_AVOID_SIDE_EFFECTS; | |
1506 | then only the type of the result need be correct. */ | |
1507 | ||
2d67c7e9 | 1508 | static value_ptr |
bd5635a1 RP |
1509 | evaluate_subexp_for_address (exp, pos, noside) |
1510 | register struct expression *exp; | |
1511 | register int *pos; | |
1512 | enum noside noside; | |
1513 | { | |
1514 | enum exp_opcode op; | |
1515 | register int pc; | |
e17960fb | 1516 | struct symbol *var; |
bd5635a1 RP |
1517 | |
1518 | pc = (*pos); | |
1519 | op = exp->elts[pc].opcode; | |
1520 | ||
1521 | switch (op) | |
1522 | { | |
1523 | case UNOP_IND: | |
1524 | (*pos)++; | |
1525 | return evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1526 | ||
1527 | case UNOP_MEMVAL: | |
1528 | (*pos) += 3; | |
1529 | return value_cast (lookup_pointer_type (exp->elts[pc + 1].type), | |
1530 | evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
1531 | ||
1532 | case OP_VAR_VALUE: | |
479fdd26 | 1533 | var = exp->elts[pc + 2].symbol; |
e17960fb JG |
1534 | |
1535 | /* C++: The "address" of a reference should yield the address | |
1536 | * of the object pointed to. Let value_addr() deal with it. */ | |
1537 | if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF) | |
1538 | goto default_case; | |
1539 | ||
479fdd26 | 1540 | (*pos) += 4; |
bd5635a1 RP |
1541 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
1542 | { | |
1543 | struct type *type = | |
e17960fb JG |
1544 | lookup_pointer_type (SYMBOL_TYPE (var)); |
1545 | enum address_class sym_class = SYMBOL_CLASS (var); | |
bd5635a1 RP |
1546 | |
1547 | if (sym_class == LOC_CONST | |
1548 | || sym_class == LOC_CONST_BYTES | |
1549 | || sym_class == LOC_REGISTER | |
1550 | || sym_class == LOC_REGPARM) | |
1551 | error ("Attempt to take address of register or constant."); | |
1552 | ||
1553 | return | |
1554 | value_zero (type, not_lval); | |
1555 | } | |
1556 | else | |
479fdd26 JK |
1557 | return |
1558 | locate_var_value | |
1559 | (var, | |
1560 | block_innermost_frame (exp->elts[pc + 1].block)); | |
bd5635a1 RP |
1561 | |
1562 | default: | |
e17960fb | 1563 | default_case: |
bd5635a1 RP |
1564 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
1565 | { | |
2d67c7e9 | 1566 | value_ptr x = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
bd5635a1 | 1567 | if (VALUE_LVAL (x) == lval_memory) |
0a5d35ed | 1568 | return value_zero (lookup_pointer_type (VALUE_TYPE (x)), |
bd5635a1 RP |
1569 | not_lval); |
1570 | else | |
1571 | error ("Attempt to take address of non-lval"); | |
1572 | } | |
1573 | return value_addr (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
1574 | } | |
1575 | } | |
1576 | ||
1577 | /* Evaluate like `evaluate_subexp' except coercing arrays to pointers. | |
fb6e675f FF |
1578 | When used in contexts where arrays will be coerced anyway, this is |
1579 | equivalent to `evaluate_subexp' but much faster because it avoids | |
479fdd26 JK |
1580 | actually fetching array contents (perhaps obsolete now that we have |
1581 | VALUE_LAZY). | |
fb6e675f FF |
1582 | |
1583 | Note that we currently only do the coercion for C expressions, where | |
1584 | arrays are zero based and the coercion is correct. For other languages, | |
1585 | with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION | |
1586 | to decide if coercion is appropriate. | |
1587 | ||
479fdd26 | 1588 | */ |
bd5635a1 | 1589 | |
7398958c | 1590 | value_ptr |
bd5635a1 RP |
1591 | evaluate_subexp_with_coercion (exp, pos, noside) |
1592 | register struct expression *exp; | |
1593 | register int *pos; | |
1594 | enum noside noside; | |
1595 | { | |
1596 | register enum exp_opcode op; | |
1597 | register int pc; | |
2d67c7e9 | 1598 | register value_ptr val; |
e17960fb | 1599 | struct symbol *var; |
bd5635a1 RP |
1600 | |
1601 | pc = (*pos); | |
1602 | op = exp->elts[pc].opcode; | |
1603 | ||
1604 | switch (op) | |
1605 | { | |
1606 | case OP_VAR_VALUE: | |
479fdd26 | 1607 | var = exp->elts[pc + 2].symbol; |
fb6e675f FF |
1608 | if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_ARRAY |
1609 | && CAST_IS_CONVERSION) | |
bd5635a1 | 1610 | { |
479fdd26 JK |
1611 | (*pos) += 4; |
1612 | val = | |
1613 | locate_var_value | |
1614 | (var, block_innermost_frame (exp->elts[pc + 1].block)); | |
e17960fb | 1615 | return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var))), |
bd5635a1 RP |
1616 | val); |
1617 | } | |
479fdd26 JK |
1618 | /* FALLTHROUGH */ |
1619 | ||
1620 | default: | |
1621 | return evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
bd5635a1 RP |
1622 | } |
1623 | } | |
1624 | ||
1625 | /* Evaluate a subexpression of EXP, at index *POS, | |
1626 | and return a value for the size of that subexpression. | |
1627 | Advance *POS over the subexpression. */ | |
1628 | ||
2d67c7e9 | 1629 | static value_ptr |
bd5635a1 RP |
1630 | evaluate_subexp_for_sizeof (exp, pos) |
1631 | register struct expression *exp; | |
1632 | register int *pos; | |
1633 | { | |
1634 | enum exp_opcode op; | |
1635 | register int pc; | |
2d67c7e9 | 1636 | value_ptr val; |
bd5635a1 RP |
1637 | |
1638 | pc = (*pos); | |
1639 | op = exp->elts[pc].opcode; | |
1640 | ||
1641 | switch (op) | |
1642 | { | |
1643 | /* This case is handled specially | |
1644 | so that we avoid creating a value for the result type. | |
1645 | If the result type is very big, it's desirable not to | |
1646 | create a value unnecessarily. */ | |
1647 | case UNOP_IND: | |
1648 | (*pos)++; | |
1649 | val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
2ccb3837 | 1650 | return value_from_longest (builtin_type_int, (LONGEST) |
bd5635a1 RP |
1651 | TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val)))); |
1652 | ||
1653 | case UNOP_MEMVAL: | |
1654 | (*pos) += 3; | |
2ccb3837 | 1655 | return value_from_longest (builtin_type_int, |
bd5635a1 RP |
1656 | (LONGEST) TYPE_LENGTH (exp->elts[pc + 1].type)); |
1657 | ||
1658 | case OP_VAR_VALUE: | |
479fdd26 JK |
1659 | (*pos) += 4; |
1660 | return | |
1661 | value_from_longest | |
1662 | (builtin_type_int, | |
1663 | (LONGEST) TYPE_LENGTH (SYMBOL_TYPE (exp->elts[pc + 2].symbol))); | |
bd5635a1 RP |
1664 | |
1665 | default: | |
1666 | val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
2ccb3837 | 1667 | return value_from_longest (builtin_type_int, |
bd5635a1 RP |
1668 | (LONGEST) TYPE_LENGTH (VALUE_TYPE (val))); |
1669 | } | |
1670 | } | |
0a5d35ed SG |
1671 | |
1672 | /* Parse a type expression in the string [P..P+LENGTH). */ | |
1673 | ||
1674 | struct type * | |
1675 | parse_and_eval_type (p, length) | |
1676 | char *p; | |
1677 | int length; | |
1678 | { | |
1679 | char *tmp = (char *)alloca (length + 4); | |
1680 | struct expression *expr; | |
1681 | tmp[0] = '('; | |
35fcebce | 1682 | memcpy (tmp+1, p, length); |
0a5d35ed SG |
1683 | tmp[length+1] = ')'; |
1684 | tmp[length+2] = '0'; | |
1685 | tmp[length+3] = '\0'; | |
1686 | expr = parse_expression (tmp); | |
1687 | if (expr->elts[0].opcode != UNOP_CAST) | |
1688 | error ("Internal error in eval_type."); | |
1689 | return expr->elts[1].type; | |
1690 | } | |
2d67c7e9 PB |
1691 | |
1692 | int | |
1693 | calc_f77_array_dims (array_type) | |
1694 | struct type *array_type; | |
1695 | { | |
1696 | int ndimen = 1; | |
1697 | struct type *tmp_type; | |
1698 | ||
1699 | if ((TYPE_CODE(array_type) != TYPE_CODE_ARRAY)) | |
1700 | error ("Can't get dimensions for a non-array type"); | |
1701 | ||
1702 | tmp_type = array_type; | |
1703 | ||
477b2425 | 1704 | while ((tmp_type = TYPE_TARGET_TYPE (tmp_type))) |
2d67c7e9 PB |
1705 | { |
1706 | if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY) | |
1707 | ++ndimen; | |
1708 | } | |
1709 | return ndimen; | |
1710 | } |