1 /* Evaluate expressions for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
29 #include "expression.h"
32 #include "language.h" /* For CAST_IS_CONVERSION */
33 #include "f-lang.h" /* for array bound stuff */
37 /* Defined in symtab.c */
38 extern int hp_som_som_object_present
;
40 /* This is defined in valops.c */
41 extern int overload_resolution
;
43 /* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue
44 on with successful lookup for member/method of the rtti type. */
45 extern int objectprint
;
47 /* Prototypes for local functions. */
49 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *);
51 static struct value
*evaluate_subexp_for_address (struct expression
*,
54 static struct value
*evaluate_subexp (struct type
*, struct expression
*,
57 static char *get_label (struct expression
*, int *);
59 static struct value
*evaluate_struct_tuple (struct value
*,
60 struct expression
*, int *,
63 static LONGEST
init_array_element (struct value
*, struct value
*,
64 struct expression
*, int *, enum noside
,
68 evaluate_subexp (struct type
*expect_type
, register struct expression
*exp
,
69 register int *pos
, enum noside noside
)
71 return (*exp
->language_defn
->evaluate_exp
) (expect_type
, exp
, pos
, noside
);
74 /* Parse the string EXP as a C expression, evaluate it,
75 and return the result as a number. */
78 parse_and_eval_address (char *exp
)
80 struct expression
*expr
= parse_expression (exp
);
81 register CORE_ADDR addr
;
82 register struct cleanup
*old_chain
=
83 make_cleanup (free_current_contents
, &expr
);
85 addr
= value_as_address (evaluate_expression (expr
));
86 do_cleanups (old_chain
);
90 /* Like parse_and_eval_address but takes a pointer to a char * variable
91 and advanced that variable across the characters parsed. */
94 parse_and_eval_address_1 (char **expptr
)
96 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*) 0, 0);
97 register CORE_ADDR addr
;
98 register struct cleanup
*old_chain
=
99 make_cleanup (free_current_contents
, &expr
);
101 addr
= value_as_address (evaluate_expression (expr
));
102 do_cleanups (old_chain
);
106 /* Like parse_and_eval_address, but treats the value of the expression
107 as an integer, not an address, returns a LONGEST, not a CORE_ADDR */
109 parse_and_eval_long (char *exp
)
111 struct expression
*expr
= parse_expression (exp
);
112 register LONGEST retval
;
113 register struct cleanup
*old_chain
=
114 make_cleanup (free_current_contents
, &expr
);
116 retval
= value_as_long (evaluate_expression (expr
));
117 do_cleanups (old_chain
);
122 parse_and_eval (char *exp
)
124 struct expression
*expr
= parse_expression (exp
);
126 register struct cleanup
*old_chain
=
127 make_cleanup (free_current_contents
, &expr
);
129 val
= evaluate_expression (expr
);
130 do_cleanups (old_chain
);
134 /* Parse up to a comma (or to a closeparen)
135 in the string EXPP as an expression, evaluate it, and return the value.
136 EXPP is advanced to point to the comma. */
139 parse_to_comma_and_eval (char **expp
)
141 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
143 register struct cleanup
*old_chain
=
144 make_cleanup (free_current_contents
, &expr
);
146 val
= evaluate_expression (expr
);
147 do_cleanups (old_chain
);
151 /* Evaluate an expression in internal prefix form
152 such as is constructed by parse.y.
154 See expression.h for info on the format of an expression. */
157 evaluate_expression (struct expression
*exp
)
160 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
163 /* Evaluate an expression, avoiding all memory references
164 and getting a value whose type alone is correct. */
167 evaluate_type (struct expression
*exp
)
170 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
173 /* If the next expression is an OP_LABELED, skips past it,
174 returning the label. Otherwise, does nothing and returns NULL. */
177 get_label (register struct expression
*exp
, int *pos
)
179 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
182 char *name
= &exp
->elts
[pc
+ 2].string
;
183 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
184 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
191 /* This function evaluates tuples (in (the deleted) Chill) or
192 brace-initializers (in C/C++) for structure types. */
194 static struct value
*
195 evaluate_struct_tuple (struct value
*struct_val
,
196 register struct expression
*exp
,
197 register int *pos
, enum noside noside
, int nargs
)
199 struct type
*struct_type
= check_typedef (VALUE_TYPE (struct_val
));
200 struct type
*substruct_type
= struct_type
;
201 struct type
*field_type
;
208 struct value
*val
= NULL
;
213 /* Skip past the labels, and count them. */
214 while (get_label (exp
, pos
) != NULL
)
219 char *label
= get_label (exp
, &pc
);
222 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
225 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
226 if (field_name
!= NULL
&& STREQ (field_name
, label
))
229 subfieldno
= fieldno
;
230 substruct_type
= struct_type
;
234 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
237 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
238 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
239 if ((field_name
== 0 || *field_name
== '\0')
240 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
243 for (; variantno
< TYPE_NFIELDS (field_type
);
247 = TYPE_FIELD_TYPE (field_type
, variantno
);
248 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
251 subfieldno
< TYPE_NFIELDS (substruct_type
);
254 if (STREQ (TYPE_FIELD_NAME (substruct_type
,
265 error ("there is no field named %s", label
);
271 /* Unlabelled tuple element - go to next field. */
275 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
278 substruct_type
= struct_type
;
284 subfieldno
= fieldno
;
285 if (fieldno
>= TYPE_NFIELDS (struct_type
))
286 error ("too many initializers");
287 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
288 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
289 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
290 error ("don't know which variant you want to set");
294 /* Here, struct_type is the type of the inner struct,
295 while substruct_type is the type of the inner struct.
296 These are the same for normal structures, but a variant struct
297 contains anonymous union fields that contain substruct fields.
298 The value fieldno is the index of the top-level (normal or
299 anonymous union) field in struct_field, while the value
300 subfieldno is the index of the actual real (named inner) field
301 in substruct_type. */
303 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
305 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
307 /* Now actually set the field in struct_val. */
309 /* Assign val to field fieldno. */
310 if (VALUE_TYPE (val
) != field_type
)
311 val
= value_cast (field_type
, val
);
313 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
314 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
316 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
317 addr
= VALUE_CONTENTS (struct_val
) + bitpos
/ 8;
319 modify_field (addr
, value_as_long (val
),
320 bitpos
% 8, bitsize
);
322 memcpy (addr
, VALUE_CONTENTS (val
),
323 TYPE_LENGTH (VALUE_TYPE (val
)));
325 while (--nlabels
> 0);
330 /* Recursive helper function for setting elements of array tuples for
331 (the deleted) Chill. The target is ARRAY (which has bounds
332 LOW_BOUND to HIGH_BOUND); the element value is ELEMENT; EXP, POS
333 and NOSIDE are as usual. Evaluates index expresions and sets the
334 specified element(s) of ARRAY to ELEMENT. Returns last index
338 init_array_element (struct value
*array
, struct value
*element
,
339 register struct expression
*exp
, register int *pos
,
340 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
343 int element_size
= TYPE_LENGTH (VALUE_TYPE (element
));
344 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
347 init_array_element (array
, element
, exp
, pos
, noside
,
348 low_bound
, high_bound
);
349 return init_array_element (array
, element
,
350 exp
, pos
, noside
, low_bound
, high_bound
);
352 else if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
356 low
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
357 high
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
358 if (low
< low_bound
|| high
> high_bound
)
359 error ("tuple range index out of range");
360 for (index
= low
; index
<= high
; index
++)
362 memcpy (VALUE_CONTENTS_RAW (array
)
363 + (index
- low_bound
) * element_size
,
364 VALUE_CONTENTS (element
), element_size
);
369 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
370 if (index
< low_bound
|| index
> high_bound
)
371 error ("tuple index out of range");
372 memcpy (VALUE_CONTENTS_RAW (array
) + (index
- low_bound
) * element_size
,
373 VALUE_CONTENTS (element
), element_size
);
379 evaluate_subexp_standard (struct type
*expect_type
,
380 register struct expression
*exp
, register int *pos
,
385 register int pc
, pc2
= 0, oldpos
;
386 struct value
*arg1
= NULL
;
387 struct value
*arg2
= NULL
;
391 struct value
**argvec
;
392 int upper
, lower
, retcode
;
396 struct type
**arg_types
;
400 op
= exp
->elts
[pc
].opcode
;
405 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
406 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
407 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
409 exp
->elts
[pc
+ 1].type
,
410 &exp
->elts
[pc
+ 3].string
,
413 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
418 return value_from_longest (exp
->elts
[pc
+ 1].type
,
419 exp
->elts
[pc
+ 2].longconst
);
423 return value_from_double (exp
->elts
[pc
+ 1].type
,
424 exp
->elts
[pc
+ 2].doubleconst
);
428 if (noside
== EVAL_SKIP
)
431 /* JYG: We used to just return value_zero of the symbol type
432 if we're asked to avoid side effects. Otherwise we return
433 value_of_variable (...). However I'm not sure if
434 value_of_variable () has any side effect.
435 We need a full value object returned here for whatis_exp ()
436 to call evaluate_type () and then pass the full value to
437 value_rtti_target_type () if we are dealing with a pointer
438 or reference to a base class and print object is on. */
440 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
441 exp
->elts
[pc
+ 1].block
);
446 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
450 int regno
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
451 struct value
*val
= value_of_register (regno
, get_selected_frame ());
454 error ("Value of register %s not available.",
455 frame_map_regnum_to_name (regno
));
461 return value_from_longest (LA_BOOL_TYPE
,
462 exp
->elts
[pc
+ 1].longconst
);
466 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
469 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
470 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
471 if (noside
== EVAL_SKIP
)
473 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
476 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
478 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
479 if (noside
== EVAL_SKIP
)
481 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
486 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
487 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
488 nargs
= tem3
- tem2
+ 1;
489 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
491 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
492 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
494 struct value
*rec
= allocate_value (expect_type
);
495 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (type
));
496 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
499 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
500 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
502 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
503 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
504 struct value
*array
= allocate_value (expect_type
);
505 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
506 LONGEST low_bound
, high_bound
, index
;
507 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
510 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
513 memset (VALUE_CONTENTS_RAW (array
), 0, TYPE_LENGTH (expect_type
));
514 for (tem
= nargs
; --nargs
>= 0;)
516 struct value
*element
;
518 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
521 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
523 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
524 if (VALUE_TYPE (element
) != element_type
)
525 element
= value_cast (element_type
, element
);
528 int continue_pc
= *pos
;
530 index
= init_array_element (array
, element
, exp
, pos
, noside
,
531 low_bound
, high_bound
);
536 if (index
> high_bound
)
537 /* to avoid memory corruption */
538 error ("Too many array elements");
539 memcpy (VALUE_CONTENTS_RAW (array
)
540 + (index
- low_bound
) * element_size
,
541 VALUE_CONTENTS (element
),
549 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
550 && TYPE_CODE (type
) == TYPE_CODE_SET
)
552 struct value
*set
= allocate_value (expect_type
);
553 char *valaddr
= VALUE_CONTENTS_RAW (set
);
554 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
555 struct type
*check_type
= element_type
;
556 LONGEST low_bound
, high_bound
;
558 /* get targettype of elementtype */
559 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
||
560 TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
561 check_type
= TYPE_TARGET_TYPE (check_type
);
563 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
564 error ("(power)set type with unknown size");
565 memset (valaddr
, '\0', TYPE_LENGTH (type
));
566 for (tem
= 0; tem
< nargs
; tem
++)
568 LONGEST range_low
, range_high
;
569 struct type
*range_low_type
, *range_high_type
;
570 struct value
*elem_val
;
571 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
574 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
575 range_low_type
= VALUE_TYPE (elem_val
);
576 range_low
= value_as_long (elem_val
);
577 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
578 range_high_type
= VALUE_TYPE (elem_val
);
579 range_high
= value_as_long (elem_val
);
583 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
584 range_low_type
= range_high_type
= VALUE_TYPE (elem_val
);
585 range_low
= range_high
= value_as_long (elem_val
);
587 /* check types of elements to avoid mixture of elements from
588 different types. Also check if type of element is "compatible"
589 with element type of powerset */
590 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
591 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
592 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
593 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
594 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
)) ||
595 (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
&&
596 (range_low_type
!= range_high_type
)))
597 /* different element modes */
598 error ("POWERSET tuple elements of different mode");
599 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
)) ||
600 (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
&&
601 range_low_type
!= check_type
))
602 error ("incompatible POWERSET tuple elements");
603 if (range_low
> range_high
)
605 warning ("empty POWERSET tuple range");
608 if (range_low
< low_bound
|| range_high
> high_bound
)
609 error ("POWERSET tuple element out of range");
610 range_low
-= low_bound
;
611 range_high
-= low_bound
;
612 for (; range_low
<= range_high
; range_low
++)
614 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
616 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
617 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
624 argvec
= (struct value
**) alloca (sizeof (struct value
*) * nargs
);
625 for (tem
= 0; tem
< nargs
; tem
++)
627 /* Ensure that array expressions are coerced into pointer objects. */
628 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
630 if (noside
== EVAL_SKIP
)
632 return value_array (tem2
, tem3
, argvec
);
636 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
638 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
640 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
641 if (noside
== EVAL_SKIP
)
643 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
646 case TERNOP_SLICE_COUNT
:
648 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
650 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
652 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
653 return value_slice (array
, lowbound
, length
);
657 /* Skip third and second args to evaluate the first one. */
658 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
659 if (value_logical_not (arg1
))
661 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
662 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
666 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
667 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
673 op
= exp
->elts
[*pos
].opcode
;
674 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
675 /* Allocate arg vector, including space for the function to be
676 called in argvec[0] and a terminating NULL */
677 argvec
= (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 3));
678 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
682 /* 1997-08-01 Currently we do not support function invocation
683 via pointers-to-methods with HP aCC. Pointer does not point
684 to the function, but possibly to some thunk. */
685 if (hp_som_som_object_present
)
687 error ("Not implemented: function invocation through pointer to method with HP aCC");
691 /* First, evaluate the structure into arg2 */
694 if (noside
== EVAL_SKIP
)
697 if (op
== STRUCTOP_MEMBER
)
699 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
703 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
706 /* If the function is a virtual function, then the
707 aggregate value (providing the structure) plays
708 its part by providing the vtable. Otherwise,
709 it is just along for the ride: call the function
712 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
714 fnptr
= value_as_long (arg1
);
716 if (METHOD_PTR_IS_VIRTUAL (fnptr
))
718 int fnoffset
= METHOD_PTR_TO_VOFFSET (fnptr
);
719 struct type
*basetype
;
720 struct type
*domain_type
=
721 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
723 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
724 if (domain_type
!= basetype
)
725 arg2
= value_cast (lookup_pointer_type (domain_type
), arg2
);
726 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
727 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
729 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
730 /* If one is virtual, then all are virtual. */
731 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
732 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
733 if ((int) TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
735 struct value
*temp
= value_ind (arg2
);
736 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
737 arg2
= value_addr (temp
);
742 error ("virtual function at index %d not found", fnoffset
);
746 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
750 /* Now, say which argument to start evaluating from */
753 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
755 /* Hair for method invocations */
759 /* First, evaluate the structure into arg2 */
761 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
762 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
763 if (noside
== EVAL_SKIP
)
766 if (op
== STRUCTOP_STRUCT
)
768 /* If v is a variable in a register, and the user types
769 v.method (), this will produce an error, because v has
772 A possible way around this would be to allocate a
773 copy of the variable on the stack, copy in the
774 contents, call the function, and copy out the
775 contents. I.e. convert this from call by reference
776 to call by copy-return (or whatever it's called).
777 However, this does not work because it is not the
778 same: the method being called could stash a copy of
779 the address, and then future uses through that address
780 (after the method returns) would be expected to
781 use the variable itself, not some copy of it. */
782 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
786 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
788 /* Now, say which argument to start evaluating from */
793 /* Non-method function call */
795 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
797 type
= VALUE_TYPE (argvec
[0]);
798 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
799 type
= TYPE_TARGET_TYPE (type
);
800 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
802 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
804 /* pai: FIXME This seems to be coercing arguments before
805 * overload resolution has been done! */
806 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
, tem
- 1),
812 /* Evaluate arguments */
813 for (; tem
<= nargs
; tem
++)
815 /* Ensure that array expressions are coerced into pointer objects. */
816 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
819 /* signal end of arglist */
822 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
827 /* Method invocation : stuff "this" as first parameter */
829 /* Name of method from expression */
830 strcpy (tstr
, &exp
->elts
[pc2
+ 2].string
);
832 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
834 /* Language is C++, do some overload resolution before evaluation */
835 struct value
*valp
= NULL
;
837 /* Prepare list of argument types for overload resolution */
838 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
839 for (ix
= 1; ix
<= nargs
; ix
++)
840 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
842 (void) find_overload_match (arg_types
, nargs
, tstr
,
843 1 /* method */ , 0 /* strict match */ ,
844 &arg2
/* the object */ , NULL
,
845 &valp
, NULL
, &static_memfuncp
);
848 argvec
[1] = arg2
; /* the ``this'' pointer */
849 argvec
[0] = valp
; /* use the method found after overload resolution */
852 /* Non-C++ case -- or no overload resolution */
854 struct value
*temp
= arg2
;
855 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
857 op
== STRUCTOP_STRUCT
858 ? "structure" : "structure pointer");
859 /* value_struct_elt updates temp with the correct value
860 of the ``this'' pointer if necessary, so modify argvec[1] to
861 reflect any ``this'' changes. */
862 arg2
= value_from_longest (lookup_pointer_type(VALUE_TYPE (temp
)),
863 VALUE_ADDRESS (temp
) + VALUE_OFFSET (temp
)
864 + VALUE_EMBEDDED_OFFSET (temp
));
865 argvec
[1] = arg2
; /* the ``this'' pointer */
870 argvec
[1] = argvec
[0];
875 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
880 else if (op
== OP_VAR_VALUE
)
882 /* Non-member function being called */
883 /* fn: This can only be done for C++ functions. A C-style function
884 in a C++ program, for instance, does not have the fields that
887 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
889 /* Language is C++, do some overload resolution before evaluation */
892 /* Prepare list of argument types for overload resolution */
893 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
894 for (ix
= 1; ix
<= nargs
; ix
++)
895 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
897 (void) find_overload_match (arg_types
, nargs
, NULL
/* no need for name */ ,
898 0 /* not method */ , 0 /* strict match */ ,
899 NULL
, exp
->elts
[save_pos1
+2].symbol
/* the function */ ,
902 /* Now fix the expression being evaluated */
903 exp
->elts
[save_pos1
+2].symbol
= symp
;
904 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
908 /* Not C++, or no overload resolution allowed */
909 /* nothing to be done; argvec already correctly set up */
914 /* It is probably a C-style function */
915 /* nothing to be done; argvec already correctly set up */
920 if (noside
== EVAL_SKIP
)
922 if (argvec
[0] == NULL
)
923 error ("Cannot evaluate function -- may be inlined");
924 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
926 /* If the return type doesn't look like a function type, call an
927 error. This can happen if somebody tries to turn a variable into
928 a function call. This is here because people often want to
929 call, eg, strcmp, which gdb doesn't know is a function. If
930 gdb isn't asked for it's opinion (ie. through "whatis"),
931 it won't offer it. */
934 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
937 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
939 error ("Expression of type other than \"Function returning ...\" used as function");
941 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
942 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
944 case OP_F77_UNDETERMINED_ARGLIST
:
946 /* Remember that in F77, functions, substring ops and
947 array subscript operations cannot be disambiguated
948 at parse time. We have made all array subscript operations,
949 substring operations as well as function calls come here
950 and we now have to discover what the heck this thing actually was.
951 If it is a function, we process just as if we got an OP_FUNCALL. */
953 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
956 /* First determine the type code we are dealing with. */
957 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
958 type
= check_typedef (VALUE_TYPE (arg1
));
959 code
= TYPE_CODE (type
);
963 case TYPE_CODE_ARRAY
:
964 goto multi_f77_subscript
;
966 case TYPE_CODE_STRING
:
971 /* It's a function call. */
972 /* Allocate arg vector, including space for the function to be
973 called in argvec[0] and a terminating NULL */
974 argvec
= (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 2));
977 for (; tem
<= nargs
; tem
++)
978 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
979 argvec
[tem
] = 0; /* signal end of arglist */
983 error ("Cannot perform substring on this type");
987 /* We have a substring operation on our hands here,
988 let us get the string we will be dealing with */
990 /* Now evaluate the 'from' and 'to' */
992 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
995 return value_subscript (arg1
, arg2
);
997 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
999 if (noside
== EVAL_SKIP
)
1002 tem2
= value_as_long (arg2
);
1003 tem3
= value_as_long (arg3
);
1005 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
1008 /* We have a complex number, There should be 2 floating
1009 point numbers that compose it */
1010 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1011 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1013 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
1015 case STRUCTOP_STRUCT
:
1016 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1017 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1018 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1019 if (noside
== EVAL_SKIP
)
1021 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1022 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1023 &exp
->elts
[pc
+ 2].string
,
1028 struct value
*temp
= arg1
;
1029 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1034 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1035 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1036 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1037 if (noside
== EVAL_SKIP
)
1040 /* JYG: if print object is on we need to replace the base type
1041 with rtti type in order to continue on with successful
1042 lookup of member / method only available in the rtti type. */
1044 struct type
*type
= VALUE_TYPE (arg1
);
1045 struct type
*real_type
;
1046 int full
, top
, using_enc
;
1048 if (objectprint
&& TYPE_TARGET_TYPE(type
) &&
1049 (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CLASS
))
1051 real_type
= value_rtti_target_type (arg1
, &full
, &top
, &using_enc
);
1054 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1055 real_type
= lookup_pointer_type (real_type
);
1057 real_type
= lookup_reference_type (real_type
);
1059 arg1
= value_cast (real_type
, arg1
);
1064 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1065 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1066 &exp
->elts
[pc
+ 2].string
,
1071 struct value
*temp
= arg1
;
1072 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1073 NULL
, "structure pointer");
1076 case STRUCTOP_MEMBER
:
1077 arg1
= evaluate_subexp_for_address (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
);
1087 goto handle_pointer_to_member
;
1090 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1091 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1093 /* With HP aCC, pointers to methods do not point to the function code */
1094 if (hp_som_som_object_present
&&
1095 (TYPE_CODE (VALUE_TYPE (arg2
)) == TYPE_CODE_PTR
) &&
1096 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
))) == TYPE_CODE_METHOD
))
1097 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1099 mem_offset
= value_as_long (arg2
);
1101 handle_pointer_to_member
:
1102 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1103 a real offset to the member. */
1104 if (hp_som_som_object_present
)
1106 if (!mem_offset
) /* no bias -> really null */
1107 error ("Attempted dereference of null pointer-to-member");
1108 mem_offset
&= ~0x20000000;
1110 if (noside
== EVAL_SKIP
)
1112 type
= check_typedef (VALUE_TYPE (arg2
));
1113 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
1114 goto bad_pointer_to_member
;
1115 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1116 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
1117 error ("not implemented: pointer-to-method in pointer-to-member construct");
1118 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
1119 goto bad_pointer_to_member
;
1120 /* Now, convert these values to an address. */
1121 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
1123 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1124 value_as_long (arg1
) + mem_offset
);
1125 return value_ind (arg3
);
1126 bad_pointer_to_member
:
1127 error ("non-pointer-to-member value used in pointer-to-member construct");
1130 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1131 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1132 if (noside
== EVAL_SKIP
)
1134 if (binop_user_defined_p (op
, arg1
, arg2
))
1135 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1137 return value_concat (arg1
, arg2
);
1140 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1141 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1143 /* Do special stuff for HP aCC pointers to members */
1144 if (hp_som_som_object_present
)
1146 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1147 the implementation yet; but the pointer appears to point to a code
1148 sequence (thunk) in memory -- in any case it is *not* the address
1149 of the function as it would be in a naive implementation. */
1150 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1151 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
))
1152 error ("Assignment to pointers to methods not implemented with HP aCC");
1154 /* HP aCC pointers to data members require a constant bias */
1155 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1156 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
))
1158 unsigned int *ptr
= (unsigned int *) VALUE_CONTENTS (arg2
); /* forces evaluation */
1159 *ptr
|= 0x20000000; /* set 29th bit */
1163 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1165 if (binop_user_defined_p (op
, arg1
, arg2
))
1166 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1168 return value_assign (arg1
, arg2
);
1170 case BINOP_ASSIGN_MODIFY
:
1172 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1173 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1174 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1176 op
= exp
->elts
[pc
+ 1].opcode
;
1177 if (binop_user_defined_p (op
, arg1
, arg2
))
1178 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
1179 else if (op
== BINOP_ADD
)
1180 arg2
= value_add (arg1
, arg2
);
1181 else if (op
== BINOP_SUB
)
1182 arg2
= value_sub (arg1
, arg2
);
1184 arg2
= value_binop (arg1
, arg2
, op
);
1185 return value_assign (arg1
, arg2
);
1188 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1189 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1190 if (noside
== EVAL_SKIP
)
1192 if (binop_user_defined_p (op
, arg1
, arg2
))
1193 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1195 return value_add (arg1
, arg2
);
1198 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1199 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1200 if (noside
== EVAL_SKIP
)
1202 if (binop_user_defined_p (op
, arg1
, arg2
))
1203 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1205 return value_sub (arg1
, arg2
);
1213 case BINOP_BITWISE_AND
:
1214 case BINOP_BITWISE_IOR
:
1215 case BINOP_BITWISE_XOR
:
1216 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1217 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1218 if (noside
== EVAL_SKIP
)
1220 if (binop_user_defined_p (op
, arg1
, arg2
))
1221 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1222 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
1223 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
1224 return value_zero (VALUE_TYPE (arg1
), not_lval
);
1226 return value_binop (arg1
, arg2
, op
);
1229 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1230 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1231 if (noside
== EVAL_SKIP
)
1233 error ("':' operator used in invalid context");
1235 case BINOP_SUBSCRIPT
:
1236 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1237 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1238 if (noside
== EVAL_SKIP
)
1240 if (binop_user_defined_p (op
, arg1
, arg2
))
1241 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1244 /* If the user attempts to subscript something that is not an
1245 array or pointer type (like a plain int variable for example),
1246 then report this as an error. */
1249 type
= check_typedef (VALUE_TYPE (arg1
));
1250 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
1251 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
1253 if (TYPE_NAME (type
))
1254 error ("cannot subscript something of type `%s'",
1257 error ("cannot subscript requested type");
1260 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1261 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
1263 return value_subscript (arg1
, arg2
);
1267 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1268 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1269 if (noside
== EVAL_SKIP
)
1271 return value_in (arg1
, arg2
);
1273 case MULTI_SUBSCRIPT
:
1275 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1276 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1279 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1280 /* FIXME: EVAL_SKIP handling may not be correct. */
1281 if (noside
== EVAL_SKIP
)
1292 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1293 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1295 /* If the user attempts to subscript something that has no target
1296 type (like a plain int variable for example), then report this
1299 type
= TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (arg1
)));
1302 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1308 error ("cannot subscript something of type `%s'",
1309 TYPE_NAME (VALUE_TYPE (arg1
)));
1313 if (binop_user_defined_p (op
, arg1
, arg2
))
1315 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1319 arg1
= value_subscript (arg1
, arg2
);
1324 multi_f77_subscript
:
1326 int subscript_array
[MAX_FORTRAN_DIMS
+ 1]; /* 1-based array of
1327 subscripts, max == 7 */
1328 int array_size_array
[MAX_FORTRAN_DIMS
+ 1];
1329 int ndimensions
= 1, i
;
1330 struct type
*tmp_type
;
1331 int offset_item
; /* The array offset where the item lives */
1333 if (nargs
> MAX_FORTRAN_DIMS
)
1334 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
1336 tmp_type
= check_typedef (VALUE_TYPE (arg1
));
1337 ndimensions
= calc_f77_array_dims (type
);
1339 if (nargs
!= ndimensions
)
1340 error ("Wrong number of subscripts");
1342 /* Now that we know we have a legal array subscript expression
1343 let us actually find out where this element exists in the array. */
1346 for (i
= 1; i
<= nargs
; i
++)
1348 /* Evaluate each subscript, It must be a legal integer in F77 */
1349 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1351 /* Fill in the subscript and array size arrays */
1353 subscript_array
[i
] = value_as_long (arg2
);
1355 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1356 if (retcode
== BOUND_FETCH_ERROR
)
1357 error ("Cannot obtain dynamic upper bound");
1359 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1360 if (retcode
== BOUND_FETCH_ERROR
)
1361 error ("Cannot obtain dynamic lower bound");
1363 array_size_array
[i
] = upper
- lower
+ 1;
1365 /* Zero-normalize subscripts so that offsetting will work. */
1367 subscript_array
[i
] -= lower
;
1369 /* If we are at the bottom of a multidimensional
1370 array type then keep a ptr to the last ARRAY
1371 type around for use when calling value_subscript()
1372 below. This is done because we pretend to value_subscript
1373 that we actually have a one-dimensional array
1374 of base element type that we apply a simple
1378 tmp_type
= check_typedef (TYPE_TARGET_TYPE (tmp_type
));
1381 /* Now let us calculate the offset for this item */
1383 offset_item
= subscript_array
[ndimensions
];
1385 for (i
= ndimensions
- 1; i
>= 1; i
--)
1387 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1389 /* Construct a value node with the value of the offset */
1391 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1393 /* Let us now play a dirty trick: we will take arg1
1394 which is a value node pointing to the topmost level
1395 of the multidimensional array-set and pretend
1396 that it is actually a array of the final element
1397 type, this will ensure that value_subscript()
1398 returns the correct type value */
1400 VALUE_TYPE (arg1
) = tmp_type
;
1401 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1404 case BINOP_LOGICAL_AND
:
1405 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1406 if (noside
== EVAL_SKIP
)
1408 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1413 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1416 if (binop_user_defined_p (op
, arg1
, arg2
))
1418 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1419 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1423 tem
= value_logical_not (arg1
);
1424 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1425 (tem
? EVAL_SKIP
: noside
));
1426 return value_from_longest (LA_BOOL_TYPE
,
1427 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1430 case BINOP_LOGICAL_OR
:
1431 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1432 if (noside
== EVAL_SKIP
)
1434 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1439 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1442 if (binop_user_defined_p (op
, arg1
, arg2
))
1444 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1445 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1449 tem
= value_logical_not (arg1
);
1450 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1451 (!tem
? EVAL_SKIP
: noside
));
1452 return value_from_longest (LA_BOOL_TYPE
,
1453 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1457 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1458 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1459 if (noside
== EVAL_SKIP
)
1461 if (binop_user_defined_p (op
, arg1
, arg2
))
1463 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1467 tem
= value_equal (arg1
, arg2
);
1468 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1471 case BINOP_NOTEQUAL
:
1472 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1473 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1474 if (noside
== EVAL_SKIP
)
1476 if (binop_user_defined_p (op
, arg1
, arg2
))
1478 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1482 tem
= value_equal (arg1
, arg2
);
1483 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) ! tem
);
1487 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1488 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1489 if (noside
== EVAL_SKIP
)
1491 if (binop_user_defined_p (op
, arg1
, arg2
))
1493 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1497 tem
= value_less (arg1
, arg2
);
1498 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1502 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1503 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1504 if (noside
== EVAL_SKIP
)
1506 if (binop_user_defined_p (op
, arg1
, arg2
))
1508 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1512 tem
= value_less (arg2
, arg1
);
1513 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1517 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1518 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1519 if (noside
== EVAL_SKIP
)
1521 if (binop_user_defined_p (op
, arg1
, arg2
))
1523 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1527 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1528 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1532 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1533 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1534 if (noside
== EVAL_SKIP
)
1536 if (binop_user_defined_p (op
, arg1
, arg2
))
1538 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1542 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1543 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1547 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1548 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1549 if (noside
== EVAL_SKIP
)
1551 type
= check_typedef (VALUE_TYPE (arg2
));
1552 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
1553 error ("Non-integral right operand for \"@\" operator.");
1554 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1556 return allocate_repeat_value (VALUE_TYPE (arg1
),
1557 longest_to_int (value_as_long (arg2
)));
1560 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1563 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1564 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1567 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1568 if (noside
== EVAL_SKIP
)
1570 if (unop_user_defined_p (op
, arg1
))
1571 return value_x_unop (arg1
, op
, noside
);
1573 return value_neg (arg1
);
1575 case UNOP_COMPLEMENT
:
1576 /* C++: check for and handle destructor names. */
1577 op
= exp
->elts
[*pos
].opcode
;
1579 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1580 if (noside
== EVAL_SKIP
)
1582 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1583 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
1585 return value_complement (arg1
);
1587 case UNOP_LOGICAL_NOT
:
1588 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1589 if (noside
== EVAL_SKIP
)
1591 if (unop_user_defined_p (op
, arg1
))
1592 return value_x_unop (arg1
, op
, noside
);
1594 return value_from_longest (LA_BOOL_TYPE
,
1595 (LONGEST
) value_logical_not (arg1
));
1598 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1599 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1600 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1601 if ((TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) &&
1602 ((TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
) ||
1603 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
)))
1604 error ("Attempt to dereference pointer to member without an object");
1605 if (noside
== EVAL_SKIP
)
1607 if (unop_user_defined_p (op
, arg1
))
1608 return value_x_unop (arg1
, op
, noside
);
1609 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1611 type
= check_typedef (VALUE_TYPE (arg1
));
1612 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1613 || TYPE_CODE (type
) == TYPE_CODE_REF
1614 /* In C you can dereference an array to get the 1st elt. */
1615 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
1617 return value_zero (TYPE_TARGET_TYPE (type
),
1619 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
1620 /* GDB allows dereferencing an int. */
1621 return value_zero (builtin_type_int
, lval_memory
);
1623 error ("Attempt to take contents of a non-pointer value.");
1625 return value_ind (arg1
);
1628 /* C++: check for and handle pointer to members. */
1630 op
= exp
->elts
[*pos
].opcode
;
1632 if (noside
== EVAL_SKIP
)
1636 int temm
= longest_to_int (exp
->elts
[pc
+ 3].longconst
);
1637 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1640 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1645 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
, noside
);
1646 /* If HP aCC object, use bias for pointers to members */
1647 if (hp_som_som_object_present
&&
1648 (TYPE_CODE (VALUE_TYPE (retvalp
)) == TYPE_CODE_PTR
) &&
1649 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (retvalp
))) == TYPE_CODE_MEMBER
))
1651 unsigned int *ptr
= (unsigned int *) VALUE_CONTENTS (retvalp
); /* forces evaluation */
1652 *ptr
|= 0x20000000; /* set 29th bit */
1658 if (noside
== EVAL_SKIP
)
1660 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1663 return evaluate_subexp_for_sizeof (exp
, pos
);
1667 type
= exp
->elts
[pc
+ 1].type
;
1668 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1669 if (noside
== EVAL_SKIP
)
1671 if (type
!= VALUE_TYPE (arg1
))
1672 arg1
= value_cast (type
, arg1
);
1677 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1678 if (noside
== EVAL_SKIP
)
1680 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1681 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1683 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1684 value_as_address (arg1
),
1687 case UNOP_PREINCREMENT
:
1688 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1689 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1691 else if (unop_user_defined_p (op
, arg1
))
1693 return value_x_unop (arg1
, op
, noside
);
1697 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1699 return value_assign (arg1
, arg2
);
1702 case UNOP_PREDECREMENT
:
1703 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1704 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1706 else if (unop_user_defined_p (op
, arg1
))
1708 return value_x_unop (arg1
, op
, noside
);
1712 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1714 return value_assign (arg1
, arg2
);
1717 case UNOP_POSTINCREMENT
:
1718 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1719 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1721 else if (unop_user_defined_p (op
, arg1
))
1723 return value_x_unop (arg1
, op
, noside
);
1727 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1729 value_assign (arg1
, arg2
);
1733 case UNOP_POSTDECREMENT
:
1734 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1735 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1737 else if (unop_user_defined_p (op
, arg1
))
1739 return value_x_unop (arg1
, op
, noside
);
1743 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1745 value_assign (arg1
, arg2
);
1751 return value_of_this (1);
1754 error ("Attempt to use a type name as an expression");
1757 /* Removing this case and compiling with gcc -Wall reveals that
1758 a lot of cases are hitting this case. Some of these should
1759 probably be removed from expression.h; others are legitimate
1760 expressions which are (apparently) not fully implemented.
1762 If there are any cases landing here which mean a user error,
1763 then they should be separate cases, with more descriptive
1767 GDB does not (yet) know how to evaluate that kind of expression");
1771 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1774 /* Evaluate a subexpression of EXP, at index *POS,
1775 and return the address of that subexpression.
1776 Advance *POS over the subexpression.
1777 If the subexpression isn't an lvalue, get an error.
1778 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1779 then only the type of the result need be correct. */
1781 static struct value
*
1782 evaluate_subexp_for_address (register struct expression
*exp
, register int *pos
,
1790 op
= exp
->elts
[pc
].opcode
;
1796 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1800 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1801 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1804 var
= exp
->elts
[pc
+ 2].symbol
;
1806 /* C++: The "address" of a reference should yield the address
1807 * of the object pointed to. Let value_addr() deal with it. */
1808 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1812 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1815 lookup_pointer_type (SYMBOL_TYPE (var
));
1816 enum address_class sym_class
= SYMBOL_CLASS (var
);
1818 if (sym_class
== LOC_CONST
1819 || sym_class
== LOC_CONST_BYTES
1820 || sym_class
== LOC_REGISTER
1821 || sym_class
== LOC_REGPARM
)
1822 error ("Attempt to take address of register or constant.");
1825 value_zero (type
, not_lval
);
1831 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1835 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1837 struct value
*x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1838 if (VALUE_LVAL (x
) == lval_memory
)
1839 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1842 error ("Attempt to take address of non-lval");
1844 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1848 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1849 When used in contexts where arrays will be coerced anyway, this is
1850 equivalent to `evaluate_subexp' but much faster because it avoids
1851 actually fetching array contents (perhaps obsolete now that we have
1854 Note that we currently only do the coercion for C expressions, where
1855 arrays are zero based and the coercion is correct. For other languages,
1856 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1857 to decide if coercion is appropriate.
1862 evaluate_subexp_with_coercion (register struct expression
*exp
,
1863 register int *pos
, enum noside noside
)
1865 register enum exp_opcode op
;
1871 op
= exp
->elts
[pc
].opcode
;
1876 var
= exp
->elts
[pc
+ 2].symbol
;
1877 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var
))) == TYPE_CODE_ARRAY
1878 && CAST_IS_CONVERSION
)
1883 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1884 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var
)))),
1890 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1894 /* Evaluate a subexpression of EXP, at index *POS,
1895 and return a value for the size of that subexpression.
1896 Advance *POS over the subexpression. */
1898 static struct value
*
1899 evaluate_subexp_for_sizeof (register struct expression
*exp
, register int *pos
)
1907 op
= exp
->elts
[pc
].opcode
;
1911 /* This case is handled specially
1912 so that we avoid creating a value for the result type.
1913 If the result type is very big, it's desirable not to
1914 create a value unnecessarily. */
1917 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1918 type
= check_typedef (VALUE_TYPE (val
));
1919 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1920 && TYPE_CODE (type
) != TYPE_CODE_REF
1921 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1922 error ("Attempt to take contents of a non-pointer value.");
1923 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1924 return value_from_longest (builtin_type_int
, (LONGEST
)
1925 TYPE_LENGTH (type
));
1929 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
1930 return value_from_longest (builtin_type_int
,
1931 (LONGEST
) TYPE_LENGTH (type
));
1935 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
1937 value_from_longest (builtin_type_int
, (LONGEST
) TYPE_LENGTH (type
));
1940 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1941 return value_from_longest (builtin_type_int
,
1942 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1946 /* Parse a type expression in the string [P..P+LENGTH). */
1949 parse_and_eval_type (char *p
, int length
)
1951 char *tmp
= (char *) alloca (length
+ 4);
1952 struct expression
*expr
;
1954 memcpy (tmp
+ 1, p
, length
);
1955 tmp
[length
+ 1] = ')';
1956 tmp
[length
+ 2] = '0';
1957 tmp
[length
+ 3] = '\0';
1958 expr
= parse_expression (tmp
);
1959 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1960 error ("Internal error in eval_type.");
1961 return expr
->elts
[1].type
;
1965 calc_f77_array_dims (struct type
*array_type
)
1968 struct type
*tmp_type
;
1970 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
1971 error ("Can't get dimensions for a non-array type");
1973 tmp_type
= array_type
;
1975 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1977 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)