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