1 /* Evaluate expressions for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
28 #include "expression.h"
31 #include "language.h" /* For CAST_IS_CONVERSION */
32 #include "f-lang.h" /* for array bound stuff */
35 /* Defined in symtab.c */
36 extern int hp_som_som_object_present
;
38 /* This is defined in valops.c */
39 extern int overload_resolution
;
41 /* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue
42 on with successful lookup for member/method of the rtti type. */
43 extern int objectprint
;
45 /* Prototypes for local functions. */
47 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *);
49 static struct value
*evaluate_subexp_for_address (struct expression
*,
52 static struct value
*evaluate_subexp (struct type
*, struct expression
*,
55 static char *get_label (struct expression
*, int *);
57 static struct value
*evaluate_struct_tuple (struct value
*,
58 struct expression
*, int *,
61 static LONGEST
init_array_element (struct value
*, struct value
*,
62 struct expression
*, int *, enum noside
,
66 evaluate_subexp (struct type
*expect_type
, register struct expression
*exp
,
67 register int *pos
, enum noside noside
)
69 return (*exp
->language_defn
->evaluate_exp
) (expect_type
, exp
, pos
, noside
);
72 /* Parse the string EXP as a C expression, evaluate it,
73 and return the result as a number. */
76 parse_and_eval_address (char *exp
)
78 struct expression
*expr
= parse_expression (exp
);
79 register CORE_ADDR addr
;
80 register struct cleanup
*old_chain
=
81 make_cleanup (free_current_contents
, &expr
);
83 addr
= value_as_address (evaluate_expression (expr
));
84 do_cleanups (old_chain
);
88 /* Like parse_and_eval_address but takes a pointer to a char * variable
89 and advanced that variable across the characters parsed. */
92 parse_and_eval_address_1 (char **expptr
)
94 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*) 0, 0);
95 register CORE_ADDR addr
;
96 register struct cleanup
*old_chain
=
97 make_cleanup (free_current_contents
, &expr
);
99 addr
= value_as_address (evaluate_expression (expr
));
100 do_cleanups (old_chain
);
104 /* Like parse_and_eval_address, but treats the value of the expression
105 as an integer, not an address, returns a LONGEST, not a CORE_ADDR */
107 parse_and_eval_long (char *exp
)
109 struct expression
*expr
= parse_expression (exp
);
110 register LONGEST retval
;
111 register struct cleanup
*old_chain
=
112 make_cleanup (free_current_contents
, &expr
);
114 retval
= value_as_long (evaluate_expression (expr
));
115 do_cleanups (old_chain
);
120 parse_and_eval (char *exp
)
122 struct expression
*expr
= parse_expression (exp
);
124 register struct cleanup
*old_chain
=
125 make_cleanup (free_current_contents
, &expr
);
127 val
= evaluate_expression (expr
);
128 do_cleanups (old_chain
);
132 /* Parse up to a comma (or to a closeparen)
133 in the string EXPP as an expression, evaluate it, and return the value.
134 EXPP is advanced to point to the comma. */
137 parse_to_comma_and_eval (char **expp
)
139 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
141 register struct cleanup
*old_chain
=
142 make_cleanup (free_current_contents
, &expr
);
144 val
= evaluate_expression (expr
);
145 do_cleanups (old_chain
);
149 /* Evaluate an expression in internal prefix form
150 such as is constructed by parse.y.
152 See expression.h for info on the format of an expression. */
155 evaluate_expression (struct expression
*exp
)
158 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
161 /* Evaluate an expression, avoiding all memory references
162 and getting a value whose type alone is correct. */
165 evaluate_type (struct expression
*exp
)
168 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
171 /* If the next expression is an OP_LABELED, skips past it,
172 returning the label. Otherwise, does nothing and returns NULL. */
175 get_label (register struct expression
*exp
, int *pos
)
177 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
180 char *name
= &exp
->elts
[pc
+ 2].string
;
181 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
182 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
189 /* This function evaluates tuples (in (OBSOLETE) Chill) or
190 brace-initializers (in C/C++) for structure types. */
192 static struct value
*
193 evaluate_struct_tuple (struct value
*struct_val
,
194 register struct expression
*exp
,
195 register int *pos
, enum noside noside
, int nargs
)
197 struct type
*struct_type
= check_typedef (VALUE_TYPE (struct_val
));
198 struct type
*substruct_type
= struct_type
;
199 struct type
*field_type
;
206 struct value
*val
= NULL
;
211 /* Skip past the labels, and count them. */
212 while (get_label (exp
, pos
) != NULL
)
217 char *label
= get_label (exp
, &pc
);
220 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
223 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
224 if (field_name
!= NULL
&& STREQ (field_name
, label
))
227 subfieldno
= fieldno
;
228 substruct_type
= struct_type
;
232 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
235 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
236 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
237 if ((field_name
== 0 || *field_name
== '\0')
238 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
241 for (; variantno
< TYPE_NFIELDS (field_type
);
245 = TYPE_FIELD_TYPE (field_type
, variantno
);
246 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
249 subfieldno
< TYPE_NFIELDS (substruct_type
);
252 if (STREQ (TYPE_FIELD_NAME (substruct_type
,
263 error ("there is no field named %s", label
);
269 /* Unlabelled tuple element - go to next field. */
273 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
276 substruct_type
= struct_type
;
282 subfieldno
= fieldno
;
283 if (fieldno
>= TYPE_NFIELDS (struct_type
))
284 error ("too many initializers");
285 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
286 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
287 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
288 error ("don't know which variant you want to set");
292 /* Here, struct_type is the type of the inner struct,
293 while substruct_type is the type of the inner struct.
294 These are the same for normal structures, but a variant struct
295 contains anonymous union fields that contain substruct fields.
296 The value fieldno is the index of the top-level (normal or
297 anonymous union) field in struct_field, while the value
298 subfieldno is the index of the actual real (named inner) field
299 in substruct_type. */
301 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
303 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
305 /* Now actually set the field in struct_val. */
307 /* Assign val to field fieldno. */
308 if (VALUE_TYPE (val
) != field_type
)
309 val
= value_cast (field_type
, val
);
311 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
312 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
314 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
315 addr
= VALUE_CONTENTS (struct_val
) + bitpos
/ 8;
317 modify_field (addr
, value_as_long (val
),
318 bitpos
% 8, bitsize
);
320 memcpy (addr
, VALUE_CONTENTS (val
),
321 TYPE_LENGTH (VALUE_TYPE (val
)));
323 while (--nlabels
> 0);
328 /* Recursive helper function for setting elements of array tuples for
329 (OBSOLETE) Chill. The target is ARRAY (which has bounds LOW_BOUND
330 to HIGH_BOUND); the element value is ELEMENT; EXP, POS and NOSIDE
331 are as usual. Evaluates index expresions and sets the specified
332 element(s) of ARRAY to ELEMENT. Returns last index value. */
335 init_array_element (struct value
*array
, struct value
*element
,
336 register struct expression
*exp
, register int *pos
,
337 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
340 int element_size
= TYPE_LENGTH (VALUE_TYPE (element
));
341 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
344 init_array_element (array
, element
, exp
, pos
, noside
,
345 low_bound
, high_bound
);
346 return init_array_element (array
, element
,
347 exp
, pos
, noside
, low_bound
, high_bound
);
349 else if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
353 low
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
354 high
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
355 if (low
< low_bound
|| high
> high_bound
)
356 error ("tuple range index out of range");
357 for (index
= low
; index
<= high
; index
++)
359 memcpy (VALUE_CONTENTS_RAW (array
)
360 + (index
- low_bound
) * element_size
,
361 VALUE_CONTENTS (element
), element_size
);
366 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
367 if (index
< low_bound
|| index
> high_bound
)
368 error ("tuple index out of range");
369 memcpy (VALUE_CONTENTS_RAW (array
) + (index
- low_bound
) * element_size
,
370 VALUE_CONTENTS (element
), element_size
);
376 evaluate_subexp_standard (struct type
*expect_type
,
377 register struct expression
*exp
, register int *pos
,
382 register int pc
, pc2
= 0, oldpos
;
383 struct value
*arg1
= NULL
;
384 struct value
*arg2
= NULL
;
388 struct value
**argvec
;
389 int upper
, lower
, retcode
;
393 struct type
**arg_types
;
397 op
= exp
->elts
[pc
].opcode
;
402 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
403 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
404 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
406 exp
->elts
[pc
+ 1].type
,
407 &exp
->elts
[pc
+ 3].string
,
410 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
415 return value_from_longest (exp
->elts
[pc
+ 1].type
,
416 exp
->elts
[pc
+ 2].longconst
);
420 return value_from_double (exp
->elts
[pc
+ 1].type
,
421 exp
->elts
[pc
+ 2].doubleconst
);
425 if (noside
== EVAL_SKIP
)
428 /* JYG: We used to just return value_zero of the symbol type
429 if we're asked to avoid side effects. Otherwise we return
430 value_of_variable (...). However I'm not sure if
431 value_of_variable () has any side effect.
432 We need a full value object returned here for whatis_exp ()
433 to call evaluate_type () and then pass the full value to
434 value_rtti_target_type () if we are dealing with a pointer
435 or reference to a base class and print object is on. */
437 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
438 exp
->elts
[pc
+ 1].block
);
443 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
447 int regno
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
448 struct value
*val
= value_of_register (regno
, selected_frame
);
451 error ("Value of register %s not available.",
452 frame_map_regnum_to_name (regno
));
458 return value_from_longest (LA_BOOL_TYPE
,
459 exp
->elts
[pc
+ 1].longconst
);
463 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
466 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
467 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
468 if (noside
== EVAL_SKIP
)
470 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
473 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
475 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
476 if (noside
== EVAL_SKIP
)
478 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
483 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
484 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
485 nargs
= tem3
- tem2
+ 1;
486 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
488 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
489 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
491 struct value
*rec
= allocate_value (expect_type
);
492 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (type
));
493 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
496 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
497 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
499 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
500 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
501 struct value
*array
= allocate_value (expect_type
);
502 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
503 LONGEST low_bound
, high_bound
, index
;
504 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
507 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
510 memset (VALUE_CONTENTS_RAW (array
), 0, TYPE_LENGTH (expect_type
));
511 for (tem
= nargs
; --nargs
>= 0;)
513 struct value
*element
;
515 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
518 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
520 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
521 if (VALUE_TYPE (element
) != element_type
)
522 element
= value_cast (element_type
, element
);
525 int continue_pc
= *pos
;
527 index
= init_array_element (array
, element
, exp
, pos
, noside
,
528 low_bound
, high_bound
);
533 if (index
> high_bound
)
534 /* to avoid memory corruption */
535 error ("Too many array elements");
536 memcpy (VALUE_CONTENTS_RAW (array
)
537 + (index
- low_bound
) * element_size
,
538 VALUE_CONTENTS (element
),
546 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
547 && TYPE_CODE (type
) == TYPE_CODE_SET
)
549 struct value
*set
= allocate_value (expect_type
);
550 char *valaddr
= VALUE_CONTENTS_RAW (set
);
551 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
552 struct type
*check_type
= element_type
;
553 LONGEST low_bound
, high_bound
;
555 /* get targettype of elementtype */
556 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
||
557 TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
558 check_type
= TYPE_TARGET_TYPE (check_type
);
560 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
561 error ("(power)set type with unknown size");
562 memset (valaddr
, '\0', TYPE_LENGTH (type
));
563 for (tem
= 0; tem
< nargs
; tem
++)
565 LONGEST range_low
, range_high
;
566 struct type
*range_low_type
, *range_high_type
;
567 struct value
*elem_val
;
568 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
571 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
572 range_low_type
= VALUE_TYPE (elem_val
);
573 range_low
= value_as_long (elem_val
);
574 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
575 range_high_type
= VALUE_TYPE (elem_val
);
576 range_high
= value_as_long (elem_val
);
580 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
581 range_low_type
= range_high_type
= VALUE_TYPE (elem_val
);
582 range_low
= range_high
= value_as_long (elem_val
);
584 /* check types of elements to avoid mixture of elements from
585 different types. Also check if type of element is "compatible"
586 with element type of powerset */
587 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
588 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
589 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
590 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
591 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
)) ||
592 (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
&&
593 (range_low_type
!= range_high_type
)))
594 /* different element modes */
595 error ("POWERSET tuple elements of different mode");
596 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
)) ||
597 (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
&&
598 range_low_type
!= check_type
))
599 error ("incompatible POWERSET tuple elements");
600 if (range_low
> range_high
)
602 warning ("empty POWERSET tuple range");
605 if (range_low
< low_bound
|| range_high
> high_bound
)
606 error ("POWERSET tuple element out of range");
607 range_low
-= low_bound
;
608 range_high
-= low_bound
;
609 for (; range_low
<= range_high
; range_low
++)
611 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
613 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
614 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
621 argvec
= (struct value
**) alloca (sizeof (struct value
*) * nargs
);
622 for (tem
= 0; tem
< nargs
; tem
++)
624 /* Ensure that array expressions are coerced into pointer objects. */
625 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
627 if (noside
== EVAL_SKIP
)
629 return value_array (tem2
, tem3
, argvec
);
633 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
635 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
637 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
638 if (noside
== EVAL_SKIP
)
640 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
643 case TERNOP_SLICE_COUNT
:
645 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
647 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
649 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
650 return value_slice (array
, lowbound
, length
);
654 /* Skip third and second args to evaluate the first one. */
655 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
656 if (value_logical_not (arg1
))
658 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
659 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
663 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
664 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
670 op
= exp
->elts
[*pos
].opcode
;
671 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
672 /* Allocate arg vector, including space for the function to be
673 called in argvec[0] and a terminating NULL */
674 argvec
= (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 3));
675 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
679 /* 1997-08-01 Currently we do not support function invocation
680 via pointers-to-methods with HP aCC. Pointer does not point
681 to the function, but possibly to some thunk. */
682 if (hp_som_som_object_present
)
684 error ("Not implemented: function invocation through pointer to method with HP aCC");
688 /* First, evaluate the structure into arg2 */
691 if (noside
== EVAL_SKIP
)
694 if (op
== STRUCTOP_MEMBER
)
696 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
700 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
703 /* If the function is a virtual function, then the
704 aggregate value (providing the structure) plays
705 its part by providing the vtable. Otherwise,
706 it is just along for the ride: call the function
709 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
711 fnptr
= value_as_long (arg1
);
713 if (METHOD_PTR_IS_VIRTUAL (fnptr
))
715 int fnoffset
= METHOD_PTR_TO_VOFFSET (fnptr
);
716 struct type
*basetype
;
717 struct type
*domain_type
=
718 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
720 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
721 if (domain_type
!= basetype
)
722 arg2
= value_cast (lookup_pointer_type (domain_type
), arg2
);
723 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
724 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
726 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
727 /* If one is virtual, then all are virtual. */
728 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
729 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
730 if ((int) TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
732 struct value
*temp
= value_ind (arg2
);
733 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
734 arg2
= value_addr (temp
);
739 error ("virtual function at index %d not found", fnoffset
);
743 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
747 /* Now, say which argument to start evaluating from */
750 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
752 /* Hair for method invocations */
756 /* First, evaluate the structure into arg2 */
758 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
759 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
760 if (noside
== EVAL_SKIP
)
763 if (op
== STRUCTOP_STRUCT
)
765 /* If v is a variable in a register, and the user types
766 v.method (), this will produce an error, because v has
769 A possible way around this would be to allocate a
770 copy of the variable on the stack, copy in the
771 contents, call the function, and copy out the
772 contents. I.e. convert this from call by reference
773 to call by copy-return (or whatever it's called).
774 However, this does not work because it is not the
775 same: the method being called could stash a copy of
776 the address, and then future uses through that address
777 (after the method returns) would be expected to
778 use the variable itself, not some copy of it. */
779 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
783 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
785 /* Now, say which argument to start evaluating from */
790 /* Non-method function call */
792 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
794 type
= VALUE_TYPE (argvec
[0]);
795 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
796 type
= TYPE_TARGET_TYPE (type
);
797 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
799 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
801 /* pai: FIXME This seems to be coercing arguments before
802 * overload resolution has been done! */
803 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
, tem
- 1),
809 /* Evaluate arguments */
810 for (; tem
<= nargs
; tem
++)
812 /* Ensure that array expressions are coerced into pointer objects. */
813 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
816 /* signal end of arglist */
819 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
824 /* Method invocation : stuff "this" as first parameter */
826 /* Name of method from expression */
827 strcpy (tstr
, &exp
->elts
[pc2
+ 2].string
);
829 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
831 /* Language is C++, do some overload resolution before evaluation */
832 struct value
*valp
= NULL
;
834 /* Prepare list of argument types for overload resolution */
835 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
836 for (ix
= 1; ix
<= nargs
; ix
++)
837 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
839 (void) find_overload_match (arg_types
, nargs
, tstr
,
840 1 /* method */ , 0 /* strict match */ ,
841 &arg2
/* the object */ , NULL
,
842 &valp
, NULL
, &static_memfuncp
);
845 argvec
[1] = arg2
; /* the ``this'' pointer */
846 argvec
[0] = valp
; /* use the method found after overload resolution */
849 /* Non-C++ case -- or no overload resolution */
851 struct value
*temp
= arg2
;
852 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
854 op
== STRUCTOP_STRUCT
855 ? "structure" : "structure pointer");
856 /* value_struct_elt updates temp with the correct value
857 of the ``this'' pointer if necessary, so modify argvec[1] to
858 reflect any ``this'' changes. */
859 arg2
= value_from_longest (lookup_pointer_type(VALUE_TYPE (temp
)),
860 VALUE_ADDRESS (temp
) + VALUE_OFFSET (temp
)
861 + VALUE_EMBEDDED_OFFSET (temp
));
862 argvec
[1] = arg2
; /* the ``this'' pointer */
867 argvec
[1] = argvec
[0];
872 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
877 else if (op
== OP_VAR_VALUE
)
879 /* Non-member function being called */
880 /* fn: This can only be done for C++ functions. A C-style function
881 in a C++ program, for instance, does not have the fields that
884 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
886 /* Language is C++, do some overload resolution before evaluation */
889 /* Prepare list of argument types for overload resolution */
890 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
891 for (ix
= 1; ix
<= nargs
; ix
++)
892 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
894 (void) find_overload_match (arg_types
, nargs
, NULL
/* no need for name */ ,
895 0 /* not method */ , 0 /* strict match */ ,
896 NULL
, exp
->elts
[save_pos1
+2].symbol
/* the function */ ,
899 /* Now fix the expression being evaluated */
900 exp
->elts
[save_pos1
+2].symbol
= symp
;
901 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
905 /* Not C++, or no overload resolution allowed */
906 /* nothing to be done; argvec already correctly set up */
911 /* It is probably a C-style function */
912 /* nothing to be done; argvec already correctly set up */
917 if (noside
== EVAL_SKIP
)
919 if (argvec
[0] == NULL
)
920 error ("Cannot evaluate function -- may be inlined");
921 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
923 /* If the return type doesn't look like a function type, call an
924 error. This can happen if somebody tries to turn a variable into
925 a function call. This is here because people often want to
926 call, eg, strcmp, which gdb doesn't know is a function. If
927 gdb isn't asked for it's opinion (ie. through "whatis"),
928 it won't offer it. */
931 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
934 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
936 error ("Expression of type other than \"Function returning ...\" used as function");
938 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
939 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
941 case OP_F77_UNDETERMINED_ARGLIST
:
943 /* Remember that in F77, functions, substring ops and
944 array subscript operations cannot be disambiguated
945 at parse time. We have made all array subscript operations,
946 substring operations as well as function calls come here
947 and we now have to discover what the heck this thing actually was.
948 If it is a function, we process just as if we got an OP_FUNCALL. */
950 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
953 /* First determine the type code we are dealing with. */
954 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
955 type
= check_typedef (VALUE_TYPE (arg1
));
956 code
= TYPE_CODE (type
);
960 case TYPE_CODE_ARRAY
:
961 goto multi_f77_subscript
;
963 case TYPE_CODE_STRING
:
968 /* It's a function call. */
969 /* Allocate arg vector, including space for the function to be
970 called in argvec[0] and a terminating NULL */
971 argvec
= (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 2));
974 for (; tem
<= nargs
; tem
++)
975 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
976 argvec
[tem
] = 0; /* signal end of arglist */
980 error ("Cannot perform substring on this type");
984 /* We have a substring operation on our hands here,
985 let us get the string we will be dealing with */
987 /* Now evaluate the 'from' and 'to' */
989 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
992 return value_subscript (arg1
, arg2
);
994 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
996 if (noside
== EVAL_SKIP
)
999 tem2
= value_as_long (arg2
);
1000 tem3
= value_as_long (arg3
);
1002 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
1005 /* We have a complex number, There should be 2 floating
1006 point numbers that compose it */
1007 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1008 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1010 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
1012 case STRUCTOP_STRUCT
:
1013 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1014 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1015 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1016 if (noside
== EVAL_SKIP
)
1018 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1019 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1020 &exp
->elts
[pc
+ 2].string
,
1025 struct value
*temp
= arg1
;
1026 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1031 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1032 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1033 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1034 if (noside
== EVAL_SKIP
)
1037 /* JYG: if print object is on we need to replace the base type
1038 with rtti type in order to continue on with successful
1039 lookup of member / method only available in the rtti type. */
1041 struct type
*type
= VALUE_TYPE (arg1
);
1042 struct type
*real_type
;
1043 int full
, top
, using_enc
;
1045 if (objectprint
&& TYPE_TARGET_TYPE(type
) &&
1046 (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CLASS
))
1048 real_type
= value_rtti_target_type (arg1
, &full
, &top
, &using_enc
);
1051 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1052 real_type
= lookup_pointer_type (real_type
);
1054 real_type
= lookup_reference_type (real_type
);
1056 arg1
= value_cast (real_type
, arg1
);
1061 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1062 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1063 &exp
->elts
[pc
+ 2].string
,
1068 struct value
*temp
= arg1
;
1069 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1070 NULL
, "structure pointer");
1073 case STRUCTOP_MEMBER
:
1074 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1075 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1077 /* With HP aCC, pointers to methods do not point to the function code */
1078 if (hp_som_som_object_present
&&
1079 (TYPE_CODE (VALUE_TYPE (arg2
)) == TYPE_CODE_PTR
) &&
1080 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
))) == TYPE_CODE_METHOD
))
1081 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1083 mem_offset
= value_as_long (arg2
);
1084 goto handle_pointer_to_member
;
1087 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1088 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1090 /* With HP aCC, pointers to methods do not point to the function code */
1091 if (hp_som_som_object_present
&&
1092 (TYPE_CODE (VALUE_TYPE (arg2
)) == TYPE_CODE_PTR
) &&
1093 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
))) == TYPE_CODE_METHOD
))
1094 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1096 mem_offset
= value_as_long (arg2
);
1098 handle_pointer_to_member
:
1099 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1100 a real offset to the member. */
1101 if (hp_som_som_object_present
)
1103 if (!mem_offset
) /* no bias -> really null */
1104 error ("Attempted dereference of null pointer-to-member");
1105 mem_offset
&= ~0x20000000;
1107 if (noside
== EVAL_SKIP
)
1109 type
= check_typedef (VALUE_TYPE (arg2
));
1110 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
1111 goto bad_pointer_to_member
;
1112 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1113 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
1114 error ("not implemented: pointer-to-method in pointer-to-member construct");
1115 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
1116 goto bad_pointer_to_member
;
1117 /* Now, convert these values to an address. */
1118 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
1120 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1121 value_as_long (arg1
) + mem_offset
);
1122 return value_ind (arg3
);
1123 bad_pointer_to_member
:
1124 error ("non-pointer-to-member value used in pointer-to-member construct");
1127 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1128 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1129 if (noside
== EVAL_SKIP
)
1131 if (binop_user_defined_p (op
, arg1
, arg2
))
1132 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1134 return value_concat (arg1
, arg2
);
1137 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1138 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1140 /* Do special stuff for HP aCC pointers to members */
1141 if (hp_som_som_object_present
)
1143 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1144 the implementation yet; but the pointer appears to point to a code
1145 sequence (thunk) in memory -- in any case it is *not* the address
1146 of the function as it would be in a naive implementation. */
1147 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1148 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
))
1149 error ("Assignment to pointers to methods not implemented with HP aCC");
1151 /* HP aCC pointers to data members require a constant bias */
1152 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1153 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
))
1155 unsigned int *ptr
= (unsigned int *) VALUE_CONTENTS (arg2
); /* forces evaluation */
1156 *ptr
|= 0x20000000; /* set 29th bit */
1160 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1162 if (binop_user_defined_p (op
, arg1
, arg2
))
1163 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1165 return value_assign (arg1
, arg2
);
1167 case BINOP_ASSIGN_MODIFY
:
1169 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1170 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1171 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1173 op
= exp
->elts
[pc
+ 1].opcode
;
1174 if (binop_user_defined_p (op
, arg1
, arg2
))
1175 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
1176 else if (op
== BINOP_ADD
)
1177 arg2
= value_add (arg1
, arg2
);
1178 else if (op
== BINOP_SUB
)
1179 arg2
= value_sub (arg1
, arg2
);
1181 arg2
= value_binop (arg1
, arg2
, op
);
1182 return value_assign (arg1
, arg2
);
1185 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1186 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1187 if (noside
== EVAL_SKIP
)
1189 if (binop_user_defined_p (op
, arg1
, arg2
))
1190 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1192 return value_add (arg1
, arg2
);
1195 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1196 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1197 if (noside
== EVAL_SKIP
)
1199 if (binop_user_defined_p (op
, arg1
, arg2
))
1200 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1202 return value_sub (arg1
, arg2
);
1210 case BINOP_BITWISE_AND
:
1211 case BINOP_BITWISE_IOR
:
1212 case BINOP_BITWISE_XOR
:
1213 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1214 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1215 if (noside
== EVAL_SKIP
)
1217 if (binop_user_defined_p (op
, arg1
, arg2
))
1218 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1219 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
1220 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
1221 return value_zero (VALUE_TYPE (arg1
), not_lval
);
1223 return value_binop (arg1
, arg2
, op
);
1226 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1227 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1228 if (noside
== EVAL_SKIP
)
1230 error ("':' operator used in invalid context");
1232 case BINOP_SUBSCRIPT
:
1233 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1234 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1235 if (noside
== EVAL_SKIP
)
1237 if (binop_user_defined_p (op
, arg1
, arg2
))
1238 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1241 /* If the user attempts to subscript something that is not an
1242 array or pointer type (like a plain int variable for example),
1243 then report this as an error. */
1246 type
= check_typedef (VALUE_TYPE (arg1
));
1247 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
1248 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
1250 if (TYPE_NAME (type
))
1251 error ("cannot subscript something of type `%s'",
1254 error ("cannot subscript requested type");
1257 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1258 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
1260 return value_subscript (arg1
, arg2
);
1264 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1265 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1266 if (noside
== EVAL_SKIP
)
1268 return value_in (arg1
, arg2
);
1270 case MULTI_SUBSCRIPT
:
1272 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1273 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1276 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1277 /* FIXME: EVAL_SKIP handling may not be correct. */
1278 if (noside
== EVAL_SKIP
)
1289 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1290 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1292 /* If the user attempts to subscript something that has no target
1293 type (like a plain int variable for example), then report this
1296 type
= TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (arg1
)));
1299 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1305 error ("cannot subscript something of type `%s'",
1306 TYPE_NAME (VALUE_TYPE (arg1
)));
1310 if (binop_user_defined_p (op
, arg1
, arg2
))
1312 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1316 arg1
= value_subscript (arg1
, arg2
);
1321 multi_f77_subscript
:
1323 int subscript_array
[MAX_FORTRAN_DIMS
+ 1]; /* 1-based array of
1324 subscripts, max == 7 */
1325 int array_size_array
[MAX_FORTRAN_DIMS
+ 1];
1326 int ndimensions
= 1, i
;
1327 struct type
*tmp_type
;
1328 int offset_item
; /* The array offset where the item lives */
1330 if (nargs
> MAX_FORTRAN_DIMS
)
1331 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
1333 tmp_type
= check_typedef (VALUE_TYPE (arg1
));
1334 ndimensions
= calc_f77_array_dims (type
);
1336 if (nargs
!= ndimensions
)
1337 error ("Wrong number of subscripts");
1339 /* Now that we know we have a legal array subscript expression
1340 let us actually find out where this element exists in the array. */
1343 for (i
= 1; i
<= nargs
; i
++)
1345 /* Evaluate each subscript, It must be a legal integer in F77 */
1346 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1348 /* Fill in the subscript and array size arrays */
1350 subscript_array
[i
] = value_as_long (arg2
);
1352 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1353 if (retcode
== BOUND_FETCH_ERROR
)
1354 error ("Cannot obtain dynamic upper bound");
1356 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1357 if (retcode
== BOUND_FETCH_ERROR
)
1358 error ("Cannot obtain dynamic lower bound");
1360 array_size_array
[i
] = upper
- lower
+ 1;
1362 /* Zero-normalize subscripts so that offsetting will work. */
1364 subscript_array
[i
] -= lower
;
1366 /* If we are at the bottom of a multidimensional
1367 array type then keep a ptr to the last ARRAY
1368 type around for use when calling value_subscript()
1369 below. This is done because we pretend to value_subscript
1370 that we actually have a one-dimensional array
1371 of base element type that we apply a simple
1375 tmp_type
= check_typedef (TYPE_TARGET_TYPE (tmp_type
));
1378 /* Now let us calculate the offset for this item */
1380 offset_item
= subscript_array
[ndimensions
];
1382 for (i
= ndimensions
- 1; i
>= 1; i
--)
1384 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1386 /* Construct a value node with the value of the offset */
1388 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1390 /* Let us now play a dirty trick: we will take arg1
1391 which is a value node pointing to the topmost level
1392 of the multidimensional array-set and pretend
1393 that it is actually a array of the final element
1394 type, this will ensure that value_subscript()
1395 returns the correct type value */
1397 VALUE_TYPE (arg1
) = tmp_type
;
1398 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1401 case BINOP_LOGICAL_AND
:
1402 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1403 if (noside
== EVAL_SKIP
)
1405 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1410 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1413 if (binop_user_defined_p (op
, arg1
, arg2
))
1415 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1416 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1420 tem
= value_logical_not (arg1
);
1421 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1422 (tem
? EVAL_SKIP
: noside
));
1423 return value_from_longest (LA_BOOL_TYPE
,
1424 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1427 case BINOP_LOGICAL_OR
:
1428 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1429 if (noside
== EVAL_SKIP
)
1431 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1436 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1439 if (binop_user_defined_p (op
, arg1
, arg2
))
1441 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1442 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1446 tem
= value_logical_not (arg1
);
1447 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1448 (!tem
? EVAL_SKIP
: noside
));
1449 return value_from_longest (LA_BOOL_TYPE
,
1450 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1454 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1455 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1456 if (noside
== EVAL_SKIP
)
1458 if (binop_user_defined_p (op
, arg1
, arg2
))
1460 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1464 tem
= value_equal (arg1
, arg2
);
1465 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1468 case BINOP_NOTEQUAL
:
1469 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1470 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1471 if (noside
== EVAL_SKIP
)
1473 if (binop_user_defined_p (op
, arg1
, arg2
))
1475 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1479 tem
= value_equal (arg1
, arg2
);
1480 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) ! tem
);
1484 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1485 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1486 if (noside
== EVAL_SKIP
)
1488 if (binop_user_defined_p (op
, arg1
, arg2
))
1490 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1494 tem
= value_less (arg1
, arg2
);
1495 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1499 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1500 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1501 if (noside
== EVAL_SKIP
)
1503 if (binop_user_defined_p (op
, arg1
, arg2
))
1505 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1509 tem
= value_less (arg2
, arg1
);
1510 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1514 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1515 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1516 if (noside
== EVAL_SKIP
)
1518 if (binop_user_defined_p (op
, arg1
, arg2
))
1520 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1524 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1525 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1529 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1530 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1531 if (noside
== EVAL_SKIP
)
1533 if (binop_user_defined_p (op
, arg1
, arg2
))
1535 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1539 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1540 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1544 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1545 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1546 if (noside
== EVAL_SKIP
)
1548 type
= check_typedef (VALUE_TYPE (arg2
));
1549 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
1550 error ("Non-integral right operand for \"@\" operator.");
1551 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1553 return allocate_repeat_value (VALUE_TYPE (arg1
),
1554 longest_to_int (value_as_long (arg2
)));
1557 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1560 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1561 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1564 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1565 if (noside
== EVAL_SKIP
)
1567 if (unop_user_defined_p (op
, arg1
))
1568 return value_x_unop (arg1
, op
, noside
);
1570 return value_neg (arg1
);
1572 case UNOP_COMPLEMENT
:
1573 /* C++: check for and handle destructor names. */
1574 op
= exp
->elts
[*pos
].opcode
;
1576 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1577 if (noside
== EVAL_SKIP
)
1579 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1580 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
1582 return value_complement (arg1
);
1584 case UNOP_LOGICAL_NOT
:
1585 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1586 if (noside
== EVAL_SKIP
)
1588 if (unop_user_defined_p (op
, arg1
))
1589 return value_x_unop (arg1
, op
, noside
);
1591 return value_from_longest (LA_BOOL_TYPE
,
1592 (LONGEST
) value_logical_not (arg1
));
1595 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1596 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1597 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1598 if ((TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) &&
1599 ((TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
) ||
1600 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
)))
1601 error ("Attempt to dereference pointer to member without an object");
1602 if (noside
== EVAL_SKIP
)
1604 if (unop_user_defined_p (op
, arg1
))
1605 return value_x_unop (arg1
, op
, noside
);
1606 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1608 type
= check_typedef (VALUE_TYPE (arg1
));
1609 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1610 || TYPE_CODE (type
) == TYPE_CODE_REF
1611 /* In C you can dereference an array to get the 1st elt. */
1612 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
1614 return value_zero (TYPE_TARGET_TYPE (type
),
1616 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
1617 /* GDB allows dereferencing an int. */
1618 return value_zero (builtin_type_int
, lval_memory
);
1620 error ("Attempt to take contents of a non-pointer value.");
1622 return value_ind (arg1
);
1625 /* C++: check for and handle pointer to members. */
1627 op
= exp
->elts
[*pos
].opcode
;
1629 if (noside
== EVAL_SKIP
)
1633 int temm
= longest_to_int (exp
->elts
[pc
+ 3].longconst
);
1634 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1637 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1642 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
, noside
);
1643 /* If HP aCC object, use bias for pointers to members */
1644 if (hp_som_som_object_present
&&
1645 (TYPE_CODE (VALUE_TYPE (retvalp
)) == TYPE_CODE_PTR
) &&
1646 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (retvalp
))) == TYPE_CODE_MEMBER
))
1648 unsigned int *ptr
= (unsigned int *) VALUE_CONTENTS (retvalp
); /* forces evaluation */
1649 *ptr
|= 0x20000000; /* set 29th bit */
1655 if (noside
== EVAL_SKIP
)
1657 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1660 return evaluate_subexp_for_sizeof (exp
, pos
);
1664 type
= exp
->elts
[pc
+ 1].type
;
1665 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1666 if (noside
== EVAL_SKIP
)
1668 if (type
!= VALUE_TYPE (arg1
))
1669 arg1
= value_cast (type
, arg1
);
1674 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1675 if (noside
== EVAL_SKIP
)
1677 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1678 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1680 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1681 value_as_address (arg1
),
1684 case UNOP_PREINCREMENT
:
1685 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1686 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1688 else if (unop_user_defined_p (op
, arg1
))
1690 return value_x_unop (arg1
, op
, noside
);
1694 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1696 return value_assign (arg1
, arg2
);
1699 case UNOP_PREDECREMENT
:
1700 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1701 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1703 else if (unop_user_defined_p (op
, arg1
))
1705 return value_x_unop (arg1
, op
, noside
);
1709 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1711 return value_assign (arg1
, arg2
);
1714 case UNOP_POSTINCREMENT
:
1715 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1716 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1718 else if (unop_user_defined_p (op
, arg1
))
1720 return value_x_unop (arg1
, op
, noside
);
1724 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1726 value_assign (arg1
, arg2
);
1730 case UNOP_POSTDECREMENT
:
1731 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1732 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1734 else if (unop_user_defined_p (op
, arg1
))
1736 return value_x_unop (arg1
, op
, noside
);
1740 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1742 value_assign (arg1
, arg2
);
1748 return value_of_this (1);
1751 error ("Attempt to use a type name as an expression");
1754 /* Removing this case and compiling with gcc -Wall reveals that
1755 a lot of cases are hitting this case. Some of these should
1756 probably be removed from expression.h; others are legitimate
1757 expressions which are (apparently) not fully implemented.
1759 If there are any cases landing here which mean a user error,
1760 then they should be separate cases, with more descriptive
1764 GDB does not (yet) know how to evaluate that kind of expression");
1768 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1771 /* Evaluate a subexpression of EXP, at index *POS,
1772 and return the address of that subexpression.
1773 Advance *POS over the subexpression.
1774 If the subexpression isn't an lvalue, get an error.
1775 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1776 then only the type of the result need be correct. */
1778 static struct value
*
1779 evaluate_subexp_for_address (register struct expression
*exp
, register int *pos
,
1787 op
= exp
->elts
[pc
].opcode
;
1793 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1797 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1798 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1801 var
= exp
->elts
[pc
+ 2].symbol
;
1803 /* C++: The "address" of a reference should yield the address
1804 * of the object pointed to. Let value_addr() deal with it. */
1805 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1809 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1812 lookup_pointer_type (SYMBOL_TYPE (var
));
1813 enum address_class sym_class
= SYMBOL_CLASS (var
);
1815 if (sym_class
== LOC_CONST
1816 || sym_class
== LOC_CONST_BYTES
1817 || sym_class
== LOC_REGISTER
1818 || sym_class
== LOC_REGPARM
)
1819 error ("Attempt to take address of register or constant.");
1822 value_zero (type
, not_lval
);
1828 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1832 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1834 struct value
*x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1835 if (VALUE_LVAL (x
) == lval_memory
)
1836 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1839 error ("Attempt to take address of non-lval");
1841 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1845 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1846 When used in contexts where arrays will be coerced anyway, this is
1847 equivalent to `evaluate_subexp' but much faster because it avoids
1848 actually fetching array contents (perhaps obsolete now that we have
1851 Note that we currently only do the coercion for C expressions, where
1852 arrays are zero based and the coercion is correct. For other languages,
1853 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1854 to decide if coercion is appropriate.
1859 evaluate_subexp_with_coercion (register struct expression
*exp
,
1860 register int *pos
, enum noside noside
)
1862 register enum exp_opcode op
;
1868 op
= exp
->elts
[pc
].opcode
;
1873 var
= exp
->elts
[pc
+ 2].symbol
;
1874 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var
))) == TYPE_CODE_ARRAY
1875 && CAST_IS_CONVERSION
)
1880 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1881 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var
)))),
1887 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1891 /* Evaluate a subexpression of EXP, at index *POS,
1892 and return a value for the size of that subexpression.
1893 Advance *POS over the subexpression. */
1895 static struct value
*
1896 evaluate_subexp_for_sizeof (register struct expression
*exp
, register int *pos
)
1904 op
= exp
->elts
[pc
].opcode
;
1908 /* This case is handled specially
1909 so that we avoid creating a value for the result type.
1910 If the result type is very big, it's desirable not to
1911 create a value unnecessarily. */
1914 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1915 type
= check_typedef (VALUE_TYPE (val
));
1916 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1917 && TYPE_CODE (type
) != TYPE_CODE_REF
1918 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1919 error ("Attempt to take contents of a non-pointer value.");
1920 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1921 return value_from_longest (builtin_type_int
, (LONGEST
)
1922 TYPE_LENGTH (type
));
1926 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
1927 return value_from_longest (builtin_type_int
,
1928 (LONGEST
) TYPE_LENGTH (type
));
1932 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
1934 value_from_longest (builtin_type_int
, (LONGEST
) TYPE_LENGTH (type
));
1937 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1938 return value_from_longest (builtin_type_int
,
1939 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1943 /* Parse a type expression in the string [P..P+LENGTH). */
1946 parse_and_eval_type (char *p
, int length
)
1948 char *tmp
= (char *) alloca (length
+ 4);
1949 struct expression
*expr
;
1951 memcpy (tmp
+ 1, p
, length
);
1952 tmp
[length
+ 1] = ')';
1953 tmp
[length
+ 2] = '0';
1954 tmp
[length
+ 3] = '\0';
1955 expr
= parse_expression (tmp
);
1956 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1957 error ("Internal error in eval_type.");
1958 return expr
->elts
[1].type
;
1962 calc_f77_array_dims (struct type
*array_type
)
1965 struct type
*tmp_type
;
1967 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
1968 error ("Can't get dimensions for a non-array type");
1970 tmp_type
= array_type
;
1972 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1974 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)