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