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, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
26 #include "expression.h"
30 #include "language.h" /* For CAST_IS_CONVERSION */
31 #include "f-lang.h" /* for array bound stuff */
33 /* Defined in symtab.c */
34 extern int hp_som_som_object_present
;
36 /* This is defined in valops.c */
37 extern int overload_resolution
;
40 /* Prototypes for local functions. */
42 static value_ptr evaluate_subexp_for_sizeof
PARAMS ((struct expression
*,
45 static value_ptr evaluate_subexp_for_address
PARAMS ((struct expression
*,
48 static value_ptr evaluate_subexp
PARAMS ((struct type
*, struct expression
*,
51 static char *get_label
PARAMS ((struct expression
*, int *));
54 evaluate_struct_tuple
PARAMS ((value_ptr
, struct expression
*, int *,
58 init_array_element
PARAMS ((value_ptr
, value_ptr
, struct expression
*,
59 int *, enum noside
, LONGEST
, LONGEST
));
65 evaluate_subexp (expect_type
, exp
, pos
, noside
)
66 struct type
*expect_type
;
67 register struct expression
*exp
;
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 (exp
)
81 struct expression
*expr
= parse_expression (exp
);
82 register CORE_ADDR addr
;
83 register struct cleanup
*old_chain
=
84 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
86 addr
= value_as_pointer (evaluate_expression (expr
));
87 do_cleanups (old_chain
);
91 /* Like parse_and_eval_address but takes a pointer to a char * variable
92 and advanced that variable across the characters parsed. */
95 parse_and_eval_address_1 (expptr
)
98 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*)0, 0);
99 register CORE_ADDR addr
;
100 register struct cleanup
*old_chain
=
101 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
103 addr
= value_as_pointer (evaluate_expression (expr
));
104 do_cleanups (old_chain
);
112 struct expression
*expr
= parse_expression (exp
);
113 register value_ptr val
;
114 register struct cleanup
*old_chain
115 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
117 val
= evaluate_expression (expr
);
118 do_cleanups (old_chain
);
122 /* Parse up to a comma (or to a closeparen)
123 in the string EXPP as an expression, evaluate it, and return the value.
124 EXPP is advanced to point to the comma. */
127 parse_to_comma_and_eval (expp
)
130 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
131 register value_ptr val
;
132 register struct cleanup
*old_chain
133 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
135 val
= evaluate_expression (expr
);
136 do_cleanups (old_chain
);
140 /* Evaluate an expression in internal prefix form
141 such as is constructed by parse.y.
143 See expression.h for info on the format of an expression. */
146 evaluate_expression (exp
)
147 struct expression
*exp
;
150 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
153 /* Evaluate an expression, avoiding all memory references
154 and getting a value whose type alone is correct. */
158 struct expression
*exp
;
161 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
164 /* If the next expression is an OP_LABELED, skips past it,
165 returning the label. Otherwise, does nothing and returns NULL. */
169 register struct expression
*exp
;
172 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
175 char *name
= &exp
->elts
[pc
+ 2].string
;
176 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
177 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
184 /* This function evaluates tupes (in Chill) or brace-initializers
185 (in C/C++) for structure types. */
188 evaluate_struct_tuple (struct_val
, exp
, pos
, noside
, nargs
)
189 value_ptr struct_val
;
190 register struct expression
*exp
;
195 struct type
*struct_type
= check_typedef (VALUE_TYPE (struct_val
));
196 struct type
*substruct_type
= struct_type
;
197 struct type
*field_type
;
204 value_ptr val
= NULL
;
209 /* Skip past the labels, and count them. */
210 while (get_label (exp
, pos
) != NULL
)
215 char *label
= get_label (exp
, &pc
);
218 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
221 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
222 if (field_name
!= NULL
&& STREQ (field_name
, label
))
225 subfieldno
= fieldno
;
226 substruct_type
= struct_type
;
230 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
233 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
234 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
235 if ((field_name
== 0 || *field_name
== '\0')
236 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
239 for (; variantno
< TYPE_NFIELDS (field_type
);
243 = TYPE_FIELD_TYPE (field_type
, variantno
);
244 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
247 subfieldno
< TYPE_NFIELDS (substruct_type
);
250 if (STREQ (TYPE_FIELD_NAME (substruct_type
,
261 error ("there is no field named %s", label
);
267 /* Unlabelled tuple element - go to next field. */
271 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
274 substruct_type
= struct_type
;
280 subfieldno
= fieldno
;
281 if (fieldno
>= TYPE_NFIELDS (struct_type
))
282 error ("too many initializers");
283 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
284 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
285 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
286 error ("don't know which variant you want to set");
290 /* Here, struct_type is the type of the inner struct,
291 while substruct_type is the type of the inner struct.
292 These are the same for normal structures, but a variant struct
293 contains anonymous union fields that contain substruct fields.
294 The value fieldno is the index of the top-level (normal or
295 anonymous union) field in struct_field, while the value
296 subfieldno is the index of the actual real (named inner) field
297 in substruct_type. */
299 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
301 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
303 /* Now actually set the field in struct_val. */
305 /* Assign val to field fieldno. */
306 if (VALUE_TYPE (val
) != field_type
)
307 val
= value_cast (field_type
, val
);
309 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
310 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
312 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
313 addr
= VALUE_CONTENTS (struct_val
) + bitpos
/ 8;
315 modify_field (addr
, value_as_long (val
),
316 bitpos
% 8, bitsize
);
318 memcpy (addr
, VALUE_CONTENTS (val
),
319 TYPE_LENGTH (VALUE_TYPE (val
)));
320 } while (--nlabels
> 0);
325 /* Recursive helper function for setting elements of array tuples for Chill.
326 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND);
327 the element value is ELEMENT;
328 EXP, POS and NOSIDE are as usual.
329 Evaluates index expresions and sets the specified element(s) of
331 Returns last index value. */
334 init_array_element (array
, element
, exp
, pos
, noside
, low_bound
, high_bound
)
335 value_ptr array
, element
;
336 register struct expression
*exp
;
339 LONGEST low_bound
, 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 (expect_type
, exp
, pos
, noside
)
379 struct type
*expect_type
;
380 register struct expression
*exp
;
386 register int pc
, pc2
= 0, oldpos
;
387 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
391 int upper
, lower
, retcode
;
396 struct type
** arg_types
;
400 op
= exp
->elts
[pc
].opcode
;
405 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
406 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
407 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
409 exp
->elts
[pc
+ 1].type
,
410 &exp
->elts
[pc
+ 3].string
,
413 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
418 return value_from_longest (exp
->elts
[pc
+ 1].type
,
419 exp
->elts
[pc
+ 2].longconst
);
423 return value_from_double (exp
->elts
[pc
+ 1].type
,
424 exp
->elts
[pc
+ 2].doubleconst
);
428 if (noside
== EVAL_SKIP
)
430 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
432 struct symbol
* sym
= exp
->elts
[pc
+ 2].symbol
;
435 switch (SYMBOL_CLASS (sym
))
439 case LOC_CONST_BYTES
:
453 return value_zero (SYMBOL_TYPE (sym
), lv
);
456 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
457 exp
->elts
[pc
+ 1].block
);
462 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
466 int regno
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
467 value_ptr val
= value_of_register (regno
);
471 error ("Value of register %s not available.", REGISTER_NAME (regno
));
477 return value_from_longest (LA_BOOL_TYPE
,
478 exp
->elts
[pc
+ 1].longconst
);
482 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
485 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
486 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
487 if (noside
== EVAL_SKIP
)
489 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
492 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
494 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
495 if (noside
== EVAL_SKIP
)
497 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
502 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
503 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
504 nargs
= tem3
- tem2
+ 1;
505 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
507 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
508 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
510 value_ptr rec
= allocate_value (expect_type
);
511 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (type
));
512 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
515 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
516 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
518 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
519 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
520 value_ptr array
= allocate_value (expect_type
);
521 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
522 LONGEST low_bound
, high_bound
, index
;
523 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
526 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
529 memset (VALUE_CONTENTS_RAW (array
), 0, TYPE_LENGTH (expect_type
));
530 for (tem
= nargs
; --nargs
>= 0; )
534 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
537 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
539 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
540 if (VALUE_TYPE (element
) != element_type
)
541 element
= value_cast (element_type
, element
);
544 int continue_pc
= *pos
;
546 index
= init_array_element (array
, element
, exp
, pos
, noside
,
547 low_bound
, high_bound
);
552 if (index
> high_bound
)
553 /* to avoid memory corruption */
554 error ("Too many array elements");
555 memcpy (VALUE_CONTENTS_RAW (array
)
556 + (index
- low_bound
) * element_size
,
557 VALUE_CONTENTS (element
),
565 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
566 && TYPE_CODE (type
) == TYPE_CODE_SET
)
568 value_ptr set
= allocate_value (expect_type
);
569 char *valaddr
= VALUE_CONTENTS_RAW (set
);
570 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
571 struct type
*check_type
= element_type
;
572 LONGEST low_bound
, high_bound
;
574 /* get targettype of elementtype */
575 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
||
576 TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
577 check_type
= TYPE_TARGET_TYPE (check_type
);
579 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
580 error ("(power)set type with unknown size");
581 memset (valaddr
, '\0', TYPE_LENGTH (type
));
582 for (tem
= 0; tem
< nargs
; tem
++)
584 LONGEST range_low
, range_high
;
585 struct type
*range_low_type
, *range_high_type
;
587 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
590 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
591 range_low_type
= VALUE_TYPE (elem_val
);
592 range_low
= value_as_long (elem_val
);
593 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
594 range_high_type
= VALUE_TYPE (elem_val
);
595 range_high
= value_as_long (elem_val
);
599 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
600 range_low_type
= range_high_type
= VALUE_TYPE (elem_val
);
601 range_low
= range_high
= value_as_long (elem_val
);
603 /* check types of elements to avoid mixture of elements from
604 different types. Also check if type of element is "compatible"
605 with element type of powerset */
606 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
607 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
608 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
609 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
610 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
)) ||
611 (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
&&
612 (range_low_type
!= range_high_type
)))
613 /* different element modes */
614 error ("POWERSET tuple elements of different mode");
615 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
)) ||
616 (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
&&
617 range_low_type
!= check_type
))
618 error ("incompatible POWERSET tuple elements");
619 if (range_low
> range_high
)
621 warning ("empty POWERSET tuple range");
624 if (range_low
< low_bound
|| range_high
> high_bound
)
625 error ("POWERSET tuple element out of range");
626 range_low
-= low_bound
;
627 range_high
-= low_bound
;
628 for ( ; range_low
<= range_high
; range_low
++)
630 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
632 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
633 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
640 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
641 for (tem
= 0; tem
< nargs
; tem
++)
643 /* Ensure that array expressions are coerced into pointer objects. */
644 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
646 if (noside
== EVAL_SKIP
)
648 return value_array (tem2
, tem3
, argvec
);
652 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
654 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
656 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
657 if (noside
== EVAL_SKIP
)
659 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
662 case TERNOP_SLICE_COUNT
:
664 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
666 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
668 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
669 return value_slice (array
, lowbound
, length
);
673 /* Skip third and second args to evaluate the first one. */
674 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
675 if (value_logical_not (arg1
))
677 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
678 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
682 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
683 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
689 op
= exp
->elts
[*pos
].opcode
;
690 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
691 /* Allocate arg vector, including space for the function to be
692 called in argvec[0] and a terminating NULL */
693 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 3));
694 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
698 /* 1997-08-01 Currently we do not support function invocation
699 via pointers-to-methods with HP aCC. Pointer does not point
700 to the function, but possibly to some thunk. */
701 if (hp_som_som_object_present
)
703 error ("Not implemented: function invocation through pointer to method with HP aCC");
707 /* First, evaluate the structure into arg2 */
710 if (noside
== EVAL_SKIP
)
713 if (op
== STRUCTOP_MEMBER
)
715 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
719 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
722 /* If the function is a virtual function, then the
723 aggregate value (providing the structure) plays
724 its part by providing the vtable. Otherwise,
725 it is just along for the ride: call the function
728 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
730 fnptr
= value_as_long (arg1
);
732 if (METHOD_PTR_IS_VIRTUAL(fnptr
))
734 int fnoffset
= METHOD_PTR_TO_VOFFSET(fnptr
);
735 struct type
*basetype
;
736 struct type
*domain_type
=
737 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
739 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
740 if (domain_type
!= basetype
)
741 arg2
= value_cast(lookup_pointer_type (domain_type
), arg2
);
742 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
743 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
745 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
746 /* If one is virtual, then all are virtual. */
747 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
748 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
749 if ((int) TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
751 value_ptr temp
= value_ind (arg2
);
752 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
753 arg2
= value_addr (temp
);
758 error ("virtual function at index %d not found", fnoffset
);
762 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
766 /* Now, say which argument to start evaluating from */
769 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
771 /* Hair for method invocations */
775 /* First, evaluate the structure into arg2 */
777 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
778 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
779 if (noside
== EVAL_SKIP
)
782 if (op
== STRUCTOP_STRUCT
)
784 /* If v is a variable in a register, and the user types
785 v.method (), this will produce an error, because v has
788 A possible way around this would be to allocate a
789 copy of the variable on the stack, copy in the
790 contents, call the function, and copy out the
791 contents. I.e. convert this from call by reference
792 to call by copy-return (or whatever it's called).
793 However, this does not work because it is not the
794 same: the method being called could stash a copy of
795 the address, and then future uses through that address
796 (after the method returns) would be expected to
797 use the variable itself, not some copy of it. */
798 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
802 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
804 /* Now, say which argument to start evaluating from */
809 /* Non-method function call */
811 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
813 type
= VALUE_TYPE (argvec
[0]);
814 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
815 type
= TYPE_TARGET_TYPE (type
);
816 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
818 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
820 /* pai: FIXME This seems to be coercing arguments before
821 * overload resolution has been done! */
822 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
, tem
-1),
828 /* Evaluate arguments */
829 for (; tem
<= nargs
; tem
++)
831 /* Ensure that array expressions are coerced into pointer objects. */
832 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
835 /* signal end of arglist */
838 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
841 value_ptr temp
= arg2
;
843 struct fn_field
* fns_ptr
;
845 struct type
* basetype
;
848 /* Method invocation : stuff "this" as first parameter */
849 /* pai: this used to have lookup_pointer_type for some reason,
850 * but temp is already a pointer to the object */
851 argvec
[1] = value_from_longest (VALUE_TYPE (temp
),
852 VALUE_ADDRESS (temp
)+VALUE_OFFSET (temp
));
853 /* Name of method from expression */
854 strcpy(tstr
, &exp
->elts
[pc2
+2].string
);
856 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
858 /* Language is C++, do some overload resolution before evaluation */
859 value_ptr valp
= NULL
;
861 /* Prepare list of argument types for overload resolution */
862 arg_types
= (struct type
**) xmalloc (nargs
* (sizeof (struct type
*)));
863 for (ix
=1; ix
<= nargs
; ix
++)
864 arg_types
[ix
-1] = VALUE_TYPE (argvec
[ix
]);
866 (void) find_overload_match (arg_types
, nargs
, tstr
,
867 1 /* method */, 0 /* strict match */,
868 arg2
/* the object */, NULL
,
869 &valp
, NULL
, &static_memfuncp
);
872 argvec
[1] = arg2
; /* the ``this'' pointer */
873 argvec
[0] = valp
; /* use the method found after overload resolution */
875 else /* Non-C++ case -- or no overload resolution */
878 argvec
[0] = value_struct_elt (&temp
, argvec
+1, tstr
,
880 op
== STRUCTOP_STRUCT
881 ? "structure" : "structure pointer");
882 argvec
[1] = arg2
; /* the ``this'' pointer */
887 argvec
[1] = argvec
[0];
892 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
899 /* Non-member function being called */
901 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
903 /* Language is C++, do some overload resolution before evaluation */
904 struct symbol
* symp
;
906 /* Prepare list of argument types for overload resolution */
907 arg_types
= (struct type
**) xmalloc (nargs
* (sizeof (struct type
*)));
908 for (ix
=1; ix
<= nargs
; ix
++)
909 arg_types
[ix
-1] = VALUE_TYPE (argvec
[ix
]);
911 (void) find_overload_match (arg_types
, nargs
, NULL
/* no need for name */,
912 0 /* not method */, 0 /* strict match */,
913 NULL
, exp
->elts
[5].symbol
/* the function */,
916 /* Now fix the expression being evaluated */
917 exp
->elts
[5].symbol
= symp
;
918 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
922 /* Not C++, or no overload resolution allowed */
923 /* nothing to be done; argvec already correctly set up */
929 if (noside
== EVAL_SKIP
)
931 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
933 /* If the return type doesn't look like a function type, call an
934 error. This can happen if somebody tries to turn a variable into
935 a function call. This is here because people often want to
936 call, eg, strcmp, which gdb doesn't know is a function. If
937 gdb isn't asked for it's opinion (ie. through "whatis"),
938 it won't offer it. */
941 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
944 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
946 error ("Expression of type other than \"Function returning ...\" used as function");
948 if (argvec
[0] == NULL
)
949 error ("Cannot evaluate function -- may be inlined");
950 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
951 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
953 case OP_F77_UNDETERMINED_ARGLIST
:
955 /* Remember that in F77, functions, substring ops and
956 array subscript operations cannot be disambiguated
957 at parse time. We have made all array subscript operations,
958 substring operations as well as function calls come here
959 and we now have to discover what the heck this thing actually was.
960 If it is a function, we process just as if we got an OP_FUNCALL. */
962 nargs
= longest_to_int (exp
->elts
[pc
+1].longconst
);
965 /* First determine the type code we are dealing with. */
966 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
967 type
= check_typedef (VALUE_TYPE (arg1
));
968 code
= TYPE_CODE (type
);
972 case TYPE_CODE_ARRAY
:
973 goto multi_f77_subscript
;
975 case TYPE_CODE_STRING
:
980 /* It's a function call. */
981 /* Allocate arg vector, including space for the function to be
982 called in argvec[0] and a terminating NULL */
983 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
986 for (; tem
<= nargs
; tem
++)
987 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
988 argvec
[tem
] = 0; /* signal end of arglist */
992 error ("Cannot perform substring on this type");
996 /* We have a substring operation on our hands here,
997 let us get the string we will be dealing with */
999 /* Now evaluate the 'from' and 'to' */
1001 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1004 return value_subscript (arg1
, arg2
);
1006 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1008 if (noside
== EVAL_SKIP
)
1011 tem2
= value_as_long (arg2
);
1012 tem3
= value_as_long (arg3
);
1014 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
1017 /* We have a complex number, There should be 2 floating
1018 point numbers that compose it */
1019 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1020 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1022 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
1024 case STRUCTOP_STRUCT
:
1025 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1026 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1027 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1028 if (noside
== EVAL_SKIP
)
1030 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1031 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1032 &exp
->elts
[pc
+ 2].string
,
1037 value_ptr temp
= arg1
;
1038 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1043 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1044 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1045 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1046 if (noside
== EVAL_SKIP
)
1048 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1049 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1050 &exp
->elts
[pc
+ 2].string
,
1055 value_ptr temp
= arg1
;
1056 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1057 NULL
, "structure pointer");
1060 case STRUCTOP_MEMBER
:
1061 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1062 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1064 /* With HP aCC, pointers to methods do not point to the function code */
1065 if (hp_som_som_object_present
&&
1066 (TYPE_CODE (VALUE_TYPE (arg2
)) == TYPE_CODE_PTR
) &&
1067 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
))) == TYPE_CODE_METHOD
))
1068 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1070 mem_offset
= value_as_long (arg2
);
1071 goto handle_pointer_to_member
;
1074 arg1
= evaluate_subexp (NULL_TYPE
, 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
);
1085 handle_pointer_to_member
:
1086 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1087 a real offset to the member. */
1088 if (hp_som_som_object_present
)
1090 if (!mem_offset
) /* no bias -> really null */
1091 error ("Attempted dereference of null pointer-to-member");
1092 mem_offset
&= ~0x20000000;
1094 if (noside
== EVAL_SKIP
)
1096 type
= check_typedef (VALUE_TYPE (arg2
));
1097 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
1098 goto bad_pointer_to_member
;
1099 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1100 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
1101 error ("not implemented: pointer-to-method in pointer-to-member construct");
1102 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
1103 goto bad_pointer_to_member
;
1104 /* Now, convert these values to an address. */
1105 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
1107 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1108 value_as_long (arg1
) + mem_offset
);
1109 return value_ind (arg3
);
1110 bad_pointer_to_member
:
1111 error("non-pointer-to-member value used in pointer-to-member construct");
1114 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1115 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1116 if (noside
== EVAL_SKIP
)
1118 if (binop_user_defined_p (op
, arg1
, arg2
))
1119 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1121 return value_concat (arg1
, arg2
);
1124 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1125 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1127 /* Do special stuff for HP aCC pointers to members */
1128 if (hp_som_som_object_present
)
1130 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1131 the implementation yet; but the pointer appears to point to a code
1132 sequence (thunk) in memory -- in any case it is *not* the address
1133 of the function as it would be in a naive implementation. */
1134 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1135 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
))
1136 error ("Assignment to pointers to methods not implemented with HP aCC");
1138 /* HP aCC pointers to data members require a constant bias */
1139 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1140 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
))
1142 unsigned int * ptr
= (unsigned int *) VALUE_CONTENTS (arg2
); /* forces evaluation */
1143 *ptr
|= 0x20000000; /* set 29th bit */
1147 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1149 if (binop_user_defined_p (op
, arg1
, arg2
))
1150 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1152 return value_assign (arg1
, arg2
);
1154 case BINOP_ASSIGN_MODIFY
:
1156 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1157 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1158 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1160 op
= exp
->elts
[pc
+ 1].opcode
;
1161 if (binop_user_defined_p (op
, arg1
, arg2
))
1162 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
1163 else if (op
== BINOP_ADD
)
1164 arg2
= value_add (arg1
, arg2
);
1165 else if (op
== BINOP_SUB
)
1166 arg2
= value_sub (arg1
, arg2
);
1168 arg2
= value_binop (arg1
, arg2
, op
);
1169 return value_assign (arg1
, arg2
);
1172 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1173 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1174 if (noside
== EVAL_SKIP
)
1176 if (binop_user_defined_p (op
, arg1
, arg2
))
1177 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1179 return value_add (arg1
, arg2
);
1182 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1183 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1184 if (noside
== EVAL_SKIP
)
1186 if (binop_user_defined_p (op
, arg1
, arg2
))
1187 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1189 return value_sub (arg1
, arg2
);
1197 case BINOP_BITWISE_AND
:
1198 case BINOP_BITWISE_IOR
:
1199 case BINOP_BITWISE_XOR
:
1200 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1201 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1202 if (noside
== EVAL_SKIP
)
1204 if (binop_user_defined_p (op
, arg1
, arg2
))
1205 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1207 if (noside
== EVAL_AVOID_SIDE_EFFECTS
1208 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
1209 return value_zero (VALUE_TYPE (arg1
), not_lval
);
1211 return value_binop (arg1
, arg2
, op
);
1214 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1215 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1216 if (noside
== EVAL_SKIP
)
1218 error ("':' operator used in invalid context");
1220 case BINOP_SUBSCRIPT
:
1221 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1222 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1223 if (noside
== EVAL_SKIP
)
1225 if (binop_user_defined_p (op
, arg1
, arg2
))
1226 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1229 /* If the user attempts to subscript something that is not an
1230 array or pointer type (like a plain int variable for example),
1231 then report this as an error. */
1234 type
= check_typedef (VALUE_TYPE (arg1
));
1235 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
1236 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
1238 if (TYPE_NAME (type
))
1239 error ("cannot subscript something of type `%s'",
1242 error ("cannot subscript requested type");
1245 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1246 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
1248 return value_subscript (arg1
, arg2
);
1252 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1253 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1254 if (noside
== EVAL_SKIP
)
1256 return value_in (arg1
, arg2
);
1258 case MULTI_SUBSCRIPT
:
1260 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1261 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1264 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1265 /* FIXME: EVAL_SKIP handling may not be correct. */
1266 if (noside
== EVAL_SKIP
)
1277 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1278 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1280 /* If the user attempts to subscript something that has no target
1281 type (like a plain int variable for example), then report this
1284 type
= TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (arg1
)));
1287 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1293 error ("cannot subscript something of type `%s'",
1294 TYPE_NAME (VALUE_TYPE (arg1
)));
1298 if (binop_user_defined_p (op
, arg1
, arg2
))
1300 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1304 arg1
= value_subscript (arg1
, arg2
);
1309 multi_f77_subscript
:
1311 int subscript_array
[MAX_FORTRAN_DIMS
+1]; /* 1-based array of
1312 subscripts, max == 7 */
1313 int array_size_array
[MAX_FORTRAN_DIMS
+1];
1314 int ndimensions
=1,i
;
1315 struct type
*tmp_type
;
1316 int offset_item
; /* The array offset where the item lives */
1318 if (nargs
> MAX_FORTRAN_DIMS
)
1319 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
1321 tmp_type
= check_typedef (VALUE_TYPE (arg1
));
1322 ndimensions
= calc_f77_array_dims (type
);
1324 if (nargs
!= ndimensions
)
1325 error ("Wrong number of subscripts");
1327 /* Now that we know we have a legal array subscript expression
1328 let us actually find out where this element exists in the array. */
1331 for (i
= 1; i
<= nargs
; i
++)
1333 /* Evaluate each subscript, It must be a legal integer in F77 */
1334 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1336 /* Fill in the subscript and array size arrays */
1338 subscript_array
[i
] = value_as_long (arg2
);
1340 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1341 if (retcode
== BOUND_FETCH_ERROR
)
1342 error ("Cannot obtain dynamic upper bound");
1344 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1345 if (retcode
== BOUND_FETCH_ERROR
)
1346 error("Cannot obtain dynamic lower bound");
1348 array_size_array
[i
] = upper
- lower
+ 1;
1350 /* Zero-normalize subscripts so that offsetting will work. */
1352 subscript_array
[i
] -= lower
;
1354 /* If we are at the bottom of a multidimensional
1355 array type then keep a ptr to the last ARRAY
1356 type around for use when calling value_subscript()
1357 below. This is done because we pretend to value_subscript
1358 that we actually have a one-dimensional array
1359 of base element type that we apply a simple
1363 tmp_type
= check_typedef (TYPE_TARGET_TYPE (tmp_type
));
1366 /* Now let us calculate the offset for this item */
1368 offset_item
= subscript_array
[ndimensions
];
1370 for (i
= ndimensions
- 1; i
>= 1; i
--)
1372 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1374 /* Construct a value node with the value of the offset */
1376 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1378 /* Let us now play a dirty trick: we will take arg1
1379 which is a value node pointing to the topmost level
1380 of the multidimensional array-set and pretend
1381 that it is actually a array of the final element
1382 type, this will ensure that value_subscript()
1383 returns the correct type value */
1385 VALUE_TYPE (arg1
) = tmp_type
;
1386 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1389 case BINOP_LOGICAL_AND
:
1390 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1391 if (noside
== EVAL_SKIP
)
1393 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1398 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1401 if (binop_user_defined_p (op
, arg1
, arg2
))
1403 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1404 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1408 tem
= value_logical_not (arg1
);
1409 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1410 (tem
? EVAL_SKIP
: noside
));
1411 return value_from_longest (LA_BOOL_TYPE
,
1412 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1415 case BINOP_LOGICAL_OR
:
1416 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1417 if (noside
== EVAL_SKIP
)
1419 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1424 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1427 if (binop_user_defined_p (op
, arg1
, arg2
))
1429 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1430 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1434 tem
= value_logical_not (arg1
);
1435 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1436 (!tem
? EVAL_SKIP
: noside
));
1437 return value_from_longest (LA_BOOL_TYPE
,
1438 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1442 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1443 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1444 if (noside
== EVAL_SKIP
)
1446 if (binop_user_defined_p (op
, arg1
, arg2
))
1448 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1452 tem
= value_equal (arg1
, arg2
);
1453 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1456 case BINOP_NOTEQUAL
:
1457 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1458 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1459 if (noside
== EVAL_SKIP
)
1461 if (binop_user_defined_p (op
, arg1
, arg2
))
1463 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1467 tem
= value_equal (arg1
, arg2
);
1468 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) ! tem
);
1472 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1473 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1474 if (noside
== EVAL_SKIP
)
1476 if (binop_user_defined_p (op
, arg1
, arg2
))
1478 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1482 tem
= value_less (arg1
, arg2
);
1483 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1487 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1488 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1489 if (noside
== EVAL_SKIP
)
1491 if (binop_user_defined_p (op
, arg1
, arg2
))
1493 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1497 tem
= value_less (arg2
, arg1
);
1498 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1502 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1503 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1504 if (noside
== EVAL_SKIP
)
1506 if (binop_user_defined_p (op
, arg1
, arg2
))
1508 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1512 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1513 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1517 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1518 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1519 if (noside
== EVAL_SKIP
)
1521 if (binop_user_defined_p (op
, arg1
, arg2
))
1523 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1527 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1528 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1532 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1533 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1534 if (noside
== EVAL_SKIP
)
1536 type
= check_typedef (VALUE_TYPE (arg2
));
1537 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
1538 error ("Non-integral right operand for \"@\" operator.");
1539 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1541 return allocate_repeat_value (VALUE_TYPE (arg1
),
1542 longest_to_int (value_as_long (arg2
)));
1545 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1548 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1549 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1552 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1553 if (noside
== EVAL_SKIP
)
1555 if (unop_user_defined_p (op
, arg1
))
1556 return value_x_unop (arg1
, op
, noside
);
1558 return value_neg (arg1
);
1560 case UNOP_COMPLEMENT
:
1561 /* C++: check for and handle destructor names. */
1562 op
= exp
->elts
[*pos
].opcode
;
1564 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1565 if (noside
== EVAL_SKIP
)
1567 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1568 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
1570 return value_complement (arg1
);
1572 case UNOP_LOGICAL_NOT
:
1573 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1574 if (noside
== EVAL_SKIP
)
1576 if (unop_user_defined_p (op
, arg1
))
1577 return value_x_unop (arg1
, op
, noside
);
1579 return value_from_longest (LA_BOOL_TYPE
,
1580 (LONGEST
) value_logical_not (arg1
));
1583 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1584 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1585 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1586 if ((TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) &&
1587 ((TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
) ||
1588 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
)))
1589 error ("Attempt to dereference pointer to member without an object");
1590 if (noside
== EVAL_SKIP
)
1592 if (unop_user_defined_p (op
, arg1
))
1593 return value_x_unop (arg1
, op
, noside
);
1594 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1596 type
= check_typedef (VALUE_TYPE (arg1
));
1597 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1598 || TYPE_CODE (type
) == TYPE_CODE_REF
1599 /* In C you can dereference an array to get the 1st elt. */
1600 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
1602 return value_zero (TYPE_TARGET_TYPE (type
),
1604 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
1605 /* GDB allows dereferencing an int. */
1606 return value_zero (builtin_type_int
, lval_memory
);
1608 error ("Attempt to take contents of a non-pointer value.");
1610 return value_ind (arg1
);
1613 /* C++: check for and handle pointer to members. */
1615 op
= exp
->elts
[*pos
].opcode
;
1617 if (noside
== EVAL_SKIP
)
1621 int temm
= longest_to_int (exp
->elts
[pc
+3].longconst
);
1622 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1625 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1630 value_ptr retvalp
= evaluate_subexp_for_address (exp
, pos
, noside
);
1631 /* If HP aCC object, use bias for pointers to members */
1632 if (hp_som_som_object_present
&&
1633 (TYPE_CODE (VALUE_TYPE (retvalp
)) == TYPE_CODE_PTR
) &&
1634 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (retvalp
))) == TYPE_CODE_MEMBER
))
1636 unsigned int * ptr
= (unsigned int *) VALUE_CONTENTS (retvalp
); /* forces evaluation */
1637 *ptr
|= 0x20000000; /* set 29th bit */
1643 if (noside
== EVAL_SKIP
)
1645 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1648 return evaluate_subexp_for_sizeof (exp
, pos
);
1652 type
= exp
->elts
[pc
+ 1].type
;
1653 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1654 if (noside
== EVAL_SKIP
)
1656 if (type
!= VALUE_TYPE (arg1
))
1657 arg1
= value_cast (type
, arg1
);
1662 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1663 if (noside
== EVAL_SKIP
)
1665 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1666 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1668 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1669 value_as_pointer (arg1
),
1672 case UNOP_PREINCREMENT
:
1673 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1674 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1676 else if (unop_user_defined_p (op
, arg1
))
1678 return value_x_unop (arg1
, op
, noside
);
1682 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1684 return value_assign (arg1
, arg2
);
1687 case UNOP_PREDECREMENT
:
1688 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1689 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1691 else if (unop_user_defined_p (op
, arg1
))
1693 return value_x_unop (arg1
, op
, noside
);
1697 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1699 return value_assign (arg1
, arg2
);
1702 case UNOP_POSTINCREMENT
:
1703 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1704 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1706 else if (unop_user_defined_p (op
, arg1
))
1708 return value_x_unop (arg1
, op
, noside
);
1712 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1714 value_assign (arg1
, arg2
);
1718 case UNOP_POSTDECREMENT
:
1719 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1720 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1722 else if (unop_user_defined_p (op
, arg1
))
1724 return value_x_unop (arg1
, op
, noside
);
1728 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1730 value_assign (arg1
, arg2
);
1736 return value_of_this (1);
1739 error ("Attempt to use a type name as an expression");
1742 /* Removing this case and compiling with gcc -Wall reveals that
1743 a lot of cases are hitting this case. Some of these should
1744 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1745 and an OP_SCOPE?); others are legitimate expressions which are
1746 (apparently) not fully implemented.
1748 If there are any cases landing here which mean a user error,
1749 then they should be separate cases, with more descriptive
1753 GDB does not (yet) know how to evaluate that kind of expression");
1757 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1760 /* Evaluate a subexpression of EXP, at index *POS,
1761 and return the address of that subexpression.
1762 Advance *POS over the subexpression.
1763 If the subexpression isn't an lvalue, get an error.
1764 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1765 then only the type of the result need be correct. */
1768 evaluate_subexp_for_address (exp
, pos
, noside
)
1769 register struct expression
*exp
;
1778 op
= exp
->elts
[pc
].opcode
;
1784 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1788 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1789 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1792 var
= exp
->elts
[pc
+ 2].symbol
;
1794 /* C++: The "address" of a reference should yield the address
1795 * of the object pointed to. Let value_addr() deal with it. */
1796 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1800 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1803 lookup_pointer_type (SYMBOL_TYPE (var
));
1804 enum address_class sym_class
= SYMBOL_CLASS (var
);
1806 if (sym_class
== LOC_CONST
1807 || sym_class
== LOC_CONST_BYTES
1808 || sym_class
== LOC_REGISTER
1809 || sym_class
== LOC_REGPARM
)
1810 error ("Attempt to take address of register or constant.");
1813 value_zero (type
, not_lval
);
1819 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1823 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1825 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1826 if (VALUE_LVAL (x
) == lval_memory
)
1827 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1830 error ("Attempt to take address of non-lval");
1832 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1836 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1837 When used in contexts where arrays will be coerced anyway, this is
1838 equivalent to `evaluate_subexp' but much faster because it avoids
1839 actually fetching array contents (perhaps obsolete now that we have
1842 Note that we currently only do the coercion for C expressions, where
1843 arrays are zero based and the coercion is correct. For other languages,
1844 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1845 to decide if coercion is appropriate.
1850 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1851 register struct expression
*exp
;
1855 register enum exp_opcode op
;
1857 register value_ptr val
;
1861 op
= exp
->elts
[pc
].opcode
;
1866 var
= exp
->elts
[pc
+ 2].symbol
;
1867 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var
))) == TYPE_CODE_ARRAY
1868 && CAST_IS_CONVERSION
)
1873 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1874 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1880 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1884 /* Evaluate a subexpression of EXP, at index *POS,
1885 and return a value for the size of that subexpression.
1886 Advance *POS over the subexpression. */
1889 evaluate_subexp_for_sizeof (exp
, pos
)
1890 register struct expression
*exp
;
1899 op
= exp
->elts
[pc
].opcode
;
1903 /* This case is handled specially
1904 so that we avoid creating a value for the result type.
1905 If the result type is very big, it's desirable not to
1906 create a value unnecessarily. */
1909 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1910 type
= check_typedef (VALUE_TYPE (val
));
1911 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1912 && TYPE_CODE (type
) != TYPE_CODE_REF
1913 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1914 error ("Attempt to take contents of a non-pointer value.");
1915 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1916 return value_from_longest (builtin_type_int
, (LONGEST
)
1917 TYPE_LENGTH (type
));
1921 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
1922 return value_from_longest (builtin_type_int
,
1923 (LONGEST
) TYPE_LENGTH (type
));
1927 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
1929 value_from_longest (builtin_type_int
, (LONGEST
) TYPE_LENGTH (type
));
1932 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1933 return value_from_longest (builtin_type_int
,
1934 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1938 /* Parse a type expression in the string [P..P+LENGTH). */
1941 parse_and_eval_type (p
, length
)
1945 char *tmp
= (char *)alloca (length
+ 4);
1946 struct expression
*expr
;
1948 memcpy (tmp
+1, p
, length
);
1949 tmp
[length
+1] = ')';
1950 tmp
[length
+2] = '0';
1951 tmp
[length
+3] = '\0';
1952 expr
= parse_expression (tmp
);
1953 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1954 error ("Internal error in eval_type.");
1955 return expr
->elts
[1].type
;
1959 calc_f77_array_dims (array_type
)
1960 struct type
*array_type
;
1963 struct type
*tmp_type
;
1965 if ((TYPE_CODE(array_type
) != TYPE_CODE_ARRAY
))
1966 error ("Can't get dimensions for a non-array type");
1968 tmp_type
= array_type
;
1970 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1972 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)