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