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