1 /* Evaluate expressions for GDB.
2 Copyright 1986, 87, 89, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
27 #include "expression.h"
31 #include "language.h" /* For CAST_IS_CONVERSION */
32 #include "f-lang.h" /* for array bound stuff */
34 /* Defined in symtab.c */
35 extern int hp_som_som_object_present;
37 /* This is defined in valops.c */
38 extern int overload_resolution;
40 /* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue
41 on with successful lookup for member/method of the rtti type. */
42 extern int objectprint;
44 /* Prototypes for local functions. */
46 static value_ptr evaluate_subexp_for_sizeof (struct expression *, int *);
48 static value_ptr evaluate_subexp_for_address (struct expression *,
51 static value_ptr evaluate_subexp (struct type *, struct expression *,
54 static char *get_label (struct expression *, int *);
57 evaluate_struct_tuple (value_ptr, struct expression *, int *,
61 init_array_element (value_ptr, value_ptr, struct expression *,
62 int *, enum noside, LONGEST, LONGEST);
64 #if defined (__GNUC__) && !__STDC__
68 evaluate_subexp (struct type *expect_type, register struct expression *exp,
69 register int *pos, enum noside noside)
71 return (*exp->language_defn->evaluate_exp) (expect_type, exp, pos, noside);
74 /* Parse the string EXP as a C expression, evaluate it,
75 and return the result as a number. */
78 parse_and_eval_address (char *exp)
80 struct expression *expr = parse_expression (exp);
81 register CORE_ADDR addr;
82 register struct cleanup *old_chain =
83 make_cleanup (free_current_contents, &expr);
85 addr = value_as_pointer (evaluate_expression (expr));
86 do_cleanups (old_chain);
90 /* Like parse_and_eval_address but takes a pointer to a char * variable
91 and advanced that variable across the characters parsed. */
94 parse_and_eval_address_1 (char **expptr)
96 struct expression *expr = parse_exp_1 (expptr, (struct block *) 0, 0);
97 register CORE_ADDR addr;
98 register struct cleanup *old_chain =
99 make_cleanup (free_current_contents, &expr);
101 addr = value_as_pointer (evaluate_expression (expr));
102 do_cleanups (old_chain);
106 /* Like parse_and_eval_address, but treats the value of the expression
107 as an integer, not an address, returns a LONGEST, not a CORE_ADDR */
109 parse_and_eval_long (char *exp)
111 struct expression *expr = parse_expression (exp);
112 register LONGEST retval;
113 register struct cleanup *old_chain =
114 make_cleanup (free_current_contents, &expr);
116 retval = value_as_long (evaluate_expression (expr));
117 do_cleanups (old_chain);
122 parse_and_eval (char *exp)
124 struct expression *expr = parse_expression (exp);
125 register value_ptr val;
126 register struct cleanup *old_chain
127 = make_cleanup (free_current_contents, &expr);
129 val = evaluate_expression (expr);
130 do_cleanups (old_chain);
134 /* Parse up to a comma (or to a closeparen)
135 in the string EXPP as an expression, evaluate it, and return the value.
136 EXPP is advanced to point to the comma. */
139 parse_to_comma_and_eval (char **expp)
141 struct expression *expr = parse_exp_1 (expp, (struct block *) 0, 1);
142 register value_ptr val;
143 register struct cleanup *old_chain
144 = make_cleanup (free_current_contents, &expr);
146 val = evaluate_expression (expr);
147 do_cleanups (old_chain);
151 /* Evaluate an expression in internal prefix form
152 such as is constructed by parse.y.
154 See expression.h for info on the format of an expression. */
157 evaluate_expression (struct expression *exp)
160 return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
163 /* Evaluate an expression, avoiding all memory references
164 and getting a value whose type alone is correct. */
167 evaluate_type (struct expression *exp)
170 return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
173 /* If the next expression is an OP_LABELED, skips past it,
174 returning the label. Otherwise, does nothing and returns NULL. */
177 get_label (register struct expression *exp, int *pos)
179 if (exp->elts[*pos].opcode == OP_LABELED)
182 char *name = &exp->elts[pc + 2].string;
183 int tem = longest_to_int (exp->elts[pc + 1].longconst);
184 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
191 /* This function evaluates tuples (in Chill) or brace-initializers
192 (in C/C++) for structure types. */
195 evaluate_struct_tuple (value_ptr struct_val, 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 value_ptr 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 Chill.
330 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND);
331 the element value is ELEMENT;
332 EXP, POS and NOSIDE are as usual.
333 Evaluates index expresions and sets the specified element(s) of
335 Returns last index value. */
338 init_array_element (value_ptr array, value_ptr element,
339 register struct expression *exp, register int *pos,
340 enum noside noside, LONGEST low_bound, LONGEST high_bound)
343 int element_size = TYPE_LENGTH (VALUE_TYPE (element));
344 if (exp->elts[*pos].opcode == BINOP_COMMA)
347 init_array_element (array, element, exp, pos, noside,
348 low_bound, high_bound);
349 return init_array_element (array, element,
350 exp, pos, noside, low_bound, high_bound);
352 else if (exp->elts[*pos].opcode == BINOP_RANGE)
356 low = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
357 high = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
358 if (low < low_bound || high > high_bound)
359 error ("tuple range index out of range");
360 for (index = low; index <= high; index++)
362 memcpy (VALUE_CONTENTS_RAW (array)
363 + (index - low_bound) * element_size,
364 VALUE_CONTENTS (element), element_size);
369 index = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
370 if (index < low_bound || index > high_bound)
371 error ("tuple index out of range");
372 memcpy (VALUE_CONTENTS_RAW (array) + (index - low_bound) * element_size,
373 VALUE_CONTENTS (element), element_size);
379 evaluate_subexp_standard (struct type *expect_type,
380 register struct expression *exp, register int *pos,
385 register int pc, pc2 = 0, oldpos;
386 register value_ptr arg1 = NULL, arg2 = NULL, arg3;
390 int upper, lower, retcode;
394 struct type **arg_types;
398 op = exp->elts[pc].opcode;
403 tem = longest_to_int (exp->elts[pc + 2].longconst);
404 (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
405 arg1 = value_struct_elt_for_reference (exp->elts[pc + 1].type,
407 exp->elts[pc + 1].type,
408 &exp->elts[pc + 3].string,
411 error ("There is no field named %s", &exp->elts[pc + 3].string);
416 return value_from_longest (exp->elts[pc + 1].type,
417 exp->elts[pc + 2].longconst);
421 return value_from_double (exp->elts[pc + 1].type,
422 exp->elts[pc + 2].doubleconst);
426 if (noside == EVAL_SKIP)
429 /* JYG: We used to just return value_zero of the symbol type
430 if we're asked to avoid side effects. Otherwise we return
431 value_of_variable (...). However I'm not sure if
432 value_of_variable () has any side effect.
433 We need a full value object returned here for whatis_exp ()
434 to call evaluate_type () and then pass the full value to
435 value_rtti_target_type () if we are dealing with a pointer
436 or reference to a base class and print object is on. */
438 return value_of_variable (exp->elts[pc + 2].symbol,
439 exp->elts[pc + 1].block);
444 access_value_history (longest_to_int (exp->elts[pc + 1].longconst));
448 int regno = longest_to_int (exp->elts[pc + 1].longconst);
449 value_ptr val = value_of_register (regno);
453 error ("Value of register %s not available.", REGISTER_NAME (regno));
459 return value_from_longest (LA_BOOL_TYPE,
460 exp->elts[pc + 1].longconst);
464 return value_of_internalvar (exp->elts[pc + 1].internalvar);
467 tem = longest_to_int (exp->elts[pc + 1].longconst);
468 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
469 if (noside == EVAL_SKIP)
471 return value_string (&exp->elts[pc + 2].string, tem);
474 tem = longest_to_int (exp->elts[pc + 1].longconst);
476 += 3 + BYTES_TO_EXP_ELEM ((tem + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT);
477 if (noside == EVAL_SKIP)
479 return value_bitstring (&exp->elts[pc + 2].string, tem);
484 tem2 = longest_to_int (exp->elts[pc + 1].longconst);
485 tem3 = longest_to_int (exp->elts[pc + 2].longconst);
486 nargs = tem3 - tem2 + 1;
487 type = expect_type ? check_typedef (expect_type) : NULL_TYPE;
489 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
490 && TYPE_CODE (type) == TYPE_CODE_STRUCT)
492 value_ptr rec = allocate_value (expect_type);
493 memset (VALUE_CONTENTS_RAW (rec), '\0', TYPE_LENGTH (type));
494 return evaluate_struct_tuple (rec, exp, pos, noside, nargs);
497 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
498 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
500 struct type *range_type = TYPE_FIELD_TYPE (type, 0);
501 struct type *element_type = TYPE_TARGET_TYPE (type);
502 value_ptr array = allocate_value (expect_type);
503 int element_size = TYPE_LENGTH (check_typedef (element_type));
504 LONGEST low_bound, high_bound, index;
505 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
508 high_bound = (TYPE_LENGTH (type) / element_size) - 1;
511 memset (VALUE_CONTENTS_RAW (array), 0, TYPE_LENGTH (expect_type));
512 for (tem = nargs; --nargs >= 0;)
516 if (exp->elts[*pos].opcode == BINOP_RANGE)
519 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
521 element = evaluate_subexp (element_type, exp, pos, noside);
522 if (VALUE_TYPE (element) != element_type)
523 element = value_cast (element_type, element);
526 int continue_pc = *pos;
528 index = init_array_element (array, element, exp, pos, noside,
529 low_bound, high_bound);
534 if (index > high_bound)
535 /* to avoid memory corruption */
536 error ("Too many array elements");
537 memcpy (VALUE_CONTENTS_RAW (array)
538 + (index - low_bound) * element_size,
539 VALUE_CONTENTS (element),
547 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
548 && TYPE_CODE (type) == TYPE_CODE_SET)
550 value_ptr set = allocate_value (expect_type);
551 char *valaddr = VALUE_CONTENTS_RAW (set);
552 struct type *element_type = TYPE_INDEX_TYPE (type);
553 struct type *check_type = element_type;
554 LONGEST low_bound, high_bound;
556 /* get targettype of elementtype */
557 while (TYPE_CODE (check_type) == TYPE_CODE_RANGE ||
558 TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
559 check_type = TYPE_TARGET_TYPE (check_type);
561 if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
562 error ("(power)set type with unknown size");
563 memset (valaddr, '\0', TYPE_LENGTH (type));
564 for (tem = 0; tem < nargs; tem++)
566 LONGEST range_low, range_high;
567 struct type *range_low_type, *range_high_type;
569 if (exp->elts[*pos].opcode == BINOP_RANGE)
572 elem_val = evaluate_subexp (element_type, exp, pos, noside);
573 range_low_type = VALUE_TYPE (elem_val);
574 range_low = value_as_long (elem_val);
575 elem_val = evaluate_subexp (element_type, exp, pos, noside);
576 range_high_type = VALUE_TYPE (elem_val);
577 range_high = value_as_long (elem_val);
581 elem_val = evaluate_subexp (element_type, exp, pos, noside);
582 range_low_type = range_high_type = VALUE_TYPE (elem_val);
583 range_low = range_high = value_as_long (elem_val);
585 /* check types of elements to avoid mixture of elements from
586 different types. Also check if type of element is "compatible"
587 with element type of powerset */
588 if (TYPE_CODE (range_low_type) == TYPE_CODE_RANGE)
589 range_low_type = TYPE_TARGET_TYPE (range_low_type);
590 if (TYPE_CODE (range_high_type) == TYPE_CODE_RANGE)
591 range_high_type = TYPE_TARGET_TYPE (range_high_type);
592 if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type)) ||
593 (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM &&
594 (range_low_type != range_high_type)))
595 /* different element modes */
596 error ("POWERSET tuple elements of different mode");
597 if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type)) ||
598 (TYPE_CODE (check_type) == TYPE_CODE_ENUM &&
599 range_low_type != check_type))
600 error ("incompatible POWERSET tuple elements");
601 if (range_low > range_high)
603 warning ("empty POWERSET tuple range");
606 if (range_low < low_bound || range_high > high_bound)
607 error ("POWERSET tuple element out of range");
608 range_low -= low_bound;
609 range_high -= low_bound;
610 for (; range_low <= range_high; range_low++)
612 int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;
614 bit_index = TARGET_CHAR_BIT - 1 - bit_index;
615 valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
622 argvec = (value_ptr *) alloca (sizeof (value_ptr) * nargs);
623 for (tem = 0; tem < nargs; tem++)
625 /* Ensure that array expressions are coerced into pointer objects. */
626 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
628 if (noside == EVAL_SKIP)
630 return value_array (tem2, tem3, argvec);
634 value_ptr array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
636 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
638 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
639 if (noside == EVAL_SKIP)
641 return value_slice (array, lowbound, upper - lowbound + 1);
644 case TERNOP_SLICE_COUNT:
646 value_ptr array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
648 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
650 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
651 return value_slice (array, lowbound, length);
655 /* Skip third and second args to evaluate the first one. */
656 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
657 if (value_logical_not (arg1))
659 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
660 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
664 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
665 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
671 op = exp->elts[*pos].opcode;
672 nargs = longest_to_int (exp->elts[pc + 1].longconst);
673 /* Allocate arg vector, including space for the function to be
674 called in argvec[0] and a terminating NULL */
675 argvec = (value_ptr *) alloca (sizeof (value_ptr) * (nargs + 3));
676 if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
680 /* 1997-08-01 Currently we do not support function invocation
681 via pointers-to-methods with HP aCC. Pointer does not point
682 to the function, but possibly to some thunk. */
683 if (hp_som_som_object_present)
685 error ("Not implemented: function invocation through pointer to method with HP aCC");
689 /* First, evaluate the structure into arg2 */
692 if (noside == EVAL_SKIP)
695 if (op == STRUCTOP_MEMBER)
697 arg2 = evaluate_subexp_for_address (exp, pos, noside);
701 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
704 /* If the function is a virtual function, then the
705 aggregate value (providing the structure) plays
706 its part by providing the vtable. Otherwise,
707 it is just along for the ride: call the function
710 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
712 fnptr = value_as_long (arg1);
714 if (METHOD_PTR_IS_VIRTUAL (fnptr))
716 int fnoffset = METHOD_PTR_TO_VOFFSET (fnptr);
717 struct type *basetype;
718 struct type *domain_type =
719 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)));
721 basetype = TYPE_TARGET_TYPE (VALUE_TYPE (arg2));
722 if (domain_type != basetype)
723 arg2 = value_cast (lookup_pointer_type (domain_type), arg2);
724 basetype = TYPE_VPTR_BASETYPE (domain_type);
725 for (i = TYPE_NFN_FIELDS (basetype) - 1; i >= 0; i--)
727 struct fn_field *f = TYPE_FN_FIELDLIST1 (basetype, i);
728 /* If one is virtual, then all are virtual. */
729 if (TYPE_FN_FIELD_VIRTUAL_P (f, 0))
730 for (j = TYPE_FN_FIELDLIST_LENGTH (basetype, i) - 1; j >= 0; --j)
731 if ((int) TYPE_FN_FIELD_VOFFSET (f, j) == fnoffset)
733 value_ptr temp = value_ind (arg2);
734 arg1 = value_virtual_fn_field (&temp, f, j, domain_type, 0);
735 arg2 = value_addr (temp);
740 error ("virtual function at index %d not found", fnoffset);
744 VALUE_TYPE (arg1) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)));
748 /* Now, say which argument to start evaluating from */
751 else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
753 /* Hair for method invocations */
757 /* First, evaluate the structure into arg2 */
759 tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
760 *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);
761 if (noside == EVAL_SKIP)
764 if (op == STRUCTOP_STRUCT)
766 /* If v is a variable in a register, and the user types
767 v.method (), this will produce an error, because v has
770 A possible way around this would be to allocate a
771 copy of the variable on the stack, copy in the
772 contents, call the function, and copy out the
773 contents. I.e. convert this from call by reference
774 to call by copy-return (or whatever it's called).
775 However, this does not work because it is not the
776 same: the method being called could stash a copy of
777 the address, and then future uses through that address
778 (after the method returns) would be expected to
779 use the variable itself, not some copy of it. */
780 arg2 = evaluate_subexp_for_address (exp, pos, noside);
784 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
786 /* Now, say which argument to start evaluating from */
791 /* Non-method function call */
793 argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
795 type = VALUE_TYPE (argvec[0]);
796 if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
797 type = TYPE_TARGET_TYPE (type);
798 if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
800 for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
802 /* pai: FIXME This seems to be coercing arguments before
803 * overload resolution has been done! */
804 argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type, tem - 1),
810 /* Evaluate arguments */
811 for (; tem <= nargs; tem++)
813 /* Ensure that array expressions are coerced into pointer objects. */
814 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
817 /* signal end of arglist */
820 if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
823 value_ptr temp = arg2;
826 /* Method invocation : stuff "this" as first parameter */
827 /* pai: this used to have lookup_pointer_type for some reason,
828 * but temp is already a pointer to the object */
830 = value_from_pointer (VALUE_TYPE (temp),
831 VALUE_ADDRESS (temp) + VALUE_OFFSET (temp));
832 /* Name of method from expression */
833 strcpy (tstr, &exp->elts[pc2 + 2].string);
835 if (overload_resolution && (exp->language_defn->la_language == language_cplus))
837 /* Language is C++, do some overload resolution before evaluation */
838 value_ptr valp = NULL;
840 /* Prepare list of argument types for overload resolution */
841 arg_types = (struct type **) xmalloc (nargs * (sizeof (struct type *)));
842 for (ix = 1; ix <= nargs; ix++)
843 arg_types[ix - 1] = VALUE_TYPE (argvec[ix]);
845 (void) find_overload_match (arg_types, nargs, tstr,
846 1 /* method */ , 0 /* strict match */ ,
847 arg2 /* the object */ , NULL,
848 &valp, NULL, &static_memfuncp);
851 argvec[1] = arg2; /* the ``this'' pointer */
852 argvec[0] = valp; /* use the method found after overload resolution */
855 /* Non-C++ case -- or no overload resolution */
858 argvec[0] = value_struct_elt (&temp, argvec + 1, tstr,
860 op == STRUCTOP_STRUCT
861 ? "structure" : "structure pointer");
862 argvec[1] = arg2; /* the ``this'' pointer */
867 argvec[1] = argvec[0];
872 else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
877 else if (op == OP_VAR_VALUE)
879 /* Non-member function being called */
880 /* fn: This can only be done for C++ functions. A C-style function
881 in a C++ program, for instance, does not have the fields that
884 if (overload_resolution && (exp->language_defn->la_language == language_cplus))
886 /* Language is C++, do some overload resolution before evaluation */
889 /* Prepare list of argument types for overload resolution */
890 arg_types = (struct type **) xmalloc (nargs * (sizeof (struct type *)));
891 for (ix = 1; ix <= nargs; ix++)
892 arg_types[ix - 1] = VALUE_TYPE (argvec[ix]);
894 (void) find_overload_match (arg_types, nargs, NULL /* no need for name */ ,
895 0 /* not method */ , 0 /* strict match */ ,
896 NULL, exp->elts[save_pos1+2].symbol /* the function */ ,
899 /* Now fix the expression being evaluated */
900 exp->elts[save_pos1+2].symbol = symp;
901 argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
905 /* Not C++, or no overload resolution allowed */
906 /* nothing to be done; argvec already correctly set up */
911 /* It is probably a C-style function */
912 /* nothing to be done; argvec already correctly set up */
917 if (noside == EVAL_SKIP)
919 if (noside == EVAL_AVOID_SIDE_EFFECTS)
921 /* If the return type doesn't look like a function type, call an
922 error. This can happen if somebody tries to turn a variable into
923 a function call. This is here because people often want to
924 call, eg, strcmp, which gdb doesn't know is a function. If
925 gdb isn't asked for it's opinion (ie. through "whatis"),
926 it won't offer it. */
929 TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0]));
932 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0])));
934 error ("Expression of type other than \"Function returning ...\" used as function");
936 if (argvec[0] == NULL)
937 error ("Cannot evaluate function -- may be inlined");
938 return call_function_by_hand (argvec[0], nargs, argvec + 1);
939 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
941 case OP_F77_UNDETERMINED_ARGLIST:
943 /* Remember that in F77, functions, substring ops and
944 array subscript operations cannot be disambiguated
945 at parse time. We have made all array subscript operations,
946 substring operations as well as function calls come here
947 and we now have to discover what the heck this thing actually was.
948 If it is a function, we process just as if we got an OP_FUNCALL. */
950 nargs = longest_to_int (exp->elts[pc + 1].longconst);
953 /* First determine the type code we are dealing with. */
954 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
955 type = check_typedef (VALUE_TYPE (arg1));
956 code = TYPE_CODE (type);
960 case TYPE_CODE_ARRAY:
961 goto multi_f77_subscript;
963 case TYPE_CODE_STRING:
968 /* It's a function call. */
969 /* Allocate arg vector, including space for the function to be
970 called in argvec[0] and a terminating NULL */
971 argvec = (value_ptr *) alloca (sizeof (value_ptr) * (nargs + 2));
974 for (; tem <= nargs; tem++)
975 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
976 argvec[tem] = 0; /* signal end of arglist */
980 error ("Cannot perform substring on this type");
984 /* We have a substring operation on our hands here,
985 let us get the string we will be dealing with */
987 /* Now evaluate the 'from' and 'to' */
989 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
992 return value_subscript (arg1, arg2);
994 arg3 = evaluate_subexp_with_coercion (exp, pos, noside);
996 if (noside == EVAL_SKIP)
999 tem2 = value_as_long (arg2);
1000 tem3 = value_as_long (arg3);
1002 return value_slice (arg1, tem2, tem3 - tem2 + 1);
1005 /* We have a complex number, There should be 2 floating
1006 point numbers that compose it */
1007 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1008 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1010 return value_literal_complex (arg1, arg2, builtin_type_f_complex_s16);
1012 case STRUCTOP_STRUCT:
1013 tem = longest_to_int (exp->elts[pc + 1].longconst);
1014 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1015 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1016 if (noside == EVAL_SKIP)
1018 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1019 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1),
1020 &exp->elts[pc + 2].string,
1025 value_ptr temp = arg1;
1026 return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
1031 tem = longest_to_int (exp->elts[pc + 1].longconst);
1032 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1033 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1034 if (noside == EVAL_SKIP)
1037 /* JYG: if print object is on we need to replace the base type
1038 with rtti type in order to continue on with successful
1039 lookup of member / method only available in the rtti type. */
1041 struct type *type = VALUE_TYPE (arg1);
1042 struct type *real_type;
1043 int full, top, using_enc;
1045 if (objectprint && TYPE_TARGET_TYPE(type) &&
1046 (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
1048 real_type = value_rtti_target_type (arg1, &full, &top, &using_enc);
1051 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1052 real_type = lookup_pointer_type (real_type);
1054 real_type = lookup_reference_type (real_type);
1056 arg1 = value_cast (real_type, arg1);
1061 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1062 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1),
1063 &exp->elts[pc + 2].string,
1068 value_ptr temp = arg1;
1069 return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
1070 NULL, "structure pointer");
1073 case STRUCTOP_MEMBER:
1074 arg1 = evaluate_subexp_for_address (exp, pos, noside);
1075 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1077 /* With HP aCC, pointers to methods do not point to the function code */
1078 if (hp_som_som_object_present &&
1079 (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_PTR) &&
1080 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) == TYPE_CODE_METHOD))
1081 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1083 mem_offset = value_as_long (arg2);
1084 goto handle_pointer_to_member;
1087 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1088 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1090 /* With HP aCC, pointers to methods do not point to the function code */
1091 if (hp_som_som_object_present &&
1092 (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_PTR) &&
1093 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) == TYPE_CODE_METHOD))
1094 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1096 mem_offset = value_as_long (arg2);
1098 handle_pointer_to_member:
1099 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1100 a real offset to the member. */
1101 if (hp_som_som_object_present)
1103 if (!mem_offset) /* no bias -> really null */
1104 error ("Attempted dereference of null pointer-to-member");
1105 mem_offset &= ~0x20000000;
1107 if (noside == EVAL_SKIP)
1109 type = check_typedef (VALUE_TYPE (arg2));
1110 if (TYPE_CODE (type) != TYPE_CODE_PTR)
1111 goto bad_pointer_to_member;
1112 type = check_typedef (TYPE_TARGET_TYPE (type));
1113 if (TYPE_CODE (type) == TYPE_CODE_METHOD)
1114 error ("not implemented: pointer-to-method in pointer-to-member construct");
1115 if (TYPE_CODE (type) != TYPE_CODE_MEMBER)
1116 goto bad_pointer_to_member;
1117 /* Now, convert these values to an address. */
1118 arg1 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
1120 arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
1121 value_as_long (arg1) + mem_offset);
1122 return value_ind (arg3);
1123 bad_pointer_to_member:
1124 error ("non-pointer-to-member value used in pointer-to-member construct");
1127 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1128 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1129 if (noside == EVAL_SKIP)
1131 if (binop_user_defined_p (op, arg1, arg2))
1132 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1134 return value_concat (arg1, arg2);
1137 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1138 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1140 /* Do special stuff for HP aCC pointers to members */
1141 if (hp_som_som_object_present)
1143 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1144 the implementation yet; but the pointer appears to point to a code
1145 sequence (thunk) in memory -- in any case it is *not* the address
1146 of the function as it would be in a naive implementation. */
1147 if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR) &&
1148 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_METHOD))
1149 error ("Assignment to pointers to methods not implemented with HP aCC");
1151 /* HP aCC pointers to data members require a constant bias */
1152 if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR) &&
1153 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_MEMBER))
1155 unsigned int *ptr = (unsigned int *) VALUE_CONTENTS (arg2); /* forces evaluation */
1156 *ptr |= 0x20000000; /* set 29th bit */
1160 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1162 if (binop_user_defined_p (op, arg1, arg2))
1163 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1165 return value_assign (arg1, arg2);
1167 case BINOP_ASSIGN_MODIFY:
1169 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1170 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1171 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1173 op = exp->elts[pc + 1].opcode;
1174 if (binop_user_defined_p (op, arg1, arg2))
1175 return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
1176 else if (op == BINOP_ADD)
1177 arg2 = value_add (arg1, arg2);
1178 else if (op == BINOP_SUB)
1179 arg2 = value_sub (arg1, arg2);
1181 arg2 = value_binop (arg1, arg2, op);
1182 return value_assign (arg1, arg2);
1185 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1186 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1187 if (noside == EVAL_SKIP)
1189 if (binop_user_defined_p (op, arg1, arg2))
1190 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1192 return value_add (arg1, arg2);
1195 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1196 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1197 if (noside == EVAL_SKIP)
1199 if (binop_user_defined_p (op, arg1, arg2))
1200 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1202 return value_sub (arg1, arg2);
1210 case BINOP_BITWISE_AND:
1211 case BINOP_BITWISE_IOR:
1212 case BINOP_BITWISE_XOR:
1213 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1214 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1215 if (noside == EVAL_SKIP)
1217 if (binop_user_defined_p (op, arg1, arg2))
1218 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1219 else if (noside == EVAL_AVOID_SIDE_EFFECTS
1220 && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
1221 return value_zero (VALUE_TYPE (arg1), not_lval);
1223 return value_binop (arg1, arg2, op);
1226 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1227 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1228 if (noside == EVAL_SKIP)
1230 error ("':' operator used in invalid context");
1232 case BINOP_SUBSCRIPT:
1233 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1234 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1235 if (noside == EVAL_SKIP)
1237 if (binop_user_defined_p (op, arg1, arg2))
1238 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1241 /* If the user attempts to subscript something that is not an
1242 array or pointer type (like a plain int variable for example),
1243 then report this as an error. */
1246 type = check_typedef (VALUE_TYPE (arg1));
1247 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
1248 && TYPE_CODE (type) != TYPE_CODE_PTR)
1250 if (TYPE_NAME (type))
1251 error ("cannot subscript something of type `%s'",
1254 error ("cannot subscript requested type");
1257 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1258 return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
1260 return value_subscript (arg1, arg2);
1264 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1265 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1266 if (noside == EVAL_SKIP)
1268 return value_in (arg1, arg2);
1270 case MULTI_SUBSCRIPT:
1272 nargs = longest_to_int (exp->elts[pc + 1].longconst);
1273 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1276 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1277 /* FIXME: EVAL_SKIP handling may not be correct. */
1278 if (noside == EVAL_SKIP)
1289 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1290 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1292 /* If the user attempts to subscript something that has no target
1293 type (like a plain int variable for example), then report this
1296 type = TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (arg1)));
1299 arg1 = value_zero (type, VALUE_LVAL (arg1));
1305 error ("cannot subscript something of type `%s'",
1306 TYPE_NAME (VALUE_TYPE (arg1)));
1310 if (binop_user_defined_p (op, arg1, arg2))
1312 arg1 = value_x_binop (arg1, arg2, op, OP_NULL, noside);
1316 arg1 = value_subscript (arg1, arg2);
1321 multi_f77_subscript:
1323 int subscript_array[MAX_FORTRAN_DIMS + 1]; /* 1-based array of
1324 subscripts, max == 7 */
1325 int array_size_array[MAX_FORTRAN_DIMS + 1];
1326 int ndimensions = 1, i;
1327 struct type *tmp_type;
1328 int offset_item; /* The array offset where the item lives */
1330 if (nargs > MAX_FORTRAN_DIMS)
1331 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS);
1333 tmp_type = check_typedef (VALUE_TYPE (arg1));
1334 ndimensions = calc_f77_array_dims (type);
1336 if (nargs != ndimensions)
1337 error ("Wrong number of subscripts");
1339 /* Now that we know we have a legal array subscript expression
1340 let us actually find out where this element exists in the array. */
1343 for (i = 1; i <= nargs; i++)
1345 /* Evaluate each subscript, It must be a legal integer in F77 */
1346 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1348 /* Fill in the subscript and array size arrays */
1350 subscript_array[i] = value_as_long (arg2);
1352 retcode = f77_get_dynamic_upperbound (tmp_type, &upper);
1353 if (retcode == BOUND_FETCH_ERROR)
1354 error ("Cannot obtain dynamic upper bound");
1356 retcode = f77_get_dynamic_lowerbound (tmp_type, &lower);
1357 if (retcode == BOUND_FETCH_ERROR)
1358 error ("Cannot obtain dynamic lower bound");
1360 array_size_array[i] = upper - lower + 1;
1362 /* Zero-normalize subscripts so that offsetting will work. */
1364 subscript_array[i] -= lower;
1366 /* If we are at the bottom of a multidimensional
1367 array type then keep a ptr to the last ARRAY
1368 type around for use when calling value_subscript()
1369 below. This is done because we pretend to value_subscript
1370 that we actually have a one-dimensional array
1371 of base element type that we apply a simple
1375 tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
1378 /* Now let us calculate the offset for this item */
1380 offset_item = subscript_array[ndimensions];
1382 for (i = ndimensions - 1; i >= 1; i--)
1384 array_size_array[i] * offset_item + subscript_array[i];
1386 /* Construct a value node with the value of the offset */
1388 arg2 = value_from_longest (builtin_type_f_integer, offset_item);
1390 /* Let us now play a dirty trick: we will take arg1
1391 which is a value node pointing to the topmost level
1392 of the multidimensional array-set and pretend
1393 that it is actually a array of the final element
1394 type, this will ensure that value_subscript()
1395 returns the correct type value */
1397 VALUE_TYPE (arg1) = tmp_type;
1398 return value_ind (value_add (value_coerce_array (arg1), arg2));
1401 case BINOP_LOGICAL_AND:
1402 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1403 if (noside == EVAL_SKIP)
1405 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1410 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1413 if (binop_user_defined_p (op, arg1, arg2))
1415 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1416 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1420 tem = value_logical_not (arg1);
1421 arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
1422 (tem ? EVAL_SKIP : noside));
1423 return value_from_longest (LA_BOOL_TYPE,
1424 (LONGEST) (!tem && !value_logical_not (arg2)));
1427 case BINOP_LOGICAL_OR:
1428 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1429 if (noside == EVAL_SKIP)
1431 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1436 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1439 if (binop_user_defined_p (op, arg1, arg2))
1441 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1442 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1446 tem = value_logical_not (arg1);
1447 arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
1448 (!tem ? EVAL_SKIP : noside));
1449 return value_from_longest (LA_BOOL_TYPE,
1450 (LONGEST) (!tem || !value_logical_not (arg2)));
1454 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1455 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1456 if (noside == EVAL_SKIP)
1458 if (binop_user_defined_p (op, arg1, arg2))
1460 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1464 tem = value_equal (arg1, arg2);
1465 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1468 case BINOP_NOTEQUAL:
1469 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1470 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1471 if (noside == EVAL_SKIP)
1473 if (binop_user_defined_p (op, arg1, arg2))
1475 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1479 tem = value_equal (arg1, arg2);
1480 return value_from_longest (LA_BOOL_TYPE, (LONGEST) ! tem);
1484 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1485 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1486 if (noside == EVAL_SKIP)
1488 if (binop_user_defined_p (op, arg1, arg2))
1490 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1494 tem = value_less (arg1, arg2);
1495 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1499 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1500 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1501 if (noside == EVAL_SKIP)
1503 if (binop_user_defined_p (op, arg1, arg2))
1505 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1509 tem = value_less (arg2, arg1);
1510 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1514 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1515 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1516 if (noside == EVAL_SKIP)
1518 if (binop_user_defined_p (op, arg1, arg2))
1520 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1524 tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
1525 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1529 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1530 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
1531 if (noside == EVAL_SKIP)
1533 if (binop_user_defined_p (op, arg1, arg2))
1535 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1539 tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
1540 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1544 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1545 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1546 if (noside == EVAL_SKIP)
1548 type = check_typedef (VALUE_TYPE (arg2));
1549 if (TYPE_CODE (type) != TYPE_CODE_INT)
1550 error ("Non-integral right operand for \"@\" operator.");
1551 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1553 return allocate_repeat_value (VALUE_TYPE (arg1),
1554 longest_to_int (value_as_long (arg2)));
1557 return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
1560 evaluate_subexp (NULL_TYPE, exp, pos, noside);
1561 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
1564 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1565 if (noside == EVAL_SKIP)
1567 if (unop_user_defined_p (op, arg1))
1568 return value_x_unop (arg1, op, noside);
1570 return value_neg (arg1);
1572 case UNOP_COMPLEMENT:
1573 /* C++: check for and handle destructor names. */
1574 op = exp->elts[*pos].opcode;
1576 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1577 if (noside == EVAL_SKIP)
1579 if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
1580 return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
1582 return value_complement (arg1);
1584 case UNOP_LOGICAL_NOT:
1585 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1586 if (noside == EVAL_SKIP)
1588 if (unop_user_defined_p (op, arg1))
1589 return value_x_unop (arg1, op, noside);
1591 return value_from_longest (LA_BOOL_TYPE,
1592 (LONGEST) value_logical_not (arg1));
1595 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
1596 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
1597 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1598 if ((TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) &&
1599 ((TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_METHOD) ||
1600 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_MEMBER)))
1601 error ("Attempt to dereference pointer to member without an object");
1602 if (noside == EVAL_SKIP)
1604 if (unop_user_defined_p (op, arg1))
1605 return value_x_unop (arg1, op, noside);
1606 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1608 type = check_typedef (VALUE_TYPE (arg1));
1609 if (TYPE_CODE (type) == TYPE_CODE_PTR
1610 || TYPE_CODE (type) == TYPE_CODE_REF
1611 /* In C you can dereference an array to get the 1st elt. */
1612 || TYPE_CODE (type) == TYPE_CODE_ARRAY
1614 return value_zero (TYPE_TARGET_TYPE (type),
1616 else if (TYPE_CODE (type) == TYPE_CODE_INT)
1617 /* GDB allows dereferencing an int. */
1618 return value_zero (builtin_type_int, lval_memory);
1620 error ("Attempt to take contents of a non-pointer value.");
1622 return value_ind (arg1);
1625 /* C++: check for and handle pointer to members. */
1627 op = exp->elts[*pos].opcode;
1629 if (noside == EVAL_SKIP)
1633 int temm = longest_to_int (exp->elts[pc + 3].longconst);
1634 (*pos) += 3 + BYTES_TO_EXP_ELEM (temm + 1);
1637 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
1642 value_ptr retvalp = evaluate_subexp_for_address (exp, pos, noside);
1643 /* If HP aCC object, use bias for pointers to members */
1644 if (hp_som_som_object_present &&
1645 (TYPE_CODE (VALUE_TYPE (retvalp)) == TYPE_CODE_PTR) &&
1646 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (retvalp))) == TYPE_CODE_MEMBER))
1648 unsigned int *ptr = (unsigned int *) VALUE_CONTENTS (retvalp); /* forces evaluation */
1649 *ptr |= 0x20000000; /* set 29th bit */
1655 if (noside == EVAL_SKIP)
1657 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
1660 return evaluate_subexp_for_sizeof (exp, pos);
1664 type = exp->elts[pc + 1].type;
1665 arg1 = evaluate_subexp (type, exp, pos, noside);
1666 if (noside == EVAL_SKIP)
1668 if (type != VALUE_TYPE (arg1))
1669 arg1 = value_cast (type, arg1);
1674 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1675 if (noside == EVAL_SKIP)
1677 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1678 return value_zero (exp->elts[pc + 1].type, lval_memory);
1680 return value_at_lazy (exp->elts[pc + 1].type,
1681 value_as_pointer (arg1),
1684 case UNOP_PREINCREMENT:
1685 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1686 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1688 else if (unop_user_defined_p (op, arg1))
1690 return value_x_unop (arg1, op, noside);
1694 arg2 = value_add (arg1, value_from_longest (builtin_type_char,
1696 return value_assign (arg1, arg2);
1699 case UNOP_PREDECREMENT:
1700 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1701 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1703 else if (unop_user_defined_p (op, arg1))
1705 return value_x_unop (arg1, op, noside);
1709 arg2 = value_sub (arg1, value_from_longest (builtin_type_char,
1711 return value_assign (arg1, arg2);
1714 case UNOP_POSTINCREMENT:
1715 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1716 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1718 else if (unop_user_defined_p (op, arg1))
1720 return value_x_unop (arg1, op, noside);
1724 arg2 = value_add (arg1, value_from_longest (builtin_type_char,
1726 value_assign (arg1, arg2);
1730 case UNOP_POSTDECREMENT:
1731 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1732 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1734 else if (unop_user_defined_p (op, arg1))
1736 return value_x_unop (arg1, op, noside);
1740 arg2 = value_sub (arg1, value_from_longest (builtin_type_char,
1742 value_assign (arg1, arg2);
1748 return value_of_this (1);
1751 error ("Attempt to use a type name as an expression");
1754 /* Removing this case and compiling with gcc -Wall reveals that
1755 a lot of cases are hitting this case. Some of these should
1756 probably be removed from expression.h; others are legitimate
1757 expressions which are (apparently) not fully implemented.
1759 If there are any cases landing here which mean a user error,
1760 then they should be separate cases, with more descriptive
1764 GDB does not (yet) know how to evaluate that kind of expression");
1768 return value_from_longest (builtin_type_long, (LONGEST) 1);
1771 /* Evaluate a subexpression of EXP, at index *POS,
1772 and return the address of that subexpression.
1773 Advance *POS over the subexpression.
1774 If the subexpression isn't an lvalue, get an error.
1775 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1776 then only the type of the result need be correct. */
1779 evaluate_subexp_for_address (register struct expression *exp, register int *pos,
1787 op = exp->elts[pc].opcode;
1793 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
1797 return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
1798 evaluate_subexp (NULL_TYPE, exp, pos, noside));
1801 var = exp->elts[pc + 2].symbol;
1803 /* C++: The "address" of a reference should yield the address
1804 * of the object pointed to. Let value_addr() deal with it. */
1805 if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
1809 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1812 lookup_pointer_type (SYMBOL_TYPE (var));
1813 enum address_class sym_class = SYMBOL_CLASS (var);
1815 if (sym_class == LOC_CONST
1816 || sym_class == LOC_CONST_BYTES
1817 || sym_class == LOC_REGISTER
1818 || sym_class == LOC_REGPARM)
1819 error ("Attempt to take address of register or constant.");
1822 value_zero (type, not_lval);
1828 block_innermost_frame (exp->elts[pc + 1].block));
1832 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1834 value_ptr x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1835 if (VALUE_LVAL (x) == lval_memory)
1836 return value_zero (lookup_pointer_type (VALUE_TYPE (x)),
1839 error ("Attempt to take address of non-lval");
1841 return value_addr (evaluate_subexp (NULL_TYPE, exp, pos, noside));
1845 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1846 When used in contexts where arrays will be coerced anyway, this is
1847 equivalent to `evaluate_subexp' but much faster because it avoids
1848 actually fetching array contents (perhaps obsolete now that we have
1851 Note that we currently only do the coercion for C expressions, where
1852 arrays are zero based and the coercion is correct. For other languages,
1853 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1854 to decide if coercion is appropriate.
1859 evaluate_subexp_with_coercion (register struct expression *exp,
1860 register int *pos, enum noside noside)
1862 register enum exp_opcode op;
1864 register value_ptr val;
1868 op = exp->elts[pc].opcode;
1873 var = exp->elts[pc + 2].symbol;
1874 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var))) == TYPE_CODE_ARRAY
1875 && CAST_IS_CONVERSION)
1880 (var, block_innermost_frame (exp->elts[pc + 1].block));
1881 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var)))),
1887 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
1891 /* Evaluate a subexpression of EXP, at index *POS,
1892 and return a value for the size of that subexpression.
1893 Advance *POS over the subexpression. */
1896 evaluate_subexp_for_sizeof (register struct expression *exp, register int *pos)
1904 op = exp->elts[pc].opcode;
1908 /* This case is handled specially
1909 so that we avoid creating a value for the result type.
1910 If the result type is very big, it's desirable not to
1911 create a value unnecessarily. */
1914 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1915 type = check_typedef (VALUE_TYPE (val));
1916 if (TYPE_CODE (type) != TYPE_CODE_PTR
1917 && TYPE_CODE (type) != TYPE_CODE_REF
1918 && TYPE_CODE (type) != TYPE_CODE_ARRAY)
1919 error ("Attempt to take contents of a non-pointer value.");
1920 type = check_typedef (TYPE_TARGET_TYPE (type));
1921 return value_from_longest (builtin_type_int, (LONGEST)
1922 TYPE_LENGTH (type));
1926 type = check_typedef (exp->elts[pc + 1].type);
1927 return value_from_longest (builtin_type_int,
1928 (LONGEST) TYPE_LENGTH (type));
1932 type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
1934 value_from_longest (builtin_type_int, (LONGEST) TYPE_LENGTH (type));
1937 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1938 return value_from_longest (builtin_type_int,
1939 (LONGEST) TYPE_LENGTH (VALUE_TYPE (val)));
1943 /* Parse a type expression in the string [P..P+LENGTH). */
1946 parse_and_eval_type (char *p, int length)
1948 char *tmp = (char *) alloca (length + 4);
1949 struct expression *expr;
1951 memcpy (tmp + 1, p, length);
1952 tmp[length + 1] = ')';
1953 tmp[length + 2] = '0';
1954 tmp[length + 3] = '\0';
1955 expr = parse_expression (tmp);
1956 if (expr->elts[0].opcode != UNOP_CAST)
1957 error ("Internal error in eval_type.");
1958 return expr->elts[1].type;
1962 calc_f77_array_dims (struct type *array_type)
1965 struct type *tmp_type;
1967 if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
1968 error ("Can't get dimensions for a non-array type");
1970 tmp_type = array_type;
1972 while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
1974 if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)