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