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 /* Values of NOSIDE argument to eval_subexp. */
38 EVAL_SKIP
, /* Only effect is to increment pos. */
39 EVAL_AVOID_SIDE_EFFECTS
/* Don't modify any variables or
40 call any functions. The value
41 returned will have the correct
42 type, and will have an
43 approximately correct lvalue
44 type (inaccuracy: anything that is
45 listed as being in a register in
46 the function in which it was
47 declared will be lval_register). */
50 /* Prototypes for local functions. */
52 static value_ptr evaluate_subexp_for_sizeof
PARAMS ((struct expression
*,
55 static value_ptr evaluate_subexp_with_coercion
PARAMS ((struct expression
*,
58 static value_ptr evaluate_subexp_for_address
PARAMS ((struct expression
*,
61 static value_ptr evaluate_subexp
PARAMS ((struct type
*, struct expression
*,
65 /* Parse the string EXP as a C expression, evaluate it,
66 and return the result as a number. */
69 parse_and_eval_address (exp
)
72 struct expression
*expr
= parse_expression (exp
);
73 register CORE_ADDR addr
;
74 register struct cleanup
*old_chain
=
75 make_cleanup (free_current_contents
, &expr
);
77 addr
= value_as_pointer (evaluate_expression (expr
));
78 do_cleanups (old_chain
);
82 /* Like parse_and_eval_address but takes a pointer to a char * variable
83 and advanced that variable across the characters parsed. */
86 parse_and_eval_address_1 (expptr
)
89 struct expression
*expr
= parse_exp_1 (expptr
, (struct block
*)0, 0);
90 register CORE_ADDR addr
;
91 register struct cleanup
*old_chain
=
92 make_cleanup (free_current_contents
, &expr
);
94 addr
= value_as_pointer (evaluate_expression (expr
));
95 do_cleanups (old_chain
);
103 struct expression
*expr
= parse_expression (exp
);
104 register value_ptr val
;
105 register struct cleanup
*old_chain
106 = make_cleanup (free_current_contents
, &expr
);
108 val
= evaluate_expression (expr
);
109 do_cleanups (old_chain
);
113 /* Parse up to a comma (or to a closeparen)
114 in the string EXPP as an expression, evaluate it, and return the value.
115 EXPP is advanced to point to the comma. */
118 parse_to_comma_and_eval (expp
)
121 struct expression
*expr
= parse_exp_1 (expp
, (struct block
*) 0, 1);
122 register value_ptr val
;
123 register struct cleanup
*old_chain
124 = make_cleanup (free_current_contents
, &expr
);
126 val
= evaluate_expression (expr
);
127 do_cleanups (old_chain
);
131 /* Evaluate an expression in internal prefix form
132 such as is constructed by parse.y.
134 See expression.h for info on the format of an expression. */
137 evaluate_expression (exp
)
138 struct expression
*exp
;
141 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_NORMAL
);
144 /* Evaluate an expression, avoiding all memory references
145 and getting a value whose type alone is correct. */
149 struct expression
*exp
;
152 return evaluate_subexp (NULL_TYPE
, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
155 /* Helper function called by evaluate_subexp to initialize a field
156 a structure from a tuple in Chill. This is recursive, to handle
157 more than one field name labels.
159 STRUCT_VAL is the structure value we are constructing.
160 (*FIELDNOP) is the field to set, if there is no label.
161 It is set to the field following this one.
162 EXP, POS, and NOSIDE are as for evaluate_subexp.
164 This function does not handle variant records. FIXME */
167 evaluate_labeled_field_init (struct_val
, fieldnop
, exp
, pos
, noside
)
168 value_ptr struct_val
;
170 register struct expression
*exp
;
174 int fieldno
= *fieldnop
;
178 struct type
*struct_type
= VALUE_TYPE (struct_val
);
179 if (exp
->elts
[*pos
].opcode
== OP_LABELED
)
182 char *name
= &exp
->elts
[pc
+ 2].string
;
183 int tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
184 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
185 for (fieldno
= 0; ; fieldno
++)
187 if (fieldno
>= TYPE_NFIELDS (struct_type
))
188 error ("there is no field named %s", name
);
189 if (STREQ (TYPE_FIELD_NAME (struct_type
, fieldno
), name
))
193 val
= evaluate_labeled_field_init (struct_val
, fieldnop
,
198 fieldno
= (*fieldnop
)++;
199 if (fieldno
>= TYPE_NFIELDS (struct_type
))
200 error ("too many initializers");
201 val
= evaluate_subexp (TYPE_FIELD_TYPE (struct_type
, fieldno
),
205 /* Assign val to field fieldno. */
206 if (VALUE_TYPE (val
) != TYPE_FIELD_TYPE (struct_type
, fieldno
))
207 val
= value_cast (TYPE_FIELD_TYPE (struct_type
, fieldno
), val
);
209 bitsize
= TYPE_FIELD_BITSIZE (struct_type
, fieldno
);
210 bitpos
= TYPE_FIELD_BITPOS (struct_type
, fieldno
);
211 addr
= VALUE_CONTENTS (struct_val
);
214 modify_field (addr
, value_as_long (val
),
215 bitpos
% 8, bitsize
);
217 memcpy (addr
, VALUE_CONTENTS (val
),
218 TYPE_LENGTH (VALUE_TYPE (val
)));
220 value_assign (value_primitive_field (struct_val
, 0, fieldno
, struct_type
),
227 evaluate_subexp (expect_type
, exp
, pos
, noside
)
228 struct type
*expect_type
;
229 register struct expression
*exp
;
235 register int pc
, pc2
= 0, oldpos
;
236 register value_ptr arg1
= NULL
, arg2
= NULL
, arg3
;
240 int tmp_pos
, tmp1_pos
;
241 struct symbol
*tmp_symbol
;
242 int upper
, lower
, retcode
;
244 struct internalvar
*var
;
246 /* This expect_type crap should not be used for C. C expressions do
247 not have any notion of expected types, never has and (goddess
248 willing) never will. The C++ code uses it for some twisted
249 purpose (I haven't investigated but I suspect it just the usual
250 combination of Stroustrup figuring out some crazy language
251 feature and Tiemann figuring out some crazier way to try to
252 implement it). CHILL has the tuple stuff; I don't know enough
253 about CHILL to know whether expected types is the way to do it.
254 FORTRAN I don't know. */
255 if (exp
->language_defn
->la_language
!= language_cplus
256 && exp
->language_defn
->la_language
!= language_chill
)
257 expect_type
= NULL_TYPE
;
260 op
= exp
->elts
[pc
].opcode
;
265 tem
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
266 (*pos
) += 4 + BYTES_TO_EXP_ELEM (tem
+ 1);
267 arg1
= value_struct_elt_for_reference (exp
->elts
[pc
+ 1].type
,
269 exp
->elts
[pc
+ 1].type
,
270 &exp
->elts
[pc
+ 3].string
,
273 error ("There is no field named %s", &exp
->elts
[pc
+ 3].string
);
278 return value_from_longest (exp
->elts
[pc
+ 1].type
,
279 exp
->elts
[pc
+ 2].longconst
);
283 return value_from_double (exp
->elts
[pc
+ 1].type
,
284 exp
->elts
[pc
+ 2].doubleconst
);
288 if (noside
== EVAL_SKIP
)
290 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
292 struct symbol
* sym
= exp
->elts
[pc
+ 2].symbol
;
295 switch (SYMBOL_CLASS (sym
))
299 case LOC_CONST_BYTES
:
313 return value_zero (SYMBOL_TYPE (sym
), lv
);
316 return value_of_variable (exp
->elts
[pc
+ 2].symbol
,
317 exp
->elts
[pc
+ 1].block
);
322 access_value_history (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
326 return value_of_register (longest_to_int (exp
->elts
[pc
+ 1].longconst
));
330 if (current_language
->la_language
== language_fortran
)
331 return value_from_longest (builtin_type_f_logical_s2
,
332 exp
->elts
[pc
+ 1].longconst
);
334 return value_from_longest (builtin_type_chill_bool
,
335 exp
->elts
[pc
+ 1].longconst
);
339 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
342 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
343 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
344 if (noside
== EVAL_SKIP
)
346 return value_string (&exp
->elts
[pc
+ 2].string
, tem
);
349 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
351 += 3 + BYTES_TO_EXP_ELEM ((tem
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
);
352 if (noside
== EVAL_SKIP
)
354 return value_bitstring (&exp
->elts
[pc
+ 2].string
, tem
);
359 tem2
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
360 tem3
= longest_to_int (exp
->elts
[pc
+ 2].longconst
);
361 nargs
= tem3
- tem2
+ 1;
363 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
364 && TYPE_CODE (expect_type
) == TYPE_CODE_STRUCT
)
366 value_ptr rec
= allocate_value (expect_type
);
368 memset (VALUE_CONTENTS_RAW (rec
), '\0', TYPE_LENGTH (expect_type
));
369 for (tem
= 0; tem
< nargs
; tem
++)
370 evaluate_labeled_field_init (rec
, &fieldno
, exp
, pos
, noside
);
374 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
375 && TYPE_CODE (expect_type
) == TYPE_CODE_ARRAY
)
377 struct type
*range_type
= TYPE_FIELD_TYPE (expect_type
, 0);
378 struct type
*element_type
= TYPE_TARGET_TYPE (expect_type
);
379 LONGEST low_bound
= TYPE_FIELD_BITPOS (range_type
, 0);
380 LONGEST high_bound
= TYPE_FIELD_BITPOS (range_type
, 1);
381 int element_size
= TYPE_LENGTH (element_type
);
382 value_ptr array
= allocate_value (expect_type
);
383 if (nargs
!= (high_bound
- low_bound
+ 1))
384 error ("wrong number of initialiers for array type");
385 for (tem
= low_bound
; tem
<= high_bound
; tem
++)
387 value_ptr element
= evaluate_subexp (element_type
,
389 if (VALUE_TYPE (element
) != element_type
)
390 element
= value_cast (element_type
, element
);
391 memcpy (VALUE_CONTENTS_RAW (array
)
392 + (tem
- low_bound
) * element_size
,
393 VALUE_CONTENTS (element
),
399 if (expect_type
!= NULL_TYPE
&& noside
!= EVAL_SKIP
400 && TYPE_CODE (expect_type
) == TYPE_CODE_SET
)
402 value_ptr set
= allocate_value (expect_type
);
403 struct type
*element_type
= TYPE_INDEX_TYPE (expect_type
);
404 int low_bound
= TYPE_LOW_BOUND (element_type
);
405 int high_bound
= TYPE_HIGH_BOUND (element_type
);
406 char *valaddr
= VALUE_CONTENTS_RAW (set
);
407 memset (valaddr
, '\0', TYPE_LENGTH (expect_type
));
408 for (tem
= 0; tem
< nargs
; tem
++)
410 value_ptr element_val
= evaluate_subexp (element_type
,
412 LONGEST element
= value_as_long (element_val
);
414 if (element
< low_bound
|| element
> high_bound
)
415 error ("POWERSET tuple element out of range");
416 element
-= low_bound
;
417 bit_index
= (unsigned) element
% TARGET_CHAR_BIT
;
419 bit_index
= TARGET_CHAR_BIT
- 1 - bit_index
;
420 valaddr
[(unsigned) element
/ TARGET_CHAR_BIT
] |= 1 << bit_index
;
425 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * nargs
);
426 for (tem
= 0; tem
< nargs
; tem
++)
428 /* Ensure that array expressions are coerced into pointer objects. */
429 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
431 if (noside
== EVAL_SKIP
)
433 if (current_language
->la_language
== language_fortran
)
434 /* For F77, we need to do special things to literal strings */
435 return (f77_value_literal_string (tem2
, tem3
, argvec
));
436 return value_array (tem2
, tem3
, argvec
);
441 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
443 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
445 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
446 return value_slice (array
, lowbound
, upper
- lowbound
+ 1);
449 case TERNOP_SLICE_COUNT
:
451 value_ptr array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
453 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
455 = value_as_long (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
456 return value_slice (array
, lowbound
, length
);
460 /* Skip third and second args to evaluate the first one. */
461 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
462 if (value_logical_not (arg1
))
464 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
465 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
469 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
470 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
476 op
= exp
->elts
[*pos
].opcode
;
477 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
481 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
482 /* First, evaluate the structure into arg2 */
485 if (noside
== EVAL_SKIP
)
488 if (op
== STRUCTOP_MEMBER
)
490 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
494 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
497 /* If the function is a virtual function, then the
498 aggregate value (providing the structure) plays
499 its part by providing the vtable. Otherwise,
500 it is just along for the ride: call the function
503 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
505 fnptr
= value_as_long (arg1
);
507 if (METHOD_PTR_IS_VIRTUAL(fnptr
))
509 int fnoffset
= METHOD_PTR_TO_VOFFSET(fnptr
);
510 struct type
*basetype
;
511 struct type
*domain_type
=
512 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
514 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
515 if (domain_type
!= basetype
)
516 arg2
= value_cast(lookup_pointer_type (domain_type
), arg2
);
517 basetype
= TYPE_VPTR_BASETYPE (domain_type
);
518 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
520 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
521 /* If one is virtual, then all are virtual. */
522 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
523 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
524 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == fnoffset
)
526 value_ptr temp
= value_ind (arg2
);
527 arg1
= value_virtual_fn_field (&temp
, f
, j
, domain_type
, 0);
528 arg2
= value_addr (temp
);
533 error ("virtual function at index %d not found", fnoffset
);
537 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
541 /* Now, say which argument to start evaluating from */
544 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
546 /* Hair for method invocations */
549 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
550 /* First, evaluate the structure into arg2 */
552 tem2
= longest_to_int (exp
->elts
[pc2
+ 1].longconst
);
553 *pos
+= 3 + BYTES_TO_EXP_ELEM (tem2
+ 1);
554 if (noside
== EVAL_SKIP
)
557 if (op
== STRUCTOP_STRUCT
)
559 /* If v is a variable in a register, and the user types
560 v.method (), this will produce an error, because v has
563 A possible way around this would be to allocate a
564 copy of the variable on the stack, copy in the
565 contents, call the function, and copy out the
566 contents. I.e. convert this from call by reference
567 to call by copy-return (or whatever it's called).
568 However, this does not work because it is not the
569 same: the method being called could stash a copy of
570 the address, and then future uses through that address
571 (after the method returns) would be expected to
572 use the variable itself, not some copy of it. */
573 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
577 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
579 /* Now, say which argument to start evaluating from */
584 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
587 /* Allocate arg vector, including space for the function to be
588 called in argvec[0] and a terminating NULL */
589 argvec
= (value_ptr
*) alloca (sizeof (value_ptr
) * (nargs
+ 2));
590 for (; tem
<= nargs
; tem
++)
591 /* Ensure that array expressions are coerced into pointer objects. */
592 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
594 /* signal end of arglist */
597 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
600 value_ptr temp
= arg2
;
605 strcpy(tstr
, &exp
->elts
[pc2
+2].string
);
610 value_struct_elt (&temp
, argvec
+1, tstr
,
612 op
== STRUCTOP_STRUCT
613 ? "structure" : "structure pointer");
615 arg2
= value_from_longest (lookup_pointer_type(VALUE_TYPE (temp
)),
616 VALUE_ADDRESS (temp
)+VALUE_OFFSET (temp
));
621 argvec
[1] = argvec
[0];
626 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
632 if (noside
== EVAL_SKIP
)
634 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
636 /* If the return type doesn't look like a function type, call an
637 error. This can happen if somebody tries to turn a variable into
638 a function call. This is here because people often want to
639 call, eg, strcmp, which gdb doesn't know is a function. If
640 gdb isn't asked for it's opinion (ie. through "whatis"),
641 it won't offer it. */
644 TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0]));
647 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
649 error ("Expression of type other than \"Function returning ...\" used as function");
651 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
653 case OP_F77_UNDETERMINED_ARGLIST
:
655 tmp_pos
= pc
; /* Point to this instr */
657 /* Remember that in F77, functions, substring ops and
658 array subscript operations cannot be disambiguated
659 at parse time. We have made all array subscript operations,
660 substring operations as well as function calls come here
661 and we now have to discover what the heck this thing actually was.
662 If it is an array, we massage it into a form that the
663 MULTI_F77_SUBSCRIPT operator can deal with. If it is
664 a function, we process just as if we got an OP_FUNCALL and
665 for a subscring operation, we perform the appropriate
666 substring operation. */
668 /* First get the nargs and then jump all the way over the:
670 OP_UNDETERMINED_ARGLIST
672 OP_UNDETERMINED_ARGLIST
674 instruction sequence */
676 nargs
= longest_to_int (exp
->elts
[tmp_pos
+1].longconst
);
677 tmp_pos
+= 3; /* size(op_funcall) == 3 elts */
679 /* We will always have an OP_VAR_VALUE as the next opcode.
680 The data stored after the OP_VAR_VALUE is the a pointer
681 to the function/array/string symbol. We should now check and
682 make sure that the symbols is an array and not a function.
683 If it is an array type, we have hit a F77 subscript operation and
684 we have to do some magic. If it is not an array, we check
685 to see if we found a string here. If there is a string,
686 we recursively evaluate and let OP_f77_SUBSTR deal with
687 things. If there is no string, we know there is a function
688 call at hand and change OP_FUNCALL_OR_SUBSCRIPT -> OP_FUNCALL.
689 In all cases, we recursively evaluate. */
691 /* First determine the type code we are dealing with. */
693 switch (exp
->elts
[tmp_pos
].opcode
)
696 tmp_pos
+= 1; /* To get to the symbol ptr */
697 tmp_symbol
= exp
->elts
[tmp_pos
].symbol
;
698 code
= TYPE_CODE (SYMBOL_TYPE (tmp_symbol
));
703 var
= exp
->elts
[tmp_pos
].internalvar
;
704 code
= TYPE_CODE(VALUE_TYPE(var
->value
));
707 case OP_F77_UNDETERMINED_ARGLIST
:
708 /* Special case when you do stuff like print ARRAY(1,1)(3:4) */
710 arg2
= evaluate_subexp (NULL_TYPE
, exp
, &tmp1_pos
, noside
);
711 code
=TYPE_CODE (VALUE_TYPE (arg2
));
715 error ("Cannot perform substring on this type");
720 case TYPE_CODE_ARRAY
:
721 /* Transform this into what it really is: a MULTI_F77_SUBSCRIPT */
723 exp
->elts
[tmp_pos
].opcode
= MULTI_F77_SUBSCRIPT
;
724 exp
->elts
[tmp_pos
+2].opcode
= MULTI_F77_SUBSCRIPT
;
727 case TYPE_CODE_LITERAL_STRING
: /* When substring'ing internalvars */
728 case TYPE_CODE_STRING
:
730 exp
->elts
[tmp_pos
].opcode
= OP_F77_SUBSTR
;
731 exp
->elts
[tmp_pos
+2].opcode
= OP_F77_SUBSTR
;
736 /* This is just a regular OP_FUNCALL, transform it
737 and recursively evaluate */
738 tmp_pos
= pc
; /* Point to OP_FUNCALL_OR_SUBSCRIPT */
739 exp
->elts
[tmp_pos
].opcode
= OP_FUNCALL
;
740 exp
->elts
[tmp_pos
+2].opcode
= OP_FUNCALL
;
744 error ("Cannot perform substring on this type");
747 /* Pretend like you never saw this expression */
749 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
753 /* We have a substring operation on our hands here,
754 let us get the string we will be dealing with */
757 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
759 /* Now evaluate the 'from' and 'to' */
761 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
763 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
764 error ("Substring arguments must be of type integer");
766 arg3
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
768 if (TYPE_CODE (VALUE_TYPE (arg3
)) != TYPE_CODE_INT
)
769 error ("Substring arguments must be of type integer");
771 tem2
= *((int *) VALUE_CONTENTS_RAW (arg2
));
772 tem3
= *((int *) VALUE_CONTENTS_RAW (arg3
));
774 if ((tem2
< 1) || (tem2
> tem3
))
775 error ("Bad 'from' value %d on substring operation", tem2
);
777 if ((tem3
< tem2
) || (tem3
> (TYPE_LENGTH (VALUE_TYPE (arg1
)))))
778 error ("Bad 'to' value %d on substring operation", tem3
);
780 if (noside
== EVAL_SKIP
)
783 return f77_value_substring (arg1
, tem2
, tem3
);
785 case OP_F77_LITERAL_COMPLEX
:
786 /* We have a complex number, There should be 2 floating
787 point numbers that compose it */
788 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
789 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
791 /* Complex*16 is the default size to create */
792 return f77_value_literal_complex (arg1
, arg2
, 16);
794 case STRUCTOP_STRUCT
:
795 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
796 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
797 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
798 if (noside
== EVAL_SKIP
)
800 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
801 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
802 &exp
->elts
[pc
+ 2].string
,
807 value_ptr temp
= arg1
;
808 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
813 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
814 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
815 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
816 if (noside
== EVAL_SKIP
)
818 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
819 return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1
),
820 &exp
->elts
[pc
+ 2].string
,
825 value_ptr temp
= arg1
;
826 return value_struct_elt (&temp
, NULL
, &exp
->elts
[pc
+ 2].string
,
827 NULL
, "structure pointer");
830 case STRUCTOP_MEMBER
:
831 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
832 goto handle_pointer_to_member
;
834 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
835 handle_pointer_to_member
:
836 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
837 if (noside
== EVAL_SKIP
)
839 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_PTR
)
840 goto bad_pointer_to_member
;
841 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
842 if (TYPE_CODE (type
) == TYPE_CODE_METHOD
)
843 error ("not implemented: pointer-to-method in pointer-to-member construct");
844 if (TYPE_CODE (type
) != TYPE_CODE_MEMBER
)
845 goto bad_pointer_to_member
;
846 /* Now, convert these values to an address. */
847 arg1
= value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type
)),
849 arg3
= value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
850 value_as_long (arg1
) + value_as_long (arg2
));
851 return value_ind (arg3
);
852 bad_pointer_to_member
:
853 error("non-pointer-to-member value used in pointer-to-member construct");
856 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
857 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
858 if (noside
== EVAL_SKIP
)
860 if (binop_user_defined_p (op
, arg1
, arg2
))
861 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
863 return value_concat (arg1
, arg2
);
866 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
867 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
868 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
870 if (binop_user_defined_p (op
, arg1
, arg2
))
871 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
873 return value_assign (arg1
, arg2
);
875 case BINOP_ASSIGN_MODIFY
:
877 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
878 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
879 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
881 op
= exp
->elts
[pc
+ 1].opcode
;
882 if (binop_user_defined_p (op
, arg1
, arg2
))
883 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
);
884 else if (op
== BINOP_ADD
)
885 arg2
= value_add (arg1
, arg2
);
886 else if (op
== BINOP_SUB
)
887 arg2
= value_sub (arg1
, arg2
);
889 arg2
= value_binop (arg1
, arg2
, op
);
890 return value_assign (arg1
, arg2
);
893 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
894 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
895 if (noside
== EVAL_SKIP
)
897 if (binop_user_defined_p (op
, arg1
, arg2
))
898 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
900 return value_add (arg1
, arg2
);
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_sub (arg1
, arg2
);
918 case BINOP_BITWISE_AND
:
919 case BINOP_BITWISE_IOR
:
920 case BINOP_BITWISE_XOR
:
921 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
922 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
923 if (noside
== EVAL_SKIP
)
925 if (binop_user_defined_p (op
, arg1
, arg2
))
926 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
928 if (noside
== EVAL_AVOID_SIDE_EFFECTS
929 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
930 return value_zero (VALUE_TYPE (arg1
), not_lval
);
932 return value_binop (arg1
, arg2
, op
);
934 case BINOP_SUBSCRIPT
:
935 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
936 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
937 if (noside
== EVAL_SKIP
)
939 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
941 /* If the user attempts to subscript something that has no target
942 type (like a plain int variable for example), then report this
945 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
947 return value_zero (type
, VALUE_LVAL (arg1
));
949 error ("cannot subscript something of type `%s'",
950 TYPE_NAME (VALUE_TYPE (arg1
)));
953 if (binop_user_defined_p (op
, arg1
, arg2
))
954 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
956 return value_subscript (arg1
, arg2
);
959 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
960 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
961 if (noside
== EVAL_SKIP
)
963 return value_in (arg1
, arg2
);
965 case MULTI_SUBSCRIPT
:
967 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
968 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
971 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
972 /* FIXME: EVAL_SKIP handling may not be correct. */
973 if (noside
== EVAL_SKIP
)
984 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
985 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
987 /* If the user attempts to subscript something that has no target
988 type (like a plain int variable for example), then report this
991 type
= TYPE_TARGET_TYPE (VALUE_TYPE (arg1
));
994 arg1
= value_zero (type
, VALUE_LVAL (arg1
));
1000 error ("cannot subscript something of type `%s'",
1001 TYPE_NAME (VALUE_TYPE (arg1
)));
1005 if (binop_user_defined_p (op
, arg1
, arg2
)
1006 && ! chill_varying_type (VALUE_TYPE (arg1
)))
1008 arg1
= value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1012 arg1
= value_subscript (arg1
, arg2
);
1017 case MULTI_F77_SUBSCRIPT
:
1019 int subscript_array
[MAX_FORTRAN_DIMS
+1]; /* 1-based array of
1020 subscripts, max == 7 */
1021 int array_size_array
[MAX_FORTRAN_DIMS
+1];
1022 int ndimensions
=1,i
;
1023 struct type
*tmp_type
;
1024 int offset_item
; /* The array offset where the item lives */
1025 int fixed_subscript
;
1028 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
1030 if (nargs
> MAX_FORTRAN_DIMS
)
1031 error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS
);
1033 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1035 ndimensions
= calc_f77_array_dims (VALUE_TYPE (arg1
));
1037 if (nargs
!= ndimensions
)
1038 error ("Wrong number of subscripts");
1040 /* Now that we know we have a legal array subscript expression
1041 let us actually find out where this element exists in the array. */
1043 tmp_type
= VALUE_TYPE (arg1
);
1045 for (i
= 1; i
<= nargs
; i
++)
1047 /* Evaluate each subscript, It must be a legal integer in F77 */
1048 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
1050 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1051 error ("Array subscripts must be of type integer");
1053 /* Fill in the subscript and array size arrays */
1055 subscript_array
[i
] = (* (unsigned int *) VALUE_CONTENTS(arg2
));
1057 retcode
= f77_get_dynamic_upperbound (tmp_type
, &upper
);
1058 if (retcode
== BOUND_FETCH_ERROR
)
1059 error ("Cannot obtain dynamic upper bound");
1061 retcode
= f77_get_dynamic_lowerbound (tmp_type
, &lower
);
1062 if (retcode
== BOUND_FETCH_ERROR
)
1063 error("Cannot obtain dynamic lower bound");
1065 array_size_array
[i
] = upper
- lower
+ 1;
1067 /* Zero-normalize subscripts so that offsetting will work. */
1069 subscript_array
[i
] -= lower
;
1071 /* If we are at the bottom of a multidimensional
1072 array type then keep a ptr to the last ARRAY
1073 type around for use when calling value_subscript()
1074 below. This is done because we pretend to value_subscript
1075 that we actually have a one-dimensional array
1076 of base element type that we apply a simple
1080 tmp_type
= TYPE_TARGET_TYPE (tmp_type
);
1083 /* Now let us calculate the offset for this item */
1085 offset_item
= subscript_array
[ndimensions
];
1087 for (i
= ndimensions
- 1; i
>= 1; i
--)
1089 array_size_array
[i
] * offset_item
+ subscript_array
[i
];
1091 /* Construct a value node with the value of the offset */
1093 arg2
= value_from_longest (builtin_type_f_integer
, offset_item
);
1095 /* Let us now play a dirty trick: we will take arg1
1096 which is a value node pointing to the topmost level
1097 of the multidimensional array-set and pretend
1098 that it is actually a array of the final element
1099 type, this will ensure that value_subscript()
1100 returns the correct type value */
1102 VALUE_TYPE (arg1
) = tmp_type
;
1104 arg1
= value_subscript (arg1
, arg2
);
1108 case BINOP_LOGICAL_AND
:
1109 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1110 if (noside
== EVAL_SKIP
)
1112 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1117 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1120 if (binop_user_defined_p (op
, arg1
, arg2
))
1122 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1123 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1127 tem
= value_logical_not (arg1
);
1128 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1129 (tem
? EVAL_SKIP
: noside
));
1130 return value_from_longest (builtin_type_int
,
1131 (LONGEST
) (!tem
&& !value_logical_not (arg2
)));
1134 case BINOP_LOGICAL_OR
:
1135 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1136 if (noside
== EVAL_SKIP
)
1138 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1143 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1146 if (binop_user_defined_p (op
, arg1
, arg2
))
1148 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1149 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1153 tem
= value_logical_not (arg1
);
1154 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
,
1155 (!tem
? EVAL_SKIP
: noside
));
1156 return value_from_longest (builtin_type_int
,
1157 (LONGEST
) (!tem
|| !value_logical_not (arg2
)));
1161 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1162 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1163 if (noside
== EVAL_SKIP
)
1165 if (binop_user_defined_p (op
, arg1
, arg2
))
1167 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1171 tem
= value_equal (arg1
, arg2
);
1172 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1175 case BINOP_NOTEQUAL
:
1176 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1177 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1178 if (noside
== EVAL_SKIP
)
1180 if (binop_user_defined_p (op
, arg1
, arg2
))
1182 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1186 tem
= value_equal (arg1
, arg2
);
1187 return value_from_longest (builtin_type_int
, (LONGEST
) ! tem
);
1191 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1192 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1193 if (noside
== EVAL_SKIP
)
1195 if (binop_user_defined_p (op
, arg1
, arg2
))
1197 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1201 tem
= value_less (arg1
, arg2
);
1202 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1206 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1207 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1208 if (noside
== EVAL_SKIP
)
1210 if (binop_user_defined_p (op
, arg1
, arg2
))
1212 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1216 tem
= value_less (arg2
, arg1
);
1217 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1221 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1222 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1223 if (noside
== EVAL_SKIP
)
1225 if (binop_user_defined_p (op
, arg1
, arg2
))
1227 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1231 tem
= value_less (arg2
, arg1
) || value_equal (arg1
, arg2
);
1232 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1236 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1237 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
1238 if (noside
== EVAL_SKIP
)
1240 if (binop_user_defined_p (op
, arg1
, arg2
))
1242 return value_x_binop (arg1
, arg2
, op
, OP_NULL
);
1246 tem
= value_less (arg1
, arg2
) || value_equal (arg1
, arg2
);
1247 return value_from_longest (builtin_type_int
, (LONGEST
) tem
);
1251 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1252 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1253 if (noside
== EVAL_SKIP
)
1255 if (TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_INT
)
1256 error ("Non-integral right operand for \"@\" operator.");
1257 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1258 return allocate_repeat_value (VALUE_TYPE (arg1
),
1259 longest_to_int (value_as_long (arg2
)));
1261 return value_repeat (arg1
, longest_to_int (value_as_long (arg2
)));
1264 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1265 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1268 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1269 if (noside
== EVAL_SKIP
)
1271 if (unop_user_defined_p (op
, arg1
))
1272 return value_x_unop (arg1
, op
);
1274 return value_neg (arg1
);
1276 case UNOP_COMPLEMENT
:
1277 /* C++: check for and handle destructor names. */
1278 op
= exp
->elts
[*pos
].opcode
;
1280 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1281 if (noside
== EVAL_SKIP
)
1283 if (unop_user_defined_p (UNOP_COMPLEMENT
, arg1
))
1284 return value_x_unop (arg1
, UNOP_COMPLEMENT
);
1286 return value_complement (arg1
);
1288 case UNOP_LOGICAL_NOT
:
1289 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1290 if (noside
== EVAL_SKIP
)
1292 if (unop_user_defined_p (op
, arg1
))
1293 return value_x_unop (arg1
, op
);
1295 return value_from_longest (builtin_type_int
,
1296 (LONGEST
) value_logical_not (arg1
));
1299 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
1300 expect_type
= TYPE_TARGET_TYPE (expect_type
);
1301 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1302 if (noside
== EVAL_SKIP
)
1304 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1306 if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_PTR
1307 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_REF
1308 /* In C you can dereference an array to get the 1st elt. */
1309 || TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_ARRAY
1311 return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)),
1313 else if (TYPE_CODE (VALUE_TYPE (arg1
)) == TYPE_CODE_INT
)
1314 /* GDB allows dereferencing an int. */
1315 return value_zero (builtin_type_int
, lval_memory
);
1317 error ("Attempt to take contents of a non-pointer value.");
1319 return value_ind (arg1
);
1322 /* C++: check for and handle pointer to members. */
1324 op
= exp
->elts
[*pos
].opcode
;
1326 if (noside
== EVAL_SKIP
)
1330 int temm
= longest_to_int (exp
->elts
[pc
+3].longconst
);
1331 (*pos
) += 3 + BYTES_TO_EXP_ELEM (temm
+ 1);
1334 evaluate_subexp (expect_type
, exp
, pos
, EVAL_SKIP
);
1338 return evaluate_subexp_for_address (exp
, pos
, noside
);
1341 if (noside
== EVAL_SKIP
)
1343 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
1346 return evaluate_subexp_for_sizeof (exp
, pos
);
1350 type
= exp
->elts
[pc
+ 1].type
;
1351 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
1352 if (noside
== EVAL_SKIP
)
1354 if (type
!= VALUE_TYPE (arg1
))
1355 arg1
= value_cast (type
, arg1
);
1360 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1361 if (noside
== EVAL_SKIP
)
1363 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1364 return value_zero (exp
->elts
[pc
+ 1].type
, lval_memory
);
1366 return value_at_lazy (exp
->elts
[pc
+ 1].type
,
1367 value_as_pointer (arg1
));
1369 case UNOP_PREINCREMENT
:
1370 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1371 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1373 else if (unop_user_defined_p (op
, arg1
))
1375 return value_x_unop (arg1
, op
);
1379 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1381 return value_assign (arg1
, arg2
);
1384 case UNOP_PREDECREMENT
:
1385 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1386 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1388 else if (unop_user_defined_p (op
, arg1
))
1390 return value_x_unop (arg1
, op
);
1394 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1396 return value_assign (arg1
, arg2
);
1399 case UNOP_POSTINCREMENT
:
1400 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1401 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1403 else if (unop_user_defined_p (op
, arg1
))
1405 return value_x_unop (arg1
, op
);
1409 arg2
= value_add (arg1
, value_from_longest (builtin_type_char
,
1411 value_assign (arg1
, arg2
);
1415 case UNOP_POSTDECREMENT
:
1416 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
1417 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
1419 else if (unop_user_defined_p (op
, arg1
))
1421 return value_x_unop (arg1
, op
);
1425 arg2
= value_sub (arg1
, value_from_longest (builtin_type_char
,
1427 value_assign (arg1
, arg2
);
1433 return value_of_this (1);
1436 error ("Attempt to use a type name as an expression");
1439 /* Removing this case and compiling with gcc -Wall reveals that
1440 a lot of cases are hitting this case. Some of these should
1441 probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
1442 and an OP_SCOPE?); others are legitimate expressions which are
1443 (apparently) not fully implemented.
1445 If there are any cases landing here which mean a user error,
1446 then they should be separate cases, with more descriptive
1450 GDB does not (yet) know how to evaluate that kind of expression");
1454 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
1457 /* Evaluate a subexpression of EXP, at index *POS,
1458 and return the address of that subexpression.
1459 Advance *POS over the subexpression.
1460 If the subexpression isn't an lvalue, get an error.
1461 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
1462 then only the type of the result need be correct. */
1465 evaluate_subexp_for_address (exp
, pos
, noside
)
1466 register struct expression
*exp
;
1475 op
= exp
->elts
[pc
].opcode
;
1481 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1485 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
1486 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1489 var
= exp
->elts
[pc
+ 2].symbol
;
1491 /* C++: The "address" of a reference should yield the address
1492 * of the object pointed to. Let value_addr() deal with it. */
1493 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_REF
)
1497 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1500 lookup_pointer_type (SYMBOL_TYPE (var
));
1501 enum address_class sym_class
= SYMBOL_CLASS (var
);
1503 if (sym_class
== LOC_CONST
1504 || sym_class
== LOC_CONST_BYTES
1505 || sym_class
== LOC_REGISTER
1506 || sym_class
== LOC_REGPARM
)
1507 error ("Attempt to take address of register or constant.");
1510 value_zero (type
, not_lval
);
1516 block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1520 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
1522 value_ptr x
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1523 if (VALUE_LVAL (x
) == lval_memory
)
1524 return value_zero (lookup_pointer_type (VALUE_TYPE (x
)),
1527 error ("Attempt to take address of non-lval");
1529 return value_addr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
1533 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
1534 When used in contexts where arrays will be coerced anyway, this is
1535 equivalent to `evaluate_subexp' but much faster because it avoids
1536 actually fetching array contents (perhaps obsolete now that we have
1539 Note that we currently only do the coercion for C expressions, where
1540 arrays are zero based and the coercion is correct. For other languages,
1541 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
1542 to decide if coercion is appropriate.
1547 evaluate_subexp_with_coercion (exp
, pos
, noside
)
1548 register struct expression
*exp
;
1552 register enum exp_opcode op
;
1554 register value_ptr val
;
1558 op
= exp
->elts
[pc
].opcode
;
1563 var
= exp
->elts
[pc
+ 2].symbol
;
1564 if (TYPE_CODE (SYMBOL_TYPE (var
)) == TYPE_CODE_ARRAY
1565 && CAST_IS_CONVERSION
)
1570 (var
, block_innermost_frame (exp
->elts
[pc
+ 1].block
));
1571 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var
))),
1577 return evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
1581 /* Evaluate a subexpression of EXP, at index *POS,
1582 and return a value for the size of that subexpression.
1583 Advance *POS over the subexpression. */
1586 evaluate_subexp_for_sizeof (exp
, pos
)
1587 register struct expression
*exp
;
1595 op
= exp
->elts
[pc
].opcode
;
1599 /* This case is handled specially
1600 so that we avoid creating a value for the result type.
1601 If the result type is very big, it's desirable not to
1602 create a value unnecessarily. */
1605 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1606 return value_from_longest (builtin_type_int
, (LONGEST
)
1607 TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val
))));
1611 return value_from_longest (builtin_type_int
,
1612 (LONGEST
) TYPE_LENGTH (exp
->elts
[pc
+ 1].type
));
1619 (LONGEST
) TYPE_LENGTH (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
)));
1622 val
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
1623 return value_from_longest (builtin_type_int
,
1624 (LONGEST
) TYPE_LENGTH (VALUE_TYPE (val
)));
1628 /* Parse a type expression in the string [P..P+LENGTH). */
1631 parse_and_eval_type (p
, length
)
1635 char *tmp
= (char *)alloca (length
+ 4);
1636 struct expression
*expr
;
1638 memcpy (tmp
+1, p
, length
);
1639 tmp
[length
+1] = ')';
1640 tmp
[length
+2] = '0';
1641 tmp
[length
+3] = '\0';
1642 expr
= parse_expression (tmp
);
1643 if (expr
->elts
[0].opcode
!= UNOP_CAST
)
1644 error ("Internal error in eval_type.");
1645 return expr
->elts
[1].type
;
1649 calc_f77_array_dims (array_type
)
1650 struct type
*array_type
;
1653 struct type
*tmp_type
;
1655 if ((TYPE_CODE(array_type
) != TYPE_CODE_ARRAY
))
1656 error ("Can't get dimensions for a non-array type");
1658 tmp_type
= array_type
;
1660 while (tmp_type
= TYPE_TARGET_TYPE (tmp_type
))
1662 if (TYPE_CODE (tmp_type
) == TYPE_CODE_ARRAY
)