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 */
32 /* start-sanitize-gm */
35 #endif /* GENERAL_MAGIC */
38 /* Prototypes for local functions. */
40 static value_ptr evaluate_subexp_for_sizeof
PARAMS ((struct expression
*,
43 static value_ptr evaluate_subexp_for_address
PARAMS ((struct expression
*,
50 evaluate_subexp (expect_type
, exp
, pos
, noside
)
51 struct type
*expect_type
;
52 register struct expression
*exp
;
56 return (*exp
->language_defn
->evaluate_exp
) (expect_type
, exp
, pos
, noside
);
59 /* Parse the string EXP as a C expression, evaluate it,
60 and return the result as a number. */
63 parse_and_eval_address (exp
)
66 struct expression
*expr
= parse_expression (exp
);
67 register CORE_ADDR addr
;
68 register struct cleanup
*old_chain
=
69 make_cleanup (free_current_contents
, &expr
);
71 addr
= value_as_pointer (evaluate_expression (expr
));
72 do_cleanups (old_chain
);
76 /* Like parse_and_eval_address but takes a pointer to a char * variable
77 and advanced that variable across the characters parsed. */
80 parse_and_eval_address_1 (expptr
)
83 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*)0, 0);
84 register CORE_ADDR addr
;
85 register struct cleanup
*old_chain
=
86 make_cleanup (free_current_contents
, &expr
);
88 addr
= value_as_pointer (evaluate_expression (expr
));
89 do_cleanups (old_chain
);
97 struct expression
*expr
= parse_expression (exp
);
98 register value_ptr val
;
99 register struct cleanup
*old_chain
100 = make_cleanup (free_current_contents
, &expr
);
102 val
= evaluate_expression (expr
);
103 do_cleanups (old_chain
);
107 /* Parse up to a comma (or to a closeparen)
108 in the string EXPP as an expression, evaluate it, and return the value.
109 EXPP is advanced to point to the comma. */
112 parse_to_comma_and_eval (expp
)
115 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
116 register value_ptr val
;
117 register struct cleanup
*old_chain
118 = make_cleanup (free_current_contents
, &expr
);
120 val
= evaluate_expression (expr
);
121 do_cleanups (old_chain
);
125 /* Evaluate an expression in internal prefix form
126 such as is constructed by parse.y.
128 See expression.h for info on the format of an expression. */
131 evaluate_expression (exp
)
132 struct expression
*exp
;
135 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
138 /* Evaluate an expression, avoiding all memory references
139 and getting a value whose type alone is correct. */
143 struct expression
*exp
;
146 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
149 /* If the next expression is an OP_LABELED, skips past it,
150 returning the label. Otherwise, does nothing and returns NULL. */
154 register struct expression
*exp
;
157 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
160 char *name
= &exp
->elts
[pc
+ 2].string
;
161 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
162 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
169 /* This function evaluates tupes (in Chill) or brace-initializers
170 (in C/C++) for structure types. */
173 evaluate_struct_tuple (struct_val
, exp
, pos
, noside
, nargs
)
174 value_ptr struct_val
;
175 register struct expression
*exp
;
180 struct type
*struct_type
= VALUE_TYPE (struct_val
);
181 struct type
*substruct_type
= struct_type
;
182 struct type
*field_type
;
189 value_ptr val
= NULL
;
194 /* Skip past the labels, and count them. */
195 while (get_label (exp
, pos
) != NULL
)
200 char *label
= get_label (exp
, &pc
);
203 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
206 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
207 if (field_name
!= NULL
&& STREQ (field_name
, label
))
210 subfieldno
= fieldno
;
211 substruct_type
= struct_type
;
215 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
);
218 char *field_name
= TYPE_FIELD_NAME (struct_type
, fieldno
);
219 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
220 if ((field_name
== 0 || *field_name
== '\0')
221 && TYPE_CODE (field_type
) == TYPE_CODE_UNION
)
224 for (; variantno
< TYPE_NFIELDS (field_type
);
228 = TYPE_FIELD_TYPE (field_type
, variantno
);
229 if (TYPE_CODE (substruct_type
) == TYPE_CODE_STRUCT
)
232 subfieldno
< TYPE_NFIELDS (substruct_type
);
235 if (STREQ (TYPE_FIELD_NAME (substruct_type
,
246 error ("there is no field named %s", label
);
252 /* Unlabelled tuple element - go to next field. */
256 if (subfieldno
>= TYPE_NFIELDS (substruct_type
))
259 substruct_type
= struct_type
;
265 subfieldno
= fieldno
;
266 if (fieldno
>= TYPE_NFIELDS (struct_type
))
267 error ("too many initializers");
268 field_type
= TYPE_FIELD_TYPE (struct_type
, fieldno
);
269 if (TYPE_CODE (field_type
) == TYPE_CODE_UNION
270 && TYPE_FIELD_NAME (struct_type
, fieldno
)[0] == '0')
271 error ("don't know which variant you want to set");
275 /* Here, struct_type is the type of the inner struct,
276 while substruct_type is the type of the inner struct.
277 These are the same for normal structures, but a variant struct
278 contains anonymous union fields that contain substruct fields.
279 The value fieldno is the index of the top-level (normal or
280 anonymous union) field in struct_field, while the value
281 subfieldno is the index of the actual real (named inner) field
282 in substruct_type. */
284 field_type
= TYPE_FIELD_TYPE (substruct_type
, subfieldno
);
286 val
= evaluate_subexp (substruct_type
, exp
, pos
, noside
);
288 /* Now actually set the field in struct_val. */
290 /* Assign val to field fieldno. */
291 if (VALUE_TYPE (val
) != field_type
)
292 val
= value_cast (field_type
, val
);
294 bitsize
= TYPE_FIELD_BITSIZE (substruct_type
, subfieldno
);
295 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
297 bitpos
+= TYPE_FIELD_BITPOS (substruct_type
, subfieldno
);
298 addr
= VALUE_CONTENTS (struct_val
) + bitpos
/ 8;
300 modify_field (addr
, value_as_long (val
),
301 bitpos
% 8, bitsize
);
303 memcpy (addr
, VALUE_CONTENTS (val
),
304 TYPE_LENGTH (VALUE_TYPE (val
)));
305 } while (--nlabels
> 0);
311 evaluate_subexp_standard (expect_type
, exp
, pos
, noside
)
312 struct type
*expect_type
;
313 register struct expression
*exp
;
319 register int pc
, pc2
= 0, oldpos
;
320 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
324 int upper
, lower
, retcode
;
327 /* This expect_type crap should not be used for C. C expressions do
328 not have any notion of expected types, never has and (goddess
329 willing) never will. The C++ code uses it for some twisted
330 purpose (I haven't investigated but I suspect it just the usual
331 combination of Stroustrup figuring out some crazy language
332 feature and Tiemann figuring out some crazier way to try to
333 implement it). CHILL has the tuple stuff; I don't know enough
334 about CHILL to know whether expected types is the way to do it.
335 FORTRAN I don't know. */
336 if (exp
->language_defn
->la_language
!= language_cplus
337 && exp
->language_defn
->la_language
!= language_chill
)
338 expect_type
= NULL_TYPE
;
341 op
= exp
->elts
[pc
].opcode
;
346 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
347 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
348 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
350 exp
->elts
[pc
+ 1].type
,
351 &exp
->elts
[pc
+ 3].string
,
354 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
359 return value_from_longest (exp
->elts
[pc
+ 1].type
,
360 exp
->elts
[pc
+ 2].longconst
);
364 return value_from_double (exp
->elts
[pc
+ 1].type
,
365 exp
->elts
[pc
+ 2].doubleconst
);
369 if (noside
== EVAL_SKIP
)
371 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
373 struct symbol
* sym
= exp
->elts
[pc
+ 2].symbol
;
376 switch (SYMBOL_CLASS (sym
))
380 case LOC_CONST_BYTES
:
394 return value_zero (SYMBOL_TYPE (sym
), lv
);
397 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
398 exp
->elts
[pc
+ 1].block
);
403 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
407 return value_of_register (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
411 if (current_language
->la_language
== language_fortran
)
412 return value_from_longest (builtin_type_f_logical_s2
,
413 exp
->elts
[pc
+ 1].longconst
);
415 return value_from_longest (builtin_type_chill_bool
,
416 exp
->elts
[pc
+ 1].longconst
);
420 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
423 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
424 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
425 if (noside
== EVAL_SKIP
)
427 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
430 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
432 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
433 if (noside
== EVAL_SKIP
)
435 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
440 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
441 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
442 nargs
= tem3
- tem2
+ 1;
444 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
445 && TYPE_CODE (expect_type
) == TYPE_CODE_STRUCT
)
447 value_ptr rec
= allocate_value (expect_type
);
448 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (expect_type
));
449 return evaluate_struct_tuple (rec
, exp
, pos
, noside
, nargs
);
452 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
453 && TYPE_CODE (expect_type
) == TYPE_CODE_ARRAY
)
455 struct type
*range_type
= TYPE_FIELD_TYPE (expect_type
, 0);
456 struct type
*element_type
= TYPE_TARGET_TYPE (expect_type
);
457 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
458 LONGEST high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
459 int element_size
= TYPE_LENGTH (element_type
);
460 value_ptr array
= allocate_value (expect_type
);
461 if (nargs
!= (high_bound
- low_bound
+ 1))
462 error ("wrong number of initialiers for array type");
463 for (tem
= low_bound
; tem
<= high_bound
; tem
++)
465 value_ptr element
= evaluate_subexp (element_type
,
467 if (VALUE_TYPE (element
) != element_type
)
468 element
= value_cast (element_type
, element
);
469 memcpy (VALUE_CONTENTS_RAW (array
)
470 + (tem
- low_bound
) * element_size
,
471 VALUE_CONTENTS (element
),
477 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
478 && TYPE_CODE (expect_type
) == TYPE_CODE_SET
)
480 value_ptr set
= allocate_value (expect_type
);
481 struct type
*element_type
= TYPE_INDEX_TYPE (expect_type
);
482 int low_bound
= TYPE_LOW_BOUND (element_type
);
483 int high_bound
= TYPE_HIGH_BOUND (element_type
);
484 char *valaddr
= VALUE_CONTENTS_RAW (set
);
485 memset (valaddr
, '\0', TYPE_LENGTH (expect_type
));
486 for (tem
= 0; tem
< nargs
; tem
++)
488 value_ptr element_val
= evaluate_subexp (element_type
,
490 LONGEST element
= value_as_long (element_val
);
492 if (element
< low_bound
|| element
> high_bound
)
493 error ("POWERSET tuple element out of range");
494 element
-= low_bound
;
495 bit_index
= (unsigned) element
% TARGET_CHAR_BIT
;
497 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
498 valaddr
[(unsigned) element
/ TARGET_CHAR_BIT
] |= 1 << bit_index
;
503 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
504 for (tem
= 0; tem
< nargs
; tem
++)
506 /* Ensure that array expressions are coerced into pointer objects. */
507 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
509 if (noside
== EVAL_SKIP
)
511 return value_array (tem2
, tem3
, argvec
);
515 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
517 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
519 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
520 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
523 case TERNOP_SLICE_COUNT
:
525 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
527 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
529 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
530 return value_slice (array
, lowbound
, length
);
534 /* Skip third and second args to evaluate the first one. */
535 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
536 if (value_logical_not (arg1
))
538 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
539 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
543 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
544 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
550 op
= exp
->elts
[*pos
].opcode
;
551 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
555 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
556 /* First, evaluate the structure into arg2 */
559 if (noside
== EVAL_SKIP
)
562 if (op
== STRUCTOP_MEMBER
)
564 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
568 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
571 /* If the function is a virtual function, then the
572 aggregate value (providing the structure) plays
573 its part by providing the vtable. Otherwise,
574 it is just along for the ride: call the function
577 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
579 fnptr
= value_as_long (arg1
);
581 if (METHOD_PTR_IS_VIRTUAL(fnptr
))
583 int fnoffset
= METHOD_PTR_TO_VOFFSET(fnptr
);
584 struct type
*basetype
;
585 struct type
*domain_type
=
586 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
588 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
589 if (domain_type
!= basetype
)
590 arg2
= value_cast(lookup_pointer_type (domain_type
), arg2
);
591 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
592 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
594 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
595 /* If one is virtual, then all are virtual. */
596 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
597 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
598 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
600 value_ptr temp
= value_ind (arg2
);
601 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
602 arg2
= value_addr (temp
);
607 error ("virtual function at index %d not found", fnoffset
);
611 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
615 /* Now, say which argument to start evaluating from */
618 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
620 /* Hair for method invocations */
623 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
624 /* First, evaluate the structure into arg2 */
626 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
627 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
628 if (noside
== EVAL_SKIP
)
631 if (op
== STRUCTOP_STRUCT
)
633 /* If v is a variable in a register, and the user types
634 v.method (), this will produce an error, because v has
637 A possible way around this would be to allocate a
638 copy of the variable on the stack, copy in the
639 contents, call the function, and copy out the
640 contents. I.e. convert this from call by reference
641 to call by copy-return (or whatever it's called).
642 However, this does not work because it is not the
643 same: the method being called could stash a copy of
644 the address, and then future uses through that address
645 (after the method returns) would be expected to
646 use the variable itself, not some copy of it. */
647 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
651 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
653 /* Now, say which argument to start evaluating from */
658 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
661 /* Allocate arg vector, including space for the function to be
662 called in argvec[0] and a terminating NULL */
663 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
664 for (; tem
<= nargs
; tem
++)
665 /* Ensure that array expressions are coerced into pointer objects. */
666 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
668 /* signal end of arglist */
671 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
674 value_ptr temp
= arg2
;
679 strcpy(tstr
, &exp
->elts
[pc2
+2].string
);
684 value_struct_elt (&temp
, argvec
+1, tstr
,
686 op
== STRUCTOP_STRUCT
687 ? "structure" : "structure pointer");
689 arg2
= value_from_longest (lookup_pointer_type(VALUE_TYPE (temp
)),
690 VALUE_ADDRESS (temp
)+VALUE_OFFSET (temp
));
695 argvec
[1] = argvec
[0];
700 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
708 if (noside
== EVAL_SKIP
)
710 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
712 /* If the return type doesn't look like a function type, call an
713 error. This can happen if somebody tries to turn a variable into
714 a function call. This is here because people often want to
715 call, eg, strcmp, which gdb doesn't know is a function. If
716 gdb isn't asked for it's opinion (ie. through "whatis"),
717 it won't offer it. */
720 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
723 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
725 error ("Expression of type other than \"Function returning ...\" used as function");
727 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
729 case OP_F77_UNDETERMINED_ARGLIST
:
731 /* Remember that in F77, functions, substring ops and
732 array subscript operations cannot be disambiguated
733 at parse time. We have made all array subscript operations,
734 substring operations as well as function calls come here
735 and we now have to discover what the heck this thing actually was.
736 If it is a function, we process just as if we got an OP_FUNCALL. */
738 nargs
= longest_to_int (exp
->elts
[pc
+1].longconst
);
741 /* First determine the type code we are dealing with. */
742 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
743 code
= TYPE_CODE (VALUE_TYPE (arg1
));
747 case TYPE_CODE_ARRAY
:
748 goto multi_f77_subscript
;
750 case TYPE_CODE_STRING
:
755 /* It's a function call. */
756 /* Allocate arg vector, including space for the function to be
757 called in argvec[0] and a terminating NULL */
758 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
761 for (; tem
<= nargs
; tem
++)
762 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
763 argvec
[tem
] = 0; /* signal end of arglist */
767 error ("Cannot perform substring on this type");
771 /* We have a substring operation on our hands here,
772 let us get the string we will be dealing with */
774 /* Now evaluate the 'from' and 'to' */
776 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
778 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
779 error ("Substring arguments must be of type integer");
782 return value_subscript (arg1
, arg2
);
784 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
786 if (TYPE_CODE (VALUE_TYPE (arg3
)) != TYPE_CODE_INT
)
787 error ("Substring arguments must be of type integer");
789 tem2
= *((int *) VALUE_CONTENTS_RAW (arg2
));
790 tem3
= *((int *) VALUE_CONTENTS_RAW (arg3
));
792 if ((tem2
< 1) || (tem2
> tem3
))
793 error ("Bad 'from' value %d on substring operation", tem2
);
795 if ((tem3
< tem2
) || (tem3
> (TYPE_LENGTH (VALUE_TYPE (arg1
)))))
796 error ("Bad 'to' value %d on substring operation", tem3
);
798 if (noside
== EVAL_SKIP
)
801 return value_slice (arg1
, tem2
, tem3
- tem2
+ 1);
804 /* We have a complex number, There should be 2 floating
805 point numbers that compose it */
806 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
807 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
809 return value_literal_complex (arg1
, arg2
, builtin_type_f_complex_s16
);
811 case STRUCTOP_STRUCT
:
812 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
813 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
814 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
815 if (noside
== EVAL_SKIP
)
817 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
818 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
819 &exp
->elts
[pc
+ 2].string
,
824 value_ptr temp
= arg1
;
825 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
830 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
831 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
832 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
833 if (noside
== EVAL_SKIP
)
835 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
836 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
837 &exp
->elts
[pc
+ 2].string
,
842 value_ptr temp
= arg1
;
843 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
844 NULL
, "structure pointer");
847 /* start-sanitize-gm */
850 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
851 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
852 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
853 if (noside
== EVAL_SKIP
)
856 CORE_ADDR object
= value_as_long (arg1
);
857 struct type
*type
= type_of_object (object
);
859 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
860 return value_zero (lookup_struct_elt_type (type
,
861 &exp
->elts
[pc
+ 2].string
,
866 value_ptr temp
= value_from_longest (builtin_type_unsigned_long
,
867 baseptr_of_object (value_as_long(arg1
)));
869 VALUE_TYPE (temp
) = type
;
870 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
871 NULL
, "structure pointer");
874 #endif /* GENERAL_MAGIC */
875 /* end-sanitize-gm */
877 case STRUCTOP_MEMBER
:
878 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
879 goto handle_pointer_to_member
;
881 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
882 handle_pointer_to_member
:
883 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
884 if (noside
== EVAL_SKIP
)
886 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_PTR
)
887 goto bad_pointer_to_member
;
888 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
889 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
890 error ("not implemented: pointer-to-method in pointer-to-member construct");
891 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
892 goto bad_pointer_to_member
;
893 /* Now, convert these values to an address. */
894 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
896 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
897 value_as_long (arg1
) + value_as_long (arg2
));
898 return value_ind (arg3
);
899 bad_pointer_to_member
:
900 error("non-pointer-to-member value used in pointer-to-member construct");
903 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
904 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
905 if (noside
== EVAL_SKIP
)
907 if (binop_user_defined_p (op
, arg1
, arg2
))
908 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
910 return value_concat (arg1
, arg2
);
913 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
914 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
915 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
917 if (binop_user_defined_p (op
, arg1
, arg2
))
918 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
920 return value_assign (arg1
, arg2
);
922 case BINOP_ASSIGN_MODIFY
:
924 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
925 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
926 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
928 op
= exp
->elts
[pc
+ 1].opcode
;
929 if (binop_user_defined_p (op
, arg1
, arg2
))
930 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
);
931 else if (op
== BINOP_ADD
)
932 arg2
= value_add (arg1
, arg2
);
933 else if (op
== BINOP_SUB
)
934 arg2
= value_sub (arg1
, arg2
);
936 arg2
= value_binop (arg1
, arg2
, op
);
937 return value_assign (arg1
, arg2
);
940 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
941 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
942 if (noside
== EVAL_SKIP
)
944 if (binop_user_defined_p (op
, arg1
, arg2
))
945 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
947 return value_add (arg1
, arg2
);
950 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
951 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
952 if (noside
== EVAL_SKIP
)
954 if (binop_user_defined_p (op
, arg1
, arg2
))
955 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
957 return value_sub (arg1
, arg2
);
965 case BINOP_BITWISE_AND
:
966 case BINOP_BITWISE_IOR
:
967 case BINOP_BITWISE_XOR
:
968 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
969 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
970 if (noside
== EVAL_SKIP
)
972 if (binop_user_defined_p (op
, arg1
, arg2
))
973 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
975 if (noside
== EVAL_AVOID_SIDE_EFFECTS
976 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
977 return value_zero (VALUE_TYPE (arg1
), not_lval
);
979 return value_binop (arg1
, arg2
, op
);
981 case BINOP_SUBSCRIPT
:
982 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
983 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
984 if (noside
== EVAL_SKIP
)
986 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
988 /* If the user attempts to subscript something that has no target
989 type (like a plain int variable for example), then report this
992 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
994 return value_zero (type
, VALUE_LVAL (arg1
));
996 error ("cannot subscript something of type `%s'",
997 TYPE_NAME (VALUE_TYPE (arg1
)));
1000 if (binop_user_defined_p (op
, arg1
, arg2
))
1001 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1003 return value_subscript (arg1
, arg2
);
1006 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1007 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1008 if (noside
== EVAL_SKIP
)
1010 return value_in (arg1
, arg2
);
1012 case MULTI_SUBSCRIPT
:
1014 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1015 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1018 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1019 /* FIXME: EVAL_SKIP handling may not be correct. */
1020 if (noside
== EVAL_SKIP
)
1031 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1032 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1034 /* If the user attempts to subscript something that has no target
1035 type (like a plain int variable for example), then report this
1038 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
1041 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1047 error ("cannot subscript something of type `%s'",
1048 TYPE_NAME (VALUE_TYPE (arg1
)));
1052 if (binop_user_defined_p (op
, arg1
, arg2
))
1054 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1058 arg1
= value_subscript (arg1
, arg2
);
1063 multi_f77_subscript
:
1065 int subscript_array
[MAX_FORTRAN_DIMS
+1]; /* 1-based array of
1066 subscripts, max == 7 */
1067 int array_size_array
[MAX_FORTRAN_DIMS
+1];
1068 int ndimensions
=1,i
;
1069 struct type
*tmp_type
;
1070 int offset_item
; /* The array offset where the item lives */
1072 if (nargs
> MAX_FORTRAN_DIMS
)
1073 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
1075 ndimensions
= calc_f77_array_dims (VALUE_TYPE (arg1
));
1077 if (nargs
!= ndimensions
)
1078 error ("Wrong number of subscripts");
1080 /* Now that we know we have a legal array subscript expression
1081 let us actually find out where this element exists in the array. */
1083 tmp_type
= VALUE_TYPE (arg1
);
1085 for (i
= 1; i
<= nargs
; i
++)
1087 /* Evaluate each subscript, It must be a legal integer in F77 */
1088 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1090 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1091 error ("Array subscripts must be of type integer");
1093 /* Fill in the subscript and array size arrays */
1095 subscript_array
[i
] = (* (unsigned int *) VALUE_CONTENTS(arg2
));
1097 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1098 if (retcode
== BOUND_FETCH_ERROR
)
1099 error ("Cannot obtain dynamic upper bound");
1101 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1102 if (retcode
== BOUND_FETCH_ERROR
)
1103 error("Cannot obtain dynamic lower bound");
1105 array_size_array
[i
] = upper
- lower
+ 1;
1107 /* Zero-normalize subscripts so that offsetting will work. */
1109 subscript_array
[i
] -= lower
;
1111 /* If we are at the bottom of a multidimensional
1112 array type then keep a ptr to the last ARRAY
1113 type around for use when calling value_subscript()
1114 below. This is done because we pretend to value_subscript
1115 that we actually have a one-dimensional array
1116 of base element type that we apply a simple
1120 tmp_type
= TYPE_TARGET_TYPE (tmp_type
);
1123 /* Now let us calculate the offset for this item */
1125 offset_item
= subscript_array
[ndimensions
];
1127 for (i
= ndimensions
- 1; i
>= 1; i
--)
1129 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1131 /* Construct a value node with the value of the offset */
1133 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1135 /* Let us now play a dirty trick: we will take arg1
1136 which is a value node pointing to the topmost level
1137 of the multidimensional array-set and pretend
1138 that it is actually a array of the final element
1139 type, this will ensure that value_subscript()
1140 returns the correct type value */
1142 VALUE_TYPE (arg1
) = tmp_type
;
1143 return value_ind (value_add (value_coerce_array (arg1
), arg2
));
1146 case BINOP_LOGICAL_AND
:
1147 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1148 if (noside
== EVAL_SKIP
)
1150 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1155 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1158 if (binop_user_defined_p (op
, arg1
, arg2
))
1160 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1161 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1165 tem
= value_logical_not (arg1
);
1166 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1167 (tem
? EVAL_SKIP
: noside
));
1168 return value_from_longest (builtin_type_int
,
1169 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1172 case BINOP_LOGICAL_OR
:
1173 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1174 if (noside
== EVAL_SKIP
)
1176 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1181 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1184 if (binop_user_defined_p (op
, arg1
, arg2
))
1186 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1187 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1191 tem
= value_logical_not (arg1
);
1192 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1193 (!tem
? EVAL_SKIP
: noside
));
1194 return value_from_longest (builtin_type_int
,
1195 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1199 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1200 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1201 if (noside
== EVAL_SKIP
)
1203 if (binop_user_defined_p (op
, arg1
, arg2
))
1205 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1209 tem
= value_equal (arg1
, arg2
);
1210 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1213 case BINOP_NOTEQUAL
:
1214 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1215 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1216 if (noside
== EVAL_SKIP
)
1218 if (binop_user_defined_p (op
, arg1
, arg2
))
1220 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1224 tem
= value_equal (arg1
, arg2
);
1225 return value_from_longest (builtin_type_int
, (LONGEST
) ! tem
);
1229 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1230 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1231 if (noside
== EVAL_SKIP
)
1233 if (binop_user_defined_p (op
, arg1
, arg2
))
1235 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1239 tem
= value_less (arg1
, arg2
);
1240 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1244 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1245 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1246 if (noside
== EVAL_SKIP
)
1248 if (binop_user_defined_p (op
, arg1
, arg2
))
1250 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1254 tem
= value_less (arg2
, arg1
);
1255 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1259 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1260 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1261 if (noside
== EVAL_SKIP
)
1263 if (binop_user_defined_p (op
, arg1
, arg2
))
1265 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1269 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1270 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1274 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1275 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1276 if (noside
== EVAL_SKIP
)
1278 if (binop_user_defined_p (op
, arg1
, arg2
))
1280 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1284 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1285 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1289 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1290 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1291 if (noside
== EVAL_SKIP
)
1293 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1294 error ("Non-integral right operand for \"@\" operator.");
1295 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1297 return allocate_repeat_value (VALUE_TYPE (arg1
),
1298 longest_to_int (value_as_long (arg2
)));
1301 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1304 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1305 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1308 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1309 if (noside
== EVAL_SKIP
)
1311 if (unop_user_defined_p (op
, arg1
))
1312 return value_x_unop (arg1
, op
);
1314 return value_neg (arg1
);
1316 case UNOP_COMPLEMENT
:
1317 /* C++: check for and handle destructor names. */
1318 op
= exp
->elts
[*pos
].opcode
;
1320 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1321 if (noside
== EVAL_SKIP
)
1323 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1324 return value_x_unop (arg1
, UNOP_COMPLEMENT
);
1326 return value_complement (arg1
);
1328 case UNOP_LOGICAL_NOT
:
1329 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1330 if (noside
== EVAL_SKIP
)
1332 if (unop_user_defined_p (op
, arg1
))
1333 return value_x_unop (arg1
, op
);
1335 return value_from_longest (builtin_type_int
,
1336 (LONGEST
) value_logical_not (arg1
));
1339 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1340 expect_type
= TYPE_TARGET_TYPE (expect_type
);
1341 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1342 if (noside
== EVAL_SKIP
)
1344 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1346 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
1347 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_REF
1348 /* In C you can dereference an array to get the 1st elt. */
1349 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_ARRAY
1351 return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)),
1353 else if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_INT
)
1354 /* GDB allows dereferencing an int. */
1355 return value_zero (builtin_type_int
, lval_memory
);
1357 error ("Attempt to take contents of a non-pointer value.");
1359 return value_ind (arg1
);
1362 /* C++: check for and handle pointer to members. */
1364 op
= exp
->elts
[*pos
].opcode
;
1366 if (noside
== EVAL_SKIP
)
1370 int temm
= longest_to_int (exp
->elts
[pc
+3].longconst
);
1371 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1374 evaluate_subexp (expect_type
, exp
, pos
, EVAL_SKIP
);
1378 return evaluate_subexp_for_address (exp
, pos
, noside
);
1381 if (noside
== EVAL_SKIP
)
1383 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1386 return evaluate_subexp_for_sizeof (exp
, pos
);
1390 type
= exp
->elts
[pc
+ 1].type
;
1391 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1392 if (noside
== EVAL_SKIP
)
1394 if (type
!= VALUE_TYPE (arg1
))
1395 arg1
= value_cast (type
, arg1
);
1400 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1401 if (noside
== EVAL_SKIP
)
1403 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1404 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1406 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1407 value_as_pointer (arg1
));
1409 case UNOP_PREINCREMENT
:
1410 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1411 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1413 else if (unop_user_defined_p (op
, arg1
))
1415 return value_x_unop (arg1
, op
);
1419 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1421 return value_assign (arg1
, arg2
);
1424 case UNOP_PREDECREMENT
:
1425 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1426 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1428 else if (unop_user_defined_p (op
, arg1
))
1430 return value_x_unop (arg1
, op
);
1434 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1436 return value_assign (arg1
, arg2
);
1439 case UNOP_POSTINCREMENT
:
1440 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1441 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1443 else if (unop_user_defined_p (op
, arg1
))
1445 return value_x_unop (arg1
, op
);
1449 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1451 value_assign (arg1
, arg2
);
1455 case UNOP_POSTDECREMENT
:
1456 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1457 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1459 else if (unop_user_defined_p (op
, arg1
))
1461 return value_x_unop (arg1
, op
);
1465 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1467 value_assign (arg1
, arg2
);
1473 return value_of_this (1);
1476 error ("Attempt to use a type name as an expression");
1479 /* Removing this case and compiling with gcc -Wall reveals that
1480 a lot of cases are hitting this case. Some of these should
1481 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1482 and an OP_SCOPE?); others are legitimate expressions which are
1483 (apparently) not fully implemented.
1485 If there are any cases landing here which mean a user error,
1486 then they should be separate cases, with more descriptive
1490 GDB does not (yet) know how to evaluate that kind of expression");
1494 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1497 /* Evaluate a subexpression of EXP, at index *POS,
1498 and return the address of that subexpression.
1499 Advance *POS over the subexpression.
1500 If the subexpression isn't an lvalue, get an error.
1501 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1502 then only the type of the result need be correct. */
1505 evaluate_subexp_for_address (exp
, pos
, noside
)
1506 register struct expression
*exp
;
1515 op
= exp
->elts
[pc
].opcode
;
1521 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1525 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1526 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1529 var
= exp
->elts
[pc
+ 2].symbol
;
1531 /* C++: The "address" of a reference should yield the address
1532 * of the object pointed to. Let value_addr() deal with it. */
1533 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1537 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1540 lookup_pointer_type (SYMBOL_TYPE (var
));
1541 enum address_class sym_class
= SYMBOL_CLASS (var
);
1543 if (sym_class
== LOC_CONST
1544 || sym_class
== LOC_CONST_BYTES
1545 || sym_class
== LOC_REGISTER
1546 || sym_class
== LOC_REGPARM
)
1547 error ("Attempt to take address of register or constant.");
1550 value_zero (type
, not_lval
);
1556 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1560 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1562 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1563 if (VALUE_LVAL (x
) == lval_memory
)
1564 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1567 error ("Attempt to take address of non-lval");
1569 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1573 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1574 When used in contexts where arrays will be coerced anyway, this is
1575 equivalent to `evaluate_subexp' but much faster because it avoids
1576 actually fetching array contents (perhaps obsolete now that we have
1579 Note that we currently only do the coercion for C expressions, where
1580 arrays are zero based and the coercion is correct. For other languages,
1581 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1582 to decide if coercion is appropriate.
1587 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1588 register struct expression
*exp
;
1592 register enum exp_opcode op
;
1594 register value_ptr val
;
1598 op
= exp
->elts
[pc
].opcode
;
1603 var
= exp
->elts
[pc
+ 2].symbol
;
1604 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_ARRAY
1605 && CAST_IS_CONVERSION
)
1610 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1611 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1617 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1621 /* Evaluate a subexpression of EXP, at index *POS,
1622 and return a value for the size of that subexpression.
1623 Advance *POS over the subexpression. */
1626 evaluate_subexp_for_sizeof (exp
, pos
)
1627 register struct expression
*exp
;
1635 op
= exp
->elts
[pc
].opcode
;
1639 /* This case is handled specially
1640 so that we avoid creating a value for the result type.
1641 If the result type is very big, it's desirable not to
1642 create a value unnecessarily. */
1645 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1646 return value_from_longest (builtin_type_int
, (LONGEST
)
1647 TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val
))));
1651 return value_from_longest (builtin_type_int
,
1652 (LONGEST
) TYPE_LENGTH (exp
->elts
[pc
+ 1].type
));
1659 (LONGEST
) TYPE_LENGTH (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
)));
1662 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1663 return value_from_longest (builtin_type_int
,
1664 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1668 /* Parse a type expression in the string [P..P+LENGTH). */
1671 parse_and_eval_type (p
, length
)
1675 char *tmp
= (char *)alloca (length
+ 4);
1676 struct expression
*expr
;
1678 memcpy (tmp
+1, p
, length
);
1679 tmp
[length
+1] = ')';
1680 tmp
[length
+2] = '0';
1681 tmp
[length
+3] = '\0';
1682 expr
= parse_expression (tmp
);
1683 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1684 error ("Internal error in eval_type.");
1685 return expr
->elts
[1].type
;
1689 calc_f77_array_dims (array_type
)
1690 struct type
*array_type
;
1693 struct type
*tmp_type
;
1695 if ((TYPE_CODE(array_type
) != TYPE_CODE_ARRAY
))
1696 error ("Can't get dimensions for a non-array type");
1698 tmp_type
= array_type
;
1700 while ((tmp_type
= TYPE_TARGET_TYPE (tmp_type
)))
1702 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)