1 /* Evaluate expressions for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005 Free
5 Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
25 #include "gdb_string.h"
29 #include "expression.h"
32 #include "language.h" /* For CAST_IS_CONVERSION */
33 #include "f-lang.h" /* for array bound stuff */
36 #include "objc-lang.h"
38 #include "parser-defs.h"
39 #include "cp-support.h"
41 /* This is defined in valops.c */
42 extern int overload_resolution
;
44 /* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue
45 on with successful lookup for member/method of the rtti type. */
46 extern int objectprint
;
48 /* Prototypes for local functions. */
50 static struct value
*evaluate_subexp_for_sizeof (struct expression
*, int *);
52 static struct value
*evaluate_subexp_for_address (struct expression
*,
55 static struct value
*evaluate_subexp (struct type
*, struct expression
*,
58 static char *get_label (struct expression
*, int *);
60 static struct value
*evaluate_struct_tuple (struct value
*,
61 struct expression
*, int *,
64 static LONGEST
init_array_element (struct value
*, struct value
*,
65 struct expression
*, int *, enum noside
,
69 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
70 int *pos
, enum noside noside
)
72 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
73 (expect_type
, exp
, pos
, noside
);
76 /* Parse the string EXP as a C expression, evaluate it,
77 and return the result as a number. */
80 parse_and_eval_address (char *exp
)
82 struct expression
*expr
= parse_expression (exp
);
84 struct cleanup
*old_chain
=
85 make_cleanup (free_current_contents
, &expr
);
87 addr
= value_as_address (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 (char **expptr
)
98 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*) 0, 0);
100 struct cleanup
*old_chain
=
101 make_cleanup (free_current_contents
, &expr
);
103 addr
= value_as_address (evaluate_expression (expr
));
104 do_cleanups (old_chain
);
108 /* Like parse_and_eval_address, but treats the value of the expression
109 as an integer, not an address, returns a LONGEST, not a CORE_ADDR */
111 parse_and_eval_long (char *exp
)
113 struct expression
*expr
= parse_expression (exp
);
115 struct cleanup
*old_chain
=
116 make_cleanup (free_current_contents
, &expr
);
118 retval
= value_as_long (evaluate_expression (expr
));
119 do_cleanups (old_chain
);
124 parse_and_eval (char *exp
)
126 struct expression
*expr
= parse_expression (exp
);
128 struct cleanup
*old_chain
=
129 make_cleanup (free_current_contents
, &expr
);
131 val
= evaluate_expression (expr
);
132 do_cleanups (old_chain
);
136 /* Parse up to a comma (or to a closeparen)
137 in the string EXPP as an expression, evaluate it, and return the value.
138 EXPP is advanced to point to the comma. */
141 parse_to_comma_and_eval (char **expp
)
143 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
145 struct cleanup
*old_chain
=
146 make_cleanup (free_current_contents
, &expr
);
148 val
= evaluate_expression (expr
);
149 do_cleanups (old_chain
);
153 /* Evaluate an expression in internal prefix form
154 such as is constructed by parse.y.
156 See expression.h for info on the format of an expression. */
159 evaluate_expression (struct expression
*exp
)
162 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
165 /* Evaluate an expression, avoiding all memory references
166 and getting a value whose type alone is correct. */
169 evaluate_type (struct expression
*exp
)
172 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
175 /* If the next expression is an OP_LABELED, skips past it,
176 returning the label. Otherwise, does nothing and returns NULL. */
179 get_label (struct expression
*exp
, int *pos
)
181 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
184 char *name
= &exp
->elts
[pc
+ 2].string
;
185 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
186 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
193 /* This function evaluates tuples (in (the deleted) Chill) or
194 brace-initializers (in C/C++) for structure types. */
196 static struct value
*
197 evaluate_struct_tuple (struct value
*struct_val
,
198 struct expression
*exp
,
199 int *pos
, enum noside noside
, int nargs
)
201 struct type
*struct_type
= check_typedef (value_type (struct_val
));
202 struct type
*substruct_type
= struct_type
;
203 struct type
*field_type
;
210 struct value
*val
= NULL
;
215 /* Skip past the labels, and count them. */
216 while (get_label (exp
, pos
) != NULL
)
221 char *label
= get_label (exp
, &pc
);
224 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
227 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
228 if (field_name
!= NULL
&& strcmp (field_name
, label
) == 0)
231 subfieldno
= fieldno
;
232 substruct_type
= struct_type
;
236 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
239 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
240 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
241 if ((field_name
== 0 || *field_name
== '\0')
242 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
245 for (; variantno
< TYPE_NFIELDS (field_type
);
249 = TYPE_FIELD_TYPE (field_type
, variantno
);
250 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
253 subfieldno
< TYPE_NFIELDS (substruct_type
);
256 if (strcmp(TYPE_FIELD_NAME (substruct_type
,
267 error (_("there is no field named %s"), label
);
273 /* Unlabelled tuple element - go to next field. */
277 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
280 substruct_type
= struct_type
;
286 subfieldno
= fieldno
;
287 if (fieldno
>= TYPE_NFIELDS (struct_type
))
288 error (_("too many initializers"));
289 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
290 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
291 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
292 error (_("don't know which variant you want to set"));
296 /* Here, struct_type is the type of the inner struct,
297 while substruct_type is the type of the inner struct.
298 These are the same for normal structures, but a variant struct
299 contains anonymous union fields that contain substruct fields.
300 The value fieldno is the index of the top-level (normal or
301 anonymous union) field in struct_field, while the value
302 subfieldno is the index of the actual real (named inner) field
303 in substruct_type. */
305 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
307 val
= evaluate_subexp (field_type
, exp
, pos
, noside
);
309 /* Now actually set the field in struct_val. */
311 /* Assign val to field fieldno. */
312 if (value_type (val
) != field_type
)
313 val
= value_cast (field_type
, val
);
315 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
316 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
318 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
319 addr
= value_contents_writeable (struct_val
) + bitpos
/ 8;
321 modify_field (addr
, value_as_long (val
),
322 bitpos
% 8, bitsize
);
324 memcpy (addr
, value_contents (val
),
325 TYPE_LENGTH (value_type (val
)));
327 while (--nlabels
> 0);
332 /* Recursive helper function for setting elements of array tuples for
333 (the deleted) Chill. The target is ARRAY (which has bounds
334 LOW_BOUND to HIGH_BOUND); the element value is ELEMENT; EXP, POS
335 and NOSIDE are as usual. Evaluates index expresions and sets the
336 specified element(s) of ARRAY to ELEMENT. Returns last index
340 init_array_element (struct value
*array
, struct value
*element
,
341 struct expression
*exp
, int *pos
,
342 enum noside noside
, LONGEST low_bound
, LONGEST high_bound
)
345 int element_size
= TYPE_LENGTH (value_type (element
));
346 if (exp
->elts
[*pos
].opcode
== BINOP_COMMA
)
349 init_array_element (array
, element
, exp
, pos
, noside
,
350 low_bound
, high_bound
);
351 return init_array_element (array
, element
,
352 exp
, pos
, noside
, low_bound
, high_bound
);
354 else if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
358 low
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
359 high
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
360 if (low
< low_bound
|| high
> high_bound
)
361 error (_("tuple range index out of range"));
362 for (index
= low
; index
<= high
; index
++)
364 memcpy (value_contents_raw (array
)
365 + (index
- low_bound
) * element_size
,
366 value_contents (element
), element_size
);
371 index
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
372 if (index
< low_bound
|| index
> high_bound
)
373 error (_("tuple index out of range"));
374 memcpy (value_contents_raw (array
) + (index
- low_bound
) * element_size
,
375 value_contents (element
), element_size
);
381 value_f90_subarray (struct value
*array
,
382 struct expression
*exp
, int *pos
, enum noside noside
)
385 LONGEST low_bound
, high_bound
;
386 struct type
*range
= check_typedef (TYPE_INDEX_TYPE (value_type (array
)));
387 enum f90_range_type range_type
= longest_to_int (exp
->elts
[pc
].longconst
);
391 if (range_type
== LOW_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
392 low_bound
= TYPE_LOW_BOUND (range
);
394 low_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
396 if (range_type
== HIGH_BOUND_DEFAULT
|| range_type
== BOTH_BOUND_DEFAULT
)
397 high_bound
= TYPE_HIGH_BOUND (range
);
399 high_bound
= value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
401 return value_slice (array
, low_bound
, high_bound
- low_bound
+ 1);
405 evaluate_subexp_standard (struct type
*expect_type
,
406 struct expression
*exp
, int *pos
,
411 int pc
, pc2
= 0, oldpos
;
412 struct value
*arg1
= NULL
;
413 struct value
*arg2
= NULL
;
417 struct value
**argvec
;
418 int upper
, lower
, retcode
;
422 struct type
**arg_types
;
426 op
= exp
->elts
[pc
].opcode
;
431 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
432 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
433 arg1
= value_aggregate_elt (exp
->elts
[pc
+ 1].type
,
434 &exp
->elts
[pc
+ 3].string
,
437 error (_("There is no field named %s"), &exp
->elts
[pc
+ 3].string
);
442 return value_from_longest (exp
->elts
[pc
+ 1].type
,
443 exp
->elts
[pc
+ 2].longconst
);
447 return value_from_double (exp
->elts
[pc
+ 1].type
,
448 exp
->elts
[pc
+ 2].doubleconst
);
452 if (noside
== EVAL_SKIP
)
455 /* JYG: We used to just return value_zero of the symbol type
456 if we're asked to avoid side effects. Otherwise we return
457 value_of_variable (...). However I'm not sure if
458 value_of_variable () has any side effect.
459 We need a full value object returned here for whatis_exp ()
460 to call evaluate_type () and then pass the full value to
461 value_rtti_target_type () if we are dealing with a pointer
462 or reference to a base class and print object is on. */
464 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
465 exp
->elts
[pc
+ 1].block
);
470 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
474 int regno
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
475 struct value
*val
= value_of_register (regno
, get_selected_frame (NULL
));
478 error (_("Value of register %s not available."),
479 frame_map_regnum_to_name (get_selected_frame (NULL
), regno
));
485 return value_from_longest (LA_BOOL_TYPE
,
486 exp
->elts
[pc
+ 1].longconst
);
490 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
493 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
494 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
495 if (noside
== EVAL_SKIP
)
497 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
499 case OP_OBJC_NSSTRING
: /* Objective C Foundation Class NSString constant. */
500 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
501 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
502 if (noside
== EVAL_SKIP
)
506 return (struct value
*) value_nsstring (&exp
->elts
[pc
+ 2].string
, tem
+ 1);
509 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
511 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
512 if (noside
== EVAL_SKIP
)
514 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
519 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
520 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
521 nargs
= tem3
- tem2
+ 1;
522 type
= expect_type
? check_typedef (expect_type
) : NULL_TYPE
;
524 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
525 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
527 struct value
*rec
= allocate_value (expect_type
);
528 memset (value_contents_raw (rec
), '\0', TYPE_LENGTH (type
));
529 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
532 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
533 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
535 struct type
*range_type
= TYPE_FIELD_TYPE (type
, 0);
536 struct type
*element_type
= TYPE_TARGET_TYPE (type
);
537 struct value
*array
= allocate_value (expect_type
);
538 int element_size
= TYPE_LENGTH (check_typedef (element_type
));
539 LONGEST low_bound
, high_bound
, index
;
540 if (get_discrete_bounds (range_type
, &low_bound
, &high_bound
) < 0)
543 high_bound
= (TYPE_LENGTH (type
) / element_size
) - 1;
546 memset (value_contents_raw (array
), 0, TYPE_LENGTH (expect_type
));
547 for (tem
= nargs
; --nargs
>= 0;)
549 struct value
*element
;
551 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
554 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
556 element
= evaluate_subexp (element_type
, exp
, pos
, noside
);
557 if (value_type (element
) != element_type
)
558 element
= value_cast (element_type
, element
);
561 int continue_pc
= *pos
;
563 index
= init_array_element (array
, element
, exp
, pos
, noside
,
564 low_bound
, high_bound
);
569 if (index
> high_bound
)
570 /* to avoid memory corruption */
571 error (_("Too many array elements"));
572 memcpy (value_contents_raw (array
)
573 + (index
- low_bound
) * element_size
,
574 value_contents (element
),
582 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
583 && TYPE_CODE (type
) == TYPE_CODE_SET
)
585 struct value
*set
= allocate_value (expect_type
);
586 gdb_byte
*valaddr
= value_contents_raw (set
);
587 struct type
*element_type
= TYPE_INDEX_TYPE (type
);
588 struct type
*check_type
= element_type
;
589 LONGEST low_bound
, high_bound
;
591 /* get targettype of elementtype */
592 while (TYPE_CODE (check_type
) == TYPE_CODE_RANGE
||
593 TYPE_CODE (check_type
) == TYPE_CODE_TYPEDEF
)
594 check_type
= TYPE_TARGET_TYPE (check_type
);
596 if (get_discrete_bounds (element_type
, &low_bound
, &high_bound
) < 0)
597 error (_("(power)set type with unknown size"));
598 memset (valaddr
, '\0', TYPE_LENGTH (type
));
599 for (tem
= 0; tem
< nargs
; tem
++)
601 LONGEST range_low
, range_high
;
602 struct type
*range_low_type
, *range_high_type
;
603 struct value
*elem_val
;
604 if (exp
->elts
[*pos
].opcode
== BINOP_RANGE
)
607 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
608 range_low_type
= value_type (elem_val
);
609 range_low
= value_as_long (elem_val
);
610 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
611 range_high_type
= value_type (elem_val
);
612 range_high
= value_as_long (elem_val
);
616 elem_val
= evaluate_subexp (element_type
, exp
, pos
, noside
);
617 range_low_type
= range_high_type
= value_type (elem_val
);
618 range_low
= range_high
= value_as_long (elem_val
);
620 /* check types of elements to avoid mixture of elements from
621 different types. Also check if type of element is "compatible"
622 with element type of powerset */
623 if (TYPE_CODE (range_low_type
) == TYPE_CODE_RANGE
)
624 range_low_type
= TYPE_TARGET_TYPE (range_low_type
);
625 if (TYPE_CODE (range_high_type
) == TYPE_CODE_RANGE
)
626 range_high_type
= TYPE_TARGET_TYPE (range_high_type
);
627 if ((TYPE_CODE (range_low_type
) != TYPE_CODE (range_high_type
)) ||
628 (TYPE_CODE (range_low_type
) == TYPE_CODE_ENUM
&&
629 (range_low_type
!= range_high_type
)))
630 /* different element modes */
631 error (_("POWERSET tuple elements of different mode"));
632 if ((TYPE_CODE (check_type
) != TYPE_CODE (range_low_type
)) ||
633 (TYPE_CODE (check_type
) == TYPE_CODE_ENUM
&&
634 range_low_type
!= check_type
))
635 error (_("incompatible POWERSET tuple elements"));
636 if (range_low
> range_high
)
638 warning (_("empty POWERSET tuple range"));
641 if (range_low
< low_bound
|| range_high
> high_bound
)
642 error (_("POWERSET tuple element out of range"));
643 range_low
-= low_bound
;
644 range_high
-= low_bound
;
645 for (; range_low
<= range_high
; range_low
++)
647 int bit_index
= (unsigned) range_low
% TARGET_CHAR_BIT
;
649 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
650 valaddr
[(unsigned) range_low
/ TARGET_CHAR_BIT
]
657 argvec
= (struct value
**) alloca (sizeof (struct value
*) * nargs
);
658 for (tem
= 0; tem
< nargs
; tem
++)
660 /* Ensure that array expressions are coerced into pointer objects. */
661 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
663 if (noside
== EVAL_SKIP
)
665 return value_array (tem2
, tem3
, argvec
);
669 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
671 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
673 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
674 if (noside
== EVAL_SKIP
)
676 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
679 case TERNOP_SLICE_COUNT
:
681 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
683 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
685 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
686 return value_slice (array
, lowbound
, length
);
690 /* Skip third and second args to evaluate the first one. */
691 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
692 if (value_logical_not (arg1
))
694 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
695 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
699 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
700 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
704 case OP_OBJC_SELECTOR
:
705 { /* Objective C @selector operator. */
706 char *sel
= &exp
->elts
[pc
+ 2].string
;
707 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
709 (*pos
) += 3 + BYTES_TO_EXP_ELEM (len
+ 1);
710 if (noside
== EVAL_SKIP
)
714 sel
[len
] = 0; /* Make sure it's terminated. */
715 return value_from_longest (lookup_pointer_type (builtin_type_void
),
716 lookup_child_selector (sel
));
719 case OP_OBJC_MSGCALL
:
720 { /* Objective C message (method) call. */
722 static CORE_ADDR responds_selector
= 0;
723 static CORE_ADDR method_selector
= 0;
725 CORE_ADDR selector
= 0;
728 int struct_return
= 0;
731 static struct value
*msg_send
= NULL
;
732 static struct value
*msg_send_stret
= NULL
;
733 static int gnu_runtime
= 0;
735 struct value
*target
= NULL
;
736 struct value
*method
= NULL
;
737 struct value
*called_method
= NULL
;
739 struct type
*selector_type
= NULL
;
741 struct value
*ret
= NULL
;
744 selector
= exp
->elts
[pc
+ 1].longconst
;
745 nargs
= exp
->elts
[pc
+ 2].longconst
;
746 argvec
= (struct value
**) alloca (sizeof (struct value
*)
751 selector_type
= lookup_pointer_type (builtin_type_void
);
752 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
753 sub_no_side
= EVAL_NORMAL
;
755 sub_no_side
= noside
;
757 target
= evaluate_subexp (selector_type
, exp
, pos
, sub_no_side
);
759 if (value_as_long (target
) == 0)
760 return value_from_longest (builtin_type_long
, 0);
762 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0))
765 /* Find the method dispatch (Apple runtime) or method lookup
766 (GNU runtime) function for Objective-C. These will be used
767 to lookup the symbol information for the method. If we
768 can't find any symbol information, then we'll use these to
769 call the method, otherwise we can call the method
770 directly. The msg_send_stret function is used in the special
771 case of a method that returns a structure (Apple runtime
776 type
= lookup_pointer_type (builtin_type_void
);
777 type
= lookup_function_type (type
);
778 type
= lookup_pointer_type (type
);
779 type
= lookup_function_type (type
);
780 type
= lookup_pointer_type (type
);
782 msg_send
= find_function_in_inferior ("objc_msg_lookup");
783 msg_send_stret
= find_function_in_inferior ("objc_msg_lookup");
785 msg_send
= value_from_pointer (type
, value_as_address (msg_send
));
786 msg_send_stret
= value_from_pointer (type
,
787 value_as_address (msg_send_stret
));
791 msg_send
= find_function_in_inferior ("objc_msgSend");
792 /* Special dispatcher for methods returning structs */
793 msg_send_stret
= find_function_in_inferior ("objc_msgSend_stret");
796 /* Verify the target object responds to this method. The
797 standard top-level 'Object' class uses a different name for
798 the verification method than the non-standard, but more
799 often used, 'NSObject' class. Make sure we check for both. */
801 responds_selector
= lookup_child_selector ("respondsToSelector:");
802 if (responds_selector
== 0)
803 responds_selector
= lookup_child_selector ("respondsTo:");
805 if (responds_selector
== 0)
806 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
808 method_selector
= lookup_child_selector ("methodForSelector:");
809 if (method_selector
== 0)
810 method_selector
= lookup_child_selector ("methodFor:");
812 if (method_selector
== 0)
813 error (_("no 'methodFor:' or 'methodForSelector:' method"));
815 /* Call the verification method, to make sure that the target
816 class implements the desired method. */
818 argvec
[0] = msg_send
;
820 argvec
[2] = value_from_longest (builtin_type_long
, responds_selector
);
821 argvec
[3] = value_from_longest (builtin_type_long
, selector
);
824 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
827 /* Function objc_msg_lookup returns a pointer. */
829 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
831 if (value_as_long (ret
) == 0)
832 error (_("Target does not respond to this message selector."));
834 /* Call "methodForSelector:" method, to get the address of a
835 function method that implements this selector for this
836 class. If we can find a symbol at that address, then we
837 know the return type, parameter types etc. (that's a good
840 argvec
[0] = msg_send
;
842 argvec
[2] = value_from_longest (builtin_type_long
, method_selector
);
843 argvec
[3] = value_from_longest (builtin_type_long
, selector
);
846 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
850 ret
= call_function_by_hand (argvec
[0], 3, argvec
+ 1);
853 /* ret should now be the selector. */
855 addr
= value_as_long (ret
);
858 struct symbol
*sym
= NULL
;
859 /* Is it a high_level symbol? */
861 sym
= find_pc_function (addr
);
863 method
= value_of_variable (sym
, 0);
866 /* If we found a method with symbol information, check to see
867 if it returns a struct. Otherwise assume it doesn't. */
873 struct type
*value_type
;
875 funaddr
= find_function_addr (method
, &value_type
);
877 b
= block_for_pc (funaddr
);
879 /* If compiled without -g, assume GCC 2. */
880 using_gcc
= (b
== NULL
? 2 : BLOCK_GCC_COMPILED (b
));
882 CHECK_TYPEDEF (value_type
);
884 if ((value_type
== NULL
)
885 || (TYPE_CODE(value_type
) == TYPE_CODE_ERROR
))
887 if (expect_type
!= NULL
)
888 value_type
= expect_type
;
891 struct_return
= using_struct_return (value_type
, using_gcc
);
893 else if (expect_type
!= NULL
)
895 struct_return
= using_struct_return (check_typedef (expect_type
), using_gcc
);
898 /* Found a function symbol. Now we will substitute its
899 value in place of the message dispatcher (obj_msgSend),
900 so that we call the method directly instead of thru
901 the dispatcher. The main reason for doing this is that
902 we can now evaluate the return value and parameter values
903 according to their known data types, in case we need to
904 do things like promotion, dereferencing, special handling
905 of structs and doubles, etc.
907 We want to use the type signature of 'method', but still
908 jump to objc_msgSend() or objc_msgSend_stret() to better
909 mimic the behavior of the runtime. */
913 if (TYPE_CODE (value_type (method
)) != TYPE_CODE_FUNC
)
914 error (_("method address has symbol information with non-function type; skipping"));
916 VALUE_ADDRESS (method
) = value_as_address (msg_send_stret
);
918 VALUE_ADDRESS (method
) = value_as_address (msg_send
);
919 called_method
= method
;
924 called_method
= msg_send_stret
;
926 called_method
= msg_send
;
929 if (noside
== EVAL_SKIP
)
932 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
934 /* If the return type doesn't look like a function type,
935 call an error. This can happen if somebody tries to
936 turn a variable into a function call. This is here
937 because people often want to call, eg, strcmp, which
938 gdb doesn't know is a function. If gdb isn't asked for
939 it's opinion (ie. through "whatis"), it won't offer
942 struct type
*type
= value_type (called_method
);
943 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
944 type
= TYPE_TARGET_TYPE (type
);
945 type
= TYPE_TARGET_TYPE (type
);
949 if ((TYPE_CODE (type
) == TYPE_CODE_ERROR
) && expect_type
)
950 return allocate_value (expect_type
);
952 return allocate_value (type
);
955 error (_("Expression of type other than \"method returning ...\" used as a method"));
958 /* Now depending on whether we found a symbol for the method,
959 we will either call the runtime dispatcher or the method
962 argvec
[0] = called_method
;
964 argvec
[2] = value_from_longest (builtin_type_long
, selector
);
965 /* User-supplied arguments. */
966 for (tem
= 0; tem
< nargs
; tem
++)
967 argvec
[tem
+ 3] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
970 if (gnu_runtime
&& (method
!= NULL
))
972 /* Function objc_msg_lookup returns a pointer. */
973 deprecated_set_value_type (argvec
[0],
974 lookup_function_type (lookup_pointer_type (value_type (argvec
[0]))));
975 argvec
[0] = call_function_by_hand (argvec
[0], nargs
+ 2, argvec
+ 1);
978 ret
= call_function_by_hand (argvec
[0], nargs
+ 2, argvec
+ 1);
985 op
= exp
->elts
[*pos
].opcode
;
986 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
987 /* Allocate arg vector, including space for the function to be
988 called in argvec[0] and a terminating NULL */
989 argvec
= (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 3));
990 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
994 /* 1997-08-01 Currently we do not support function invocation
995 via pointers-to-methods with HP aCC. Pointer does not point
996 to the function, but possibly to some thunk. */
997 if (deprecated_hp_som_som_object_present
)
999 error (_("Not implemented: function invocation through pointer to method with HP aCC"));
1003 /* First, evaluate the structure into arg2 */
1006 if (noside
== EVAL_SKIP
)
1009 if (op
== STRUCTOP_MEMBER
)
1011 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1015 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1018 /* If the function is a virtual function, then the
1019 aggregate value (providing the structure) plays
1020 its part by providing the vtable. Otherwise,
1021 it is just along for the ride: call the function
1024 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1026 fnptr
= value_as_long (arg1
);
1028 if (METHOD_PTR_IS_VIRTUAL (fnptr
))
1030 int fnoffset
= METHOD_PTR_TO_VOFFSET (fnptr
);
1031 struct type
*basetype
;
1032 struct type
*domain_type
=
1033 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (value_type (arg1
)));
1035 basetype
= TYPE_TARGET_TYPE (value_type (arg2
));
1036 if (domain_type
!= basetype
)
1037 arg2
= value_cast (lookup_pointer_type (domain_type
), arg2
);
1038 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
1039 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
1041 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
1042 /* If one is virtual, then all are virtual. */
1043 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
1044 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
1045 if ((int) TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
1047 struct value
*temp
= value_ind (arg2
);
1048 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
1049 arg2
= value_addr (temp
);
1054 error (_("virtual function at index %d not found"), fnoffset
);
1058 deprecated_set_value_type (arg1
, lookup_pointer_type (TYPE_TARGET_TYPE (value_type (arg1
))));
1062 /* Now, say which argument to start evaluating from */
1065 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
1067 /* Hair for method invocations */
1071 /* First, evaluate the structure into arg2 */
1073 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
1074 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
1075 if (noside
== EVAL_SKIP
)
1078 if (op
== STRUCTOP_STRUCT
)
1080 /* If v is a variable in a register, and the user types
1081 v.method (), this will produce an error, because v has
1084 A possible way around this would be to allocate a
1085 copy of the variable on the stack, copy in the
1086 contents, call the function, and copy out the
1087 contents. I.e. convert this from call by reference
1088 to call by copy-return (or whatever it's called).
1089 However, this does not work because it is not the
1090 same: the method being called could stash a copy of
1091 the address, and then future uses through that address
1092 (after the method returns) would be expected to
1093 use the variable itself, not some copy of it. */
1094 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
1098 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1100 /* Now, say which argument to start evaluating from */
1105 /* Non-method function call */
1107 argvec
[0] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1109 type
= value_type (argvec
[0]);
1110 if (type
&& TYPE_CODE (type
) == TYPE_CODE_PTR
)
1111 type
= TYPE_TARGET_TYPE (type
);
1112 if (type
&& TYPE_CODE (type
) == TYPE_CODE_FUNC
)
1114 for (; tem
<= nargs
&& tem
<= TYPE_NFIELDS (type
); tem
++)
1116 /* pai: FIXME This seems to be coercing arguments before
1117 * overload resolution has been done! */
1118 argvec
[tem
] = evaluate_subexp (TYPE_FIELD_TYPE (type
, tem
- 1),
1124 /* Evaluate arguments */
1125 for (; tem
<= nargs
; tem
++)
1127 /* Ensure that array expressions are coerced into pointer objects. */
1128 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1131 /* signal end of arglist */
1134 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
1136 int static_memfuncp
;
1139 /* Method invocation : stuff "this" as first parameter */
1141 /* Name of method from expression */
1142 strcpy (tstr
, &exp
->elts
[pc2
+ 2].string
);
1144 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
1146 /* Language is C++, do some overload resolution before evaluation */
1147 struct value
*valp
= NULL
;
1149 /* Prepare list of argument types for overload resolution */
1150 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
1151 for (ix
= 1; ix
<= nargs
; ix
++)
1152 arg_types
[ix
- 1] = value_type (argvec
[ix
]);
1154 (void) find_overload_match (arg_types
, nargs
, tstr
,
1155 1 /* method */ , 0 /* strict match */ ,
1156 &arg2
/* the object */ , NULL
,
1157 &valp
, NULL
, &static_memfuncp
);
1160 argvec
[1] = arg2
; /* the ``this'' pointer */
1161 argvec
[0] = valp
; /* use the method found after overload resolution */
1164 /* Non-C++ case -- or no overload resolution */
1166 struct value
*temp
= arg2
;
1167 argvec
[0] = value_struct_elt (&temp
, argvec
+ 1, tstr
,
1169 op
== STRUCTOP_STRUCT
1170 ? "structure" : "structure pointer");
1171 /* value_struct_elt updates temp with the correct value
1172 of the ``this'' pointer if necessary, so modify argvec[1] to
1173 reflect any ``this'' changes. */
1174 arg2
= value_from_longest (lookup_pointer_type(value_type (temp
)),
1175 VALUE_ADDRESS (temp
) + value_offset (temp
)
1176 + value_embedded_offset (temp
));
1177 argvec
[1] = arg2
; /* the ``this'' pointer */
1180 if (static_memfuncp
)
1182 argvec
[1] = argvec
[0];
1187 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
1192 else if (op
== OP_VAR_VALUE
)
1194 /* Non-member function being called */
1195 /* fn: This can only be done for C++ functions. A C-style function
1196 in a C++ program, for instance, does not have the fields that
1197 are expected here */
1199 if (overload_resolution
&& (exp
->language_defn
->la_language
== language_cplus
))
1201 /* Language is C++, do some overload resolution before evaluation */
1202 struct symbol
*symp
;
1204 /* Prepare list of argument types for overload resolution */
1205 arg_types
= (struct type
**) alloca (nargs
* (sizeof (struct type
*)));
1206 for (ix
= 1; ix
<= nargs
; ix
++)
1207 arg_types
[ix
- 1] = value_type (argvec
[ix
]);
1209 (void) find_overload_match (arg_types
, nargs
, NULL
/* no need for name */ ,
1210 0 /* not method */ , 0 /* strict match */ ,
1211 NULL
, exp
->elts
[save_pos1
+2].symbol
/* the function */ ,
1214 /* Now fix the expression being evaluated */
1215 exp
->elts
[save_pos1
+2].symbol
= symp
;
1216 argvec
[0] = evaluate_subexp_with_coercion (exp
, &save_pos1
, noside
);
1220 /* Not C++, or no overload resolution allowed */
1221 /* nothing to be done; argvec already correctly set up */
1226 /* It is probably a C-style function */
1227 /* nothing to be done; argvec already correctly set up */
1232 if (noside
== EVAL_SKIP
)
1234 if (argvec
[0] == NULL
)
1235 error (_("Cannot evaluate function -- may be inlined"));
1236 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1238 /* If the return type doesn't look like a function type, call an
1239 error. This can happen if somebody tries to turn a variable into
1240 a function call. This is here because people often want to
1241 call, eg, strcmp, which gdb doesn't know is a function. If
1242 gdb isn't asked for it's opinion (ie. through "whatis"),
1243 it won't offer it. */
1245 struct type
*ftype
=
1246 TYPE_TARGET_TYPE (value_type (argvec
[0]));
1249 return allocate_value (TYPE_TARGET_TYPE (value_type (argvec
[0])));
1251 error (_("Expression of type other than \"Function returning ...\" used as function"));
1253 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
1254 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
1256 case OP_F77_UNDETERMINED_ARGLIST
:
1258 /* Remember that in F77, functions, substring ops and
1259 array subscript operations cannot be disambiguated
1260 at parse time. We have made all array subscript operations,
1261 substring operations as well as function calls come here
1262 and we now have to discover what the heck this thing actually was.
1263 If it is a function, we process just as if we got an OP_FUNCALL. */
1265 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1268 /* First determine the type code we are dealing with. */
1269 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1270 type
= check_typedef (value_type (arg1
));
1271 code
= TYPE_CODE (type
);
1273 if (code
== TYPE_CODE_PTR
)
1275 /* Fortran always passes variable to subroutines as pointer.
1276 So we need to look into its target type to see if it is
1277 array, string or function. If it is, we need to switch
1278 to the target value the original one points to. */
1279 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
1281 if (TYPE_CODE (target_type
) == TYPE_CODE_ARRAY
1282 || TYPE_CODE (target_type
) == TYPE_CODE_STRING
1283 || TYPE_CODE (target_type
) == TYPE_CODE_FUNC
)
1285 arg1
= value_ind (arg1
);
1286 type
= check_typedef (value_type (arg1
));
1287 code
= TYPE_CODE (type
);
1293 case TYPE_CODE_ARRAY
:
1294 if (exp
->elts
[*pos
].opcode
== OP_F90_RANGE
)
1295 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1297 goto multi_f77_subscript
;
1299 case TYPE_CODE_STRING
:
1300 if (exp
->elts
[*pos
].opcode
== OP_F90_RANGE
)
1301 return value_f90_subarray (arg1
, exp
, pos
, noside
);
1304 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1305 return value_subscript (arg1
, arg2
);
1309 case TYPE_CODE_FUNC
:
1310 /* It's a function call. */
1311 /* Allocate arg vector, including space for the function to be
1312 called in argvec[0] and a terminating NULL */
1313 argvec
= (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 2));
1316 for (; tem
<= nargs
; tem
++)
1317 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
1318 argvec
[tem
] = 0; /* signal end of arglist */
1322 error (_("Cannot perform substring on this type"));
1326 /* We have a complex number, There should be 2 floating
1327 point numbers that compose it */
1328 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1329 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1331 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
1333 case STRUCTOP_STRUCT
:
1334 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1335 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1336 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1337 if (noside
== EVAL_SKIP
)
1339 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1340 return value_zero (lookup_struct_elt_type (value_type (arg1
),
1341 &exp
->elts
[pc
+ 2].string
,
1346 struct value
*temp
= arg1
;
1347 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1352 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1353 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
1354 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1355 if (noside
== EVAL_SKIP
)
1358 /* JYG: if print object is on we need to replace the base type
1359 with rtti type in order to continue on with successful
1360 lookup of member / method only available in the rtti type. */
1362 struct type
*type
= value_type (arg1
);
1363 struct type
*real_type
;
1364 int full
, top
, using_enc
;
1366 if (objectprint
&& TYPE_TARGET_TYPE(type
) &&
1367 (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_CLASS
))
1369 real_type
= value_rtti_target_type (arg1
, &full
, &top
, &using_enc
);
1372 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1373 real_type
= lookup_pointer_type (real_type
);
1375 real_type
= lookup_reference_type (real_type
);
1377 arg1
= value_cast (real_type
, arg1
);
1382 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1383 return value_zero (lookup_struct_elt_type (value_type (arg1
),
1384 &exp
->elts
[pc
+ 2].string
,
1389 struct value
*temp
= arg1
;
1390 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
1391 NULL
, "structure pointer");
1394 case STRUCTOP_MEMBER
:
1395 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
1396 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1398 /* With HP aCC, pointers to methods do not point to the function code */
1399 if (deprecated_hp_som_som_object_present
&&
1400 (TYPE_CODE (value_type (arg2
)) == TYPE_CODE_PTR
) &&
1401 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg2
))) == TYPE_CODE_METHOD
))
1402 error (_("Pointers to methods not supported with HP aCC")); /* 1997-08-19 */
1404 mem_offset
= value_as_long (arg2
);
1405 goto handle_pointer_to_member
;
1408 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1409 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1411 /* With HP aCC, pointers to methods do not point to the function code */
1412 if (deprecated_hp_som_som_object_present
&&
1413 (TYPE_CODE (value_type (arg2
)) == TYPE_CODE_PTR
) &&
1414 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg2
))) == TYPE_CODE_METHOD
))
1415 error (_("Pointers to methods not supported with HP aCC")); /* 1997-08-19 */
1417 mem_offset
= value_as_long (arg2
);
1419 handle_pointer_to_member
:
1420 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1421 a real offset to the member. */
1422 if (deprecated_hp_som_som_object_present
)
1424 if (!mem_offset
) /* no bias -> really null */
1425 error (_("Attempted dereference of null pointer-to-member"));
1426 mem_offset
&= ~0x20000000;
1428 if (noside
== EVAL_SKIP
)
1430 type
= check_typedef (value_type (arg2
));
1431 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
1432 goto bad_pointer_to_member
;
1433 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1434 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
1435 error (_("not implemented: pointer-to-method in pointer-to-member construct"));
1436 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
1437 goto bad_pointer_to_member
;
1438 /* Now, convert these values to an address. */
1439 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
1441 arg3
= value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
1442 value_as_long (arg1
) + mem_offset
);
1443 return value_ind (arg3
);
1444 bad_pointer_to_member
:
1445 error (_("non-pointer-to-member value used in pointer-to-member construct"));
1448 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1449 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1450 if (noside
== EVAL_SKIP
)
1452 if (binop_user_defined_p (op
, arg1
, arg2
))
1453 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1455 return value_concat (arg1
, arg2
);
1458 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1459 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1461 /* Do special stuff for HP aCC pointers to members */
1462 if (deprecated_hp_som_som_object_present
)
1464 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1465 the implementation yet; but the pointer appears to point to a code
1466 sequence (thunk) in memory -- in any case it is *not* the address
1467 of the function as it would be in a naive implementation. */
1468 if ((TYPE_CODE (value_type (arg1
)) == TYPE_CODE_PTR
) &&
1469 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg1
))) == TYPE_CODE_METHOD
))
1470 error (_("Assignment to pointers to methods not implemented with HP aCC"));
1472 /* HP aCC pointers to data members require a constant bias */
1473 if ((TYPE_CODE (value_type (arg1
)) == TYPE_CODE_PTR
) &&
1474 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg1
))) == TYPE_CODE_MEMBER
))
1476 unsigned int *ptr
= (unsigned int *) value_contents (arg2
); /* forces evaluation */
1477 *ptr
|= 0x20000000; /* set 29th bit */
1481 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1483 if (binop_user_defined_p (op
, arg1
, arg2
))
1484 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1486 return value_assign (arg1
, arg2
);
1488 case BINOP_ASSIGN_MODIFY
:
1490 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1491 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1492 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1494 op
= exp
->elts
[pc
+ 1].opcode
;
1495 if (binop_user_defined_p (op
, arg1
, arg2
))
1496 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
, noside
);
1497 else if (op
== BINOP_ADD
)
1498 arg2
= value_add (arg1
, arg2
);
1499 else if (op
== BINOP_SUB
)
1500 arg2
= value_sub (arg1
, arg2
);
1502 arg2
= value_binop (arg1
, arg2
, op
);
1503 return value_assign (arg1
, arg2
);
1506 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1507 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1508 if (noside
== EVAL_SKIP
)
1510 if (binop_user_defined_p (op
, arg1
, arg2
))
1511 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1513 return value_add (arg1
, arg2
);
1516 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1517 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1518 if (noside
== EVAL_SKIP
)
1520 if (binop_user_defined_p (op
, arg1
, arg2
))
1521 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1523 return value_sub (arg1
, arg2
);
1532 case BINOP_BITWISE_AND
:
1533 case BINOP_BITWISE_IOR
:
1534 case BINOP_BITWISE_XOR
:
1535 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1536 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1537 if (noside
== EVAL_SKIP
)
1539 if (binop_user_defined_p (op
, arg1
, arg2
))
1540 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1541 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
1542 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
1543 return value_zero (value_type (arg1
), not_lval
);
1545 return value_binop (arg1
, arg2
, op
);
1548 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1549 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1550 if (noside
== EVAL_SKIP
)
1552 error (_("':' operator used in invalid context"));
1554 case BINOP_SUBSCRIPT
:
1555 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1556 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1557 if (noside
== EVAL_SKIP
)
1559 if (binop_user_defined_p (op
, arg1
, arg2
))
1560 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1563 /* If the user attempts to subscript something that is not an
1564 array or pointer type (like a plain int variable for example),
1565 then report this as an error. */
1567 arg1
= coerce_ref (arg1
);
1568 type
= check_typedef (value_type (arg1
));
1569 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
1570 && TYPE_CODE (type
) != TYPE_CODE_PTR
)
1572 if (TYPE_NAME (type
))
1573 error (_("cannot subscript something of type `%s'"),
1576 error (_("cannot subscript requested type"));
1579 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1580 return value_zero (TYPE_TARGET_TYPE (type
), VALUE_LVAL (arg1
));
1582 return value_subscript (arg1
, arg2
);
1586 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1587 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1588 if (noside
== EVAL_SKIP
)
1590 return value_in (arg1
, arg2
);
1592 case MULTI_SUBSCRIPT
:
1594 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1595 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1598 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1599 /* FIXME: EVAL_SKIP handling may not be correct. */
1600 if (noside
== EVAL_SKIP
)
1611 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1612 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1614 /* If the user attempts to subscript something that has no target
1615 type (like a plain int variable for example), then report this
1618 type
= TYPE_TARGET_TYPE (check_typedef (value_type (arg1
)));
1621 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1627 error (_("cannot subscript something of type `%s'"),
1628 TYPE_NAME (value_type (arg1
)));
1632 if (binop_user_defined_p (op
, arg1
, arg2
))
1634 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1638 arg1
= value_subscript (arg1
, arg2
);
1643 multi_f77_subscript
:
1645 int subscript_array
[MAX_FORTRAN_DIMS
];
1646 int array_size_array
[MAX_FORTRAN_DIMS
];
1647 int ndimensions
= 1, i
;
1648 struct type
*tmp_type
;
1649 int offset_item
; /* The array offset where the item lives */
1651 if (nargs
> MAX_FORTRAN_DIMS
)
1652 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS
);
1654 tmp_type
= check_typedef (value_type (arg1
));
1655 ndimensions
= calc_f77_array_dims (type
);
1657 if (nargs
!= ndimensions
)
1658 error (_("Wrong number of subscripts"));
1660 /* Now that we know we have a legal array subscript expression
1661 let us actually find out where this element exists in the array. */
1664 /* Take array indices left to right */
1665 for (i
= 0; i
< nargs
; i
++)
1667 /* Evaluate each subscript, It must be a legal integer in F77 */
1668 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1670 /* Fill in the subscript and array size arrays */
1672 subscript_array
[i
] = value_as_long (arg2
);
1675 /* Internal type of array is arranged right to left */
1676 for (i
= 0; i
< nargs
; i
++)
1678 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1679 if (retcode
== BOUND_FETCH_ERROR
)
1680 error (_("Cannot obtain dynamic upper bound"));
1682 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1683 if (retcode
== BOUND_FETCH_ERROR
)
1684 error (_("Cannot obtain dynamic lower bound"));
1686 array_size_array
[nargs
- i
- 1] = upper
- lower
+ 1;
1688 /* Zero-normalize subscripts so that offsetting will work. */
1690 subscript_array
[nargs
- i
- 1] -= lower
;
1692 /* If we are at the bottom of a multidimensional
1693 array type then keep a ptr to the last ARRAY
1694 type around for use when calling value_subscript()
1695 below. This is done because we pretend to value_subscript
1696 that we actually have a one-dimensional array
1697 of base element type that we apply a simple
1701 tmp_type
= check_typedef (TYPE_TARGET_TYPE (tmp_type
));
1704 /* Now let us calculate the offset for this item */
1706 offset_item
= subscript_array
[ndimensions
- 1];
1708 for (i
= ndimensions
- 1; i
> 0; --i
)
1710 array_size_array
[i
- 1] * offset_item
+ subscript_array
[i
- 1];
1712 /* Construct a value node with the value of the offset */
1714 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1716 /* Let us now play a dirty trick: we will take arg1
1717 which is a value node pointing to the topmost level
1718 of the multidimensional array-set and pretend
1719 that it is actually a array of the final element
1720 type, this will ensure that value_subscript()
1721 returns the correct type value */
1723 deprecated_set_value_type (arg1
, tmp_type
);
1724 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1727 case BINOP_LOGICAL_AND
:
1728 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1729 if (noside
== EVAL_SKIP
)
1731 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1736 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1739 if (binop_user_defined_p (op
, arg1
, arg2
))
1741 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1742 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1746 tem
= value_logical_not (arg1
);
1747 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1748 (tem
? EVAL_SKIP
: noside
));
1749 return value_from_longest (LA_BOOL_TYPE
,
1750 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1753 case BINOP_LOGICAL_OR
:
1754 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1755 if (noside
== EVAL_SKIP
)
1757 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1762 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1765 if (binop_user_defined_p (op
, arg1
, arg2
))
1767 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1768 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1772 tem
= value_logical_not (arg1
);
1773 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1774 (!tem
? EVAL_SKIP
: noside
));
1775 return value_from_longest (LA_BOOL_TYPE
,
1776 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1780 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1781 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1782 if (noside
== EVAL_SKIP
)
1784 if (binop_user_defined_p (op
, arg1
, arg2
))
1786 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1790 tem
= value_equal (arg1
, arg2
);
1791 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1794 case BINOP_NOTEQUAL
:
1795 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1796 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1797 if (noside
== EVAL_SKIP
)
1799 if (binop_user_defined_p (op
, arg1
, arg2
))
1801 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1805 tem
= value_equal (arg1
, arg2
);
1806 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) ! tem
);
1810 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1811 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1812 if (noside
== EVAL_SKIP
)
1814 if (binop_user_defined_p (op
, arg1
, arg2
))
1816 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1820 tem
= value_less (arg1
, arg2
);
1821 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1825 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1826 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1827 if (noside
== EVAL_SKIP
)
1829 if (binop_user_defined_p (op
, arg1
, arg2
))
1831 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1835 tem
= value_less (arg2
, arg1
);
1836 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1840 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1841 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1842 if (noside
== EVAL_SKIP
)
1844 if (binop_user_defined_p (op
, arg1
, arg2
))
1846 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1850 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1851 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1855 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1856 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
1857 if (noside
== EVAL_SKIP
)
1859 if (binop_user_defined_p (op
, arg1
, arg2
))
1861 return value_x_binop (arg1
, arg2
, op
, OP_NULL
, noside
);
1865 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1866 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
1870 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1871 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1872 if (noside
== EVAL_SKIP
)
1874 type
= check_typedef (value_type (arg2
));
1875 if (TYPE_CODE (type
) != TYPE_CODE_INT
)
1876 error (_("Non-integral right operand for \"@\" operator."));
1877 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1879 return allocate_repeat_value (value_type (arg1
),
1880 longest_to_int (value_as_long (arg2
)));
1883 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1886 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1887 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1890 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1891 if (noside
== EVAL_SKIP
)
1893 if (unop_user_defined_p (op
, arg1
))
1894 return value_x_unop (arg1
, op
, noside
);
1896 return value_pos (arg1
);
1899 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1900 if (noside
== EVAL_SKIP
)
1902 if (unop_user_defined_p (op
, arg1
))
1903 return value_x_unop (arg1
, op
, noside
);
1905 return value_neg (arg1
);
1907 case UNOP_COMPLEMENT
:
1908 /* C++: check for and handle destructor names. */
1909 op
= exp
->elts
[*pos
].opcode
;
1911 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1912 if (noside
== EVAL_SKIP
)
1914 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1915 return value_x_unop (arg1
, UNOP_COMPLEMENT
, noside
);
1917 return value_complement (arg1
);
1919 case UNOP_LOGICAL_NOT
:
1920 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1921 if (noside
== EVAL_SKIP
)
1923 if (unop_user_defined_p (op
, arg1
))
1924 return value_x_unop (arg1
, op
, noside
);
1926 return value_from_longest (LA_BOOL_TYPE
,
1927 (LONGEST
) value_logical_not (arg1
));
1930 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1931 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
1932 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1933 if ((TYPE_TARGET_TYPE (value_type (arg1
))) &&
1934 ((TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg1
))) == TYPE_CODE_METHOD
) ||
1935 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg1
))) == TYPE_CODE_MEMBER
)))
1936 error (_("Attempt to dereference pointer to member without an object"));
1937 if (noside
== EVAL_SKIP
)
1939 if (unop_user_defined_p (op
, arg1
))
1940 return value_x_unop (arg1
, op
, noside
);
1941 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1943 type
= check_typedef (value_type (arg1
));
1944 if (TYPE_CODE (type
) == TYPE_CODE_PTR
1945 || TYPE_CODE (type
) == TYPE_CODE_REF
1946 /* In C you can dereference an array to get the 1st elt. */
1947 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
1949 return value_zero (TYPE_TARGET_TYPE (type
),
1951 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
1952 /* GDB allows dereferencing an int. */
1953 return value_zero (builtin_type_int
, lval_memory
);
1955 error (_("Attempt to take contents of a non-pointer value."));
1957 return value_ind (arg1
);
1960 /* C++: check for and handle pointer to members. */
1962 op
= exp
->elts
[*pos
].opcode
;
1964 if (noside
== EVAL_SKIP
)
1968 int temm
= longest_to_int (exp
->elts
[pc
+ 3].longconst
);
1969 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1972 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1977 struct value
*retvalp
= evaluate_subexp_for_address (exp
, pos
, noside
);
1978 /* If HP aCC object, use bias for pointers to members */
1979 if (deprecated_hp_som_som_object_present
&&
1980 (TYPE_CODE (value_type (retvalp
)) == TYPE_CODE_PTR
) &&
1981 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (retvalp
))) == TYPE_CODE_MEMBER
))
1983 unsigned int *ptr
= (unsigned int *) value_contents (retvalp
); /* forces evaluation */
1984 *ptr
|= 0x20000000; /* set 29th bit */
1990 if (noside
== EVAL_SKIP
)
1992 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1995 return evaluate_subexp_for_sizeof (exp
, pos
);
1999 type
= exp
->elts
[pc
+ 1].type
;
2000 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
2001 if (noside
== EVAL_SKIP
)
2003 if (type
!= value_type (arg1
))
2004 arg1
= value_cast (type
, arg1
);
2009 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2010 if (noside
== EVAL_SKIP
)
2012 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2013 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
2015 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
2016 value_as_address (arg1
));
2018 case UNOP_PREINCREMENT
:
2019 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2020 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2022 else if (unop_user_defined_p (op
, arg1
))
2024 return value_x_unop (arg1
, op
, noside
);
2028 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
2030 return value_assign (arg1
, arg2
);
2033 case UNOP_PREDECREMENT
:
2034 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2035 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2037 else if (unop_user_defined_p (op
, arg1
))
2039 return value_x_unop (arg1
, op
, noside
);
2043 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
2045 return value_assign (arg1
, arg2
);
2048 case UNOP_POSTINCREMENT
:
2049 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2050 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2052 else if (unop_user_defined_p (op
, arg1
))
2054 return value_x_unop (arg1
, op
, noside
);
2058 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
2060 value_assign (arg1
, arg2
);
2064 case UNOP_POSTDECREMENT
:
2065 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
2066 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
2068 else if (unop_user_defined_p (op
, arg1
))
2070 return value_x_unop (arg1
, op
, noside
);
2074 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
2076 value_assign (arg1
, arg2
);
2082 return value_of_this (1);
2086 return value_of_local ("self", 1);
2089 /* The value is not supposed to be used. This is here to make it
2090 easier to accommodate expressions that contain types. */
2092 if (noside
== EVAL_SKIP
)
2094 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2095 return allocate_value (exp
->elts
[pc
+ 1].type
);
2097 error (_("Attempt to use a type name as an expression"));
2100 /* Removing this case and compiling with gcc -Wall reveals that
2101 a lot of cases are hitting this case. Some of these should
2102 probably be removed from expression.h; others are legitimate
2103 expressions which are (apparently) not fully implemented.
2105 If there are any cases landing here which mean a user error,
2106 then they should be separate cases, with more descriptive
2110 GDB does not (yet) know how to evaluate that kind of expression"));
2114 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
2117 /* Evaluate a subexpression of EXP, at index *POS,
2118 and return the address of that subexpression.
2119 Advance *POS over the subexpression.
2120 If the subexpression isn't an lvalue, get an error.
2121 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2122 then only the type of the result need be correct. */
2124 static struct value
*
2125 evaluate_subexp_for_address (struct expression
*exp
, int *pos
,
2133 op
= exp
->elts
[pc
].opcode
;
2139 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2143 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
2144 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2147 var
= exp
->elts
[pc
+ 2].symbol
;
2149 /* C++: The "address" of a reference should yield the address
2150 * of the object pointed to. Let value_addr() deal with it. */
2151 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
2155 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2158 lookup_pointer_type (SYMBOL_TYPE (var
));
2159 enum address_class sym_class
= SYMBOL_CLASS (var
);
2161 if (sym_class
== LOC_CONST
2162 || sym_class
== LOC_CONST_BYTES
2163 || sym_class
== LOC_REGISTER
2164 || sym_class
== LOC_REGPARM
)
2165 error (_("Attempt to take address of register or constant."));
2168 value_zero (type
, not_lval
);
2174 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
2178 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
2180 struct value
*x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2181 if (VALUE_LVAL (x
) == lval_memory
)
2182 return value_zero (lookup_pointer_type (value_type (x
)),
2185 error (_("Attempt to take address of non-lval"));
2187 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
2191 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
2192 When used in contexts where arrays will be coerced anyway, this is
2193 equivalent to `evaluate_subexp' but much faster because it avoids
2194 actually fetching array contents (perhaps obsolete now that we have
2197 Note that we currently only do the coercion for C expressions, where
2198 arrays are zero based and the coercion is correct. For other languages,
2199 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
2200 to decide if coercion is appropriate.
2205 evaluate_subexp_with_coercion (struct expression
*exp
,
2206 int *pos
, enum noside noside
)
2214 op
= exp
->elts
[pc
].opcode
;
2219 var
= exp
->elts
[pc
+ 2].symbol
;
2220 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var
))) == TYPE_CODE_ARRAY
2221 && CAST_IS_CONVERSION
)
2226 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
2227 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var
)))),
2233 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
2237 /* Evaluate a subexpression of EXP, at index *POS,
2238 and return a value for the size of that subexpression.
2239 Advance *POS over the subexpression. */
2241 static struct value
*
2242 evaluate_subexp_for_sizeof (struct expression
*exp
, int *pos
)
2250 op
= exp
->elts
[pc
].opcode
;
2254 /* This case is handled specially
2255 so that we avoid creating a value for the result type.
2256 If the result type is very big, it's desirable not to
2257 create a value unnecessarily. */
2260 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2261 type
= check_typedef (value_type (val
));
2262 if (TYPE_CODE (type
) != TYPE_CODE_PTR
2263 && TYPE_CODE (type
) != TYPE_CODE_REF
2264 && TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
2265 error (_("Attempt to take contents of a non-pointer value."));
2266 type
= check_typedef (TYPE_TARGET_TYPE (type
));
2267 return value_from_longest (builtin_type_int
, (LONGEST
)
2268 TYPE_LENGTH (type
));
2272 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
2273 return value_from_longest (builtin_type_int
,
2274 (LONGEST
) TYPE_LENGTH (type
));
2278 type
= check_typedef (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
2280 value_from_longest (builtin_type_int
, (LONGEST
) TYPE_LENGTH (type
));
2283 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
2284 return value_from_longest (builtin_type_int
,
2285 (LONGEST
) TYPE_LENGTH (value_type (val
)));
2289 /* Parse a type expression in the string [P..P+LENGTH). */
2292 parse_and_eval_type (char *p
, int length
)
2294 char *tmp
= (char *) alloca (length
+ 4);
2295 struct expression
*expr
;
2297 memcpy (tmp
+ 1, p
, length
);
2298 tmp
[length
+ 1] = ')';
2299 tmp
[length
+ 2] = '0';
2300 tmp
[length
+ 3] = '\0';
2301 expr
= parse_expression (tmp
);
2302 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
2303 error (_("Internal error in eval_type."));
2304 return expr
->elts
[1].type
;
2308 calc_f77_array_dims (struct type
*array_type
)
2311 struct type
*tmp_type
;
2313 if ((TYPE_CODE (array_type
) != TYPE_CODE_ARRAY
))
2314 error (_("Can't get dimensions for a non-array type"));
2316 tmp_type
= array_type
;
2318 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
2320 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)