1 /* Evaluate expressions for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
29 #include "expression.h"
32 #include "language.h" /* For CAST_IS_CONVERSION */
33 #include "f-lang.h" /* for array bound stuff */
36 /* Defined in symtab.c */
37 extern int hp_som_som_object_present;
39 /* This is defined in valops.c */
40 extern int overload_resolution;
42 /* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue
43 on with successful lookup for member/method of the rtti type. */
44 extern int objectprint;
46 /* Prototypes for local functions. */
48 static struct value *evaluate_subexp_for_sizeof (struct expression *, int *);
50 static struct value *evaluate_subexp_for_address (struct expression *,
53 static struct value *evaluate_subexp (struct type *, struct expression *,
56 static char *get_label (struct expression *, int *);
58 static struct value *evaluate_struct_tuple (struct value *,
59 struct expression *, int *,
62 static LONGEST init_array_element (struct value *, struct value *,
63 struct expression *, int *, enum noside,
67 evaluate_subexp (struct type *expect_type, register struct expression *exp,
68 register int *pos, enum noside noside)
70 return (*exp->language_defn->evaluate_exp) (expect_type, exp, pos, noside);
73 /* Parse the string EXP as a C expression, evaluate it,
74 and return the result as a number. */
77 parse_and_eval_address (char *exp)
79 struct expression *expr = parse_expression (exp);
80 register CORE_ADDR addr;
81 register struct cleanup *old_chain =
82 make_cleanup (free_current_contents, &expr);
84 addr = value_as_address (evaluate_expression (expr));
85 do_cleanups (old_chain);
89 /* Like parse_and_eval_address but takes a pointer to a char * variable
90 and advanced that variable across the characters parsed. */
93 parse_and_eval_address_1 (char **expptr)
95 struct expression *expr = parse_exp_1 (expptr, (struct block *) 0, 0);
96 register CORE_ADDR addr;
97 register struct cleanup *old_chain =
98 make_cleanup (free_current_contents, &expr);
100 addr = value_as_address (evaluate_expression (expr));
101 do_cleanups (old_chain);
105 /* Like parse_and_eval_address, but treats the value of the expression
106 as an integer, not an address, returns a LONGEST, not a CORE_ADDR */
108 parse_and_eval_long (char *exp)
110 struct expression *expr = parse_expression (exp);
111 register LONGEST retval;
112 register struct cleanup *old_chain =
113 make_cleanup (free_current_contents, &expr);
115 retval = value_as_long (evaluate_expression (expr));
116 do_cleanups (old_chain);
121 parse_and_eval (char *exp)
123 struct expression *expr = parse_expression (exp);
125 register struct cleanup *old_chain =
126 make_cleanup (free_current_contents, &expr);
128 val = evaluate_expression (expr);
129 do_cleanups (old_chain);
133 /* Parse up to a comma (or to a closeparen)
134 in the string EXPP as an expression, evaluate it, and return the value.
135 EXPP is advanced to point to the comma. */
138 parse_to_comma_and_eval (char **expp)
140 struct expression *expr = parse_exp_1 (expp, (struct block *) 0, 1);
142 register struct cleanup *old_chain =
143 make_cleanup (free_current_contents, &expr);
145 val = evaluate_expression (expr);
146 do_cleanups (old_chain);
150 /* Evaluate an expression in internal prefix form
151 such as is constructed by parse.y.
153 See expression.h for info on the format of an expression. */
156 evaluate_expression (struct expression *exp)
159 return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
162 /* Evaluate an expression, avoiding all memory references
163 and getting a value whose type alone is correct. */
166 evaluate_type (struct expression *exp)
169 return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
172 /* If the next expression is an OP_LABELED, skips past it,
173 returning the label. Otherwise, does nothing and returns NULL. */
176 get_label (register struct expression *exp, int *pos)
178 if (exp->elts[*pos].opcode == OP_LABELED)
181 char *name = &exp->elts[pc + 2].string;
182 int tem = longest_to_int (exp->elts[pc + 1].longconst);
183 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
190 /* This function evaluates tuples (in (the deleted) Chill) or
191 brace-initializers (in C/C++) for structure types. */
193 static struct value *
194 evaluate_struct_tuple (struct value *struct_val,
195 register struct expression *exp,
196 register int *pos, enum noside noside, int nargs)
198 struct type *struct_type = check_typedef (VALUE_TYPE (struct_val));
199 struct type *substruct_type = struct_type;
200 struct type *field_type;
207 struct value *val = NULL;
212 /* Skip past the labels, and count them. */
213 while (get_label (exp, pos) != NULL)
218 char *label = get_label (exp, &pc);
221 for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type);
224 char *field_name = TYPE_FIELD_NAME (struct_type, fieldno);
225 if (field_name != NULL && STREQ (field_name, label))
228 subfieldno = fieldno;
229 substruct_type = struct_type;
233 for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type);
236 char *field_name = TYPE_FIELD_NAME (struct_type, fieldno);
237 field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
238 if ((field_name == 0 || *field_name == '\0')
239 && TYPE_CODE (field_type) == TYPE_CODE_UNION)
242 for (; variantno < TYPE_NFIELDS (field_type);
246 = TYPE_FIELD_TYPE (field_type, variantno);
247 if (TYPE_CODE (substruct_type) == TYPE_CODE_STRUCT)
250 subfieldno < TYPE_NFIELDS (substruct_type);
253 if (STREQ (TYPE_FIELD_NAME (substruct_type,
264 error ("there is no field named %s", label);
270 /* Unlabelled tuple element - go to next field. */
274 if (subfieldno >= TYPE_NFIELDS (substruct_type))
277 substruct_type = struct_type;
283 subfieldno = fieldno;
284 if (fieldno >= TYPE_NFIELDS (struct_type))
285 error ("too many initializers");
286 field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
287 if (TYPE_CODE (field_type) == TYPE_CODE_UNION
288 && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
289 error ("don't know which variant you want to set");
293 /* Here, struct_type is the type of the inner struct,
294 while substruct_type is the type of the inner struct.
295 These are the same for normal structures, but a variant struct
296 contains anonymous union fields that contain substruct fields.
297 The value fieldno is the index of the top-level (normal or
298 anonymous union) field in struct_field, while the value
299 subfieldno is the index of the actual real (named inner) field
300 in substruct_type. */
302 field_type = TYPE_FIELD_TYPE (substruct_type, subfieldno);
304 val = evaluate_subexp (field_type, exp, pos, noside);
306 /* Now actually set the field in struct_val. */
308 /* Assign val to field fieldno. */
309 if (VALUE_TYPE (val) != field_type)
310 val = value_cast (field_type, val);
312 bitsize = TYPE_FIELD_BITSIZE (substruct_type, subfieldno);
313 bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
315 bitpos += TYPE_FIELD_BITPOS (substruct_type, subfieldno);
316 addr = VALUE_CONTENTS (struct_val) + bitpos / 8;
318 modify_field (addr, value_as_long (val),
319 bitpos % 8, bitsize);
321 memcpy (addr, VALUE_CONTENTS (val),
322 TYPE_LENGTH (VALUE_TYPE (val)));
324 while (--nlabels > 0);
329 /* Recursive helper function for setting elements of array tuples for
330 (the deleted) Chill. The target is ARRAY (which has bounds
331 LOW_BOUND to HIGH_BOUND); the element value is ELEMENT; EXP, POS
332 and NOSIDE are as usual. Evaluates index expresions and sets the
333 specified element(s) of ARRAY to ELEMENT. Returns last index
337 init_array_element (struct value *array, struct value *element,
338 register struct expression *exp, register int *pos,
339 enum noside noside, LONGEST low_bound, LONGEST high_bound)
342 int element_size = TYPE_LENGTH (VALUE_TYPE (element));
343 if (exp->elts[*pos].opcode == BINOP_COMMA)
346 init_array_element (array, element, exp, pos, noside,
347 low_bound, high_bound);
348 return init_array_element (array, element,
349 exp, pos, noside, low_bound, high_bound);
351 else if (exp->elts[*pos].opcode == BINOP_RANGE)
355 low = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
356 high = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
357 if (low < low_bound || high > high_bound)
358 error ("tuple range index out of range");
359 for (index = low; index <= high; index++)
361 memcpy (VALUE_CONTENTS_RAW (array)
362 + (index - low_bound) * element_size,
363 VALUE_CONTENTS (element), element_size);
368 index = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
369 if (index < low_bound || index > high_bound)
370 error ("tuple index out of range");
371 memcpy (VALUE_CONTENTS_RAW (array) + (index - low_bound) * element_size,
372 VALUE_CONTENTS (element), element_size);
378 evaluate_subexp_standard (struct type *expect_type,
379 register struct expression *exp, register int *pos,
384 register int pc, pc2 = 0, oldpos;
385 struct value *arg1 = NULL;
386 struct value *arg2 = NULL;
390 struct value **argvec;
391 int upper, lower, retcode;
395 struct type **arg_types;
399 op = exp->elts[pc].opcode;
404 tem = longest_to_int (exp->elts[pc + 2].longconst);
405 (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
406 arg1 = value_struct_elt_for_reference (exp->elts[pc + 1].type,
408 exp->elts[pc + 1].type,
409 &exp->elts[pc + 3].string,
412 error ("There is no field named %s", &exp->elts[pc + 3].string);
417 return value_from_longest (exp->elts[pc + 1].type,
418 exp->elts[pc + 2].longconst);
422 return value_from_double (exp->elts[pc + 1].type,
423 exp->elts[pc + 2].doubleconst);
427 if (noside == EVAL_SKIP)
430 /* JYG: We used to just return value_zero of the symbol type
431 if we're asked to avoid side effects. Otherwise we return
432 value_of_variable (...). However I'm not sure if
433 value_of_variable () has any side effect.
434 We need a full value object returned here for whatis_exp ()
435 to call evaluate_type () and then pass the full value to
436 value_rtti_target_type () if we are dealing with a pointer
437 or reference to a base class and print object is on. */
439 return value_of_variable (exp->elts[pc + 2].symbol,
440 exp->elts[pc + 1].block);
445 access_value_history (longest_to_int (exp->elts[pc + 1].longconst));
449 int regno = longest_to_int (exp->elts[pc + 1].longconst);
450 struct value *val = value_of_register (regno, get_selected_frame ());
453 error ("Value of register %s not available.",
454 frame_map_regnum_to_name (regno));
460 return value_from_longest (LA_BOOL_TYPE,
461 exp->elts[pc + 1].longconst);
465 return value_of_internalvar (exp->elts[pc + 1].internalvar);
468 tem = longest_to_int (exp->elts[pc + 1].longconst);
469 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
470 if (noside == EVAL_SKIP)
472 return value_string (&exp->elts[pc + 2].string, tem);
475 tem = longest_to_int (exp->elts[pc + 1].longconst);
477 += 3 + BYTES_TO_EXP_ELEM ((tem + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT);
478 if (noside == EVAL_SKIP)
480 return value_bitstring (&exp->elts[pc + 2].string, tem);
485 tem2 = longest_to_int (exp->elts[pc + 1].longconst);
486 tem3 = longest_to_int (exp->elts[pc + 2].longconst);
487 nargs = tem3 - tem2 + 1;
488 type = expect_type ? check_typedef (expect_type) : NULL_TYPE;
490 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
491 && TYPE_CODE (type) == TYPE_CODE_STRUCT)
493 struct value *rec = allocate_value (expect_type);
494 memset (VALUE_CONTENTS_RAW (rec), '\0', TYPE_LENGTH (type));
495 return evaluate_struct_tuple (rec, exp, pos, noside, nargs);
498 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
499 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
501 struct type *range_type = TYPE_FIELD_TYPE (type, 0);
502 struct type *element_type = TYPE_TARGET_TYPE (type);
503 struct value *array = allocate_value (expect_type);
504 int element_size = TYPE_LENGTH (check_typedef (element_type));
505 LONGEST low_bound, high_bound, index;
506 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
509 high_bound = (TYPE_LENGTH (type) / element_size) - 1;
512 memset (VALUE_CONTENTS_RAW (array), 0, TYPE_LENGTH (expect_type));
513 for (tem = nargs; --nargs >= 0;)
515 struct value *element;
517 if (exp->elts[*pos].opcode == BINOP_RANGE)
520 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
522 element = evaluate_subexp (element_type, exp, pos, noside);
523 if (VALUE_TYPE (element) != element_type)
524 element = value_cast (element_type, element);
527 int continue_pc = *pos;
529 index = init_array_element (array, element, exp, pos, noside,
530 low_bound, high_bound);
535 if (index > high_bound)
536 /* to avoid memory corruption */
537 error ("Too many array elements");
538 memcpy (VALUE_CONTENTS_RAW (array)
539 + (index - low_bound) * element_size,
540 VALUE_CONTENTS (element),
548 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
549 && TYPE_CODE (type) == TYPE_CODE_SET)
551 struct value *set = allocate_value (expect_type);
552 char *valaddr = VALUE_CONTENTS_RAW (set);
553 struct type *element_type = TYPE_INDEX_TYPE (type);
554 struct type *check_type = element_type;
555 LONGEST low_bound, high_bound;
557 /* get targettype of elementtype */
558 while (TYPE_CODE (check_type) == TYPE_CODE_RANGE ||
559 TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
560 check_type = TYPE_TARGET_TYPE (check_type);
562 if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
563 error ("(power)set type with unknown size");
564 memset (valaddr, '\0', TYPE_LENGTH (type));
565 for (tem = 0; tem < nargs; tem++)
567 LONGEST range_low, range_high;
568 struct type *range_low_type, *range_high_type;
569 struct value *elem_val;
570 if (exp->elts[*pos].opcode == BINOP_RANGE)
573 elem_val = evaluate_subexp (element_type, exp, pos, noside);
574 range_low_type = VALUE_TYPE (elem_val);
575 range_low = value_as_long (elem_val);
576 elem_val = evaluate_subexp (element_type, exp, pos, noside);
577 range_high_type = VALUE_TYPE (elem_val);
578 range_high = value_as_long (elem_val);
582 elem_val = evaluate_subexp (element_type, exp, pos, noside);
583 range_low_type = range_high_type = VALUE_TYPE (elem_val);
584 range_low = range_high = value_as_long (elem_val);
586 /* check types of elements to avoid mixture of elements from
587 different types. Also check if type of element is "compatible"
588 with element type of powerset */
589 if (TYPE_CODE (range_low_type) == TYPE_CODE_RANGE)
590 range_low_type = TYPE_TARGET_TYPE (range_low_type);
591 if (TYPE_CODE (range_high_type) == TYPE_CODE_RANGE)
592 range_high_type = TYPE_TARGET_TYPE (range_high_type);
593 if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type)) ||
594 (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM &&
595 (range_low_type != range_high_type)))
596 /* different element modes */
597 error ("POWERSET tuple elements of different mode");
598 if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type)) ||
599 (TYPE_CODE (check_type) == TYPE_CODE_ENUM &&
600 range_low_type != check_type))
601 error ("incompatible POWERSET tuple elements");
602 if (range_low > range_high)
604 warning ("empty POWERSET tuple range");
607 if (range_low < low_bound || range_high > high_bound)
608 error ("POWERSET tuple element out of range");
609 range_low -= low_bound;
610 range_high -= low_bound;
611 for (; range_low <= range_high; range_low++)
613 int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;
615 bit_index = TARGET_CHAR_BIT - 1 - bit_index;
616 valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
623 argvec = (struct value **) alloca (sizeof (struct value *) * nargs);
624 for (tem = 0; tem < nargs; tem++)
626 /* Ensure that array expressions are coerced into pointer objects. */
627 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
629 if (noside == EVAL_SKIP)
631 return value_array (tem2, tem3, argvec);
635 struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
637 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
639 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
640 if (noside == EVAL_SKIP)
642 return value_slice (array, lowbound, upper - lowbound + 1);
645 case TERNOP_SLICE_COUNT:
647 struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
649 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
651 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
652 return value_slice (array, lowbound, length);
656 /* Skip third and second args to evaluate the first one. */
657 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
658 if (value_logical_not (arg1))
660 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
661 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
665 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
666 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
672 op = exp->elts[*pos].opcode;
673 nargs = longest_to_int (exp->elts[pc + 1].longconst);
674 /* Allocate arg vector, including space for the function to be
675 called in argvec[0] and a terminating NULL */
676 argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 3));
677 if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
681 /* 1997-08-01 Currently we do not support function invocation
682 via pointers-to-methods with HP aCC. Pointer does not point
683 to the function, but possibly to some thunk. */
684 if (hp_som_som_object_present)
686 error ("Not implemented: function invocation through pointer to method with HP aCC");
690 /* First, evaluate the structure into arg2 */
693 if (noside == EVAL_SKIP)
696 if (op == STRUCTOP_MEMBER)
698 arg2 = evaluate_subexp_for_address (exp, pos, noside);
702 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
705 /* If the function is a virtual function, then the
706 aggregate value (providing the structure) plays
707 its part by providing the vtable. Otherwise,
708 it is just along for the ride: call the function
711 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
713 fnptr = value_as_long (arg1);
715 if (METHOD_PTR_IS_VIRTUAL (fnptr))
717 int fnoffset = METHOD_PTR_TO_VOFFSET (fnptr);
718 struct type *basetype;
719 struct type *domain_type =
720 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)));
722 basetype = TYPE_TARGET_TYPE (VALUE_TYPE (arg2));
723 if (domain_type != basetype)
724 arg2 = value_cast (lookup_pointer_type (domain_type), arg2);
725 basetype = TYPE_VPTR_BASETYPE (domain_type);
726 for (i = TYPE_NFN_FIELDS (basetype) - 1; i >= 0; i--)
728 struct fn_field *f = TYPE_FN_FIELDLIST1 (basetype, i);
729 /* If one is virtual, then all are virtual. */
730 if (TYPE_FN_FIELD_VIRTUAL_P (f, 0))
731 for (j = TYPE_FN_FIELDLIST_LENGTH (basetype, i) - 1; j >= 0; --j)
732 if ((int) TYPE_FN_FIELD_VOFFSET (f, j) == fnoffset)
734 struct value *temp = value_ind (arg2);
735 arg1 = value_virtual_fn_field (&temp, f, j, domain_type, 0);
736 arg2 = value_addr (temp);
741 error ("virtual function at index %d not found", fnoffset);
745 VALUE_TYPE (arg1) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)));
749 /* Now, say which argument to start evaluating from */
752 else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
754 /* Hair for method invocations */
758 /* First, evaluate the structure into arg2 */
760 tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
761 *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);
762 if (noside == EVAL_SKIP)
765 if (op == STRUCTOP_STRUCT)
767 /* If v is a variable in a register, and the user types
768 v.method (), this will produce an error, because v has
771 A possible way around this would be to allocate a
772 copy of the variable on the stack, copy in the
773 contents, call the function, and copy out the
774 contents. I.e. convert this from call by reference
775 to call by copy-return (or whatever it's called).
776 However, this does not work because it is not the
777 same: the method being called could stash a copy of
778 the address, and then future uses through that address
779 (after the method returns) would be expected to
780 use the variable itself, not some copy of it. */
781 arg2 = evaluate_subexp_for_address (exp, pos, noside);
785 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
787 /* Now, say which argument to start evaluating from */
792 /* Non-method function call */
794 argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
796 type = VALUE_TYPE (argvec[0]);
797 if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
798 type = TYPE_TARGET_TYPE (type);
799 if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
801 for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
803 /* pai: FIXME This seems to be coercing arguments before
804 * overload resolution has been done! */
805 argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type, tem - 1),
811 /* Evaluate arguments */
812 for (; tem <= nargs; tem++)
814 /* Ensure that array expressions are coerced into pointer objects. */
815 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
818 /* signal end of arglist */
821 if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
826 /* Method invocation : stuff "this" as first parameter */
828 /* Name of method from expression */
829 strcpy (tstr, &exp->elts[pc2 + 2].string);
831 if (overload_resolution && (exp->language_defn->la_language == language_cplus))
833 /* Language is C++, do some overload resolution before evaluation */
834 struct value *valp = NULL;
836 /* Prepare list of argument types for overload resolution */
837 arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
838 for (ix = 1; ix <= nargs; ix++)
839 arg_types[ix - 1] = VALUE_TYPE (argvec[ix]);
841 (void) find_overload_match (arg_types, nargs, tstr,
842 1 /* method */ , 0 /* strict match */ ,
843 &arg2 /* the object */ , NULL,
844 &valp, NULL, &static_memfuncp);
847 argvec[1] = arg2; /* the ``this'' pointer */
848 argvec[0] = valp; /* use the method found after overload resolution */
851 /* Non-C++ case -- or no overload resolution */
853 struct value *temp = arg2;
854 argvec[0] = value_struct_elt (&temp, argvec + 1, tstr,
856 op == STRUCTOP_STRUCT
857 ? "structure" : "structure pointer");
858 /* value_struct_elt updates temp with the correct value
859 of the ``this'' pointer if necessary, so modify argvec[1] to
860 reflect any ``this'' changes. */
861 arg2 = value_from_longest (lookup_pointer_type(VALUE_TYPE (temp)),
862 VALUE_ADDRESS (temp) + VALUE_OFFSET (temp)
863 + VALUE_EMBEDDED_OFFSET (temp));
864 argvec[1] = arg2; /* the ``this'' pointer */
869 argvec[1] = argvec[0];
874 else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
879 else if (op == OP_VAR_VALUE)
881 /* Non-member function being called */
882 /* fn: This can only be done for C++ functions. A C-style function
883 in a C++ program, for instance, does not have the fields that
886 if (overload_resolution && (exp->language_defn->la_language == language_cplus))
888 /* Language is C++, do some overload resolution before evaluation */
891 /* Prepare list of argument types for overload resolution */
892 arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
893 for (ix = 1; ix <= nargs; ix++)
894 arg_types[ix - 1] = VALUE_TYPE (argvec[ix]);
896 (void) find_overload_match (arg_types, nargs, NULL /* no need for name */ ,
897 0 /* not method */ , 0 /* strict match */ ,
898 NULL, exp->elts[save_pos1+2].symbol /* the function */ ,
901 /* Now fix the expression being evaluated */
902 exp->elts[save_pos1+2].symbol = symp;
903 argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
907 /* Not C++, or no overload resolution allowed */
908 /* nothing to be done; argvec already correctly set up */
913 /* It is probably a C-style function */
914 /* nothing to be done; argvec already correctly set up */
919 if (noside == EVAL_SKIP)
921 if (argvec[0] == NULL)
922 error ("Cannot evaluate function -- may be inlined");
923 if (noside == EVAL_AVOID_SIDE_EFFECTS)
925 /* If the return type doesn't look like a function type, call an
926 error. This can happen if somebody tries to turn a variable into
927 a function call. This is here because people often want to
928 call, eg, strcmp, which gdb doesn't know is a function. If
929 gdb isn't asked for it's opinion (ie. through "whatis"),
930 it won't offer it. */
933 TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0]));
936 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0])));
938 error ("Expression of type other than \"Function returning ...\" used as function");
940 return call_function_by_hand (argvec[0], nargs, argvec + 1);
941 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
943 case OP_F77_UNDETERMINED_ARGLIST:
945 /* Remember that in F77, functions, substring ops and
946 array subscript operations cannot be disambiguated
947 at parse time. We have made all array subscript operations,
948 substring operations as well as function calls come here
949 and we now have to discover what the heck this thing actually was.
950 If it is a function, we process just as if we got an OP_FUNCALL. */
952 nargs = longest_to_int (exp->elts[pc + 1].longconst);
955 /* First determine the type code we are dealing with. */
956 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
957 type = check_typedef (VALUE_TYPE (arg1));
958 code = TYPE_CODE (type);
962 case TYPE_CODE_ARRAY:
963 goto multi_f77_subscript;
965 case TYPE_CODE_STRING:
970 /* It's a function call. */
971 /* Allocate arg vector, including space for the function to be
972 called in argvec[0] and a terminating NULL */
973 argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 2));
976 for (; tem <= nargs; tem++)
977 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
978 argvec[tem] = 0; /* signal end of arglist */
982 error ("Cannot perform substring on this type");
986 /* We have a substring operation on our hands here,
987 let us get the string we will be dealing with */
989 /* Now evaluate the 'from' and 'to' */
991 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
994 return value_subscript (arg1, arg2);
996 arg3 = evaluate_subexp_with_coercion (exp, pos, noside);
998 if (noside == EVAL_SKIP)
1001 tem2 = value_as_long (arg2);
1002 tem3 = value_as_long (arg3);
1004 return value_slice (arg1, tem2, tem3 - tem2 + 1);
1007 /* We have a complex number, There should be 2 floating
1008 point numbers that compose it */
1009 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1010 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1012 return value_literal_complex (arg1, arg2, builtin_type_f_complex_s16);
1014 case STRUCTOP_STRUCT:
1015 tem = longest_to_int (exp->elts[pc + 1].longconst);
1016 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1017 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1018 if (noside == EVAL_SKIP)
1020 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1021 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1),
1022 &exp->elts[pc + 2].string,
1027 struct value *temp = arg1;
1028 return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
1033 tem = longest_to_int (exp->elts[pc + 1].longconst);
1034 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1035 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1036 if (noside == EVAL_SKIP)
1039 /* JYG: if print object is on we need to replace the base type
1040 with rtti type in order to continue on with successful
1041 lookup of member / method only available in the rtti type. */
1043 struct type *type = VALUE_TYPE (arg1);
1044 struct type *real_type;
1045 int full, top, using_enc;
1047 if (objectprint && TYPE_TARGET_TYPE(type) &&
1048 (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
1050 real_type = value_rtti_target_type (arg1, &full, &top, &using_enc);
1053 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1054 real_type = lookup_pointer_type (real_type);
1056 real_type = lookup_reference_type (real_type);
1058 arg1 = value_cast (real_type, arg1);
1063 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1064 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1),
1065 &exp->elts[pc + 2].string,
1070 struct value *temp = arg1;
1071 return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
1072 NULL, "structure pointer");
1075 case STRUCTOP_MEMBER:
1076 arg1 = evaluate_subexp_for_address (exp, pos, noside);
1077 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1079 /* With HP aCC, pointers to methods do not point to the function code */
1080 if (hp_som_som_object_present &&
1081 (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_PTR) &&
1082 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) == TYPE_CODE_METHOD))
1083 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1085 mem_offset = value_as_long (arg2);
1086 goto handle_pointer_to_member;
1089 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1090 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1092 /* With HP aCC, pointers to methods do not point to the function code */
1093 if (hp_som_som_object_present &&
1094 (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_PTR) &&
1095 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) == TYPE_CODE_METHOD))
1096 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1098 mem_offset = value_as_long (arg2);
1100 handle_pointer_to_member:
1101 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1102 a real offset to the member. */
1103 if (hp_som_som_object_present)
1105 if (!mem_offset) /* no bias -> really null */
1106 error ("Attempted dereference of null pointer-to-member");
1107 mem_offset &= ~0x20000000;
1109 if (noside == EVAL_SKIP)
1111 type = check_typedef (VALUE_TYPE (arg2));
1112 if (TYPE_CODE (type) != TYPE_CODE_PTR)
1113 goto bad_pointer_to_member;
1114 type = check_typedef (TYPE_TARGET_TYPE (type));
1115 if (TYPE_CODE (type) == TYPE_CODE_METHOD)
1116 error ("not implemented: pointer-to-method in pointer-to-member construct");
1117 if (TYPE_CODE (type) != TYPE_CODE_MEMBER)
1118 goto bad_pointer_to_member;
1119 /* Now, convert these values to an address. */
1120 arg1 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
1122 arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
1123 value_as_long (arg1) + mem_offset);
1124 return value_ind (arg3);
1125 bad_pointer_to_member:
1126 error ("non-pointer-to-member value used in pointer-to-member construct");
1129 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1130 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1131 if (noside == EVAL_SKIP)
1133 if (binop_user_defined_p (op, arg1, arg2))
1134 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1136 return value_concat (arg1, arg2);
1139 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1140 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1142 /* Do special stuff for HP aCC pointers to members */
1143 if (hp_som_som_object_present)
1145 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1146 the implementation yet; but the pointer appears to point to a code
1147 sequence (thunk) in memory -- in any case it is *not* the address
1148 of the function as it would be in a naive implementation. */
1149 if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR) &&
1150 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_METHOD))
1151 error ("Assignment to pointers to methods not implemented with HP aCC");
1153 /* HP aCC pointers to data members require a constant bias */
1154 if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR) &&
1155 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_MEMBER))
1157 unsigned int *ptr = (unsigned int *) VALUE_CONTENTS (arg2); /* forces evaluation */
1158 *ptr |= 0x20000000; /* set 29th bit */
1162 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1164 if (binop_user_defined_p (op, arg1, arg2))
1165 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1167 return value_assign (arg1, arg2);
1169 case BINOP_ASSIGN_MODIFY:
1171 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1172 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1173 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1175 op = exp->elts[pc + 1].opcode;
1176 if (binop_user_defined_p (op, arg1, arg2))
1177 return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
1178 else if (op == BINOP_ADD)
1179 arg2 = value_add (arg1, arg2);
1180 else if (op == BINOP_SUB)
1181 arg2 = value_sub (arg1, arg2);
1183 arg2 = value_binop (arg1, arg2, op);
1184 return value_assign (arg1, arg2);
1187 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1188 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1189 if (noside == EVAL_SKIP)
1191 if (binop_user_defined_p (op, arg1, arg2))
1192 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1194 return value_add (arg1, arg2);
1197 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1198 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1199 if (noside == EVAL_SKIP)
1201 if (binop_user_defined_p (op, arg1, arg2))
1202 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1204 return value_sub (arg1, arg2);
1212 case BINOP_BITWISE_AND:
1213 case BINOP_BITWISE_IOR:
1214 case BINOP_BITWISE_XOR:
1215 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1216 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1217 if (noside == EVAL_SKIP)
1219 if (binop_user_defined_p (op, arg1, arg2))
1220 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1221 else if (noside == EVAL_AVOID_SIDE_EFFECTS
1222 && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
1223 return value_zero (VALUE_TYPE (arg1), not_lval);
1225 return value_binop (arg1, arg2, op);
1228 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1229 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1230 if (noside == EVAL_SKIP)
1232 error ("':' operator used in invalid context");
1234 case BINOP_SUBSCRIPT:
1235 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1236 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1237 if (noside == EVAL_SKIP)
1239 if (binop_user_defined_p (op, arg1, arg2))
1240 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1243 /* If the user attempts to subscript something that is not an
1244 array or pointer type (like a plain int variable for example),
1245 then report this as an error. */
1248 type = check_typedef (VALUE_TYPE (arg1));
1249 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
1250 && TYPE_CODE (type) != TYPE_CODE_PTR)
1252 if (TYPE_NAME (type))
1253 error ("cannot subscript something of type `%s'",
1256 error ("cannot subscript requested type");
1259 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1260 return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
1262 return value_subscript (arg1, arg2);
1266 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1267 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1268 if (noside == EVAL_SKIP)
1270 return value_in (arg1, arg2);
1272 case MULTI_SUBSCRIPT:
1274 nargs = longest_to_int (exp->elts[pc + 1].longconst);
1275 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1278 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1279 /* FIXME: EVAL_SKIP handling may not be correct. */
1280 if (noside == EVAL_SKIP)
1291 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1292 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1294 /* If the user attempts to subscript something that has no target
1295 type (like a plain int variable for example), then report this
1298 type = TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (arg1)));
1301 arg1 = value_zero (type, VALUE_LVAL (arg1));
1307 error ("cannot subscript something of type `%s'",
1308 TYPE_NAME (VALUE_TYPE (arg1)));
1312 if (binop_user_defined_p (op, arg1, arg2))
1314 arg1 = value_x_binop (arg1, arg2, op, OP_NULL, noside);
1318 arg1 = value_subscript (arg1, arg2);
1323 multi_f77_subscript:
1325 int subscript_array[MAX_FORTRAN_DIMS + 1]; /* 1-based array of
1326 subscripts, max == 7 */
1327 int array_size_array[MAX_FORTRAN_DIMS + 1];
1328 int ndimensions = 1, i;
1329 struct type *tmp_type;
1330 int offset_item; /* The array offset where the item lives */
1332 if (nargs > MAX_FORTRAN_DIMS)
1333 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS);
1335 tmp_type = check_typedef (VALUE_TYPE (arg1));
1336 ndimensions = calc_f77_array_dims (type);
1338 if (nargs != ndimensions)
1339 error ("Wrong number of subscripts");
1341 /* Now that we know we have a legal array subscript expression
1342 let us actually find out where this element exists in the array. */
1345 for (i = 1; i <= nargs; i++)
1347 /* Evaluate each subscript, It must be a legal integer in F77 */
1348 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1350 /* Fill in the subscript and array size arrays */
1352 subscript_array[i] = value_as_long (arg2);
1354 retcode = f77_get_dynamic_upperbound (tmp_type, &upper);
1355 if (retcode == BOUND_FETCH_ERROR)
1356 error ("Cannot obtain dynamic upper bound");
1358 retcode = f77_get_dynamic_lowerbound (tmp_type, &lower);
1359 if (retcode == BOUND_FETCH_ERROR)
1360 error ("Cannot obtain dynamic lower bound");
1362 array_size_array[i] = upper - lower + 1;
1364 /* Zero-normalize subscripts so that offsetting will work. */
1366 subscript_array[i] -= lower;
1368 /* If we are at the bottom of a multidimensional
1369 array type then keep a ptr to the last ARRAY
1370 type around for use when calling value_subscript()
1371 below. This is done because we pretend to value_subscript
1372 that we actually have a one-dimensional array
1373 of base element type that we apply a simple
1377 tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
1380 /* Now let us calculate the offset for this item */
1382 offset_item = subscript_array[ndimensions];
1384 for (i = ndimensions - 1; i >= 1; i--)
1386 array_size_array[i] * offset_item + subscript_array[i];
1388 /* Construct a value node with the value of the offset */
1390 arg2 = value_from_longest (builtin_type_f_integer, offset_item);
1392 /* Let us now play a dirty trick: we will take arg1
1393 which is a value node pointing to the topmost level
1394 of the multidimensional array-set and pretend
1395 that it is actually a array of the final element
1396 type, this will ensure that value_subscript()
1397 returns the correct type value */
1399 VALUE_TYPE (arg1) = tmp_type;
1400 return value_ind (value_add (value_coerce_array (arg1), arg2));
1403 case BINOP_LOGICAL_AND:
1404 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1405 if (noside == EVAL_SKIP)
1407 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1412 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1415 if (binop_user_defined_p (op, arg1, arg2))
1417 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1418 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1422 tem = value_logical_not (arg1);
1423 arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
1424 (tem ? EVAL_SKIP : noside));
1425 return value_from_longest (LA_BOOL_TYPE,
1426 (LONGEST) (!tem && !value_logical_not (arg2)));
1429 case BINOP_LOGICAL_OR:
1430 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1431 if (noside == EVAL_SKIP)
1433 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1438 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1441 if (binop_user_defined_p (op, arg1, arg2))
1443 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1444 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1448 tem = value_logical_not (arg1);
1449 arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
1450 (!tem ? EVAL_SKIP : noside));
1451 return value_from_longest (LA_BOOL_TYPE,
1452 (LONGEST) (!tem || !value_logical_not (arg2)));
1456 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1457 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1458 if (noside == EVAL_SKIP)
1460 if (binop_user_defined_p (op, arg1, arg2))
1462 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1466 tem = value_equal (arg1, arg2);
1467 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1470 case BINOP_NOTEQUAL:
1471 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1472 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1473 if (noside == EVAL_SKIP)
1475 if (binop_user_defined_p (op, arg1, arg2))
1477 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1481 tem = value_equal (arg1, arg2);
1482 return value_from_longest (LA_BOOL_TYPE, (LONGEST) ! tem);
1486 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1487 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1488 if (noside == EVAL_SKIP)
1490 if (binop_user_defined_p (op, arg1, arg2))
1492 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1496 tem = value_less (arg1, arg2);
1497 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1501 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1502 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1503 if (noside == EVAL_SKIP)
1505 if (binop_user_defined_p (op, arg1, arg2))
1507 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1511 tem = value_less (arg2, arg1);
1512 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1516 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1517 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1518 if (noside == EVAL_SKIP)
1520 if (binop_user_defined_p (op, arg1, arg2))
1522 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1526 tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
1527 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1531 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1532 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1533 if (noside == EVAL_SKIP)
1535 if (binop_user_defined_p (op, arg1, arg2))
1537 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1541 tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
1542 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1546 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1547 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1548 if (noside == EVAL_SKIP)
1550 type = check_typedef (VALUE_TYPE (arg2));
1551 if (TYPE_CODE (type) != TYPE_CODE_INT)
1552 error ("Non-integral right operand for \"@\" operator.");
1553 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1555 return allocate_repeat_value (VALUE_TYPE (arg1),
1556 longest_to_int (value_as_long (arg2)));
1559 return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
1562 evaluate_subexp (NULL_TYPE, exp, pos, noside);
1563 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
1566 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1567 if (noside == EVAL_SKIP)
1569 if (unop_user_defined_p (op, arg1))
1570 return value_x_unop (arg1, op, noside);
1572 return value_neg (arg1);
1574 case UNOP_COMPLEMENT:
1575 /* C++: check for and handle destructor names. */
1576 op = exp->elts[*pos].opcode;
1578 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1579 if (noside == EVAL_SKIP)
1581 if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
1582 return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
1584 return value_complement (arg1);
1586 case UNOP_LOGICAL_NOT:
1587 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1588 if (noside == EVAL_SKIP)
1590 if (unop_user_defined_p (op, arg1))
1591 return value_x_unop (arg1, op, noside);
1593 return value_from_longest (LA_BOOL_TYPE,
1594 (LONGEST) value_logical_not (arg1));
1597 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
1598 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
1599 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1600 if ((TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) &&
1601 ((TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_METHOD) ||
1602 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_MEMBER)))
1603 error ("Attempt to dereference pointer to member without an object");
1604 if (noside == EVAL_SKIP)
1606 if (unop_user_defined_p (op, arg1))
1607 return value_x_unop (arg1, op, noside);
1608 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1610 type = check_typedef (VALUE_TYPE (arg1));
1611 if (TYPE_CODE (type) == TYPE_CODE_PTR
1612 || TYPE_CODE (type) == TYPE_CODE_REF
1613 /* In C you can dereference an array to get the 1st elt. */
1614 || TYPE_CODE (type) == TYPE_CODE_ARRAY
1616 return value_zero (TYPE_TARGET_TYPE (type),
1618 else if (TYPE_CODE (type) == TYPE_CODE_INT)
1619 /* GDB allows dereferencing an int. */
1620 return value_zero (builtin_type_int, lval_memory);
1622 error ("Attempt to take contents of a non-pointer value.");
1624 return value_ind (arg1);
1627 /* C++: check for and handle pointer to members. */
1629 op = exp->elts[*pos].opcode;
1631 if (noside == EVAL_SKIP)
1635 int temm = longest_to_int (exp->elts[pc + 3].longconst);
1636 (*pos) += 3 + BYTES_TO_EXP_ELEM (temm + 1);
1639 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
1644 struct value *retvalp = evaluate_subexp_for_address (exp, pos, noside);
1645 /* If HP aCC object, use bias for pointers to members */
1646 if (hp_som_som_object_present &&
1647 (TYPE_CODE (VALUE_TYPE (retvalp)) == TYPE_CODE_PTR) &&
1648 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (retvalp))) == TYPE_CODE_MEMBER))
1650 unsigned int *ptr = (unsigned int *) VALUE_CONTENTS (retvalp); /* forces evaluation */
1651 *ptr |= 0x20000000; /* set 29th bit */
1657 if (noside == EVAL_SKIP)
1659 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
1662 return evaluate_subexp_for_sizeof (exp, pos);
1666 type = exp->elts[pc + 1].type;
1667 arg1 = evaluate_subexp (type, exp, pos, noside);
1668 if (noside == EVAL_SKIP)
1670 if (type != VALUE_TYPE (arg1))
1671 arg1 = value_cast (type, arg1);
1676 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1677 if (noside == EVAL_SKIP)
1679 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1680 return value_zero (exp->elts[pc + 1].type, lval_memory);
1682 return value_at_lazy (exp->elts[pc + 1].type,
1683 value_as_address (arg1),
1686 case UNOP_PREINCREMENT:
1687 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1688 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1690 else if (unop_user_defined_p (op, arg1))
1692 return value_x_unop (arg1, op, noside);
1696 arg2 = value_add (arg1, value_from_longest (builtin_type_char,
1698 return value_assign (arg1, arg2);
1701 case UNOP_PREDECREMENT:
1702 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1703 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1705 else if (unop_user_defined_p (op, arg1))
1707 return value_x_unop (arg1, op, noside);
1711 arg2 = value_sub (arg1, value_from_longest (builtin_type_char,
1713 return value_assign (arg1, arg2);
1716 case UNOP_POSTINCREMENT:
1717 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1718 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1720 else if (unop_user_defined_p (op, arg1))
1722 return value_x_unop (arg1, op, noside);
1726 arg2 = value_add (arg1, value_from_longest (builtin_type_char,
1728 value_assign (arg1, arg2);
1732 case UNOP_POSTDECREMENT:
1733 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1734 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1736 else if (unop_user_defined_p (op, arg1))
1738 return value_x_unop (arg1, op, noside);
1742 arg2 = value_sub (arg1, value_from_longest (builtin_type_char,
1744 value_assign (arg1, arg2);
1750 return value_of_this (1);
1753 error ("Attempt to use a type name as an expression");
1756 /* Removing this case and compiling with gcc -Wall reveals that
1757 a lot of cases are hitting this case. Some of these should
1758 probably be removed from expression.h; others are legitimate
1759 expressions which are (apparently) not fully implemented.
1761 If there are any cases landing here which mean a user error,
1762 then they should be separate cases, with more descriptive
1766 GDB does not (yet) know how to evaluate that kind of expression");
1770 return value_from_longest (builtin_type_long, (LONGEST) 1);
1773 /* Evaluate a subexpression of EXP, at index *POS,
1774 and return the address of that subexpression.
1775 Advance *POS over the subexpression.
1776 If the subexpression isn't an lvalue, get an error.
1777 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1778 then only the type of the result need be correct. */
1780 static struct value *
1781 evaluate_subexp_for_address (register struct expression *exp, register int *pos,
1789 op = exp->elts[pc].opcode;
1795 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
1799 return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
1800 evaluate_subexp (NULL_TYPE, exp, pos, noside));
1803 var = exp->elts[pc + 2].symbol;
1805 /* C++: The "address" of a reference should yield the address
1806 * of the object pointed to. Let value_addr() deal with it. */
1807 if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
1811 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1814 lookup_pointer_type (SYMBOL_TYPE (var));
1815 enum address_class sym_class = SYMBOL_CLASS (var);
1817 if (sym_class == LOC_CONST
1818 || sym_class == LOC_CONST_BYTES
1819 || sym_class == LOC_REGISTER
1820 || sym_class == LOC_REGPARM)
1821 error ("Attempt to take address of register or constant.");
1824 value_zero (type, not_lval);
1830 block_innermost_frame (exp->elts[pc + 1].block));
1834 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1836 struct value *x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1837 if (VALUE_LVAL (x) == lval_memory)
1838 return value_zero (lookup_pointer_type (VALUE_TYPE (x)),
1841 error ("Attempt to take address of non-lval");
1843 return value_addr (evaluate_subexp (NULL_TYPE, exp, pos, noside));
1847 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1848 When used in contexts where arrays will be coerced anyway, this is
1849 equivalent to `evaluate_subexp' but much faster because it avoids
1850 actually fetching array contents (perhaps obsolete now that we have
1853 Note that we currently only do the coercion for C expressions, where
1854 arrays are zero based and the coercion is correct. For other languages,
1855 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1856 to decide if coercion is appropriate.
1861 evaluate_subexp_with_coercion (register struct expression *exp,
1862 register int *pos, enum noside noside)
1864 register enum exp_opcode op;
1870 op = exp->elts[pc].opcode;
1875 var = exp->elts[pc + 2].symbol;
1876 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var))) == TYPE_CODE_ARRAY
1877 && CAST_IS_CONVERSION)
1882 (var, block_innermost_frame (exp->elts[pc + 1].block));
1883 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var)))),
1889 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
1893 /* Evaluate a subexpression of EXP, at index *POS,
1894 and return a value for the size of that subexpression.
1895 Advance *POS over the subexpression. */
1897 static struct value *
1898 evaluate_subexp_for_sizeof (register struct expression *exp, register int *pos)
1906 op = exp->elts[pc].opcode;
1910 /* This case is handled specially
1911 so that we avoid creating a value for the result type.
1912 If the result type is very big, it's desirable not to
1913 create a value unnecessarily. */
1916 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1917 type = check_typedef (VALUE_TYPE (val));
1918 if (TYPE_CODE (type) != TYPE_CODE_PTR
1919 && TYPE_CODE (type) != TYPE_CODE_REF
1920 && TYPE_CODE (type) != TYPE_CODE_ARRAY)
1921 error ("Attempt to take contents of a non-pointer value.");
1922 type = check_typedef (TYPE_TARGET_TYPE (type));
1923 return value_from_longest (builtin_type_int, (LONGEST)
1924 TYPE_LENGTH (type));
1928 type = check_typedef (exp->elts[pc + 1].type);
1929 return value_from_longest (builtin_type_int,
1930 (LONGEST) TYPE_LENGTH (type));
1934 type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
1936 value_from_longest (builtin_type_int, (LONGEST) TYPE_LENGTH (type));
1939 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1940 return value_from_longest (builtin_type_int,
1941 (LONGEST) TYPE_LENGTH (VALUE_TYPE (val)));
1945 /* Parse a type expression in the string [P..P+LENGTH). */
1948 parse_and_eval_type (char *p, int length)
1950 char *tmp = (char *) alloca (length + 4);
1951 struct expression *expr;
1953 memcpy (tmp + 1, p, length);
1954 tmp[length + 1] = ')';
1955 tmp[length + 2] = '0';
1956 tmp[length + 3] = '\0';
1957 expr = parse_expression (tmp);
1958 if (expr->elts[0].opcode != UNOP_CAST)
1959 error ("Internal error in eval_type.");
1960 return expr->elts[1].type;
1964 calc_f77_array_dims (struct type *array_type)
1967 struct type *tmp_type;
1969 if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
1970 error ("Can't get dimensions for a non-array type");
1972 tmp_type = array_type;
1974 while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
1976 if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)