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
;
41 /* Prototypes for local functions. */
43 static value_ptr evaluate_subexp_for_sizeof
PARAMS ((struct expression
*,
46 static value_ptr evaluate_subexp_for_address
PARAMS ((struct expression
*,
49 static value_ptr evaluate_subexp
PARAMS ((struct type
*, struct expression
*,
52 static char *get_label
PARAMS ((struct expression
*, int *));
55 evaluate_struct_tuple
PARAMS ((value_ptr
, struct expression
*, int *,
59 init_array_element
PARAMS ((value_ptr
, value_ptr
, struct expression
*,
60 int *, enum noside
, LONGEST
, LONGEST
));
66 evaluate_subexp (expect_type
, exp
, pos
, noside
)
67 struct type
*expect_type
;
68 register struct expression
*exp
;
72 return (*exp
->language_defn
->evaluate_exp
) (expect_type
, exp
, pos
, noside
);
75 /* Parse the string EXP as a C expression, evaluate it,
76 and return the result as a number. */
79 parse_and_eval_address (exp
)
82 struct expression
*expr
= parse_expression (exp
);
83 register CORE_ADDR addr
;
84 register struct cleanup
*old_chain
=
85 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
87 addr
= value_as_pointer (evaluate_expression (expr
));
88 do_cleanups (old_chain
);
92 /* Like parse_and_eval_address but takes a pointer to a char * variable
93 and advanced that variable across the characters parsed. */
96 parse_and_eval_address_1 (expptr
)
99 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*) 0, 0);
100 register CORE_ADDR addr
;
101 register struct cleanup
*old_chain
=
102 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
104 addr
= value_as_pointer (evaluate_expression (expr
));
105 do_cleanups (old_chain
);
113 struct expression
*expr
= parse_expression (exp
);
114 register value_ptr val
;
115 register struct cleanup
*old_chain
116 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
118 val
= evaluate_expression (expr
);
119 do_cleanups (old_chain
);
123 /* Parse up to a comma (or to a closeparen)
124 in the string EXPP as an expression, evaluate it, and return the value.
125 EXPP is advanced to point to the comma. */
128 parse_to_comma_and_eval (expp
)
131 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
132 register value_ptr val
;
133 register struct cleanup
*old_chain
134 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
136 val
= evaluate_expression (expr
);
137 do_cleanups (old_chain
);
141 /* Evaluate an expression in internal prefix form
142 such as is constructed by parse.y.
144 See expression.h for info on the format of an expression. */
147 evaluate_expression (exp
)
148 struct expression
*exp
;
151 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
154 /* Evaluate an expression, avoiding all memory references
155 and getting a value whose type alone is correct. */
159 struct expression
*exp
;
162 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
165 /* If the next expression is an OP_LABELED, skips past it,
166 returning the label. Otherwise, does nothing and returns NULL. */
170 register struct expression
*exp
;
173 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
176 char *name
= &exp
->elts
[pc
+ 2].string
;
177 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
178 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
185 /* This function evaluates tupes (in Chill) or brace-initializers
186 (in C/C++) for structure types. */
189 evaluate_struct_tuple (struct_val
, exp
, pos
, noside
, nargs
)
190 value_ptr struct_val
;
191 register struct expression
*exp
;
196 struct type
*struct_type
= check_typedef (VALUE_TYPE (struct_val
));
197 struct type
*substruct_type
= struct_type
;
198 struct type
*field_type
;
205 value_ptr val
= NULL
;
210 /* Skip past the labels, and count them. */
211 while (get_label (exp
, pos
) != NULL
)
216 char *label
= get_label (exp
, &pc
);
219 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
222 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
223 if (field_name
!= NULL
&& STREQ (field_name
, label
))
226 subfieldno
= fieldno
;
227 substruct_type
= struct_type
;
231 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
234 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
235 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
236 if ((field_name
== 0 || *field_name
== '\0')
237 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
240 for (; variantno
< TYPE_NFIELDS (field_type
);
244 = TYPE_FIELD_TYPE (field_type
, variantno
);
245 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
248 subfieldno
< TYPE_NFIELDS (substruct_type
);
251 if (STREQ (TYPE_FIELD_NAME (substruct_type
,
262 error ("there is no field named %s", label
);
268 /* Unlabelled tuple element - go to next field. */
272 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
275 substruct_type
= struct_type
;
281 subfieldno
= fieldno
;
282 if (fieldno
>= TYPE_NFIELDS (struct_type
))
283 error ("too many initializers");
284 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
285 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
286 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
287 error ("don't know which variant you want to set");
291 /* Here, struct_type is the type of the inner struct,
292 while substruct_type is the type of the inner struct.
293 These are the same for normal structures, but a variant struct
294 contains anonymous union fields that contain substruct fields.
295 The value fieldno is the index of the top-level (normal or
296 anonymous union) field in struct_field, while the value
297 subfieldno is the index of the actual real (named inner) field
298 in substruct_type. */
300 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
302 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
304 /* Now actually set the field in struct_val. */
306 /* Assign val to field fieldno. */
307 if (VALUE_TYPE (val
) != field_type
)
308 val
= value_cast (field_type
, val
);
310 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
311 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
313 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
314 addr
= VALUE_CONTENTS (struct_val
) + bitpos
/ 8;
316 modify_field (addr
, value_as_long (val
),
317 bitpos
% 8, bitsize
);
319 memcpy (addr
, VALUE_CONTENTS (val
),
320 TYPE_LENGTH (VALUE_TYPE (val
)));
322 while (--nlabels
> 0);
327 /* Recursive helper function for setting elements of array tuples for Chill.
328 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND);
329 the element value is ELEMENT;
330 EXP, POS and NOSIDE are as usual.
331 Evaluates index expresions and sets the specified element(s) of
333 Returns last index value. */
336 init_array_element (array
, element
, exp
, pos
, noside
, low_bound
, high_bound
)
337 value_ptr array
, element
;
338 register struct expression
*exp
;
341 LONGEST low_bound
, high_bound
;
344 int element_size
= TYPE_LENGTH (VALUE_TYPE (element
));
345 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
348 init_array_element (array
, element
, exp
, pos
, noside
,
349 low_bound
, high_bound
);
350 return init_array_element (array
, element
,
351 exp
, pos
, noside
, low_bound
, high_bound
);
353 else if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
357 low
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
358 high
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
359 if (low
< low_bound
|| high
> high_bound
)
360 error ("tuple range index out of range");
361 for (index
= low
; index
<= high
; index
++)
363 memcpy (VALUE_CONTENTS_RAW (array
)
364 + (index
- low_bound
) * element_size
,
365 VALUE_CONTENTS (element
), element_size
);
370 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
371 if (index
< low_bound
|| index
> high_bound
)
372 error ("tuple index out of range");
373 memcpy (VALUE_CONTENTS_RAW (array
) + (index
- low_bound
) * element_size
,
374 VALUE_CONTENTS (element
), element_size
);
380 evaluate_subexp_standard (expect_type
, exp
, pos
, noside
)
381 struct type
*expect_type
;
382 register struct expression
*exp
;
388 register int pc
, pc2
= 0, oldpos
;
389 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
393 int upper
, lower
, retcode
;
398 struct type
**arg_types
;
402 op
= exp
->elts
[pc
].opcode
;
407 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
408 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
409 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
411 exp
->elts
[pc
+ 1].type
,
412 &exp
->elts
[pc
+ 3].string
,
415 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
420 return value_from_longest (exp
->elts
[pc
+ 1].type
,
421 exp
->elts
[pc
+ 2].longconst
);
425 return value_from_double (exp
->elts
[pc
+ 1].type
,
426 exp
->elts
[pc
+ 2].doubleconst
);
430 if (noside
== EVAL_SKIP
)
432 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
434 struct symbol
*sym
= exp
->elts
[pc
+ 2].symbol
;
437 switch (SYMBOL_CLASS (sym
))
441 case LOC_CONST_BYTES
:
455 return value_zero (SYMBOL_TYPE (sym
), lv
);
458 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
459 exp
->elts
[pc
+ 1].block
);
464 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
468 int regno
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
469 value_ptr val
= value_of_register (regno
);
473 error ("Value of register %s not available.", REGISTER_NAME (regno
));
479 return value_from_longest (LA_BOOL_TYPE
,
480 exp
->elts
[pc
+ 1].longconst
);
484 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
487 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
488 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
489 if (noside
== EVAL_SKIP
)
491 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
494 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
496 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
497 if (noside
== EVAL_SKIP
)
499 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
504 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
505 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
506 nargs
= tem3
- tem2
+ 1;
507 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
509 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
510 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
512 value_ptr rec
= allocate_value (expect_type
);
513 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (type
));
514 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
517 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
518 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
520 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
521 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
522 value_ptr array
= allocate_value (expect_type
);
523 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
524 LONGEST low_bound
, high_bound
, index
;
525 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
528 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
531 memset (VALUE_CONTENTS_RAW (array
), 0, TYPE_LENGTH (expect_type
));
532 for (tem
= nargs
; --nargs
>= 0;)
536 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
539 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
541 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
542 if (VALUE_TYPE (element
) != element_type
)
543 element
= value_cast (element_type
, element
);
546 int continue_pc
= *pos
;
548 index
= init_array_element (array
, element
, exp
, pos
, noside
,
549 low_bound
, high_bound
);
554 if (index
> high_bound
)
555 /* to avoid memory corruption */
556 error ("Too many array elements");
557 memcpy (VALUE_CONTENTS_RAW (array
)
558 + (index
- low_bound
) * element_size
,
559 VALUE_CONTENTS (element
),
567 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
568 && TYPE_CODE (type
) == TYPE_CODE_SET
)
570 value_ptr set
= allocate_value (expect_type
);
571 char *valaddr
= VALUE_CONTENTS_RAW (set
);
572 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
573 struct type
*check_type
= element_type
;
574 LONGEST low_bound
, high_bound
;
576 /* get targettype of elementtype */
577 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
||
578 TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
579 check_type
= TYPE_TARGET_TYPE (check_type
);
581 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
582 error ("(power)set type with unknown size");
583 memset (valaddr
, '\0', TYPE_LENGTH (type
));
584 for (tem
= 0; tem
< nargs
; tem
++)
586 LONGEST range_low
, range_high
;
587 struct type
*range_low_type
, *range_high_type
;
589 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
592 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
593 range_low_type
= VALUE_TYPE (elem_val
);
594 range_low
= value_as_long (elem_val
);
595 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
596 range_high_type
= VALUE_TYPE (elem_val
);
597 range_high
= value_as_long (elem_val
);
601 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
602 range_low_type
= range_high_type
= VALUE_TYPE (elem_val
);
603 range_low
= range_high
= value_as_long (elem_val
);
605 /* check types of elements to avoid mixture of elements from
606 different types. Also check if type of element is "compatible"
607 with element type of powerset */
608 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
609 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
610 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
611 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
612 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
)) ||
613 (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
&&
614 (range_low_type
!= range_high_type
)))
615 /* different element modes */
616 error ("POWERSET tuple elements of different mode");
617 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
)) ||
618 (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
&&
619 range_low_type
!= check_type
))
620 error ("incompatible POWERSET tuple elements");
621 if (range_low
> range_high
)
623 warning ("empty POWERSET tuple range");
626 if (range_low
< low_bound
|| range_high
> high_bound
)
627 error ("POWERSET tuple element out of range");
628 range_low
-= low_bound
;
629 range_high
-= low_bound
;
630 for (; range_low
<= range_high
; range_low
++)
632 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
634 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
635 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
642 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
643 for (tem
= 0; tem
< nargs
; tem
++)
645 /* Ensure that array expressions are coerced into pointer objects. */
646 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
648 if (noside
== EVAL_SKIP
)
650 return value_array (tem2
, tem3
, argvec
);
654 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
656 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
658 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
659 if (noside
== EVAL_SKIP
)
661 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
664 case TERNOP_SLICE_COUNT
:
666 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
668 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
670 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
671 return value_slice (array
, lowbound
, length
);
675 /* Skip third and second args to evaluate the first one. */
676 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
677 if (value_logical_not (arg1
))
679 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
680 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
684 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
685 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
691 op
= exp
->elts
[*pos
].opcode
;
692 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
693 /* Allocate arg vector, including space for the function to be
694 called in argvec[0] and a terminating NULL */
695 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 3));
696 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
700 /* 1997-08-01 Currently we do not support function invocation
701 via pointers-to-methods with HP aCC. Pointer does not point
702 to the function, but possibly to some thunk. */
703 if (hp_som_som_object_present
)
705 error ("Not implemented: function invocation through pointer to method with HP aCC");
709 /* First, evaluate the structure into arg2 */
712 if (noside
== EVAL_SKIP
)
715 if (op
== STRUCTOP_MEMBER
)
717 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
721 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
724 /* If the function is a virtual function, then the
725 aggregate value (providing the structure) plays
726 its part by providing the vtable. Otherwise,
727 it is just along for the ride: call the function
730 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
732 fnptr
= value_as_long (arg1
);
734 if (METHOD_PTR_IS_VIRTUAL (fnptr
))
736 int fnoffset
= METHOD_PTR_TO_VOFFSET (fnptr
);
737 struct type
*basetype
;
738 struct type
*domain_type
=
739 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
741 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
742 if (domain_type
!= basetype
)
743 arg2
= value_cast (lookup_pointer_type (domain_type
), arg2
);
744 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
745 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
747 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
748 /* If one is virtual, then all are virtual. */
749 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
750 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
751 if ((int) TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
753 value_ptr temp
= value_ind (arg2
);
754 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
755 arg2
= value_addr (temp
);
760 error ("virtual function at index %d not found", fnoffset
);
764 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
768 /* Now, say which argument to start evaluating from */
771 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
773 /* Hair for method invocations */
777 /* First, evaluate the structure into arg2 */
779 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
780 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
781 if (noside
== EVAL_SKIP
)
784 if (op
== STRUCTOP_STRUCT
)
786 /* If v is a variable in a register, and the user types
787 v.method (), this will produce an error, because v has
790 A possible way around this would be to allocate a
791 copy of the variable on the stack, copy in the
792 contents, call the function, and copy out the
793 contents. I.e. convert this from call by reference
794 to call by copy-return (or whatever it's called).
795 However, this does not work because it is not the
796 same: the method being called could stash a copy of
797 the address, and then future uses through that address
798 (after the method returns) would be expected to
799 use the variable itself, not some copy of it. */
800 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
804 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
806 /* Now, say which argument to start evaluating from */
811 /* Non-method function call */
813 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
815 type
= VALUE_TYPE (argvec
[0]);
816 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
817 type
= TYPE_TARGET_TYPE (type
);
818 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
820 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
822 /* pai: FIXME This seems to be coercing arguments before
823 * overload resolution has been done! */
824 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
, tem
- 1),
830 /* Evaluate arguments */
831 for (; tem
<= nargs
; tem
++)
833 /* Ensure that array expressions are coerced into pointer objects. */
834 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
837 /* signal end of arglist */
840 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
843 value_ptr temp
= arg2
;
845 struct fn_field
*fns_ptr
;
847 struct type
*basetype
;
850 /* Method invocation : stuff "this" as first parameter */
851 /* pai: this used to have lookup_pointer_type for some reason,
852 * but temp is already a pointer to the object */
853 argvec
[1] = value_from_longest (VALUE_TYPE (temp
),
854 VALUE_ADDRESS (temp
) + VALUE_OFFSET (temp
));
855 /* Name of method from expression */
856 strcpy (tstr
, &exp
->elts
[pc2
+ 2].string
);
858 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
860 /* Language is C++, do some overload resolution before evaluation */
861 value_ptr valp
= NULL
;
863 /* Prepare list of argument types for overload resolution */
864 arg_types
= (struct type
**) xmalloc (nargs
* (sizeof (struct type
*)));
865 for (ix
= 1; ix
<= nargs
; ix
++)
866 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
868 (void) find_overload_match (arg_types
, nargs
, tstr
,
869 1 /* method */ , 0 /* strict match */ ,
870 arg2
/* the object */ , NULL
,
871 &valp
, NULL
, &static_memfuncp
);
874 argvec
[1] = arg2
; /* the ``this'' pointer */
875 argvec
[0] = valp
; /* use the method found after overload resolution */
878 /* Non-C++ case -- or no overload resolution */
881 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
883 op
== STRUCTOP_STRUCT
884 ? "structure" : "structure pointer");
885 argvec
[1] = arg2
; /* the ``this'' pointer */
890 argvec
[1] = argvec
[0];
895 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
902 /* Non-member function being called */
904 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
906 /* Language is C++, do some overload resolution before evaluation */
909 /* Prepare list of argument types for overload resolution */
910 arg_types
= (struct type
**) xmalloc (nargs
* (sizeof (struct type
*)));
911 for (ix
= 1; ix
<= nargs
; ix
++)
912 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
914 (void) find_overload_match (arg_types
, nargs
, NULL
/* no need for name */ ,
915 0 /* not method */ , 0 /* strict match */ ,
916 NULL
, exp
->elts
[5].symbol
/* the function */ ,
919 /* Now fix the expression being evaluated */
920 exp
->elts
[5].symbol
= symp
;
921 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
925 /* Not C++, or no overload resolution allowed */
926 /* nothing to be done; argvec already correctly set up */
932 if (noside
== EVAL_SKIP
)
934 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
936 /* If the return type doesn't look like a function type, call an
937 error. This can happen if somebody tries to turn a variable into
938 a function call. This is here because people often want to
939 call, eg, strcmp, which gdb doesn't know is a function. If
940 gdb isn't asked for it's opinion (ie. through "whatis"),
941 it won't offer it. */
944 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
947 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
949 error ("Expression of type other than \"Function returning ...\" used as function");
951 if (argvec
[0] == NULL
)
952 error ("Cannot evaluate function -- may be inlined");
953 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
954 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
956 case OP_F77_UNDETERMINED_ARGLIST
:
958 /* Remember that in F77, functions, substring ops and
959 array subscript operations cannot be disambiguated
960 at parse time. We have made all array subscript operations,
961 substring operations as well as function calls come here
962 and we now have to discover what the heck this thing actually was.
963 If it is a function, we process just as if we got an OP_FUNCALL. */
965 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
968 /* First determine the type code we are dealing with. */
969 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
970 type
= check_typedef (VALUE_TYPE (arg1
));
971 code
= TYPE_CODE (type
);
975 case TYPE_CODE_ARRAY
:
976 goto multi_f77_subscript
;
978 case TYPE_CODE_STRING
:
983 /* It's a function call. */
984 /* Allocate arg vector, including space for the function to be
985 called in argvec[0] and a terminating NULL */
986 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
989 for (; tem
<= nargs
; tem
++)
990 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
991 argvec
[tem
] = 0; /* signal end of arglist */
995 error ("Cannot perform substring on this type");
999 /* We have a substring operation on our hands here,
1000 let us get the string we will be dealing with */
1002 /* Now evaluate the 'from' and 'to' */
1004 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1007 return value_subscript (arg1
, arg2
);
1009 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1011 if (noside
== EVAL_SKIP
)
1014 tem2
= value_as_long (arg2
);
1015 tem3
= value_as_long (arg3
);
1017 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
1020 /* We have a complex number, There should be 2 floating
1021 point numbers that compose it */
1022 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1023 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1025 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
1027 case STRUCTOP_STRUCT
:
1028 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1029 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1030 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1031 if (noside
== EVAL_SKIP
)
1033 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1034 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1035 &exp
->elts
[pc
+ 2].string
,
1040 value_ptr temp
= arg1
;
1041 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1046 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1047 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1048 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1049 if (noside
== EVAL_SKIP
)
1051 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1052 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1053 &exp
->elts
[pc
+ 2].string
,
1058 value_ptr temp
= arg1
;
1059 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1060 NULL
, "structure pointer");
1063 case STRUCTOP_MEMBER
:
1064 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1065 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1067 /* With HP aCC, pointers to methods do not point to the function code */
1068 if (hp_som_som_object_present
&&
1069 (TYPE_CODE (VALUE_TYPE (arg2
)) == TYPE_CODE_PTR
) &&
1070 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
))) == TYPE_CODE_METHOD
))
1071 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1073 mem_offset
= value_as_long (arg2
);
1074 goto handle_pointer_to_member
;
1077 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1078 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1080 /* With HP aCC, pointers to methods do not point to the function code */
1081 if (hp_som_som_object_present
&&
1082 (TYPE_CODE (VALUE_TYPE (arg2
)) == TYPE_CODE_PTR
) &&
1083 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
))) == TYPE_CODE_METHOD
))
1084 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1086 mem_offset
= value_as_long (arg2
);
1088 handle_pointer_to_member
:
1089 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1090 a real offset to the member. */
1091 if (hp_som_som_object_present
)
1093 if (!mem_offset
) /* no bias -> really null */
1094 error ("Attempted dereference of null pointer-to-member");
1095 mem_offset
&= ~0x20000000;
1097 if (noside
== EVAL_SKIP
)
1099 type
= check_typedef (VALUE_TYPE (arg2
));
1100 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
1101 goto bad_pointer_to_member
;
1102 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1103 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
1104 error ("not implemented: pointer-to-method in pointer-to-member construct");
1105 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
1106 goto bad_pointer_to_member
;
1107 /* Now, convert these values to an address. */
1108 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
1110 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1111 value_as_long (arg1
) + mem_offset
);
1112 return value_ind (arg3
);
1113 bad_pointer_to_member
:
1114 error ("non-pointer-to-member value used in pointer-to-member construct");
1117 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1118 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1119 if (noside
== EVAL_SKIP
)
1121 if (binop_user_defined_p (op
, arg1
, arg2
))
1122 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1124 return value_concat (arg1
, arg2
);
1127 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1128 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1130 /* Do special stuff for HP aCC pointers to members */
1131 if (hp_som_som_object_present
)
1133 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1134 the implementation yet; but the pointer appears to point to a code
1135 sequence (thunk) in memory -- in any case it is *not* the address
1136 of the function as it would be in a naive implementation. */
1137 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1138 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
))
1139 error ("Assignment to pointers to methods not implemented with HP aCC");
1141 /* HP aCC pointers to data members require a constant bias */
1142 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1143 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
))
1145 unsigned int *ptr
= (unsigned int *) VALUE_CONTENTS (arg2
); /* forces evaluation */
1146 *ptr
|= 0x20000000; /* set 29th bit */
1150 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1152 if (binop_user_defined_p (op
, arg1
, arg2
))
1153 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1155 return value_assign (arg1
, arg2
);
1157 case BINOP_ASSIGN_MODIFY
:
1159 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1160 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1161 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1163 op
= exp
->elts
[pc
+ 1].opcode
;
1164 if (binop_user_defined_p (op
, arg1
, arg2
))
1165 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
1166 else if (op
== BINOP_ADD
)
1167 arg2
= value_add (arg1
, arg2
);
1168 else if (op
== BINOP_SUB
)
1169 arg2
= value_sub (arg1
, arg2
);
1171 arg2
= value_binop (arg1
, arg2
, op
);
1172 return value_assign (arg1
, arg2
);
1175 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1176 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1177 if (noside
== EVAL_SKIP
)
1179 if (binop_user_defined_p (op
, arg1
, arg2
))
1180 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1182 return value_add (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_sub (arg1
, arg2
);
1200 case BINOP_BITWISE_AND
:
1201 case BINOP_BITWISE_IOR
:
1202 case BINOP_BITWISE_XOR
:
1203 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1204 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1205 if (noside
== EVAL_SKIP
)
1207 if (binop_user_defined_p (op
, arg1
, arg2
))
1208 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1209 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
1210 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
1211 return value_zero (VALUE_TYPE (arg1
), not_lval
);
1213 return value_binop (arg1
, arg2
, op
);
1216 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1217 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1218 if (noside
== EVAL_SKIP
)
1220 error ("':' operator used in invalid context");
1222 case BINOP_SUBSCRIPT
:
1223 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1224 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1225 if (noside
== EVAL_SKIP
)
1227 if (binop_user_defined_p (op
, arg1
, arg2
))
1228 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1231 /* If the user attempts to subscript something that is not an
1232 array or pointer type (like a plain int variable for example),
1233 then report this as an error. */
1236 type
= check_typedef (VALUE_TYPE (arg1
));
1237 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
1238 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
1240 if (TYPE_NAME (type
))
1241 error ("cannot subscript something of type `%s'",
1244 error ("cannot subscript requested type");
1247 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1248 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
1250 return value_subscript (arg1
, arg2
);
1254 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1255 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1256 if (noside
== EVAL_SKIP
)
1258 return value_in (arg1
, arg2
);
1260 case MULTI_SUBSCRIPT
:
1262 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1263 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1266 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1267 /* FIXME: EVAL_SKIP handling may not be correct. */
1268 if (noside
== EVAL_SKIP
)
1279 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1280 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1282 /* If the user attempts to subscript something that has no target
1283 type (like a plain int variable for example), then report this
1286 type
= TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (arg1
)));
1289 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1295 error ("cannot subscript something of type `%s'",
1296 TYPE_NAME (VALUE_TYPE (arg1
)));
1300 if (binop_user_defined_p (op
, arg1
, arg2
))
1302 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1306 arg1
= value_subscript (arg1
, arg2
);
1311 multi_f77_subscript
:
1313 int subscript_array
[MAX_FORTRAN_DIMS
+ 1]; /* 1-based array of
1314 subscripts, max == 7 */
1315 int array_size_array
[MAX_FORTRAN_DIMS
+ 1];
1316 int ndimensions
= 1, i
;
1317 struct type
*tmp_type
;
1318 int offset_item
; /* The array offset where the item lives */
1320 if (nargs
> MAX_FORTRAN_DIMS
)
1321 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
1323 tmp_type
= check_typedef (VALUE_TYPE (arg1
));
1324 ndimensions
= calc_f77_array_dims (type
);
1326 if (nargs
!= ndimensions
)
1327 error ("Wrong number of subscripts");
1329 /* Now that we know we have a legal array subscript expression
1330 let us actually find out where this element exists in the array. */
1333 for (i
= 1; i
<= nargs
; i
++)
1335 /* Evaluate each subscript, It must be a legal integer in F77 */
1336 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1338 /* Fill in the subscript and array size arrays */
1340 subscript_array
[i
] = value_as_long (arg2
);
1342 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1343 if (retcode
== BOUND_FETCH_ERROR
)
1344 error ("Cannot obtain dynamic upper bound");
1346 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1347 if (retcode
== BOUND_FETCH_ERROR
)
1348 error ("Cannot obtain dynamic lower bound");
1350 array_size_array
[i
] = upper
- lower
+ 1;
1352 /* Zero-normalize subscripts so that offsetting will work. */
1354 subscript_array
[i
] -= lower
;
1356 /* If we are at the bottom of a multidimensional
1357 array type then keep a ptr to the last ARRAY
1358 type around for use when calling value_subscript()
1359 below. This is done because we pretend to value_subscript
1360 that we actually have a one-dimensional array
1361 of base element type that we apply a simple
1365 tmp_type
= check_typedef (TYPE_TARGET_TYPE (tmp_type
));
1368 /* Now let us calculate the offset for this item */
1370 offset_item
= subscript_array
[ndimensions
];
1372 for (i
= ndimensions
- 1; i
>= 1; i
--)
1374 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1376 /* Construct a value node with the value of the offset */
1378 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1380 /* Let us now play a dirty trick: we will take arg1
1381 which is a value node pointing to the topmost level
1382 of the multidimensional array-set and pretend
1383 that it is actually a array of the final element
1384 type, this will ensure that value_subscript()
1385 returns the correct type value */
1387 VALUE_TYPE (arg1
) = tmp_type
;
1388 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1391 case BINOP_LOGICAL_AND
:
1392 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1393 if (noside
== EVAL_SKIP
)
1395 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1400 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1403 if (binop_user_defined_p (op
, arg1
, arg2
))
1405 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1406 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1410 tem
= value_logical_not (arg1
);
1411 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1412 (tem
? EVAL_SKIP
: noside
));
1413 return value_from_longest (LA_BOOL_TYPE
,
1414 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1417 case BINOP_LOGICAL_OR
:
1418 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1419 if (noside
== EVAL_SKIP
)
1421 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1426 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1429 if (binop_user_defined_p (op
, arg1
, arg2
))
1431 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1432 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1436 tem
= value_logical_not (arg1
);
1437 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1438 (!tem
? EVAL_SKIP
: noside
));
1439 return value_from_longest (LA_BOOL_TYPE
,
1440 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1444 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1445 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1446 if (noside
== EVAL_SKIP
)
1448 if (binop_user_defined_p (op
, arg1
, arg2
))
1450 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1454 tem
= value_equal (arg1
, arg2
);
1455 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1458 case BINOP_NOTEQUAL
:
1459 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1460 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1461 if (noside
== EVAL_SKIP
)
1463 if (binop_user_defined_p (op
, arg1
, arg2
))
1465 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1469 tem
= value_equal (arg1
, arg2
);
1470 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) ! tem
);
1474 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1475 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1476 if (noside
== EVAL_SKIP
)
1478 if (binop_user_defined_p (op
, arg1
, arg2
))
1480 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1484 tem
= value_less (arg1
, arg2
);
1485 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1489 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1490 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1491 if (noside
== EVAL_SKIP
)
1493 if (binop_user_defined_p (op
, arg1
, arg2
))
1495 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1499 tem
= value_less (arg2
, arg1
);
1500 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1504 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1505 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1506 if (noside
== EVAL_SKIP
)
1508 if (binop_user_defined_p (op
, arg1
, arg2
))
1510 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1514 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1515 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1519 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1520 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1521 if (noside
== EVAL_SKIP
)
1523 if (binop_user_defined_p (op
, arg1
, arg2
))
1525 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1529 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1530 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1534 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1535 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1536 if (noside
== EVAL_SKIP
)
1538 type
= check_typedef (VALUE_TYPE (arg2
));
1539 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
1540 error ("Non-integral right operand for \"@\" operator.");
1541 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1543 return allocate_repeat_value (VALUE_TYPE (arg1
),
1544 longest_to_int (value_as_long (arg2
)));
1547 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1550 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1551 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1554 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1555 if (noside
== EVAL_SKIP
)
1557 if (unop_user_defined_p (op
, arg1
))
1558 return value_x_unop (arg1
, op
, noside
);
1560 return value_neg (arg1
);
1562 case UNOP_COMPLEMENT
:
1563 /* C++: check for and handle destructor names. */
1564 op
= exp
->elts
[*pos
].opcode
;
1566 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1567 if (noside
== EVAL_SKIP
)
1569 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1570 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
1572 return value_complement (arg1
);
1574 case UNOP_LOGICAL_NOT
:
1575 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1576 if (noside
== EVAL_SKIP
)
1578 if (unop_user_defined_p (op
, arg1
))
1579 return value_x_unop (arg1
, op
, noside
);
1581 return value_from_longest (LA_BOOL_TYPE
,
1582 (LONGEST
) value_logical_not (arg1
));
1585 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1586 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1587 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1588 if ((TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) &&
1589 ((TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
) ||
1590 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
)))
1591 error ("Attempt to dereference pointer to member without an object");
1592 if (noside
== EVAL_SKIP
)
1594 if (unop_user_defined_p (op
, arg1
))
1595 return value_x_unop (arg1
, op
, noside
);
1596 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1598 type
= check_typedef (VALUE_TYPE (arg1
));
1599 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1600 || TYPE_CODE (type
) == TYPE_CODE_REF
1601 /* In C you can dereference an array to get the 1st elt. */
1602 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
1604 return value_zero (TYPE_TARGET_TYPE (type
),
1606 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
1607 /* GDB allows dereferencing an int. */
1608 return value_zero (builtin_type_int
, lval_memory
);
1610 error ("Attempt to take contents of a non-pointer value.");
1612 return value_ind (arg1
);
1615 /* C++: check for and handle pointer to members. */
1617 op
= exp
->elts
[*pos
].opcode
;
1619 if (noside
== EVAL_SKIP
)
1623 int temm
= longest_to_int (exp
->elts
[pc
+ 3].longconst
);
1624 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1627 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1632 value_ptr retvalp
= evaluate_subexp_for_address (exp
, pos
, noside
);
1633 /* If HP aCC object, use bias for pointers to members */
1634 if (hp_som_som_object_present
&&
1635 (TYPE_CODE (VALUE_TYPE (retvalp
)) == TYPE_CODE_PTR
) &&
1636 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (retvalp
))) == TYPE_CODE_MEMBER
))
1638 unsigned int *ptr
= (unsigned int *) VALUE_CONTENTS (retvalp
); /* forces evaluation */
1639 *ptr
|= 0x20000000; /* set 29th bit */
1645 if (noside
== EVAL_SKIP
)
1647 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1650 return evaluate_subexp_for_sizeof (exp
, pos
);
1654 type
= exp
->elts
[pc
+ 1].type
;
1655 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1656 if (noside
== EVAL_SKIP
)
1658 if (type
!= VALUE_TYPE (arg1
))
1659 arg1
= value_cast (type
, arg1
);
1664 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1665 if (noside
== EVAL_SKIP
)
1667 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1668 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1670 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1671 value_as_pointer (arg1
),
1674 case UNOP_PREINCREMENT
:
1675 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1676 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1678 else if (unop_user_defined_p (op
, arg1
))
1680 return value_x_unop (arg1
, op
, noside
);
1684 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1686 return value_assign (arg1
, arg2
);
1689 case UNOP_PREDECREMENT
:
1690 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1691 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1693 else if (unop_user_defined_p (op
, arg1
))
1695 return value_x_unop (arg1
, op
, noside
);
1699 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1701 return value_assign (arg1
, arg2
);
1704 case UNOP_POSTINCREMENT
:
1705 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1706 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1708 else if (unop_user_defined_p (op
, arg1
))
1710 return value_x_unop (arg1
, op
, noside
);
1714 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1716 value_assign (arg1
, arg2
);
1720 case UNOP_POSTDECREMENT
:
1721 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1722 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1724 else if (unop_user_defined_p (op
, arg1
))
1726 return value_x_unop (arg1
, op
, noside
);
1730 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1732 value_assign (arg1
, arg2
);
1738 return value_of_this (1);
1741 error ("Attempt to use a type name as an expression");
1744 /* Removing this case and compiling with gcc -Wall reveals that
1745 a lot of cases are hitting this case. Some of these should
1746 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1747 and an OP_SCOPE?); others are legitimate expressions which are
1748 (apparently) not fully implemented.
1750 If there are any cases landing here which mean a user error,
1751 then they should be separate cases, with more descriptive
1755 GDB does not (yet) know how to evaluate that kind of expression");
1759 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1762 /* Evaluate a subexpression of EXP, at index *POS,
1763 and return the address of that subexpression.
1764 Advance *POS over the subexpression.
1765 If the subexpression isn't an lvalue, get an error.
1766 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1767 then only the type of the result need be correct. */
1770 evaluate_subexp_for_address (exp
, pos
, noside
)
1771 register struct expression
*exp
;
1780 op
= exp
->elts
[pc
].opcode
;
1786 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1790 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1791 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1794 var
= exp
->elts
[pc
+ 2].symbol
;
1796 /* C++: The "address" of a reference should yield the address
1797 * of the object pointed to. Let value_addr() deal with it. */
1798 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1802 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1805 lookup_pointer_type (SYMBOL_TYPE (var
));
1806 enum address_class sym_class
= SYMBOL_CLASS (var
);
1808 if (sym_class
== LOC_CONST
1809 || sym_class
== LOC_CONST_BYTES
1810 || sym_class
== LOC_REGISTER
1811 || sym_class
== LOC_REGPARM
)
1812 error ("Attempt to take address of register or constant.");
1815 value_zero (type
, not_lval
);
1821 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1825 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1827 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1828 if (VALUE_LVAL (x
) == lval_memory
)
1829 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1832 error ("Attempt to take address of non-lval");
1834 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1838 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1839 When used in contexts where arrays will be coerced anyway, this is
1840 equivalent to `evaluate_subexp' but much faster because it avoids
1841 actually fetching array contents (perhaps obsolete now that we have
1844 Note that we currently only do the coercion for C expressions, where
1845 arrays are zero based and the coercion is correct. For other languages,
1846 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1847 to decide if coercion is appropriate.
1852 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1853 register struct expression
*exp
;
1857 register enum exp_opcode op
;
1859 register value_ptr val
;
1863 op
= exp
->elts
[pc
].opcode
;
1868 var
= exp
->elts
[pc
+ 2].symbol
;
1869 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var
))) == TYPE_CODE_ARRAY
1870 && CAST_IS_CONVERSION
)
1875 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1876 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1882 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1886 /* Evaluate a subexpression of EXP, at index *POS,
1887 and return a value for the size of that subexpression.
1888 Advance *POS over the subexpression. */
1891 evaluate_subexp_for_sizeof (exp
, pos
)
1892 register struct expression
*exp
;
1901 op
= exp
->elts
[pc
].opcode
;
1905 /* This case is handled specially
1906 so that we avoid creating a value for the result type.
1907 If the result type is very big, it's desirable not to
1908 create a value unnecessarily. */
1911 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1912 type
= check_typedef (VALUE_TYPE (val
));
1913 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1914 && TYPE_CODE (type
) != TYPE_CODE_REF
1915 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1916 error ("Attempt to take contents of a non-pointer value.");
1917 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1918 return value_from_longest (builtin_type_int
, (LONGEST
)
1919 TYPE_LENGTH (type
));
1923 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
1924 return value_from_longest (builtin_type_int
,
1925 (LONGEST
) TYPE_LENGTH (type
));
1929 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
1931 value_from_longest (builtin_type_int
, (LONGEST
) TYPE_LENGTH (type
));
1934 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1935 return value_from_longest (builtin_type_int
,
1936 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1940 /* Parse a type expression in the string [P..P+LENGTH). */
1943 parse_and_eval_type (p
, length
)
1947 char *tmp
= (char *) alloca (length
+ 4);
1948 struct expression
*expr
;
1950 memcpy (tmp
+ 1, p
, length
);
1951 tmp
[length
+ 1] = ')';
1952 tmp
[length
+ 2] = '0';
1953 tmp
[length
+ 3] = '\0';
1954 expr
= parse_expression (tmp
);
1955 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1956 error ("Internal error in eval_type.");
1957 return expr
->elts
[1].type
;
1961 calc_f77_array_dims (array_type
)
1962 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
)