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