1 /* Evaluate expressions for GDB.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994
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 value_ptr evaluate_subexp_with_coercion
PARAMS ((struct expression
*,
41 static value_ptr evaluate_subexp_for_address
PARAMS ((struct expression
*,
48 evaluate_subexp (expect_type
, exp
, pos
, noside
)
49 struct type
*expect_type
;
50 register struct expression
*exp
;
54 return (*exp
->language_defn
->evaluate_exp
) (expect_type
, exp
, pos
, noside
);
57 /* Parse the string EXP as a C expression, evaluate it,
58 and return the result as a number. */
61 parse_and_eval_address (exp
)
64 struct expression
*expr
= parse_expression (exp
);
65 register CORE_ADDR addr
;
66 register struct cleanup
*old_chain
=
67 make_cleanup (free_current_contents
, &expr
);
69 addr
= value_as_pointer (evaluate_expression (expr
));
70 do_cleanups (old_chain
);
74 /* Like parse_and_eval_address but takes a pointer to a char * variable
75 and advanced that variable across the characters parsed. */
78 parse_and_eval_address_1 (expptr
)
81 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*)0, 0);
82 register CORE_ADDR addr
;
83 register struct cleanup
*old_chain
=
84 make_cleanup (free_current_contents
, &expr
);
86 addr
= value_as_pointer (evaluate_expression (expr
));
87 do_cleanups (old_chain
);
95 struct expression
*expr
= parse_expression (exp
);
96 register value_ptr val
;
97 register struct cleanup
*old_chain
98 = make_cleanup (free_current_contents
, &expr
);
100 val
= evaluate_expression (expr
);
101 do_cleanups (old_chain
);
105 /* Parse up to a comma (or to a closeparen)
106 in the string EXPP as an expression, evaluate it, and return the value.
107 EXPP is advanced to point to the comma. */
110 parse_to_comma_and_eval (expp
)
113 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
114 register value_ptr val
;
115 register struct cleanup
*old_chain
116 = make_cleanup (free_current_contents
, &expr
);
118 val
= evaluate_expression (expr
);
119 do_cleanups (old_chain
);
123 /* Evaluate an expression in internal prefix form
124 such as is constructed by parse.y.
126 See expression.h for info on the format of an expression. */
129 evaluate_expression (exp
)
130 struct expression
*exp
;
133 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
136 /* Evaluate an expression, avoiding all memory references
137 and getting a value whose type alone is correct. */
141 struct expression
*exp
;
144 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
147 /* Helper function called by evaluate_subexp to initialize a field
148 a structure from a tuple in Chill. This is recursive, to handle
149 more than one field name labels.
151 STRUCT_VAL is the structure value we are constructing.
152 (*FIELDNOP) is the field to set, if there is no label.
153 It is set to the field following this one.
154 EXP, POS, and NOSIDE are as for evaluate_subexp.
156 This function does not handle variant records. FIXME */
159 evaluate_labeled_field_init (struct_val
, fieldnop
, exp
, pos
, noside
)
160 value_ptr struct_val
;
162 register struct expression
*exp
;
166 int fieldno
= *fieldnop
;
170 struct type
*struct_type
= VALUE_TYPE (struct_val
);
171 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
174 char *name
= &exp
->elts
[pc
+ 2].string
;
175 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
176 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
177 for (fieldno
= 0; ; fieldno
++)
179 if (fieldno
>= TYPE_NFIELDS (struct_type
))
180 error ("there is no field named %s", name
);
181 if (STREQ (TYPE_FIELD_NAME (struct_type
, fieldno
), name
))
185 val
= evaluate_labeled_field_init (struct_val
, fieldnop
,
190 fieldno
= (*fieldnop
)++;
191 if (fieldno
>= TYPE_NFIELDS (struct_type
))
192 error ("too many initializers");
193 val
= evaluate_subexp (TYPE_FIELD_TYPE (struct_type
, fieldno
),
197 /* Assign val to field fieldno. */
198 if (VALUE_TYPE (val
) != TYPE_FIELD_TYPE (struct_type
, fieldno
))
199 val
= value_cast (TYPE_FIELD_TYPE (struct_type
, fieldno
), val
);
201 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
202 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
203 addr
= VALUE_CONTENTS (struct_val
);
206 modify_field (addr
, value_as_long (val
),
207 bitpos
% 8, bitsize
);
209 memcpy (addr
, VALUE_CONTENTS (val
),
210 TYPE_LENGTH (VALUE_TYPE (val
)));
212 value_assign (value_primitive_field (struct_val
, 0, fieldno
, struct_type
),
219 evaluate_subexp_standard (expect_type
, exp
, pos
, noside
)
220 struct type
*expect_type
;
221 register struct expression
*exp
;
227 register int pc
, pc2
= 0, oldpos
;
228 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
232 struct symbol
*tmp_symbol
;
233 int upper
, lower
, retcode
;
235 struct internalvar
*var
;
237 /* This expect_type crap should not be used for C. C expressions do
238 not have any notion of expected types, never has and (goddess
239 willing) never will. The C++ code uses it for some twisted
240 purpose (I haven't investigated but I suspect it just the usual
241 combination of Stroustrup figuring out some crazy language
242 feature and Tiemann figuring out some crazier way to try to
243 implement it). CHILL has the tuple stuff; I don't know enough
244 about CHILL to know whether expected types is the way to do it.
245 FORTRAN I don't know. */
246 if (exp
->language_defn
->la_language
!= language_cplus
247 && exp
->language_defn
->la_language
!= language_chill
)
248 expect_type
= NULL_TYPE
;
251 op
= exp
->elts
[pc
].opcode
;
256 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
257 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
258 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
260 exp
->elts
[pc
+ 1].type
,
261 &exp
->elts
[pc
+ 3].string
,
264 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
269 return value_from_longest (exp
->elts
[pc
+ 1].type
,
270 exp
->elts
[pc
+ 2].longconst
);
274 return value_from_double (exp
->elts
[pc
+ 1].type
,
275 exp
->elts
[pc
+ 2].doubleconst
);
279 if (noside
== EVAL_SKIP
)
281 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
283 struct symbol
* sym
= exp
->elts
[pc
+ 2].symbol
;
286 switch (SYMBOL_CLASS (sym
))
290 case LOC_CONST_BYTES
:
304 return value_zero (SYMBOL_TYPE (sym
), lv
);
307 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
308 exp
->elts
[pc
+ 1].block
);
313 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
317 return value_of_register (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
321 if (current_language
->la_language
== language_fortran
)
322 return value_from_longest (builtin_type_f_logical_s2
,
323 exp
->elts
[pc
+ 1].longconst
);
325 return value_from_longest (builtin_type_chill_bool
,
326 exp
->elts
[pc
+ 1].longconst
);
330 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
333 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
334 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
335 if (noside
== EVAL_SKIP
)
337 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
340 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
342 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
343 if (noside
== EVAL_SKIP
)
345 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
350 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
351 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
352 nargs
= tem3
- tem2
+ 1;
354 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
355 && TYPE_CODE (expect_type
) == TYPE_CODE_STRUCT
)
357 value_ptr rec
= allocate_value (expect_type
);
359 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (expect_type
));
360 for (tem
= 0; tem
< nargs
; tem
++)
361 evaluate_labeled_field_init (rec
, &fieldno
, exp
, pos
, noside
);
365 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
366 && TYPE_CODE (expect_type
) == TYPE_CODE_ARRAY
)
368 struct type
*range_type
= TYPE_FIELD_TYPE (expect_type
, 0);
369 struct type
*element_type
= TYPE_TARGET_TYPE (expect_type
);
370 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
371 LONGEST high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
372 int element_size
= TYPE_LENGTH (element_type
);
373 value_ptr array
= allocate_value (expect_type
);
374 if (nargs
!= (high_bound
- low_bound
+ 1))
375 error ("wrong number of initialiers for array type");
376 for (tem
= low_bound
; tem
<= high_bound
; tem
++)
378 value_ptr element
= evaluate_subexp (element_type
,
380 if (VALUE_TYPE (element
) != element_type
)
381 element
= value_cast (element_type
, element
);
382 memcpy (VALUE_CONTENTS_RAW (array
)
383 + (tem
- low_bound
) * element_size
,
384 VALUE_CONTENTS (element
),
390 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
391 && TYPE_CODE (expect_type
) == TYPE_CODE_SET
)
393 value_ptr set
= allocate_value (expect_type
);
394 struct type
*element_type
= TYPE_INDEX_TYPE (expect_type
);
395 int low_bound
= TYPE_LOW_BOUND (element_type
);
396 int high_bound
= TYPE_HIGH_BOUND (element_type
);
397 char *valaddr
= VALUE_CONTENTS_RAW (set
);
398 memset (valaddr
, '\0', TYPE_LENGTH (expect_type
));
399 for (tem
= 0; tem
< nargs
; tem
++)
401 value_ptr element_val
= evaluate_subexp (element_type
,
403 LONGEST element
= value_as_long (element_val
);
405 if (element
< low_bound
|| element
> high_bound
)
406 error ("POWERSET tuple element out of range");
407 element
-= low_bound
;
408 bit_index
= (unsigned) element
% TARGET_CHAR_BIT
;
410 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
411 valaddr
[(unsigned) element
/ TARGET_CHAR_BIT
] |= 1 << bit_index
;
416 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
417 for (tem
= 0; tem
< nargs
; tem
++)
419 /* Ensure that array expressions are coerced into pointer objects. */
420 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
422 if (noside
== EVAL_SKIP
)
424 return value_array (tem2
, tem3
, argvec
);
428 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
430 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
432 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
433 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
436 case TERNOP_SLICE_COUNT
:
438 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
440 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
442 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
443 return value_slice (array
, lowbound
, length
);
447 /* Skip third and second args to evaluate the first one. */
448 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
449 if (value_logical_not (arg1
))
451 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
452 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
456 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
457 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
463 op
= exp
->elts
[*pos
].opcode
;
464 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
468 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
469 /* First, evaluate the structure into arg2 */
472 if (noside
== EVAL_SKIP
)
475 if (op
== STRUCTOP_MEMBER
)
477 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
481 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
484 /* If the function is a virtual function, then the
485 aggregate value (providing the structure) plays
486 its part by providing the vtable. Otherwise,
487 it is just along for the ride: call the function
490 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
492 fnptr
= value_as_long (arg1
);
494 if (METHOD_PTR_IS_VIRTUAL(fnptr
))
496 int fnoffset
= METHOD_PTR_TO_VOFFSET(fnptr
);
497 struct type
*basetype
;
498 struct type
*domain_type
=
499 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
501 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
502 if (domain_type
!= basetype
)
503 arg2
= value_cast(lookup_pointer_type (domain_type
), arg2
);
504 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
505 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
507 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
508 /* If one is virtual, then all are virtual. */
509 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
510 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
511 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
513 value_ptr temp
= value_ind (arg2
);
514 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
515 arg2
= value_addr (temp
);
520 error ("virtual function at index %d not found", fnoffset
);
524 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
528 /* Now, say which argument to start evaluating from */
531 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
533 /* Hair for method invocations */
536 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
537 /* First, evaluate the structure into arg2 */
539 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
540 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
541 if (noside
== EVAL_SKIP
)
544 if (op
== STRUCTOP_STRUCT
)
546 /* If v is a variable in a register, and the user types
547 v.method (), this will produce an error, because v has
550 A possible way around this would be to allocate a
551 copy of the variable on the stack, copy in the
552 contents, call the function, and copy out the
553 contents. I.e. convert this from call by reference
554 to call by copy-return (or whatever it's called).
555 However, this does not work because it is not the
556 same: the method being called could stash a copy of
557 the address, and then future uses through that address
558 (after the method returns) would be expected to
559 use the variable itself, not some copy of it. */
560 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
564 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
566 /* Now, say which argument to start evaluating from */
571 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
574 /* Allocate arg vector, including space for the function to be
575 called in argvec[0] and a terminating NULL */
576 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
577 for (; tem
<= nargs
; tem
++)
578 /* Ensure that array expressions are coerced into pointer objects. */
579 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
581 /* signal end of arglist */
584 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
587 value_ptr temp
= arg2
;
592 strcpy(tstr
, &exp
->elts
[pc2
+2].string
);
597 value_struct_elt (&temp
, argvec
+1, tstr
,
599 op
== STRUCTOP_STRUCT
600 ? "structure" : "structure pointer");
602 arg2
= value_from_longest (lookup_pointer_type(VALUE_TYPE (temp
)),
603 VALUE_ADDRESS (temp
)+VALUE_OFFSET (temp
));
608 argvec
[1] = argvec
[0];
613 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
621 if (noside
== EVAL_SKIP
)
623 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
625 /* If the return type doesn't look like a function type, call an
626 error. This can happen if somebody tries to turn a variable into
627 a function call. This is here because people often want to
628 call, eg, strcmp, which gdb doesn't know is a function. If
629 gdb isn't asked for it's opinion (ie. through "whatis"),
630 it won't offer it. */
633 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
636 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
638 error ("Expression of type other than \"Function returning ...\" used as function");
640 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
642 case OP_F77_UNDETERMINED_ARGLIST
:
644 /* Remember that in F77, functions, substring ops and
645 array subscript operations cannot be disambiguated
646 at parse time. We have made all array subscript operations,
647 substring operations as well as function calls come here
648 and we now have to discover what the heck this thing actually was.
649 If it is a function, we process just as if we got an OP_FUNCALL. */
651 nargs
= longest_to_int (exp
->elts
[pc
+1].longconst
);
654 /* First determine the type code we are dealing with. */
655 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
656 code
= TYPE_CODE (VALUE_TYPE (arg1
));
660 case TYPE_CODE_ARRAY
:
661 goto multi_f77_subscript
;
663 case TYPE_CODE_STRING
:
668 /* It's a function call. */
669 /* Allocate arg vector, including space for the function to be
670 called in argvec[0] and a terminating NULL */
671 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
674 for (; tem
<= nargs
; tem
++)
675 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
676 argvec
[tem
] = 0; /* signal end of arglist */
680 error ("Cannot perform substring on this type");
684 /* We have a substring operation on our hands here,
685 let us get the string we will be dealing with */
687 /* Now evaluate the 'from' and 'to' */
689 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
691 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
692 error ("Substring arguments must be of type integer");
695 return value_subscript (arg1
, arg2
);
697 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
699 if (TYPE_CODE (VALUE_TYPE (arg3
)) != TYPE_CODE_INT
)
700 error ("Substring arguments must be of type integer");
702 tem2
= *((int *) VALUE_CONTENTS_RAW (arg2
));
703 tem3
= *((int *) VALUE_CONTENTS_RAW (arg3
));
705 if ((tem2
< 1) || (tem2
> tem3
))
706 error ("Bad 'from' value %d on substring operation", tem2
);
708 if ((tem3
< tem2
) || (tem3
> (TYPE_LENGTH (VALUE_TYPE (arg1
)))))
709 error ("Bad 'to' value %d on substring operation", tem3
);
711 if (noside
== EVAL_SKIP
)
714 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
717 /* We have a complex number, There should be 2 floating
718 point numbers that compose it */
719 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
720 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
722 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
724 case STRUCTOP_STRUCT
:
725 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
726 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
727 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
728 if (noside
== EVAL_SKIP
)
730 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
731 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
732 &exp
->elts
[pc
+ 2].string
,
737 value_ptr temp
= arg1
;
738 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
743 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
744 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
745 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
746 if (noside
== EVAL_SKIP
)
748 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
749 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
750 &exp
->elts
[pc
+ 2].string
,
755 value_ptr temp
= arg1
;
756 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
757 NULL
, "structure pointer");
760 case STRUCTOP_MEMBER
:
761 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
762 goto handle_pointer_to_member
;
764 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
765 handle_pointer_to_member
:
766 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
767 if (noside
== EVAL_SKIP
)
769 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_PTR
)
770 goto bad_pointer_to_member
;
771 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
772 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
773 error ("not implemented: pointer-to-method in pointer-to-member construct");
774 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
775 goto bad_pointer_to_member
;
776 /* Now, convert these values to an address. */
777 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
779 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
780 value_as_long (arg1
) + value_as_long (arg2
));
781 return value_ind (arg3
);
782 bad_pointer_to_member
:
783 error("non-pointer-to-member value used in pointer-to-member construct");
786 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
787 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
788 if (noside
== EVAL_SKIP
)
790 if (binop_user_defined_p (op
, arg1
, arg2
))
791 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
793 return value_concat (arg1
, arg2
);
796 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
797 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
798 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
800 if (binop_user_defined_p (op
, arg1
, arg2
))
801 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
803 return value_assign (arg1
, arg2
);
805 case BINOP_ASSIGN_MODIFY
:
807 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
808 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
809 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
811 op
= exp
->elts
[pc
+ 1].opcode
;
812 if (binop_user_defined_p (op
, arg1
, arg2
))
813 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
);
814 else if (op
== BINOP_ADD
)
815 arg2
= value_add (arg1
, arg2
);
816 else if (op
== BINOP_SUB
)
817 arg2
= value_sub (arg1
, arg2
);
819 arg2
= value_binop (arg1
, arg2
, op
);
820 return value_assign (arg1
, arg2
);
823 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
824 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
825 if (noside
== EVAL_SKIP
)
827 if (binop_user_defined_p (op
, arg1
, arg2
))
828 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
830 return value_add (arg1
, arg2
);
833 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
834 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
835 if (noside
== EVAL_SKIP
)
837 if (binop_user_defined_p (op
, arg1
, arg2
))
838 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
840 return value_sub (arg1
, arg2
);
848 case BINOP_BITWISE_AND
:
849 case BINOP_BITWISE_IOR
:
850 case BINOP_BITWISE_XOR
:
851 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
852 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
853 if (noside
== EVAL_SKIP
)
855 if (binop_user_defined_p (op
, arg1
, arg2
))
856 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
858 if (noside
== EVAL_AVOID_SIDE_EFFECTS
859 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
860 return value_zero (VALUE_TYPE (arg1
), not_lval
);
862 return value_binop (arg1
, arg2
, op
);
864 case BINOP_SUBSCRIPT
:
865 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
866 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
867 if (noside
== EVAL_SKIP
)
869 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
871 /* If the user attempts to subscript something that has no target
872 type (like a plain int variable for example), then report this
875 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
877 return value_zero (type
, VALUE_LVAL (arg1
));
879 error ("cannot subscript something of type `%s'",
880 TYPE_NAME (VALUE_TYPE (arg1
)));
883 if (binop_user_defined_p (op
, arg1
, arg2
))
884 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
886 return value_subscript (arg1
, arg2
);
889 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
890 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
891 if (noside
== EVAL_SKIP
)
893 return value_in (arg1
, arg2
);
895 case MULTI_SUBSCRIPT
:
897 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
898 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
901 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
902 /* FIXME: EVAL_SKIP handling may not be correct. */
903 if (noside
== EVAL_SKIP
)
914 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
915 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
917 /* If the user attempts to subscript something that has no target
918 type (like a plain int variable for example), then report this
921 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
924 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
930 error ("cannot subscript something of type `%s'",
931 TYPE_NAME (VALUE_TYPE (arg1
)));
935 if (binop_user_defined_p (op
, arg1
, arg2
))
937 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
);
941 arg1
= value_subscript (arg1
, arg2
);
948 int subscript_array
[MAX_FORTRAN_DIMS
+1]; /* 1-based array of
949 subscripts, max == 7 */
950 int array_size_array
[MAX_FORTRAN_DIMS
+1];
952 struct type
*tmp_type
;
953 int offset_item
; /* The array offset where the item lives */
956 if (nargs
> MAX_FORTRAN_DIMS
)
957 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
959 ndimensions
= calc_f77_array_dims (VALUE_TYPE (arg1
));
961 if (nargs
!= ndimensions
)
962 error ("Wrong number of subscripts");
964 /* Now that we know we have a legal array subscript expression
965 let us actually find out where this element exists in the array. */
967 tmp_type
= VALUE_TYPE (arg1
);
969 for (i
= 1; i
<= nargs
; i
++)
971 /* Evaluate each subscript, It must be a legal integer in F77 */
972 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
974 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
975 error ("Array subscripts must be of type integer");
977 /* Fill in the subscript and array size arrays */
979 subscript_array
[i
] = (* (unsigned int *) VALUE_CONTENTS(arg2
));
981 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
982 if (retcode
== BOUND_FETCH_ERROR
)
983 error ("Cannot obtain dynamic upper bound");
985 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
986 if (retcode
== BOUND_FETCH_ERROR
)
987 error("Cannot obtain dynamic lower bound");
989 array_size_array
[i
] = upper
- lower
+ 1;
991 /* Zero-normalize subscripts so that offsetting will work. */
993 subscript_array
[i
] -= lower
;
995 /* If we are at the bottom of a multidimensional
996 array type then keep a ptr to the last ARRAY
997 type around for use when calling value_subscript()
998 below. This is done because we pretend to value_subscript
999 that we actually have a one-dimensional array
1000 of base element type that we apply a simple
1004 tmp_type
= TYPE_TARGET_TYPE (tmp_type
);
1007 /* Now let us calculate the offset for this item */
1009 offset_item
= subscript_array
[ndimensions
];
1011 for (i
= ndimensions
- 1; i
>= 1; i
--)
1013 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1015 /* Construct a value node with the value of the offset */
1017 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1019 /* Let us now play a dirty trick: we will take arg1
1020 which is a value node pointing to the topmost level
1021 of the multidimensional array-set and pretend
1022 that it is actually a array of the final element
1023 type, this will ensure that value_subscript()
1024 returns the correct type value */
1026 VALUE_TYPE (arg1
) = tmp_type
;
1027 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1030 case BINOP_LOGICAL_AND
:
1031 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1032 if (noside
== EVAL_SKIP
)
1034 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1039 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1042 if (binop_user_defined_p (op
, arg1
, arg2
))
1044 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1045 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1049 tem
= value_logical_not (arg1
);
1050 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1051 (tem
? EVAL_SKIP
: noside
));
1052 return value_from_longest (builtin_type_int
,
1053 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1056 case BINOP_LOGICAL_OR
:
1057 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1058 if (noside
== EVAL_SKIP
)
1060 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1065 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1068 if (binop_user_defined_p (op
, arg1
, arg2
))
1070 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1071 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1075 tem
= value_logical_not (arg1
);
1076 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1077 (!tem
? EVAL_SKIP
: noside
));
1078 return value_from_longest (builtin_type_int
,
1079 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1083 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1084 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1085 if (noside
== EVAL_SKIP
)
1087 if (binop_user_defined_p (op
, arg1
, arg2
))
1089 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1093 tem
= value_equal (arg1
, arg2
);
1094 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1097 case BINOP_NOTEQUAL
:
1098 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1099 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1100 if (noside
== EVAL_SKIP
)
1102 if (binop_user_defined_p (op
, arg1
, arg2
))
1104 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1108 tem
= value_equal (arg1
, arg2
);
1109 return value_from_longest (builtin_type_int
, (LONGEST
) ! tem
);
1113 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1114 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1115 if (noside
== EVAL_SKIP
)
1117 if (binop_user_defined_p (op
, arg1
, arg2
))
1119 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1123 tem
= value_less (arg1
, arg2
);
1124 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1128 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1129 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1130 if (noside
== EVAL_SKIP
)
1132 if (binop_user_defined_p (op
, arg1
, arg2
))
1134 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1138 tem
= value_less (arg2
, arg1
);
1139 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1143 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1144 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1145 if (noside
== EVAL_SKIP
)
1147 if (binop_user_defined_p (op
, arg1
, arg2
))
1149 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1153 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1154 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1158 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1159 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1160 if (noside
== EVAL_SKIP
)
1162 if (binop_user_defined_p (op
, arg1
, arg2
))
1164 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1168 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1169 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1173 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1174 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1175 if (noside
== EVAL_SKIP
)
1177 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1178 error ("Non-integral right operand for \"@\" operator.");
1179 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1180 return allocate_repeat_value (VALUE_TYPE (arg1
),
1181 longest_to_int (value_as_long (arg2
)));
1183 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1186 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1187 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1190 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1191 if (noside
== EVAL_SKIP
)
1193 if (unop_user_defined_p (op
, arg1
))
1194 return value_x_unop (arg1
, op
);
1196 return value_neg (arg1
);
1198 case UNOP_COMPLEMENT
:
1199 /* C++: check for and handle destructor names. */
1200 op
= exp
->elts
[*pos
].opcode
;
1202 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1203 if (noside
== EVAL_SKIP
)
1205 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1206 return value_x_unop (arg1
, UNOP_COMPLEMENT
);
1208 return value_complement (arg1
);
1210 case UNOP_LOGICAL_NOT
:
1211 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1212 if (noside
== EVAL_SKIP
)
1214 if (unop_user_defined_p (op
, arg1
))
1215 return value_x_unop (arg1
, op
);
1217 return value_from_longest (builtin_type_int
,
1218 (LONGEST
) value_logical_not (arg1
));
1221 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1222 expect_type
= TYPE_TARGET_TYPE (expect_type
);
1223 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1224 if (noside
== EVAL_SKIP
)
1226 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1228 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
1229 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_REF
1230 /* In C you can dereference an array to get the 1st elt. */
1231 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_ARRAY
1233 return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)),
1235 else if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_INT
)
1236 /* GDB allows dereferencing an int. */
1237 return value_zero (builtin_type_int
, lval_memory
);
1239 error ("Attempt to take contents of a non-pointer value.");
1241 return value_ind (arg1
);
1244 /* C++: check for and handle pointer to members. */
1246 op
= exp
->elts
[*pos
].opcode
;
1248 if (noside
== EVAL_SKIP
)
1252 int temm
= longest_to_int (exp
->elts
[pc
+3].longconst
);
1253 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1256 evaluate_subexp (expect_type
, exp
, pos
, EVAL_SKIP
);
1260 return evaluate_subexp_for_address (exp
, pos
, noside
);
1263 if (noside
== EVAL_SKIP
)
1265 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1268 return evaluate_subexp_for_sizeof (exp
, pos
);
1272 type
= exp
->elts
[pc
+ 1].type
;
1273 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1274 if (noside
== EVAL_SKIP
)
1276 if (type
!= VALUE_TYPE (arg1
))
1277 arg1
= value_cast (type
, arg1
);
1282 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1283 if (noside
== EVAL_SKIP
)
1285 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1286 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1288 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1289 value_as_pointer (arg1
));
1291 case UNOP_PREINCREMENT
:
1292 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1293 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1295 else if (unop_user_defined_p (op
, arg1
))
1297 return value_x_unop (arg1
, op
);
1301 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1303 return value_assign (arg1
, arg2
);
1306 case UNOP_PREDECREMENT
:
1307 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1308 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1310 else if (unop_user_defined_p (op
, arg1
))
1312 return value_x_unop (arg1
, op
);
1316 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1318 return value_assign (arg1
, arg2
);
1321 case UNOP_POSTINCREMENT
:
1322 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1323 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1325 else if (unop_user_defined_p (op
, arg1
))
1327 return value_x_unop (arg1
, op
);
1331 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1333 value_assign (arg1
, arg2
);
1337 case UNOP_POSTDECREMENT
:
1338 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1339 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1341 else if (unop_user_defined_p (op
, arg1
))
1343 return value_x_unop (arg1
, op
);
1347 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1349 value_assign (arg1
, arg2
);
1355 return value_of_this (1);
1358 error ("Attempt to use a type name as an expression");
1361 /* Removing this case and compiling with gcc -Wall reveals that
1362 a lot of cases are hitting this case. Some of these should
1363 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1364 and an OP_SCOPE?); others are legitimate expressions which are
1365 (apparently) not fully implemented.
1367 If there are any cases landing here which mean a user error,
1368 then they should be separate cases, with more descriptive
1372 GDB does not (yet) know how to evaluate that kind of expression");
1376 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1379 /* Evaluate a subexpression of EXP, at index *POS,
1380 and return the address of that subexpression.
1381 Advance *POS over the subexpression.
1382 If the subexpression isn't an lvalue, get an error.
1383 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1384 then only the type of the result need be correct. */
1387 evaluate_subexp_for_address (exp
, pos
, noside
)
1388 register struct expression
*exp
;
1397 op
= exp
->elts
[pc
].opcode
;
1403 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1407 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1408 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1411 var
= exp
->elts
[pc
+ 2].symbol
;
1413 /* C++: The "address" of a reference should yield the address
1414 * of the object pointed to. Let value_addr() deal with it. */
1415 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1419 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1422 lookup_pointer_type (SYMBOL_TYPE (var
));
1423 enum address_class sym_class
= SYMBOL_CLASS (var
);
1425 if (sym_class
== LOC_CONST
1426 || sym_class
== LOC_CONST_BYTES
1427 || sym_class
== LOC_REGISTER
1428 || sym_class
== LOC_REGPARM
)
1429 error ("Attempt to take address of register or constant.");
1432 value_zero (type
, not_lval
);
1438 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1442 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1444 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1445 if (VALUE_LVAL (x
) == lval_memory
)
1446 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1449 error ("Attempt to take address of non-lval");
1451 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1455 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1456 When used in contexts where arrays will be coerced anyway, this is
1457 equivalent to `evaluate_subexp' but much faster because it avoids
1458 actually fetching array contents (perhaps obsolete now that we have
1461 Note that we currently only do the coercion for C expressions, where
1462 arrays are zero based and the coercion is correct. For other languages,
1463 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1464 to decide if coercion is appropriate.
1469 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1470 register struct expression
*exp
;
1474 register enum exp_opcode op
;
1476 register value_ptr val
;
1480 op
= exp
->elts
[pc
].opcode
;
1485 var
= exp
->elts
[pc
+ 2].symbol
;
1486 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_ARRAY
1487 && CAST_IS_CONVERSION
)
1492 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1493 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1499 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1503 /* Evaluate a subexpression of EXP, at index *POS,
1504 and return a value for the size of that subexpression.
1505 Advance *POS over the subexpression. */
1508 evaluate_subexp_for_sizeof (exp
, pos
)
1509 register struct expression
*exp
;
1517 op
= exp
->elts
[pc
].opcode
;
1521 /* This case is handled specially
1522 so that we avoid creating a value for the result type.
1523 If the result type is very big, it's desirable not to
1524 create a value unnecessarily. */
1527 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1528 return value_from_longest (builtin_type_int
, (LONGEST
)
1529 TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val
))));
1533 return value_from_longest (builtin_type_int
,
1534 (LONGEST
) TYPE_LENGTH (exp
->elts
[pc
+ 1].type
));
1541 (LONGEST
) TYPE_LENGTH (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
)));
1544 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1545 return value_from_longest (builtin_type_int
,
1546 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1550 /* Parse a type expression in the string [P..P+LENGTH). */
1553 parse_and_eval_type (p
, length
)
1557 char *tmp
= (char *)alloca (length
+ 4);
1558 struct expression
*expr
;
1560 memcpy (tmp
+1, p
, length
);
1561 tmp
[length
+1] = ')';
1562 tmp
[length
+2] = '0';
1563 tmp
[length
+3] = '\0';
1564 expr
= parse_expression (tmp
);
1565 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1566 error ("Internal error in eval_type.");
1567 return expr
->elts
[1].type
;
1571 calc_f77_array_dims (array_type
)
1572 struct type
*array_type
;
1575 struct type
*tmp_type
;
1577 if ((TYPE_CODE(array_type
) != TYPE_CODE_ARRAY
))
1578 error ("Can't get dimensions for a non-array type");
1580 tmp_type
= array_type
;
1582 while (tmp_type
= TYPE_TARGET_TYPE (tmp_type
))
1584 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)