1 /* Evaluate expressions for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "expression.h"
30 #include "language.h" /* For CAST_IS_CONVERSION */
31 #include "f-lang.h" /* for array bound stuff */
33 /* Prototypes for local functions. */
35 static value_ptr evaluate_subexp_for_sizeof
PARAMS ((struct expression
*,
38 static value_ptr evaluate_subexp_for_address
PARAMS ((struct expression
*,
45 evaluate_subexp (expect_type
, exp
, pos
, noside
)
46 struct type
*expect_type
;
47 register struct expression
*exp
;
51 return (*exp
->language_defn
->evaluate_exp
) (expect_type
, exp
, pos
, noside
);
54 /* Parse the string EXP as a C expression, evaluate it,
55 and return the result as a number. */
58 parse_and_eval_address (exp
)
61 struct expression
*expr
= parse_expression (exp
);
62 register CORE_ADDR addr
;
63 register struct cleanup
*old_chain
=
64 make_cleanup (free_current_contents
, &expr
);
66 addr
= value_as_pointer (evaluate_expression (expr
));
67 do_cleanups (old_chain
);
71 /* Like parse_and_eval_address but takes a pointer to a char * variable
72 and advanced that variable across the characters parsed. */
75 parse_and_eval_address_1 (expptr
)
78 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*)0, 0);
79 register CORE_ADDR addr
;
80 register struct cleanup
*old_chain
=
81 make_cleanup (free_current_contents
, &expr
);
83 addr
= value_as_pointer (evaluate_expression (expr
));
84 do_cleanups (old_chain
);
92 struct expression
*expr
= parse_expression (exp
);
93 register value_ptr val
;
94 register struct cleanup
*old_chain
95 = make_cleanup (free_current_contents
, &expr
);
97 val
= evaluate_expression (expr
);
98 do_cleanups (old_chain
);
102 /* Parse up to a comma (or to a closeparen)
103 in the string EXPP as an expression, evaluate it, and return the value.
104 EXPP is advanced to point to the comma. */
107 parse_to_comma_and_eval (expp
)
110 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
111 register value_ptr val
;
112 register struct cleanup
*old_chain
113 = make_cleanup (free_current_contents
, &expr
);
115 val
= evaluate_expression (expr
);
116 do_cleanups (old_chain
);
120 /* Evaluate an expression in internal prefix form
121 such as is constructed by parse.y.
123 See expression.h for info on the format of an expression. */
126 evaluate_expression (exp
)
127 struct expression
*exp
;
130 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
133 /* Evaluate an expression, avoiding all memory references
134 and getting a value whose type alone is correct. */
138 struct expression
*exp
;
141 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
144 /* Helper function called by evaluate_subexp to initialize a field
145 a structure from a tuple in Chill. This is recursive, to handle
146 more than one field name labels.
148 STRUCT_VAL is the structure value we are constructing.
149 (*FIELDNOP) is the field to set, if there is no label.
150 It is set to the field following this one.
151 EXP, POS, and NOSIDE are as for evaluate_subexp.
153 This function does not handle variant records. FIXME */
156 evaluate_labeled_field_init (struct_val
, fieldnop
, exp
, pos
, noside
)
157 value_ptr struct_val
;
159 register struct expression
*exp
;
163 int fieldno
= *fieldnop
;
167 struct type
*struct_type
= VALUE_TYPE (struct_val
);
168 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
171 char *name
= &exp
->elts
[pc
+ 2].string
;
172 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
173 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
174 for (fieldno
= 0; ; fieldno
++)
176 if (fieldno
>= TYPE_NFIELDS (struct_type
))
177 error ("there is no field named %s", name
);
178 if (STREQ (TYPE_FIELD_NAME (struct_type
, fieldno
), name
))
182 val
= evaluate_labeled_field_init (struct_val
, fieldnop
,
187 fieldno
= (*fieldnop
)++;
188 if (fieldno
>= TYPE_NFIELDS (struct_type
))
189 error ("too many initializers");
190 val
= evaluate_subexp (TYPE_FIELD_TYPE (struct_type
, fieldno
),
194 /* Assign val to field fieldno. */
195 if (VALUE_TYPE (val
) != TYPE_FIELD_TYPE (struct_type
, fieldno
))
196 val
= value_cast (TYPE_FIELD_TYPE (struct_type
, fieldno
), val
);
198 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
199 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
200 addr
= VALUE_CONTENTS (struct_val
);
203 modify_field (addr
, value_as_long (val
),
204 bitpos
% 8, bitsize
);
206 memcpy (addr
, VALUE_CONTENTS (val
),
207 TYPE_LENGTH (VALUE_TYPE (val
)));
209 value_assign (value_primitive_field (struct_val
, 0, fieldno
, struct_type
),
216 evaluate_subexp_standard (expect_type
, exp
, pos
, noside
)
217 struct type
*expect_type
;
218 register struct expression
*exp
;
224 register int pc
, pc2
= 0, oldpos
;
225 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
229 struct symbol
*tmp_symbol
;
230 int upper
, lower
, retcode
;
232 struct internalvar
*var
;
234 /* This expect_type crap should not be used for C. C expressions do
235 not have any notion of expected types, never has and (goddess
236 willing) never will. The C++ code uses it for some twisted
237 purpose (I haven't investigated but I suspect it just the usual
238 combination of Stroustrup figuring out some crazy language
239 feature and Tiemann figuring out some crazier way to try to
240 implement it). CHILL has the tuple stuff; I don't know enough
241 about CHILL to know whether expected types is the way to do it.
242 FORTRAN I don't know. */
243 if (exp
->language_defn
->la_language
!= language_cplus
244 && exp
->language_defn
->la_language
!= language_chill
)
245 expect_type
= NULL_TYPE
;
248 op
= exp
->elts
[pc
].opcode
;
253 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
254 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
255 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
257 exp
->elts
[pc
+ 1].type
,
258 &exp
->elts
[pc
+ 3].string
,
261 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
266 return value_from_longest (exp
->elts
[pc
+ 1].type
,
267 exp
->elts
[pc
+ 2].longconst
);
271 return value_from_double (exp
->elts
[pc
+ 1].type
,
272 exp
->elts
[pc
+ 2].doubleconst
);
276 if (noside
== EVAL_SKIP
)
278 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
280 struct symbol
* sym
= exp
->elts
[pc
+ 2].symbol
;
283 switch (SYMBOL_CLASS (sym
))
287 case LOC_CONST_BYTES
:
301 return value_zero (SYMBOL_TYPE (sym
), lv
);
304 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
305 exp
->elts
[pc
+ 1].block
);
310 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
314 return value_of_register (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
318 if (current_language
->la_language
== language_fortran
)
319 return value_from_longest (builtin_type_f_logical_s2
,
320 exp
->elts
[pc
+ 1].longconst
);
322 return value_from_longest (builtin_type_chill_bool
,
323 exp
->elts
[pc
+ 1].longconst
);
327 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
330 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
331 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
332 if (noside
== EVAL_SKIP
)
334 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
337 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
339 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
340 if (noside
== EVAL_SKIP
)
342 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
347 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
348 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
349 nargs
= tem3
- tem2
+ 1;
351 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
352 && TYPE_CODE (expect_type
) == TYPE_CODE_STRUCT
)
354 value_ptr rec
= allocate_value (expect_type
);
356 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (expect_type
));
357 for (tem
= 0; tem
< nargs
; tem
++)
358 evaluate_labeled_field_init (rec
, &fieldno
, exp
, pos
, noside
);
362 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
363 && TYPE_CODE (expect_type
) == TYPE_CODE_ARRAY
)
365 struct type
*range_type
= TYPE_FIELD_TYPE (expect_type
, 0);
366 struct type
*element_type
= TYPE_TARGET_TYPE (expect_type
);
367 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
368 LONGEST high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
369 int element_size
= TYPE_LENGTH (element_type
);
370 value_ptr array
= allocate_value (expect_type
);
371 if (nargs
!= (high_bound
- low_bound
+ 1))
372 error ("wrong number of initialiers for array type");
373 for (tem
= low_bound
; tem
<= high_bound
; tem
++)
375 value_ptr element
= evaluate_subexp (element_type
,
377 if (VALUE_TYPE (element
) != element_type
)
378 element
= value_cast (element_type
, element
);
379 memcpy (VALUE_CONTENTS_RAW (array
)
380 + (tem
- low_bound
) * element_size
,
381 VALUE_CONTENTS (element
),
387 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
388 && TYPE_CODE (expect_type
) == TYPE_CODE_SET
)
390 value_ptr set
= allocate_value (expect_type
);
391 struct type
*element_type
= TYPE_INDEX_TYPE (expect_type
);
392 int low_bound
= TYPE_LOW_BOUND (element_type
);
393 int high_bound
= TYPE_HIGH_BOUND (element_type
);
394 char *valaddr
= VALUE_CONTENTS_RAW (set
);
395 memset (valaddr
, '\0', TYPE_LENGTH (expect_type
));
396 for (tem
= 0; tem
< nargs
; tem
++)
398 value_ptr element_val
= evaluate_subexp (element_type
,
400 LONGEST element
= value_as_long (element_val
);
402 if (element
< low_bound
|| element
> high_bound
)
403 error ("POWERSET tuple element out of range");
404 element
-= low_bound
;
405 bit_index
= (unsigned) element
% TARGET_CHAR_BIT
;
407 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
408 valaddr
[(unsigned) element
/ TARGET_CHAR_BIT
] |= 1 << bit_index
;
413 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
414 for (tem
= 0; tem
< nargs
; tem
++)
416 /* Ensure that array expressions are coerced into pointer objects. */
417 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
419 if (noside
== EVAL_SKIP
)
421 return value_array (tem2
, tem3
, argvec
);
425 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
427 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
429 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
430 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
433 case TERNOP_SLICE_COUNT
:
435 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
437 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
439 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
440 return value_slice (array
, lowbound
, length
);
444 /* Skip third and second args to evaluate the first one. */
445 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
446 if (value_logical_not (arg1
))
448 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
449 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
453 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
454 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
460 op
= exp
->elts
[*pos
].opcode
;
461 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
465 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
466 /* First, evaluate the structure into arg2 */
469 if (noside
== EVAL_SKIP
)
472 if (op
== STRUCTOP_MEMBER
)
474 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
478 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
481 /* If the function is a virtual function, then the
482 aggregate value (providing the structure) plays
483 its part by providing the vtable. Otherwise,
484 it is just along for the ride: call the function
487 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
489 fnptr
= value_as_long (arg1
);
491 if (METHOD_PTR_IS_VIRTUAL(fnptr
))
493 int fnoffset
= METHOD_PTR_TO_VOFFSET(fnptr
);
494 struct type
*basetype
;
495 struct type
*domain_type
=
496 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
498 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
499 if (domain_type
!= basetype
)
500 arg2
= value_cast(lookup_pointer_type (domain_type
), arg2
);
501 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
502 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
504 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
505 /* If one is virtual, then all are virtual. */
506 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
507 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
508 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
510 value_ptr temp
= value_ind (arg2
);
511 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
512 arg2
= value_addr (temp
);
517 error ("virtual function at index %d not found", fnoffset
);
521 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
525 /* Now, say which argument to start evaluating from */
528 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
530 /* Hair for method invocations */
533 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
534 /* First, evaluate the structure into arg2 */
536 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
537 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
538 if (noside
== EVAL_SKIP
)
541 if (op
== STRUCTOP_STRUCT
)
543 /* If v is a variable in a register, and the user types
544 v.method (), this will produce an error, because v has
547 A possible way around this would be to allocate a
548 copy of the variable on the stack, copy in the
549 contents, call the function, and copy out the
550 contents. I.e. convert this from call by reference
551 to call by copy-return (or whatever it's called).
552 However, this does not work because it is not the
553 same: the method being called could stash a copy of
554 the address, and then future uses through that address
555 (after the method returns) would be expected to
556 use the variable itself, not some copy of it. */
557 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
561 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
563 /* Now, say which argument to start evaluating from */
568 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
571 /* Allocate arg vector, including space for the function to be
572 called in argvec[0] and a terminating NULL */
573 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
574 for (; tem
<= nargs
; tem
++)
575 /* Ensure that array expressions are coerced into pointer objects. */
576 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
578 /* signal end of arglist */
581 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
584 value_ptr temp
= arg2
;
589 strcpy(tstr
, &exp
->elts
[pc2
+2].string
);
594 value_struct_elt (&temp
, argvec
+1, tstr
,
596 op
== STRUCTOP_STRUCT
597 ? "structure" : "structure pointer");
599 arg2
= value_from_longest (lookup_pointer_type(VALUE_TYPE (temp
)),
600 VALUE_ADDRESS (temp
)+VALUE_OFFSET (temp
));
605 argvec
[1] = argvec
[0];
610 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
618 if (noside
== EVAL_SKIP
)
620 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
622 /* If the return type doesn't look like a function type, call an
623 error. This can happen if somebody tries to turn a variable into
624 a function call. This is here because people often want to
625 call, eg, strcmp, which gdb doesn't know is a function. If
626 gdb isn't asked for it's opinion (ie. through "whatis"),
627 it won't offer it. */
630 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
633 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
635 error ("Expression of type other than \"Function returning ...\" used as function");
637 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
639 case OP_F77_UNDETERMINED_ARGLIST
:
641 /* Remember that in F77, functions, substring ops and
642 array subscript operations cannot be disambiguated
643 at parse time. We have made all array subscript operations,
644 substring operations as well as function calls come here
645 and we now have to discover what the heck this thing actually was.
646 If it is a function, we process just as if we got an OP_FUNCALL. */
648 nargs
= longest_to_int (exp
->elts
[pc
+1].longconst
);
651 /* First determine the type code we are dealing with. */
652 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
653 code
= TYPE_CODE (VALUE_TYPE (arg1
));
657 case TYPE_CODE_ARRAY
:
658 goto multi_f77_subscript
;
660 case TYPE_CODE_STRING
:
665 /* It's a function call. */
666 /* Allocate arg vector, including space for the function to be
667 called in argvec[0] and a terminating NULL */
668 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
671 for (; tem
<= nargs
; tem
++)
672 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
673 argvec
[tem
] = 0; /* signal end of arglist */
677 error ("Cannot perform substring on this type");
681 /* We have a substring operation on our hands here,
682 let us get the string we will be dealing with */
684 /* Now evaluate the 'from' and 'to' */
686 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
688 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
689 error ("Substring arguments must be of type integer");
692 return value_subscript (arg1
, arg2
);
694 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
696 if (TYPE_CODE (VALUE_TYPE (arg3
)) != TYPE_CODE_INT
)
697 error ("Substring arguments must be of type integer");
699 tem2
= *((int *) VALUE_CONTENTS_RAW (arg2
));
700 tem3
= *((int *) VALUE_CONTENTS_RAW (arg3
));
702 if ((tem2
< 1) || (tem2
> tem3
))
703 error ("Bad 'from' value %d on substring operation", tem2
);
705 if ((tem3
< tem2
) || (tem3
> (TYPE_LENGTH (VALUE_TYPE (arg1
)))))
706 error ("Bad 'to' value %d on substring operation", tem3
);
708 if (noside
== EVAL_SKIP
)
711 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
714 /* We have a complex number, There should be 2 floating
715 point numbers that compose it */
716 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
717 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
719 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
721 case STRUCTOP_STRUCT
:
722 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
723 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
724 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
725 if (noside
== EVAL_SKIP
)
727 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
728 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
729 &exp
->elts
[pc
+ 2].string
,
734 value_ptr temp
= arg1
;
735 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
740 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
741 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
742 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
743 if (noside
== EVAL_SKIP
)
745 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
746 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
747 &exp
->elts
[pc
+ 2].string
,
752 value_ptr temp
= arg1
;
753 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
754 NULL
, "structure pointer");
757 case STRUCTOP_MEMBER
:
758 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
759 goto handle_pointer_to_member
;
761 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
762 handle_pointer_to_member
:
763 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
764 if (noside
== EVAL_SKIP
)
766 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_PTR
)
767 goto bad_pointer_to_member
;
768 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
769 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
770 error ("not implemented: pointer-to-method in pointer-to-member construct");
771 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
772 goto bad_pointer_to_member
;
773 /* Now, convert these values to an address. */
774 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
776 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
777 value_as_long (arg1
) + value_as_long (arg2
));
778 return value_ind (arg3
);
779 bad_pointer_to_member
:
780 error("non-pointer-to-member value used in pointer-to-member construct");
783 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
784 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
785 if (noside
== EVAL_SKIP
)
787 if (binop_user_defined_p (op
, arg1
, arg2
))
788 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
790 return value_concat (arg1
, arg2
);
793 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
794 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
795 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
797 if (binop_user_defined_p (op
, arg1
, arg2
))
798 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
800 return value_assign (arg1
, arg2
);
802 case BINOP_ASSIGN_MODIFY
:
804 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
805 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
806 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
808 op
= exp
->elts
[pc
+ 1].opcode
;
809 if (binop_user_defined_p (op
, arg1
, arg2
))
810 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
);
811 else if (op
== BINOP_ADD
)
812 arg2
= value_add (arg1
, arg2
);
813 else if (op
== BINOP_SUB
)
814 arg2
= value_sub (arg1
, arg2
);
816 arg2
= value_binop (arg1
, arg2
, op
);
817 return value_assign (arg1
, arg2
);
820 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
821 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
822 if (noside
== EVAL_SKIP
)
824 if (binop_user_defined_p (op
, arg1
, arg2
))
825 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
827 return value_add (arg1
, arg2
);
830 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
831 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
832 if (noside
== EVAL_SKIP
)
834 if (binop_user_defined_p (op
, arg1
, arg2
))
835 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
837 return value_sub (arg1
, arg2
);
845 case BINOP_BITWISE_AND
:
846 case BINOP_BITWISE_IOR
:
847 case BINOP_BITWISE_XOR
:
848 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
849 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
850 if (noside
== EVAL_SKIP
)
852 if (binop_user_defined_p (op
, arg1
, arg2
))
853 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
855 if (noside
== EVAL_AVOID_SIDE_EFFECTS
856 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
857 return value_zero (VALUE_TYPE (arg1
), not_lval
);
859 return value_binop (arg1
, arg2
, op
);
861 case BINOP_SUBSCRIPT
:
862 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
863 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
864 if (noside
== EVAL_SKIP
)
866 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
868 /* If the user attempts to subscript something that has no target
869 type (like a plain int variable for example), then report this
872 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
874 return value_zero (type
, VALUE_LVAL (arg1
));
876 error ("cannot subscript something of type `%s'",
877 TYPE_NAME (VALUE_TYPE (arg1
)));
880 if (binop_user_defined_p (op
, arg1
, arg2
))
881 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
883 return value_subscript (arg1
, arg2
);
886 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
887 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
888 if (noside
== EVAL_SKIP
)
890 return value_in (arg1
, arg2
);
892 case MULTI_SUBSCRIPT
:
894 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
895 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
898 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
899 /* FIXME: EVAL_SKIP handling may not be correct. */
900 if (noside
== EVAL_SKIP
)
911 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
912 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
914 /* If the user attempts to subscript something that has no target
915 type (like a plain int variable for example), then report this
918 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
921 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
927 error ("cannot subscript something of type `%s'",
928 TYPE_NAME (VALUE_TYPE (arg1
)));
932 if (binop_user_defined_p (op
, arg1
, arg2
))
934 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
);
938 arg1
= value_subscript (arg1
, arg2
);
945 int subscript_array
[MAX_FORTRAN_DIMS
+1]; /* 1-based array of
946 subscripts, max == 7 */
947 int array_size_array
[MAX_FORTRAN_DIMS
+1];
949 struct type
*tmp_type
;
950 int offset_item
; /* The array offset where the item lives */
952 if (nargs
> MAX_FORTRAN_DIMS
)
953 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
955 ndimensions
= calc_f77_array_dims (VALUE_TYPE (arg1
));
957 if (nargs
!= ndimensions
)
958 error ("Wrong number of subscripts");
960 /* Now that we know we have a legal array subscript expression
961 let us actually find out where this element exists in the array. */
963 tmp_type
= VALUE_TYPE (arg1
);
965 for (i
= 1; i
<= nargs
; i
++)
967 /* Evaluate each subscript, It must be a legal integer in F77 */
968 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
970 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
971 error ("Array subscripts must be of type integer");
973 /* Fill in the subscript and array size arrays */
975 subscript_array
[i
] = (* (unsigned int *) VALUE_CONTENTS(arg2
));
977 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
978 if (retcode
== BOUND_FETCH_ERROR
)
979 error ("Cannot obtain dynamic upper bound");
981 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
982 if (retcode
== BOUND_FETCH_ERROR
)
983 error("Cannot obtain dynamic lower bound");
985 array_size_array
[i
] = upper
- lower
+ 1;
987 /* Zero-normalize subscripts so that offsetting will work. */
989 subscript_array
[i
] -= lower
;
991 /* If we are at the bottom of a multidimensional
992 array type then keep a ptr to the last ARRAY
993 type around for use when calling value_subscript()
994 below. This is done because we pretend to value_subscript
995 that we actually have a one-dimensional array
996 of base element type that we apply a simple
1000 tmp_type
= TYPE_TARGET_TYPE (tmp_type
);
1003 /* Now let us calculate the offset for this item */
1005 offset_item
= subscript_array
[ndimensions
];
1007 for (i
= ndimensions
- 1; i
>= 1; i
--)
1009 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1011 /* Construct a value node with the value of the offset */
1013 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1015 /* Let us now play a dirty trick: we will take arg1
1016 which is a value node pointing to the topmost level
1017 of the multidimensional array-set and pretend
1018 that it is actually a array of the final element
1019 type, this will ensure that value_subscript()
1020 returns the correct type value */
1022 VALUE_TYPE (arg1
) = tmp_type
;
1023 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1026 case BINOP_LOGICAL_AND
:
1027 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1028 if (noside
== EVAL_SKIP
)
1030 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1035 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1038 if (binop_user_defined_p (op
, arg1
, arg2
))
1040 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1041 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1045 tem
= value_logical_not (arg1
);
1046 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1047 (tem
? EVAL_SKIP
: noside
));
1048 return value_from_longest (builtin_type_int
,
1049 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1052 case BINOP_LOGICAL_OR
:
1053 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1054 if (noside
== EVAL_SKIP
)
1056 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1061 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1064 if (binop_user_defined_p (op
, arg1
, arg2
))
1066 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1067 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1071 tem
= value_logical_not (arg1
);
1072 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1073 (!tem
? EVAL_SKIP
: noside
));
1074 return value_from_longest (builtin_type_int
,
1075 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1079 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1080 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1081 if (noside
== EVAL_SKIP
)
1083 if (binop_user_defined_p (op
, arg1
, arg2
))
1085 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1089 tem
= value_equal (arg1
, arg2
);
1090 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1093 case BINOP_NOTEQUAL
:
1094 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1095 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1096 if (noside
== EVAL_SKIP
)
1098 if (binop_user_defined_p (op
, arg1
, arg2
))
1100 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1104 tem
= value_equal (arg1
, arg2
);
1105 return value_from_longest (builtin_type_int
, (LONGEST
) ! tem
);
1109 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1110 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1111 if (noside
== EVAL_SKIP
)
1113 if (binop_user_defined_p (op
, arg1
, arg2
))
1115 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1119 tem
= value_less (arg1
, arg2
);
1120 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1124 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1125 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1126 if (noside
== EVAL_SKIP
)
1128 if (binop_user_defined_p (op
, arg1
, arg2
))
1130 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1134 tem
= value_less (arg2
, arg1
);
1135 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1139 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1140 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1141 if (noside
== EVAL_SKIP
)
1143 if (binop_user_defined_p (op
, arg1
, arg2
))
1145 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1149 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1150 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1154 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1155 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1156 if (noside
== EVAL_SKIP
)
1158 if (binop_user_defined_p (op
, arg1
, arg2
))
1160 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1164 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1165 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1169 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1170 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1171 if (noside
== EVAL_SKIP
)
1173 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1174 error ("Non-integral right operand for \"@\" operator.");
1175 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1176 return allocate_repeat_value (VALUE_TYPE (arg1
),
1177 longest_to_int (value_as_long (arg2
)));
1179 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1182 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1183 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1186 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1187 if (noside
== EVAL_SKIP
)
1189 if (unop_user_defined_p (op
, arg1
))
1190 return value_x_unop (arg1
, op
);
1192 return value_neg (arg1
);
1194 case UNOP_COMPLEMENT
:
1195 /* C++: check for and handle destructor names. */
1196 op
= exp
->elts
[*pos
].opcode
;
1198 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1199 if (noside
== EVAL_SKIP
)
1201 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1202 return value_x_unop (arg1
, UNOP_COMPLEMENT
);
1204 return value_complement (arg1
);
1206 case UNOP_LOGICAL_NOT
:
1207 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1208 if (noside
== EVAL_SKIP
)
1210 if (unop_user_defined_p (op
, arg1
))
1211 return value_x_unop (arg1
, op
);
1213 return value_from_longest (builtin_type_int
,
1214 (LONGEST
) value_logical_not (arg1
));
1217 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1218 expect_type
= TYPE_TARGET_TYPE (expect_type
);
1219 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1220 if (noside
== EVAL_SKIP
)
1222 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1224 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
1225 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_REF
1226 /* In C you can dereference an array to get the 1st elt. */
1227 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_ARRAY
1229 return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)),
1231 else if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_INT
)
1232 /* GDB allows dereferencing an int. */
1233 return value_zero (builtin_type_int
, lval_memory
);
1235 error ("Attempt to take contents of a non-pointer value.");
1237 return value_ind (arg1
);
1240 /* C++: check for and handle pointer to members. */
1242 op
= exp
->elts
[*pos
].opcode
;
1244 if (noside
== EVAL_SKIP
)
1248 int temm
= longest_to_int (exp
->elts
[pc
+3].longconst
);
1249 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1252 evaluate_subexp (expect_type
, exp
, pos
, EVAL_SKIP
);
1256 return evaluate_subexp_for_address (exp
, pos
, noside
);
1259 if (noside
== EVAL_SKIP
)
1261 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1264 return evaluate_subexp_for_sizeof (exp
, pos
);
1268 type
= exp
->elts
[pc
+ 1].type
;
1269 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1270 if (noside
== EVAL_SKIP
)
1272 if (type
!= VALUE_TYPE (arg1
))
1273 arg1
= value_cast (type
, arg1
);
1278 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1279 if (noside
== EVAL_SKIP
)
1281 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1282 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1284 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1285 value_as_pointer (arg1
));
1287 case UNOP_PREINCREMENT
:
1288 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1289 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1291 else if (unop_user_defined_p (op
, arg1
))
1293 return value_x_unop (arg1
, op
);
1297 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1299 return value_assign (arg1
, arg2
);
1302 case UNOP_PREDECREMENT
:
1303 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1304 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1306 else if (unop_user_defined_p (op
, arg1
))
1308 return value_x_unop (arg1
, op
);
1312 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1314 return value_assign (arg1
, arg2
);
1317 case UNOP_POSTINCREMENT
:
1318 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1319 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1321 else if (unop_user_defined_p (op
, arg1
))
1323 return value_x_unop (arg1
, op
);
1327 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1329 value_assign (arg1
, arg2
);
1333 case UNOP_POSTDECREMENT
:
1334 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1335 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1337 else if (unop_user_defined_p (op
, arg1
))
1339 return value_x_unop (arg1
, op
);
1343 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1345 value_assign (arg1
, arg2
);
1351 return value_of_this (1);
1354 error ("Attempt to use a type name as an expression");
1357 /* Removing this case and compiling with gcc -Wall reveals that
1358 a lot of cases are hitting this case. Some of these should
1359 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1360 and an OP_SCOPE?); others are legitimate expressions which are
1361 (apparently) not fully implemented.
1363 If there are any cases landing here which mean a user error,
1364 then they should be separate cases, with more descriptive
1368 GDB does not (yet) know how to evaluate that kind of expression");
1372 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1375 /* Evaluate a subexpression of EXP, at index *POS,
1376 and return the address of that subexpression.
1377 Advance *POS over the subexpression.
1378 If the subexpression isn't an lvalue, get an error.
1379 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1380 then only the type of the result need be correct. */
1383 evaluate_subexp_for_address (exp
, pos
, noside
)
1384 register struct expression
*exp
;
1393 op
= exp
->elts
[pc
].opcode
;
1399 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1403 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1404 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1407 var
= exp
->elts
[pc
+ 2].symbol
;
1409 /* C++: The "address" of a reference should yield the address
1410 * of the object pointed to. Let value_addr() deal with it. */
1411 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1415 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1418 lookup_pointer_type (SYMBOL_TYPE (var
));
1419 enum address_class sym_class
= SYMBOL_CLASS (var
);
1421 if (sym_class
== LOC_CONST
1422 || sym_class
== LOC_CONST_BYTES
1423 || sym_class
== LOC_REGISTER
1424 || sym_class
== LOC_REGPARM
)
1425 error ("Attempt to take address of register or constant.");
1428 value_zero (type
, not_lval
);
1434 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1438 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1440 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1441 if (VALUE_LVAL (x
) == lval_memory
)
1442 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1445 error ("Attempt to take address of non-lval");
1447 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1451 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1452 When used in contexts where arrays will be coerced anyway, this is
1453 equivalent to `evaluate_subexp' but much faster because it avoids
1454 actually fetching array contents (perhaps obsolete now that we have
1457 Note that we currently only do the coercion for C expressions, where
1458 arrays are zero based and the coercion is correct. For other languages,
1459 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1460 to decide if coercion is appropriate.
1465 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1466 register struct expression
*exp
;
1470 register enum exp_opcode op
;
1472 register value_ptr val
;
1476 op
= exp
->elts
[pc
].opcode
;
1481 var
= exp
->elts
[pc
+ 2].symbol
;
1482 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_ARRAY
1483 && CAST_IS_CONVERSION
)
1488 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1489 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1495 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1499 /* Evaluate a subexpression of EXP, at index *POS,
1500 and return a value for the size of that subexpression.
1501 Advance *POS over the subexpression. */
1504 evaluate_subexp_for_sizeof (exp
, pos
)
1505 register struct expression
*exp
;
1513 op
= exp
->elts
[pc
].opcode
;
1517 /* This case is handled specially
1518 so that we avoid creating a value for the result type.
1519 If the result type is very big, it's desirable not to
1520 create a value unnecessarily. */
1523 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1524 return value_from_longest (builtin_type_int
, (LONGEST
)
1525 TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val
))));
1529 return value_from_longest (builtin_type_int
,
1530 (LONGEST
) TYPE_LENGTH (exp
->elts
[pc
+ 1].type
));
1537 (LONGEST
) TYPE_LENGTH (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
)));
1540 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1541 return value_from_longest (builtin_type_int
,
1542 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1546 /* Parse a type expression in the string [P..P+LENGTH). */
1549 parse_and_eval_type (p
, length
)
1553 char *tmp
= (char *)alloca (length
+ 4);
1554 struct expression
*expr
;
1556 memcpy (tmp
+1, p
, length
);
1557 tmp
[length
+1] = ')';
1558 tmp
[length
+2] = '0';
1559 tmp
[length
+3] = '\0';
1560 expr
= parse_expression (tmp
);
1561 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1562 error ("Internal error in eval_type.");
1563 return expr
->elts
[1].type
;
1567 calc_f77_array_dims (array_type
)
1568 struct type
*array_type
;
1571 struct type
*tmp_type
;
1573 if ((TYPE_CODE(array_type
) != TYPE_CODE_ARRAY
))
1574 error ("Can't get dimensions for a non-array type");
1576 tmp_type
= array_type
;
1578 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1580 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)