]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/eval.c
* gdb.fortran/exprs.exp (test_arithmetic_expressions): Add five
[thirdparty/binutils-gdb.git] / gdb / eval.c
CommitLineData
c906108c 1/* Evaluate expressions for GDB.
1bac305b
AC
2
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
990a07ab
AC
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005 Free
5 Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
c906108c
SS
23
24#include "defs.h"
25#include "gdb_string.h"
26#include "symtab.h"
27#include "gdbtypes.h"
28#include "value.h"
29#include "expression.h"
30#include "target.h"
31#include "frame.h"
c5aa993b
JM
32#include "language.h" /* For CAST_IS_CONVERSION */
33#include "f-lang.h" /* for array bound stuff */
015a42b4 34#include "cp-abi.h"
04714b91 35#include "infcall.h"
a9fa03de
AF
36#include "objc-lang.h"
37#include "block.h"
5f9769d1 38#include "parser-defs.h"
d3cbe7ef 39#include "cp-support.h"
c906108c 40
c5aa993b 41/* This is defined in valops.c */
c906108c
SS
42extern int overload_resolution;
43
070ad9f0
DB
44/* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue
45 on with successful lookup for member/method of the rtti type. */
46extern int objectprint;
c906108c
SS
47
48/* Prototypes for local functions. */
49
61051030 50static struct value *evaluate_subexp_for_sizeof (struct expression *, int *);
c906108c 51
61051030
AC
52static struct value *evaluate_subexp_for_address (struct expression *,
53 int *, enum noside);
c906108c 54
61051030
AC
55static struct value *evaluate_subexp (struct type *, struct expression *,
56 int *, enum noside);
c906108c 57
a14ed312 58static char *get_label (struct expression *, int *);
c906108c 59
61051030
AC
60static struct value *evaluate_struct_tuple (struct value *,
61 struct expression *, int *,
62 enum noside, int);
c906108c 63
61051030
AC
64static LONGEST init_array_element (struct value *, struct value *,
65 struct expression *, int *, enum noside,
66 LONGEST, LONGEST);
c906108c 67
61051030 68static struct value *
aa1ee363
AC
69evaluate_subexp (struct type *expect_type, struct expression *exp,
70 int *pos, enum noside noside)
c906108c 71{
5f9769d1
PH
72 return (*exp->language_defn->la_exp_desc->evaluate_exp)
73 (expect_type, exp, pos, noside);
c906108c
SS
74}
75\f
76/* Parse the string EXP as a C expression, evaluate it,
77 and return the result as a number. */
78
79CORE_ADDR
fba45db2 80parse_and_eval_address (char *exp)
c906108c
SS
81{
82 struct expression *expr = parse_expression (exp);
52f0bd74
AC
83 CORE_ADDR addr;
84 struct cleanup *old_chain =
62995fc4 85 make_cleanup (free_current_contents, &expr);
c906108c 86
1aa20aa8 87 addr = value_as_address (evaluate_expression (expr));
c906108c
SS
88 do_cleanups (old_chain);
89 return addr;
90}
91
92/* Like parse_and_eval_address but takes a pointer to a char * variable
93 and advanced that variable across the characters parsed. */
94
95CORE_ADDR
fba45db2 96parse_and_eval_address_1 (char **expptr)
c906108c 97{
c5aa993b 98 struct expression *expr = parse_exp_1 (expptr, (struct block *) 0, 0);
52f0bd74
AC
99 CORE_ADDR addr;
100 struct cleanup *old_chain =
62995fc4 101 make_cleanup (free_current_contents, &expr);
c906108c 102
1aa20aa8 103 addr = value_as_address (evaluate_expression (expr));
c906108c
SS
104 do_cleanups (old_chain);
105 return addr;
106}
107
bb518678
DT
108/* Like parse_and_eval_address, but treats the value of the expression
109 as an integer, not an address, returns a LONGEST, not a CORE_ADDR */
110LONGEST
111parse_and_eval_long (char *exp)
112{
113 struct expression *expr = parse_expression (exp);
52f0bd74
AC
114 LONGEST retval;
115 struct cleanup *old_chain =
bb518678
DT
116 make_cleanup (free_current_contents, &expr);
117
118 retval = value_as_long (evaluate_expression (expr));
119 do_cleanups (old_chain);
120 return (retval);
121}
122
61051030 123struct value *
fba45db2 124parse_and_eval (char *exp)
c906108c
SS
125{
126 struct expression *expr = parse_expression (exp);
61051030 127 struct value *val;
52f0bd74 128 struct cleanup *old_chain =
62995fc4 129 make_cleanup (free_current_contents, &expr);
c906108c
SS
130
131 val = evaluate_expression (expr);
132 do_cleanups (old_chain);
133 return val;
134}
135
136/* Parse up to a comma (or to a closeparen)
137 in the string EXPP as an expression, evaluate it, and return the value.
138 EXPP is advanced to point to the comma. */
139
61051030 140struct value *
fba45db2 141parse_to_comma_and_eval (char **expp)
c906108c
SS
142{
143 struct expression *expr = parse_exp_1 (expp, (struct block *) 0, 1);
61051030 144 struct value *val;
52f0bd74 145 struct cleanup *old_chain =
62995fc4 146 make_cleanup (free_current_contents, &expr);
c906108c
SS
147
148 val = evaluate_expression (expr);
149 do_cleanups (old_chain);
150 return val;
151}
152\f
153/* Evaluate an expression in internal prefix form
154 such as is constructed by parse.y.
155
156 See expression.h for info on the format of an expression. */
157
61051030 158struct value *
fba45db2 159evaluate_expression (struct expression *exp)
c906108c
SS
160{
161 int pc = 0;
162 return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
163}
164
165/* Evaluate an expression, avoiding all memory references
166 and getting a value whose type alone is correct. */
167
61051030 168struct value *
fba45db2 169evaluate_type (struct expression *exp)
c906108c
SS
170{
171 int pc = 0;
172 return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
173}
174
175/* If the next expression is an OP_LABELED, skips past it,
176 returning the label. Otherwise, does nothing and returns NULL. */
177
c5aa993b 178static char *
aa1ee363 179get_label (struct expression *exp, int *pos)
c906108c
SS
180{
181 if (exp->elts[*pos].opcode == OP_LABELED)
182 {
183 int pc = (*pos)++;
184 char *name = &exp->elts[pc + 2].string;
185 int tem = longest_to_int (exp->elts[pc + 1].longconst);
186 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
187 return name;
188 }
189 else
190 return NULL;
191}
192
1b831c93 193/* This function evaluates tuples (in (the deleted) Chill) or
db034ac5 194 brace-initializers (in C/C++) for structure types. */
c906108c 195
61051030
AC
196static struct value *
197evaluate_struct_tuple (struct value *struct_val,
aa1ee363
AC
198 struct expression *exp,
199 int *pos, enum noside noside, int nargs)
c906108c 200{
df407dfe 201 struct type *struct_type = check_typedef (value_type (struct_val));
c906108c
SS
202 struct type *substruct_type = struct_type;
203 struct type *field_type;
204 int fieldno = -1;
205 int variantno = -1;
206 int subfieldno = -1;
c5aa993b 207 while (--nargs >= 0)
c906108c
SS
208 {
209 int pc = *pos;
61051030 210 struct value *val = NULL;
c906108c
SS
211 int nlabels = 0;
212 int bitpos, bitsize;
0fd88904 213 bfd_byte *addr;
c5aa993b 214
c906108c
SS
215 /* Skip past the labels, and count them. */
216 while (get_label (exp, pos) != NULL)
217 nlabels++;
218
219 do
220 {
221 char *label = get_label (exp, &pc);
222 if (label)
223 {
224 for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type);
225 fieldno++)
226 {
227 char *field_name = TYPE_FIELD_NAME (struct_type, fieldno);
edf8c5a3 228 if (field_name != NULL && strcmp (field_name, label) == 0)
c906108c
SS
229 {
230 variantno = -1;
231 subfieldno = fieldno;
232 substruct_type = struct_type;
233 goto found;
234 }
235 }
236 for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type);
237 fieldno++)
238 {
239 char *field_name = TYPE_FIELD_NAME (struct_type, fieldno);
240 field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
241 if ((field_name == 0 || *field_name == '\0')
242 && TYPE_CODE (field_type) == TYPE_CODE_UNION)
243 {
244 variantno = 0;
245 for (; variantno < TYPE_NFIELDS (field_type);
246 variantno++)
247 {
248 substruct_type
249 = TYPE_FIELD_TYPE (field_type, variantno);
250 if (TYPE_CODE (substruct_type) == TYPE_CODE_STRUCT)
c5aa993b 251 {
c906108c 252 for (subfieldno = 0;
c5aa993b 253 subfieldno < TYPE_NFIELDS (substruct_type);
c906108c
SS
254 subfieldno++)
255 {
edf8c5a3 256 if (strcmp(TYPE_FIELD_NAME (substruct_type,
c906108c 257 subfieldno),
edf8c5a3 258 label) == 0)
c906108c
SS
259 {
260 goto found;
261 }
262 }
263 }
264 }
265 }
266 }
8a3fe4f8 267 error (_("there is no field named %s"), label);
c906108c
SS
268 found:
269 ;
270 }
271 else
272 {
273 /* Unlabelled tuple element - go to next field. */
274 if (variantno >= 0)
275 {
276 subfieldno++;
277 if (subfieldno >= TYPE_NFIELDS (substruct_type))
278 {
279 variantno = -1;
280 substruct_type = struct_type;
281 }
282 }
283 if (variantno < 0)
284 {
285 fieldno++;
286 subfieldno = fieldno;
287 if (fieldno >= TYPE_NFIELDS (struct_type))
8a3fe4f8 288 error (_("too many initializers"));
c906108c
SS
289 field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
290 if (TYPE_CODE (field_type) == TYPE_CODE_UNION
291 && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
8a3fe4f8 292 error (_("don't know which variant you want to set"));
c906108c
SS
293 }
294 }
295
296 /* Here, struct_type is the type of the inner struct,
297 while substruct_type is the type of the inner struct.
298 These are the same for normal structures, but a variant struct
299 contains anonymous union fields that contain substruct fields.
300 The value fieldno is the index of the top-level (normal or
301 anonymous union) field in struct_field, while the value
302 subfieldno is the index of the actual real (named inner) field
303 in substruct_type. */
304
305 field_type = TYPE_FIELD_TYPE (substruct_type, subfieldno);
306 if (val == 0)
307 val = evaluate_subexp (field_type, exp, pos, noside);
308
309 /* Now actually set the field in struct_val. */
310
311 /* Assign val to field fieldno. */
df407dfe 312 if (value_type (val) != field_type)
c906108c
SS
313 val = value_cast (field_type, val);
314
315 bitsize = TYPE_FIELD_BITSIZE (substruct_type, subfieldno);
316 bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
317 if (variantno >= 0)
318 bitpos += TYPE_FIELD_BITPOS (substruct_type, subfieldno);
0fd88904 319 addr = value_contents_writeable (struct_val) + bitpos / 8;
c906108c
SS
320 if (bitsize)
321 modify_field (addr, value_as_long (val),
322 bitpos % 8, bitsize);
323 else
0fd88904 324 memcpy (addr, value_contents (val),
df407dfe 325 TYPE_LENGTH (value_type (val)));
c5aa993b
JM
326 }
327 while (--nlabels > 0);
c906108c
SS
328 }
329 return struct_val;
330}
331
db034ac5 332/* Recursive helper function for setting elements of array tuples for
1b831c93
AC
333 (the deleted) Chill. The target is ARRAY (which has bounds
334 LOW_BOUND to HIGH_BOUND); the element value is ELEMENT; EXP, POS
335 and NOSIDE are as usual. Evaluates index expresions and sets the
336 specified element(s) of ARRAY to ELEMENT. Returns last index
337 value. */
c906108c
SS
338
339static LONGEST
61051030 340init_array_element (struct value *array, struct value *element,
aa1ee363 341 struct expression *exp, int *pos,
fba45db2 342 enum noside noside, LONGEST low_bound, LONGEST high_bound)
c906108c
SS
343{
344 LONGEST index;
df407dfe 345 int element_size = TYPE_LENGTH (value_type (element));
c906108c
SS
346 if (exp->elts[*pos].opcode == BINOP_COMMA)
347 {
348 (*pos)++;
349 init_array_element (array, element, exp, pos, noside,
350 low_bound, high_bound);
351 return init_array_element (array, element,
352 exp, pos, noside, low_bound, high_bound);
353 }
354 else if (exp->elts[*pos].opcode == BINOP_RANGE)
355 {
356 LONGEST low, high;
357 (*pos)++;
358 low = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
359 high = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
360 if (low < low_bound || high > high_bound)
8a3fe4f8 361 error (_("tuple range index out of range"));
c5aa993b 362 for (index = low; index <= high; index++)
c906108c 363 {
990a07ab 364 memcpy (value_contents_raw (array)
c906108c 365 + (index - low_bound) * element_size,
0fd88904 366 value_contents (element), element_size);
c906108c
SS
367 }
368 }
369 else
370 {
371 index = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
372 if (index < low_bound || index > high_bound)
8a3fe4f8 373 error (_("tuple index out of range"));
990a07ab 374 memcpy (value_contents_raw (array) + (index - low_bound) * element_size,
0fd88904 375 value_contents (element), element_size);
c906108c
SS
376 }
377 return index;
378}
379
61051030 380struct value *
fba45db2 381evaluate_subexp_standard (struct type *expect_type,
aa1ee363 382 struct expression *exp, int *pos,
fba45db2 383 enum noside noside)
c906108c
SS
384{
385 enum exp_opcode op;
386 int tem, tem2, tem3;
52f0bd74 387 int pc, pc2 = 0, oldpos;
61051030
AC
388 struct value *arg1 = NULL;
389 struct value *arg2 = NULL;
390 struct value *arg3;
c906108c
SS
391 struct type *type;
392 int nargs;
61051030 393 struct value **argvec;
c5aa993b 394 int upper, lower, retcode;
c906108c
SS
395 int code;
396 int ix;
397 long mem_offset;
c5aa993b 398 struct type **arg_types;
c906108c
SS
399 int save_pos1;
400
c906108c
SS
401 pc = (*pos)++;
402 op = exp->elts[pc].opcode;
403
404 switch (op)
405 {
406 case OP_SCOPE:
407 tem = longest_to_int (exp->elts[pc + 2].longconst);
408 (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
79c2c32d
DC
409 arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
410 &exp->elts[pc + 3].string,
411 noside);
c906108c 412 if (arg1 == NULL)
8a3fe4f8 413 error (_("There is no field named %s"), &exp->elts[pc + 3].string);
c906108c
SS
414 return arg1;
415
416 case OP_LONG:
417 (*pos) += 3;
418 return value_from_longest (exp->elts[pc + 1].type,
419 exp->elts[pc + 2].longconst);
420
421 case OP_DOUBLE:
422 (*pos) += 3;
423 return value_from_double (exp->elts[pc + 1].type,
424 exp->elts[pc + 2].doubleconst);
425
426 case OP_VAR_VALUE:
427 (*pos) += 3;
428 if (noside == EVAL_SKIP)
429 goto nosideret;
c906108c 430
070ad9f0
DB
431 /* JYG: We used to just return value_zero of the symbol type
432 if we're asked to avoid side effects. Otherwise we return
433 value_of_variable (...). However I'm not sure if
434 value_of_variable () has any side effect.
435 We need a full value object returned here for whatis_exp ()
436 to call evaluate_type () and then pass the full value to
437 value_rtti_target_type () if we are dealing with a pointer
438 or reference to a base class and print object is on. */
c906108c 439
c906108c
SS
440 return value_of_variable (exp->elts[pc + 2].symbol,
441 exp->elts[pc + 1].block);
442
443 case OP_LAST:
444 (*pos) += 2;
445 return
446 access_value_history (longest_to_int (exp->elts[pc + 1].longconst));
447
448 case OP_REGISTER:
449 {
c5aa993b 450 int regno = longest_to_int (exp->elts[pc + 1].longconst);
b04f3ab4 451 struct value *val = value_of_register (regno, get_selected_frame (NULL));
c906108c
SS
452 (*pos) += 2;
453 if (val == NULL)
8a3fe4f8 454 error (_("Value of register %s not available."),
b04f3ab4 455 frame_map_regnum_to_name (get_selected_frame (NULL), regno));
c906108c
SS
456 else
457 return val;
458 }
459 case OP_BOOL:
460 (*pos) += 2;
461 return value_from_longest (LA_BOOL_TYPE,
c5aa993b 462 exp->elts[pc + 1].longconst);
c906108c
SS
463
464 case OP_INTERNALVAR:
465 (*pos) += 2;
466 return value_of_internalvar (exp->elts[pc + 1].internalvar);
467
468 case OP_STRING:
469 tem = longest_to_int (exp->elts[pc + 1].longconst);
470 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
471 if (noside == EVAL_SKIP)
472 goto nosideret;
473 return value_string (&exp->elts[pc + 2].string, tem);
474
a9fa03de
AF
475 case OP_OBJC_NSSTRING: /* Objective C Foundation Class NSString constant. */
476 tem = longest_to_int (exp->elts[pc + 1].longconst);
477 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
478 if (noside == EVAL_SKIP)
479 {
480 goto nosideret;
481 }
482 return (struct value *) value_nsstring (&exp->elts[pc + 2].string, tem + 1);
483
c906108c
SS
484 case OP_BITSTRING:
485 tem = longest_to_int (exp->elts[pc + 1].longconst);
486 (*pos)
487 += 3 + BYTES_TO_EXP_ELEM ((tem + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT);
488 if (noside == EVAL_SKIP)
489 goto nosideret;
490 return value_bitstring (&exp->elts[pc + 2].string, tem);
491 break;
492
493 case OP_ARRAY:
494 (*pos) += 3;
495 tem2 = longest_to_int (exp->elts[pc + 1].longconst);
496 tem3 = longest_to_int (exp->elts[pc + 2].longconst);
497 nargs = tem3 - tem2 + 1;
498 type = expect_type ? check_typedef (expect_type) : NULL_TYPE;
499
500 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
501 && TYPE_CODE (type) == TYPE_CODE_STRUCT)
502 {
61051030 503 struct value *rec = allocate_value (expect_type);
990a07ab 504 memset (value_contents_raw (rec), '\0', TYPE_LENGTH (type));
c906108c
SS
505 return evaluate_struct_tuple (rec, exp, pos, noside, nargs);
506 }
507
508 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
509 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
510 {
511 struct type *range_type = TYPE_FIELD_TYPE (type, 0);
512 struct type *element_type = TYPE_TARGET_TYPE (type);
61051030 513 struct value *array = allocate_value (expect_type);
c906108c
SS
514 int element_size = TYPE_LENGTH (check_typedef (element_type));
515 LONGEST low_bound, high_bound, index;
516 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
517 {
518 low_bound = 0;
519 high_bound = (TYPE_LENGTH (type) / element_size) - 1;
520 }
521 index = low_bound;
990a07ab 522 memset (value_contents_raw (array), 0, TYPE_LENGTH (expect_type));
c5aa993b 523 for (tem = nargs; --nargs >= 0;)
c906108c 524 {
61051030 525 struct value *element;
c906108c
SS
526 int index_pc = 0;
527 if (exp->elts[*pos].opcode == BINOP_RANGE)
528 {
529 index_pc = ++(*pos);
530 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
531 }
532 element = evaluate_subexp (element_type, exp, pos, noside);
df407dfe 533 if (value_type (element) != element_type)
c906108c
SS
534 element = value_cast (element_type, element);
535 if (index_pc)
536 {
537 int continue_pc = *pos;
538 *pos = index_pc;
539 index = init_array_element (array, element, exp, pos, noside,
540 low_bound, high_bound);
541 *pos = continue_pc;
542 }
543 else
544 {
545 if (index > high_bound)
546 /* to avoid memory corruption */
8a3fe4f8 547 error (_("Too many array elements"));
990a07ab 548 memcpy (value_contents_raw (array)
c906108c 549 + (index - low_bound) * element_size,
0fd88904 550 value_contents (element),
c906108c
SS
551 element_size);
552 }
553 index++;
554 }
555 return array;
556 }
557
558 if (expect_type != NULL_TYPE && noside != EVAL_SKIP
559 && TYPE_CODE (type) == TYPE_CODE_SET)
560 {
61051030 561 struct value *set = allocate_value (expect_type);
47b667de 562 gdb_byte *valaddr = value_contents_raw (set);
c906108c
SS
563 struct type *element_type = TYPE_INDEX_TYPE (type);
564 struct type *check_type = element_type;
565 LONGEST low_bound, high_bound;
566
567 /* get targettype of elementtype */
568 while (TYPE_CODE (check_type) == TYPE_CODE_RANGE ||
569 TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
570 check_type = TYPE_TARGET_TYPE (check_type);
571
572 if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
8a3fe4f8 573 error (_("(power)set type with unknown size"));
c906108c
SS
574 memset (valaddr, '\0', TYPE_LENGTH (type));
575 for (tem = 0; tem < nargs; tem++)
576 {
577 LONGEST range_low, range_high;
578 struct type *range_low_type, *range_high_type;
61051030 579 struct value *elem_val;
c906108c
SS
580 if (exp->elts[*pos].opcode == BINOP_RANGE)
581 {
582 (*pos)++;
583 elem_val = evaluate_subexp (element_type, exp, pos, noside);
df407dfe 584 range_low_type = value_type (elem_val);
c906108c
SS
585 range_low = value_as_long (elem_val);
586 elem_val = evaluate_subexp (element_type, exp, pos, noside);
df407dfe 587 range_high_type = value_type (elem_val);
c906108c
SS
588 range_high = value_as_long (elem_val);
589 }
590 else
591 {
592 elem_val = evaluate_subexp (element_type, exp, pos, noside);
df407dfe 593 range_low_type = range_high_type = value_type (elem_val);
c906108c
SS
594 range_low = range_high = value_as_long (elem_val);
595 }
596 /* check types of elements to avoid mixture of elements from
c5aa993b
JM
597 different types. Also check if type of element is "compatible"
598 with element type of powerset */
c906108c
SS
599 if (TYPE_CODE (range_low_type) == TYPE_CODE_RANGE)
600 range_low_type = TYPE_TARGET_TYPE (range_low_type);
601 if (TYPE_CODE (range_high_type) == TYPE_CODE_RANGE)
602 range_high_type = TYPE_TARGET_TYPE (range_high_type);
603 if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type)) ||
604 (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM &&
605 (range_low_type != range_high_type)))
606 /* different element modes */
8a3fe4f8 607 error (_("POWERSET tuple elements of different mode"));
c906108c
SS
608 if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type)) ||
609 (TYPE_CODE (check_type) == TYPE_CODE_ENUM &&
610 range_low_type != check_type))
8a3fe4f8 611 error (_("incompatible POWERSET tuple elements"));
c906108c
SS
612 if (range_low > range_high)
613 {
8a3fe4f8 614 warning (_("empty POWERSET tuple range"));
c906108c
SS
615 continue;
616 }
617 if (range_low < low_bound || range_high > high_bound)
8a3fe4f8 618 error (_("POWERSET tuple element out of range"));
c906108c
SS
619 range_low -= low_bound;
620 range_high -= low_bound;
c5aa993b 621 for (; range_low <= range_high; range_low++)
c906108c
SS
622 {
623 int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;
624 if (BITS_BIG_ENDIAN)
625 bit_index = TARGET_CHAR_BIT - 1 - bit_index;
c5aa993b 626 valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
c906108c
SS
627 |= 1 << bit_index;
628 }
629 }
630 return set;
631 }
632
f976f6d4 633 argvec = (struct value **) alloca (sizeof (struct value *) * nargs);
c906108c
SS
634 for (tem = 0; tem < nargs; tem++)
635 {
636 /* Ensure that array expressions are coerced into pointer objects. */
637 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
638 }
639 if (noside == EVAL_SKIP)
640 goto nosideret;
641 return value_array (tem2, tem3, argvec);
642
643 case TERNOP_SLICE:
644 {
61051030 645 struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
c906108c 646 int lowbound
c5aa993b 647 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
c906108c 648 int upper
c5aa993b 649 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
c906108c
SS
650 if (noside == EVAL_SKIP)
651 goto nosideret;
652 return value_slice (array, lowbound, upper - lowbound + 1);
653 }
654
655 case TERNOP_SLICE_COUNT:
656 {
61051030 657 struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
c906108c 658 int lowbound
c5aa993b 659 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
c906108c 660 int length
c5aa993b 661 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
c906108c
SS
662 return value_slice (array, lowbound, length);
663 }
664
665 case TERNOP_COND:
666 /* Skip third and second args to evaluate the first one. */
667 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
668 if (value_logical_not (arg1))
669 {
670 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
671 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
672 }
673 else
674 {
675 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
676 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
677 return arg2;
678 }
679
a9fa03de
AF
680 case OP_OBJC_SELECTOR:
681 { /* Objective C @selector operator. */
682 char *sel = &exp->elts[pc + 2].string;
683 int len = longest_to_int (exp->elts[pc + 1].longconst);
684
685 (*pos) += 3 + BYTES_TO_EXP_ELEM (len + 1);
686 if (noside == EVAL_SKIP)
687 goto nosideret;
688
689 if (sel[len] != 0)
690 sel[len] = 0; /* Make sure it's terminated. */
691 return value_from_longest (lookup_pointer_type (builtin_type_void),
692 lookup_child_selector (sel));
693 }
694
695 case OP_OBJC_MSGCALL:
696 { /* Objective C message (method) call. */
697
c253954e
JB
698 static CORE_ADDR responds_selector = 0;
699 static CORE_ADDR method_selector = 0;
a9fa03de 700
c253954e 701 CORE_ADDR selector = 0;
a9fa03de
AF
702
703 int using_gcc = 0;
704 int struct_return = 0;
705 int sub_no_side = 0;
706
707 static struct value *msg_send = NULL;
708 static struct value *msg_send_stret = NULL;
709 static int gnu_runtime = 0;
710
711 struct value *target = NULL;
712 struct value *method = NULL;
713 struct value *called_method = NULL;
714
715 struct type *selector_type = NULL;
716
717 struct value *ret = NULL;
718 CORE_ADDR addr = 0;
719
720 selector = exp->elts[pc + 1].longconst;
721 nargs = exp->elts[pc + 2].longconst;
722 argvec = (struct value **) alloca (sizeof (struct value *)
723 * (nargs + 5));
724
725 (*pos) += 3;
726
727 selector_type = lookup_pointer_type (builtin_type_void);
728 if (noside == EVAL_AVOID_SIDE_EFFECTS)
729 sub_no_side = EVAL_NORMAL;
730 else
731 sub_no_side = noside;
732
733 target = evaluate_subexp (selector_type, exp, pos, sub_no_side);
734
735 if (value_as_long (target) == 0)
736 return value_from_longest (builtin_type_long, 0);
737
738 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0))
739 gnu_runtime = 1;
740
741 /* Find the method dispatch (Apple runtime) or method lookup
742 (GNU runtime) function for Objective-C. These will be used
743 to lookup the symbol information for the method. If we
744 can't find any symbol information, then we'll use these to
745 call the method, otherwise we can call the method
746 directly. The msg_send_stret function is used in the special
747 case of a method that returns a structure (Apple runtime
748 only). */
749 if (gnu_runtime)
750 {
c253954e
JB
751 struct type *type;
752 type = lookup_pointer_type (builtin_type_void);
753 type = lookup_function_type (type);
754 type = lookup_pointer_type (type);
755 type = lookup_function_type (type);
756 type = lookup_pointer_type (type);
757
a9fa03de
AF
758 msg_send = find_function_in_inferior ("objc_msg_lookup");
759 msg_send_stret = find_function_in_inferior ("objc_msg_lookup");
c253954e
JB
760
761 msg_send = value_from_pointer (type, value_as_address (msg_send));
762 msg_send_stret = value_from_pointer (type,
763 value_as_address (msg_send_stret));
a9fa03de
AF
764 }
765 else
766 {
767 msg_send = find_function_in_inferior ("objc_msgSend");
768 /* Special dispatcher for methods returning structs */
769 msg_send_stret = find_function_in_inferior ("objc_msgSend_stret");
770 }
771
772 /* Verify the target object responds to this method. The
773 standard top-level 'Object' class uses a different name for
774 the verification method than the non-standard, but more
775 often used, 'NSObject' class. Make sure we check for both. */
776
777 responds_selector = lookup_child_selector ("respondsToSelector:");
778 if (responds_selector == 0)
779 responds_selector = lookup_child_selector ("respondsTo:");
780
781 if (responds_selector == 0)
8a3fe4f8 782 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
a9fa03de
AF
783
784 method_selector = lookup_child_selector ("methodForSelector:");
785 if (method_selector == 0)
786 method_selector = lookup_child_selector ("methodFor:");
787
788 if (method_selector == 0)
8a3fe4f8 789 error (_("no 'methodFor:' or 'methodForSelector:' method"));
a9fa03de
AF
790
791 /* Call the verification method, to make sure that the target
792 class implements the desired method. */
793
794 argvec[0] = msg_send;
795 argvec[1] = target;
796 argvec[2] = value_from_longest (builtin_type_long, responds_selector);
797 argvec[3] = value_from_longest (builtin_type_long, selector);
798 argvec[4] = 0;
799
800 ret = call_function_by_hand (argvec[0], 3, argvec + 1);
801 if (gnu_runtime)
802 {
803 /* Function objc_msg_lookup returns a pointer. */
804 argvec[0] = ret;
805 ret = call_function_by_hand (argvec[0], 3, argvec + 1);
806 }
807 if (value_as_long (ret) == 0)
8a3fe4f8 808 error (_("Target does not respond to this message selector."));
a9fa03de
AF
809
810 /* Call "methodForSelector:" method, to get the address of a
811 function method that implements this selector for this
812 class. If we can find a symbol at that address, then we
813 know the return type, parameter types etc. (that's a good
814 thing). */
815
816 argvec[0] = msg_send;
817 argvec[1] = target;
818 argvec[2] = value_from_longest (builtin_type_long, method_selector);
819 argvec[3] = value_from_longest (builtin_type_long, selector);
820 argvec[4] = 0;
821
822 ret = call_function_by_hand (argvec[0], 3, argvec + 1);
823 if (gnu_runtime)
824 {
825 argvec[0] = ret;
826 ret = call_function_by_hand (argvec[0], 3, argvec + 1);
827 }
828
829 /* ret should now be the selector. */
830
831 addr = value_as_long (ret);
832 if (addr)
833 {
834 struct symbol *sym = NULL;
835 /* Is it a high_level symbol? */
836
837 sym = find_pc_function (addr);
838 if (sym != NULL)
839 method = value_of_variable (sym, 0);
840 }
841
842 /* If we found a method with symbol information, check to see
843 if it returns a struct. Otherwise assume it doesn't. */
844
845 if (method)
846 {
847 struct block *b;
848 CORE_ADDR funaddr;
849 struct type *value_type;
850
851 funaddr = find_function_addr (method, &value_type);
852
853 b = block_for_pc (funaddr);
854
855 /* If compiled without -g, assume GCC 2. */
856 using_gcc = (b == NULL ? 2 : BLOCK_GCC_COMPILED (b));
857
858 CHECK_TYPEDEF (value_type);
859
860 if ((value_type == NULL)
861 || (TYPE_CODE(value_type) == TYPE_CODE_ERROR))
862 {
863 if (expect_type != NULL)
864 value_type = expect_type;
865 }
866
48436ce6 867 struct_return = using_struct_return (value_type, using_gcc);
a9fa03de
AF
868 }
869 else if (expect_type != NULL)
870 {
48436ce6 871 struct_return = using_struct_return (check_typedef (expect_type), using_gcc);
a9fa03de
AF
872 }
873
874 /* Found a function symbol. Now we will substitute its
875 value in place of the message dispatcher (obj_msgSend),
876 so that we call the method directly instead of thru
877 the dispatcher. The main reason for doing this is that
878 we can now evaluate the return value and parameter values
879 according to their known data types, in case we need to
880 do things like promotion, dereferencing, special handling
881 of structs and doubles, etc.
882
883 We want to use the type signature of 'method', but still
884 jump to objc_msgSend() or objc_msgSend_stret() to better
885 mimic the behavior of the runtime. */
886
887 if (method)
888 {
df407dfe 889 if (TYPE_CODE (value_type (method)) != TYPE_CODE_FUNC)
8a3fe4f8 890 error (_("method address has symbol information with non-function type; skipping"));
a9fa03de
AF
891 if (struct_return)
892 VALUE_ADDRESS (method) = value_as_address (msg_send_stret);
893 else
894 VALUE_ADDRESS (method) = value_as_address (msg_send);
895 called_method = method;
896 }
897 else
898 {
899 if (struct_return)
900 called_method = msg_send_stret;
901 else
902 called_method = msg_send;
903 }
904
905 if (noside == EVAL_SKIP)
906 goto nosideret;
907
908 if (noside == EVAL_AVOID_SIDE_EFFECTS)
909 {
910 /* If the return type doesn't look like a function type,
911 call an error. This can happen if somebody tries to
912 turn a variable into a function call. This is here
913 because people often want to call, eg, strcmp, which
914 gdb doesn't know is a function. If gdb isn't asked for
915 it's opinion (ie. through "whatis"), it won't offer
916 it. */
917
df407dfe 918 struct type *type = value_type (called_method);
a9fa03de
AF
919 if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
920 type = TYPE_TARGET_TYPE (type);
921 type = TYPE_TARGET_TYPE (type);
922
923 if (type)
924 {
925 if ((TYPE_CODE (type) == TYPE_CODE_ERROR) && expect_type)
926 return allocate_value (expect_type);
927 else
928 return allocate_value (type);
929 }
930 else
8a3fe4f8 931 error (_("Expression of type other than \"method returning ...\" used as a method"));
a9fa03de
AF
932 }
933
934 /* Now depending on whether we found a symbol for the method,
935 we will either call the runtime dispatcher or the method
936 directly. */
937
938 argvec[0] = called_method;
939 argvec[1] = target;
940 argvec[2] = value_from_longest (builtin_type_long, selector);
941 /* User-supplied arguments. */
942 for (tem = 0; tem < nargs; tem++)
943 argvec[tem + 3] = evaluate_subexp_with_coercion (exp, pos, noside);
944 argvec[tem + 3] = 0;
945
946 if (gnu_runtime && (method != NULL))
947 {
a9fa03de 948 /* Function objc_msg_lookup returns a pointer. */
04624583
AC
949 deprecated_set_value_type (argvec[0],
950 lookup_function_type (lookup_pointer_type (value_type (argvec[0]))));
c253954e 951 argvec[0] = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
a9fa03de 952 }
a9fa03de 953
c253954e 954 ret = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
a9fa03de
AF
955 return ret;
956 }
957 break;
958
c906108c
SS
959 case OP_FUNCALL:
960 (*pos) += 2;
961 op = exp->elts[*pos].opcode;
962 nargs = longest_to_int (exp->elts[pc + 1].longconst);
963 /* Allocate arg vector, including space for the function to be
c5aa993b 964 called in argvec[0] and a terminating NULL */
f976f6d4 965 argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 3));
c906108c
SS
966 if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
967 {
968 LONGEST fnptr;
969
c5aa993b
JM
970 /* 1997-08-01 Currently we do not support function invocation
971 via pointers-to-methods with HP aCC. Pointer does not point
972 to the function, but possibly to some thunk. */
f83f82bc 973 if (deprecated_hp_som_som_object_present)
c5aa993b 974 {
8a3fe4f8 975 error (_("Not implemented: function invocation through pointer to method with HP aCC"));
c5aa993b 976 }
c906108c
SS
977
978 nargs++;
979 /* First, evaluate the structure into arg2 */
980 pc2 = (*pos)++;
981
982 if (noside == EVAL_SKIP)
983 goto nosideret;
984
985 if (op == STRUCTOP_MEMBER)
986 {
987 arg2 = evaluate_subexp_for_address (exp, pos, noside);
988 }
989 else
990 {
991 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
992 }
993
994 /* If the function is a virtual function, then the
995 aggregate value (providing the structure) plays
996 its part by providing the vtable. Otherwise,
997 it is just along for the ride: call the function
998 directly. */
999
1000 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1001
1002 fnptr = value_as_long (arg1);
1003
c5aa993b 1004 if (METHOD_PTR_IS_VIRTUAL (fnptr))
c906108c 1005 {
c5aa993b 1006 int fnoffset = METHOD_PTR_TO_VOFFSET (fnptr);
c906108c
SS
1007 struct type *basetype;
1008 struct type *domain_type =
df407dfe 1009 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (value_type (arg1)));
c906108c 1010 int i, j;
df407dfe 1011 basetype = TYPE_TARGET_TYPE (value_type (arg2));
c906108c 1012 if (domain_type != basetype)
c5aa993b 1013 arg2 = value_cast (lookup_pointer_type (domain_type), arg2);
c906108c
SS
1014 basetype = TYPE_VPTR_BASETYPE (domain_type);
1015 for (i = TYPE_NFN_FIELDS (basetype) - 1; i >= 0; i--)
1016 {
1017 struct fn_field *f = TYPE_FN_FIELDLIST1 (basetype, i);
1018 /* If one is virtual, then all are virtual. */
1019 if (TYPE_FN_FIELD_VIRTUAL_P (f, 0))
1020 for (j = TYPE_FN_FIELDLIST_LENGTH (basetype, i) - 1; j >= 0; --j)
1021 if ((int) TYPE_FN_FIELD_VOFFSET (f, j) == fnoffset)
1022 {
61051030 1023 struct value *temp = value_ind (arg2);
c906108c
SS
1024 arg1 = value_virtual_fn_field (&temp, f, j, domain_type, 0);
1025 arg2 = value_addr (temp);
1026 goto got_it;
1027 }
1028 }
1029 if (i < 0)
8a3fe4f8 1030 error (_("virtual function at index %d not found"), fnoffset);
c906108c
SS
1031 }
1032 else
1033 {
04624583 1034 deprecated_set_value_type (arg1, lookup_pointer_type (TYPE_TARGET_TYPE (value_type (arg1))));
c906108c
SS
1035 }
1036 got_it:
1037
1038 /* Now, say which argument to start evaluating from */
1039 tem = 2;
1040 }
1041 else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
1042 {
1043 /* Hair for method invocations */
1044 int tem2;
1045
1046 nargs++;
1047 /* First, evaluate the structure into arg2 */
1048 pc2 = (*pos)++;
1049 tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
1050 *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);
1051 if (noside == EVAL_SKIP)
1052 goto nosideret;
1053
1054 if (op == STRUCTOP_STRUCT)
1055 {
1056 /* If v is a variable in a register, and the user types
c5aa993b
JM
1057 v.method (), this will produce an error, because v has
1058 no address.
1059
1060 A possible way around this would be to allocate a
1061 copy of the variable on the stack, copy in the
1062 contents, call the function, and copy out the
1063 contents. I.e. convert this from call by reference
1064 to call by copy-return (or whatever it's called).
1065 However, this does not work because it is not the
1066 same: the method being called could stash a copy of
1067 the address, and then future uses through that address
1068 (after the method returns) would be expected to
1069 use the variable itself, not some copy of it. */
c906108c
SS
1070 arg2 = evaluate_subexp_for_address (exp, pos, noside);
1071 }
1072 else
1073 {
1074 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1075 }
1076 /* Now, say which argument to start evaluating from */
1077 tem = 2;
1078 }
1079 else
1080 {
1081 /* Non-method function call */
1082 save_pos1 = *pos;
1083 argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
1084 tem = 1;
df407dfe 1085 type = value_type (argvec[0]);
c906108c
SS
1086 if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
1087 type = TYPE_TARGET_TYPE (type);
1088 if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
1089 {
1090 for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
1091 {
c5aa993b
JM
1092 /* pai: FIXME This seems to be coercing arguments before
1093 * overload resolution has been done! */
1094 argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type, tem - 1),
c906108c
SS
1095 exp, pos, noside);
1096 }
1097 }
1098 }
1099
1100 /* Evaluate arguments */
1101 for (; tem <= nargs; tem++)
1102 {
1103 /* Ensure that array expressions are coerced into pointer objects. */
1104 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
1105 }
1106
1107 /* signal end of arglist */
1108 argvec[tem] = 0;
1109
1110 if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
1111 {
1112 int static_memfuncp;
c906108c 1113 char tstr[256];
c5aa993b
JM
1114
1115 /* Method invocation : stuff "this" as first parameter */
9b013045 1116 argvec[1] = arg2;
c5aa993b
JM
1117 /* Name of method from expression */
1118 strcpy (tstr, &exp->elts[pc2 + 2].string);
1119
1120 if (overload_resolution && (exp->language_defn->la_language == language_cplus))
1121 {
1122 /* Language is C++, do some overload resolution before evaluation */
61051030 1123 struct value *valp = NULL;
c5aa993b
JM
1124
1125 /* Prepare list of argument types for overload resolution */
c2636352 1126 arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
c5aa993b 1127 for (ix = 1; ix <= nargs; ix++)
df407dfe 1128 arg_types[ix - 1] = value_type (argvec[ix]);
c5aa993b
JM
1129
1130 (void) find_overload_match (arg_types, nargs, tstr,
1131 1 /* method */ , 0 /* strict match */ ,
7f8c9282 1132 &arg2 /* the object */ , NULL,
c5aa993b
JM
1133 &valp, NULL, &static_memfuncp);
1134
1135
1136 argvec[1] = arg2; /* the ``this'' pointer */
1137 argvec[0] = valp; /* use the method found after overload resolution */
1138 }
1139 else
1140 /* Non-C++ case -- or no overload resolution */
1141 {
9b013045 1142 struct value *temp = arg2;
c5aa993b
JM
1143 argvec[0] = value_struct_elt (&temp, argvec + 1, tstr,
1144 &static_memfuncp,
1145 op == STRUCTOP_STRUCT
1146 ? "structure" : "structure pointer");
9b013045
PS
1147 /* value_struct_elt updates temp with the correct value
1148 of the ``this'' pointer if necessary, so modify argvec[1] to
1149 reflect any ``this'' changes. */
df407dfe
AC
1150 arg2 = value_from_longest (lookup_pointer_type(value_type (temp)),
1151 VALUE_ADDRESS (temp) + value_offset (temp)
13c3b5f5 1152 + value_embedded_offset (temp));
c5aa993b
JM
1153 argvec[1] = arg2; /* the ``this'' pointer */
1154 }
c906108c
SS
1155
1156 if (static_memfuncp)
1157 {
1158 argvec[1] = argvec[0];
1159 nargs--;
1160 argvec++;
1161 }
1162 }
1163 else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
1164 {
1165 argvec[1] = arg2;
1166 argvec[0] = arg1;
1167 }
917317f4 1168 else if (op == OP_VAR_VALUE)
c5aa993b 1169 {
c906108c 1170 /* Non-member function being called */
917317f4
JM
1171 /* fn: This can only be done for C++ functions. A C-style function
1172 in a C++ program, for instance, does not have the fields that
1173 are expected here */
c906108c 1174
c5aa993b
JM
1175 if (overload_resolution && (exp->language_defn->la_language == language_cplus))
1176 {
1177 /* Language is C++, do some overload resolution before evaluation */
1178 struct symbol *symp;
1179
1180 /* Prepare list of argument types for overload resolution */
c2636352 1181 arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
c5aa993b 1182 for (ix = 1; ix <= nargs; ix++)
df407dfe 1183 arg_types[ix - 1] = value_type (argvec[ix]);
c5aa993b
JM
1184
1185 (void) find_overload_match (arg_types, nargs, NULL /* no need for name */ ,
1186 0 /* not method */ , 0 /* strict match */ ,
917317f4 1187 NULL, exp->elts[save_pos1+2].symbol /* the function */ ,
c5aa993b
JM
1188 NULL, &symp, NULL);
1189
1190 /* Now fix the expression being evaluated */
917317f4 1191 exp->elts[save_pos1+2].symbol = symp;
c5aa993b
JM
1192 argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
1193 }
1194 else
1195 {
1196 /* Not C++, or no overload resolution allowed */
1197 /* nothing to be done; argvec already correctly set up */
1198 }
1199 }
917317f4
JM
1200 else
1201 {
1202 /* It is probably a C-style function */
1203 /* nothing to be done; argvec already correctly set up */
1204 }
c906108c
SS
1205
1206 do_call_it:
1207
1208 if (noside == EVAL_SKIP)
1209 goto nosideret;
0478d61c 1210 if (argvec[0] == NULL)
8a3fe4f8 1211 error (_("Cannot evaluate function -- may be inlined"));
c906108c
SS
1212 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1213 {
1214 /* If the return type doesn't look like a function type, call an
1215 error. This can happen if somebody tries to turn a variable into
1216 a function call. This is here because people often want to
1217 call, eg, strcmp, which gdb doesn't know is a function. If
1218 gdb isn't asked for it's opinion (ie. through "whatis"),
1219 it won't offer it. */
1220
1221 struct type *ftype =
df407dfe 1222 TYPE_TARGET_TYPE (value_type (argvec[0]));
c906108c
SS
1223
1224 if (ftype)
df407dfe 1225 return allocate_value (TYPE_TARGET_TYPE (value_type (argvec[0])));
c906108c 1226 else
8a3fe4f8 1227 error (_("Expression of type other than \"Function returning ...\" used as function"));
c906108c 1228 }
c906108c
SS
1229 return call_function_by_hand (argvec[0], nargs, argvec + 1);
1230 /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve */
1231
c5aa993b 1232 case OP_F77_UNDETERMINED_ARGLIST:
c906108c
SS
1233
1234 /* Remember that in F77, functions, substring ops and
1235 array subscript operations cannot be disambiguated
1236 at parse time. We have made all array subscript operations,
1237 substring operations as well as function calls come here
1238 and we now have to discover what the heck this thing actually was.
c5aa993b 1239 If it is a function, we process just as if we got an OP_FUNCALL. */
c906108c 1240
c5aa993b 1241 nargs = longest_to_int (exp->elts[pc + 1].longconst);
c906108c
SS
1242 (*pos) += 2;
1243
c5aa993b 1244 /* First determine the type code we are dealing with. */
c906108c 1245 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1246 type = check_typedef (value_type (arg1));
c906108c
SS
1247 code = TYPE_CODE (type);
1248
df0ca547
WZ
1249 if (code == TYPE_CODE_PTR)
1250 {
1251 /* Fortran always passes variable to subroutines as pointer.
1252 So we need to look into its target type to see if it is
1253 array, string or function. If it is, we need to switch
1254 to the target value the original one points to. */
1255 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1256
1257 if (TYPE_CODE (target_type) == TYPE_CODE_ARRAY
1258 || TYPE_CODE (target_type) == TYPE_CODE_STRING
1259 || TYPE_CODE (target_type) == TYPE_CODE_FUNC)
1260 {
1261 arg1 = value_ind (arg1);
1262 type = check_typedef (value_type (arg1));
1263 code = TYPE_CODE (type);
1264 }
1265 }
1266
c5aa993b 1267 switch (code)
c906108c
SS
1268 {
1269 case TYPE_CODE_ARRAY:
1270 goto multi_f77_subscript;
1271
1272 case TYPE_CODE_STRING:
1273 goto op_f77_substr;
1274
1275 case TYPE_CODE_PTR:
1276 case TYPE_CODE_FUNC:
1277 /* It's a function call. */
1278 /* Allocate arg vector, including space for the function to be
1279 called in argvec[0] and a terminating NULL */
f976f6d4 1280 argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 2));
c906108c
SS
1281 argvec[0] = arg1;
1282 tem = 1;
1283 for (; tem <= nargs; tem++)
1284 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
c5aa993b 1285 argvec[tem] = 0; /* signal end of arglist */
c906108c
SS
1286 goto do_call_it;
1287
1288 default:
8a3fe4f8 1289 error (_("Cannot perform substring on this type"));
c906108c
SS
1290 }
1291
1292 op_f77_substr:
1293 /* We have a substring operation on our hands here,
1294 let us get the string we will be dealing with */
1295
1296 /* Now evaluate the 'from' and 'to' */
1297
1298 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1299
1300 if (nargs < 2)
1301 return value_subscript (arg1, arg2);
1302
1303 arg3 = evaluate_subexp_with_coercion (exp, pos, noside);
1304
1305 if (noside == EVAL_SKIP)
c5aa993b
JM
1306 goto nosideret;
1307
c906108c
SS
1308 tem2 = value_as_long (arg2);
1309 tem3 = value_as_long (arg3);
c5aa993b 1310
c906108c
SS
1311 return value_slice (arg1, tem2, tem3 - tem2 + 1);
1312
1313 case OP_COMPLEX:
1314 /* We have a complex number, There should be 2 floating
c5aa993b 1315 point numbers that compose it */
c906108c 1316 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
c5aa993b 1317 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
c906108c
SS
1318
1319 return value_literal_complex (arg1, arg2, builtin_type_f_complex_s16);
1320
1321 case STRUCTOP_STRUCT:
1322 tem = longest_to_int (exp->elts[pc + 1].longconst);
1323 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1324 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1325 if (noside == EVAL_SKIP)
1326 goto nosideret;
1327 if (noside == EVAL_AVOID_SIDE_EFFECTS)
df407dfe 1328 return value_zero (lookup_struct_elt_type (value_type (arg1),
c906108c
SS
1329 &exp->elts[pc + 2].string,
1330 0),
1331 lval_memory);
1332 else
1333 {
61051030 1334 struct value *temp = arg1;
c906108c
SS
1335 return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
1336 NULL, "structure");
1337 }
1338
1339 case STRUCTOP_PTR:
1340 tem = longest_to_int (exp->elts[pc + 1].longconst);
1341 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
1342 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1343 if (noside == EVAL_SKIP)
1344 goto nosideret;
070ad9f0
DB
1345
1346 /* JYG: if print object is on we need to replace the base type
1347 with rtti type in order to continue on with successful
1348 lookup of member / method only available in the rtti type. */
1349 {
df407dfe 1350 struct type *type = value_type (arg1);
070ad9f0
DB
1351 struct type *real_type;
1352 int full, top, using_enc;
1353
1354 if (objectprint && TYPE_TARGET_TYPE(type) &&
1355 (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
1356 {
1357 real_type = value_rtti_target_type (arg1, &full, &top, &using_enc);
1358 if (real_type)
1359 {
1360 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1361 real_type = lookup_pointer_type (real_type);
1362 else
1363 real_type = lookup_reference_type (real_type);
1364
1365 arg1 = value_cast (real_type, arg1);
1366 }
1367 }
1368 }
1369
c906108c 1370 if (noside == EVAL_AVOID_SIDE_EFFECTS)
df407dfe 1371 return value_zero (lookup_struct_elt_type (value_type (arg1),
c906108c
SS
1372 &exp->elts[pc + 2].string,
1373 0),
1374 lval_memory);
1375 else
1376 {
61051030 1377 struct value *temp = arg1;
c906108c
SS
1378 return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
1379 NULL, "structure pointer");
1380 }
1381
1382 case STRUCTOP_MEMBER:
1383 arg1 = evaluate_subexp_for_address (exp, pos, noside);
1384 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1385
c5aa993b 1386 /* With HP aCC, pointers to methods do not point to the function code */
f83f82bc 1387 if (deprecated_hp_som_som_object_present &&
df407dfe
AC
1388 (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR) &&
1389 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg2))) == TYPE_CODE_METHOD))
8a3fe4f8 1390 error (_("Pointers to methods not supported with HP aCC")); /* 1997-08-19 */
c5aa993b 1391
c906108c
SS
1392 mem_offset = value_as_long (arg2);
1393 goto handle_pointer_to_member;
1394
1395 case STRUCTOP_MPTR:
1396 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1397 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1398
c5aa993b 1399 /* With HP aCC, pointers to methods do not point to the function code */
f83f82bc 1400 if (deprecated_hp_som_som_object_present &&
df407dfe
AC
1401 (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR) &&
1402 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg2))) == TYPE_CODE_METHOD))
8a3fe4f8 1403 error (_("Pointers to methods not supported with HP aCC")); /* 1997-08-19 */
c906108c
SS
1404
1405 mem_offset = value_as_long (arg2);
1406
c5aa993b 1407 handle_pointer_to_member:
c906108c
SS
1408 /* HP aCC generates offsets that have bit #29 set; turn it off to get
1409 a real offset to the member. */
f83f82bc 1410 if (deprecated_hp_som_som_object_present)
c5aa993b
JM
1411 {
1412 if (!mem_offset) /* no bias -> really null */
8a3fe4f8 1413 error (_("Attempted dereference of null pointer-to-member"));
c5aa993b
JM
1414 mem_offset &= ~0x20000000;
1415 }
c906108c
SS
1416 if (noside == EVAL_SKIP)
1417 goto nosideret;
df407dfe 1418 type = check_typedef (value_type (arg2));
c906108c
SS
1419 if (TYPE_CODE (type) != TYPE_CODE_PTR)
1420 goto bad_pointer_to_member;
1421 type = check_typedef (TYPE_TARGET_TYPE (type));
1422 if (TYPE_CODE (type) == TYPE_CODE_METHOD)
8a3fe4f8 1423 error (_("not implemented: pointer-to-method in pointer-to-member construct"));
c906108c
SS
1424 if (TYPE_CODE (type) != TYPE_CODE_MEMBER)
1425 goto bad_pointer_to_member;
1426 /* Now, convert these values to an address. */
1427 arg1 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
1428 arg1);
4478b372 1429 arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
c906108c
SS
1430 value_as_long (arg1) + mem_offset);
1431 return value_ind (arg3);
c5aa993b 1432 bad_pointer_to_member:
8a3fe4f8 1433 error (_("non-pointer-to-member value used in pointer-to-member construct"));
c906108c
SS
1434
1435 case BINOP_CONCAT:
1436 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1437 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1438 if (noside == EVAL_SKIP)
1439 goto nosideret;
1440 if (binop_user_defined_p (op, arg1, arg2))
1441 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1442 else
1443 return value_concat (arg1, arg2);
1444
1445 case BINOP_ASSIGN:
1446 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1447 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
c906108c 1448
c5aa993b 1449 /* Do special stuff for HP aCC pointers to members */
f83f82bc 1450 if (deprecated_hp_som_som_object_present)
c5aa993b
JM
1451 {
1452 /* 1997-08-19 Can't assign HP aCC pointers to methods. No details of
1453 the implementation yet; but the pointer appears to point to a code
1454 sequence (thunk) in memory -- in any case it is *not* the address
1455 of the function as it would be in a naive implementation. */
df407dfe
AC
1456 if ((TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR) &&
1457 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg1))) == TYPE_CODE_METHOD))
8a3fe4f8 1458 error (_("Assignment to pointers to methods not implemented with HP aCC"));
c5aa993b
JM
1459
1460 /* HP aCC pointers to data members require a constant bias */
df407dfe
AC
1461 if ((TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR) &&
1462 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg1))) == TYPE_CODE_MEMBER))
c5aa993b 1463 {
0fd88904 1464 unsigned int *ptr = (unsigned int *) value_contents (arg2); /* forces evaluation */
c5aa993b
JM
1465 *ptr |= 0x20000000; /* set 29th bit */
1466 }
1467 }
1468
c906108c
SS
1469 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1470 return arg1;
1471 if (binop_user_defined_p (op, arg1, arg2))
1472 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1473 else
1474 return value_assign (arg1, arg2);
1475
1476 case BINOP_ASSIGN_MODIFY:
1477 (*pos) += 2;
1478 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1479 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
c906108c
SS
1480 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
1481 return arg1;
1482 op = exp->elts[pc + 1].opcode;
1483 if (binop_user_defined_p (op, arg1, arg2))
1484 return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
1485 else if (op == BINOP_ADD)
1486 arg2 = value_add (arg1, arg2);
1487 else if (op == BINOP_SUB)
1488 arg2 = value_sub (arg1, arg2);
1489 else
1490 arg2 = value_binop (arg1, arg2, op);
1491 return value_assign (arg1, arg2);
1492
1493 case BINOP_ADD:
1494 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1495 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1496 if (noside == EVAL_SKIP)
1497 goto nosideret;
1498 if (binop_user_defined_p (op, arg1, arg2))
1499 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1500 else
1501 return value_add (arg1, arg2);
1502
1503 case BINOP_SUB:
1504 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1505 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1506 if (noside == EVAL_SKIP)
1507 goto nosideret;
1508 if (binop_user_defined_p (op, arg1, arg2))
1509 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1510 else
1511 return value_sub (arg1, arg2);
1512
1513 case BINOP_MUL:
1514 case BINOP_DIV:
1515 case BINOP_REM:
1516 case BINOP_MOD:
1517 case BINOP_LSH:
1518 case BINOP_RSH:
1519 case BINOP_BITWISE_AND:
1520 case BINOP_BITWISE_IOR:
1521 case BINOP_BITWISE_XOR:
1522 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1523 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1524 if (noside == EVAL_SKIP)
1525 goto nosideret;
1526 if (binop_user_defined_p (op, arg1, arg2))
1527 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
c5aa993b
JM
1528 else if (noside == EVAL_AVOID_SIDE_EFFECTS
1529 && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
df407dfe 1530 return value_zero (value_type (arg1), not_lval);
c906108c
SS
1531 else
1532 return value_binop (arg1, arg2, op);
1533
1534 case BINOP_RANGE:
1535 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1536 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1537 if (noside == EVAL_SKIP)
1538 goto nosideret;
8a3fe4f8 1539 error (_("':' operator used in invalid context"));
c906108c
SS
1540
1541 case BINOP_SUBSCRIPT:
1542 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1543 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1544 if (noside == EVAL_SKIP)
1545 goto nosideret;
1546 if (binop_user_defined_p (op, arg1, arg2))
1547 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1548 else
c5aa993b 1549 {
c906108c
SS
1550 /* If the user attempts to subscript something that is not an
1551 array or pointer type (like a plain int variable for example),
1552 then report this as an error. */
1553
994b9211 1554 arg1 = coerce_ref (arg1);
df407dfe 1555 type = check_typedef (value_type (arg1));
c906108c
SS
1556 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
1557 && TYPE_CODE (type) != TYPE_CODE_PTR)
1558 {
1559 if (TYPE_NAME (type))
8a3fe4f8 1560 error (_("cannot subscript something of type `%s'"),
c906108c
SS
1561 TYPE_NAME (type));
1562 else
8a3fe4f8 1563 error (_("cannot subscript requested type"));
c906108c
SS
1564 }
1565
1566 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1567 return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
1568 else
1569 return value_subscript (arg1, arg2);
c5aa993b 1570 }
c906108c
SS
1571
1572 case BINOP_IN:
1573 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1574 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1575 if (noside == EVAL_SKIP)
1576 goto nosideret;
1577 return value_in (arg1, arg2);
c5aa993b 1578
c906108c
SS
1579 case MULTI_SUBSCRIPT:
1580 (*pos) += 2;
1581 nargs = longest_to_int (exp->elts[pc + 1].longconst);
1582 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
1583 while (nargs-- > 0)
1584 {
1585 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1586 /* FIXME: EVAL_SKIP handling may not be correct. */
1587 if (noside == EVAL_SKIP)
1588 {
1589 if (nargs > 0)
1590 {
1591 continue;
1592 }
1593 else
1594 {
1595 goto nosideret;
1596 }
1597 }
1598 /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
1599 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1600 {
1601 /* If the user attempts to subscript something that has no target
c5aa993b
JM
1602 type (like a plain int variable for example), then report this
1603 as an error. */
1604
df407dfe 1605 type = TYPE_TARGET_TYPE (check_typedef (value_type (arg1)));
c906108c
SS
1606 if (type != NULL)
1607 {
1608 arg1 = value_zero (type, VALUE_LVAL (arg1));
1609 noside = EVAL_SKIP;
1610 continue;
1611 }
1612 else
1613 {
8a3fe4f8 1614 error (_("cannot subscript something of type `%s'"),
df407dfe 1615 TYPE_NAME (value_type (arg1)));
c906108c
SS
1616 }
1617 }
c5aa993b 1618
c906108c
SS
1619 if (binop_user_defined_p (op, arg1, arg2))
1620 {
1621 arg1 = value_x_binop (arg1, arg2, op, OP_NULL, noside);
1622 }
1623 else
1624 {
1625 arg1 = value_subscript (arg1, arg2);
1626 }
1627 }
1628 return (arg1);
1629
1630 multi_f77_subscript:
c5aa993b 1631 {
7ca2d3a3
DL
1632 int subscript_array[MAX_FORTRAN_DIMS];
1633 int array_size_array[MAX_FORTRAN_DIMS];
c5aa993b
JM
1634 int ndimensions = 1, i;
1635 struct type *tmp_type;
1636 int offset_item; /* The array offset where the item lives */
c906108c
SS
1637
1638 if (nargs > MAX_FORTRAN_DIMS)
8a3fe4f8 1639 error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
c906108c 1640
df407dfe 1641 tmp_type = check_typedef (value_type (arg1));
c906108c
SS
1642 ndimensions = calc_f77_array_dims (type);
1643
1644 if (nargs != ndimensions)
8a3fe4f8 1645 error (_("Wrong number of subscripts"));
c906108c
SS
1646
1647 /* Now that we know we have a legal array subscript expression
c5aa993b 1648 let us actually find out where this element exists in the array. */
c906108c 1649
c5aa993b 1650 offset_item = 0;
7ca2d3a3
DL
1651 /* Take array indices left to right */
1652 for (i = 0; i < nargs; i++)
c906108c 1653 {
c5aa993b 1654 /* Evaluate each subscript, It must be a legal integer in F77 */
c906108c
SS
1655 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
1656
c5aa993b 1657 /* Fill in the subscript and array size arrays */
c906108c
SS
1658
1659 subscript_array[i] = value_as_long (arg2);
7ca2d3a3 1660 }
c5aa993b 1661
7ca2d3a3
DL
1662 /* Internal type of array is arranged right to left */
1663 for (i = 0; i < nargs; i++)
1664 {
c906108c
SS
1665 retcode = f77_get_dynamic_upperbound (tmp_type, &upper);
1666 if (retcode == BOUND_FETCH_ERROR)
8a3fe4f8 1667 error (_("Cannot obtain dynamic upper bound"));
c906108c 1668
c5aa993b 1669 retcode = f77_get_dynamic_lowerbound (tmp_type, &lower);
c906108c 1670 if (retcode == BOUND_FETCH_ERROR)
8a3fe4f8 1671 error (_("Cannot obtain dynamic lower bound"));
c906108c 1672
7ca2d3a3 1673 array_size_array[nargs - i - 1] = upper - lower + 1;
c5aa993b
JM
1674
1675 /* Zero-normalize subscripts so that offsetting will work. */
1676
7ca2d3a3 1677 subscript_array[nargs - i - 1] -= lower;
c906108c
SS
1678
1679 /* If we are at the bottom of a multidimensional
1680 array type then keep a ptr to the last ARRAY
1681 type around for use when calling value_subscript()
1682 below. This is done because we pretend to value_subscript
1683 that we actually have a one-dimensional array
1684 of base element type that we apply a simple
c5aa993b 1685 offset to. */
c906108c 1686
7ca2d3a3 1687 if (i < nargs - 1)
c5aa993b 1688 tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
c906108c
SS
1689 }
1690
1691 /* Now let us calculate the offset for this item */
1692
7ca2d3a3 1693 offset_item = subscript_array[ndimensions - 1];
c5aa993b 1694
7ca2d3a3 1695 for (i = ndimensions - 1; i > 0; --i)
c5aa993b 1696 offset_item =
7ca2d3a3 1697 array_size_array[i - 1] * offset_item + subscript_array[i - 1];
c906108c 1698
962d6d93
DL
1699 /* Construct a value node with the value of the offset */
1700
1701 arg2 = value_from_longest (builtin_type_f_integer, offset_item);
1702
c906108c
SS
1703 /* Let us now play a dirty trick: we will take arg1
1704 which is a value node pointing to the topmost level
1705 of the multidimensional array-set and pretend
1706 that it is actually a array of the final element
1707 type, this will ensure that value_subscript()
1708 returns the correct type value */
1709
04624583 1710 deprecated_set_value_type (arg1, tmp_type);
962d6d93 1711 return value_ind (value_add (value_coerce_array (arg1), arg2));
c906108c
SS
1712 }
1713
1714 case BINOP_LOGICAL_AND:
1715 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1716 if (noside == EVAL_SKIP)
1717 {
1718 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1719 goto nosideret;
1720 }
c5aa993b 1721
c906108c
SS
1722 oldpos = *pos;
1723 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1724 *pos = oldpos;
c5aa993b
JM
1725
1726 if (binop_user_defined_p (op, arg1, arg2))
c906108c
SS
1727 {
1728 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1729 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1730 }
1731 else
1732 {
1733 tem = value_logical_not (arg1);
1734 arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
1735 (tem ? EVAL_SKIP : noside));
1736 return value_from_longest (LA_BOOL_TYPE,
c5aa993b 1737 (LONGEST) (!tem && !value_logical_not (arg2)));
c906108c
SS
1738 }
1739
1740 case BINOP_LOGICAL_OR:
1741 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1742 if (noside == EVAL_SKIP)
1743 {
1744 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1745 goto nosideret;
1746 }
c5aa993b 1747
c906108c
SS
1748 oldpos = *pos;
1749 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
1750 *pos = oldpos;
c5aa993b
JM
1751
1752 if (binop_user_defined_p (op, arg1, arg2))
c906108c
SS
1753 {
1754 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1755 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1756 }
1757 else
1758 {
1759 tem = value_logical_not (arg1);
1760 arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
1761 (!tem ? EVAL_SKIP : noside));
1762 return value_from_longest (LA_BOOL_TYPE,
c5aa993b 1763 (LONGEST) (!tem || !value_logical_not (arg2)));
c906108c
SS
1764 }
1765
1766 case BINOP_EQUAL:
1767 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1768 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
c906108c
SS
1769 if (noside == EVAL_SKIP)
1770 goto nosideret;
1771 if (binop_user_defined_p (op, arg1, arg2))
1772 {
1773 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1774 }
1775 else
1776 {
1777 tem = value_equal (arg1, arg2);
1778 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1779 }
1780
1781 case BINOP_NOTEQUAL:
1782 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1783 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
c906108c
SS
1784 if (noside == EVAL_SKIP)
1785 goto nosideret;
1786 if (binop_user_defined_p (op, arg1, arg2))
1787 {
1788 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1789 }
1790 else
1791 {
1792 tem = value_equal (arg1, arg2);
1793 return value_from_longest (LA_BOOL_TYPE, (LONGEST) ! tem);
1794 }
1795
1796 case BINOP_LESS:
1797 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1798 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
c906108c
SS
1799 if (noside == EVAL_SKIP)
1800 goto nosideret;
1801 if (binop_user_defined_p (op, arg1, arg2))
1802 {
1803 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1804 }
1805 else
1806 {
1807 tem = value_less (arg1, arg2);
1808 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1809 }
1810
1811 case BINOP_GTR:
1812 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1813 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
c906108c
SS
1814 if (noside == EVAL_SKIP)
1815 goto nosideret;
1816 if (binop_user_defined_p (op, arg1, arg2))
1817 {
1818 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1819 }
1820 else
1821 {
1822 tem = value_less (arg2, arg1);
1823 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1824 }
1825
1826 case BINOP_GEQ:
1827 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1828 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
c906108c
SS
1829 if (noside == EVAL_SKIP)
1830 goto nosideret;
1831 if (binop_user_defined_p (op, arg1, arg2))
1832 {
1833 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1834 }
1835 else
1836 {
1837 tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
1838 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1839 }
1840
1841 case BINOP_LEQ:
1842 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
df407dfe 1843 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
c906108c
SS
1844 if (noside == EVAL_SKIP)
1845 goto nosideret;
1846 if (binop_user_defined_p (op, arg1, arg2))
1847 {
1848 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1849 }
c5aa993b 1850 else
c906108c
SS
1851 {
1852 tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
1853 return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem);
1854 }
1855
1856 case BINOP_REPEAT:
1857 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1858 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1859 if (noside == EVAL_SKIP)
1860 goto nosideret;
df407dfe 1861 type = check_typedef (value_type (arg2));
c906108c 1862 if (TYPE_CODE (type) != TYPE_CODE_INT)
8a3fe4f8 1863 error (_("Non-integral right operand for \"@\" operator."));
c906108c
SS
1864 if (noside == EVAL_AVOID_SIDE_EFFECTS)
1865 {
df407dfe 1866 return allocate_repeat_value (value_type (arg1),
c5aa993b 1867 longest_to_int (value_as_long (arg2)));
c906108c
SS
1868 }
1869 else
1870 return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
1871
1872 case BINOP_COMMA:
1873 evaluate_subexp (NULL_TYPE, exp, pos, noside);
1874 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
1875
36e9969c
NS
1876 case UNOP_PLUS:
1877 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1878 if (noside == EVAL_SKIP)
1879 goto nosideret;
1880 if (unop_user_defined_p (op, arg1))
1881 return value_x_unop (arg1, op, noside);
1882 else
1883 return value_pos (arg1);
1884
c906108c
SS
1885 case UNOP_NEG:
1886 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1887 if (noside == EVAL_SKIP)
1888 goto nosideret;
1889 if (unop_user_defined_p (op, arg1))
1890 return value_x_unop (arg1, op, noside);
1891 else
1892 return value_neg (arg1);
1893
1894 case UNOP_COMPLEMENT:
1895 /* C++: check for and handle destructor names. */
1896 op = exp->elts[*pos].opcode;
1897
1898 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1899 if (noside == EVAL_SKIP)
1900 goto nosideret;
1901 if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
1902 return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
1903 else
1904 return value_complement (arg1);
1905
1906 case UNOP_LOGICAL_NOT:
1907 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1908 if (noside == EVAL_SKIP)
1909 goto nosideret;
1910 if (unop_user_defined_p (op, arg1))
1911 return value_x_unop (arg1, op, noside);
1912 else
1913 return value_from_longest (LA_BOOL_TYPE,
1914 (LONGEST) value_logical_not (arg1));
1915
1916 case UNOP_IND:
1917 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
c5aa993b 1918 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
c906108c 1919 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
df407dfe
AC
1920 if ((TYPE_TARGET_TYPE (value_type (arg1))) &&
1921 ((TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg1))) == TYPE_CODE_METHOD) ||
1922 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (arg1))) == TYPE_CODE_MEMBER)))
8a3fe4f8 1923 error (_("Attempt to dereference pointer to member without an object"));
c906108c
SS
1924 if (noside == EVAL_SKIP)
1925 goto nosideret;
1926 if (unop_user_defined_p (op, arg1))
1927 return value_x_unop (arg1, op, noside);
1928 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1929 {
df407dfe 1930 type = check_typedef (value_type (arg1));
c906108c
SS
1931 if (TYPE_CODE (type) == TYPE_CODE_PTR
1932 || TYPE_CODE (type) == TYPE_CODE_REF
c5aa993b 1933 /* In C you can dereference an array to get the 1st elt. */
c906108c 1934 || TYPE_CODE (type) == TYPE_CODE_ARRAY
c5aa993b 1935 )
c906108c
SS
1936 return value_zero (TYPE_TARGET_TYPE (type),
1937 lval_memory);
1938 else if (TYPE_CODE (type) == TYPE_CODE_INT)
1939 /* GDB allows dereferencing an int. */
1940 return value_zero (builtin_type_int, lval_memory);
1941 else
8a3fe4f8 1942 error (_("Attempt to take contents of a non-pointer value."));
c906108c
SS
1943 }
1944 return value_ind (arg1);
1945
1946 case UNOP_ADDR:
1947 /* C++: check for and handle pointer to members. */
c5aa993b 1948
c906108c
SS
1949 op = exp->elts[*pos].opcode;
1950
1951 if (noside == EVAL_SKIP)
1952 {
1953 if (op == OP_SCOPE)
1954 {
c5aa993b 1955 int temm = longest_to_int (exp->elts[pc + 3].longconst);
c906108c
SS
1956 (*pos) += 3 + BYTES_TO_EXP_ELEM (temm + 1);
1957 }
1958 else
cce74817 1959 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
c906108c
SS
1960 goto nosideret;
1961 }
c5aa993b
JM
1962 else
1963 {
61051030 1964 struct value *retvalp = evaluate_subexp_for_address (exp, pos, noside);
c5aa993b 1965 /* If HP aCC object, use bias for pointers to members */
f83f82bc 1966 if (deprecated_hp_som_som_object_present &&
df407dfe
AC
1967 (TYPE_CODE (value_type (retvalp)) == TYPE_CODE_PTR) &&
1968 (TYPE_CODE (TYPE_TARGET_TYPE (value_type (retvalp))) == TYPE_CODE_MEMBER))
c5aa993b 1969 {
0fd88904 1970 unsigned int *ptr = (unsigned int *) value_contents (retvalp); /* forces evaluation */
c5aa993b
JM
1971 *ptr |= 0x20000000; /* set 29th bit */
1972 }
1973 return retvalp;
1974 }
1975
c906108c
SS
1976 case UNOP_SIZEOF:
1977 if (noside == EVAL_SKIP)
1978 {
1979 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
1980 goto nosideret;
1981 }
1982 return evaluate_subexp_for_sizeof (exp, pos);
1983
1984 case UNOP_CAST:
1985 (*pos) += 2;
1986 type = exp->elts[pc + 1].type;
1987 arg1 = evaluate_subexp (type, exp, pos, noside);
1988 if (noside == EVAL_SKIP)
1989 goto nosideret;
df407dfe 1990 if (type != value_type (arg1))
c906108c
SS
1991 arg1 = value_cast (type, arg1);
1992 return arg1;
1993
1994 case UNOP_MEMVAL:
1995 (*pos) += 2;
1996 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
1997 if (noside == EVAL_SKIP)
1998 goto nosideret;
1999 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2000 return value_zero (exp->elts[pc + 1].type, lval_memory);
2001 else
2002 return value_at_lazy (exp->elts[pc + 1].type,
00a4c844 2003 value_as_address (arg1));
c906108c
SS
2004
2005 case UNOP_PREINCREMENT:
2006 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2007 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2008 return arg1;
2009 else if (unop_user_defined_p (op, arg1))
2010 {
2011 return value_x_unop (arg1, op, noside);
2012 }
2013 else
2014 {
c5aa993b
JM
2015 arg2 = value_add (arg1, value_from_longest (builtin_type_char,
2016 (LONGEST) 1));
c906108c
SS
2017 return value_assign (arg1, arg2);
2018 }
2019
2020 case UNOP_PREDECREMENT:
2021 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2022 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2023 return arg1;
2024 else if (unop_user_defined_p (op, arg1))
2025 {
2026 return value_x_unop (arg1, op, noside);
2027 }
2028 else
2029 {
c5aa993b
JM
2030 arg2 = value_sub (arg1, value_from_longest (builtin_type_char,
2031 (LONGEST) 1));
c906108c
SS
2032 return value_assign (arg1, arg2);
2033 }
2034
2035 case UNOP_POSTINCREMENT:
2036 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2037 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2038 return arg1;
2039 else if (unop_user_defined_p (op, arg1))
2040 {
2041 return value_x_unop (arg1, op, noside);
2042 }
2043 else
2044 {
c5aa993b
JM
2045 arg2 = value_add (arg1, value_from_longest (builtin_type_char,
2046 (LONGEST) 1));
c906108c
SS
2047 value_assign (arg1, arg2);
2048 return arg1;
2049 }
2050
2051 case UNOP_POSTDECREMENT:
2052 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2053 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
2054 return arg1;
2055 else if (unop_user_defined_p (op, arg1))
2056 {
2057 return value_x_unop (arg1, op, noside);
2058 }
2059 else
2060 {
c5aa993b
JM
2061 arg2 = value_sub (arg1, value_from_longest (builtin_type_char,
2062 (LONGEST) 1));
c906108c
SS
2063 value_assign (arg1, arg2);
2064 return arg1;
2065 }
c5aa993b 2066
c906108c
SS
2067 case OP_THIS:
2068 (*pos) += 1;
2069 return value_of_this (1);
2070
a9fa03de
AF
2071 case OP_OBJC_SELF:
2072 (*pos) += 1;
2073 return value_of_local ("self", 1);
2074
c906108c 2075 case OP_TYPE:
8a3fe4f8 2076 error (_("Attempt to use a type name as an expression"));
c906108c
SS
2077
2078 default:
2079 /* Removing this case and compiling with gcc -Wall reveals that
c5aa993b 2080 a lot of cases are hitting this case. Some of these should
2df3850c
JM
2081 probably be removed from expression.h; others are legitimate
2082 expressions which are (apparently) not fully implemented.
c906108c 2083
c5aa993b
JM
2084 If there are any cases landing here which mean a user error,
2085 then they should be separate cases, with more descriptive
2086 error messages. */
c906108c 2087
8a3fe4f8
AC
2088 error (_("\
2089GDB does not (yet) know how to evaluate that kind of expression"));
c906108c
SS
2090 }
2091
c5aa993b 2092nosideret:
c906108c
SS
2093 return value_from_longest (builtin_type_long, (LONGEST) 1);
2094}
2095\f
2096/* Evaluate a subexpression of EXP, at index *POS,
2097 and return the address of that subexpression.
2098 Advance *POS over the subexpression.
2099 If the subexpression isn't an lvalue, get an error.
2100 NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
2101 then only the type of the result need be correct. */
2102
61051030 2103static struct value *
aa1ee363 2104evaluate_subexp_for_address (struct expression *exp, int *pos,
fba45db2 2105 enum noside noside)
c906108c
SS
2106{
2107 enum exp_opcode op;
52f0bd74 2108 int pc;
c906108c
SS
2109 struct symbol *var;
2110
2111 pc = (*pos);
2112 op = exp->elts[pc].opcode;
2113
2114 switch (op)
2115 {
2116 case UNOP_IND:
2117 (*pos)++;
2118 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
2119
2120 case UNOP_MEMVAL:
2121 (*pos) += 3;
2122 return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
2123 evaluate_subexp (NULL_TYPE, exp, pos, noside));
2124
2125 case OP_VAR_VALUE:
2126 var = exp->elts[pc + 2].symbol;
2127
2128 /* C++: The "address" of a reference should yield the address
2129 * of the object pointed to. Let value_addr() deal with it. */
2130 if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
c5aa993b 2131 goto default_case;
c906108c
SS
2132
2133 (*pos) += 4;
2134 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2135 {
2136 struct type *type =
c5aa993b 2137 lookup_pointer_type (SYMBOL_TYPE (var));
c906108c
SS
2138 enum address_class sym_class = SYMBOL_CLASS (var);
2139
2140 if (sym_class == LOC_CONST
2141 || sym_class == LOC_CONST_BYTES
2142 || sym_class == LOC_REGISTER
2143 || sym_class == LOC_REGPARM)
8a3fe4f8 2144 error (_("Attempt to take address of register or constant."));
c906108c 2145
c5aa993b
JM
2146 return
2147 value_zero (type, not_lval);
c906108c
SS
2148 }
2149 else
2150 return
2151 locate_var_value
c5aa993b
JM
2152 (var,
2153 block_innermost_frame (exp->elts[pc + 1].block));
c906108c
SS
2154
2155 default:
2156 default_case:
2157 if (noside == EVAL_AVOID_SIDE_EFFECTS)
2158 {
61051030 2159 struct value *x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
c906108c 2160 if (VALUE_LVAL (x) == lval_memory)
df407dfe 2161 return value_zero (lookup_pointer_type (value_type (x)),
c906108c
SS
2162 not_lval);
2163 else
8a3fe4f8 2164 error (_("Attempt to take address of non-lval"));
c906108c
SS
2165 }
2166 return value_addr (evaluate_subexp (NULL_TYPE, exp, pos, noside));
2167 }
2168}
2169
2170/* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
2171 When used in contexts where arrays will be coerced anyway, this is
2172 equivalent to `evaluate_subexp' but much faster because it avoids
2173 actually fetching array contents (perhaps obsolete now that we have
d69fe07e 2174 value_lazy()).
c906108c
SS
2175
2176 Note that we currently only do the coercion for C expressions, where
2177 arrays are zero based and the coercion is correct. For other languages,
2178 with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
2179 to decide if coercion is appropriate.
2180
c5aa993b 2181 */
c906108c 2182
61051030 2183struct value *
aa1ee363
AC
2184evaluate_subexp_with_coercion (struct expression *exp,
2185 int *pos, enum noside noside)
c906108c 2186{
52f0bd74
AC
2187 enum exp_opcode op;
2188 int pc;
61051030 2189 struct value *val;
c906108c
SS
2190 struct symbol *var;
2191
2192 pc = (*pos);
2193 op = exp->elts[pc].opcode;
2194
2195 switch (op)
2196 {
2197 case OP_VAR_VALUE:
2198 var = exp->elts[pc + 2].symbol;
2199 if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var))) == TYPE_CODE_ARRAY
2200 && CAST_IS_CONVERSION)
2201 {
2202 (*pos) += 4;
2203 val =
2204 locate_var_value
c5aa993b 2205 (var, block_innermost_frame (exp->elts[pc + 1].block));
751a959b 2206 return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var)))),
c906108c
SS
2207 val);
2208 }
2209 /* FALLTHROUGH */
2210
2211 default:
2212 return evaluate_subexp (NULL_TYPE, exp, pos, noside);
2213 }
2214}
2215
2216/* Evaluate a subexpression of EXP, at index *POS,
2217 and return a value for the size of that subexpression.
2218 Advance *POS over the subexpression. */
2219
61051030 2220static struct value *
aa1ee363 2221evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
c906108c
SS
2222{
2223 enum exp_opcode op;
52f0bd74 2224 int pc;
c906108c 2225 struct type *type;
61051030 2226 struct value *val;
c906108c
SS
2227
2228 pc = (*pos);
2229 op = exp->elts[pc].opcode;
2230
2231 switch (op)
2232 {
2233 /* This case is handled specially
c5aa993b
JM
2234 so that we avoid creating a value for the result type.
2235 If the result type is very big, it's desirable not to
2236 create a value unnecessarily. */
c906108c
SS
2237 case UNOP_IND:
2238 (*pos)++;
2239 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
df407dfe 2240 type = check_typedef (value_type (val));
c906108c
SS
2241 if (TYPE_CODE (type) != TYPE_CODE_PTR
2242 && TYPE_CODE (type) != TYPE_CODE_REF
2243 && TYPE_CODE (type) != TYPE_CODE_ARRAY)
8a3fe4f8 2244 error (_("Attempt to take contents of a non-pointer value."));
c906108c
SS
2245 type = check_typedef (TYPE_TARGET_TYPE (type));
2246 return value_from_longest (builtin_type_int, (LONGEST)
c5aa993b 2247 TYPE_LENGTH (type));
c906108c
SS
2248
2249 case UNOP_MEMVAL:
2250 (*pos) += 3;
2251 type = check_typedef (exp->elts[pc + 1].type);
2252 return value_from_longest (builtin_type_int,
2253 (LONGEST) TYPE_LENGTH (type));
2254
2255 case OP_VAR_VALUE:
2256 (*pos) += 4;
2257 type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
2258 return
2259 value_from_longest (builtin_type_int, (LONGEST) TYPE_LENGTH (type));
2260
2261 default:
2262 val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2263 return value_from_longest (builtin_type_int,
df407dfe 2264 (LONGEST) TYPE_LENGTH (value_type (val)));
c906108c
SS
2265 }
2266}
2267
2268/* Parse a type expression in the string [P..P+LENGTH). */
2269
2270struct type *
fba45db2 2271parse_and_eval_type (char *p, int length)
c906108c 2272{
c5aa993b
JM
2273 char *tmp = (char *) alloca (length + 4);
2274 struct expression *expr;
2275 tmp[0] = '(';
2276 memcpy (tmp + 1, p, length);
2277 tmp[length + 1] = ')';
2278 tmp[length + 2] = '0';
2279 tmp[length + 3] = '\0';
2280 expr = parse_expression (tmp);
2281 if (expr->elts[0].opcode != UNOP_CAST)
8a3fe4f8 2282 error (_("Internal error in eval_type."));
c5aa993b 2283 return expr->elts[1].type;
c906108c
SS
2284}
2285
2286int
fba45db2 2287calc_f77_array_dims (struct type *array_type)
c906108c
SS
2288{
2289 int ndimen = 1;
2290 struct type *tmp_type;
2291
c5aa993b 2292 if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
8a3fe4f8 2293 error (_("Can't get dimensions for a non-array type"));
c5aa993b
JM
2294
2295 tmp_type = array_type;
c906108c
SS
2296
2297 while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
2298 {
2299 if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
2300 ++ndimen;
2301 }
c5aa993b 2302 return ndimen;
c906108c 2303}