1 /* Evaluate expressions for GDB.
2 Copyright 1986, 87, 89, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
27 #include "expression.h"
31 #include "language.h" /* For CAST_IS_CONVERSION */
32 #include "f-lang.h" /* for array bound stuff */
34 /* Defined in symtab.c */
35 extern int hp_som_som_object_present
;
37 /* This is defined in valops.c */
38 extern int overload_resolution
;
41 /* Prototypes for local functions. */
43 static value_ptr evaluate_subexp_for_sizeof
PARAMS ((struct expression
*,
46 static value_ptr evaluate_subexp_for_address
PARAMS ((struct expression
*,
49 static value_ptr evaluate_subexp
PARAMS ((struct type
*, struct expression
*,
52 static char *get_label
PARAMS ((struct expression
*, int *));
55 evaluate_struct_tuple
PARAMS ((value_ptr
, struct expression
*, int *,
59 init_array_element
PARAMS ((value_ptr
, value_ptr
, struct expression
*,
60 int *, enum noside
, LONGEST
, LONGEST
));
66 evaluate_subexp (expect_type
, exp
, pos
, noside
)
67 struct type
*expect_type
;
68 register struct expression
*exp
;
72 return (*exp
->language_defn
->evaluate_exp
) (expect_type
, exp
, pos
, noside
);
75 /* Parse the string EXP as a C expression, evaluate it,
76 and return the result as a number. */
79 parse_and_eval_address (exp
)
82 struct expression
*expr
= parse_expression (exp
);
83 register CORE_ADDR addr
;
84 register struct cleanup
*old_chain
=
85 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
87 addr
= value_as_pointer (evaluate_expression (expr
));
88 do_cleanups (old_chain
);
92 /* Like parse_and_eval_address but takes a pointer to a char * variable
93 and advanced that variable across the characters parsed. */
96 parse_and_eval_address_1 (expptr
)
99 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*) 0, 0);
100 register CORE_ADDR addr
;
101 register struct cleanup
*old_chain
=
102 make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
104 addr
= value_as_pointer (evaluate_expression (expr
));
105 do_cleanups (old_chain
);
113 struct expression
*expr
= parse_expression (exp
);
114 register value_ptr val
;
115 register struct cleanup
*old_chain
116 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
118 val
= evaluate_expression (expr
);
119 do_cleanups (old_chain
);
123 /* Parse up to a comma (or to a closeparen)
124 in the string EXPP as an expression, evaluate it, and return the value.
125 EXPP is advanced to point to the comma. */
128 parse_to_comma_and_eval (expp
)
131 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
132 register value_ptr val
;
133 register struct cleanup
*old_chain
134 = make_cleanup ((make_cleanup_func
) free_current_contents
, &expr
);
136 val
= evaluate_expression (expr
);
137 do_cleanups (old_chain
);
141 /* Evaluate an expression in internal prefix form
142 such as is constructed by parse.y.
144 See expression.h for info on the format of an expression. */
147 evaluate_expression (exp
)
148 struct expression
*exp
;
151 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
154 /* Evaluate an expression, avoiding all memory references
155 and getting a value whose type alone is correct. */
159 struct expression
*exp
;
162 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
165 /* If the next expression is an OP_LABELED, skips past it,
166 returning the label. Otherwise, does nothing and returns NULL. */
170 register struct expression
*exp
;
173 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
176 char *name
= &exp
->elts
[pc
+ 2].string
;
177 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
178 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
185 /* This function evaluates tupes (in Chill) or brace-initializers
186 (in C/C++) for structure types. */
189 evaluate_struct_tuple (struct_val
, exp
, pos
, noside
, nargs
)
190 value_ptr struct_val
;
191 register struct expression
*exp
;
196 struct type
*struct_type
= check_typedef (VALUE_TYPE (struct_val
));
197 struct type
*substruct_type
= struct_type
;
198 struct type
*field_type
;
205 value_ptr val
= NULL
;
210 /* Skip past the labels, and count them. */
211 while (get_label (exp
, pos
) != NULL
)
216 char *label
= get_label (exp
, &pc
);
219 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
222 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
223 if (field_name
!= NULL
&& STREQ (field_name
, label
))
226 subfieldno
= fieldno
;
227 substruct_type
= struct_type
;
231 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
234 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
235 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
236 if ((field_name
== 0 || *field_name
== '\0')
237 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
240 for (; variantno
< TYPE_NFIELDS (field_type
);
244 = TYPE_FIELD_TYPE (field_type
, variantno
);
245 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
248 subfieldno
< TYPE_NFIELDS (substruct_type
);
251 if (STREQ (TYPE_FIELD_NAME (substruct_type
,
262 error ("there is no field named %s", label
);
268 /* Unlabelled tuple element - go to next field. */
272 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
275 substruct_type
= struct_type
;
281 subfieldno
= fieldno
;
282 if (fieldno
>= TYPE_NFIELDS (struct_type
))
283 error ("too many initializers");
284 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
285 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
286 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
287 error ("don't know which variant you want to set");
291 /* Here, struct_type is the type of the inner struct,
292 while substruct_type is the type of the inner struct.
293 These are the same for normal structures, but a variant struct
294 contains anonymous union fields that contain substruct fields.
295 The value fieldno is the index of the top-level (normal or
296 anonymous union) field in struct_field, while the value
297 subfieldno is the index of the actual real (named inner) field
298 in substruct_type. */
300 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
302 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
304 /* Now actually set the field in struct_val. */
306 /* Assign val to field fieldno. */
307 if (VALUE_TYPE (val
) != field_type
)
308 val
= value_cast (field_type
, val
);
310 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
311 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
313 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
314 addr
= VALUE_CONTENTS (struct_val
) + bitpos
/ 8;
316 modify_field (addr
, value_as_long (val
),
317 bitpos
% 8, bitsize
);
319 memcpy (addr
, VALUE_CONTENTS (val
),
320 TYPE_LENGTH (VALUE_TYPE (val
)));
322 while (--nlabels
> 0);
327 /* Recursive helper function for setting elements of array tuples for Chill.
328 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND);
329 the element value is ELEMENT;
330 EXP, POS and NOSIDE are as usual.
331 Evaluates index expresions and sets the specified element(s) of
333 Returns last index value. */
336 init_array_element (array
, element
, exp
, pos
, noside
, low_bound
, high_bound
)
337 value_ptr array
, element
;
338 register struct expression
*exp
;
341 LONGEST low_bound
, high_bound
;
344 int element_size
= TYPE_LENGTH (VALUE_TYPE (element
));
345 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
348 init_array_element (array
, element
, exp
, pos
, noside
,
349 low_bound
, high_bound
);
350 return init_array_element (array
, element
,
351 exp
, pos
, noside
, low_bound
, high_bound
);
353 else if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
357 low
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
358 high
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
359 if (low
< low_bound
|| high
> high_bound
)
360 error ("tuple range index out of range");
361 for (index
= low
; index
<= high
; index
++)
363 memcpy (VALUE_CONTENTS_RAW (array
)
364 + (index
- low_bound
) * element_size
,
365 VALUE_CONTENTS (element
), element_size
);
370 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
371 if (index
< low_bound
|| index
> high_bound
)
372 error ("tuple index out of range");
373 memcpy (VALUE_CONTENTS_RAW (array
) + (index
- low_bound
) * element_size
,
374 VALUE_CONTENTS (element
), element_size
);
380 evaluate_subexp_standard (expect_type
, exp
, pos
, noside
)
381 struct type
*expect_type
;
382 register struct expression
*exp
;
388 register int pc
, pc2
= 0, oldpos
;
389 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
393 int upper
, lower
, retcode
;
397 struct type
**arg_types
;
401 op
= exp
->elts
[pc
].opcode
;
406 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
407 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
408 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
410 exp
->elts
[pc
+ 1].type
,
411 &exp
->elts
[pc
+ 3].string
,
414 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
419 return value_from_longest (exp
->elts
[pc
+ 1].type
,
420 exp
->elts
[pc
+ 2].longconst
);
424 return value_from_double (exp
->elts
[pc
+ 1].type
,
425 exp
->elts
[pc
+ 2].doubleconst
);
429 if (noside
== EVAL_SKIP
)
431 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
433 struct symbol
*sym
= exp
->elts
[pc
+ 2].symbol
;
436 switch (SYMBOL_CLASS (sym
))
440 case LOC_CONST_BYTES
:
454 return value_zero (SYMBOL_TYPE (sym
), lv
);
457 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
458 exp
->elts
[pc
+ 1].block
);
463 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
467 int regno
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
468 value_ptr val
= value_of_register (regno
);
472 error ("Value of register %s not available.", REGISTER_NAME (regno
));
478 return value_from_longest (LA_BOOL_TYPE
,
479 exp
->elts
[pc
+ 1].longconst
);
483 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
486 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
487 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
488 if (noside
== EVAL_SKIP
)
490 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
493 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
495 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
496 if (noside
== EVAL_SKIP
)
498 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
503 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
504 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
505 nargs
= tem3
- tem2
+ 1;
506 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
508 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
509 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
511 value_ptr rec
= allocate_value (expect_type
);
512 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (type
));
513 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
516 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
517 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
519 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
520 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
521 value_ptr array
= allocate_value (expect_type
);
522 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
523 LONGEST low_bound
, high_bound
, index
;
524 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
527 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
530 memset (VALUE_CONTENTS_RAW (array
), 0, TYPE_LENGTH (expect_type
));
531 for (tem
= nargs
; --nargs
>= 0;)
535 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
538 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
540 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
541 if (VALUE_TYPE (element
) != element_type
)
542 element
= value_cast (element_type
, element
);
545 int continue_pc
= *pos
;
547 index
= init_array_element (array
, element
, exp
, pos
, noside
,
548 low_bound
, high_bound
);
553 if (index
> high_bound
)
554 /* to avoid memory corruption */
555 error ("Too many array elements");
556 memcpy (VALUE_CONTENTS_RAW (array
)
557 + (index
- low_bound
) * element_size
,
558 VALUE_CONTENTS (element
),
566 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
567 && TYPE_CODE (type
) == TYPE_CODE_SET
)
569 value_ptr set
= allocate_value (expect_type
);
570 char *valaddr
= VALUE_CONTENTS_RAW (set
);
571 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
572 struct type
*check_type
= element_type
;
573 LONGEST low_bound
, high_bound
;
575 /* get targettype of elementtype */
576 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
||
577 TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
578 check_type
= TYPE_TARGET_TYPE (check_type
);
580 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
581 error ("(power)set type with unknown size");
582 memset (valaddr
, '\0', TYPE_LENGTH (type
));
583 for (tem
= 0; tem
< nargs
; tem
++)
585 LONGEST range_low
, range_high
;
586 struct type
*range_low_type
, *range_high_type
;
588 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
591 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
592 range_low_type
= VALUE_TYPE (elem_val
);
593 range_low
= value_as_long (elem_val
);
594 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
595 range_high_type
= VALUE_TYPE (elem_val
);
596 range_high
= value_as_long (elem_val
);
600 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
601 range_low_type
= range_high_type
= VALUE_TYPE (elem_val
);
602 range_low
= range_high
= value_as_long (elem_val
);
604 /* check types of elements to avoid mixture of elements from
605 different types. Also check if type of element is "compatible"
606 with element type of powerset */
607 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
608 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
609 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
610 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
611 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
)) ||
612 (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
&&
613 (range_low_type
!= range_high_type
)))
614 /* different element modes */
615 error ("POWERSET tuple elements of different mode");
616 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
)) ||
617 (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
&&
618 range_low_type
!= check_type
))
619 error ("incompatible POWERSET tuple elements");
620 if (range_low
> range_high
)
622 warning ("empty POWERSET tuple range");
625 if (range_low
< low_bound
|| range_high
> high_bound
)
626 error ("POWERSET tuple element out of range");
627 range_low
-= low_bound
;
628 range_high
-= low_bound
;
629 for (; range_low
<= range_high
; range_low
++)
631 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
633 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
634 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
641 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
642 for (tem
= 0; tem
< nargs
; tem
++)
644 /* Ensure that array expressions are coerced into pointer objects. */
645 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
647 if (noside
== EVAL_SKIP
)
649 return value_array (tem2
, tem3
, argvec
);
653 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
655 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
657 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
658 if (noside
== EVAL_SKIP
)
660 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
663 case TERNOP_SLICE_COUNT
:
665 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
667 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
669 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
670 return value_slice (array
, lowbound
, length
);
674 /* Skip third and second args to evaluate the first one. */
675 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
676 if (value_logical_not (arg1
))
678 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
679 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
683 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
684 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
690 op
= exp
->elts
[*pos
].opcode
;
691 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
692 /* Allocate arg vector, including space for the function to be
693 called in argvec[0] and a terminating NULL */
694 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 3));
695 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
699 /* 1997-08-01 Currently we do not support function invocation
700 via pointers-to-methods with HP aCC. Pointer does not point
701 to the function, but possibly to some thunk. */
702 if (hp_som_som_object_present
)
704 error ("Not implemented: function invocation through pointer to method with HP aCC");
708 /* First, evaluate the structure into arg2 */
711 if (noside
== EVAL_SKIP
)
714 if (op
== STRUCTOP_MEMBER
)
716 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
720 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
723 /* If the function is a virtual function, then the
724 aggregate value (providing the structure) plays
725 its part by providing the vtable. Otherwise,
726 it is just along for the ride: call the function
729 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
731 fnptr
= value_as_long (arg1
);
733 if (METHOD_PTR_IS_VIRTUAL (fnptr
))
735 int fnoffset
= METHOD_PTR_TO_VOFFSET (fnptr
);
736 struct type
*basetype
;
737 struct type
*domain_type
=
738 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
740 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
741 if (domain_type
!= basetype
)
742 arg2
= value_cast (lookup_pointer_type (domain_type
), arg2
);
743 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
744 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
746 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
747 /* If one is virtual, then all are virtual. */
748 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
749 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
750 if ((int) TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
752 value_ptr temp
= value_ind (arg2
);
753 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
754 arg2
= value_addr (temp
);
759 error ("virtual function at index %d not found", fnoffset
);
763 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
767 /* Now, say which argument to start evaluating from */
770 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
772 /* Hair for method invocations */
776 /* First, evaluate the structure into arg2 */
778 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
779 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
780 if (noside
== EVAL_SKIP
)
783 if (op
== STRUCTOP_STRUCT
)
785 /* If v is a variable in a register, and the user types
786 v.method (), this will produce an error, because v has
789 A possible way around this would be to allocate a
790 copy of the variable on the stack, copy in the
791 contents, call the function, and copy out the
792 contents. I.e. convert this from call by reference
793 to call by copy-return (or whatever it's called).
794 However, this does not work because it is not the
795 same: the method being called could stash a copy of
796 the address, and then future uses through that address
797 (after the method returns) would be expected to
798 use the variable itself, not some copy of it. */
799 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
803 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
805 /* Now, say which argument to start evaluating from */
810 /* Non-method function call */
812 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
814 type
= VALUE_TYPE (argvec
[0]);
815 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
816 type
= TYPE_TARGET_TYPE (type
);
817 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
819 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
821 /* pai: FIXME This seems to be coercing arguments before
822 * overload resolution has been done! */
823 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
, tem
- 1),
829 /* Evaluate arguments */
830 for (; tem
<= nargs
; tem
++)
832 /* Ensure that array expressions are coerced into pointer objects. */
833 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
836 /* signal end of arglist */
839 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
842 value_ptr temp
= arg2
;
845 /* Method invocation : stuff "this" as first parameter */
846 /* pai: this used to have lookup_pointer_type for some reason,
847 * but temp is already a pointer to the object */
848 argvec
[1] = value_from_longest (VALUE_TYPE (temp
),
849 VALUE_ADDRESS (temp
) + VALUE_OFFSET (temp
));
850 /* Name of method from expression */
851 strcpy (tstr
, &exp
->elts
[pc2
+ 2].string
);
853 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
855 /* Language is C++, do some overload resolution before evaluation */
856 value_ptr valp
= NULL
;
858 /* Prepare list of argument types for overload resolution */
859 arg_types
= (struct type
**) xmalloc (nargs
* (sizeof (struct type
*)));
860 for (ix
= 1; ix
<= nargs
; ix
++)
861 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
863 (void) find_overload_match (arg_types
, nargs
, tstr
,
864 1 /* method */ , 0 /* strict match */ ,
865 arg2
/* the object */ , NULL
,
866 &valp
, NULL
, &static_memfuncp
);
869 argvec
[1] = arg2
; /* the ``this'' pointer */
870 argvec
[0] = valp
; /* use the method found after overload resolution */
873 /* Non-C++ case -- or no overload resolution */
876 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
878 op
== STRUCTOP_STRUCT
879 ? "structure" : "structure pointer");
880 argvec
[1] = arg2
; /* the ``this'' pointer */
885 argvec
[1] = argvec
[0];
890 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
897 /* Non-member function being called */
899 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
901 /* Language is C++, do some overload resolution before evaluation */
904 /* Prepare list of argument types for overload resolution */
905 arg_types
= (struct type
**) xmalloc (nargs
* (sizeof (struct type
*)));
906 for (ix
= 1; ix
<= nargs
; ix
++)
907 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
909 (void) find_overload_match (arg_types
, nargs
, NULL
/* no need for name */ ,
910 0 /* not method */ , 0 /* strict match */ ,
911 NULL
, exp
->elts
[5].symbol
/* the function */ ,
914 /* Now fix the expression being evaluated */
915 exp
->elts
[5].symbol
= symp
;
916 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
920 /* Not C++, or no overload resolution allowed */
921 /* nothing to be done; argvec already correctly set up */
927 if (noside
== EVAL_SKIP
)
929 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
931 /* If the return type doesn't look like a function type, call an
932 error. This can happen if somebody tries to turn a variable into
933 a function call. This is here because people often want to
934 call, eg, strcmp, which gdb doesn't know is a function. If
935 gdb isn't asked for it's opinion (ie. through "whatis"),
936 it won't offer it. */
939 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
942 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
944 error ("Expression of type other than \"Function returning ...\" used as function");
946 if (argvec
[0] == NULL
)
947 error ("Cannot evaluate function -- may be inlined");
948 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
949 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
951 case OP_F77_UNDETERMINED_ARGLIST
:
953 /* Remember that in F77, functions, substring ops and
954 array subscript operations cannot be disambiguated
955 at parse time. We have made all array subscript operations,
956 substring operations as well as function calls come here
957 and we now have to discover what the heck this thing actually was.
958 If it is a function, we process just as if we got an OP_FUNCALL. */
960 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
963 /* First determine the type code we are dealing with. */
964 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
965 type
= check_typedef (VALUE_TYPE (arg1
));
966 code
= TYPE_CODE (type
);
970 case TYPE_CODE_ARRAY
:
971 goto multi_f77_subscript
;
973 case TYPE_CODE_STRING
:
978 /* It's a function call. */
979 /* Allocate arg vector, including space for the function to be
980 called in argvec[0] and a terminating NULL */
981 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
984 for (; tem
<= nargs
; tem
++)
985 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
986 argvec
[tem
] = 0; /* signal end of arglist */
990 error ("Cannot perform substring on this type");
994 /* We have a substring operation on our hands here,
995 let us get the string we will be dealing with */
997 /* Now evaluate the 'from' and 'to' */
999 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1002 return value_subscript (arg1
, arg2
);
1004 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1006 if (noside
== EVAL_SKIP
)
1009 tem2
= value_as_long (arg2
);
1010 tem3
= value_as_long (arg3
);
1012 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
1015 /* We have a complex number, There should be 2 floating
1016 point numbers that compose it */
1017 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1018 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1020 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
1022 case STRUCTOP_STRUCT
:
1023 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1024 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1025 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1026 if (noside
== EVAL_SKIP
)
1028 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1029 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1030 &exp
->elts
[pc
+ 2].string
,
1035 value_ptr temp
= arg1
;
1036 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1041 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1042 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1043 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1044 if (noside
== EVAL_SKIP
)
1046 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1047 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1048 &exp
->elts
[pc
+ 2].string
,
1053 value_ptr temp
= arg1
;
1054 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1055 NULL
, "structure pointer");
1058 case STRUCTOP_MEMBER
:
1059 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1060 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1062 /* With HP aCC, pointers to methods do not point to the function code */
1063 if (hp_som_som_object_present
&&
1064 (TYPE_CODE (VALUE_TYPE (arg2
)) == TYPE_CODE_PTR
) &&
1065 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
))) == TYPE_CODE_METHOD
))
1066 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1068 mem_offset
= value_as_long (arg2
);
1069 goto handle_pointer_to_member
;
1072 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1073 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1075 /* With HP aCC, pointers to methods do not point to the function code */
1076 if (hp_som_som_object_present
&&
1077 (TYPE_CODE (VALUE_TYPE (arg2
)) == TYPE_CODE_PTR
) &&
1078 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
))) == TYPE_CODE_METHOD
))
1079 error ("Pointers to methods not supported with HP aCC"); /* 1997-08-19 */
1081 mem_offset
= value_as_long (arg2
);
1083 handle_pointer_to_member
:
1084 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1085 a real offset to the member. */
1086 if (hp_som_som_object_present
)
1088 if (!mem_offset
) /* no bias -> really null */
1089 error ("Attempted dereference of null pointer-to-member");
1090 mem_offset
&= ~0x20000000;
1092 if (noside
== EVAL_SKIP
)
1094 type
= check_typedef (VALUE_TYPE (arg2
));
1095 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
1096 goto bad_pointer_to_member
;
1097 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1098 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
1099 error ("not implemented: pointer-to-method in pointer-to-member construct");
1100 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
1101 goto bad_pointer_to_member
;
1102 /* Now, convert these values to an address. */
1103 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
1105 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1106 value_as_long (arg1
) + mem_offset
);
1107 return value_ind (arg3
);
1108 bad_pointer_to_member
:
1109 error ("non-pointer-to-member value used in pointer-to-member construct");
1112 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1113 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1114 if (noside
== EVAL_SKIP
)
1116 if (binop_user_defined_p (op
, arg1
, arg2
))
1117 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1119 return value_concat (arg1
, arg2
);
1122 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1123 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1125 /* Do special stuff for HP aCC pointers to members */
1126 if (hp_som_som_object_present
)
1128 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1129 the implementation yet; but the pointer appears to point to a code
1130 sequence (thunk) in memory -- in any case it is *not* the address
1131 of the function as it would be in a naive implementation. */
1132 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1133 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
))
1134 error ("Assignment to pointers to methods not implemented with HP aCC");
1136 /* HP aCC pointers to data members require a constant bias */
1137 if ((TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
) &&
1138 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
))
1140 unsigned int *ptr
= (unsigned int *) VALUE_CONTENTS (arg2
); /* forces evaluation */
1141 *ptr
|= 0x20000000; /* set 29th bit */
1145 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1147 if (binop_user_defined_p (op
, arg1
, arg2
))
1148 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1150 return value_assign (arg1
, arg2
);
1152 case BINOP_ASSIGN_MODIFY
:
1154 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1155 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1156 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1158 op
= exp
->elts
[pc
+ 1].opcode
;
1159 if (binop_user_defined_p (op
, arg1
, arg2
))
1160 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
1161 else if (op
== BINOP_ADD
)
1162 arg2
= value_add (arg1
, arg2
);
1163 else if (op
== BINOP_SUB
)
1164 arg2
= value_sub (arg1
, arg2
);
1166 arg2
= value_binop (arg1
, arg2
, op
);
1167 return value_assign (arg1
, arg2
);
1170 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1171 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1172 if (noside
== EVAL_SKIP
)
1174 if (binop_user_defined_p (op
, arg1
, arg2
))
1175 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1177 return value_add (arg1
, arg2
);
1180 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1181 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1182 if (noside
== EVAL_SKIP
)
1184 if (binop_user_defined_p (op
, arg1
, arg2
))
1185 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1187 return value_sub (arg1
, arg2
);
1195 case BINOP_BITWISE_AND
:
1196 case BINOP_BITWISE_IOR
:
1197 case BINOP_BITWISE_XOR
:
1198 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1199 arg2
= evaluate_subexp (NULL_TYPE
, 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
);
1204 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
1205 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
1206 return value_zero (VALUE_TYPE (arg1
), not_lval
);
1208 return value_binop (arg1
, arg2
, op
);
1211 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1212 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1213 if (noside
== EVAL_SKIP
)
1215 error ("':' operator used in invalid context");
1217 case BINOP_SUBSCRIPT
:
1218 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1219 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1220 if (noside
== EVAL_SKIP
)
1222 if (binop_user_defined_p (op
, arg1
, arg2
))
1223 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1226 /* If the user attempts to subscript something that is not an
1227 array or pointer type (like a plain int variable for example),
1228 then report this as an error. */
1231 type
= check_typedef (VALUE_TYPE (arg1
));
1232 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
1233 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
1235 if (TYPE_NAME (type
))
1236 error ("cannot subscript something of type `%s'",
1239 error ("cannot subscript requested type");
1242 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1243 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
1245 return value_subscript (arg1
, arg2
);
1249 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1250 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1251 if (noside
== EVAL_SKIP
)
1253 return value_in (arg1
, arg2
);
1255 case MULTI_SUBSCRIPT
:
1257 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1258 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1261 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1262 /* FIXME: EVAL_SKIP handling may not be correct. */
1263 if (noside
== EVAL_SKIP
)
1274 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1275 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1277 /* If the user attempts to subscript something that has no target
1278 type (like a plain int variable for example), then report this
1281 type
= TYPE_TARGET_TYPE (check_typedef (VALUE_TYPE (arg1
)));
1284 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1290 error ("cannot subscript something of type `%s'",
1291 TYPE_NAME (VALUE_TYPE (arg1
)));
1295 if (binop_user_defined_p (op
, arg1
, arg2
))
1297 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1301 arg1
= value_subscript (arg1
, arg2
);
1306 multi_f77_subscript
:
1308 int subscript_array
[MAX_FORTRAN_DIMS
+ 1]; /* 1-based array of
1309 subscripts, max == 7 */
1310 int array_size_array
[MAX_FORTRAN_DIMS
+ 1];
1311 int ndimensions
= 1, i
;
1312 struct type
*tmp_type
;
1313 int offset_item
; /* The array offset where the item lives */
1315 if (nargs
> MAX_FORTRAN_DIMS
)
1316 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
1318 tmp_type
= check_typedef (VALUE_TYPE (arg1
));
1319 ndimensions
= calc_f77_array_dims (type
);
1321 if (nargs
!= ndimensions
)
1322 error ("Wrong number of subscripts");
1324 /* Now that we know we have a legal array subscript expression
1325 let us actually find out where this element exists in the array. */
1328 for (i
= 1; i
<= nargs
; i
++)
1330 /* Evaluate each subscript, It must be a legal integer in F77 */
1331 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1333 /* Fill in the subscript and array size arrays */
1335 subscript_array
[i
] = value_as_long (arg2
);
1337 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1338 if (retcode
== BOUND_FETCH_ERROR
)
1339 error ("Cannot obtain dynamic upper bound");
1341 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1342 if (retcode
== BOUND_FETCH_ERROR
)
1343 error ("Cannot obtain dynamic lower bound");
1345 array_size_array
[i
] = upper
- lower
+ 1;
1347 /* Zero-normalize subscripts so that offsetting will work. */
1349 subscript_array
[i
] -= lower
;
1351 /* If we are at the bottom of a multidimensional
1352 array type then keep a ptr to the last ARRAY
1353 type around for use when calling value_subscript()
1354 below. This is done because we pretend to value_subscript
1355 that we actually have a one-dimensional array
1356 of base element type that we apply a simple
1360 tmp_type
= check_typedef (TYPE_TARGET_TYPE (tmp_type
));
1363 /* Now let us calculate the offset for this item */
1365 offset_item
= subscript_array
[ndimensions
];
1367 for (i
= ndimensions
- 1; i
>= 1; i
--)
1369 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1371 /* Construct a value node with the value of the offset */
1373 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1375 /* Let us now play a dirty trick: we will take arg1
1376 which is a value node pointing to the topmost level
1377 of the multidimensional array-set and pretend
1378 that it is actually a array of the final element
1379 type, this will ensure that value_subscript()
1380 returns the correct type value */
1382 VALUE_TYPE (arg1
) = tmp_type
;
1383 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1386 case BINOP_LOGICAL_AND
:
1387 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1388 if (noside
== EVAL_SKIP
)
1390 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1395 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1398 if (binop_user_defined_p (op
, arg1
, arg2
))
1400 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1401 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1405 tem
= value_logical_not (arg1
);
1406 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1407 (tem
? EVAL_SKIP
: noside
));
1408 return value_from_longest (LA_BOOL_TYPE
,
1409 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1412 case BINOP_LOGICAL_OR
:
1413 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1414 if (noside
== EVAL_SKIP
)
1416 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1421 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1424 if (binop_user_defined_p (op
, arg1
, arg2
))
1426 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1427 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1431 tem
= value_logical_not (arg1
);
1432 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1433 (!tem
? EVAL_SKIP
: noside
));
1434 return value_from_longest (LA_BOOL_TYPE
,
1435 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1439 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1440 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1441 if (noside
== EVAL_SKIP
)
1443 if (binop_user_defined_p (op
, arg1
, arg2
))
1445 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1449 tem
= value_equal (arg1
, arg2
);
1450 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1453 case BINOP_NOTEQUAL
:
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
);
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_less (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 (arg2
, arg1
);
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
) || value_equal (arg1
, arg2
);
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 (arg1
, arg2
) || 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 (NULL_TYPE
, exp
, pos
, noside
);
1531 if (noside
== EVAL_SKIP
)
1533 type
= check_typedef (VALUE_TYPE (arg2
));
1534 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
1535 error ("Non-integral right operand for \"@\" operator.");
1536 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1538 return allocate_repeat_value (VALUE_TYPE (arg1
),
1539 longest_to_int (value_as_long (arg2
)));
1542 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1545 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1546 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1549 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1550 if (noside
== EVAL_SKIP
)
1552 if (unop_user_defined_p (op
, arg1
))
1553 return value_x_unop (arg1
, op
, noside
);
1555 return value_neg (arg1
);
1557 case UNOP_COMPLEMENT
:
1558 /* C++: check for and handle destructor names. */
1559 op
= exp
->elts
[*pos
].opcode
;
1561 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1562 if (noside
== EVAL_SKIP
)
1564 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1565 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
1567 return value_complement (arg1
);
1569 case UNOP_LOGICAL_NOT
:
1570 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1571 if (noside
== EVAL_SKIP
)
1573 if (unop_user_defined_p (op
, arg1
))
1574 return value_x_unop (arg1
, op
, noside
);
1576 return value_from_longest (LA_BOOL_TYPE
,
1577 (LONGEST
) value_logical_not (arg1
));
1580 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1581 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1582 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1583 if ((TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) &&
1584 ((TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_METHOD
) ||
1585 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
))) == TYPE_CODE_MEMBER
)))
1586 error ("Attempt to dereference pointer to member without an object");
1587 if (noside
== EVAL_SKIP
)
1589 if (unop_user_defined_p (op
, arg1
))
1590 return value_x_unop (arg1
, op
, noside
);
1591 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1593 type
= check_typedef (VALUE_TYPE (arg1
));
1594 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1595 || TYPE_CODE (type
) == TYPE_CODE_REF
1596 /* In C you can dereference an array to get the 1st elt. */
1597 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
1599 return value_zero (TYPE_TARGET_TYPE (type
),
1601 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
1602 /* GDB allows dereferencing an int. */
1603 return value_zero (builtin_type_int
, lval_memory
);
1605 error ("Attempt to take contents of a non-pointer value.");
1607 return value_ind (arg1
);
1610 /* C++: check for and handle pointer to members. */
1612 op
= exp
->elts
[*pos
].opcode
;
1614 if (noside
== EVAL_SKIP
)
1618 int temm
= longest_to_int (exp
->elts
[pc
+ 3].longconst
);
1619 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1622 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1627 value_ptr retvalp
= evaluate_subexp_for_address (exp
, pos
, noside
);
1628 /* If HP aCC object, use bias for pointers to members */
1629 if (hp_som_som_object_present
&&
1630 (TYPE_CODE (VALUE_TYPE (retvalp
)) == TYPE_CODE_PTR
) &&
1631 (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (retvalp
))) == TYPE_CODE_MEMBER
))
1633 unsigned int *ptr
= (unsigned int *) VALUE_CONTENTS (retvalp
); /* forces evaluation */
1634 *ptr
|= 0x20000000; /* set 29th bit */
1640 if (noside
== EVAL_SKIP
)
1642 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1645 return evaluate_subexp_for_sizeof (exp
, pos
);
1649 type
= exp
->elts
[pc
+ 1].type
;
1650 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1651 if (noside
== EVAL_SKIP
)
1653 if (type
!= VALUE_TYPE (arg1
))
1654 arg1
= value_cast (type
, arg1
);
1659 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1660 if (noside
== EVAL_SKIP
)
1662 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1663 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1665 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1666 value_as_pointer (arg1
),
1669 case UNOP_PREINCREMENT
:
1670 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1671 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1673 else if (unop_user_defined_p (op
, arg1
))
1675 return value_x_unop (arg1
, op
, noside
);
1679 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1681 return value_assign (arg1
, arg2
);
1684 case UNOP_PREDECREMENT
:
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_sub (arg1
, value_from_longest (builtin_type_char
,
1696 return value_assign (arg1
, arg2
);
1699 case UNOP_POSTINCREMENT
:
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_add (arg1
, value_from_longest (builtin_type_char
,
1711 value_assign (arg1
, arg2
);
1715 case UNOP_POSTDECREMENT
:
1716 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1717 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1719 else if (unop_user_defined_p (op
, arg1
))
1721 return value_x_unop (arg1
, op
, noside
);
1725 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1727 value_assign (arg1
, arg2
);
1733 return value_of_this (1);
1736 error ("Attempt to use a type name as an expression");
1739 /* Removing this case and compiling with gcc -Wall reveals that
1740 a lot of cases are hitting this case. Some of these should
1741 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1742 and an OP_SCOPE?); others are legitimate expressions which are
1743 (apparently) not fully implemented.
1745 If there are any cases landing here which mean a user error,
1746 then they should be separate cases, with more descriptive
1750 GDB does not (yet) know how to evaluate that kind of expression");
1754 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1757 /* Evaluate a subexpression of EXP, at index *POS,
1758 and return the address of that subexpression.
1759 Advance *POS over the subexpression.
1760 If the subexpression isn't an lvalue, get an error.
1761 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1762 then only the type of the result need be correct. */
1765 evaluate_subexp_for_address (exp
, pos
, noside
)
1766 register struct expression
*exp
;
1775 op
= exp
->elts
[pc
].opcode
;
1781 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1785 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1786 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1789 var
= exp
->elts
[pc
+ 2].symbol
;
1791 /* C++: The "address" of a reference should yield the address
1792 * of the object pointed to. Let value_addr() deal with it. */
1793 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1797 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1800 lookup_pointer_type (SYMBOL_TYPE (var
));
1801 enum address_class sym_class
= SYMBOL_CLASS (var
);
1803 if (sym_class
== LOC_CONST
1804 || sym_class
== LOC_CONST_BYTES
1805 || sym_class
== LOC_REGISTER
1806 || sym_class
== LOC_REGPARM
)
1807 error ("Attempt to take address of register or constant.");
1810 value_zero (type
, not_lval
);
1816 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1820 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1822 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1823 if (VALUE_LVAL (x
) == lval_memory
)
1824 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1827 error ("Attempt to take address of non-lval");
1829 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1833 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1834 When used in contexts where arrays will be coerced anyway, this is
1835 equivalent to `evaluate_subexp' but much faster because it avoids
1836 actually fetching array contents (perhaps obsolete now that we have
1839 Note that we currently only do the coercion for C expressions, where
1840 arrays are zero based and the coercion is correct. For other languages,
1841 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1842 to decide if coercion is appropriate.
1847 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1848 register struct expression
*exp
;
1852 register enum exp_opcode op
;
1854 register value_ptr val
;
1858 op
= exp
->elts
[pc
].opcode
;
1863 var
= exp
->elts
[pc
+ 2].symbol
;
1864 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var
))) == TYPE_CODE_ARRAY
1865 && CAST_IS_CONVERSION
)
1870 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1871 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1877 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1881 /* Evaluate a subexpression of EXP, at index *POS,
1882 and return a value for the size of that subexpression.
1883 Advance *POS over the subexpression. */
1886 evaluate_subexp_for_sizeof (exp
, pos
)
1887 register struct expression
*exp
;
1896 op
= exp
->elts
[pc
].opcode
;
1900 /* This case is handled specially
1901 so that we avoid creating a value for the result type.
1902 If the result type is very big, it's desirable not to
1903 create a value unnecessarily. */
1906 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1907 type
= check_typedef (VALUE_TYPE (val
));
1908 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1909 && TYPE_CODE (type
) != TYPE_CODE_REF
1910 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1911 error ("Attempt to take contents of a non-pointer value.");
1912 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1913 return value_from_longest (builtin_type_int
, (LONGEST
)
1914 TYPE_LENGTH (type
));
1918 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
1919 return value_from_longest (builtin_type_int
,
1920 (LONGEST
) TYPE_LENGTH (type
));
1924 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
1926 value_from_longest (builtin_type_int
, (LONGEST
) TYPE_LENGTH (type
));
1929 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1930 return value_from_longest (builtin_type_int
,
1931 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1935 /* Parse a type expression in the string [P..P+LENGTH). */
1938 parse_and_eval_type (p
, length
)
1942 char *tmp
= (char *) alloca (length
+ 4);
1943 struct expression
*expr
;
1945 memcpy (tmp
+ 1, p
, length
);
1946 tmp
[length
+ 1] = ')';
1947 tmp
[length
+ 2] = '0';
1948 tmp
[length
+ 3] = '\0';
1949 expr
= parse_expression (tmp
);
1950 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1951 error ("Internal error in eval_type.");
1952 return expr
->elts
[1].type
;
1956 calc_f77_array_dims (array_type
)
1957 struct type
*array_type
;
1960 struct type
*tmp_type
;
1962 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
1963 error ("Can't get dimensions for a non-array type");
1965 tmp_type
= array_type
;
1967 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1969 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)