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