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
;
40 /* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue
41 on with successful lookup for member/method of the rtti type. */
42 extern int objectprint
;
44 /* Prototypes for local functions. */
46 static value_ptr
evaluate_subexp_for_sizeof (struct expression
*, int *);
48 static value_ptr
evaluate_subexp_for_address (struct expression
*,
51 static value_ptr
evaluate_subexp (struct type
*, struct expression
*,
54 static char *get_label (struct expression
*, int *);
57 evaluate_struct_tuple (value_ptr
, struct expression
*, int *,
61 init_array_element (value_ptr
, value_ptr
, struct expression
*,
62 int *, enum noside
, LONGEST
, LONGEST
);
64 #if defined (__GNUC__) && !__STDC__
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_pointer (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_pointer (evaluate_expression (expr
));
102 do_cleanups (old_chain
);
107 parse_and_eval (char *exp
)
109 struct expression
*expr
= parse_expression (exp
);
110 register value_ptr val
;
111 register struct cleanup
*old_chain
112 = make_cleanup (free_current_contents
, &expr
);
114 val
= evaluate_expression (expr
);
115 do_cleanups (old_chain
);
119 /* Parse up to a comma (or to a closeparen)
120 in the string EXPP as an expression, evaluate it, and return the value.
121 EXPP is advanced to point to the comma. */
124 parse_to_comma_and_eval (char **expp
)
126 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
127 register value_ptr val
;
128 register struct cleanup
*old_chain
129 = make_cleanup (free_current_contents
, &expr
);
131 val
= evaluate_expression (expr
);
132 do_cleanups (old_chain
);
136 /* Evaluate an expression in internal prefix form
137 such as is constructed by parse.y.
139 See expression.h for info on the format of an expression. */
142 evaluate_expression (struct expression
*exp
)
145 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
148 /* Evaluate an expression, avoiding all memory references
149 and getting a value whose type alone is correct. */
152 evaluate_type (struct expression
*exp
)
155 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
158 /* If the next expression is an OP_LABELED, skips past it,
159 returning the label. Otherwise, does nothing and returns NULL. */
162 get_label (register struct expression
*exp
, int *pos
)
164 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
167 char *name
= &exp
->elts
[pc
+ 2].string
;
168 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
169 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
176 /* This function evaluates tupes (in Chill) or brace-initializers
177 (in C/C++) for structure types. */
180 evaluate_struct_tuple (value_ptr struct_val
, register struct expression
*exp
,
181 register int *pos
, enum noside noside
, int nargs
)
183 struct type
*struct_type
= check_typedef (VALUE_TYPE (struct_val
));
184 struct type
*substruct_type
= struct_type
;
185 struct type
*field_type
;
192 value_ptr val
= NULL
;
197 /* Skip past the labels, and count them. */
198 while (get_label (exp
, pos
) != NULL
)
203 char *label
= get_label (exp
, &pc
);
206 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
209 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
210 if (field_name
!= NULL
&& STREQ (field_name
, label
))
213 subfieldno
= fieldno
;
214 substruct_type
= struct_type
;
218 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
221 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
222 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
223 if ((field_name
== 0 || *field_name
== '\0')
224 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
227 for (; variantno
< TYPE_NFIELDS (field_type
);
231 = TYPE_FIELD_TYPE (field_type
, variantno
);
232 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
235 subfieldno
< TYPE_NFIELDS (substruct_type
);
238 if (STREQ (TYPE_FIELD_NAME (substruct_type
,
249 error ("there is no field named %s", label
);
255 /* Unlabelled tuple element - go to next field. */
259 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
262 substruct_type
= struct_type
;
268 subfieldno
= fieldno
;
269 if (fieldno
>= TYPE_NFIELDS (struct_type
))
270 error ("too many initializers");
271 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
272 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
273 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
274 error ("don't know which variant you want to set");
278 /* Here, struct_type is the type of the inner struct,
279 while substruct_type is the type of the inner struct.
280 These are the same for normal structures, but a variant struct
281 contains anonymous union fields that contain substruct fields.
282 The value fieldno is the index of the top-level (normal or
283 anonymous union) field in struct_field, while the value
284 subfieldno is the index of the actual real (named inner) field
285 in substruct_type. */
287 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
289 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
291 /* Now actually set the field in struct_val. */
293 /* Assign val to field fieldno. */
294 if (VALUE_TYPE (val
) != field_type
)
295 val
= value_cast (field_type
, val
);
297 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
298 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
300 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
301 addr
= VALUE_CONTENTS (struct_val
) + bitpos
/ 8;
303 modify_field (addr
, value_as_long (val
),
304 bitpos
% 8, bitsize
);
306 memcpy (addr
, VALUE_CONTENTS (val
),
307 TYPE_LENGTH (VALUE_TYPE (val
)));
309 while (--nlabels
> 0);
314 /* Recursive helper function for setting elements of array tuples for Chill.
315 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND);
316 the element value is ELEMENT;
317 EXP, POS and NOSIDE are as usual.
318 Evaluates index expresions and sets the specified element(s) of
320 Returns last index value. */
323 init_array_element (value_ptr array
, value_ptr element
,
324 register struct expression
*exp
, register int *pos
,
325 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
328 int element_size
= TYPE_LENGTH (VALUE_TYPE (element
));
329 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
332 init_array_element (array
, element
, exp
, pos
, noside
,
333 low_bound
, high_bound
);
334 return init_array_element (array
, element
,
335 exp
, pos
, noside
, low_bound
, high_bound
);
337 else if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
341 low
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
342 high
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
343 if (low
< low_bound
|| high
> high_bound
)
344 error ("tuple range index out of range");
345 for (index
= low
; index
<= high
; index
++)
347 memcpy (VALUE_CONTENTS_RAW (array
)
348 + (index
- low_bound
) * element_size
,
349 VALUE_CONTENTS (element
), element_size
);
354 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
355 if (index
< low_bound
|| index
> high_bound
)
356 error ("tuple index out of range");
357 memcpy (VALUE_CONTENTS_RAW (array
) + (index
- low_bound
) * element_size
,
358 VALUE_CONTENTS (element
), element_size
);
364 evaluate_subexp_standard (struct type
*expect_type
,
365 register struct expression
*exp
, register int *pos
,
370 register int pc
, pc2
= 0, oldpos
;
371 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
375 int upper
, lower
, retcode
;
379 struct type
**arg_types
;
383 op
= exp
->elts
[pc
].opcode
;
388 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
389 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
390 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
392 exp
->elts
[pc
+ 1].type
,
393 &exp
->elts
[pc
+ 3].string
,
396 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
401 return value_from_longest (exp
->elts
[pc
+ 1].type
,
402 exp
->elts
[pc
+ 2].longconst
);
406 return value_from_double (exp
->elts
[pc
+ 1].type
,
407 exp
->elts
[pc
+ 2].doubleconst
);
411 if (noside
== EVAL_SKIP
)
414 /* JYG: We used to just return value_zero of the symbol type
415 if we're asked to avoid side effects. Otherwise we return
416 value_of_variable (...). However I'm not sure if
417 value_of_variable () has any side effect.
418 We need a full value object returned here for whatis_exp ()
419 to call evaluate_type () and then pass the full value to
420 value_rtti_target_type () if we are dealing with a pointer
421 or reference to a base class and print object is on. */
423 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
424 exp
->elts
[pc
+ 1].block
);
429 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
433 int regno
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
434 value_ptr val
= value_of_register (regno
);
438 error ("Value of register %s not available.", REGISTER_NAME (regno
));
444 return value_from_longest (LA_BOOL_TYPE
,
445 exp
->elts
[pc
+ 1].longconst
);
449 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
452 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
453 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
454 if (noside
== EVAL_SKIP
)
456 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
459 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
461 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
462 if (noside
== EVAL_SKIP
)
464 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
469 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
470 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
471 nargs
= tem3
- tem2
+ 1;
472 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
474 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
475 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
477 value_ptr rec
= allocate_value (expect_type
);
478 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (type
));
479 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
482 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
483 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
485 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
486 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
487 value_ptr array
= allocate_value (expect_type
);
488 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
489 LONGEST low_bound
, high_bound
, index
;
490 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
493 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
496 memset (VALUE_CONTENTS_RAW (array
), 0, TYPE_LENGTH (expect_type
));
497 for (tem
= nargs
; --nargs
>= 0;)
501 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
504 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
506 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
507 if (VALUE_TYPE (element
) != element_type
)
508 element
= value_cast (element_type
, element
);
511 int continue_pc
= *pos
;
513 index
= init_array_element (array
, element
, exp
, pos
, noside
,
514 low_bound
, high_bound
);
519 if (index
> high_bound
)
520 /* to avoid memory corruption */
521 error ("Too many array elements");
522 memcpy (VALUE_CONTENTS_RAW (array
)
523 + (index
- low_bound
) * element_size
,
524 VALUE_CONTENTS (element
),
532 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
533 && TYPE_CODE (type
) == TYPE_CODE_SET
)
535 value_ptr set
= allocate_value (expect_type
);
536 char *valaddr
= VALUE_CONTENTS_RAW (set
);
537 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
538 struct type
*check_type
= element_type
;
539 LONGEST low_bound
, high_bound
;
541 /* get targettype of elementtype */
542 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
||
543 TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
544 check_type
= TYPE_TARGET_TYPE (check_type
);
546 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
547 error ("(power)set type with unknown size");
548 memset (valaddr
, '\0', TYPE_LENGTH (type
));
549 for (tem
= 0; tem
< nargs
; tem
++)
551 LONGEST range_low
, range_high
;
552 struct type
*range_low_type
, *range_high_type
;
554 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
557 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
558 range_low_type
= VALUE_TYPE (elem_val
);
559 range_low
= value_as_long (elem_val
);
560 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
561 range_high_type
= VALUE_TYPE (elem_val
);
562 range_high
= value_as_long (elem_val
);
566 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
567 range_low_type
= range_high_type
= VALUE_TYPE (elem_val
);
568 range_low
= range_high
= value_as_long (elem_val
);
570 /* check types of elements to avoid mixture of elements from
571 different types. Also check if type of element is "compatible"
572 with element type of powerset */
573 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
574 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
575 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
576 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
577 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
)) ||
578 (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
&&
579 (range_low_type
!= range_high_type
)))
580 /* different element modes */
581 error ("POWERSET tuple elements of different mode");
582 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
)) ||
583 (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
&&
584 range_low_type
!= check_type
))
585 error ("incompatible POWERSET tuple elements");
586 if (range_low
> range_high
)
588 warning ("empty POWERSET tuple range");
591 if (range_low
< low_bound
|| range_high
> high_bound
)
592 error ("POWERSET tuple element out of range");
593 range_low
-= low_bound
;
594 range_high
-= low_bound
;
595 for (; range_low
<= range_high
; range_low
++)
597 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
599 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
600 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
607 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
608 for (tem
= 0; tem
< nargs
; tem
++)
610 /* Ensure that array expressions are coerced into pointer objects. */
611 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
613 if (noside
== EVAL_SKIP
)
615 return value_array (tem2
, tem3
, argvec
);
619 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
621 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
623 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
624 if (noside
== EVAL_SKIP
)
626 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
629 case TERNOP_SLICE_COUNT
:
631 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
633 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
635 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
636 return value_slice (array
, lowbound
, length
);
640 /* Skip third and second args to evaluate the first one. */
641 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
642 if (value_logical_not (arg1
))
644 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
645 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
649 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
650 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
656 op
= exp
->elts
[*pos
].opcode
;
657 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
658 /* Allocate arg vector, including space for the function to be
659 called in argvec[0] and a terminating NULL */
660 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 3));
661 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
665 /* 1997-08-01 Currently we do not support function invocation
666 via pointers-to-methods with HP aCC. Pointer does not point
667 to the function, but possibly to some thunk. */
668 if (hp_som_som_object_present
)
670 error ("Not implemented: function invocation through pointer to method with HP aCC");
674 /* First, evaluate the structure into arg2 */
677 if (noside
== EVAL_SKIP
)
680 if (op
== STRUCTOP_MEMBER
)
682 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
686 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
689 /* If the function is a virtual function, then the
690 aggregate value (providing the structure) plays
691 its part by providing the vtable. Otherwise,
692 it is just along for the ride: call the function
695 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
697 fnptr
= value_as_long (arg1
);
699 if (METHOD_PTR_IS_VIRTUAL (fnptr
))
701 int fnoffset
= METHOD_PTR_TO_VOFFSET (fnptr
);
702 struct type
*basetype
;
703 struct type
*domain_type
=
704 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
706 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
707 if (domain_type
!= basetype
)
708 arg2
= value_cast (lookup_pointer_type (domain_type
), arg2
);
709 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
710 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
712 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
713 /* If one is virtual, then all are virtual. */
714 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
715 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
716 if ((int) TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
718 value_ptr temp
= value_ind (arg2
);
719 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
720 arg2
= value_addr (temp
);
725 error ("virtual function at index %d not found", fnoffset
);
729 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
733 /* Now, say which argument to start evaluating from */
736 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
738 /* Hair for method invocations */
742 /* First, evaluate the structure into arg2 */
744 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
745 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
746 if (noside
== EVAL_SKIP
)
749 if (op
== STRUCTOP_STRUCT
)
751 /* If v is a variable in a register, and the user types
752 v.method (), this will produce an error, because v has
755 A possible way around this would be to allocate a
756 copy of the variable on the stack, copy in the
757 contents, call the function, and copy out the
758 contents. I.e. convert this from call by reference
759 to call by copy-return (or whatever it's called).
760 However, this does not work because it is not the
761 same: the method being called could stash a copy of
762 the address, and then future uses through that address
763 (after the method returns) would be expected to
764 use the variable itself, not some copy of it. */
765 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
769 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
771 /* Now, say which argument to start evaluating from */
776 /* Non-method function call */
778 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
780 type
= VALUE_TYPE (argvec
[0]);
781 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
782 type
= TYPE_TARGET_TYPE (type
);
783 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
785 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
787 /* pai: FIXME This seems to be coercing arguments before
788 * overload resolution has been done! */
789 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
, tem
- 1),
795 /* Evaluate arguments */
796 for (; tem
<= nargs
; tem
++)
798 /* Ensure that array expressions are coerced into pointer objects. */
799 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
802 /* signal end of arglist */
805 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
808 value_ptr temp
= arg2
;
811 /* Method invocation : stuff "this" as first parameter */
812 /* pai: this used to have lookup_pointer_type for some reason,
813 * but temp is already a pointer to the object */
815 = value_from_pointer (VALUE_TYPE (temp
),
816 VALUE_ADDRESS (temp
) + VALUE_OFFSET (temp
));
817 /* Name of method from expression */
818 strcpy (tstr
, &exp
->elts
[pc2
+ 2].string
);
820 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
822 /* Language is C++, do some overload resolution before evaluation */
823 value_ptr valp
= NULL
;
825 /* Prepare list of argument types for overload resolution */
826 arg_types
= (struct type
**) xmalloc (nargs
* (sizeof (struct type
*)));
827 for (ix
= 1; ix
<= nargs
; ix
++)
828 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
830 (void) find_overload_match (arg_types
, nargs
, tstr
,
831 1 /* method */ , 0 /* strict match */ ,
832 arg2
/* the object */ , NULL
,
833 &valp
, NULL
, &static_memfuncp
);
836 argvec
[1] = arg2
; /* the ``this'' pointer */
837 argvec
[0] = valp
; /* use the method found after overload resolution */
840 /* Non-C++ case -- or no overload resolution */
843 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
845 op
== STRUCTOP_STRUCT
846 ? "structure" : "structure pointer");
847 argvec
[1] = arg2
; /* the ``this'' pointer */
852 argvec
[1] = argvec
[0];
857 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
862 else if (op
== OP_VAR_VALUE
)
864 /* Non-member function being called */
865 /* fn: This can only be done for C++ functions. A C-style function
866 in a C++ program, for instance, does not have the fields that
869 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
871 /* Language is C++, do some overload resolution before evaluation */
874 /* Prepare list of argument types for overload resolution */
875 arg_types
= (struct type
**) xmalloc (nargs
* (sizeof (struct type
*)));
876 for (ix
= 1; ix
<= nargs
; ix
++)
877 arg_types
[ix
- 1] = VALUE_TYPE (argvec
[ix
]);
879 (void) find_overload_match (arg_types
, nargs
, NULL
/* no need for name */ ,
880 0 /* not method */ , 0 /* strict match */ ,
881 NULL
, exp
->elts
[save_pos1
+2].symbol
/* the function */ ,
884 /* Now fix the expression being evaluated */
885 exp
->elts
[save_pos1
+2].symbol
= symp
;
886 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
890 /* Not C++, or no overload resolution allowed */
891 /* nothing to be done; argvec already correctly set up */
896 /* It is probably a C-style function */
897 /* nothing to be done; argvec already correctly set up */
902 if (noside
== EVAL_SKIP
)
904 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
906 /* If the return type doesn't look like a function type, call an
907 error. This can happen if somebody tries to turn a variable into
908 a function call. This is here because people often want to
909 call, eg, strcmp, which gdb doesn't know is a function. If
910 gdb isn't asked for it's opinion (ie. through "whatis"),
911 it won't offer it. */
914 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
917 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
919 error ("Expression of type other than \"Function returning ...\" used as function");
921 if (argvec
[0] == NULL
)
922 error ("Cannot evaluate function -- may be inlined");
923 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
924 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
926 case OP_F77_UNDETERMINED_ARGLIST
:
928 /* Remember that in F77, functions, substring ops and
929 array subscript operations cannot be disambiguated
930 at parse time. We have made all array subscript operations,
931 substring operations as well as function calls come here
932 and we now have to discover what the heck this thing actually was.
933 If it is a function, we process just as if we got an OP_FUNCALL. */
935 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
938 /* First determine the type code we are dealing with. */
939 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
940 type
= check_typedef (VALUE_TYPE (arg1
));
941 code
= TYPE_CODE (type
);
945 case TYPE_CODE_ARRAY
:
946 goto multi_f77_subscript
;
948 case TYPE_CODE_STRING
:
953 /* It's a function call. */
954 /* Allocate arg vector, including space for the function to be
955 called in argvec[0] and a terminating NULL */
956 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
959 for (; tem
<= nargs
; tem
++)
960 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
961 argvec
[tem
] = 0; /* signal end of arglist */
965 error ("Cannot perform substring on this type");
969 /* We have a substring operation on our hands here,
970 let us get the string we will be dealing with */
972 /* Now evaluate the 'from' and 'to' */
974 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
977 return value_subscript (arg1
, arg2
);
979 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
981 if (noside
== EVAL_SKIP
)
984 tem2
= value_as_long (arg2
);
985 tem3
= value_as_long (arg3
);
987 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
990 /* We have a complex number, There should be 2 floating
991 point numbers that compose it */
992 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
993 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
995 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
997 case STRUCTOP_STRUCT
:
998 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
999 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1000 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1001 if (noside
== EVAL_SKIP
)
1003 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1004 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
1005 &exp
->elts
[pc
+ 2].string
,
1010 value_ptr temp
= arg1
;
1011 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
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
)
1022 /* JYG: if print object is on we need to replace the base type
1023 with rtti type in order to continue on with successful
1024 lookup of member / method only available in the rtti type. */
1026 struct type
*type
= VALUE_TYPE (arg1
);
1027 struct type
*real_type
;
1028 int full
, top
, using_enc
;
1030 if (objectprint
&& TYPE_TARGET_TYPE(type
) &&
1031 (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CLASS
))
1033 real_type
= value_rtti_target_type (arg1
, &full
, &top
, &using_enc
);
1036 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1037 real_type
= lookup_pointer_type (real_type
);
1039 real_type
= lookup_reference_type (real_type
);
1041 arg1
= value_cast (real_type
, arg1
);
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_pointer (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; others are legitimate
1742 expressions which are (apparently) not fully implemented.
1744 If there are any cases landing here which mean a user error,
1745 then they should be separate cases, with more descriptive
1749 GDB does not (yet) know how to evaluate that kind of expression");
1753 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1756 /* Evaluate a subexpression of EXP, at index *POS,
1757 and return the address of that subexpression.
1758 Advance *POS over the subexpression.
1759 If the subexpression isn't an lvalue, get an error.
1760 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1761 then only the type of the result need be correct. */
1764 evaluate_subexp_for_address (register struct expression
*exp
, register int *pos
,
1772 op
= exp
->elts
[pc
].opcode
;
1778 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1782 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1783 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1786 var
= exp
->elts
[pc
+ 2].symbol
;
1788 /* C++: The "address" of a reference should yield the address
1789 * of the object pointed to. Let value_addr() deal with it. */
1790 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1794 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1797 lookup_pointer_type (SYMBOL_TYPE (var
));
1798 enum address_class sym_class
= SYMBOL_CLASS (var
);
1800 if (sym_class
== LOC_CONST
1801 || sym_class
== LOC_CONST_BYTES
1802 || sym_class
== LOC_REGISTER
1803 || sym_class
== LOC_REGPARM
)
1804 error ("Attempt to take address of register or constant.");
1807 value_zero (type
, not_lval
);
1813 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1817 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1819 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1820 if (VALUE_LVAL (x
) == lval_memory
)
1821 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1824 error ("Attempt to take address of non-lval");
1826 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1830 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1831 When used in contexts where arrays will be coerced anyway, this is
1832 equivalent to `evaluate_subexp' but much faster because it avoids
1833 actually fetching array contents (perhaps obsolete now that we have
1836 Note that we currently only do the coercion for C expressions, where
1837 arrays are zero based and the coercion is correct. For other languages,
1838 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1839 to decide if coercion is appropriate.
1844 evaluate_subexp_with_coercion (register struct expression
*exp
,
1845 register int *pos
, enum noside noside
)
1847 register enum exp_opcode op
;
1849 register value_ptr val
;
1853 op
= exp
->elts
[pc
].opcode
;
1858 var
= exp
->elts
[pc
+ 2].symbol
;
1859 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var
))) == TYPE_CODE_ARRAY
1860 && CAST_IS_CONVERSION
)
1865 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1866 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var
)))),
1872 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1876 /* Evaluate a subexpression of EXP, at index *POS,
1877 and return a value for the size of that subexpression.
1878 Advance *POS over the subexpression. */
1881 evaluate_subexp_for_sizeof (register struct expression
*exp
, register int *pos
)
1889 op
= exp
->elts
[pc
].opcode
;
1893 /* This case is handled specially
1894 so that we avoid creating a value for the result type.
1895 If the result type is very big, it's desirable not to
1896 create a value unnecessarily. */
1899 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1900 type
= check_typedef (VALUE_TYPE (val
));
1901 if (TYPE_CODE (type
) != TYPE_CODE_PTR
1902 && TYPE_CODE (type
) != TYPE_CODE_REF
1903 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1904 error ("Attempt to take contents of a non-pointer value.");
1905 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1906 return value_from_longest (builtin_type_int
, (LONGEST
)
1907 TYPE_LENGTH (type
));
1911 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
1912 return value_from_longest (builtin_type_int
,
1913 (LONGEST
) TYPE_LENGTH (type
));
1917 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
1919 value_from_longest (builtin_type_int
, (LONGEST
) TYPE_LENGTH (type
));
1922 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1923 return value_from_longest (builtin_type_int
,
1924 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1928 /* Parse a type expression in the string [P..P+LENGTH). */
1931 parse_and_eval_type (char *p
, int length
)
1933 char *tmp
= (char *) alloca (length
+ 4);
1934 struct expression
*expr
;
1936 memcpy (tmp
+ 1, p
, length
);
1937 tmp
[length
+ 1] = ')';
1938 tmp
[length
+ 2] = '0';
1939 tmp
[length
+ 3] = '\0';
1940 expr
= parse_expression (tmp
);
1941 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1942 error ("Internal error in eval_type.");
1943 return expr
->elts
[1].type
;
1947 calc_f77_array_dims (struct type
*array_type
)
1950 struct type
*tmp_type
;
1952 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
1953 error ("Can't get dimensions for a non-array type");
1955 tmp_type
= array_type
;
1957 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1959 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)