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