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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 /* If the next expression is an OP_LABELED, skips past it,
145 returning the label. Otherwise, does nothing and returns NULL. */
149 register struct expression
*exp
;
152 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
155 char *name
= &exp
->elts
[pc
+ 2].string
;
156 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
157 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
164 /* This function evaluates tupes (in Chill) or brace-initializers
165 (in C/C++) for structure types. */
168 evaluate_struct_tuple (struct_val
, exp
, pos
, noside
, nargs
)
169 value_ptr struct_val
;
170 register struct expression
*exp
;
175 struct type
*struct_type
= VALUE_TYPE (struct_val
);
176 struct type
*substruct_type
= struct_type
;
177 struct type
*field_type
;
184 value_ptr val
= NULL
;
189 /* Skip past the labels, and count them. */
190 while (get_label (exp
, pos
) != NULL
)
195 char *label
= get_label (exp
, &pc
);
198 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
201 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
202 if (field_name
!= NULL
&& STREQ (field_name
, label
))
205 subfieldno
= fieldno
;
206 substruct_type
= struct_type
;
210 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
213 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
214 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
215 if ((field_name
== 0 || *field_name
== '\0')
216 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
219 for (; variantno
< TYPE_NFIELDS (field_type
);
223 = TYPE_FIELD_TYPE (field_type
, variantno
);
224 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
227 subfieldno
< TYPE_NFIELDS (substruct_type
);
230 if (STREQ (TYPE_FIELD_NAME (substruct_type
,
241 error ("there is no field named %s", label
);
247 /* Unlabelled tuple element - go to next field. */
251 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
254 substruct_type
= struct_type
;
260 subfieldno
= fieldno
;
261 if (fieldno
>= TYPE_NFIELDS (struct_type
))
262 error ("too many initializers");
263 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
264 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
265 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
266 error ("don't know which variant you want to set");
270 /* Here, struct_type is the type of the inner struct,
271 while substruct_type is the type of the inner struct.
272 These are the same for normal structures, but a variant struct
273 contains anonymous union fields that contain substruct fields.
274 The value fieldno is the index of the top-level (normal or
275 anonymous union) field in struct_field, while the value
276 subfieldno is the index of the actual real (named inner) field
277 in substruct_type. */
279 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
281 val
= evaluate_subexp (substruct_type
, exp
, pos
, noside
);
283 /* Now actually set the field in struct_val. */
285 /* Assign val to field fieldno. */
286 if (VALUE_TYPE (val
) != field_type
)
287 val
= value_cast (field_type
, val
);
289 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
290 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
292 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
293 addr
= VALUE_CONTENTS (struct_val
) + bitpos
/ 8;
295 modify_field (addr
, value_as_long (val
),
296 bitpos
% 8, bitsize
);
298 memcpy (addr
, VALUE_CONTENTS (val
),
299 TYPE_LENGTH (VALUE_TYPE (val
)));
300 } while (--nlabels
> 0);
306 evaluate_subexp_standard (expect_type
, exp
, pos
, noside
)
307 struct type
*expect_type
;
308 register struct expression
*exp
;
314 register int pc
, pc2
= 0, oldpos
;
315 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
319 int upper
, lower
, retcode
;
322 /* This expect_type crap should not be used for C. C expressions do
323 not have any notion of expected types, never has and (goddess
324 willing) never will. The C++ code uses it for some twisted
325 purpose (I haven't investigated but I suspect it just the usual
326 combination of Stroustrup figuring out some crazy language
327 feature and Tiemann figuring out some crazier way to try to
328 implement it). CHILL has the tuple stuff; I don't know enough
329 about CHILL to know whether expected types is the way to do it.
330 FORTRAN I don't know. */
331 if (exp
->language_defn
->la_language
!= language_cplus
332 && exp
->language_defn
->la_language
!= language_chill
)
333 expect_type
= NULL_TYPE
;
336 op
= exp
->elts
[pc
].opcode
;
341 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
342 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
343 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
345 exp
->elts
[pc
+ 1].type
,
346 &exp
->elts
[pc
+ 3].string
,
349 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
354 return value_from_longest (exp
->elts
[pc
+ 1].type
,
355 exp
->elts
[pc
+ 2].longconst
);
359 return value_from_double (exp
->elts
[pc
+ 1].type
,
360 exp
->elts
[pc
+ 2].doubleconst
);
364 if (noside
== EVAL_SKIP
)
366 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
368 struct symbol
* sym
= exp
->elts
[pc
+ 2].symbol
;
371 switch (SYMBOL_CLASS (sym
))
375 case LOC_CONST_BYTES
:
389 return value_zero (SYMBOL_TYPE (sym
), lv
);
392 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
393 exp
->elts
[pc
+ 1].block
);
398 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
402 return value_of_register (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
406 if (current_language
->la_language
== language_fortran
)
407 return value_from_longest (builtin_type_f_logical_s2
,
408 exp
->elts
[pc
+ 1].longconst
);
410 return value_from_longest (builtin_type_chill_bool
,
411 exp
->elts
[pc
+ 1].longconst
);
415 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
418 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
419 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
420 if (noside
== EVAL_SKIP
)
422 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
425 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
427 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
428 if (noside
== EVAL_SKIP
)
430 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
435 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
436 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
437 nargs
= tem3
- tem2
+ 1;
439 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
440 && TYPE_CODE (expect_type
) == TYPE_CODE_STRUCT
)
442 value_ptr rec
= allocate_value (expect_type
);
443 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (expect_type
));
444 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
447 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
448 && TYPE_CODE (expect_type
) == TYPE_CODE_ARRAY
)
450 struct type
*range_type
= TYPE_FIELD_TYPE (expect_type
, 0);
451 struct type
*element_type
= TYPE_TARGET_TYPE (expect_type
);
452 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
453 LONGEST high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
454 int element_size
= TYPE_LENGTH (element_type
);
455 value_ptr array
= allocate_value (expect_type
);
456 if (nargs
!= (high_bound
- low_bound
+ 1))
457 error ("wrong number of initialiers for array type");
458 for (tem
= low_bound
; tem
<= high_bound
; tem
++)
460 value_ptr element
= evaluate_subexp (element_type
,
462 if (VALUE_TYPE (element
) != element_type
)
463 element
= value_cast (element_type
, element
);
464 memcpy (VALUE_CONTENTS_RAW (array
)
465 + (tem
- low_bound
) * element_size
,
466 VALUE_CONTENTS (element
),
472 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
473 && TYPE_CODE (expect_type
) == TYPE_CODE_SET
)
475 value_ptr set
= allocate_value (expect_type
);
476 struct type
*element_type
= TYPE_INDEX_TYPE (expect_type
);
477 int low_bound
= TYPE_LOW_BOUND (element_type
);
478 int high_bound
= TYPE_HIGH_BOUND (element_type
);
479 char *valaddr
= VALUE_CONTENTS_RAW (set
);
480 memset (valaddr
, '\0', TYPE_LENGTH (expect_type
));
481 for (tem
= 0; tem
< nargs
; tem
++)
483 value_ptr element_val
= evaluate_subexp (element_type
,
485 LONGEST element
= value_as_long (element_val
);
487 if (element
< low_bound
|| element
> high_bound
)
488 error ("POWERSET tuple element out of range");
489 element
-= low_bound
;
490 bit_index
= (unsigned) element
% TARGET_CHAR_BIT
;
492 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
493 valaddr
[(unsigned) element
/ TARGET_CHAR_BIT
] |= 1 << bit_index
;
498 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
499 for (tem
= 0; tem
< nargs
; tem
++)
501 /* Ensure that array expressions are coerced into pointer objects. */
502 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
504 if (noside
== EVAL_SKIP
)
506 return value_array (tem2
, tem3
, argvec
);
510 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
512 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
514 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
515 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
518 case TERNOP_SLICE_COUNT
:
520 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
522 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
524 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
525 return value_slice (array
, lowbound
, length
);
529 /* Skip third and second args to evaluate the first one. */
530 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
531 if (value_logical_not (arg1
))
533 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
534 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
538 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
539 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
545 op
= exp
->elts
[*pos
].opcode
;
546 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
550 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
551 /* First, evaluate the structure into arg2 */
554 if (noside
== EVAL_SKIP
)
557 if (op
== STRUCTOP_MEMBER
)
559 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
563 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
566 /* If the function is a virtual function, then the
567 aggregate value (providing the structure) plays
568 its part by providing the vtable. Otherwise,
569 it is just along for the ride: call the function
572 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
574 fnptr
= value_as_long (arg1
);
576 if (METHOD_PTR_IS_VIRTUAL(fnptr
))
578 int fnoffset
= METHOD_PTR_TO_VOFFSET(fnptr
);
579 struct type
*basetype
;
580 struct type
*domain_type
=
581 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
583 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
584 if (domain_type
!= basetype
)
585 arg2
= value_cast(lookup_pointer_type (domain_type
), arg2
);
586 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
587 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
589 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
590 /* If one is virtual, then all are virtual. */
591 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
592 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
593 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
595 value_ptr temp
= value_ind (arg2
);
596 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
597 arg2
= value_addr (temp
);
602 error ("virtual function at index %d not found", fnoffset
);
606 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
610 /* Now, say which argument to start evaluating from */
613 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
615 /* Hair for method invocations */
618 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
619 /* First, evaluate the structure into arg2 */
621 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
622 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
623 if (noside
== EVAL_SKIP
)
626 if (op
== STRUCTOP_STRUCT
)
628 /* If v is a variable in a register, and the user types
629 v.method (), this will produce an error, because v has
632 A possible way around this would be to allocate a
633 copy of the variable on the stack, copy in the
634 contents, call the function, and copy out the
635 contents. I.e. convert this from call by reference
636 to call by copy-return (or whatever it's called).
637 However, this does not work because it is not the
638 same: the method being called could stash a copy of
639 the address, and then future uses through that address
640 (after the method returns) would be expected to
641 use the variable itself, not some copy of it. */
642 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
646 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
648 /* Now, say which argument to start evaluating from */
653 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
656 /* Allocate arg vector, including space for the function to be
657 called in argvec[0] and a terminating NULL */
658 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
659 for (; tem
<= nargs
; tem
++)
660 /* Ensure that array expressions are coerced into pointer objects. */
661 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
663 /* signal end of arglist */
666 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
669 value_ptr temp
= arg2
;
674 strcpy(tstr
, &exp
->elts
[pc2
+2].string
);
679 value_struct_elt (&temp
, argvec
+1, tstr
,
681 op
== STRUCTOP_STRUCT
682 ? "structure" : "structure pointer");
684 arg2
= value_from_longest (lookup_pointer_type(VALUE_TYPE (temp
)),
685 VALUE_ADDRESS (temp
)+VALUE_OFFSET (temp
));
690 argvec
[1] = argvec
[0];
695 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
703 if (noside
== EVAL_SKIP
)
705 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
707 /* If the return type doesn't look like a function type, call an
708 error. This can happen if somebody tries to turn a variable into
709 a function call. This is here because people often want to
710 call, eg, strcmp, which gdb doesn't know is a function. If
711 gdb isn't asked for it's opinion (ie. through "whatis"),
712 it won't offer it. */
715 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
718 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
720 error ("Expression of type other than \"Function returning ...\" used as function");
722 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
724 case OP_F77_UNDETERMINED_ARGLIST
:
726 /* Remember that in F77, functions, substring ops and
727 array subscript operations cannot be disambiguated
728 at parse time. We have made all array subscript operations,
729 substring operations as well as function calls come here
730 and we now have to discover what the heck this thing actually was.
731 If it is a function, we process just as if we got an OP_FUNCALL. */
733 nargs
= longest_to_int (exp
->elts
[pc
+1].longconst
);
736 /* First determine the type code we are dealing with. */
737 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
738 code
= TYPE_CODE (VALUE_TYPE (arg1
));
742 case TYPE_CODE_ARRAY
:
743 goto multi_f77_subscript
;
745 case TYPE_CODE_STRING
:
750 /* It's a function call. */
751 /* Allocate arg vector, including space for the function to be
752 called in argvec[0] and a terminating NULL */
753 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
756 for (; tem
<= nargs
; tem
++)
757 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
758 argvec
[tem
] = 0; /* signal end of arglist */
762 error ("Cannot perform substring on this type");
766 /* We have a substring operation on our hands here,
767 let us get the string we will be dealing with */
769 /* Now evaluate the 'from' and 'to' */
771 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
773 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
774 error ("Substring arguments must be of type integer");
777 return value_subscript (arg1
, arg2
);
779 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
781 if (TYPE_CODE (VALUE_TYPE (arg3
)) != TYPE_CODE_INT
)
782 error ("Substring arguments must be of type integer");
784 tem2
= *((int *) VALUE_CONTENTS_RAW (arg2
));
785 tem3
= *((int *) VALUE_CONTENTS_RAW (arg3
));
787 if ((tem2
< 1) || (tem2
> tem3
))
788 error ("Bad 'from' value %d on substring operation", tem2
);
790 if ((tem3
< tem2
) || (tem3
> (TYPE_LENGTH (VALUE_TYPE (arg1
)))))
791 error ("Bad 'to' value %d on substring operation", tem3
);
793 if (noside
== EVAL_SKIP
)
796 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
799 /* We have a complex number, There should be 2 floating
800 point numbers that compose it */
801 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
802 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
804 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
806 case STRUCTOP_STRUCT
:
807 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
808 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
809 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
810 if (noside
== EVAL_SKIP
)
812 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
813 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
814 &exp
->elts
[pc
+ 2].string
,
819 value_ptr temp
= arg1
;
820 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
825 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
826 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
827 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
828 if (noside
== EVAL_SKIP
)
830 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
831 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
832 &exp
->elts
[pc
+ 2].string
,
837 value_ptr temp
= arg1
;
838 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
839 NULL
, "structure pointer");
842 case STRUCTOP_MEMBER
:
843 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
844 goto handle_pointer_to_member
;
846 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
847 handle_pointer_to_member
:
848 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
849 if (noside
== EVAL_SKIP
)
851 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_PTR
)
852 goto bad_pointer_to_member
;
853 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
854 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
855 error ("not implemented: pointer-to-method in pointer-to-member construct");
856 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
857 goto bad_pointer_to_member
;
858 /* Now, convert these values to an address. */
859 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
861 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
862 value_as_long (arg1
) + value_as_long (arg2
));
863 return value_ind (arg3
);
864 bad_pointer_to_member
:
865 error("non-pointer-to-member value used in pointer-to-member construct");
868 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
869 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
870 if (noside
== EVAL_SKIP
)
872 if (binop_user_defined_p (op
, arg1
, arg2
))
873 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
875 return value_concat (arg1
, arg2
);
878 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
879 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
880 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
882 if (binop_user_defined_p (op
, arg1
, arg2
))
883 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
885 return value_assign (arg1
, arg2
);
887 case BINOP_ASSIGN_MODIFY
:
889 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
890 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
891 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
893 op
= exp
->elts
[pc
+ 1].opcode
;
894 if (binop_user_defined_p (op
, arg1
, arg2
))
895 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
);
896 else if (op
== BINOP_ADD
)
897 arg2
= value_add (arg1
, arg2
);
898 else if (op
== BINOP_SUB
)
899 arg2
= value_sub (arg1
, arg2
);
901 arg2
= value_binop (arg1
, arg2
, op
);
902 return value_assign (arg1
, arg2
);
905 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
906 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
907 if (noside
== EVAL_SKIP
)
909 if (binop_user_defined_p (op
, arg1
, arg2
))
910 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
912 return value_add (arg1
, arg2
);
915 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
916 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
917 if (noside
== EVAL_SKIP
)
919 if (binop_user_defined_p (op
, arg1
, arg2
))
920 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
922 return value_sub (arg1
, arg2
);
930 case BINOP_BITWISE_AND
:
931 case BINOP_BITWISE_IOR
:
932 case BINOP_BITWISE_XOR
:
933 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
934 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
935 if (noside
== EVAL_SKIP
)
937 if (binop_user_defined_p (op
, arg1
, arg2
))
938 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
940 if (noside
== EVAL_AVOID_SIDE_EFFECTS
941 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
942 return value_zero (VALUE_TYPE (arg1
), not_lval
);
944 return value_binop (arg1
, arg2
, op
);
946 case BINOP_SUBSCRIPT
:
947 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
948 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
949 if (noside
== EVAL_SKIP
)
951 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
953 /* If the user attempts to subscript something that has no target
954 type (like a plain int variable for example), then report this
957 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
959 return value_zero (type
, VALUE_LVAL (arg1
));
961 error ("cannot subscript something of type `%s'",
962 TYPE_NAME (VALUE_TYPE (arg1
)));
965 if (binop_user_defined_p (op
, arg1
, arg2
))
966 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
968 return value_subscript (arg1
, arg2
);
971 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
972 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
973 if (noside
== EVAL_SKIP
)
975 return value_in (arg1
, arg2
);
977 case MULTI_SUBSCRIPT
:
979 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
980 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
983 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
984 /* FIXME: EVAL_SKIP handling may not be correct. */
985 if (noside
== EVAL_SKIP
)
996 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
997 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
999 /* If the user attempts to subscript something that has no target
1000 type (like a plain int variable for example), then report this
1003 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
1006 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1012 error ("cannot subscript something of type `%s'",
1013 TYPE_NAME (VALUE_TYPE (arg1
)));
1017 if (binop_user_defined_p (op
, arg1
, arg2
))
1019 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1023 arg1
= value_subscript (arg1
, arg2
);
1028 multi_f77_subscript
:
1030 int subscript_array
[MAX_FORTRAN_DIMS
+1]; /* 1-based array of
1031 subscripts, max == 7 */
1032 int array_size_array
[MAX_FORTRAN_DIMS
+1];
1033 int ndimensions
=1,i
;
1034 struct type
*tmp_type
;
1035 int offset_item
; /* The array offset where the item lives */
1037 if (nargs
> MAX_FORTRAN_DIMS
)
1038 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
1040 ndimensions
= calc_f77_array_dims (VALUE_TYPE (arg1
));
1042 if (nargs
!= ndimensions
)
1043 error ("Wrong number of subscripts");
1045 /* Now that we know we have a legal array subscript expression
1046 let us actually find out where this element exists in the array. */
1048 tmp_type
= VALUE_TYPE (arg1
);
1050 for (i
= 1; i
<= nargs
; i
++)
1052 /* Evaluate each subscript, It must be a legal integer in F77 */
1053 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1055 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1056 error ("Array subscripts must be of type integer");
1058 /* Fill in the subscript and array size arrays */
1060 subscript_array
[i
] = (* (unsigned int *) VALUE_CONTENTS(arg2
));
1062 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1063 if (retcode
== BOUND_FETCH_ERROR
)
1064 error ("Cannot obtain dynamic upper bound");
1066 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1067 if (retcode
== BOUND_FETCH_ERROR
)
1068 error("Cannot obtain dynamic lower bound");
1070 array_size_array
[i
] = upper
- lower
+ 1;
1072 /* Zero-normalize subscripts so that offsetting will work. */
1074 subscript_array
[i
] -= lower
;
1076 /* If we are at the bottom of a multidimensional
1077 array type then keep a ptr to the last ARRAY
1078 type around for use when calling value_subscript()
1079 below. This is done because we pretend to value_subscript
1080 that we actually have a one-dimensional array
1081 of base element type that we apply a simple
1085 tmp_type
= TYPE_TARGET_TYPE (tmp_type
);
1088 /* Now let us calculate the offset for this item */
1090 offset_item
= subscript_array
[ndimensions
];
1092 for (i
= ndimensions
- 1; i
>= 1; i
--)
1094 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1096 /* Construct a value node with the value of the offset */
1098 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1100 /* Let us now play a dirty trick: we will take arg1
1101 which is a value node pointing to the topmost level
1102 of the multidimensional array-set and pretend
1103 that it is actually a array of the final element
1104 type, this will ensure that value_subscript()
1105 returns the correct type value */
1107 VALUE_TYPE (arg1
) = tmp_type
;
1108 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1111 case BINOP_LOGICAL_AND
:
1112 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1113 if (noside
== EVAL_SKIP
)
1115 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1120 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1123 if (binop_user_defined_p (op
, arg1
, arg2
))
1125 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1126 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1130 tem
= value_logical_not (arg1
);
1131 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1132 (tem
? EVAL_SKIP
: noside
));
1133 return value_from_longest (builtin_type_int
,
1134 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1137 case BINOP_LOGICAL_OR
:
1138 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1139 if (noside
== EVAL_SKIP
)
1141 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1146 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1149 if (binop_user_defined_p (op
, arg1
, arg2
))
1151 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1152 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1156 tem
= value_logical_not (arg1
);
1157 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1158 (!tem
? EVAL_SKIP
: noside
));
1159 return value_from_longest (builtin_type_int
,
1160 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1164 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1165 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1166 if (noside
== EVAL_SKIP
)
1168 if (binop_user_defined_p (op
, arg1
, arg2
))
1170 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1174 tem
= value_equal (arg1
, arg2
);
1175 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1178 case BINOP_NOTEQUAL
:
1179 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1180 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1181 if (noside
== EVAL_SKIP
)
1183 if (binop_user_defined_p (op
, arg1
, arg2
))
1185 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1189 tem
= value_equal (arg1
, arg2
);
1190 return value_from_longest (builtin_type_int
, (LONGEST
) ! tem
);
1194 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1195 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1196 if (noside
== EVAL_SKIP
)
1198 if (binop_user_defined_p (op
, arg1
, arg2
))
1200 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1204 tem
= value_less (arg1
, arg2
);
1205 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1209 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1210 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1211 if (noside
== EVAL_SKIP
)
1213 if (binop_user_defined_p (op
, arg1
, arg2
))
1215 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1219 tem
= value_less (arg2
, arg1
);
1220 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1224 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1225 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1226 if (noside
== EVAL_SKIP
)
1228 if (binop_user_defined_p (op
, arg1
, arg2
))
1230 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1234 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1235 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1239 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1240 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1241 if (noside
== EVAL_SKIP
)
1243 if (binop_user_defined_p (op
, arg1
, arg2
))
1245 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1249 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1250 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1254 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1255 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1256 if (noside
== EVAL_SKIP
)
1258 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1259 error ("Non-integral right operand for \"@\" operator.");
1260 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1262 if (VALUE_REPEATED (arg1
))
1263 error ("Cannot create artificial arrays of artificial arrays.");
1264 return allocate_repeat_value (VALUE_TYPE (arg1
),
1265 longest_to_int (value_as_long (arg2
)));
1268 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1271 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1272 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1275 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1276 if (noside
== EVAL_SKIP
)
1278 if (unop_user_defined_p (op
, arg1
))
1279 return value_x_unop (arg1
, op
);
1281 return value_neg (arg1
);
1283 case UNOP_COMPLEMENT
:
1284 /* C++: check for and handle destructor names. */
1285 op
= exp
->elts
[*pos
].opcode
;
1287 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1288 if (noside
== EVAL_SKIP
)
1290 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1291 return value_x_unop (arg1
, UNOP_COMPLEMENT
);
1293 return value_complement (arg1
);
1295 case UNOP_LOGICAL_NOT
:
1296 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1297 if (noside
== EVAL_SKIP
)
1299 if (unop_user_defined_p (op
, arg1
))
1300 return value_x_unop (arg1
, op
);
1302 return value_from_longest (builtin_type_int
,
1303 (LONGEST
) value_logical_not (arg1
));
1306 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1307 expect_type
= TYPE_TARGET_TYPE (expect_type
);
1308 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1309 if (noside
== EVAL_SKIP
)
1311 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1313 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
1314 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_REF
1315 /* In C you can dereference an array to get the 1st elt. */
1316 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_ARRAY
1318 return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)),
1320 else if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_INT
)
1321 /* GDB allows dereferencing an int. */
1322 return value_zero (builtin_type_int
, lval_memory
);
1324 error ("Attempt to take contents of a non-pointer value.");
1326 return value_ind (arg1
);
1329 /* C++: check for and handle pointer to members. */
1331 op
= exp
->elts
[*pos
].opcode
;
1333 if (noside
== EVAL_SKIP
)
1337 int temm
= longest_to_int (exp
->elts
[pc
+3].longconst
);
1338 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1341 evaluate_subexp (expect_type
, exp
, pos
, EVAL_SKIP
);
1345 return evaluate_subexp_for_address (exp
, pos
, noside
);
1348 if (noside
== EVAL_SKIP
)
1350 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1353 return evaluate_subexp_for_sizeof (exp
, pos
);
1357 type
= exp
->elts
[pc
+ 1].type
;
1358 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1359 if (noside
== EVAL_SKIP
)
1361 if (type
!= VALUE_TYPE (arg1
))
1362 arg1
= value_cast (type
, arg1
);
1367 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1368 if (noside
== EVAL_SKIP
)
1370 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1371 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1373 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1374 value_as_pointer (arg1
));
1376 case UNOP_PREINCREMENT
:
1377 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1378 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1380 else if (unop_user_defined_p (op
, arg1
))
1382 return value_x_unop (arg1
, op
);
1386 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1388 return value_assign (arg1
, arg2
);
1391 case UNOP_PREDECREMENT
:
1392 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1393 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1395 else if (unop_user_defined_p (op
, arg1
))
1397 return value_x_unop (arg1
, op
);
1401 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1403 return value_assign (arg1
, arg2
);
1406 case UNOP_POSTINCREMENT
:
1407 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1408 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1410 else if (unop_user_defined_p (op
, arg1
))
1412 return value_x_unop (arg1
, op
);
1416 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1418 value_assign (arg1
, arg2
);
1422 case UNOP_POSTDECREMENT
:
1423 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1424 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1426 else if (unop_user_defined_p (op
, arg1
))
1428 return value_x_unop (arg1
, op
);
1432 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1434 value_assign (arg1
, arg2
);
1440 return value_of_this (1);
1443 error ("Attempt to use a type name as an expression");
1446 /* Removing this case and compiling with gcc -Wall reveals that
1447 a lot of cases are hitting this case. Some of these should
1448 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1449 and an OP_SCOPE?); others are legitimate expressions which are
1450 (apparently) not fully implemented.
1452 If there are any cases landing here which mean a user error,
1453 then they should be separate cases, with more descriptive
1457 GDB does not (yet) know how to evaluate that kind of expression");
1461 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1464 /* Evaluate a subexpression of EXP, at index *POS,
1465 and return the address of that subexpression.
1466 Advance *POS over the subexpression.
1467 If the subexpression isn't an lvalue, get an error.
1468 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1469 then only the type of the result need be correct. */
1472 evaluate_subexp_for_address (exp
, pos
, noside
)
1473 register struct expression
*exp
;
1482 op
= exp
->elts
[pc
].opcode
;
1488 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1492 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1493 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1496 var
= exp
->elts
[pc
+ 2].symbol
;
1498 /* C++: The "address" of a reference should yield the address
1499 * of the object pointed to. Let value_addr() deal with it. */
1500 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1504 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1507 lookup_pointer_type (SYMBOL_TYPE (var
));
1508 enum address_class sym_class
= SYMBOL_CLASS (var
);
1510 if (sym_class
== LOC_CONST
1511 || sym_class
== LOC_CONST_BYTES
1512 || sym_class
== LOC_REGISTER
1513 || sym_class
== LOC_REGPARM
)
1514 error ("Attempt to take address of register or constant.");
1517 value_zero (type
, not_lval
);
1523 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1527 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1529 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1530 if (VALUE_LVAL (x
) == lval_memory
)
1531 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1534 error ("Attempt to take address of non-lval");
1536 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1540 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1541 When used in contexts where arrays will be coerced anyway, this is
1542 equivalent to `evaluate_subexp' but much faster because it avoids
1543 actually fetching array contents (perhaps obsolete now that we have
1546 Note that we currently only do the coercion for C expressions, where
1547 arrays are zero based and the coercion is correct. For other languages,
1548 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1549 to decide if coercion is appropriate.
1554 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1555 register struct expression
*exp
;
1559 register enum exp_opcode op
;
1561 register value_ptr val
;
1565 op
= exp
->elts
[pc
].opcode
;
1570 var
= exp
->elts
[pc
+ 2].symbol
;
1571 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_ARRAY
1572 && CAST_IS_CONVERSION
)
1577 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1578 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1584 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1588 /* Evaluate a subexpression of EXP, at index *POS,
1589 and return a value for the size of that subexpression.
1590 Advance *POS over the subexpression. */
1593 evaluate_subexp_for_sizeof (exp
, pos
)
1594 register struct expression
*exp
;
1602 op
= exp
->elts
[pc
].opcode
;
1606 /* This case is handled specially
1607 so that we avoid creating a value for the result type.
1608 If the result type is very big, it's desirable not to
1609 create a value unnecessarily. */
1612 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1613 return value_from_longest (builtin_type_int
, (LONGEST
)
1614 TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val
))));
1618 return value_from_longest (builtin_type_int
,
1619 (LONGEST
) TYPE_LENGTH (exp
->elts
[pc
+ 1].type
));
1626 (LONGEST
) TYPE_LENGTH (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
)));
1629 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1630 return value_from_longest (builtin_type_int
,
1631 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1635 /* Parse a type expression in the string [P..P+LENGTH). */
1638 parse_and_eval_type (p
, length
)
1642 char *tmp
= (char *)alloca (length
+ 4);
1643 struct expression
*expr
;
1645 memcpy (tmp
+1, p
, length
);
1646 tmp
[length
+1] = ')';
1647 tmp
[length
+2] = '0';
1648 tmp
[length
+3] = '\0';
1649 expr
= parse_expression (tmp
);
1650 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1651 error ("Internal error in eval_type.");
1652 return expr
->elts
[1].type
;
1656 calc_f77_array_dims (array_type
)
1657 struct type
*array_type
;
1660 struct type
*tmp_type
;
1662 if ((TYPE_CODE(array_type
) != TYPE_CODE_ARRAY
))
1663 error ("Can't get dimensions for a non-array type");
1665 tmp_type
= array_type
;
1667 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1669 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)