Explicitly include <array> for std::array<>.
[deliverable/binutils-gdb.git] / gdb / eval.c
1 /* Evaluate expressions for GDB.
2
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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 3 of the License, or
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "gdbtypes.h"
23 #include "value.h"
24 #include "expression.h"
25 #include "target.h"
26 #include "frame.h"
27 #include "gdbthread.h"
28 #include "language.h" /* For CAST_IS_CONVERSION. */
29 #include "f-lang.h" /* For array bound stuff. */
30 #include "cp-abi.h"
31 #include "infcall.h"
32 #include "objc-lang.h"
33 #include "block.h"
34 #include "parser-defs.h"
35 #include "cp-support.h"
36 #include "ui-out.h"
37 #include "regcache.h"
38 #include "user-regs.h"
39 #include "valprint.h"
40 #include "gdb_obstack.h"
41 #include "objfiles.h"
42 #include "typeprint.h"
43 #include <ctype.h>
44
45 /* This is defined in valops.c */
46 extern int overload_resolution;
47
48 /* Prototypes for local functions. */
49
50 static struct value *evaluate_subexp_for_sizeof (struct expression *, int *,
51 enum noside);
52
53 static struct value *evaluate_subexp_for_address (struct expression *,
54 int *, enum noside);
55
56 static value *evaluate_subexp_for_cast (expression *exp, int *pos,
57 enum noside noside,
58 struct type *type);
59
60 static struct value *evaluate_struct_tuple (struct value *,
61 struct expression *, int *,
62 enum noside, int);
63
64 static LONGEST init_array_element (struct value *, struct value *,
65 struct expression *, int *, enum noside,
66 LONGEST, LONGEST);
67
68 struct value *
69 evaluate_subexp (struct type *expect_type, struct expression *exp,
70 int *pos, enum noside noside)
71 {
72 struct cleanup *cleanups;
73 struct value *retval;
74 int cleanup_temps = 0;
75
76 if (*pos == 0 && target_has_execution
77 && exp->language_defn->la_language == language_cplus
78 && !thread_stack_temporaries_enabled_p (inferior_ptid))
79 {
80 cleanups = enable_thread_stack_temporaries (inferior_ptid);
81 cleanup_temps = 1;
82 }
83
84 retval = (*exp->language_defn->la_exp_desc->evaluate_exp)
85 (expect_type, exp, pos, noside);
86
87 if (cleanup_temps)
88 {
89 if (value_in_thread_stack_temporaries (retval, inferior_ptid))
90 retval = value_non_lval (retval);
91 do_cleanups (cleanups);
92 }
93
94 return retval;
95 }
96 \f
97 /* Parse the string EXP as a C expression, evaluate it,
98 and return the result as a number. */
99
100 CORE_ADDR
101 parse_and_eval_address (const char *exp)
102 {
103 expression_up expr = parse_expression (exp);
104
105 return value_as_address (evaluate_expression (expr.get ()));
106 }
107
108 /* Like parse_and_eval_address, but treats the value of the expression
109 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
110 LONGEST
111 parse_and_eval_long (const char *exp)
112 {
113 expression_up expr = parse_expression (exp);
114
115 return value_as_long (evaluate_expression (expr.get ()));
116 }
117
118 struct value *
119 parse_and_eval (const char *exp)
120 {
121 expression_up expr = parse_expression (exp);
122
123 return evaluate_expression (expr.get ());
124 }
125
126 /* Parse up to a comma (or to a closeparen)
127 in the string EXPP as an expression, evaluate it, and return the value.
128 EXPP is advanced to point to the comma. */
129
130 struct value *
131 parse_to_comma_and_eval (const char **expp)
132 {
133 expression_up expr = parse_exp_1 (expp, 0, (struct block *) 0, 1);
134
135 return evaluate_expression (expr.get ());
136 }
137 \f
138 /* Evaluate an expression in internal prefix form
139 such as is constructed by parse.y.
140
141 See expression.h for info on the format of an expression. */
142
143 struct value *
144 evaluate_expression (struct expression *exp)
145 {
146 int pc = 0;
147
148 return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
149 }
150
151 /* Evaluate an expression, avoiding all memory references
152 and getting a value whose type alone is correct. */
153
154 struct value *
155 evaluate_type (struct expression *exp)
156 {
157 int pc = 0;
158
159 return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
160 }
161
162 /* Evaluate a subexpression, avoiding all memory references and
163 getting a value whose type alone is correct. */
164
165 struct value *
166 evaluate_subexpression_type (struct expression *exp, int subexp)
167 {
168 return evaluate_subexp (NULL_TYPE, exp, &subexp, EVAL_AVOID_SIDE_EFFECTS);
169 }
170
171 /* Find the current value of a watchpoint on EXP. Return the value in
172 *VALP and *RESULTP and the chain of intermediate and final values
173 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
174 not need them.
175
176 If PRESERVE_ERRORS is true, then exceptions are passed through.
177 Otherwise, if PRESERVE_ERRORS is false, then if a memory error
178 occurs while evaluating the expression, *RESULTP will be set to
179 NULL. *RESULTP may be a lazy value, if the result could not be
180 read from memory. It is used to determine whether a value is
181 user-specified (we should watch the whole value) or intermediate
182 (we should watch only the bit used to locate the final value).
183
184 If the final value, or any intermediate value, could not be read
185 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
186 set to any referenced values. *VALP will never be a lazy value.
187 This is the value which we store in struct breakpoint.
188
189 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
190 value chain. The caller must free the values individually. If
191 VAL_CHAIN is NULL, all generated values will be left on the value
192 chain. */
193
194 void
195 fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
196 struct value **resultp, struct value **val_chain,
197 int preserve_errors)
198 {
199 struct value *mark, *new_mark, *result;
200
201 *valp = NULL;
202 if (resultp)
203 *resultp = NULL;
204 if (val_chain)
205 *val_chain = NULL;
206
207 /* Evaluate the expression. */
208 mark = value_mark ();
209 result = NULL;
210
211 TRY
212 {
213 result = evaluate_subexp (NULL_TYPE, exp, pc, EVAL_NORMAL);
214 }
215 CATCH (ex, RETURN_MASK_ALL)
216 {
217 /* Ignore memory errors if we want watchpoints pointing at
218 inaccessible memory to still be created; otherwise, throw the
219 error to some higher catcher. */
220 switch (ex.error)
221 {
222 case MEMORY_ERROR:
223 if (!preserve_errors)
224 break;
225 default:
226 throw_exception (ex);
227 break;
228 }
229 }
230 END_CATCH
231
232 new_mark = value_mark ();
233 if (mark == new_mark)
234 return;
235 if (resultp)
236 *resultp = result;
237
238 /* Make sure it's not lazy, so that after the target stops again we
239 have a non-lazy previous value to compare with. */
240 if (result != NULL)
241 {
242 if (!value_lazy (result))
243 *valp = result;
244 else
245 {
246
247 TRY
248 {
249 value_fetch_lazy (result);
250 *valp = result;
251 }
252 CATCH (except, RETURN_MASK_ERROR)
253 {
254 }
255 END_CATCH
256 }
257 }
258
259 if (val_chain)
260 {
261 /* Return the chain of intermediate values. We use this to
262 decide which addresses to watch. */
263 *val_chain = new_mark;
264 value_release_to_mark (mark);
265 }
266 }
267
268 /* Extract a field operation from an expression. If the subexpression
269 of EXP starting at *SUBEXP is not a structure dereference
270 operation, return NULL. Otherwise, return the name of the
271 dereferenced field, and advance *SUBEXP to point to the
272 subexpression of the left-hand-side of the dereference. This is
273 used when completing field names. */
274
275 char *
276 extract_field_op (struct expression *exp, int *subexp)
277 {
278 int tem;
279 char *result;
280
281 if (exp->elts[*subexp].opcode != STRUCTOP_STRUCT
282 && exp->elts[*subexp].opcode != STRUCTOP_PTR)
283 return NULL;
284 tem = longest_to_int (exp->elts[*subexp + 1].longconst);
285 result = &exp->elts[*subexp + 2].string;
286 (*subexp) += 1 + 3 + BYTES_TO_EXP_ELEM (tem + 1);
287 return result;
288 }
289
290 /* This function evaluates brace-initializers (in C/C++) for
291 structure types. */
292
293 static struct value *
294 evaluate_struct_tuple (struct value *struct_val,
295 struct expression *exp,
296 int *pos, enum noside noside, int nargs)
297 {
298 struct type *struct_type = check_typedef (value_type (struct_val));
299 struct type *field_type;
300 int fieldno = -1;
301
302 while (--nargs >= 0)
303 {
304 struct value *val = NULL;
305 int bitpos, bitsize;
306 bfd_byte *addr;
307
308 fieldno++;
309 /* Skip static fields. */
310 while (fieldno < TYPE_NFIELDS (struct_type)
311 && field_is_static (&TYPE_FIELD (struct_type,
312 fieldno)))
313 fieldno++;
314 if (fieldno >= TYPE_NFIELDS (struct_type))
315 error (_("too many initializers"));
316 field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
317 if (TYPE_CODE (field_type) == TYPE_CODE_UNION
318 && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
319 error (_("don't know which variant you want to set"));
320
321 /* Here, struct_type is the type of the inner struct,
322 while substruct_type is the type of the inner struct.
323 These are the same for normal structures, but a variant struct
324 contains anonymous union fields that contain substruct fields.
325 The value fieldno is the index of the top-level (normal or
326 anonymous union) field in struct_field, while the value
327 subfieldno is the index of the actual real (named inner) field
328 in substruct_type. */
329
330 field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
331 if (val == 0)
332 val = evaluate_subexp (field_type, exp, pos, noside);
333
334 /* Now actually set the field in struct_val. */
335
336 /* Assign val to field fieldno. */
337 if (value_type (val) != field_type)
338 val = value_cast (field_type, val);
339
340 bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
341 bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
342 addr = value_contents_writeable (struct_val) + bitpos / 8;
343 if (bitsize)
344 modify_field (struct_type, addr,
345 value_as_long (val), bitpos % 8, bitsize);
346 else
347 memcpy (addr, value_contents (val),
348 TYPE_LENGTH (value_type (val)));
349
350 }
351 return struct_val;
352 }
353
354 /* Recursive helper function for setting elements of array tuples.
355 The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND); the
356 element value is ELEMENT; EXP, POS and NOSIDE are as usual.
357 Evaluates index expresions and sets the specified element(s) of
358 ARRAY to ELEMENT. Returns last index value. */
359
360 static LONGEST
361 init_array_element (struct value *array, struct value *element,
362 struct expression *exp, int *pos,
363 enum noside noside, LONGEST low_bound, LONGEST high_bound)
364 {
365 LONGEST index;
366 int element_size = TYPE_LENGTH (value_type (element));
367
368 if (exp->elts[*pos].opcode == BINOP_COMMA)
369 {
370 (*pos)++;
371 init_array_element (array, element, exp, pos, noside,
372 low_bound, high_bound);
373 return init_array_element (array, element,
374 exp, pos, noside, low_bound, high_bound);
375 }
376 else
377 {
378 index = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
379 if (index < low_bound || index > high_bound)
380 error (_("tuple index out of range"));
381 memcpy (value_contents_raw (array) + (index - low_bound) * element_size,
382 value_contents (element), element_size);
383 }
384 return index;
385 }
386
387 static struct value *
388 value_f90_subarray (struct value *array,
389 struct expression *exp, int *pos, enum noside noside)
390 {
391 int pc = (*pos) + 1;
392 LONGEST low_bound, high_bound;
393 struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
394 enum range_type range_type
395 = (enum range_type) longest_to_int (exp->elts[pc].longconst);
396
397 *pos += 3;
398
399 if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
400 low_bound = TYPE_LOW_BOUND (range);
401 else
402 low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
403
404 if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
405 high_bound = TYPE_HIGH_BOUND (range);
406 else
407 high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
408
409 return value_slice (array, low_bound, high_bound - low_bound + 1);
410 }
411
412
413 /* Promote value ARG1 as appropriate before performing a unary operation
414 on this argument.
415 If the result is not appropriate for any particular language then it
416 needs to patch this function. */
417
418 void
419 unop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
420 struct value **arg1)
421 {
422 struct type *type1;
423
424 *arg1 = coerce_ref (*arg1);
425 type1 = check_typedef (value_type (*arg1));
426
427 if (is_integral_type (type1))
428 {
429 switch (language->la_language)
430 {
431 default:
432 /* Perform integral promotion for ANSI C/C++.
433 If not appropropriate for any particular language
434 it needs to modify this function. */
435 {
436 struct type *builtin_int = builtin_type (gdbarch)->builtin_int;
437
438 if (TYPE_LENGTH (type1) < TYPE_LENGTH (builtin_int))
439 *arg1 = value_cast (builtin_int, *arg1);
440 }
441 break;
442 }
443 }
444 }
445
446 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
447 operation on those two operands.
448 If the result is not appropriate for any particular language then it
449 needs to patch this function. */
450
451 void
452 binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
453 struct value **arg1, struct value **arg2)
454 {
455 struct type *promoted_type = NULL;
456 struct type *type1;
457 struct type *type2;
458
459 *arg1 = coerce_ref (*arg1);
460 *arg2 = coerce_ref (*arg2);
461
462 type1 = check_typedef (value_type (*arg1));
463 type2 = check_typedef (value_type (*arg2));
464
465 if ((TYPE_CODE (type1) != TYPE_CODE_FLT
466 && TYPE_CODE (type1) != TYPE_CODE_DECFLOAT
467 && !is_integral_type (type1))
468 || (TYPE_CODE (type2) != TYPE_CODE_FLT
469 && TYPE_CODE (type2) != TYPE_CODE_DECFLOAT
470 && !is_integral_type (type2)))
471 return;
472
473 if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT
474 || TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
475 {
476 /* No promotion required. */
477 }
478 else if (TYPE_CODE (type1) == TYPE_CODE_FLT
479 || TYPE_CODE (type2) == TYPE_CODE_FLT)
480 {
481 switch (language->la_language)
482 {
483 case language_c:
484 case language_cplus:
485 case language_asm:
486 case language_objc:
487 case language_opencl:
488 /* No promotion required. */
489 break;
490
491 default:
492 /* For other languages the result type is unchanged from gdb
493 version 6.7 for backward compatibility.
494 If either arg was long double, make sure that value is also long
495 double. Otherwise use double. */
496 if (TYPE_LENGTH (type1) * 8 > gdbarch_double_bit (gdbarch)
497 || TYPE_LENGTH (type2) * 8 > gdbarch_double_bit (gdbarch))
498 promoted_type = builtin_type (gdbarch)->builtin_long_double;
499 else
500 promoted_type = builtin_type (gdbarch)->builtin_double;
501 break;
502 }
503 }
504 else if (TYPE_CODE (type1) == TYPE_CODE_BOOL
505 && TYPE_CODE (type2) == TYPE_CODE_BOOL)
506 {
507 /* No promotion required. */
508 }
509 else
510 /* Integral operations here. */
511 /* FIXME: Also mixed integral/booleans, with result an integer. */
512 {
513 const struct builtin_type *builtin = builtin_type (gdbarch);
514 unsigned int promoted_len1 = TYPE_LENGTH (type1);
515 unsigned int promoted_len2 = TYPE_LENGTH (type2);
516 int is_unsigned1 = TYPE_UNSIGNED (type1);
517 int is_unsigned2 = TYPE_UNSIGNED (type2);
518 unsigned int result_len;
519 int unsigned_operation;
520
521 /* Determine type length and signedness after promotion for
522 both operands. */
523 if (promoted_len1 < TYPE_LENGTH (builtin->builtin_int))
524 {
525 is_unsigned1 = 0;
526 promoted_len1 = TYPE_LENGTH (builtin->builtin_int);
527 }
528 if (promoted_len2 < TYPE_LENGTH (builtin->builtin_int))
529 {
530 is_unsigned2 = 0;
531 promoted_len2 = TYPE_LENGTH (builtin->builtin_int);
532 }
533
534 if (promoted_len1 > promoted_len2)
535 {
536 unsigned_operation = is_unsigned1;
537 result_len = promoted_len1;
538 }
539 else if (promoted_len2 > promoted_len1)
540 {
541 unsigned_operation = is_unsigned2;
542 result_len = promoted_len2;
543 }
544 else
545 {
546 unsigned_operation = is_unsigned1 || is_unsigned2;
547 result_len = promoted_len1;
548 }
549
550 switch (language->la_language)
551 {
552 case language_c:
553 case language_cplus:
554 case language_asm:
555 case language_objc:
556 if (result_len <= TYPE_LENGTH (builtin->builtin_int))
557 {
558 promoted_type = (unsigned_operation
559 ? builtin->builtin_unsigned_int
560 : builtin->builtin_int);
561 }
562 else if (result_len <= TYPE_LENGTH (builtin->builtin_long))
563 {
564 promoted_type = (unsigned_operation
565 ? builtin->builtin_unsigned_long
566 : builtin->builtin_long);
567 }
568 else
569 {
570 promoted_type = (unsigned_operation
571 ? builtin->builtin_unsigned_long_long
572 : builtin->builtin_long_long);
573 }
574 break;
575 case language_opencl:
576 if (result_len <= TYPE_LENGTH (lookup_signed_typename
577 (language, gdbarch, "int")))
578 {
579 promoted_type =
580 (unsigned_operation
581 ? lookup_unsigned_typename (language, gdbarch, "int")
582 : lookup_signed_typename (language, gdbarch, "int"));
583 }
584 else if (result_len <= TYPE_LENGTH (lookup_signed_typename
585 (language, gdbarch, "long")))
586 {
587 promoted_type =
588 (unsigned_operation
589 ? lookup_unsigned_typename (language, gdbarch, "long")
590 : lookup_signed_typename (language, gdbarch,"long"));
591 }
592 break;
593 default:
594 /* For other languages the result type is unchanged from gdb
595 version 6.7 for backward compatibility.
596 If either arg was long long, make sure that value is also long
597 long. Otherwise use long. */
598 if (unsigned_operation)
599 {
600 if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
601 promoted_type = builtin->builtin_unsigned_long_long;
602 else
603 promoted_type = builtin->builtin_unsigned_long;
604 }
605 else
606 {
607 if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
608 promoted_type = builtin->builtin_long_long;
609 else
610 promoted_type = builtin->builtin_long;
611 }
612 break;
613 }
614 }
615
616 if (promoted_type)
617 {
618 /* Promote both operands to common type. */
619 *arg1 = value_cast (promoted_type, *arg1);
620 *arg2 = value_cast (promoted_type, *arg2);
621 }
622 }
623
624 static int
625 ptrmath_type_p (const struct language_defn *lang, struct type *type)
626 {
627 type = check_typedef (type);
628 if (TYPE_IS_REFERENCE (type))
629 type = TYPE_TARGET_TYPE (type);
630
631 switch (TYPE_CODE (type))
632 {
633 case TYPE_CODE_PTR:
634 case TYPE_CODE_FUNC:
635 return 1;
636
637 case TYPE_CODE_ARRAY:
638 return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays;
639
640 default:
641 return 0;
642 }
643 }
644
645 /* Constructs a fake method with the given parameter types. This
646 function is used by the parser to construct an "expected" type for
647 method overload resolution. FLAGS is used as instance flags of the
648 new type, in order to be able to make the new type represent a
649 const/volatile overload. */
650
651 static struct type *
652 make_params (type_instance_flags flags,
653 int num_types, struct type **param_types)
654 {
655 struct type *type = XCNEW (struct type);
656 TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
657 TYPE_LENGTH (type) = 1;
658 TYPE_CODE (type) = TYPE_CODE_METHOD;
659 TYPE_CHAIN (type) = type;
660 TYPE_INSTANCE_FLAGS (type) = flags;
661 if (num_types > 0)
662 {
663 if (param_types[num_types - 1] == NULL)
664 {
665 --num_types;
666 TYPE_VARARGS (type) = 1;
667 }
668 else if (TYPE_CODE (check_typedef (param_types[num_types - 1]))
669 == TYPE_CODE_VOID)
670 {
671 --num_types;
672 /* Caller should have ensured this. */
673 gdb_assert (num_types == 0);
674 TYPE_PROTOTYPED (type) = 1;
675 }
676 }
677
678 TYPE_NFIELDS (type) = num_types;
679 TYPE_FIELDS (type) = (struct field *)
680 TYPE_ZALLOC (type, sizeof (struct field) * num_types);
681
682 while (num_types-- > 0)
683 TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
684
685 return type;
686 }
687
688 /* Helper for evaluating an OP_VAR_VALUE. */
689
690 static value *
691 evaluate_var_value (enum noside noside, const block *blk, symbol *var)
692 {
693 /* JYG: We used to just return value_zero of the symbol type if
694 we're asked to avoid side effects. Otherwise we return
695 value_of_variable (...). However I'm not sure if
696 value_of_variable () has any side effect. We need a full value
697 object returned here for whatis_exp () to call evaluate_type ()
698 and then pass the full value to value_rtti_target_type () if we
699 are dealing with a pointer or reference to a base class and print
700 object is on. */
701
702 struct value *ret = NULL;
703
704 TRY
705 {
706 ret = value_of_variable (var, blk);
707 }
708
709 CATCH (except, RETURN_MASK_ERROR)
710 {
711 if (noside != EVAL_AVOID_SIDE_EFFECTS)
712 throw_exception (except);
713
714 ret = value_zero (SYMBOL_TYPE (var), not_lval);
715 }
716 END_CATCH
717
718 return ret;
719 }
720
721 /* Helper for evaluating an OP_VAR_MSYM_VALUE. */
722
723 static value *
724 evaluate_var_msym_value (enum noside noside,
725 struct objfile *objfile, minimal_symbol *msymbol)
726 {
727 if (noside == EVAL_AVOID_SIDE_EFFECTS)
728 {
729 type *the_type = find_minsym_type_and_address (msymbol, objfile, NULL);
730 return value_zero (the_type, not_lval);
731 }
732 else
733 {
734 CORE_ADDR address;
735 type *the_type = find_minsym_type_and_address (msymbol, objfile, &address);
736 return value_at_lazy (the_type, address);
737 }
738 }
739
740 /* Helper for returning a value when handling EVAL_SKIP. */
741
742 static value *
743 eval_skip_value (expression *exp)
744 {
745 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
746 }
747
748 struct value *
749 evaluate_subexp_standard (struct type *expect_type,
750 struct expression *exp, int *pos,
751 enum noside noside)
752 {
753 enum exp_opcode op;
754 int tem, tem2, tem3;
755 int pc, pc2 = 0, oldpos;
756 struct value *arg1 = NULL;
757 struct value *arg2 = NULL;
758 struct value *arg3;
759 struct type *type;
760 int nargs;
761 struct value **argvec;
762 int code;
763 int ix;
764 long mem_offset;
765 struct type **arg_types;
766 int save_pos1;
767 struct symbol *function = NULL;
768 char *function_name = NULL;
769 const char *var_func_name = NULL;
770
771 pc = (*pos)++;
772 op = exp->elts[pc].opcode;
773
774 switch (op)
775 {
776 case OP_SCOPE:
777 tem = longest_to_int (exp->elts[pc + 2].longconst);
778 (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
779 if (noside == EVAL_SKIP)
780 return eval_skip_value (exp);
781 arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
782 &exp->elts[pc + 3].string,
783 expect_type, 0, noside);
784 if (arg1 == NULL)
785 error (_("There is no field named %s"), &exp->elts[pc + 3].string);
786 return arg1;
787
788 case OP_LONG:
789 (*pos) += 3;
790 return value_from_longest (exp->elts[pc + 1].type,
791 exp->elts[pc + 2].longconst);
792
793 case OP_DOUBLE:
794 (*pos) += 3;
795 return value_from_double (exp->elts[pc + 1].type,
796 exp->elts[pc + 2].doubleconst);
797
798 case OP_DECFLOAT:
799 (*pos) += 3;
800 return value_from_decfloat (exp->elts[pc + 1].type,
801 exp->elts[pc + 2].decfloatconst);
802
803 case OP_ADL_FUNC:
804 case OP_VAR_VALUE:
805 (*pos) += 3;
806 if (noside == EVAL_SKIP)
807 return eval_skip_value (exp);
808
809 {
810 symbol *var = exp->elts[pc + 2].symbol;
811 if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_ERROR)
812 error_unknown_type (SYMBOL_PRINT_NAME (var));
813
814 return evaluate_var_value (noside, exp->elts[pc + 1].block, var);
815 }
816
817 case OP_VAR_MSYM_VALUE:
818 {
819 (*pos) += 3;
820
821 minimal_symbol *msymbol = exp->elts[pc + 2].msymbol;
822 value *val = evaluate_var_msym_value (noside,
823 exp->elts[pc + 1].objfile,
824 msymbol);
825
826 type = value_type (val);
827 if (TYPE_CODE (type) == TYPE_CODE_ERROR
828 && (noside != EVAL_AVOID_SIDE_EFFECTS || pc != 0))
829 error_unknown_type (MSYMBOL_PRINT_NAME (msymbol));
830 return val;
831 }
832
833 case OP_VAR_ENTRY_VALUE:
834 (*pos) += 2;
835 if (noside == EVAL_SKIP)
836 return eval_skip_value (exp);
837
838 {
839 struct symbol *sym = exp->elts[pc + 1].symbol;
840 struct frame_info *frame;
841
842 if (noside == EVAL_AVOID_SIDE_EFFECTS)
843 return value_zero (SYMBOL_TYPE (sym), not_lval);
844
845 if (SYMBOL_COMPUTED_OPS (sym) == NULL
846 || SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
847 error (_("Symbol \"%s\" does not have any specific entry value"),
848 SYMBOL_PRINT_NAME (sym));
849
850 frame = get_selected_frame (NULL);
851 return SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry (sym, frame);
852 }
853
854 case OP_FUNC_STATIC_VAR:
855 tem = longest_to_int (exp->elts[pc + 1].longconst);
856 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
857 if (noside == EVAL_SKIP)
858 return eval_skip_value (exp);
859
860 {
861 value *func = evaluate_subexp_standard (NULL, exp, pos, noside);
862 CORE_ADDR addr = value_address (func);
863
864 const block *blk = block_for_pc (addr);
865 const char *var = &exp->elts[pc + 2].string;
866
867 struct block_symbol sym = lookup_symbol (var, blk, VAR_DOMAIN, NULL);
868
869 if (sym.symbol == NULL)
870 error (_("No symbol \"%s\" in specified context."), var);
871
872 return evaluate_var_value (noside, sym.block, sym.symbol);
873 }
874
875 case OP_LAST:
876 (*pos) += 2;
877 return
878 access_value_history (longest_to_int (exp->elts[pc + 1].longconst));
879
880 case OP_REGISTER:
881 {
882 const char *name = &exp->elts[pc + 2].string;
883 int regno;
884 struct value *val;
885
886 (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
887 regno = user_reg_map_name_to_regnum (exp->gdbarch,
888 name, strlen (name));
889 if (regno == -1)
890 error (_("Register $%s not available."), name);
891
892 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
893 a value with the appropriate register type. Unfortunately,
894 we don't have easy access to the type of user registers.
895 So for these registers, we fetch the register value regardless
896 of the evaluation mode. */
897 if (noside == EVAL_AVOID_SIDE_EFFECTS
898 && regno < gdbarch_num_regs (exp->gdbarch)
899 + gdbarch_num_pseudo_regs (exp->gdbarch))
900 val = value_zero (register_type (exp->gdbarch, regno), not_lval);
901 else
902 val = value_of_register (regno, get_selected_frame (NULL));
903 if (val == NULL)
904 error (_("Value of register %s not available."), name);
905 else
906 return val;
907 }
908 case OP_BOOL:
909 (*pos) += 2;
910 type = language_bool_type (exp->language_defn, exp->gdbarch);
911 return value_from_longest (type, exp->elts[pc + 1].longconst);
912
913 case OP_INTERNALVAR:
914 (*pos) += 2;
915 return value_of_internalvar (exp->gdbarch,
916 exp->elts[pc + 1].internalvar);
917
918 case OP_STRING:
919 tem = longest_to_int (exp->elts[pc + 1].longconst);
920 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
921 if (noside == EVAL_SKIP)
922 return eval_skip_value (exp);
923 type = language_string_char_type (exp->language_defn, exp->gdbarch);
924 return value_string (&exp->elts[pc + 2].string, tem, type);
925
926 case OP_OBJC_NSSTRING: /* Objective C Foundation Class
927 NSString constant. */
928 tem = longest_to_int (exp->elts[pc + 1].longconst);
929 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
930 if (noside == EVAL_SKIP)
931 return eval_skip_value (exp);
932 return value_nsstring (exp->gdbarch, &exp->elts[pc + 2].string, tem + 1);
933
934 case OP_ARRAY:
935 (*pos) += 3;
936 tem2 = longest_to_int (exp->elts[pc + 1].longconst);
937 tem3 = longest_to_int (exp->elts[pc + 2].longconst);
938 nargs = tem3 - tem2 + 1;
939 type = expect_type ? check_typedef (expect_type) : NULL_TYPE;
940
941 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
942 && TYPE_CODE (type) == TYPE_CODE_STRUCT)
943 {
944 struct value *rec = allocate_value (expect_type);
945
946 memset (value_contents_raw (rec), '\0', TYPE_LENGTH (type));
947 return evaluate_struct_tuple (rec, exp, pos, noside, nargs);
948 }
949
950 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
951 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
952 {
953 struct type *range_type = TYPE_INDEX_TYPE (type);
954 struct type *element_type = TYPE_TARGET_TYPE (type);
955 struct value *array = allocate_value (expect_type);
956 int element_size = TYPE_LENGTH (check_typedef (element_type));
957 LONGEST low_bound, high_bound, index;
958
959 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
960 {
961 low_bound = 0;
962 high_bound = (TYPE_LENGTH (type) / element_size) - 1;
963 }
964 index = low_bound;
965 memset (value_contents_raw (array), 0, TYPE_LENGTH (expect_type));
966 for (tem = nargs; --nargs >= 0;)
967 {
968 struct value *element;
969 int index_pc = 0;
970
971 element = evaluate_subexp (element_type, exp, pos, noside);
972 if (value_type (element) != element_type)
973 element = value_cast (element_type, element);
974 if (index_pc)
975 {
976 int continue_pc = *pos;
977
978 *pos = index_pc;
979 index = init_array_element (array, element, exp, pos, noside,
980 low_bound, high_bound);
981 *pos = continue_pc;
982 }
983 else
984 {
985 if (index > high_bound)
986 /* To avoid memory corruption. */
987 error (_("Too many array elements"));
988 memcpy (value_contents_raw (array)
989 + (index - low_bound) * element_size,
990 value_contents (element),
991 element_size);
992 }
993 index++;
994 }
995 return array;
996 }
997
998 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
999 && TYPE_CODE (type) == TYPE_CODE_SET)
1000 {
1001 struct value *set = allocate_value (expect_type);
1002 gdb_byte *valaddr = value_contents_raw (set);
1003 struct type *element_type = TYPE_INDEX_TYPE (type);
1004 struct type *check_type = element_type;
1005 LONGEST low_bound, high_bound;
1006
1007 /* Get targettype of elementtype. */
1008 while (TYPE_CODE (check_type) == TYPE_CODE_RANGE
1009 || TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
1010 check_type = TYPE_TARGET_TYPE (check_type);
1011
1012 if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
1013 error (_("(power)set type with unknown size"));
1014 memset (valaddr, '\0', TYPE_LENGTH (type));
1015 for (tem = 0; tem < nargs; tem++)
1016 {
1017 LONGEST range_low, range_high;
1018 struct type *range_low_type, *range_high_type;
1019 struct value *elem_val;
1020
1021 elem_val = evaluate_subexp (element_type, exp, pos, noside);
1022 range_low_type = range_high_type = value_type (elem_val);
1023 range_low = range_high = value_as_long (elem_val);
1024
1025 /* Check types of elements to avoid mixture of elements from
1026 different types. Also check if type of element is "compatible"
1027 with element type of powerset. */
1028 if (TYPE_CODE (range_low_type) == TYPE_CODE_RANGE)
1029 range_low_type = TYPE_TARGET_TYPE (range_low_type);
1030 if (TYPE_CODE (range_high_type) == TYPE_CODE_RANGE)
1031 range_high_type = TYPE_TARGET_TYPE (range_high_type);
1032 if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type))
1033 || (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM
1034 && (range_low_type != range_high_type)))
1035 /* different element modes. */
1036 error (_("POWERSET tuple elements of different mode"));
1037 if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type))
1038 || (TYPE_CODE (check_type) == TYPE_CODE_ENUM
1039 && range_low_type != check_type))
1040 error (_("incompatible POWERSET tuple elements"));
1041 if (range_low > range_high)
1042 {
1043 warning (_("empty POWERSET tuple range"));
1044 continue;
1045 }
1046 if (range_low < low_bound || range_high > high_bound)
1047 error (_("POWERSET tuple element out of range"));
1048 range_low -= low_bound;
1049 range_high -= low_bound;
1050 for (; range_low <= range_high; range_low++)
1051 {
1052 int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;
1053
1054 if (gdbarch_bits_big_endian (exp->gdbarch))
1055 bit_index = TARGET_CHAR_BIT - 1 - bit_index;
1056 valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
1057 |= 1 << bit_index;
1058 }
1059 }
1060 return set;
1061 }
1062
1063 argvec = XALLOCAVEC (struct value *, nargs);
1064 for (tem = 0; tem < nargs; tem++)
1065 {
1066 /* Ensure that array expressions are coerced into pointer
1067 objects. */
1068 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
1069 }
1070 if (noside == EVAL_SKIP)
1071 return eval_skip_value (exp);
1072 return value_array (tem2, tem3, argvec);
1073
1074 case TERNOP_SLICE:
1075 {
1076 struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1077 int lowbound
1078 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
1079 int upper
1080 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
1081
1082 if (noside == EVAL_SKIP)
1083 return eval_skip_value (exp);
1084 return value_slice (array, lowbound, upper - lowbound + 1);
1085 }
1086
1087 case TERNOP_COND:
1088 /* Skip third and second args to evaluate the first one. */
1089 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1090 if (value_logical_not (arg1))
1091 {
1092 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
1093 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
1094 }
1095 else
1096 {
1097 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1098 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
1099 return arg2;
1100 }
1101
1102 case OP_OBJC_SELECTOR:
1103 { /* Objective C @selector operator. */
1104 char *sel = &exp->elts[pc + 2].string;
1105 int len = longest_to_int (exp->elts[pc + 1].longconst);
1106 struct type *selector_type;
1107
1108 (*pos) += 3 + BYTES_TO_EXP_ELEM (len + 1);
1109 if (noside == EVAL_SKIP)
1110 return eval_skip_value (exp);
1111
1112 if (sel[len] != 0)
1113 sel[len] = 0; /* Make sure it's terminated. */
1114
1115 selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
1116 return value_from_longest (selector_type,
1117 lookup_child_selector (exp->gdbarch, sel));
1118 }
1119
1120 case OP_OBJC_MSGCALL:
1121 { /* Objective C message (method) call. */
1122
1123 CORE_ADDR responds_selector = 0;
1124 CORE_ADDR method_selector = 0;
1125
1126 CORE_ADDR selector = 0;
1127
1128 int struct_return = 0;
1129 enum noside sub_no_side = EVAL_NORMAL;
1130
1131 struct value *msg_send = NULL;
1132 struct value *msg_send_stret = NULL;
1133 int gnu_runtime = 0;
1134
1135 struct value *target = NULL;
1136 struct value *method = NULL;
1137 struct value *called_method = NULL;
1138
1139 struct type *selector_type = NULL;
1140 struct type *long_type;
1141
1142 struct value *ret = NULL;
1143 CORE_ADDR addr = 0;
1144
1145 selector = exp->elts[pc + 1].longconst;
1146 nargs = exp->elts[pc + 2].longconst;
1147 argvec = XALLOCAVEC (struct value *, nargs + 5);
1148
1149 (*pos) += 3;
1150
1151 long_type = builtin_type (exp->gdbarch)->builtin_long;
1152 selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
1153
1154 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1155 sub_no_side = EVAL_NORMAL;
1156 else
1157 sub_no_side = noside;
1158
1159 target = evaluate_subexp (selector_type, exp, pos, sub_no_side);
1160
1161 if (value_as_long (target) == 0)
1162 return value_from_longest (long_type, 0);
1163
1164 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym)
1165 gnu_runtime = 1;
1166
1167 /* Find the method dispatch (Apple runtime) or method lookup
1168 (GNU runtime) function for Objective-C. These will be used
1169 to lookup the symbol information for the method. If we
1170 can't find any symbol information, then we'll use these to
1171 call the method, otherwise we can call the method
1172 directly. The msg_send_stret function is used in the special
1173 case of a method that returns a structure (Apple runtime
1174 only). */
1175 if (gnu_runtime)
1176 {
1177 struct type *type = selector_type;
1178
1179 type = lookup_function_type (type);
1180 type = lookup_pointer_type (type);
1181 type = lookup_function_type (type);
1182 type = lookup_pointer_type (type);
1183
1184 msg_send = find_function_in_inferior ("objc_msg_lookup", NULL);
1185 msg_send_stret
1186 = find_function_in_inferior ("objc_msg_lookup", NULL);
1187
1188 msg_send = value_from_pointer (type, value_as_address (msg_send));
1189 msg_send_stret = value_from_pointer (type,
1190 value_as_address (msg_send_stret));
1191 }
1192 else
1193 {
1194 msg_send = find_function_in_inferior ("objc_msgSend", NULL);
1195 /* Special dispatcher for methods returning structs. */
1196 msg_send_stret
1197 = find_function_in_inferior ("objc_msgSend_stret", NULL);
1198 }
1199
1200 /* Verify the target object responds to this method. The
1201 standard top-level 'Object' class uses a different name for
1202 the verification method than the non-standard, but more
1203 often used, 'NSObject' class. Make sure we check for both. */
1204
1205 responds_selector
1206 = lookup_child_selector (exp->gdbarch, "respondsToSelector:");
1207 if (responds_selector == 0)
1208 responds_selector
1209 = lookup_child_selector (exp->gdbarch, "respondsTo:");
1210
1211 if (responds_selector == 0)
1212 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1213
1214 method_selector
1215 = lookup_child_selector (exp->gdbarch, "methodForSelector:");
1216 if (method_selector == 0)
1217 method_selector
1218 = lookup_child_selector (exp->gdbarch, "methodFor:");
1219
1220 if (method_selector == 0)
1221 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1222
1223 /* Call the verification method, to make sure that the target
1224 class implements the desired method. */
1225
1226 argvec[0] = msg_send;
1227 argvec[1] = target;
1228 argvec[2] = value_from_longest (long_type, responds_selector);
1229 argvec[3] = value_from_longest (long_type, selector);
1230 argvec[4] = 0;
1231
1232 ret = call_function_by_hand (argvec[0], NULL, 3, argvec + 1);
1233 if (gnu_runtime)
1234 {
1235 /* Function objc_msg_lookup returns a pointer. */
1236 argvec[0] = ret;
1237 ret = call_function_by_hand (argvec[0], NULL, 3, argvec + 1);
1238 }
1239 if (value_as_long (ret) == 0)
1240 error (_("Target does not respond to this message selector."));
1241
1242 /* Call "methodForSelector:" method, to get the address of a
1243 function method that implements this selector for this
1244 class. If we can find a symbol at that address, then we
1245 know the return type, parameter types etc. (that's a good
1246 thing). */
1247
1248 argvec[0] = msg_send;
1249 argvec[1] = target;
1250 argvec[2] = value_from_longest (long_type, method_selector);
1251 argvec[3] = value_from_longest (long_type, selector);
1252 argvec[4] = 0;
1253
1254 ret = call_function_by_hand (argvec[0], NULL, 3, argvec + 1);
1255 if (gnu_runtime)
1256 {
1257 argvec[0] = ret;
1258 ret = call_function_by_hand (argvec[0], NULL, 3, argvec + 1);
1259 }
1260
1261 /* ret should now be the selector. */
1262
1263 addr = value_as_long (ret);
1264 if (addr)
1265 {
1266 struct symbol *sym = NULL;
1267
1268 /* The address might point to a function descriptor;
1269 resolve it to the actual code address instead. */
1270 addr = gdbarch_convert_from_func_ptr_addr (exp->gdbarch, addr,
1271 &current_target);
1272
1273 /* Is it a high_level symbol? */
1274 sym = find_pc_function (addr);
1275 if (sym != NULL)
1276 method = value_of_variable (sym, 0);
1277 }
1278
1279 /* If we found a method with symbol information, check to see
1280 if it returns a struct. Otherwise assume it doesn't. */
1281
1282 if (method)
1283 {
1284 CORE_ADDR funaddr;
1285 struct type *val_type;
1286
1287 funaddr = find_function_addr (method, &val_type);
1288
1289 block_for_pc (funaddr);
1290
1291 val_type = check_typedef (val_type);
1292
1293 if ((val_type == NULL)
1294 || (TYPE_CODE(val_type) == TYPE_CODE_ERROR))
1295 {
1296 if (expect_type != NULL)
1297 val_type = expect_type;
1298 }
1299
1300 struct_return = using_struct_return (exp->gdbarch, method,
1301 val_type);
1302 }
1303 else if (expect_type != NULL)
1304 {
1305 struct_return = using_struct_return (exp->gdbarch, NULL,
1306 check_typedef (expect_type));
1307 }
1308
1309 /* Found a function symbol. Now we will substitute its
1310 value in place of the message dispatcher (obj_msgSend),
1311 so that we call the method directly instead of thru
1312 the dispatcher. The main reason for doing this is that
1313 we can now evaluate the return value and parameter values
1314 according to their known data types, in case we need to
1315 do things like promotion, dereferencing, special handling
1316 of structs and doubles, etc.
1317
1318 We want to use the type signature of 'method', but still
1319 jump to objc_msgSend() or objc_msgSend_stret() to better
1320 mimic the behavior of the runtime. */
1321
1322 if (method)
1323 {
1324 if (TYPE_CODE (value_type (method)) != TYPE_CODE_FUNC)
1325 error (_("method address has symbol information "
1326 "with non-function type; skipping"));
1327
1328 /* Create a function pointer of the appropriate type, and
1329 replace its value with the value of msg_send or
1330 msg_send_stret. We must use a pointer here, as
1331 msg_send and msg_send_stret are of pointer type, and
1332 the representation may be different on systems that use
1333 function descriptors. */
1334 if (struct_return)
1335 called_method
1336 = value_from_pointer (lookup_pointer_type (value_type (method)),
1337 value_as_address (msg_send_stret));
1338 else
1339 called_method
1340 = value_from_pointer (lookup_pointer_type (value_type (method)),
1341 value_as_address (msg_send));
1342 }
1343 else
1344 {
1345 if (struct_return)
1346 called_method = msg_send_stret;
1347 else
1348 called_method = msg_send;
1349 }
1350
1351 if (noside == EVAL_SKIP)
1352 return eval_skip_value (exp);
1353
1354 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1355 {
1356 /* If the return type doesn't look like a function type,
1357 call an error. This can happen if somebody tries to
1358 turn a variable into a function call. This is here
1359 because people often want to call, eg, strcmp, which
1360 gdb doesn't know is a function. If gdb isn't asked for
1361 it's opinion (ie. through "whatis"), it won't offer
1362 it. */
1363
1364 struct type *type = value_type (called_method);
1365
1366 if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
1367 type = TYPE_TARGET_TYPE (type);
1368 type = TYPE_TARGET_TYPE (type);
1369
1370 if (type)
1371 {
1372 if ((TYPE_CODE (type) == TYPE_CODE_ERROR) && expect_type)
1373 return allocate_value (expect_type);
1374 else
1375 return allocate_value (type);
1376 }
1377 else
1378 error (_("Expression of type other than "
1379 "\"method returning ...\" used as a method"));
1380 }
1381
1382 /* Now depending on whether we found a symbol for the method,
1383 we will either call the runtime dispatcher or the method
1384 directly. */
1385
1386 argvec[0] = called_method;
1387 argvec[1] = target;
1388 argvec[2] = value_from_longest (long_type, selector);
1389 /* User-supplied arguments. */
1390 for (tem = 0; tem < nargs; tem++)
1391 argvec[tem + 3] = evaluate_subexp_with_coercion (exp, pos, noside);
1392 argvec[tem + 3] = 0;
1393
1394 if (gnu_runtime && (method != NULL))
1395 {
1396 /* Function objc_msg_lookup returns a pointer. */
1397 deprecated_set_value_type (argvec[0],
1398 lookup_pointer_type (lookup_function_type (value_type (argvec[0]))));
1399 argvec[0]
1400 = call_function_by_hand (argvec[0], NULL, nargs + 2, argvec + 1);
1401 }
1402
1403 ret = call_function_by_hand (argvec[0], NULL, nargs + 2, argvec + 1);
1404 return ret;
1405 }
1406 break;
1407
1408 case OP_FUNCALL:
1409 (*pos) += 2;
1410 op = exp->elts[*pos].opcode;
1411 nargs = longest_to_int (exp->elts[pc + 1].longconst);
1412 /* Allocate arg vector, including space for the function to be
1413 called in argvec[0], a potential `this', and a terminating NULL. */
1414 argvec = (struct value **)
1415 alloca (sizeof (struct value *) * (nargs + 3));
1416 if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
1417 {
1418 /* First, evaluate the structure into arg2. */
1419 pc2 = (*pos)++;
1420
1421 if (op == STRUCTOP_MEMBER)
1422 {
1423 arg2 = evaluate_subexp_for_address (exp, pos, noside);
1424 }
1425 else
1426 {
1427 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1428 }
1429
1430 /* If the function is a virtual function, then the
1431 aggregate value (providing the structure) plays
1432 its part by providing the vtable. Otherwise,
1433 it is just along for the ride: call the function
1434 directly. */
1435
1436 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1437
1438 type = check_typedef (value_type (arg1));
1439 if (noside == EVAL_SKIP)
1440 tem = 1; /* Set it to the right arg index so that all arguments
1441 can also be skipped. */
1442 else if (TYPE_CODE (type) == TYPE_CODE_METHODPTR)
1443 {
1444 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1445 arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
1446 else
1447 arg1 = cplus_method_ptr_to_value (&arg2, arg1);
1448
1449 /* Now, say which argument to start evaluating from. */
1450 nargs++;
1451 tem = 2;
1452 argvec[1] = arg2;
1453 }
1454 else if (TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
1455 {
1456 struct type *type_ptr
1457 = lookup_pointer_type (TYPE_SELF_TYPE (type));
1458 struct type *target_type_ptr
1459 = lookup_pointer_type (TYPE_TARGET_TYPE (type));
1460
1461 /* Now, convert these values to an address. */
1462 arg2 = value_cast (type_ptr, arg2);
1463
1464 mem_offset = value_as_long (arg1);
1465
1466 arg1 = value_from_pointer (target_type_ptr,
1467 value_as_long (arg2) + mem_offset);
1468 arg1 = value_ind (arg1);
1469 tem = 1;
1470 }
1471 else
1472 error (_("Non-pointer-to-member value used in pointer-to-member "
1473 "construct"));
1474 }
1475 else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
1476 {
1477 /* Hair for method invocations. */
1478 int tem2;
1479
1480 nargs++;
1481 /* First, evaluate the structure into arg2. */
1482 pc2 = (*pos)++;
1483 tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
1484 *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);
1485
1486 if (op == STRUCTOP_STRUCT)
1487 {
1488 /* If v is a variable in a register, and the user types
1489 v.method (), this will produce an error, because v has
1490 no address.
1491
1492 A possible way around this would be to allocate a
1493 copy of the variable on the stack, copy in the
1494 contents, call the function, and copy out the
1495 contents. I.e. convert this from call by reference
1496 to call by copy-return (or whatever it's called).
1497 However, this does not work because it is not the
1498 same: the method being called could stash a copy of
1499 the address, and then future uses through that address
1500 (after the method returns) would be expected to
1501 use the variable itself, not some copy of it. */
1502 arg2 = evaluate_subexp_for_address (exp, pos, noside);
1503 }
1504 else
1505 {
1506 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1507
1508 /* Check to see if the operator '->' has been
1509 overloaded. If the operator has been overloaded
1510 replace arg2 with the value returned by the custom
1511 operator and continue evaluation. */
1512 while (unop_user_defined_p (op, arg2))
1513 {
1514 struct value *value = NULL;
1515 TRY
1516 {
1517 value = value_x_unop (arg2, op, noside);
1518 }
1519
1520 CATCH (except, RETURN_MASK_ERROR)
1521 {
1522 if (except.error == NOT_FOUND_ERROR)
1523 break;
1524 else
1525 throw_exception (except);
1526 }
1527 END_CATCH
1528
1529 arg2 = value;
1530 }
1531 }
1532 /* Now, say which argument to start evaluating from. */
1533 tem = 2;
1534 }
1535 else if (op == OP_SCOPE
1536 && overload_resolution
1537 && (exp->language_defn->la_language == language_cplus))
1538 {
1539 /* Unpack it locally so we can properly handle overload
1540 resolution. */
1541 char *name;
1542 int local_tem;
1543
1544 pc2 = (*pos)++;
1545 local_tem = longest_to_int (exp->elts[pc2 + 2].longconst);
1546 (*pos) += 4 + BYTES_TO_EXP_ELEM (local_tem + 1);
1547 type = exp->elts[pc2 + 1].type;
1548 name = &exp->elts[pc2 + 3].string;
1549
1550 function = NULL;
1551 function_name = NULL;
1552 if (TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
1553 {
1554 function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type),
1555 name,
1556 get_selected_block (0),
1557 VAR_DOMAIN).symbol;
1558 if (function == NULL)
1559 error (_("No symbol \"%s\" in namespace \"%s\"."),
1560 name, TYPE_TAG_NAME (type));
1561
1562 tem = 1;
1563 /* arg2 is left as NULL on purpose. */
1564 }
1565 else
1566 {
1567 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1568 || TYPE_CODE (type) == TYPE_CODE_UNION);
1569 function_name = name;
1570
1571 /* We need a properly typed value for method lookup. For
1572 static methods arg2 is otherwise unused. */
1573 arg2 = value_zero (type, lval_memory);
1574 ++nargs;
1575 tem = 2;
1576 }
1577 }
1578 else if (op == OP_ADL_FUNC)
1579 {
1580 /* Save the function position and move pos so that the arguments
1581 can be evaluated. */
1582 int func_name_len;
1583
1584 save_pos1 = *pos;
1585 tem = 1;
1586
1587 func_name_len = longest_to_int (exp->elts[save_pos1 + 3].longconst);
1588 (*pos) += 6 + BYTES_TO_EXP_ELEM (func_name_len + 1);
1589 }
1590 else
1591 {
1592 /* Non-method function call. */
1593 save_pos1 = *pos;
1594 tem = 1;
1595
1596 /* If this is a C++ function wait until overload resolution. */
1597 if (op == OP_VAR_VALUE
1598 && overload_resolution
1599 && (exp->language_defn->la_language == language_cplus))
1600 {
1601 (*pos) += 4; /* Skip the evaluation of the symbol. */
1602 argvec[0] = NULL;
1603 }
1604 else
1605 {
1606 if (op == OP_VAR_MSYM_VALUE)
1607 {
1608 symbol *sym = exp->elts[*pos + 2].symbol;
1609 var_func_name = SYMBOL_PRINT_NAME (sym);
1610 }
1611 else if (op == OP_VAR_VALUE)
1612 {
1613 minimal_symbol *msym = exp->elts[*pos + 2].msymbol;
1614 var_func_name = MSYMBOL_PRINT_NAME (msym);
1615 }
1616
1617 argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
1618 type = value_type (argvec[0]);
1619 if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
1620 type = TYPE_TARGET_TYPE (type);
1621 if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
1622 {
1623 for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
1624 {
1625 argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type,
1626 tem - 1),
1627 exp, pos, noside);
1628 }
1629 }
1630 }
1631 }
1632
1633 /* Evaluate arguments (if not already done, e.g., namespace::func()
1634 and overload-resolution is off). */
1635 for (; tem <= nargs; tem++)
1636 {
1637 /* Ensure that array expressions are coerced into pointer
1638 objects. */
1639 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
1640 }
1641
1642 /* Signal end of arglist. */
1643 argvec[tem] = 0;
1644
1645 if (noside == EVAL_SKIP)
1646 return eval_skip_value (exp);
1647
1648 if (op == OP_ADL_FUNC)
1649 {
1650 struct symbol *symp;
1651 char *func_name;
1652 int name_len;
1653 int string_pc = save_pos1 + 3;
1654
1655 /* Extract the function name. */
1656 name_len = longest_to_int (exp->elts[string_pc].longconst);
1657 func_name = (char *) alloca (name_len + 1);
1658 strcpy (func_name, &exp->elts[string_pc + 1].string);
1659
1660 find_overload_match (&argvec[1], nargs, func_name,
1661 NON_METHOD, /* not method */
1662 NULL, NULL, /* pass NULL symbol since
1663 symbol is unknown */
1664 NULL, &symp, NULL, 0, noside);
1665
1666 /* Now fix the expression being evaluated. */
1667 exp->elts[save_pos1 + 2].symbol = symp;
1668 argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
1669 }
1670
1671 if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR
1672 || (op == OP_SCOPE && function_name != NULL))
1673 {
1674 int static_memfuncp;
1675 char *tstr;
1676
1677 /* Method invocation: stuff "this" as first parameter.
1678 If the method turns out to be static we undo this below. */
1679 argvec[1] = arg2;
1680
1681 if (op != OP_SCOPE)
1682 {
1683 /* Name of method from expression. */
1684 tstr = &exp->elts[pc2 + 2].string;
1685 }
1686 else
1687 tstr = function_name;
1688
1689 if (overload_resolution && (exp->language_defn->la_language
1690 == language_cplus))
1691 {
1692 /* Language is C++, do some overload resolution before
1693 evaluation. */
1694 struct value *valp = NULL;
1695
1696 (void) find_overload_match (&argvec[1], nargs, tstr,
1697 METHOD, /* method */
1698 &arg2, /* the object */
1699 NULL, &valp, NULL,
1700 &static_memfuncp, 0, noside);
1701
1702 if (op == OP_SCOPE && !static_memfuncp)
1703 {
1704 /* For the time being, we don't handle this. */
1705 error (_("Call to overloaded function %s requires "
1706 "`this' pointer"),
1707 function_name);
1708 }
1709 argvec[1] = arg2; /* the ``this'' pointer */
1710 argvec[0] = valp; /* Use the method found after overload
1711 resolution. */
1712 }
1713 else
1714 /* Non-C++ case -- or no overload resolution. */
1715 {
1716 struct value *temp = arg2;
1717
1718 argvec[0] = value_struct_elt (&temp, argvec + 1, tstr,
1719 &static_memfuncp,
1720 op == STRUCTOP_STRUCT
1721 ? "structure" : "structure pointer");
1722 /* value_struct_elt updates temp with the correct value
1723 of the ``this'' pointer if necessary, so modify argvec[1] to
1724 reflect any ``this'' changes. */
1725 arg2
1726 = value_from_longest (lookup_pointer_type(value_type (temp)),
1727 value_address (temp)
1728 + value_embedded_offset (temp));
1729 argvec[1] = arg2; /* the ``this'' pointer */
1730 }
1731
1732 /* Take out `this' if needed. */
1733 if (static_memfuncp)
1734 {
1735 argvec[1] = argvec[0];
1736 nargs--;
1737 argvec++;
1738 }
1739 }
1740 else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
1741 {
1742 /* Pointer to member. argvec[1] is already set up. */
1743 argvec[0] = arg1;
1744 }
1745 else if (op == OP_VAR_VALUE || (op == OP_SCOPE && function != NULL))
1746 {
1747 /* Non-member function being called. */
1748 /* fn: This can only be done for C++ functions. A C-style function
1749 in a C++ program, for instance, does not have the fields that
1750 are expected here. */
1751
1752 if (overload_resolution && (exp->language_defn->la_language
1753 == language_cplus))
1754 {
1755 /* Language is C++, do some overload resolution before
1756 evaluation. */
1757 struct symbol *symp;
1758 int no_adl = 0;
1759
1760 /* If a scope has been specified disable ADL. */
1761 if (op == OP_SCOPE)
1762 no_adl = 1;
1763
1764 if (op == OP_VAR_VALUE)
1765 function = exp->elts[save_pos1+2].symbol;
1766
1767 (void) find_overload_match (&argvec[1], nargs,
1768 NULL, /* no need for name */
1769 NON_METHOD, /* not method */
1770 NULL, function, /* the function */
1771 NULL, &symp, NULL, no_adl, noside);
1772
1773 if (op == OP_VAR_VALUE)
1774 {
1775 /* Now fix the expression being evaluated. */
1776 exp->elts[save_pos1+2].symbol = symp;
1777 argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1,
1778 noside);
1779 }
1780 else
1781 argvec[0] = value_of_variable (symp, get_selected_block (0));
1782 }
1783 else
1784 {
1785 /* Not C++, or no overload resolution allowed. */
1786 /* Nothing to be done; argvec already correctly set up. */
1787 }
1788 }
1789 else
1790 {
1791 /* It is probably a C-style function. */
1792 /* Nothing to be done; argvec already correctly set up. */
1793 }
1794
1795 do_call_it:
1796
1797 if (argvec[0] == NULL)
1798 error (_("Cannot evaluate function -- may be inlined"));
1799 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1800 {
1801 /* If the return type doesn't look like a function type,
1802 call an error. This can happen if somebody tries to turn
1803 a variable into a function call. */
1804
1805 struct type *ftype = value_type (argvec[0]);
1806
1807 if (TYPE_CODE (ftype) == TYPE_CODE_INTERNAL_FUNCTION)
1808 {
1809 /* We don't know anything about what the internal
1810 function might return, but we have to return
1811 something. */
1812 return value_zero (builtin_type (exp->gdbarch)->builtin_int,
1813 not_lval);
1814 }
1815 else if (TYPE_CODE (ftype) == TYPE_CODE_XMETHOD)
1816 {
1817 struct type *return_type
1818 = result_type_of_xmethod (argvec[0], nargs, argvec + 1);
1819
1820 if (return_type == NULL)
1821 error (_("Xmethod is missing return type."));
1822 return value_zero (return_type, not_lval);
1823 }
1824 else if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
1825 || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
1826 {
1827 struct type *return_type = TYPE_TARGET_TYPE (ftype);
1828
1829 if (return_type == NULL)
1830 return_type = expect_type;
1831
1832 if (return_type == NULL)
1833 error_call_unknown_return_type (var_func_name);
1834
1835 return allocate_value (return_type);
1836 }
1837 else
1838 error (_("Expression of type other than "
1839 "\"Function returning ...\" used as function"));
1840 }
1841 switch (TYPE_CODE (value_type (argvec[0])))
1842 {
1843 case TYPE_CODE_INTERNAL_FUNCTION:
1844 return call_internal_function (exp->gdbarch, exp->language_defn,
1845 argvec[0], nargs, argvec + 1);
1846 case TYPE_CODE_XMETHOD:
1847 return call_xmethod (argvec[0], nargs, argvec + 1);
1848 default:
1849 return call_function_by_hand (argvec[0],
1850 expect_type, nargs, argvec + 1);
1851 }
1852 /* pai: FIXME save value from call_function_by_hand, then adjust
1853 pc by adjust_fn_pc if +ve. */
1854
1855 case OP_F77_UNDETERMINED_ARGLIST:
1856
1857 /* Remember that in F77, functions, substring ops and
1858 array subscript operations cannot be disambiguated
1859 at parse time. We have made all array subscript operations,
1860 substring operations as well as function calls come here
1861 and we now have to discover what the heck this thing actually was.
1862 If it is a function, we process just as if we got an OP_FUNCALL. */
1863
1864 nargs = longest_to_int (exp->elts[pc + 1].longconst);
1865 (*pos) += 2;
1866
1867 /* First determine the type code we are dealing with. */
1868 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1869 type = check_typedef (value_type (arg1));
1870 code = TYPE_CODE (type);
1871
1872 if (code == TYPE_CODE_PTR)
1873 {
1874 /* Fortran always passes variable to subroutines as pointer.
1875 So we need to look into its target type to see if it is
1876 array, string or function. If it is, we need to switch
1877 to the target value the original one points to. */
1878 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1879
1880 if (TYPE_CODE (target_type) == TYPE_CODE_ARRAY
1881 || TYPE_CODE (target_type) == TYPE_CODE_STRING
1882 || TYPE_CODE (target_type) == TYPE_CODE_FUNC)
1883 {
1884 arg1 = value_ind (arg1);
1885 type = check_typedef (value_type (arg1));
1886 code = TYPE_CODE (type);
1887 }
1888 }
1889
1890 switch (code)
1891 {
1892 case TYPE_CODE_ARRAY:
1893 if (exp->elts[*pos].opcode == OP_RANGE)
1894 return value_f90_subarray (arg1, exp, pos, noside);
1895 else
1896 goto multi_f77_subscript;
1897
1898 case TYPE_CODE_STRING:
1899 if (exp->elts[*pos].opcode == OP_RANGE)
1900 return value_f90_subarray (arg1, exp, pos, noside);
1901 else
1902 {
1903 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1904 return value_subscript (arg1, value_as_long (arg2));
1905 }
1906
1907 case TYPE_CODE_PTR:
1908 case TYPE_CODE_FUNC:
1909 /* It's a function call. */
1910 /* Allocate arg vector, including space for the function to be
1911 called in argvec[0] and a terminating NULL. */
1912 argvec = (struct value **)
1913 alloca (sizeof (struct value *) * (nargs + 2));
1914 argvec[0] = arg1;
1915 tem = 1;
1916 for (; tem <= nargs; tem++)
1917 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
1918 argvec[tem] = 0; /* signal end of arglist */
1919 if (noside == EVAL_SKIP)
1920 return eval_skip_value (exp);
1921 goto do_call_it;
1922
1923 default:
1924 error (_("Cannot perform substring on this type"));
1925 }
1926
1927 case OP_COMPLEX:
1928 /* We have a complex number, There should be 2 floating
1929 point numbers that compose it. */
1930 (*pos) += 2;
1931 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1932 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1933
1934 return value_literal_complex (arg1, arg2, exp->elts[pc + 1].type);
1935
1936 case STRUCTOP_STRUCT:
1937 tem = longest_to_int (exp->elts[pc + 1].longconst);
1938 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1939 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1940 if (noside == EVAL_SKIP)
1941 return eval_skip_value (exp);
1942 arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
1943 NULL, "structure");
1944 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1945 arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
1946 return arg3;
1947
1948 case STRUCTOP_PTR:
1949 tem = longest_to_int (exp->elts[pc + 1].longconst);
1950 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1951 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1952 if (noside == EVAL_SKIP)
1953 return eval_skip_value (exp);
1954
1955 /* Check to see if operator '->' has been overloaded. If so replace
1956 arg1 with the value returned by evaluating operator->(). */
1957 while (unop_user_defined_p (op, arg1))
1958 {
1959 struct value *value = NULL;
1960 TRY
1961 {
1962 value = value_x_unop (arg1, op, noside);
1963 }
1964
1965 CATCH (except, RETURN_MASK_ERROR)
1966 {
1967 if (except.error == NOT_FOUND_ERROR)
1968 break;
1969 else
1970 throw_exception (except);
1971 }
1972 END_CATCH
1973
1974 arg1 = value;
1975 }
1976
1977 /* JYG: if print object is on we need to replace the base type
1978 with rtti type in order to continue on with successful
1979 lookup of member / method only available in the rtti type. */
1980 {
1981 struct type *type = value_type (arg1);
1982 struct type *real_type;
1983 int full, using_enc;
1984 LONGEST top;
1985 struct value_print_options opts;
1986
1987 get_user_print_options (&opts);
1988 if (opts.objectprint && TYPE_TARGET_TYPE(type)
1989 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
1990 {
1991 real_type = value_rtti_indirect_type (arg1, &full, &top,
1992 &using_enc);
1993 if (real_type)
1994 arg1 = value_cast (real_type, arg1);
1995 }
1996 }
1997
1998 arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
1999 NULL, "structure pointer");
2000 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2001 arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
2002 return arg3;
2003
2004 case STRUCTOP_MEMBER:
2005 case STRUCTOP_MPTR:
2006 if (op == STRUCTOP_MEMBER)
2007 arg1 = evaluate_subexp_for_address (exp, pos, noside);
2008 else
2009 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2010
2011 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2012
2013 if (noside == EVAL_SKIP)
2014 return eval_skip_value (exp);
2015
2016 type = check_typedef (value_type (arg2));
2017 switch (TYPE_CODE (type))
2018 {
2019 case TYPE_CODE_METHODPTR:
2020 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2021 return value_zero (TYPE_TARGET_TYPE (type), not_lval);
2022 else
2023 {
2024 arg2 = cplus_method_ptr_to_value (&arg1, arg2);
2025 gdb_assert (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR);
2026 return value_ind (arg2);
2027 }
2028
2029 case TYPE_CODE_MEMBERPTR:
2030 /* Now, convert these values to an address. */
2031 arg1 = value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type)),
2032 arg1, 1);
2033
2034 mem_offset = value_as_long (arg2);
2035
2036 arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
2037 value_as_long (arg1) + mem_offset);
2038 return value_ind (arg3);
2039
2040 default:
2041 error (_("non-pointer-to-member value used "
2042 "in pointer-to-member construct"));
2043 }
2044
2045 case TYPE_INSTANCE:
2046 {
2047 type_instance_flags flags
2048 = (type_instance_flag_value) longest_to_int (exp->elts[pc + 1].longconst);
2049 nargs = longest_to_int (exp->elts[pc + 2].longconst);
2050 arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
2051 for (ix = 0; ix < nargs; ++ix)
2052 arg_types[ix] = exp->elts[pc + 2 + ix + 1].type;
2053
2054 expect_type = make_params (flags, nargs, arg_types);
2055 *(pos) += 4 + nargs;
2056 arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
2057 xfree (TYPE_FIELDS (expect_type));
2058 xfree (TYPE_MAIN_TYPE (expect_type));
2059 xfree (expect_type);
2060 return arg1;
2061 }
2062
2063 case BINOP_CONCAT:
2064 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
2065 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
2066 if (noside == EVAL_SKIP)
2067 return eval_skip_value (exp);
2068 if (binop_user_defined_p (op, arg1, arg2))
2069 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2070 else
2071 return value_concat (arg1, arg2);
2072
2073 case BINOP_ASSIGN:
2074 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2075 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
2076
2077 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2078 return arg1;
2079 if (binop_user_defined_p (op, arg1, arg2))
2080 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2081 else
2082 return value_assign (arg1, arg2);
2083
2084 case BINOP_ASSIGN_MODIFY:
2085 (*pos) += 2;
2086 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2087 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
2088 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2089 return arg1;
2090 op = exp->elts[pc + 1].opcode;
2091 if (binop_user_defined_p (op, arg1, arg2))
2092 return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
2093 else if (op == BINOP_ADD && ptrmath_type_p (exp->language_defn,
2094 value_type (arg1))
2095 && is_integral_type (value_type (arg2)))
2096 arg2 = value_ptradd (arg1, value_as_long (arg2));
2097 else if (op == BINOP_SUB && ptrmath_type_p (exp->language_defn,
2098 value_type (arg1))
2099 && is_integral_type (value_type (arg2)))
2100 arg2 = value_ptradd (arg1, - value_as_long (arg2));
2101 else
2102 {
2103 struct value *tmp = arg1;
2104
2105 /* For shift and integer exponentiation operations,
2106 only promote the first argument. */
2107 if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
2108 && is_integral_type (value_type (arg2)))
2109 unop_promote (exp->language_defn, exp->gdbarch, &tmp);
2110 else
2111 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
2112
2113 arg2 = value_binop (tmp, arg2, op);
2114 }
2115 return value_assign (arg1, arg2);
2116
2117 case BINOP_ADD:
2118 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
2119 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
2120 if (noside == EVAL_SKIP)
2121 return eval_skip_value (exp);
2122 if (binop_user_defined_p (op, arg1, arg2))
2123 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2124 else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
2125 && is_integral_type (value_type (arg2)))
2126 return value_ptradd (arg1, value_as_long (arg2));
2127 else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
2128 && is_integral_type (value_type (arg1)))
2129 return value_ptradd (arg2, value_as_long (arg1));
2130 else
2131 {
2132 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2133 return value_binop (arg1, arg2, BINOP_ADD);
2134 }
2135
2136 case BINOP_SUB:
2137 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
2138 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
2139 if (noside == EVAL_SKIP)
2140 return eval_skip_value (exp);
2141 if (binop_user_defined_p (op, arg1, arg2))
2142 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2143 else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
2144 && ptrmath_type_p (exp->language_defn, value_type (arg2)))
2145 {
2146 /* FIXME -- should be ptrdiff_t */
2147 type = builtin_type (exp->gdbarch)->builtin_long;
2148 return value_from_longest (type, value_ptrdiff (arg1, arg2));
2149 }
2150 else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
2151 && is_integral_type (value_type (arg2)))
2152 return value_ptradd (arg1, - value_as_long (arg2));
2153 else
2154 {
2155 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2156 return value_binop (arg1, arg2, BINOP_SUB);
2157 }
2158
2159 case BINOP_EXP:
2160 case BINOP_MUL:
2161 case BINOP_DIV:
2162 case BINOP_INTDIV:
2163 case BINOP_REM:
2164 case BINOP_MOD:
2165 case BINOP_LSH:
2166 case BINOP_RSH:
2167 case BINOP_BITWISE_AND:
2168 case BINOP_BITWISE_IOR:
2169 case BINOP_BITWISE_XOR:
2170 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2171 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2172 if (noside == EVAL_SKIP)
2173 return eval_skip_value (exp);
2174 if (binop_user_defined_p (op, arg1, arg2))
2175 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2176 else
2177 {
2178 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
2179 fudge arg2 to avoid division-by-zero, the caller is
2180 (theoretically) only looking for the type of the result. */
2181 if (noside == EVAL_AVOID_SIDE_EFFECTS
2182 /* ??? Do we really want to test for BINOP_MOD here?
2183 The implementation of value_binop gives it a well-defined
2184 value. */
2185 && (op == BINOP_DIV
2186 || op == BINOP_INTDIV
2187 || op == BINOP_REM
2188 || op == BINOP_MOD)
2189 && value_logical_not (arg2))
2190 {
2191 struct value *v_one, *retval;
2192
2193 v_one = value_one (value_type (arg2));
2194 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &v_one);
2195 retval = value_binop (arg1, v_one, op);
2196 return retval;
2197 }
2198 else
2199 {
2200 /* For shift and integer exponentiation operations,
2201 only promote the first argument. */
2202 if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
2203 && is_integral_type (value_type (arg2)))
2204 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
2205 else
2206 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2207
2208 return value_binop (arg1, arg2, op);
2209 }
2210 }
2211
2212 case BINOP_SUBSCRIPT:
2213 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2214 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2215 if (noside == EVAL_SKIP)
2216 return eval_skip_value (exp);
2217 if (binop_user_defined_p (op, arg1, arg2))
2218 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2219 else
2220 {
2221 /* If the user attempts to subscript something that is not an
2222 array or pointer type (like a plain int variable for example),
2223 then report this as an error. */
2224
2225 arg1 = coerce_ref (arg1);
2226 type = check_typedef (value_type (arg1));
2227 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
2228 && TYPE_CODE (type) != TYPE_CODE_PTR)
2229 {
2230 if (TYPE_NAME (type))
2231 error (_("cannot subscript something of type `%s'"),
2232 TYPE_NAME (type));
2233 else
2234 error (_("cannot subscript requested type"));
2235 }
2236
2237 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2238 return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
2239 else
2240 return value_subscript (arg1, value_as_long (arg2));
2241 }
2242 case MULTI_SUBSCRIPT:
2243 (*pos) += 2;
2244 nargs = longest_to_int (exp->elts[pc + 1].longconst);
2245 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
2246 while (nargs-- > 0)
2247 {
2248 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
2249 /* FIXME: EVAL_SKIP handling may not be correct. */
2250 if (noside == EVAL_SKIP)
2251 {
2252 if (nargs > 0)
2253 continue;
2254 return eval_skip_value (exp);
2255 }
2256 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
2257 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2258 {
2259 /* If the user attempts to subscript something that has no target
2260 type (like a plain int variable for example), then report this
2261 as an error. */
2262
2263 type = TYPE_TARGET_TYPE (check_typedef (value_type (arg1)));
2264 if (type != NULL)
2265 {
2266 arg1 = value_zero (type, VALUE_LVAL (arg1));
2267 noside = EVAL_SKIP;
2268 continue;
2269 }
2270 else
2271 {
2272 error (_("cannot subscript something of type `%s'"),
2273 TYPE_NAME (value_type (arg1)));
2274 }
2275 }
2276
2277 if (binop_user_defined_p (op, arg1, arg2))
2278 {
2279 arg1 = value_x_binop (arg1, arg2, op, OP_NULL, noside);
2280 }
2281 else
2282 {
2283 arg1 = coerce_ref (arg1);
2284 type = check_typedef (value_type (arg1));
2285
2286 switch (TYPE_CODE (type))
2287 {
2288 case TYPE_CODE_PTR:
2289 case TYPE_CODE_ARRAY:
2290 case TYPE_CODE_STRING:
2291 arg1 = value_subscript (arg1, value_as_long (arg2));
2292 break;
2293
2294 default:
2295 if (TYPE_NAME (type))
2296 error (_("cannot subscript something of type `%s'"),
2297 TYPE_NAME (type));
2298 else
2299 error (_("cannot subscript requested type"));
2300 }
2301 }
2302 }
2303 return (arg1);
2304
2305 multi_f77_subscript:
2306 {
2307 LONGEST subscript_array[MAX_FORTRAN_DIMS];
2308 int ndimensions = 1, i;
2309 struct value *array = arg1;
2310
2311 if (nargs > MAX_FORTRAN_DIMS)
2312 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
2313
2314 ndimensions = calc_f77_array_dims (type);
2315
2316 if (nargs != ndimensions)
2317 error (_("Wrong number of subscripts"));
2318
2319 gdb_assert (nargs > 0);
2320
2321 /* Now that we know we have a legal array subscript expression
2322 let us actually find out where this element exists in the array. */
2323
2324 /* Take array indices left to right. */
2325 for (i = 0; i < nargs; i++)
2326 {
2327 /* Evaluate each subscript; it must be a legal integer in F77. */
2328 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
2329
2330 /* Fill in the subscript array. */
2331
2332 subscript_array[i] = value_as_long (arg2);
2333 }
2334
2335 /* Internal type of array is arranged right to left. */
2336 for (i = nargs; i > 0; i--)
2337 {
2338 struct type *array_type = check_typedef (value_type (array));
2339 LONGEST index = subscript_array[i - 1];
2340
2341 array = value_subscripted_rvalue (array, index,
2342 f77_get_lowerbound (array_type));
2343 }
2344
2345 return array;
2346 }
2347
2348 case BINOP_LOGICAL_AND:
2349 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2350 if (noside == EVAL_SKIP)
2351 {
2352 evaluate_subexp (NULL_TYPE, exp, pos, noside);
2353 return eval_skip_value (exp);
2354 }
2355
2356 oldpos = *pos;
2357 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2358 *pos = oldpos;
2359
2360 if (binop_user_defined_p (op, arg1, arg2))
2361 {
2362 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2363 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2364 }
2365 else
2366 {
2367 tem = value_logical_not (arg1);
2368 arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
2369 (tem ? EVAL_SKIP : noside));
2370 type = language_bool_type (exp->language_defn, exp->gdbarch);
2371 return value_from_longest (type,
2372 (LONGEST) (!tem && !value_logical_not (arg2)));
2373 }
2374
2375 case BINOP_LOGICAL_OR:
2376 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2377 if (noside == EVAL_SKIP)
2378 {
2379 evaluate_subexp (NULL_TYPE, exp, pos, noside);
2380 return eval_skip_value (exp);
2381 }
2382
2383 oldpos = *pos;
2384 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2385 *pos = oldpos;
2386
2387 if (binop_user_defined_p (op, arg1, arg2))
2388 {
2389 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2390 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2391 }
2392 else
2393 {
2394 tem = value_logical_not (arg1);
2395 arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
2396 (!tem ? EVAL_SKIP : noside));
2397 type = language_bool_type (exp->language_defn, exp->gdbarch);
2398 return value_from_longest (type,
2399 (LONGEST) (!tem || !value_logical_not (arg2)));
2400 }
2401
2402 case BINOP_EQUAL:
2403 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2404 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
2405 if (noside == EVAL_SKIP)
2406 return eval_skip_value (exp);
2407 if (binop_user_defined_p (op, arg1, arg2))
2408 {
2409 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2410 }
2411 else
2412 {
2413 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2414 tem = value_equal (arg1, arg2);
2415 type = language_bool_type (exp->language_defn, exp->gdbarch);
2416 return value_from_longest (type, (LONGEST) tem);
2417 }
2418
2419 case BINOP_NOTEQUAL:
2420 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2421 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
2422 if (noside == EVAL_SKIP)
2423 return eval_skip_value (exp);
2424 if (binop_user_defined_p (op, arg1, arg2))
2425 {
2426 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2427 }
2428 else
2429 {
2430 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2431 tem = value_equal (arg1, arg2);
2432 type = language_bool_type (exp->language_defn, exp->gdbarch);
2433 return value_from_longest (type, (LONGEST) ! tem);
2434 }
2435
2436 case BINOP_LESS:
2437 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2438 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
2439 if (noside == EVAL_SKIP)
2440 return eval_skip_value (exp);
2441 if (binop_user_defined_p (op, arg1, arg2))
2442 {
2443 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2444 }
2445 else
2446 {
2447 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2448 tem = value_less (arg1, arg2);
2449 type = language_bool_type (exp->language_defn, exp->gdbarch);
2450 return value_from_longest (type, (LONGEST) tem);
2451 }
2452
2453 case BINOP_GTR:
2454 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2455 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
2456 if (noside == EVAL_SKIP)
2457 return eval_skip_value (exp);
2458 if (binop_user_defined_p (op, arg1, arg2))
2459 {
2460 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2461 }
2462 else
2463 {
2464 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2465 tem = value_less (arg2, arg1);
2466 type = language_bool_type (exp->language_defn, exp->gdbarch);
2467 return value_from_longest (type, (LONGEST) tem);
2468 }
2469
2470 case BINOP_GEQ:
2471 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2472 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
2473 if (noside == EVAL_SKIP)
2474 return eval_skip_value (exp);
2475 if (binop_user_defined_p (op, arg1, arg2))
2476 {
2477 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2478 }
2479 else
2480 {
2481 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2482 tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
2483 type = language_bool_type (exp->language_defn, exp->gdbarch);
2484 return value_from_longest (type, (LONGEST) tem);
2485 }
2486
2487 case BINOP_LEQ:
2488 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2489 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
2490 if (noside == EVAL_SKIP)
2491 return eval_skip_value (exp);
2492 if (binop_user_defined_p (op, arg1, arg2))
2493 {
2494 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2495 }
2496 else
2497 {
2498 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
2499 tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
2500 type = language_bool_type (exp->language_defn, exp->gdbarch);
2501 return value_from_longest (type, (LONGEST) tem);
2502 }
2503
2504 case BINOP_REPEAT:
2505 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2506 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2507 if (noside == EVAL_SKIP)
2508 return eval_skip_value (exp);
2509 type = check_typedef (value_type (arg2));
2510 if (TYPE_CODE (type) != TYPE_CODE_INT
2511 && TYPE_CODE (type) != TYPE_CODE_ENUM)
2512 error (_("Non-integral right operand for \"@\" operator."));
2513 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2514 {
2515 return allocate_repeat_value (value_type (arg1),
2516 longest_to_int (value_as_long (arg2)));
2517 }
2518 else
2519 return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
2520
2521 case BINOP_COMMA:
2522 evaluate_subexp (NULL_TYPE, exp, pos, noside);
2523 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
2524
2525 case UNOP_PLUS:
2526 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2527 if (noside == EVAL_SKIP)
2528 return eval_skip_value (exp);
2529 if (unop_user_defined_p (op, arg1))
2530 return value_x_unop (arg1, op, noside);
2531 else
2532 {
2533 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
2534 return value_pos (arg1);
2535 }
2536
2537 case UNOP_NEG:
2538 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2539 if (noside == EVAL_SKIP)
2540 return eval_skip_value (exp);
2541 if (unop_user_defined_p (op, arg1))
2542 return value_x_unop (arg1, op, noside);
2543 else
2544 {
2545 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
2546 return value_neg (arg1);
2547 }
2548
2549 case UNOP_COMPLEMENT:
2550 /* C++: check for and handle destructor names. */
2551
2552 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2553 if (noside == EVAL_SKIP)
2554 return eval_skip_value (exp);
2555 if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
2556 return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
2557 else
2558 {
2559 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
2560 return value_complement (arg1);
2561 }
2562
2563 case UNOP_LOGICAL_NOT:
2564 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2565 if (noside == EVAL_SKIP)
2566 return eval_skip_value (exp);
2567 if (unop_user_defined_p (op, arg1))
2568 return value_x_unop (arg1, op, noside);
2569 else
2570 {
2571 type = language_bool_type (exp->language_defn, exp->gdbarch);
2572 return value_from_longest (type, (LONGEST) value_logical_not (arg1));
2573 }
2574
2575 case UNOP_IND:
2576 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
2577 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
2578 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2579 type = check_typedef (value_type (arg1));
2580 if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
2581 || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
2582 error (_("Attempt to dereference pointer "
2583 "to member without an object"));
2584 if (noside == EVAL_SKIP)
2585 return eval_skip_value (exp);
2586 if (unop_user_defined_p (op, arg1))
2587 return value_x_unop (arg1, op, noside);
2588 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
2589 {
2590 type = check_typedef (value_type (arg1));
2591 if (TYPE_CODE (type) == TYPE_CODE_PTR
2592 || TYPE_IS_REFERENCE (type)
2593 /* In C you can dereference an array to get the 1st elt. */
2594 || TYPE_CODE (type) == TYPE_CODE_ARRAY
2595 )
2596 return value_zero (TYPE_TARGET_TYPE (type),
2597 lval_memory);
2598 else if (TYPE_CODE (type) == TYPE_CODE_INT)
2599 /* GDB allows dereferencing an int. */
2600 return value_zero (builtin_type (exp->gdbarch)->builtin_int,
2601 lval_memory);
2602 else
2603 error (_("Attempt to take contents of a non-pointer value."));
2604 }
2605
2606 /* Allow * on an integer so we can cast it to whatever we want.
2607 This returns an int, which seems like the most C-like thing to
2608 do. "long long" variables are rare enough that
2609 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
2610 if (TYPE_CODE (type) == TYPE_CODE_INT)
2611 return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
2612 (CORE_ADDR) value_as_address (arg1));
2613 return value_ind (arg1);
2614
2615 case UNOP_ADDR:
2616 /* C++: check for and handle pointer to members. */
2617
2618 if (noside == EVAL_SKIP)
2619 {
2620 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
2621 return eval_skip_value (exp);
2622 }
2623 else
2624 {
2625 struct value *retvalp = evaluate_subexp_for_address (exp, pos,
2626 noside);
2627
2628 return retvalp;
2629 }
2630
2631 case UNOP_SIZEOF:
2632 if (noside == EVAL_SKIP)
2633 {
2634 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
2635 return eval_skip_value (exp);
2636 }
2637 return evaluate_subexp_for_sizeof (exp, pos, noside);
2638
2639 case UNOP_CAST:
2640 (*pos) += 2;
2641 type = exp->elts[pc + 1].type;
2642 return evaluate_subexp_for_cast (exp, pos, noside, type);
2643
2644 case UNOP_CAST_TYPE:
2645 arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2646 type = value_type (arg1);
2647 return evaluate_subexp_for_cast (exp, pos, noside, type);
2648
2649 case UNOP_DYNAMIC_CAST:
2650 arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2651 type = value_type (arg1);
2652 arg1 = evaluate_subexp (type, exp, pos, noside);
2653 if (noside == EVAL_SKIP)
2654 return eval_skip_value (exp);
2655 return value_dynamic_cast (type, arg1);
2656
2657 case UNOP_REINTERPRET_CAST:
2658 arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2659 type = value_type (arg1);
2660 arg1 = evaluate_subexp (type, exp, pos, noside);
2661 if (noside == EVAL_SKIP)
2662 return eval_skip_value (exp);
2663 return value_reinterpret_cast (type, arg1);
2664
2665 case UNOP_MEMVAL:
2666 (*pos) += 2;
2667 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2668 if (noside == EVAL_SKIP)
2669 return eval_skip_value (exp);
2670 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2671 return value_zero (exp->elts[pc + 1].type, lval_memory);
2672 else
2673 return value_at_lazy (exp->elts[pc + 1].type,
2674 value_as_address (arg1));
2675
2676 case UNOP_MEMVAL_TYPE:
2677 arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2678 type = value_type (arg1);
2679 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2680 if (noside == EVAL_SKIP)
2681 return eval_skip_value (exp);
2682 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2683 return value_zero (type, lval_memory);
2684 else
2685 return value_at_lazy (type, value_as_address (arg1));
2686
2687 case UNOP_PREINCREMENT:
2688 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2689 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2690 return arg1;
2691 else if (unop_user_defined_p (op, arg1))
2692 {
2693 return value_x_unop (arg1, op, noside);
2694 }
2695 else
2696 {
2697 if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
2698 arg2 = value_ptradd (arg1, 1);
2699 else
2700 {
2701 struct value *tmp = arg1;
2702
2703 arg2 = value_one (value_type (arg1));
2704 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
2705 arg2 = value_binop (tmp, arg2, BINOP_ADD);
2706 }
2707
2708 return value_assign (arg1, arg2);
2709 }
2710
2711 case UNOP_PREDECREMENT:
2712 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2713 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2714 return arg1;
2715 else if (unop_user_defined_p (op, arg1))
2716 {
2717 return value_x_unop (arg1, op, noside);
2718 }
2719 else
2720 {
2721 if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
2722 arg2 = value_ptradd (arg1, -1);
2723 else
2724 {
2725 struct value *tmp = arg1;
2726
2727 arg2 = value_one (value_type (arg1));
2728 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
2729 arg2 = value_binop (tmp, arg2, BINOP_SUB);
2730 }
2731
2732 return value_assign (arg1, arg2);
2733 }
2734
2735 case UNOP_POSTINCREMENT:
2736 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2737 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2738 return arg1;
2739 else if (unop_user_defined_p (op, arg1))
2740 {
2741 return value_x_unop (arg1, op, noside);
2742 }
2743 else
2744 {
2745 arg3 = value_non_lval (arg1);
2746
2747 if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
2748 arg2 = value_ptradd (arg1, 1);
2749 else
2750 {
2751 struct value *tmp = arg1;
2752
2753 arg2 = value_one (value_type (arg1));
2754 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
2755 arg2 = value_binop (tmp, arg2, BINOP_ADD);
2756 }
2757
2758 value_assign (arg1, arg2);
2759 return arg3;
2760 }
2761
2762 case UNOP_POSTDECREMENT:
2763 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2764 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2765 return arg1;
2766 else if (unop_user_defined_p (op, arg1))
2767 {
2768 return value_x_unop (arg1, op, noside);
2769 }
2770 else
2771 {
2772 arg3 = value_non_lval (arg1);
2773
2774 if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
2775 arg2 = value_ptradd (arg1, -1);
2776 else
2777 {
2778 struct value *tmp = arg1;
2779
2780 arg2 = value_one (value_type (arg1));
2781 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
2782 arg2 = value_binop (tmp, arg2, BINOP_SUB);
2783 }
2784
2785 value_assign (arg1, arg2);
2786 return arg3;
2787 }
2788
2789 case OP_THIS:
2790 (*pos) += 1;
2791 return value_of_this (exp->language_defn);
2792
2793 case OP_TYPE:
2794 /* The value is not supposed to be used. This is here to make it
2795 easier to accommodate expressions that contain types. */
2796 (*pos) += 2;
2797 if (noside == EVAL_SKIP)
2798 return eval_skip_value (exp);
2799 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
2800 return allocate_value (exp->elts[pc + 1].type);
2801 else
2802 error (_("Attempt to use a type name as an expression"));
2803
2804 case OP_TYPEOF:
2805 case OP_DECLTYPE:
2806 if (noside == EVAL_SKIP)
2807 {
2808 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
2809 return eval_skip_value (exp);
2810 }
2811 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
2812 {
2813 enum exp_opcode sub_op = exp->elts[*pos].opcode;
2814 struct value *result;
2815
2816 result = evaluate_subexp (NULL_TYPE, exp, pos,
2817 EVAL_AVOID_SIDE_EFFECTS);
2818
2819 /* 'decltype' has special semantics for lvalues. */
2820 if (op == OP_DECLTYPE
2821 && (sub_op == BINOP_SUBSCRIPT
2822 || sub_op == STRUCTOP_MEMBER
2823 || sub_op == STRUCTOP_MPTR
2824 || sub_op == UNOP_IND
2825 || sub_op == STRUCTOP_STRUCT
2826 || sub_op == STRUCTOP_PTR
2827 || sub_op == OP_SCOPE))
2828 {
2829 struct type *type = value_type (result);
2830
2831 if (!TYPE_IS_REFERENCE (type))
2832 {
2833 type = lookup_lvalue_reference_type (type);
2834 result = allocate_value (type);
2835 }
2836 }
2837
2838 return result;
2839 }
2840 else
2841 error (_("Attempt to use a type as an expression"));
2842
2843 case OP_TYPEID:
2844 {
2845 struct value *result;
2846 enum exp_opcode sub_op = exp->elts[*pos].opcode;
2847
2848 if (sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
2849 result = evaluate_subexp (NULL_TYPE, exp, pos,
2850 EVAL_AVOID_SIDE_EFFECTS);
2851 else
2852 result = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2853
2854 if (noside != EVAL_NORMAL)
2855 return allocate_value (cplus_typeid_type (exp->gdbarch));
2856
2857 return cplus_typeid (result);
2858 }
2859
2860 default:
2861 /* Removing this case and compiling with gcc -Wall reveals that
2862 a lot of cases are hitting this case. Some of these should
2863 probably be removed from expression.h; others are legitimate
2864 expressions which are (apparently) not fully implemented.
2865
2866 If there are any cases landing here which mean a user error,
2867 then they should be separate cases, with more descriptive
2868 error messages. */
2869
2870 error (_("GDB does not (yet) know how to "
2871 "evaluate that kind of expression"));
2872 }
2873
2874 gdb_assert_not_reached ("missed return?");
2875 }
2876 \f
2877 /* Evaluate a subexpression of EXP, at index *POS,
2878 and return the address of that subexpression.
2879 Advance *POS over the subexpression.
2880 If the subexpression isn't an lvalue, get an error.
2881 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2882 then only the type of the result need be correct. */
2883
2884 static struct value *
2885 evaluate_subexp_for_address (struct expression *exp, int *pos,
2886 enum noside noside)
2887 {
2888 enum exp_opcode op;
2889 int pc;
2890 struct symbol *var;
2891 struct value *x;
2892 int tem;
2893
2894 pc = (*pos);
2895 op = exp->elts[pc].opcode;
2896
2897 switch (op)
2898 {
2899 case UNOP_IND:
2900 (*pos)++;
2901 x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2902
2903 /* We can't optimize out "&*" if there's a user-defined operator*. */
2904 if (unop_user_defined_p (op, x))
2905 {
2906 x = value_x_unop (x, op, noside);
2907 goto default_case_after_eval;
2908 }
2909
2910 return coerce_array (x);
2911
2912 case UNOP_MEMVAL:
2913 (*pos) += 3;
2914 return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
2915 evaluate_subexp (NULL_TYPE, exp, pos, noside));
2916
2917 case UNOP_MEMVAL_TYPE:
2918 {
2919 struct type *type;
2920
2921 (*pos) += 1;
2922 x = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2923 type = value_type (x);
2924 return value_cast (lookup_pointer_type (type),
2925 evaluate_subexp (NULL_TYPE, exp, pos, noside));
2926 }
2927
2928 case OP_VAR_VALUE:
2929 var = exp->elts[pc + 2].symbol;
2930
2931 /* C++: The "address" of a reference should yield the address
2932 * of the object pointed to. Let value_addr() deal with it. */
2933 if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var)))
2934 goto default_case;
2935
2936 (*pos) += 4;
2937 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2938 {
2939 struct type *type =
2940 lookup_pointer_type (SYMBOL_TYPE (var));
2941 enum address_class sym_class = SYMBOL_CLASS (var);
2942
2943 if (sym_class == LOC_CONST
2944 || sym_class == LOC_CONST_BYTES
2945 || sym_class == LOC_REGISTER)
2946 error (_("Attempt to take address of register or constant."));
2947
2948 return
2949 value_zero (type, not_lval);
2950 }
2951 else
2952 return address_of_variable (var, exp->elts[pc + 1].block);
2953
2954 case OP_VAR_MSYM_VALUE:
2955 {
2956 (*pos) += 4;
2957
2958 value *val = evaluate_var_msym_value (noside,
2959 exp->elts[pc + 1].objfile,
2960 exp->elts[pc + 2].msymbol);
2961 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2962 {
2963 struct type *type = lookup_pointer_type (value_type (val));
2964 return value_zero (type, not_lval);
2965 }
2966 else
2967 return value_addr (val);
2968 }
2969
2970 case OP_SCOPE:
2971 tem = longest_to_int (exp->elts[pc + 2].longconst);
2972 (*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
2973 x = value_aggregate_elt (exp->elts[pc + 1].type,
2974 &exp->elts[pc + 3].string,
2975 NULL, 1, noside);
2976 if (x == NULL)
2977 error (_("There is no field named %s"), &exp->elts[pc + 3].string);
2978 return x;
2979
2980 default:
2981 default_case:
2982 x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2983 default_case_after_eval:
2984 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2985 {
2986 struct type *type = check_typedef (value_type (x));
2987
2988 if (TYPE_IS_REFERENCE (type))
2989 return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
2990 not_lval);
2991 else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
2992 return value_zero (lookup_pointer_type (value_type (x)),
2993 not_lval);
2994 else
2995 error (_("Attempt to take address of "
2996 "value not located in memory."));
2997 }
2998 return value_addr (x);
2999 }
3000 }
3001
3002 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
3003 When used in contexts where arrays will be coerced anyway, this is
3004 equivalent to `evaluate_subexp' but much faster because it avoids
3005 actually fetching array contents (perhaps obsolete now that we have
3006 value_lazy()).
3007
3008 Note that we currently only do the coercion for C expressions, where
3009 arrays are zero based and the coercion is correct. For other languages,
3010 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
3011 to decide if coercion is appropriate. */
3012
3013 struct value *
3014 evaluate_subexp_with_coercion (struct expression *exp,
3015 int *pos, enum noside noside)
3016 {
3017 enum exp_opcode op;
3018 int pc;
3019 struct value *val;
3020 struct symbol *var;
3021 struct type *type;
3022
3023 pc = (*pos);
3024 op = exp->elts[pc].opcode;
3025
3026 switch (op)
3027 {
3028 case OP_VAR_VALUE:
3029 var = exp->elts[pc + 2].symbol;
3030 type = check_typedef (SYMBOL_TYPE (var));
3031 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
3032 && !TYPE_VECTOR (type)
3033 && CAST_IS_CONVERSION (exp->language_defn))
3034 {
3035 (*pos) += 4;
3036 val = address_of_variable (var, exp->elts[pc + 1].block);
3037 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
3038 val);
3039 }
3040 /* FALLTHROUGH */
3041
3042 default:
3043 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
3044 }
3045 }
3046
3047 /* Evaluate a subexpression of EXP, at index *POS,
3048 and return a value for the size of that subexpression.
3049 Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
3050 we allow side-effects on the operand if its type is a variable
3051 length array. */
3052
3053 static struct value *
3054 evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
3055 enum noside noside)
3056 {
3057 /* FIXME: This should be size_t. */
3058 struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
3059 enum exp_opcode op;
3060 int pc;
3061 struct type *type;
3062 struct value *val;
3063
3064 pc = (*pos);
3065 op = exp->elts[pc].opcode;
3066
3067 switch (op)
3068 {
3069 /* This case is handled specially
3070 so that we avoid creating a value for the result type.
3071 If the result type is very big, it's desirable not to
3072 create a value unnecessarily. */
3073 case UNOP_IND:
3074 (*pos)++;
3075 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
3076 type = check_typedef (value_type (val));
3077 if (TYPE_CODE (type) != TYPE_CODE_PTR
3078 && !TYPE_IS_REFERENCE (type)
3079 && TYPE_CODE (type) != TYPE_CODE_ARRAY)
3080 error (_("Attempt to take contents of a non-pointer value."));
3081 type = TYPE_TARGET_TYPE (type);
3082 if (is_dynamic_type (type))
3083 type = value_type (value_ind (val));
3084 return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
3085
3086 case UNOP_MEMVAL:
3087 (*pos) += 3;
3088 type = exp->elts[pc + 1].type;
3089 break;
3090
3091 case UNOP_MEMVAL_TYPE:
3092 (*pos) += 1;
3093 val = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
3094 type = value_type (val);
3095 break;
3096
3097 case OP_VAR_VALUE:
3098 type = SYMBOL_TYPE (exp->elts[pc + 2].symbol);
3099 if (is_dynamic_type (type))
3100 {
3101 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
3102 type = value_type (val);
3103 }
3104 else
3105 (*pos) += 4;
3106 break;
3107
3108 case OP_VAR_MSYM_VALUE:
3109 {
3110 (*pos) += 4;
3111
3112 minimal_symbol *msymbol = exp->elts[pc + 2].msymbol;
3113 value *val = evaluate_var_msym_value (noside,
3114 exp->elts[pc + 1].objfile,
3115 msymbol);
3116
3117 type = value_type (val);
3118 if (TYPE_CODE (type) == TYPE_CODE_ERROR)
3119 error_unknown_type (MSYMBOL_PRINT_NAME (msymbol));
3120
3121 return value_from_longest (size_type, TYPE_LENGTH (type));
3122 }
3123 break;
3124
3125 /* Deal with the special case if NOSIDE is EVAL_NORMAL and the resulting
3126 type of the subscript is a variable length array type. In this case we
3127 must re-evaluate the right hand side of the subcription to allow
3128 side-effects. */
3129 case BINOP_SUBSCRIPT:
3130 if (noside == EVAL_NORMAL)
3131 {
3132 int pc = (*pos) + 1;
3133
3134 val = evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
3135 type = check_typedef (value_type (val));
3136 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
3137 {
3138 type = check_typedef (TYPE_TARGET_TYPE (type));
3139 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
3140 {
3141 type = TYPE_INDEX_TYPE (type);
3142 /* Only re-evaluate the right hand side if the resulting type
3143 is a variable length type. */
3144 if (TYPE_RANGE_DATA (type)->flag_bound_evaluated)
3145 {
3146 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
3147 return value_from_longest
3148 (size_type, (LONGEST) TYPE_LENGTH (value_type (val)));
3149 }
3150 }
3151 }
3152 }
3153
3154 /* Fall through. */
3155
3156 default:
3157 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
3158 type = value_type (val);
3159 break;
3160 }
3161
3162 /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
3163 "When applied to a reference or a reference type, the result is
3164 the size of the referenced type." */
3165 type = check_typedef (type);
3166 if (exp->language_defn->la_language == language_cplus
3167 && (TYPE_IS_REFERENCE (type)))
3168 type = check_typedef (TYPE_TARGET_TYPE (type));
3169 return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
3170 }
3171
3172 /* Evaluate a subexpression of EXP, at index *POS, and return a value
3173 for that subexpression cast to TO_TYPE. Advance *POS over the
3174 subexpression. */
3175
3176 static value *
3177 evaluate_subexp_for_cast (expression *exp, int *pos,
3178 enum noside noside,
3179 struct type *to_type)
3180 {
3181 int pc = *pos;
3182
3183 /* Don't let symbols be evaluated with evaluate_subexp because that
3184 throws an "unknown type" error for no-debug data symbols.
3185 Instead, we want the cast to reinterpret the symbol. */
3186 if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE
3187 || exp->elts[pc].opcode == OP_VAR_VALUE)
3188 {
3189 (*pos) += 4;
3190
3191 value *val;
3192 if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE)
3193 {
3194 if (noside == EVAL_AVOID_SIDE_EFFECTS)
3195 return value_zero (to_type, not_lval);
3196
3197 val = evaluate_var_msym_value (noside,
3198 exp->elts[pc + 1].objfile,
3199 exp->elts[pc + 2].msymbol);
3200 }
3201 else
3202 val = evaluate_var_value (noside,
3203 exp->elts[pc + 1].block,
3204 exp->elts[pc + 2].symbol);
3205
3206 if (noside == EVAL_SKIP)
3207 return eval_skip_value (exp);
3208
3209 val = value_cast (to_type, val);
3210
3211 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
3212 if (VALUE_LVAL (val) == lval_memory)
3213 {
3214 if (value_lazy (val))
3215 value_fetch_lazy (val);
3216 VALUE_LVAL (val) = not_lval;
3217 }
3218 return val;
3219 }
3220
3221 value *val = evaluate_subexp (to_type, exp, pos, noside);
3222 if (noside == EVAL_SKIP)
3223 return eval_skip_value (exp);
3224 return value_cast (to_type, val);
3225 }
3226
3227 /* Parse a type expression in the string [P..P+LENGTH). */
3228
3229 struct type *
3230 parse_and_eval_type (char *p, int length)
3231 {
3232 char *tmp = (char *) alloca (length + 4);
3233
3234 tmp[0] = '(';
3235 memcpy (tmp + 1, p, length);
3236 tmp[length + 1] = ')';
3237 tmp[length + 2] = '0';
3238 tmp[length + 3] = '\0';
3239 expression_up expr = parse_expression (tmp);
3240 if (expr->elts[0].opcode != UNOP_CAST)
3241 error (_("Internal error in eval_type."));
3242 return expr->elts[1].type;
3243 }
3244
3245 int
3246 calc_f77_array_dims (struct type *array_type)
3247 {
3248 int ndimen = 1;
3249 struct type *tmp_type;
3250
3251 if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
3252 error (_("Can't get dimensions for a non-array type"));
3253
3254 tmp_type = array_type;
3255
3256 while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
3257 {
3258 if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
3259 ++ndimen;
3260 }
3261 return ndimen;
3262 }
This page took 0.09589 seconds and 4 git commands to generate.