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. */
22 #include "gdb_string.h"
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 int upper
, lower
, retcode
;
232 /* This expect_type crap should not be used for C. C expressions do
233 not have any notion of expected types, never has and (goddess
234 willing) never will. The C++ code uses it for some twisted
235 purpose (I haven't investigated but I suspect it just the usual
236 combination of Stroustrup figuring out some crazy language
237 feature and Tiemann figuring out some crazier way to try to
238 implement it). CHILL has the tuple stuff; I don't know enough
239 about CHILL to know whether expected types is the way to do it.
240 FORTRAN I don't know. */
241 if (exp
->language_defn
->la_language
!= language_cplus
242 && exp
->language_defn
->la_language
!= language_chill
)
243 expect_type
= NULL_TYPE
;
246 op
= exp
->elts
[pc
].opcode
;
251 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
252 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
253 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
255 exp
->elts
[pc
+ 1].type
,
256 &exp
->elts
[pc
+ 3].string
,
259 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
264 return value_from_longest (exp
->elts
[pc
+ 1].type
,
265 exp
->elts
[pc
+ 2].longconst
);
269 return value_from_double (exp
->elts
[pc
+ 1].type
,
270 exp
->elts
[pc
+ 2].doubleconst
);
274 if (noside
== EVAL_SKIP
)
276 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
278 struct symbol
* sym
= exp
->elts
[pc
+ 2].symbol
;
281 switch (SYMBOL_CLASS (sym
))
285 case LOC_CONST_BYTES
:
299 return value_zero (SYMBOL_TYPE (sym
), lv
);
302 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
303 exp
->elts
[pc
+ 1].block
);
308 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
312 return value_of_register (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
316 if (current_language
->la_language
== language_fortran
)
317 return value_from_longest (builtin_type_f_logical_s2
,
318 exp
->elts
[pc
+ 1].longconst
);
320 return value_from_longest (builtin_type_chill_bool
,
321 exp
->elts
[pc
+ 1].longconst
);
325 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
328 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
329 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
330 if (noside
== EVAL_SKIP
)
332 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
335 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
337 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
338 if (noside
== EVAL_SKIP
)
340 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
345 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
346 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
347 nargs
= tem3
- tem2
+ 1;
349 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
350 && TYPE_CODE (expect_type
) == TYPE_CODE_STRUCT
)
352 value_ptr rec
= allocate_value (expect_type
);
354 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (expect_type
));
355 for (tem
= 0; tem
< nargs
; tem
++)
356 evaluate_labeled_field_init (rec
, &fieldno
, exp
, pos
, noside
);
360 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
361 && TYPE_CODE (expect_type
) == TYPE_CODE_ARRAY
)
363 struct type
*range_type
= TYPE_FIELD_TYPE (expect_type
, 0);
364 struct type
*element_type
= TYPE_TARGET_TYPE (expect_type
);
365 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
366 LONGEST high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
367 int element_size
= TYPE_LENGTH (element_type
);
368 value_ptr array
= allocate_value (expect_type
);
369 if (nargs
!= (high_bound
- low_bound
+ 1))
370 error ("wrong number of initialiers for array type");
371 for (tem
= low_bound
; tem
<= high_bound
; tem
++)
373 value_ptr element
= evaluate_subexp (element_type
,
375 if (VALUE_TYPE (element
) != element_type
)
376 element
= value_cast (element_type
, element
);
377 memcpy (VALUE_CONTENTS_RAW (array
)
378 + (tem
- low_bound
) * element_size
,
379 VALUE_CONTENTS (element
),
385 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
386 && TYPE_CODE (expect_type
) == TYPE_CODE_SET
)
388 value_ptr set
= allocate_value (expect_type
);
389 struct type
*element_type
= TYPE_INDEX_TYPE (expect_type
);
390 int low_bound
= TYPE_LOW_BOUND (element_type
);
391 int high_bound
= TYPE_HIGH_BOUND (element_type
);
392 char *valaddr
= VALUE_CONTENTS_RAW (set
);
393 memset (valaddr
, '\0', TYPE_LENGTH (expect_type
));
394 for (tem
= 0; tem
< nargs
; tem
++)
396 value_ptr element_val
= evaluate_subexp (element_type
,
398 LONGEST element
= value_as_long (element_val
);
400 if (element
< low_bound
|| element
> high_bound
)
401 error ("POWERSET tuple element out of range");
402 element
-= low_bound
;
403 bit_index
= (unsigned) element
% TARGET_CHAR_BIT
;
405 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
406 valaddr
[(unsigned) element
/ TARGET_CHAR_BIT
] |= 1 << bit_index
;
411 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
412 for (tem
= 0; tem
< nargs
; tem
++)
414 /* Ensure that array expressions are coerced into pointer objects. */
415 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
417 if (noside
== EVAL_SKIP
)
419 return value_array (tem2
, tem3
, argvec
);
423 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
425 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
427 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
428 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
431 case TERNOP_SLICE_COUNT
:
433 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
435 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
437 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
438 return value_slice (array
, lowbound
, length
);
442 /* Skip third and second args to evaluate the first one. */
443 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
444 if (value_logical_not (arg1
))
446 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
447 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
451 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
452 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
458 op
= exp
->elts
[*pos
].opcode
;
459 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
463 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
464 /* First, evaluate the structure into arg2 */
467 if (noside
== EVAL_SKIP
)
470 if (op
== STRUCTOP_MEMBER
)
472 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
476 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
479 /* If the function is a virtual function, then the
480 aggregate value (providing the structure) plays
481 its part by providing the vtable. Otherwise,
482 it is just along for the ride: call the function
485 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
487 fnptr
= value_as_long (arg1
);
489 if (METHOD_PTR_IS_VIRTUAL(fnptr
))
491 int fnoffset
= METHOD_PTR_TO_VOFFSET(fnptr
);
492 struct type
*basetype
;
493 struct type
*domain_type
=
494 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
496 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
497 if (domain_type
!= basetype
)
498 arg2
= value_cast(lookup_pointer_type (domain_type
), arg2
);
499 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
500 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
502 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
503 /* If one is virtual, then all are virtual. */
504 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
505 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
506 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
508 value_ptr temp
= value_ind (arg2
);
509 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
510 arg2
= value_addr (temp
);
515 error ("virtual function at index %d not found", fnoffset
);
519 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
523 /* Now, say which argument to start evaluating from */
526 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
528 /* Hair for method invocations */
531 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
532 /* First, evaluate the structure into arg2 */
534 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
535 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
536 if (noside
== EVAL_SKIP
)
539 if (op
== STRUCTOP_STRUCT
)
541 /* If v is a variable in a register, and the user types
542 v.method (), this will produce an error, because v has
545 A possible way around this would be to allocate a
546 copy of the variable on the stack, copy in the
547 contents, call the function, and copy out the
548 contents. I.e. convert this from call by reference
549 to call by copy-return (or whatever it's called).
550 However, this does not work because it is not the
551 same: the method being called could stash a copy of
552 the address, and then future uses through that address
553 (after the method returns) would be expected to
554 use the variable itself, not some copy of it. */
555 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
559 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
561 /* Now, say which argument to start evaluating from */
566 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
569 /* Allocate arg vector, including space for the function to be
570 called in argvec[0] and a terminating NULL */
571 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
572 for (; tem
<= nargs
; tem
++)
573 /* Ensure that array expressions are coerced into pointer objects. */
574 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
576 /* signal end of arglist */
579 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
582 value_ptr temp
= arg2
;
587 strcpy(tstr
, &exp
->elts
[pc2
+2].string
);
592 value_struct_elt (&temp
, argvec
+1, tstr
,
594 op
== STRUCTOP_STRUCT
595 ? "structure" : "structure pointer");
597 arg2
= value_from_longest (lookup_pointer_type(VALUE_TYPE (temp
)),
598 VALUE_ADDRESS (temp
)+VALUE_OFFSET (temp
));
603 argvec
[1] = argvec
[0];
608 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
616 if (noside
== EVAL_SKIP
)
618 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
620 /* If the return type doesn't look like a function type, call an
621 error. This can happen if somebody tries to turn a variable into
622 a function call. This is here because people often want to
623 call, eg, strcmp, which gdb doesn't know is a function. If
624 gdb isn't asked for it's opinion (ie. through "whatis"),
625 it won't offer it. */
628 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
631 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
633 error ("Expression of type other than \"Function returning ...\" used as function");
635 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
637 case OP_F77_UNDETERMINED_ARGLIST
:
639 /* Remember that in F77, functions, substring ops and
640 array subscript operations cannot be disambiguated
641 at parse time. We have made all array subscript operations,
642 substring operations as well as function calls come here
643 and we now have to discover what the heck this thing actually was.
644 If it is a function, we process just as if we got an OP_FUNCALL. */
646 nargs
= longest_to_int (exp
->elts
[pc
+1].longconst
);
649 /* First determine the type code we are dealing with. */
650 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
651 code
= TYPE_CODE (VALUE_TYPE (arg1
));
655 case TYPE_CODE_ARRAY
:
656 goto multi_f77_subscript
;
658 case TYPE_CODE_STRING
:
663 /* It's a function call. */
664 /* Allocate arg vector, including space for the function to be
665 called in argvec[0] and a terminating NULL */
666 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
669 for (; tem
<= nargs
; tem
++)
670 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
671 argvec
[tem
] = 0; /* signal end of arglist */
675 error ("Cannot perform substring on this type");
679 /* We have a substring operation on our hands here,
680 let us get the string we will be dealing with */
682 /* Now evaluate the 'from' and 'to' */
684 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
686 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
687 error ("Substring arguments must be of type integer");
690 return value_subscript (arg1
, arg2
);
692 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
694 if (TYPE_CODE (VALUE_TYPE (arg3
)) != TYPE_CODE_INT
)
695 error ("Substring arguments must be of type integer");
697 tem2
= *((int *) VALUE_CONTENTS_RAW (arg2
));
698 tem3
= *((int *) VALUE_CONTENTS_RAW (arg3
));
700 if ((tem2
< 1) || (tem2
> tem3
))
701 error ("Bad 'from' value %d on substring operation", tem2
);
703 if ((tem3
< tem2
) || (tem3
> (TYPE_LENGTH (VALUE_TYPE (arg1
)))))
704 error ("Bad 'to' value %d on substring operation", tem3
);
706 if (noside
== EVAL_SKIP
)
709 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
712 /* We have a complex number, There should be 2 floating
713 point numbers that compose it */
714 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
715 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
717 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
719 case STRUCTOP_STRUCT
:
720 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
721 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
722 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
723 if (noside
== EVAL_SKIP
)
725 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
726 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
727 &exp
->elts
[pc
+ 2].string
,
732 value_ptr temp
= arg1
;
733 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
738 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
739 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
740 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
741 if (noside
== EVAL_SKIP
)
743 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
744 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
745 &exp
->elts
[pc
+ 2].string
,
750 value_ptr temp
= arg1
;
751 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
752 NULL
, "structure pointer");
755 case STRUCTOP_MEMBER
:
756 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
757 goto handle_pointer_to_member
;
759 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
760 handle_pointer_to_member
:
761 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
762 if (noside
== EVAL_SKIP
)
764 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_PTR
)
765 goto bad_pointer_to_member
;
766 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
767 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
768 error ("not implemented: pointer-to-method in pointer-to-member construct");
769 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
770 goto bad_pointer_to_member
;
771 /* Now, convert these values to an address. */
772 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
774 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
775 value_as_long (arg1
) + value_as_long (arg2
));
776 return value_ind (arg3
);
777 bad_pointer_to_member
:
778 error("non-pointer-to-member value used in pointer-to-member construct");
781 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
782 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
783 if (noside
== EVAL_SKIP
)
785 if (binop_user_defined_p (op
, arg1
, arg2
))
786 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
788 return value_concat (arg1
, arg2
);
791 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
792 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
793 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
795 if (binop_user_defined_p (op
, arg1
, arg2
))
796 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
798 return value_assign (arg1
, arg2
);
800 case BINOP_ASSIGN_MODIFY
:
802 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
803 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
804 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
806 op
= exp
->elts
[pc
+ 1].opcode
;
807 if (binop_user_defined_p (op
, arg1
, arg2
))
808 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
);
809 else if (op
== BINOP_ADD
)
810 arg2
= value_add (arg1
, arg2
);
811 else if (op
== BINOP_SUB
)
812 arg2
= value_sub (arg1
, arg2
);
814 arg2
= value_binop (arg1
, arg2
, op
);
815 return value_assign (arg1
, arg2
);
818 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
819 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
820 if (noside
== EVAL_SKIP
)
822 if (binop_user_defined_p (op
, arg1
, arg2
))
823 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
825 return value_add (arg1
, arg2
);
828 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
829 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
830 if (noside
== EVAL_SKIP
)
832 if (binop_user_defined_p (op
, arg1
, arg2
))
833 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
835 return value_sub (arg1
, arg2
);
843 case BINOP_BITWISE_AND
:
844 case BINOP_BITWISE_IOR
:
845 case BINOP_BITWISE_XOR
:
846 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
847 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
848 if (noside
== EVAL_SKIP
)
850 if (binop_user_defined_p (op
, arg1
, arg2
))
851 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
853 if (noside
== EVAL_AVOID_SIDE_EFFECTS
854 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
855 return value_zero (VALUE_TYPE (arg1
), not_lval
);
857 return value_binop (arg1
, arg2
, op
);
859 case BINOP_SUBSCRIPT
:
860 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
861 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
862 if (noside
== EVAL_SKIP
)
864 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
866 /* If the user attempts to subscript something that has no target
867 type (like a plain int variable for example), then report this
870 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
872 return value_zero (type
, VALUE_LVAL (arg1
));
874 error ("cannot subscript something of type `%s'",
875 TYPE_NAME (VALUE_TYPE (arg1
)));
878 if (binop_user_defined_p (op
, arg1
, arg2
))
879 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
881 return value_subscript (arg1
, arg2
);
884 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
885 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
886 if (noside
== EVAL_SKIP
)
888 return value_in (arg1
, arg2
);
890 case MULTI_SUBSCRIPT
:
892 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
893 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
896 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
897 /* FIXME: EVAL_SKIP handling may not be correct. */
898 if (noside
== EVAL_SKIP
)
909 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
910 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
912 /* If the user attempts to subscript something that has no target
913 type (like a plain int variable for example), then report this
916 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
919 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
925 error ("cannot subscript something of type `%s'",
926 TYPE_NAME (VALUE_TYPE (arg1
)));
930 if (binop_user_defined_p (op
, arg1
, arg2
))
932 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
);
936 arg1
= value_subscript (arg1
, arg2
);
943 int subscript_array
[MAX_FORTRAN_DIMS
+1]; /* 1-based array of
944 subscripts, max == 7 */
945 int array_size_array
[MAX_FORTRAN_DIMS
+1];
947 struct type
*tmp_type
;
948 int offset_item
; /* The array offset where the item lives */
950 if (nargs
> MAX_FORTRAN_DIMS
)
951 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
953 ndimensions
= calc_f77_array_dims (VALUE_TYPE (arg1
));
955 if (nargs
!= ndimensions
)
956 error ("Wrong number of subscripts");
958 /* Now that we know we have a legal array subscript expression
959 let us actually find out where this element exists in the array. */
961 tmp_type
= VALUE_TYPE (arg1
);
963 for (i
= 1; i
<= nargs
; i
++)
965 /* Evaluate each subscript, It must be a legal integer in F77 */
966 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
968 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
969 error ("Array subscripts must be of type integer");
971 /* Fill in the subscript and array size arrays */
973 subscript_array
[i
] = (* (unsigned int *) VALUE_CONTENTS(arg2
));
975 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
976 if (retcode
== BOUND_FETCH_ERROR
)
977 error ("Cannot obtain dynamic upper bound");
979 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
980 if (retcode
== BOUND_FETCH_ERROR
)
981 error("Cannot obtain dynamic lower bound");
983 array_size_array
[i
] = upper
- lower
+ 1;
985 /* Zero-normalize subscripts so that offsetting will work. */
987 subscript_array
[i
] -= lower
;
989 /* If we are at the bottom of a multidimensional
990 array type then keep a ptr to the last ARRAY
991 type around for use when calling value_subscript()
992 below. This is done because we pretend to value_subscript
993 that we actually have a one-dimensional array
994 of base element type that we apply a simple
998 tmp_type
= TYPE_TARGET_TYPE (tmp_type
);
1001 /* Now let us calculate the offset for this item */
1003 offset_item
= subscript_array
[ndimensions
];
1005 for (i
= ndimensions
- 1; i
>= 1; i
--)
1007 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1009 /* Construct a value node with the value of the offset */
1011 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1013 /* Let us now play a dirty trick: we will take arg1
1014 which is a value node pointing to the topmost level
1015 of the multidimensional array-set and pretend
1016 that it is actually a array of the final element
1017 type, this will ensure that value_subscript()
1018 returns the correct type value */
1020 VALUE_TYPE (arg1
) = tmp_type
;
1021 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1024 case BINOP_LOGICAL_AND
:
1025 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1026 if (noside
== EVAL_SKIP
)
1028 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1033 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1036 if (binop_user_defined_p (op
, arg1
, arg2
))
1038 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1039 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1043 tem
= value_logical_not (arg1
);
1044 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1045 (tem
? EVAL_SKIP
: noside
));
1046 return value_from_longest (builtin_type_int
,
1047 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1050 case BINOP_LOGICAL_OR
:
1051 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1052 if (noside
== EVAL_SKIP
)
1054 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1059 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1062 if (binop_user_defined_p (op
, arg1
, arg2
))
1064 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1065 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1069 tem
= value_logical_not (arg1
);
1070 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1071 (!tem
? EVAL_SKIP
: noside
));
1072 return value_from_longest (builtin_type_int
,
1073 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1077 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1078 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1079 if (noside
== EVAL_SKIP
)
1081 if (binop_user_defined_p (op
, arg1
, arg2
))
1083 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1087 tem
= value_equal (arg1
, arg2
);
1088 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1091 case BINOP_NOTEQUAL
:
1092 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1093 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1094 if (noside
== EVAL_SKIP
)
1096 if (binop_user_defined_p (op
, arg1
, arg2
))
1098 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1102 tem
= value_equal (arg1
, arg2
);
1103 return value_from_longest (builtin_type_int
, (LONGEST
) ! tem
);
1107 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1108 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1109 if (noside
== EVAL_SKIP
)
1111 if (binop_user_defined_p (op
, arg1
, arg2
))
1113 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1117 tem
= value_less (arg1
, arg2
);
1118 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1122 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1123 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1124 if (noside
== EVAL_SKIP
)
1126 if (binop_user_defined_p (op
, arg1
, arg2
))
1128 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1132 tem
= value_less (arg2
, arg1
);
1133 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1137 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1138 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1139 if (noside
== EVAL_SKIP
)
1141 if (binop_user_defined_p (op
, arg1
, arg2
))
1143 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1147 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1148 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1152 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1153 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1154 if (noside
== EVAL_SKIP
)
1156 if (binop_user_defined_p (op
, arg1
, arg2
))
1158 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1162 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1163 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1167 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1168 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1169 if (noside
== EVAL_SKIP
)
1171 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1172 error ("Non-integral right operand for \"@\" operator.");
1173 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1175 if (VALUE_REPEATED (arg1
))
1176 error ("Cannot create artificial arrays of artificial arrays.");
1177 return allocate_repeat_value (VALUE_TYPE (arg1
),
1178 longest_to_int (value_as_long (arg2
)));
1181 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1184 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1185 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1188 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1189 if (noside
== EVAL_SKIP
)
1191 if (unop_user_defined_p (op
, arg1
))
1192 return value_x_unop (arg1
, op
);
1194 return value_neg (arg1
);
1196 case UNOP_COMPLEMENT
:
1197 /* C++: check for and handle destructor names. */
1198 op
= exp
->elts
[*pos
].opcode
;
1200 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1201 if (noside
== EVAL_SKIP
)
1203 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1204 return value_x_unop (arg1
, UNOP_COMPLEMENT
);
1206 return value_complement (arg1
);
1208 case UNOP_LOGICAL_NOT
:
1209 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1210 if (noside
== EVAL_SKIP
)
1212 if (unop_user_defined_p (op
, arg1
))
1213 return value_x_unop (arg1
, op
);
1215 return value_from_longest (builtin_type_int
,
1216 (LONGEST
) value_logical_not (arg1
));
1219 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1220 expect_type
= TYPE_TARGET_TYPE (expect_type
);
1221 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1222 if (noside
== EVAL_SKIP
)
1224 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1226 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
1227 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_REF
1228 /* In C you can dereference an array to get the 1st elt. */
1229 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_ARRAY
1231 return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)),
1233 else if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_INT
)
1234 /* GDB allows dereferencing an int. */
1235 return value_zero (builtin_type_int
, lval_memory
);
1237 error ("Attempt to take contents of a non-pointer value.");
1239 return value_ind (arg1
);
1242 /* C++: check for and handle pointer to members. */
1244 op
= exp
->elts
[*pos
].opcode
;
1246 if (noside
== EVAL_SKIP
)
1250 int temm
= longest_to_int (exp
->elts
[pc
+3].longconst
);
1251 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1254 evaluate_subexp (expect_type
, exp
, pos
, EVAL_SKIP
);
1258 return evaluate_subexp_for_address (exp
, pos
, noside
);
1261 if (noside
== EVAL_SKIP
)
1263 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1266 return evaluate_subexp_for_sizeof (exp
, pos
);
1270 type
= exp
->elts
[pc
+ 1].type
;
1271 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1272 if (noside
== EVAL_SKIP
)
1274 if (type
!= VALUE_TYPE (arg1
))
1275 arg1
= value_cast (type
, arg1
);
1280 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1281 if (noside
== EVAL_SKIP
)
1283 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1284 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1286 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1287 value_as_pointer (arg1
));
1289 case UNOP_PREINCREMENT
:
1290 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1291 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1293 else if (unop_user_defined_p (op
, arg1
))
1295 return value_x_unop (arg1
, op
);
1299 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1301 return value_assign (arg1
, arg2
);
1304 case UNOP_PREDECREMENT
:
1305 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1306 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1308 else if (unop_user_defined_p (op
, arg1
))
1310 return value_x_unop (arg1
, op
);
1314 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1316 return value_assign (arg1
, arg2
);
1319 case UNOP_POSTINCREMENT
:
1320 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1321 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1323 else if (unop_user_defined_p (op
, arg1
))
1325 return value_x_unop (arg1
, op
);
1329 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1331 value_assign (arg1
, arg2
);
1335 case UNOP_POSTDECREMENT
:
1336 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1337 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1339 else if (unop_user_defined_p (op
, arg1
))
1341 return value_x_unop (arg1
, op
);
1345 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1347 value_assign (arg1
, arg2
);
1353 return value_of_this (1);
1356 error ("Attempt to use a type name as an expression");
1359 /* Removing this case and compiling with gcc -Wall reveals that
1360 a lot of cases are hitting this case. Some of these should
1361 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1362 and an OP_SCOPE?); others are legitimate expressions which are
1363 (apparently) not fully implemented.
1365 If there are any cases landing here which mean a user error,
1366 then they should be separate cases, with more descriptive
1370 GDB does not (yet) know how to evaluate that kind of expression");
1374 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1377 /* Evaluate a subexpression of EXP, at index *POS,
1378 and return the address of that subexpression.
1379 Advance *POS over the subexpression.
1380 If the subexpression isn't an lvalue, get an error.
1381 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1382 then only the type of the result need be correct. */
1385 evaluate_subexp_for_address (exp
, pos
, noside
)
1386 register struct expression
*exp
;
1395 op
= exp
->elts
[pc
].opcode
;
1401 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1405 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1406 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1409 var
= exp
->elts
[pc
+ 2].symbol
;
1411 /* C++: The "address" of a reference should yield the address
1412 * of the object pointed to. Let value_addr() deal with it. */
1413 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1417 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1420 lookup_pointer_type (SYMBOL_TYPE (var
));
1421 enum address_class sym_class
= SYMBOL_CLASS (var
);
1423 if (sym_class
== LOC_CONST
1424 || sym_class
== LOC_CONST_BYTES
1425 || sym_class
== LOC_REGISTER
1426 || sym_class
== LOC_REGPARM
)
1427 error ("Attempt to take address of register or constant.");
1430 value_zero (type
, not_lval
);
1436 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1440 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1442 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1443 if (VALUE_LVAL (x
) == lval_memory
)
1444 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1447 error ("Attempt to take address of non-lval");
1449 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1453 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1454 When used in contexts where arrays will be coerced anyway, this is
1455 equivalent to `evaluate_subexp' but much faster because it avoids
1456 actually fetching array contents (perhaps obsolete now that we have
1459 Note that we currently only do the coercion for C expressions, where
1460 arrays are zero based and the coercion is correct. For other languages,
1461 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1462 to decide if coercion is appropriate.
1467 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1468 register struct expression
*exp
;
1472 register enum exp_opcode op
;
1474 register value_ptr val
;
1478 op
= exp
->elts
[pc
].opcode
;
1483 var
= exp
->elts
[pc
+ 2].symbol
;
1484 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_ARRAY
1485 && CAST_IS_CONVERSION
)
1490 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1491 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1497 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1501 /* Evaluate a subexpression of EXP, at index *POS,
1502 and return a value for the size of that subexpression.
1503 Advance *POS over the subexpression. */
1506 evaluate_subexp_for_sizeof (exp
, pos
)
1507 register struct expression
*exp
;
1515 op
= exp
->elts
[pc
].opcode
;
1519 /* This case is handled specially
1520 so that we avoid creating a value for the result type.
1521 If the result type is very big, it's desirable not to
1522 create a value unnecessarily. */
1525 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1526 return value_from_longest (builtin_type_int
, (LONGEST
)
1527 TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val
))));
1531 return value_from_longest (builtin_type_int
,
1532 (LONGEST
) TYPE_LENGTH (exp
->elts
[pc
+ 1].type
));
1539 (LONGEST
) TYPE_LENGTH (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
)));
1542 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1543 return value_from_longest (builtin_type_int
,
1544 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1548 /* Parse a type expression in the string [P..P+LENGTH). */
1551 parse_and_eval_type (p
, length
)
1555 char *tmp
= (char *)alloca (length
+ 4);
1556 struct expression
*expr
;
1558 memcpy (tmp
+1, p
, length
);
1559 tmp
[length
+1] = ')';
1560 tmp
[length
+2] = '0';
1561 tmp
[length
+3] = '\0';
1562 expr
= parse_expression (tmp
);
1563 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1564 error ("Internal error in eval_type.");
1565 return expr
->elts
[1].type
;
1569 calc_f77_array_dims (array_type
)
1570 struct type
*array_type
;
1573 struct type
*tmp_type
;
1575 if ((TYPE_CODE(array_type
) != TYPE_CODE_ARRAY
))
1576 error ("Can't get dimensions for a non-array type");
1578 tmp_type
= array_type
;
1580 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1582 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)