5dcd9936c4e84d9174b8218a3d24ff5ee032d240
1 /* Evaluate expressions for GDB.
2 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
22 #include "initialize.h"
25 #include "expression.h"
29 /* Parse the string EXP as a C expression, evaluate it,
30 and return the result as a number. */
33 parse_and_eval_address (exp
)
36 struct expression
*expr
= parse_c_expression (exp
);
37 register CORE_ADDR addr
;
38 register struct cleanup
*old_chain
39 = make_cleanup (free_current_contents
, &expr
);
41 addr
= value_as_long (evaluate_expression (expr
));
42 do_cleanups (old_chain
);
46 /* Like parse_and_eval_address but takes a pointer to a char * variable
47 and advanced that variable across the characters parsed. */
50 parse_and_eval_address_1 (expptr
)
53 struct expression
*expr
= parse_c_1 (expptr
, 0, 0);
54 register CORE_ADDR addr
;
55 register struct cleanup
*old_chain
56 = make_cleanup (free_current_contents
, &expr
);
58 addr
= value_as_long (evaluate_expression (expr
));
59 do_cleanups (old_chain
);
67 struct expression
*expr
= parse_c_expression (exp
);
69 register struct cleanup
*old_chain
70 = make_cleanup (free_current_contents
, &expr
);
72 val
= evaluate_expression (expr
);
73 do_cleanups (old_chain
);
77 /* Parse up to a comma (or to a closeparen)
78 in the string EXPP as an expression, evaluate it, and return the value.
79 EXPP is advanced to point to the comma. */
82 parse_to_comma_and_eval (expp
)
85 struct expression
*expr
= parse_c_1 (expp
, 0, 1);
87 register struct cleanup
*old_chain
88 = make_cleanup (free_current_contents
, &expr
);
90 val
= evaluate_expression (expr
);
91 do_cleanups (old_chain
);
95 /* Evaluate an expression in internal prefix form
96 such as is constructed by expread.y.
98 See expression.h for info on the format of an expression. */
100 static value
evaluate_subexp ();
101 static value
evaluate_subexp_for_address ();
102 static value
evaluate_subexp_for_sizeof ();
103 static value
evaluate_subexp_with_coercion ();
105 /* Values of NOSIDE argument to eval_subexp. */
109 EVAL_AVOID_SIDE_EFFECTS
,
113 evaluate_expression (exp
)
114 struct expression
*exp
;
117 return evaluate_subexp (0, exp
, &pc
, EVAL_NORMAL
);
120 /* Evaluate an expression, avoiding all memory references
121 and getting a value whose type alone is correct. */
125 struct expression
*exp
;
128 return evaluate_subexp (0, exp
, &pc
, EVAL_AVOID_SIDE_EFFECTS
);
132 evaluate_subexp (expect_type
, exp
, pos
, noside
)
133 struct type
*expect_type
;
134 register struct expression
*exp
;
140 register int pc
, pc2
, *oldpos
;
141 register value arg1
, arg2
, arg3
;
146 op
= exp
->elts
[pc
].opcode
;
151 tem
= strlen (&exp
->elts
[pc
+ 2].string
);
152 (*pos
) += 3 + (tem
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
153 return value_static_field (exp
->elts
[pc
+ 1].type
,
154 &exp
->elts
[pc
+ 2].string
, -1);
158 return value_from_long (exp
->elts
[pc
+ 1].type
,
159 exp
->elts
[pc
+ 2].longconst
);
163 return value_from_double (exp
->elts
[pc
+ 1].type
,
164 exp
->elts
[pc
+ 2].doubleconst
);
168 if (noside
== EVAL_SKIP
)
170 return value_of_variable (exp
->elts
[pc
+ 1].symbol
);
174 return access_value_history (exp
->elts
[pc
+ 1].longconst
);
178 return value_of_register (exp
->elts
[pc
+ 1].longconst
);
182 return value_of_internalvar (exp
->elts
[pc
+ 1].internalvar
);
186 op
= exp
->elts
[*pos
].opcode
;
187 if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
192 nargs
= exp
->elts
[pc
+ 1].longconst
+ 1;
193 /* First, evaluate the structure into arg2 */
196 if (noside
== EVAL_SKIP
)
199 if (op
== STRUCTOP_MEMBER
)
201 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
205 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
208 /* If the function is a virtual function, then the
209 aggregate value (providing the structure) plays
210 its part by providing the vtable. Otherwise,
211 it is just along for the ride: call the function
214 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
216 fnptr
= value_as_long (arg1
);
219 struct type
*basetype
;
221 basetype
= TYPE_TARGET_TYPE (VALUE_TYPE (arg2
));
222 basetype
= TYPE_VPTR_BASETYPE (basetype
);
223 for (i
= TYPE_NFN_FIELDS (basetype
) - 1; i
>= 0; i
--)
225 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (basetype
, i
);
226 /* If one is virtual, then all are virtual. */
227 if (TYPE_FN_FIELD_VIRTUAL_P (f
, 0))
228 for (j
= TYPE_FN_FIELDLIST_LENGTH (basetype
, i
) - 1; j
>= 0; --j
)
229 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == fnptr
)
232 value base
= value_ind (arg2
);
233 struct type
*fntype
= lookup_pointer_type (TYPE_FN_FIELD_TYPE (f
, j
));
235 if (TYPE_VPTR_FIELDNO (basetype
) < 0)
236 TYPE_VPTR_FIELDNO (basetype
)
237 = fill_in_vptr_fieldno (basetype
);
239 VALUE_TYPE (base
) = basetype
;
240 vtbl
= value_field (base
, TYPE_VPTR_FIELDNO (basetype
));
241 VALUE_TYPE (vtbl
) = lookup_pointer_type (fntype
);
242 VALUE_TYPE (arg1
) = builtin_type_int
;
243 arg1
= value_subscript (vtbl
, arg1
);
244 VALUE_TYPE (arg1
) = fntype
;
249 error ("virtual function at index %d not found", fnptr
);
253 VALUE_TYPE (arg1
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1
)));
257 /* Now, say which argument to start evaluating from */
260 else if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
262 /* Hair for method invocations */
265 nargs
= exp
->elts
[pc
+ 1].longconst
+ 1;
266 /* First, evaluate the structure into arg2 */
268 tem2
= strlen (&exp
->elts
[pc2
+ 1].string
);
269 *pos
+= 2 + (tem2
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
270 if (noside
== EVAL_SKIP
)
273 if (op
== STRUCTOP_STRUCT
)
275 arg2
= evaluate_subexp_for_address (exp
, pos
, noside
);
279 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
281 /* Now, say which argument to start evaluating from */
286 nargs
= exp
->elts
[pc
+ 1].longconst
;
289 argvec
= (value
*) alloca (sizeof (value
) * (nargs
+ 2));
290 for (; tem
<= nargs
; tem
++)
291 /* Ensure that array expressions are coerced into pointer objects. */
292 argvec
[tem
] = evaluate_subexp_with_coercion (exp
, pos
, noside
);
294 /* signal end of arglist */
297 if (op
== STRUCTOP_STRUCT
|| op
== STRUCTOP_PTR
)
301 value_struct_elt (arg2
, argvec
+1, &exp
->elts
[pc2
+ 1].string
,
302 op
== STRUCTOP_STRUCT
303 ? "structure" : "structure pointer");
305 else if (op
== STRUCTOP_MEMBER
|| op
== STRUCTOP_MPTR
)
311 if (noside
== EVAL_SKIP
)
313 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
314 return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec
[0])));
315 return call_function (argvec
[0], nargs
, argvec
+ 1);
318 tem
= strlen (&exp
->elts
[pc
+ 1].string
);
319 (*pos
) += 2 + (tem
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
320 if (noside
== EVAL_SKIP
)
322 return value_string (&exp
->elts
[pc
+ 1].string
, tem
);
325 /* Skip third and second args to evaluate the first one. */
326 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
327 if (value_zerop (arg1
))
329 evaluate_subexp (0, exp
, pos
, EVAL_SKIP
);
330 return evaluate_subexp (0, exp
, pos
, noside
);
334 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
335 evaluate_subexp (0, exp
, pos
, EVAL_SKIP
);
339 case STRUCTOP_STRUCT
:
340 tem
= strlen (&exp
->elts
[pc
+ 1].string
);
341 (*pos
) += 2 + (tem
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
342 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
343 if (noside
== EVAL_SKIP
)
345 return value_struct_elt (arg1
, 0, &exp
->elts
[pc
+ 1].string
,
349 tem
= strlen (&exp
->elts
[pc
+ 1].string
);
350 (*pos
) += 2 + (tem
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
351 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
352 if (noside
== EVAL_SKIP
)
354 return value_struct_elt (arg1
, 0, &exp
->elts
[pc
+ 1].string
,
355 "structure pointer");
357 case STRUCTOP_MEMBER
:
358 arg1
= evaluate_subexp_for_address (exp
, pos
, noside
);
359 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
360 if (noside
== EVAL_SKIP
)
362 /* Now, convert these values to an address. */
363 arg3
= value_from_long (builtin_type_long
,
364 value_as_long (arg1
) + value_as_long (arg2
));
365 VALUE_TYPE (arg3
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
)));
366 return value_ind (arg3
);
369 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
370 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
371 if (noside
== EVAL_SKIP
)
373 /* Now, convert these values to an address. */
374 arg3
= value_from_long (builtin_type_long
,
375 value_as_long (arg1
) + value_as_long (arg2
));
376 VALUE_TYPE (arg3
) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg2
)));
377 return value_ind (arg3
);
380 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
381 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
382 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
384 if (binop_user_defined_p (op
, arg1
, arg2
))
385 return value_x_binop (arg1
, arg2
, op
, 0);
387 return value_assign (arg1
, arg2
);
389 case BINOP_ASSIGN_MODIFY
:
391 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
392 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
393 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
395 op
= exp
->elts
[pc
+ 1].opcode
;
396 if (binop_user_defined_p (op
, arg1
, arg2
))
397 return value_x_binop (arg1
, arg2
, BINOP_ASSIGN_MODIFY
, op
);
398 else if (op
== BINOP_ADD
)
399 arg2
= value_add (arg1
, arg2
);
400 else if (op
== BINOP_SUB
)
401 arg2
= value_sub (arg1
, arg2
);
403 arg2
= value_binop (arg1
, arg2
, op
);
404 return value_assign (arg1
, arg2
);
407 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
408 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
409 if (noside
== EVAL_SKIP
)
411 if (binop_user_defined_p (op
, arg1
, arg2
))
412 return value_x_binop (arg1
, arg2
, op
, 0);
414 return value_add (arg1
, arg2
);
417 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
418 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
419 if (noside
== EVAL_SKIP
)
421 if (binop_user_defined_p (op
, arg1
, arg2
))
422 return value_x_binop (arg1
, arg2
, op
, 0);
424 return value_sub (arg1
, arg2
);
434 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
435 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
436 if (noside
== EVAL_SKIP
)
438 if (binop_user_defined_p (op
, arg1
, arg2
))
439 return value_x_binop (arg1
, arg2
, op
, 0);
441 return value_binop (arg1
, arg2
, op
);
443 case BINOP_SUBSCRIPT
:
444 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
445 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
446 if (noside
== EVAL_SKIP
)
448 if (binop_user_defined_p (op
, arg1
, arg2
))
449 return value_x_binop (arg1
, arg2
, op
, 0);
451 return value_subscript (arg1
, arg2
, op
);
454 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
455 if (binop_user_defined_p (op
, arg1
, arg2
))
457 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
458 return value_x_binop (arg1
, arg2
, op
, 0);
462 tem
= value_zerop (arg1
);
463 arg2
= evaluate_subexp (0, exp
, pos
,
464 (tem
? EVAL_SKIP
: noside
));
465 return value_from_long (builtin_type_int
,
466 !tem
&& !value_zerop (arg2
));
470 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
471 if (binop_user_defined_p (op
, arg1
, arg2
))
473 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
474 return value_x_binop (arg1
, arg2
, op
, 0);
478 tem
= value_zerop (arg1
);
479 arg2
= evaluate_subexp (0, exp
, pos
,
480 (!tem
? EVAL_SKIP
: noside
));
481 return value_from_long (builtin_type_int
,
482 !tem
|| !value_zerop (arg2
));
486 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
487 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
488 if (noside
== EVAL_SKIP
)
490 if (binop_user_defined_p (op
, arg1
, arg2
))
492 return value_x_binop (arg1
, arg2
, op
, 0);
496 tem
= value_equal (arg1
, arg2
);
497 return value_from_long (builtin_type_int
, tem
);
501 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
502 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
503 if (noside
== EVAL_SKIP
)
505 if (binop_user_defined_p (op
, arg1
, arg2
))
507 return value_x_binop (arg1
, arg2
, op
, 0);
511 tem
= value_equal (arg1
, arg2
);
512 return value_from_long (builtin_type_int
, ! tem
);
516 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
517 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
518 if (noside
== EVAL_SKIP
)
520 if (binop_user_defined_p (op
, arg1
, arg2
))
522 return value_x_binop (arg1
, arg2
, op
, 0);
526 tem
= value_less (arg1
, arg2
);
527 return value_from_long (builtin_type_int
, tem
);
531 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
532 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
533 if (noside
== EVAL_SKIP
)
535 if (binop_user_defined_p (op
, arg1
, arg2
))
537 return value_x_binop (arg1
, arg2
, op
, 0);
541 tem
= value_less (arg2
, arg1
);
542 return value_from_long (builtin_type_int
, tem
);
546 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
547 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
548 if (noside
== EVAL_SKIP
)
550 if (binop_user_defined_p (op
, arg1
, arg2
))
552 return value_x_binop (arg1
, arg2
, op
, 0);
556 tem
= value_less (arg1
, arg2
);
557 return value_from_long (builtin_type_int
, ! tem
);
561 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
562 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
563 if (noside
== EVAL_SKIP
)
565 if (binop_user_defined_p (op
, arg1
, arg2
))
567 return value_x_binop (arg1
, arg2
, op
, 0);
571 tem
= value_less (arg2
, arg1
);
572 return value_from_long (builtin_type_int
, ! tem
);
576 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
577 arg2
= evaluate_subexp (0, exp
, pos
, noside
);
578 if (noside
== EVAL_SKIP
)
580 return value_repeat (arg1
, value_as_long (arg2
));
583 evaluate_subexp (0, exp
, pos
, noside
);
584 return evaluate_subexp (0, exp
, pos
, noside
);
587 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
588 if (noside
== EVAL_SKIP
)
590 if (unop_user_defined_p (op
, arg1
))
591 return value_x_unop (arg1
, op
, 0);
593 return value_neg (arg1
);
596 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
597 if (noside
== EVAL_SKIP
)
599 if (unop_user_defined_p (op
, arg1
))
600 return value_x_unop (arg1
, op
, 0);
602 return value_lognot (arg1
);
605 arg1
= evaluate_subexp (0, exp
, pos
, noside
);
606 if (noside
== EVAL_SKIP
)
608 if (unop_user_defined_p (op
, arg1
))
609 return value_x_unop (arg1
, op
, 0);
611 return value_from_long (builtin_type_int
, value_zerop (arg1
));
614 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
615 expect_type
= TYPE_TARGET_TYPE (expect_type
);
616 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
617 if (noside
== EVAL_SKIP
)
619 return value_ind (arg1
);
622 /* C++: check for and handle pointer to members. */
624 op
= exp
->elts
[*pos
].opcode
;
626 if (noside
== EVAL_SKIP
)
630 char *name
= &exp
->elts
[pc
+3].string
;
631 int tem
= strlen (name
);
632 (*pos
) += 2 + (tem
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
635 evaluate_subexp (expect_type
, exp
, pos
, EVAL_SKIP
);
641 char *name
= &exp
->elts
[pc
+3].string
;
642 int tem
= strlen (name
);
643 struct type
*domain
= exp
->elts
[pc
+2].type
;
644 (*pos
) += 2 + (tem
+ sizeof (union exp_element
)) / sizeof (union exp_element
);
645 arg1
= value_struct_elt_for_address (domain
, expect_type
, name
);
648 error ("no field `%s' in structure", name
);
651 return evaluate_subexp_for_address (exp
, pos
, noside
);
654 if (noside
== EVAL_SKIP
)
656 evaluate_subexp (0, exp
, pos
, EVAL_SKIP
);
659 return evaluate_subexp_for_sizeof (exp
, pos
);
663 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
664 if (noside
== EVAL_SKIP
)
666 return value_cast (exp
->elts
[pc
+ 1].type
, arg1
);
670 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
671 if (noside
== EVAL_SKIP
)
673 return value_at (exp
->elts
[pc
+ 1].type
, value_as_long (arg1
));
675 case UNOP_PREINCREMENT
:
676 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
677 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
679 else if (unop_user_defined_p (op
, arg1
))
681 return value_x_unop (arg1
, op
, 0);
685 arg2
= value_add (arg1
, value_from_long (builtin_type_char
, 1));
686 return value_assign (arg1
, arg2
);
689 case UNOP_PREDECREMENT
:
690 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
691 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
693 else if (unop_user_defined_p (op
, arg1
))
695 return value_x_unop (arg1
, op
, 0);
699 arg2
= value_sub (arg1
, value_from_long (builtin_type_char
, 1));
700 return value_assign (arg1
, arg2
);
703 case UNOP_POSTINCREMENT
:
704 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
705 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
707 else if (unop_user_defined_p (op
, arg1
))
709 return value_x_unop (arg1
, op
, 0);
713 arg2
= value_add (arg1
, value_from_long (builtin_type_char
, 1));
714 value_assign (arg1
, arg2
);
718 case UNOP_POSTDECREMENT
:
719 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
720 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
722 else if (unop_user_defined_p (op
, arg1
))
724 return value_x_unop (arg1
, op
, 0);
728 arg2
= value_sub (arg1
, value_from_long (builtin_type_char
, 1));
729 value_assign (arg1
, arg2
);
735 return value_of_this (1);
738 error ("internal error: I dont know how to evaluation what you gave me");
742 return value_from_long (builtin_type_long
, 1);
745 /* Evaluate a subexpression of EXP, at index *POS,
746 and return the address of that subexpression.
747 Advance *POS over the subexpression.
748 If the subexpression isn't an lvalue, get an error.
749 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
750 then only the type of the result need be correct. */
753 evaluate_subexp_for_address (exp
, pos
, noside
)
754 register struct expression
*exp
;
762 op
= exp
->elts
[pc
].opcode
;
768 return evaluate_subexp (0, exp
, pos
, noside
);
772 return value_cast (lookup_pointer_type (exp
->elts
[pc
+ 1].type
),
773 evaluate_subexp (0, exp
, pos
, noside
));
777 return locate_var_value (exp
->elts
[pc
+ 1].symbol
, (CORE_ADDR
) 0);
780 return value_addr (evaluate_subexp (0, exp
, pos
, noside
));
784 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
785 When used in contexts where arrays will be coerced anyway,
786 this is equivalent to `evaluate_subexp'
787 but much faster because it avoids actually fetching array contents. */
790 evaluate_subexp_with_coercion (exp
, pos
, noside
)
791 register struct expression
*exp
;
795 register enum exp_opcode op
;
800 op
= exp
->elts
[pc
].opcode
;
805 if (TYPE_CODE (SYMBOL_TYPE (exp
->elts
[pc
+ 1].symbol
)) == TYPE_CODE_ARRAY
)
808 val
= locate_var_value (exp
->elts
[pc
+ 1].symbol
, (CORE_ADDR
) 0);
809 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (exp
->elts
[pc
+ 1].symbol
))),
814 return evaluate_subexp (0, exp
, pos
, noside
);
817 /* Evaluate a subexpression of EXP, at index *POS,
818 and return a value for the size of that subexpression.
819 Advance *POS over the subexpression. */
822 evaluate_subexp_for_sizeof (exp
, pos
)
823 register struct expression
*exp
;
831 op
= exp
->elts
[pc
].opcode
;
835 /* This case is handled specially
836 so that we avoid creating a value for the result type.
837 If the result type is very big, it's desirable not to
838 create a value unnecessarily. */
841 val
= evaluate_subexp (0, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
842 return value_from_long (builtin_type_int
,
843 TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val
))));
847 return value_from_long (builtin_type_int
,
848 TYPE_LENGTH (exp
->elts
[pc
+ 1].type
));
852 return value_from_long (builtin_type_int
,
853 TYPE_LENGTH (SYMBOL_TYPE (exp
->elts
[pc
+ 1].symbol
)));
856 val
= evaluate_subexp (0, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
857 return value_from_long (builtin_type_int
,
858 TYPE_LENGTH (VALUE_TYPE (val
)));
This page took 0.046855 seconds and 4 git commands to generate.