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