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