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