]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Evaluate expressions for GDB. |
2d67c7e9 PB |
2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994 |
3 | Free Software Foundation, Inc. | |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
2ccb3837 | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
2ccb3837 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
2ccb3837 | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
2ccb3837 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 RP |
20 | |
21 | #include "defs.h" | |
2d67c7e9 | 22 | #include <string.h> |
bd5635a1 | 23 | #include "symtab.h" |
01be6913 | 24 | #include "gdbtypes.h" |
bd5635a1 RP |
25 | #include "value.h" |
26 | #include "expression.h" | |
27 | #include "target.h" | |
2ccb3837 | 28 | #include "frame.h" |
40620258 | 29 | #include "demangle.h" |
fb6e675f | 30 | #include "language.h" /* For CAST_IS_CONVERSION */ |
2d67c7e9 | 31 | #include "f-lang.h" /* for array bound stuff */ |
bd5635a1 | 32 | |
01be6913 | 33 | /* Values of NOSIDE argument to eval_subexp. */ |
2d67c7e9 | 34 | |
01be6913 | 35 | enum noside |
2d67c7e9 PB |
36 | { |
37 | EVAL_NORMAL, | |
01be6913 PB |
38 | EVAL_SKIP, /* Only effect is to increment pos. */ |
39 | EVAL_AVOID_SIDE_EFFECTS /* Don't modify any variables or | |
40 | call any functions. The value | |
41 | returned will have the correct | |
42 | type, and will have an | |
43 | approximately correct lvalue | |
44 | type (inaccuracy: anything that is | |
45 | listed as being in a register in | |
46 | the function in which it was | |
47 | declared will be lval_register). */ | |
48 | }; | |
49 | ||
50 | /* Prototypes for local functions. */ | |
51 | ||
2d67c7e9 PB |
52 | static value_ptr evaluate_subexp_for_sizeof PARAMS ((struct expression *, |
53 | int *)); | |
01be6913 | 54 | |
2d67c7e9 PB |
55 | static value_ptr evaluate_subexp_with_coercion PARAMS ((struct expression *, |
56 | int *, enum noside)); | |
01be6913 | 57 | |
2d67c7e9 PB |
58 | static value_ptr evaluate_subexp_for_address PARAMS ((struct expression *, |
59 | int *, enum noside)); | |
01be6913 | 60 | |
2d67c7e9 PB |
61 | static value_ptr evaluate_subexp PARAMS ((struct type *, struct expression *, |
62 | int *, enum noside)); | |
bd5635a1 RP |
63 | |
64 | \f | |
65 | /* Parse the string EXP as a C expression, evaluate it, | |
66 | and return the result as a number. */ | |
67 | ||
68 | CORE_ADDR | |
69 | parse_and_eval_address (exp) | |
70 | char *exp; | |
71 | { | |
2ccb3837 | 72 | struct expression *expr = parse_expression (exp); |
bd5635a1 | 73 | register CORE_ADDR addr; |
01be6913 PB |
74 | register struct cleanup *old_chain = |
75 | make_cleanup (free_current_contents, &expr); | |
bd5635a1 | 76 | |
2ccb3837 | 77 | addr = value_as_pointer (evaluate_expression (expr)); |
bd5635a1 RP |
78 | do_cleanups (old_chain); |
79 | return addr; | |
80 | } | |
81 | ||
82 | /* Like parse_and_eval_address but takes a pointer to a char * variable | |
83 | and advanced that variable across the characters parsed. */ | |
84 | ||
85 | CORE_ADDR | |
86 | parse_and_eval_address_1 (expptr) | |
87 | char **expptr; | |
88 | { | |
2ccb3837 | 89 | struct expression *expr = parse_exp_1 (expptr, (struct block *)0, 0); |
bd5635a1 | 90 | register CORE_ADDR addr; |
01be6913 PB |
91 | register struct cleanup *old_chain = |
92 | make_cleanup (free_current_contents, &expr); | |
bd5635a1 | 93 | |
2ccb3837 | 94 | addr = value_as_pointer (evaluate_expression (expr)); |
bd5635a1 RP |
95 | do_cleanups (old_chain); |
96 | return addr; | |
97 | } | |
98 | ||
2d67c7e9 | 99 | value_ptr |
bd5635a1 RP |
100 | parse_and_eval (exp) |
101 | char *exp; | |
102 | { | |
2ccb3837 | 103 | struct expression *expr = parse_expression (exp); |
2d67c7e9 | 104 | register value_ptr val; |
bd5635a1 RP |
105 | register struct cleanup *old_chain |
106 | = make_cleanup (free_current_contents, &expr); | |
107 | ||
108 | val = evaluate_expression (expr); | |
109 | do_cleanups (old_chain); | |
110 | return val; | |
111 | } | |
112 | ||
113 | /* Parse up to a comma (or to a closeparen) | |
114 | in the string EXPP as an expression, evaluate it, and return the value. | |
115 | EXPP is advanced to point to the comma. */ | |
116 | ||
2d67c7e9 | 117 | value_ptr |
bd5635a1 RP |
118 | parse_to_comma_and_eval (expp) |
119 | char **expp; | |
120 | { | |
2ccb3837 | 121 | struct expression *expr = parse_exp_1 (expp, (struct block *) 0, 1); |
2d67c7e9 | 122 | register value_ptr val; |
bd5635a1 RP |
123 | register struct cleanup *old_chain |
124 | = make_cleanup (free_current_contents, &expr); | |
125 | ||
126 | val = evaluate_expression (expr); | |
127 | do_cleanups (old_chain); | |
128 | return val; | |
129 | } | |
130 | \f | |
131 | /* Evaluate an expression in internal prefix form | |
0a5d35ed | 132 | such as is constructed by parse.y. |
bd5635a1 RP |
133 | |
134 | See expression.h for info on the format of an expression. */ | |
135 | ||
2d67c7e9 | 136 | value_ptr |
bd5635a1 RP |
137 | evaluate_expression (exp) |
138 | struct expression *exp; | |
139 | { | |
140 | int pc = 0; | |
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 | ||
2d67c7e9 | 147 | value_ptr |
bd5635a1 RP |
148 | evaluate_type (exp) |
149 | struct expression *exp; | |
150 | { | |
151 | int pc = 0; | |
152 | return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS); | |
153 | } | |
154 | ||
2d67c7e9 | 155 | static value_ptr |
bd5635a1 RP |
156 | evaluate_subexp (expect_type, exp, pos, noside) |
157 | struct type *expect_type; | |
158 | register struct expression *exp; | |
159 | register int *pos; | |
160 | enum noside noside; | |
161 | { | |
162 | enum exp_opcode op; | |
1500864f | 163 | int tem, tem2, tem3; |
40620258 | 164 | register int pc, pc2 = 0, oldpos; |
2d67c7e9 | 165 | register value_ptr arg1 = NULL, arg2 = NULL, arg3; |
01be6913 | 166 | struct type *type; |
bd5635a1 | 167 | int nargs; |
2d67c7e9 PB |
168 | value_ptr *argvec; |
169 | int tmp_pos, tmp1_pos; | |
170 | struct symbol *tmp_symbol; | |
171 | int upper, lower, retcode; | |
172 | int code; | |
173 | struct internalvar *var; | |
bd5635a1 RP |
174 | |
175 | pc = (*pos)++; | |
176 | op = exp->elts[pc].opcode; | |
177 | ||
178 | switch (op) | |
179 | { | |
180 | case OP_SCOPE: | |
a8a69e63 | 181 | tem = longest_to_int (exp->elts[pc + 2].longconst); |
1500864f | 182 | (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1); |
01be6913 | 183 | arg1 = value_struct_elt_for_reference (exp->elts[pc + 1].type, |
8f86a4e4 | 184 | 0, |
01be6913 | 185 | exp->elts[pc + 1].type, |
a8a69e63 | 186 | &exp->elts[pc + 3].string, |
01be6913 | 187 | expect_type); |
5f00ca54 | 188 | if (arg1 == NULL) |
a8a69e63 | 189 | error ("There is no field named %s", &exp->elts[pc + 3].string); |
5f00ca54 | 190 | return arg1; |
bd5635a1 RP |
191 | |
192 | case OP_LONG: | |
193 | (*pos) += 3; | |
2ccb3837 | 194 | return value_from_longest (exp->elts[pc + 1].type, |
a8a69e63 | 195 | exp->elts[pc + 2].longconst); |
bd5635a1 RP |
196 | |
197 | case OP_DOUBLE: | |
198 | (*pos) += 3; | |
199 | return value_from_double (exp->elts[pc + 1].type, | |
200 | exp->elts[pc + 2].doubleconst); | |
201 | ||
202 | case OP_VAR_VALUE: | |
479fdd26 | 203 | (*pos) += 3; |
bd5635a1 RP |
204 | if (noside == EVAL_SKIP) |
205 | goto nosideret; | |
206 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
207 | { | |
40620258 | 208 | struct symbol * sym = exp->elts[pc + 2].symbol; |
bd5635a1 RP |
209 | enum lval_type lv; |
210 | ||
211 | switch (SYMBOL_CLASS (sym)) | |
212 | { | |
213 | case LOC_CONST: | |
214 | case LOC_LABEL: | |
215 | case LOC_CONST_BYTES: | |
216 | lv = not_lval; | |
217 | break; | |
218 | ||
219 | case LOC_REGISTER: | |
220 | case LOC_REGPARM: | |
221 | lv = lval_register; | |
222 | break; | |
223 | ||
224 | default: | |
225 | lv = lval_memory; | |
226 | break; | |
227 | } | |
228 | ||
229 | return value_zero (SYMBOL_TYPE (sym), lv); | |
230 | } | |
231 | else | |
479fdd26 JK |
232 | return value_of_variable (exp->elts[pc + 2].symbol, |
233 | exp->elts[pc + 1].block); | |
bd5635a1 RP |
234 | |
235 | case OP_LAST: | |
236 | (*pos) += 2; | |
2ccb3837 JG |
237 | return |
238 | access_value_history (longest_to_int (exp->elts[pc + 1].longconst)); | |
bd5635a1 RP |
239 | |
240 | case OP_REGISTER: | |
241 | (*pos) += 2; | |
2ccb3837 | 242 | return value_of_register (longest_to_int (exp->elts[pc + 1].longconst)); |
bd5635a1 | 243 | |
e58de8a2 FF |
244 | case OP_BOOL: |
245 | (*pos) += 2; | |
2d67c7e9 PB |
246 | if (current_language->la_language == language_fortran) |
247 | return value_from_longest (builtin_type_f_logical_s2, | |
248 | exp->elts[pc + 1].longconst); | |
249 | else | |
250 | return value_from_longest (builtin_type_chill_bool, | |
251 | exp->elts[pc + 1].longconst); | |
e58de8a2 | 252 | |
bd5635a1 RP |
253 | case OP_INTERNALVAR: |
254 | (*pos) += 2; | |
255 | return value_of_internalvar (exp->elts[pc + 1].internalvar); | |
256 | ||
257 | case OP_STRING: | |
a8a69e63 | 258 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
1500864f | 259 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
bd5635a1 RP |
260 | if (noside == EVAL_SKIP) |
261 | goto nosideret; | |
a8a69e63 | 262 | return value_string (&exp->elts[pc + 2].string, tem); |
bd5635a1 | 263 | |
1500864f JK |
264 | case OP_BITSTRING: |
265 | error ("support for OP_BITSTRING unimplemented"); | |
266 | break; | |
267 | ||
268 | case OP_ARRAY: | |
269 | (*pos) += 3; | |
270 | tem2 = longest_to_int (exp->elts[pc + 1].longconst); | |
271 | tem3 = longest_to_int (exp->elts[pc + 2].longconst); | |
272 | nargs = tem3 - tem2 + 1; | |
2d67c7e9 PB |
273 | |
274 | if (expect_type != NULL_TYPE && noside != EVAL_SKIP | |
275 | && TYPE_CODE (expect_type) == TYPE_CODE_STRUCT) | |
276 | { | |
277 | value_ptr rec = allocate_value (expect_type); | |
278 | if (TYPE_NFIELDS (expect_type) != nargs) | |
279 | error ("wrong number of initialiers for structure type"); | |
280 | for (tem = 0; tem < nargs; tem++) | |
281 | { | |
282 | struct type *field_type = TYPE_FIELD_TYPE (expect_type, tem); | |
283 | value_ptr field_val = evaluate_subexp (field_type, | |
284 | exp, pos, noside); | |
285 | int bitsize, bitpos; | |
286 | char *addr; | |
287 | if (VALUE_TYPE (field_val) != field_type) | |
288 | field_val = value_cast (field_type, field_val); | |
289 | #if 1 | |
290 | bitsize = TYPE_FIELD_BITSIZE (expect_type, tem); | |
291 | bitpos = TYPE_FIELD_BITPOS (expect_type, tem); | |
292 | addr = VALUE_CONTENTS (rec); | |
293 | addr += bitpos / 8; | |
294 | if (bitsize) | |
295 | modify_field (addr, value_as_long (field_val), | |
296 | bitpos % 8, bitsize); | |
297 | else | |
298 | memcpy (addr, VALUE_CONTENTS (field_val), | |
299 | TYPE_LENGTH (VALUE_TYPE (field_val))); | |
300 | #else | |
301 | value_assign (value_primitive_field (rec, 0, tem, expect_type), | |
302 | field_val); | |
303 | #endif | |
304 | } | |
305 | return rec; | |
306 | } | |
307 | ||
308 | if (expect_type != NULL_TYPE && noside != EVAL_SKIP | |
309 | && TYPE_CODE (expect_type) == TYPE_CODE_ARRAY) | |
310 | { | |
311 | struct type *range_type = TYPE_FIELD_TYPE (expect_type, 0); | |
312 | struct type *element_type = TYPE_TARGET_TYPE (expect_type); | |
313 | LONGEST low_bound = TYPE_FIELD_BITPOS (range_type, 0); | |
314 | LONGEST high_bound = TYPE_FIELD_BITPOS (range_type, 1); | |
315 | int element_size = TYPE_LENGTH (element_type); | |
316 | value_ptr rec = allocate_value (expect_type); | |
317 | if (nargs != (high_bound - low_bound + 1)) | |
318 | error ("wrong number of initialiers for array type"); | |
319 | for (tem = low_bound; tem <= high_bound; tem++) | |
320 | { | |
321 | value_ptr element = evaluate_subexp (element_type, | |
322 | exp, pos, noside); | |
323 | memcpy (VALUE_CONTENTS_RAW (rec) | |
324 | + (tem - low_bound) * element_size, | |
325 | VALUE_CONTENTS (element), | |
326 | element_size); | |
327 | } | |
328 | return rec; | |
329 | } | |
330 | ||
331 | argvec = (value_ptr *) alloca (sizeof (value_ptr) * nargs); | |
1500864f JK |
332 | for (tem = 0; tem < nargs; tem++) |
333 | { | |
334 | /* Ensure that array expressions are coerced into pointer objects. */ | |
335 | argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside); | |
336 | } | |
337 | if (noside == EVAL_SKIP) | |
338 | goto nosideret; | |
2d67c7e9 PB |
339 | if (current_language->la_language == language_fortran) |
340 | /* For F77, we need to do special things to literal strings */ | |
341 | return (f77_value_literal_string (tem2, tem3, argvec)); | |
342 | return value_array (tem2, tem3, argvec); | |
1500864f JK |
343 | break; |
344 | ||
bd5635a1 RP |
345 | case TERNOP_COND: |
346 | /* Skip third and second args to evaluate the first one. */ | |
347 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
e58de8a2 | 348 | if (value_logical_not (arg1)) |
bd5635a1 RP |
349 | { |
350 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
351 | return evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
352 | } | |
353 | else | |
354 | { | |
355 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
356 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
357 | return arg2; | |
358 | } | |
359 | ||
360 | case OP_FUNCALL: | |
361 | (*pos) += 2; | |
362 | op = exp->elts[*pos].opcode; | |
363 | if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR) | |
364 | { | |
2d67c7e9 | 365 | LONGEST fnptr; |
bd5635a1 | 366 | |
2ccb3837 | 367 | nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1; |
bd5635a1 RP |
368 | /* First, evaluate the structure into arg2 */ |
369 | pc2 = (*pos)++; | |
370 | ||
371 | if (noside == EVAL_SKIP) | |
372 | goto nosideret; | |
373 | ||
374 | if (op == STRUCTOP_MEMBER) | |
375 | { | |
376 | arg2 = evaluate_subexp_for_address (exp, pos, noside); | |
377 | } | |
378 | else | |
379 | { | |
380 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
381 | } | |
382 | ||
383 | /* If the function is a virtual function, then the | |
384 | aggregate value (providing the structure) plays | |
385 | its part by providing the vtable. Otherwise, | |
386 | it is just along for the ride: call the function | |
387 | directly. */ | |
388 | ||
389 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
390 | ||
2d67c7e9 | 391 | fnptr = value_as_long (arg1); |
35fcebce PB |
392 | |
393 | if (METHOD_PTR_IS_VIRTUAL(fnptr)) | |
bd5635a1 | 394 | { |
35fcebce | 395 | int fnoffset = METHOD_PTR_TO_VOFFSET(fnptr); |
bd5635a1 | 396 | struct type *basetype; |
35fcebce PB |
397 | struct type *domain_type = |
398 | TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))); | |
bd5635a1 RP |
399 | int i, j; |
400 | basetype = TYPE_TARGET_TYPE (VALUE_TYPE (arg2)); | |
35fcebce PB |
401 | if (domain_type != basetype) |
402 | arg2 = value_cast(lookup_pointer_type (domain_type), arg2); | |
403 | basetype = TYPE_VPTR_BASETYPE (domain_type); | |
bd5635a1 RP |
404 | for (i = TYPE_NFN_FIELDS (basetype) - 1; i >= 0; i--) |
405 | { | |
406 | struct fn_field *f = TYPE_FN_FIELDLIST1 (basetype, i); | |
407 | /* If one is virtual, then all are virtual. */ | |
408 | if (TYPE_FN_FIELD_VIRTUAL_P (f, 0)) | |
409 | for (j = TYPE_FN_FIELDLIST_LENGTH (basetype, i) - 1; j >= 0; --j) | |
35fcebce | 410 | if (TYPE_FN_FIELD_VOFFSET (f, j) == fnoffset) |
bd5635a1 | 411 | { |
2d67c7e9 | 412 | value_ptr temp = value_ind (arg2); |
35fcebce PB |
413 | arg1 = value_virtual_fn_field (&temp, f, j, domain_type, 0); |
414 | arg2 = value_addr (temp); | |
bd5635a1 RP |
415 | goto got_it; |
416 | } | |
417 | } | |
418 | if (i < 0) | |
35fcebce | 419 | error ("virtual function at index %d not found", fnoffset); |
bd5635a1 RP |
420 | } |
421 | else | |
422 | { | |
423 | VALUE_TYPE (arg1) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))); | |
424 | } | |
425 | got_it: | |
426 | ||
427 | /* Now, say which argument to start evaluating from */ | |
428 | tem = 2; | |
429 | } | |
430 | else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR) | |
431 | { | |
432 | /* Hair for method invocations */ | |
433 | int tem2; | |
434 | ||
2ccb3837 | 435 | nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1; |
bd5635a1 RP |
436 | /* First, evaluate the structure into arg2 */ |
437 | pc2 = (*pos)++; | |
a8a69e63 | 438 | tem2 = longest_to_int (exp->elts[pc2 + 1].longconst); |
1500864f | 439 | *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1); |
bd5635a1 RP |
440 | if (noside == EVAL_SKIP) |
441 | goto nosideret; | |
442 | ||
443 | if (op == STRUCTOP_STRUCT) | |
444 | { | |
479fdd26 JK |
445 | /* If v is a variable in a register, and the user types |
446 | v.method (), this will produce an error, because v has | |
447 | no address. | |
448 | ||
449 | A possible way around this would be to allocate a | |
450 | copy of the variable on the stack, copy in the | |
451 | contents, call the function, and copy out the | |
452 | contents. I.e. convert this from call by reference | |
453 | to call by copy-return (or whatever it's called). | |
454 | However, this does not work because it is not the | |
455 | same: the method being called could stash a copy of | |
456 | the address, and then future uses through that address | |
457 | (after the method returns) would be expected to | |
458 | use the variable itself, not some copy of it. */ | |
bd5635a1 RP |
459 | arg2 = evaluate_subexp_for_address (exp, pos, noside); |
460 | } | |
461 | else | |
462 | { | |
463 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
464 | } | |
465 | /* Now, say which argument to start evaluating from */ | |
466 | tem = 2; | |
467 | } | |
468 | else | |
469 | { | |
2ccb3837 | 470 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
bd5635a1 RP |
471 | tem = 0; |
472 | } | |
1500864f JK |
473 | /* Allocate arg vector, including space for the function to be |
474 | called in argvec[0] and a terminating NULL */ | |
2d67c7e9 | 475 | argvec = (value_ptr *) alloca (sizeof (value_ptr) * (nargs + 2)); |
bd5635a1 RP |
476 | for (; tem <= nargs; tem++) |
477 | /* Ensure that array expressions are coerced into pointer objects. */ | |
478 | argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside); | |
479 | ||
480 | /* signal end of arglist */ | |
481 | argvec[tem] = 0; | |
482 | ||
483 | if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR) | |
484 | { | |
485 | int static_memfuncp; | |
2d67c7e9 PB |
486 | value_ptr temp = arg2; |
487 | char tstr[64]; | |
bd5635a1 RP |
488 | |
489 | argvec[1] = arg2; | |
40620258 KH |
490 | argvec[0] = 0; |
491 | strcpy(tstr, &exp->elts[pc2+2].string); | |
40620258 | 492 | if (!argvec[0]) |
bd5635a1 | 493 | { |
40620258 KH |
494 | temp = arg2; |
495 | argvec[0] = | |
496 | value_struct_elt (&temp, argvec+1, tstr, | |
497 | &static_memfuncp, | |
498 | op == STRUCTOP_STRUCT | |
499 | ? "structure" : "structure pointer"); | |
bd5635a1 | 500 | } |
40620258 KH |
501 | arg2 = value_from_longest (lookup_pointer_type(VALUE_TYPE (temp)), |
502 | VALUE_ADDRESS (temp)+VALUE_OFFSET (temp)); | |
503 | argvec[1] = arg2; | |
504 | ||
bd5635a1 RP |
505 | if (static_memfuncp) |
506 | { | |
507 | argvec[1] = argvec[0]; | |
508 | nargs--; | |
509 | argvec++; | |
510 | } | |
511 | } | |
512 | else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR) | |
513 | { | |
514 | argvec[1] = arg2; | |
515 | argvec[0] = arg1; | |
516 | } | |
517 | ||
518 | if (noside == EVAL_SKIP) | |
519 | goto nosideret; | |
520 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
521 | { | |
522 | /* If the return type doesn't look like a function type, call an | |
523 | error. This can happen if somebody tries to turn a variable into | |
524 | a function call. This is here because people often want to | |
525 | call, eg, strcmp, which gdb doesn't know is a function. If | |
526 | gdb isn't asked for it's opinion (ie. through "whatis"), | |
527 | it won't offer it. */ | |
528 | ||
529 | struct type *ftype = | |
530 | TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0])); | |
531 | ||
532 | if (ftype) | |
533 | return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0]))); | |
534 | else | |
535 | error ("Expression of type other than \"Function returning ...\" used as function"); | |
536 | } | |
e17960fb | 537 | return call_function_by_hand (argvec[0], nargs, argvec + 1); |
bd5635a1 | 538 | |
2d67c7e9 PB |
539 | case OP_F77_UNDETERMINED_ARGLIST: |
540 | ||
541 | tmp_pos = pc; /* Point to this instr */ | |
542 | ||
543 | /* Remember that in F77, functions, substring ops and | |
544 | array subscript operations cannot be disambiguated | |
545 | at parse time. We have made all array subscript operations, | |
546 | substring operations as well as function calls come here | |
547 | and we now have to discover what the heck this thing actually was. | |
548 | If it is an array, we massage it into a form that the | |
549 | MULTI_F77_SUBSCRIPT operator can deal with. If it is | |
550 | a function, we process just as if we got an OP_FUNCALL and | |
551 | for a subscring operation, we perform the appropriate | |
552 | substring operation. */ | |
553 | ||
554 | /* First get the nargs and then jump all the way over the: | |
555 | ||
556 | OP_UNDETERMINED_ARGLIST | |
557 | nargs | |
558 | OP_UNDETERMINED_ARGLIST | |
559 | ||
560 | instruction sequence */ | |
561 | ||
562 | nargs = longest_to_int (exp->elts[tmp_pos+1].longconst); | |
563 | tmp_pos += 3; /* size(op_funcall) == 3 elts */ | |
564 | ||
565 | /* We will always have an OP_VAR_VALUE as the next opcode. | |
566 | The data stored after the OP_VAR_VALUE is the a pointer | |
567 | to the function/array/string symbol. We should now check and | |
568 | make sure that the symbols is an array and not a function. | |
569 | If it is an array type, we have hit a F77 subscript operation and | |
570 | we have to do some magic. If it is not an array, we check | |
571 | to see if we found a string here. If there is a string, | |
572 | we recursively evaluate and let OP_f77_SUBSTR deal with | |
573 | things. If there is no string, we know there is a function | |
574 | call at hand and change OP_FUNCALL_OR_SUBSCRIPT -> OP_FUNCALL. | |
575 | In all cases, we recursively evaluate. */ | |
576 | ||
577 | /* First determine the type code we are dealing with. */ | |
578 | ||
579 | switch (exp->elts[tmp_pos].opcode) | |
580 | { | |
581 | case OP_VAR_VALUE: | |
582 | tmp_pos += 1; /* To get to the symbol ptr */ | |
583 | tmp_symbol = exp->elts[tmp_pos].symbol; | |
584 | code = TYPE_CODE (SYMBOL_TYPE (tmp_symbol)); | |
585 | break; | |
586 | ||
587 | case OP_INTERNALVAR: | |
588 | tmp_pos += 1; | |
589 | var = exp->elts[tmp_pos].internalvar; | |
590 | code = TYPE_CODE(VALUE_TYPE(var->value)); | |
591 | break; | |
592 | ||
593 | case OP_F77_UNDETERMINED_ARGLIST: | |
594 | /* Special case when you do stuff like print ARRAY(1,1)(3:4) */ | |
595 | tmp1_pos = tmp_pos ; | |
596 | arg2 = evaluate_subexp (NULL_TYPE, exp, &tmp1_pos, noside); | |
597 | code =TYPE_CODE (VALUE_TYPE (arg2)); | |
598 | break; | |
599 | ||
600 | default: | |
601 | error ("Cannot perform substring on this type"); | |
602 | } | |
603 | ||
604 | switch (code) | |
605 | { | |
606 | case TYPE_CODE_ARRAY: | |
607 | /* Transform this into what it really is: a MULTI_F77_SUBSCRIPT */ | |
608 | tmp_pos = pc; | |
609 | exp->elts[tmp_pos].opcode = MULTI_F77_SUBSCRIPT; | |
610 | exp->elts[tmp_pos+2].opcode = MULTI_F77_SUBSCRIPT; | |
611 | break; | |
612 | ||
613 | case TYPE_CODE_LITERAL_STRING: /* When substring'ing internalvars */ | |
614 | case TYPE_CODE_STRING: | |
615 | tmp_pos = pc; | |
616 | exp->elts[tmp_pos].opcode = OP_F77_SUBSTR; | |
617 | exp->elts[tmp_pos+2].opcode = OP_F77_SUBSTR; | |
618 | break; | |
619 | ||
620 | case TYPE_CODE_PTR: | |
621 | case TYPE_CODE_FUNC: | |
622 | /* This is just a regular OP_FUNCALL, transform it | |
623 | and recursively evaluate */ | |
624 | tmp_pos = pc; /* Point to OP_FUNCALL_OR_SUBSCRIPT */ | |
625 | exp->elts[tmp_pos].opcode = OP_FUNCALL; | |
626 | exp->elts[tmp_pos+2].opcode = OP_FUNCALL; | |
627 | break; | |
628 | ||
629 | default: | |
630 | error ("Cannot perform substring on this type"); | |
631 | } | |
632 | ||
633 | /* Pretend like you never saw this expression */ | |
634 | *pos -= 1; | |
635 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
636 | return arg2; | |
637 | ||
638 | case OP_F77_SUBSTR: | |
639 | /* We have a substring operation on our hands here, | |
640 | let us get the string we will be dealing with */ | |
641 | ||
642 | (*pos) += 2; | |
643 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
644 | ||
645 | /* Now evaluate the 'from' and 'to' */ | |
646 | ||
647 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
648 | ||
649 | if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT) | |
650 | error ("Substring arguments must be of type integer"); | |
651 | ||
652 | arg3 = evaluate_subexp_with_coercion (exp, pos, noside); | |
653 | ||
654 | if (TYPE_CODE (VALUE_TYPE (arg3)) != TYPE_CODE_INT) | |
655 | error ("Substring arguments must be of type integer"); | |
656 | ||
657 | tem2 = *((int *) VALUE_CONTENTS_RAW (arg2)); | |
658 | tem3 = *((int *) VALUE_CONTENTS_RAW (arg3)); | |
659 | ||
660 | if ((tem2 < 1) || (tem2 > tem3)) | |
661 | error ("Bad 'from' value %d on substring operation", tem2); | |
662 | ||
663 | if ((tem3 < tem2) || (tem3 > (TYPE_LENGTH (VALUE_TYPE (arg1))))) | |
664 | error ("Bad 'to' value %d on substring operation", tem3); | |
665 | ||
666 | if (noside == EVAL_SKIP) | |
667 | goto nosideret; | |
668 | ||
669 | return f77_value_substring (arg1, tem2, tem3); | |
670 | ||
671 | case OP_F77_LITERAL_COMPLEX: | |
672 | /* We have a complex number, There should be 2 floating | |
673 | point numbers that compose it */ | |
674 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
675 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
676 | ||
677 | /* Complex*16 is the default size to create */ | |
678 | return f77_value_literal_complex (arg1, arg2, 16); | |
679 | ||
bd5635a1 | 680 | case STRUCTOP_STRUCT: |
a8a69e63 | 681 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
1500864f | 682 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
bd5635a1 RP |
683 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
684 | if (noside == EVAL_SKIP) | |
685 | goto nosideret; | |
686 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
687 | return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1), | |
a8a69e63 | 688 | &exp->elts[pc + 2].string, |
35fcebce | 689 | 0), |
bd5635a1 RP |
690 | lval_memory); |
691 | else | |
692 | { | |
2d67c7e9 PB |
693 | value_ptr temp = arg1; |
694 | return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string, | |
695 | NULL, "structure"); | |
bd5635a1 RP |
696 | } |
697 | ||
698 | case STRUCTOP_PTR: | |
a8a69e63 | 699 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
1500864f | 700 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); |
bd5635a1 RP |
701 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
702 | if (noside == EVAL_SKIP) | |
703 | goto nosideret; | |
704 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
1500864f | 705 | return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1), |
a8a69e63 | 706 | &exp->elts[pc + 2].string, |
35fcebce | 707 | 0), |
bd5635a1 RP |
708 | lval_memory); |
709 | else | |
710 | { | |
2d67c7e9 PB |
711 | value_ptr temp = arg1; |
712 | return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string, | |
713 | NULL, "structure pointer"); | |
bd5635a1 RP |
714 | } |
715 | ||
716 | case STRUCTOP_MEMBER: | |
717 | arg1 = evaluate_subexp_for_address (exp, pos, noside); | |
01be6913 | 718 | goto handle_pointer_to_member; |
bd5635a1 RP |
719 | case STRUCTOP_MPTR: |
720 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
01be6913 | 721 | handle_pointer_to_member: |
bd5635a1 RP |
722 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
723 | if (noside == EVAL_SKIP) | |
724 | goto nosideret; | |
01be6913 PB |
725 | if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_PTR) |
726 | goto bad_pointer_to_member; | |
727 | type = TYPE_TARGET_TYPE (VALUE_TYPE (arg2)); | |
728 | if (TYPE_CODE (type) == TYPE_CODE_METHOD) | |
729 | error ("not implemented: pointer-to-method in pointer-to-member construct"); | |
730 | if (TYPE_CODE (type) != TYPE_CODE_MEMBER) | |
731 | goto bad_pointer_to_member; | |
bd5635a1 | 732 | /* Now, convert these values to an address. */ |
01be6913 PB |
733 | arg1 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)), |
734 | arg1); | |
735 | arg3 = value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type)), | |
736 | value_as_long (arg1) + value_as_long (arg2)); | |
bd5635a1 | 737 | return value_ind (arg3); |
01be6913 PB |
738 | bad_pointer_to_member: |
739 | error("non-pointer-to-member value used in pointer-to-member construct"); | |
bd5635a1 | 740 | |
1500864f JK |
741 | case BINOP_CONCAT: |
742 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
743 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
744 | if (noside == EVAL_SKIP) | |
745 | goto nosideret; | |
746 | if (binop_user_defined_p (op, arg1, arg2)) | |
747 | return value_x_binop (arg1, arg2, op, OP_NULL); | |
748 | else | |
749 | return value_concat (arg1, arg2); | |
750 | ||
bd5635a1 RP |
751 | case BINOP_ASSIGN: |
752 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
753 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
754 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
755 | return arg1; | |
756 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 757 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
758 | else |
759 | return value_assign (arg1, arg2); | |
760 | ||
761 | case BINOP_ASSIGN_MODIFY: | |
762 | (*pos) += 2; | |
763 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
764 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
765 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
766 | return arg1; | |
767 | op = exp->elts[pc + 1].opcode; | |
768 | if (binop_user_defined_p (op, arg1, arg2)) | |
769 | return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op); | |
770 | else if (op == BINOP_ADD) | |
771 | arg2 = value_add (arg1, arg2); | |
772 | else if (op == BINOP_SUB) | |
773 | arg2 = value_sub (arg1, arg2); | |
774 | else | |
775 | arg2 = value_binop (arg1, arg2, op); | |
776 | return value_assign (arg1, arg2); | |
777 | ||
778 | case BINOP_ADD: | |
779 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
780 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
781 | if (noside == EVAL_SKIP) | |
782 | goto nosideret; | |
783 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 784 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
785 | else |
786 | return value_add (arg1, arg2); | |
787 | ||
788 | case BINOP_SUB: | |
789 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
790 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
791 | if (noside == EVAL_SKIP) | |
792 | goto nosideret; | |
793 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 794 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
795 | else |
796 | return value_sub (arg1, arg2); | |
797 | ||
798 | case BINOP_MUL: | |
799 | case BINOP_DIV: | |
800 | case BINOP_REM: | |
76a0ffb4 | 801 | case BINOP_MOD: |
bd5635a1 RP |
802 | case BINOP_LSH: |
803 | case BINOP_RSH: | |
e58de8a2 FF |
804 | case BINOP_BITWISE_AND: |
805 | case BINOP_BITWISE_IOR: | |
806 | case BINOP_BITWISE_XOR: | |
bd5635a1 RP |
807 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
808 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
809 | if (noside == EVAL_SKIP) | |
810 | goto nosideret; | |
811 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 812 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
813 | else |
814 | if (noside == EVAL_AVOID_SIDE_EFFECTS | |
76a0ffb4 | 815 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) |
bd5635a1 RP |
816 | return value_zero (VALUE_TYPE (arg1), not_lval); |
817 | else | |
818 | return value_binop (arg1, arg2, op); | |
819 | ||
820 | case BINOP_SUBSCRIPT: | |
821 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
822 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
823 | if (noside == EVAL_SKIP) | |
824 | goto nosideret; | |
825 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
35fcebce PB |
826 | { |
827 | /* If the user attempts to subscript something that has no target | |
828 | type (like a plain int variable for example), then report this | |
829 | as an error. */ | |
830 | ||
831 | type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1)); | |
832 | if (type) | |
833 | return value_zero (type, VALUE_LVAL (arg1)); | |
834 | else | |
835 | error ("cannot subscript something of type `%s'", | |
836 | TYPE_NAME (VALUE_TYPE (arg1))); | |
837 | } | |
bd5635a1 RP |
838 | |
839 | if (binop_user_defined_p (op, arg1, arg2)) | |
2ccb3837 | 840 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
841 | else |
842 | return value_subscript (arg1, arg2); | |
2d67c7e9 PB |
843 | |
844 | case BINOP_IN: | |
845 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
846 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
847 | if (noside == EVAL_SKIP) | |
848 | goto nosideret; | |
849 | return value_in (arg1, arg2); | |
bd5635a1 | 850 | |
54bbbfb4 FF |
851 | case MULTI_SUBSCRIPT: |
852 | (*pos) += 2; | |
853 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
854 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
855 | while (nargs-- > 0) | |
856 | { | |
857 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
858 | /* FIXME: EVAL_SKIP handling may not be correct. */ | |
859 | if (noside == EVAL_SKIP) | |
860 | { | |
861 | if (nargs > 0) | |
862 | { | |
863 | continue; | |
864 | } | |
865 | else | |
866 | { | |
867 | goto nosideret; | |
868 | } | |
869 | } | |
870 | /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */ | |
871 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
872 | { | |
873 | /* If the user attempts to subscript something that has no target | |
874 | type (like a plain int variable for example), then report this | |
875 | as an error. */ | |
876 | ||
877 | type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1)); | |
878 | if (type != NULL) | |
879 | { | |
880 | arg1 = value_zero (type, VALUE_LVAL (arg1)); | |
881 | noside = EVAL_SKIP; | |
882 | continue; | |
883 | } | |
884 | else | |
885 | { | |
886 | error ("cannot subscript something of type `%s'", | |
887 | TYPE_NAME (VALUE_TYPE (arg1))); | |
888 | } | |
889 | } | |
890 | ||
891 | if (binop_user_defined_p (op, arg1, arg2)) | |
892 | { | |
893 | arg1 = value_x_binop (arg1, arg2, op, OP_NULL); | |
894 | } | |
895 | else | |
896 | { | |
897 | arg1 = value_subscript (arg1, arg2); | |
898 | } | |
899 | } | |
900 | return (arg1); | |
901 | ||
2d67c7e9 PB |
902 | case MULTI_F77_SUBSCRIPT: |
903 | { | |
904 | int subscript_array[MAX_FORTRAN_DIMS+1]; /* 1-based array of | |
905 | subscripts, max == 7 */ | |
906 | int array_size_array[MAX_FORTRAN_DIMS+1]; | |
907 | int ndimensions=1,i; | |
908 | struct type *tmp_type; | |
909 | int offset_item; /* The array offset where the item lives */ | |
910 | int fixed_subscript; | |
911 | ||
912 | (*pos) += 2; | |
913 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
914 | ||
915 | if (nargs > MAX_FORTRAN_DIMS) | |
916 | error ("Too many subscripts for F77 (%d Max)", MAX_FORTRAN_DIMS); | |
917 | ||
918 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
919 | ||
920 | ndimensions = calc_f77_array_dims (VALUE_TYPE (arg1)); | |
921 | ||
922 | if (nargs != ndimensions) | |
923 | error ("Wrong number of subscripts"); | |
924 | ||
925 | /* Now that we know we have a legal array subscript expression | |
926 | let us actually find out where this element exists in the array. */ | |
927 | ||
928 | tmp_type = VALUE_TYPE (arg1); | |
929 | offset_item = 0; | |
930 | for (i = 1; i <= nargs; i++) | |
931 | { | |
932 | /* Evaluate each subscript, It must be a legal integer in F77 */ | |
933 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
934 | ||
935 | if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT) | |
936 | error ("Array subscripts must be of type integer"); | |
937 | ||
938 | /* Fill in the subscript and array size arrays */ | |
939 | ||
940 | subscript_array[i] = (* (unsigned int *) VALUE_CONTENTS(arg2)); | |
941 | ||
942 | retcode = f77_get_dynamic_upperbound (tmp_type, &upper); | |
943 | if (retcode == BOUND_FETCH_ERROR) | |
944 | error ("Cannot obtain dynamic upper bound"); | |
945 | ||
946 | retcode = f77_get_dynamic_lowerbound (tmp_type, &lower); | |
947 | if (retcode == BOUND_FETCH_ERROR) | |
948 | error("Cannot obtain dynamic lower bound"); | |
949 | ||
950 | array_size_array[i] = upper - lower + 1; | |
951 | ||
952 | /* Zero-normalize subscripts so that offsetting will work. */ | |
953 | ||
954 | subscript_array[i] -= lower; | |
955 | ||
956 | /* If we are at the bottom of a multidimensional | |
957 | array type then keep a ptr to the last ARRAY | |
958 | type around for use when calling value_subscript() | |
959 | below. This is done because we pretend to value_subscript | |
960 | that we actually have a one-dimensional array | |
961 | of base element type that we apply a simple | |
962 | offset to. */ | |
963 | ||
964 | if (i < nargs) | |
965 | tmp_type = TYPE_TARGET_TYPE (tmp_type); | |
966 | } | |
967 | ||
968 | /* Now let us calculate the offset for this item */ | |
969 | ||
970 | offset_item = subscript_array[ndimensions]; | |
971 | ||
972 | for (i = ndimensions - 1; i >= 1; i--) | |
973 | offset_item = | |
974 | array_size_array[i] * offset_item + subscript_array[i]; | |
975 | ||
976 | /* Construct a value node with the value of the offset */ | |
977 | ||
978 | arg2 = value_from_longest (builtin_type_f_integer, offset_item); | |
979 | ||
980 | /* Let us now play a dirty trick: we will take arg1 | |
981 | which is a value node pointing to the topmost level | |
982 | of the multidimensional array-set and pretend | |
983 | that it is actually a array of the final element | |
984 | type, this will ensure that value_subscript() | |
985 | returns the correct type value */ | |
986 | ||
987 | VALUE_TYPE (arg1) = tmp_type; | |
988 | ||
989 | arg1 = value_subscript (arg1, arg2); | |
990 | return arg1; | |
991 | } | |
992 | ||
e58de8a2 | 993 | case BINOP_LOGICAL_AND: |
bd5635a1 RP |
994 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
995 | if (noside == EVAL_SKIP) | |
996 | { | |
997 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
998 | goto nosideret; | |
999 | } | |
1000 | ||
1001 | oldpos = *pos; | |
1002 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
1003 | *pos = oldpos; | |
1004 | ||
1005 | if (binop_user_defined_p (op, arg1, arg2)) | |
1006 | { | |
1007 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
2ccb3837 | 1008 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1009 | } |
1010 | else | |
1011 | { | |
e58de8a2 | 1012 | tem = value_logical_not (arg1); |
bd5635a1 RP |
1013 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, |
1014 | (tem ? EVAL_SKIP : noside)); | |
2ccb3837 | 1015 | return value_from_longest (builtin_type_int, |
e58de8a2 | 1016 | (LONGEST) (!tem && !value_logical_not (arg2))); |
bd5635a1 RP |
1017 | } |
1018 | ||
e58de8a2 | 1019 | case BINOP_LOGICAL_OR: |
bd5635a1 RP |
1020 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
1021 | if (noside == EVAL_SKIP) | |
1022 | { | |
1023 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1024 | goto nosideret; | |
1025 | } | |
1026 | ||
1027 | oldpos = *pos; | |
1028 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
1029 | *pos = oldpos; | |
1030 | ||
1031 | if (binop_user_defined_p (op, arg1, arg2)) | |
1032 | { | |
1033 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
2ccb3837 | 1034 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1035 | } |
1036 | else | |
1037 | { | |
e58de8a2 | 1038 | tem = value_logical_not (arg1); |
bd5635a1 RP |
1039 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, |
1040 | (!tem ? EVAL_SKIP : noside)); | |
2ccb3837 | 1041 | return value_from_longest (builtin_type_int, |
e58de8a2 | 1042 | (LONGEST) (!tem || !value_logical_not (arg2))); |
bd5635a1 RP |
1043 | } |
1044 | ||
1045 | case BINOP_EQUAL: | |
1046 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1047 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1048 | if (noside == EVAL_SKIP) | |
1049 | goto nosideret; | |
1050 | if (binop_user_defined_p (op, arg1, arg2)) | |
1051 | { | |
2ccb3837 | 1052 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1053 | } |
1054 | else | |
1055 | { | |
1056 | tem = value_equal (arg1, arg2); | |
2ccb3837 | 1057 | return value_from_longest (builtin_type_int, (LONGEST) tem); |
bd5635a1 RP |
1058 | } |
1059 | ||
1060 | case BINOP_NOTEQUAL: | |
1061 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1062 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1063 | if (noside == EVAL_SKIP) | |
1064 | goto nosideret; | |
1065 | if (binop_user_defined_p (op, arg1, arg2)) | |
1066 | { | |
2ccb3837 | 1067 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1068 | } |
1069 | else | |
1070 | { | |
1071 | tem = value_equal (arg1, arg2); | |
2ccb3837 | 1072 | return value_from_longest (builtin_type_int, (LONGEST) ! tem); |
bd5635a1 RP |
1073 | } |
1074 | ||
1075 | case BINOP_LESS: | |
1076 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1077 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1078 | if (noside == EVAL_SKIP) | |
1079 | goto nosideret; | |
1080 | if (binop_user_defined_p (op, arg1, arg2)) | |
1081 | { | |
2ccb3837 | 1082 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1083 | } |
1084 | else | |
1085 | { | |
1086 | tem = value_less (arg1, arg2); | |
2ccb3837 | 1087 | return value_from_longest (builtin_type_int, (LONGEST) tem); |
bd5635a1 RP |
1088 | } |
1089 | ||
1090 | case BINOP_GTR: | |
1091 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1092 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1093 | if (noside == EVAL_SKIP) | |
1094 | goto nosideret; | |
1095 | if (binop_user_defined_p (op, arg1, arg2)) | |
1096 | { | |
2ccb3837 | 1097 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1098 | } |
1099 | else | |
1100 | { | |
1101 | tem = value_less (arg2, arg1); | |
2ccb3837 | 1102 | return value_from_longest (builtin_type_int, (LONGEST) tem); |
bd5635a1 RP |
1103 | } |
1104 | ||
1105 | case BINOP_GEQ: | |
1106 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1107 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1108 | if (noside == EVAL_SKIP) | |
1109 | goto nosideret; | |
1110 | if (binop_user_defined_p (op, arg1, arg2)) | |
1111 | { | |
2ccb3837 | 1112 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1113 | } |
1114 | else | |
1115 | { | |
8f86a4e4 JG |
1116 | tem = value_less (arg2, arg1) || value_equal (arg1, arg2); |
1117 | return value_from_longest (builtin_type_int, (LONGEST) tem); | |
bd5635a1 RP |
1118 | } |
1119 | ||
1120 | case BINOP_LEQ: | |
1121 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1122 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
1123 | if (noside == EVAL_SKIP) | |
1124 | goto nosideret; | |
1125 | if (binop_user_defined_p (op, arg1, arg2)) | |
1126 | { | |
2ccb3837 | 1127 | return value_x_binop (arg1, arg2, op, OP_NULL); |
bd5635a1 RP |
1128 | } |
1129 | else | |
1130 | { | |
8f86a4e4 JG |
1131 | tem = value_less (arg1, arg2) || value_equal (arg1, arg2); |
1132 | return value_from_longest (builtin_type_int, (LONGEST) tem); | |
bd5635a1 RP |
1133 | } |
1134 | ||
1135 | case BINOP_REPEAT: | |
1136 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1137 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1138 | if (noside == EVAL_SKIP) | |
1139 | goto nosideret; | |
1140 | if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT) | |
1141 | error ("Non-integral right operand for \"@\" operator."); | |
1142 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
1143 | return allocate_repeat_value (VALUE_TYPE (arg1), | |
2ccb3837 | 1144 | longest_to_int (value_as_long (arg2))); |
bd5635a1 | 1145 | else |
2ccb3837 | 1146 | return value_repeat (arg1, longest_to_int (value_as_long (arg2))); |
bd5635a1 RP |
1147 | |
1148 | case BINOP_COMMA: | |
1149 | evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1150 | return evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1151 | ||
1152 | case UNOP_NEG: | |
1153 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1154 | if (noside == EVAL_SKIP) | |
1155 | goto nosideret; | |
1156 | if (unop_user_defined_p (op, arg1)) | |
1157 | return value_x_unop (arg1, op); | |
1158 | else | |
1159 | return value_neg (arg1); | |
1160 | ||
e58de8a2 | 1161 | case UNOP_COMPLEMENT: |
5f00ca54 JK |
1162 | /* C++: check for and handle destructor names. */ |
1163 | op = exp->elts[*pos].opcode; | |
1164 | ||
bd5635a1 RP |
1165 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
1166 | if (noside == EVAL_SKIP) | |
1167 | goto nosideret; | |
e58de8a2 FF |
1168 | if (unop_user_defined_p (UNOP_COMPLEMENT, arg1)) |
1169 | return value_x_unop (arg1, UNOP_COMPLEMENT); | |
bd5635a1 | 1170 | else |
e58de8a2 | 1171 | return value_complement (arg1); |
bd5635a1 | 1172 | |
e58de8a2 | 1173 | case UNOP_LOGICAL_NOT: |
bd5635a1 RP |
1174 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
1175 | if (noside == EVAL_SKIP) | |
1176 | goto nosideret; | |
1177 | if (unop_user_defined_p (op, arg1)) | |
1178 | return value_x_unop (arg1, op); | |
1179 | else | |
2ccb3837 | 1180 | return value_from_longest (builtin_type_int, |
e58de8a2 | 1181 | (LONGEST) value_logical_not (arg1)); |
bd5635a1 RP |
1182 | |
1183 | case UNOP_IND: | |
1184 | if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR) | |
1185 | expect_type = TYPE_TARGET_TYPE (expect_type); | |
1186 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1187 | if (noside == EVAL_SKIP) | |
1188 | goto nosideret; | |
1189 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
1190 | { | |
1191 | if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR | |
1192 | || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF | |
1193 | /* In C you can dereference an array to get the 1st elt. */ | |
1194 | || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY | |
1195 | ) | |
1196 | return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)), | |
1197 | lval_memory); | |
1198 | else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT) | |
1199 | /* GDB allows dereferencing an int. */ | |
1200 | return value_zero (builtin_type_int, lval_memory); | |
1201 | else | |
1202 | error ("Attempt to take contents of a non-pointer value."); | |
1203 | } | |
1204 | return value_ind (arg1); | |
1205 | ||
1206 | case UNOP_ADDR: | |
1207 | /* C++: check for and handle pointer to members. */ | |
1208 | ||
1209 | op = exp->elts[*pos].opcode; | |
1210 | ||
1211 | if (noside == EVAL_SKIP) | |
1212 | { | |
1213 | if (op == OP_SCOPE) | |
1214 | { | |
a8a69e63 | 1215 | int temm = longest_to_int (exp->elts[pc+3].longconst); |
1500864f | 1216 | (*pos) += 3 + BYTES_TO_EXP_ELEM (temm + 1); |
bd5635a1 RP |
1217 | } |
1218 | else | |
1219 | evaluate_subexp (expect_type, exp, pos, EVAL_SKIP); | |
1220 | goto nosideret; | |
1221 | } | |
1222 | ||
01be6913 | 1223 | return evaluate_subexp_for_address (exp, pos, noside); |
bd5635a1 RP |
1224 | |
1225 | case UNOP_SIZEOF: | |
1226 | if (noside == EVAL_SKIP) | |
1227 | { | |
1228 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
1229 | goto nosideret; | |
1230 | } | |
1231 | return evaluate_subexp_for_sizeof (exp, pos); | |
1232 | ||
1233 | case UNOP_CAST: | |
1234 | (*pos) += 2; | |
2d67c7e9 PB |
1235 | type = exp->elts[pc + 1].type; |
1236 | arg1 = evaluate_subexp (type, exp, pos, noside); | |
bd5635a1 RP |
1237 | if (noside == EVAL_SKIP) |
1238 | goto nosideret; | |
2d67c7e9 PB |
1239 | if (type != VALUE_TYPE (arg1)) |
1240 | arg1 = value_cast (type, arg1); | |
1241 | return arg1; | |
bd5635a1 RP |
1242 | |
1243 | case UNOP_MEMVAL: | |
1244 | (*pos) += 2; | |
1245 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1246 | if (noside == EVAL_SKIP) | |
1247 | goto nosideret; | |
1248 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
1249 | return value_zero (exp->elts[pc + 1].type, lval_memory); | |
1250 | else | |
1251 | return value_at_lazy (exp->elts[pc + 1].type, | |
2ccb3837 | 1252 | value_as_pointer (arg1)); |
bd5635a1 RP |
1253 | |
1254 | case UNOP_PREINCREMENT: | |
1255 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1256 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
1257 | return arg1; | |
1258 | else if (unop_user_defined_p (op, arg1)) | |
1259 | { | |
1260 | return value_x_unop (arg1, op); | |
1261 | } | |
1262 | else | |
1263 | { | |
2ccb3837 | 1264 | arg2 = value_add (arg1, value_from_longest (builtin_type_char, |
bd5635a1 RP |
1265 | (LONGEST) 1)); |
1266 | return value_assign (arg1, arg2); | |
1267 | } | |
1268 | ||
1269 | case UNOP_PREDECREMENT: | |
1270 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1271 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
1272 | return arg1; | |
1273 | else if (unop_user_defined_p (op, arg1)) | |
1274 | { | |
1275 | return value_x_unop (arg1, op); | |
1276 | } | |
1277 | else | |
1278 | { | |
2ccb3837 | 1279 | arg2 = value_sub (arg1, value_from_longest (builtin_type_char, |
bd5635a1 RP |
1280 | (LONGEST) 1)); |
1281 | return value_assign (arg1, arg2); | |
1282 | } | |
1283 | ||
1284 | case UNOP_POSTINCREMENT: | |
1285 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1286 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
1287 | return arg1; | |
1288 | else if (unop_user_defined_p (op, arg1)) | |
1289 | { | |
1290 | return value_x_unop (arg1, op); | |
1291 | } | |
1292 | else | |
1293 | { | |
2ccb3837 | 1294 | arg2 = value_add (arg1, value_from_longest (builtin_type_char, |
bd5635a1 RP |
1295 | (LONGEST) 1)); |
1296 | value_assign (arg1, arg2); | |
1297 | return arg1; | |
1298 | } | |
1299 | ||
1300 | case UNOP_POSTDECREMENT: | |
1301 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); | |
1302 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
1303 | return arg1; | |
1304 | else if (unop_user_defined_p (op, arg1)) | |
1305 | { | |
1306 | return value_x_unop (arg1, op); | |
1307 | } | |
1308 | else | |
1309 | { | |
2ccb3837 | 1310 | arg2 = value_sub (arg1, value_from_longest (builtin_type_char, |
bd5635a1 RP |
1311 | (LONGEST) 1)); |
1312 | value_assign (arg1, arg2); | |
1313 | return arg1; | |
1314 | } | |
1315 | ||
1316 | case OP_THIS: | |
1317 | (*pos) += 1; | |
1318 | return value_of_this (1); | |
1319 | ||
1500864f JK |
1320 | case OP_TYPE: |
1321 | error ("Attempt to use a type name as an expression"); | |
1322 | ||
bd5635a1 | 1323 | default: |
1500864f JK |
1324 | /* Removing this case and compiling with gcc -Wall reveals that |
1325 | a lot of cases are hitting this case. Some of these should | |
1326 | probably be removed from expression.h (e.g. do we need a BINOP_SCOPE | |
1327 | and an OP_SCOPE?); others are legitimate expressions which are | |
1328 | (apparently) not fully implemented. | |
1329 | ||
1330 | If there are any cases landing here which mean a user error, | |
1331 | then they should be separate cases, with more descriptive | |
1332 | error messages. */ | |
1333 | ||
1334 | error ("\ | |
2d67c7e9 | 1335 | GDB does not (yet) know how to evaluate that kind of expression"); |
bd5635a1 RP |
1336 | } |
1337 | ||
1338 | nosideret: | |
2ccb3837 | 1339 | return value_from_longest (builtin_type_long, (LONGEST) 1); |
bd5635a1 RP |
1340 | } |
1341 | \f | |
1342 | /* Evaluate a subexpression of EXP, at index *POS, | |
1343 | and return the address of that subexpression. | |
1344 | Advance *POS over the subexpression. | |
1345 | If the subexpression isn't an lvalue, get an error. | |
1346 | NOSIDE may be EVAL_AVOID_SIDE_EFFECTS; | |
1347 | then only the type of the result need be correct. */ | |
1348 | ||
2d67c7e9 | 1349 | static value_ptr |
bd5635a1 RP |
1350 | evaluate_subexp_for_address (exp, pos, noside) |
1351 | register struct expression *exp; | |
1352 | register int *pos; | |
1353 | enum noside noside; | |
1354 | { | |
1355 | enum exp_opcode op; | |
1356 | register int pc; | |
e17960fb | 1357 | struct symbol *var; |
bd5635a1 RP |
1358 | |
1359 | pc = (*pos); | |
1360 | op = exp->elts[pc].opcode; | |
1361 | ||
1362 | switch (op) | |
1363 | { | |
1364 | case UNOP_IND: | |
1365 | (*pos)++; | |
1366 | return evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
1367 | ||
1368 | case UNOP_MEMVAL: | |
1369 | (*pos) += 3; | |
1370 | return value_cast (lookup_pointer_type (exp->elts[pc + 1].type), | |
1371 | evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
1372 | ||
1373 | case OP_VAR_VALUE: | |
479fdd26 | 1374 | var = exp->elts[pc + 2].symbol; |
e17960fb JG |
1375 | |
1376 | /* C++: The "address" of a reference should yield the address | |
1377 | * of the object pointed to. Let value_addr() deal with it. */ | |
1378 | if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF) | |
1379 | goto default_case; | |
1380 | ||
479fdd26 | 1381 | (*pos) += 4; |
bd5635a1 RP |
1382 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
1383 | { | |
1384 | struct type *type = | |
e17960fb JG |
1385 | lookup_pointer_type (SYMBOL_TYPE (var)); |
1386 | enum address_class sym_class = SYMBOL_CLASS (var); | |
bd5635a1 RP |
1387 | |
1388 | if (sym_class == LOC_CONST | |
1389 | || sym_class == LOC_CONST_BYTES | |
1390 | || sym_class == LOC_REGISTER | |
1391 | || sym_class == LOC_REGPARM) | |
1392 | error ("Attempt to take address of register or constant."); | |
1393 | ||
1394 | return | |
1395 | value_zero (type, not_lval); | |
1396 | } | |
1397 | else | |
479fdd26 JK |
1398 | return |
1399 | locate_var_value | |
1400 | (var, | |
1401 | block_innermost_frame (exp->elts[pc + 1].block)); | |
bd5635a1 RP |
1402 | |
1403 | default: | |
e17960fb | 1404 | default_case: |
bd5635a1 RP |
1405 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
1406 | { | |
2d67c7e9 | 1407 | value_ptr x = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
bd5635a1 | 1408 | if (VALUE_LVAL (x) == lval_memory) |
0a5d35ed | 1409 | return value_zero (lookup_pointer_type (VALUE_TYPE (x)), |
bd5635a1 RP |
1410 | not_lval); |
1411 | else | |
1412 | error ("Attempt to take address of non-lval"); | |
1413 | } | |
1414 | return value_addr (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
1415 | } | |
1416 | } | |
1417 | ||
1418 | /* Evaluate like `evaluate_subexp' except coercing arrays to pointers. | |
fb6e675f FF |
1419 | When used in contexts where arrays will be coerced anyway, this is |
1420 | equivalent to `evaluate_subexp' but much faster because it avoids | |
479fdd26 JK |
1421 | actually fetching array contents (perhaps obsolete now that we have |
1422 | VALUE_LAZY). | |
fb6e675f FF |
1423 | |
1424 | Note that we currently only do the coercion for C expressions, where | |
1425 | arrays are zero based and the coercion is correct. For other languages, | |
1426 | with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION | |
1427 | to decide if coercion is appropriate. | |
1428 | ||
479fdd26 | 1429 | */ |
bd5635a1 | 1430 | |
2d67c7e9 | 1431 | static value_ptr |
bd5635a1 RP |
1432 | evaluate_subexp_with_coercion (exp, pos, noside) |
1433 | register struct expression *exp; | |
1434 | register int *pos; | |
1435 | enum noside noside; | |
1436 | { | |
1437 | register enum exp_opcode op; | |
1438 | register int pc; | |
2d67c7e9 | 1439 | register value_ptr val; |
e17960fb | 1440 | struct symbol *var; |
bd5635a1 RP |
1441 | |
1442 | pc = (*pos); | |
1443 | op = exp->elts[pc].opcode; | |
1444 | ||
1445 | switch (op) | |
1446 | { | |
1447 | case OP_VAR_VALUE: | |
479fdd26 | 1448 | var = exp->elts[pc + 2].symbol; |
fb6e675f FF |
1449 | if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_ARRAY |
1450 | && CAST_IS_CONVERSION) | |
bd5635a1 | 1451 | { |
479fdd26 JK |
1452 | (*pos) += 4; |
1453 | val = | |
1454 | locate_var_value | |
1455 | (var, block_innermost_frame (exp->elts[pc + 1].block)); | |
e17960fb | 1456 | return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var))), |
bd5635a1 RP |
1457 | val); |
1458 | } | |
479fdd26 JK |
1459 | /* FALLTHROUGH */ |
1460 | ||
1461 | default: | |
1462 | return evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
bd5635a1 RP |
1463 | } |
1464 | } | |
1465 | ||
1466 | /* Evaluate a subexpression of EXP, at index *POS, | |
1467 | and return a value for the size of that subexpression. | |
1468 | Advance *POS over the subexpression. */ | |
1469 | ||
2d67c7e9 | 1470 | static value_ptr |
bd5635a1 RP |
1471 | evaluate_subexp_for_sizeof (exp, pos) |
1472 | register struct expression *exp; | |
1473 | register int *pos; | |
1474 | { | |
1475 | enum exp_opcode op; | |
1476 | register int pc; | |
2d67c7e9 | 1477 | value_ptr val; |
bd5635a1 RP |
1478 | |
1479 | pc = (*pos); | |
1480 | op = exp->elts[pc].opcode; | |
1481 | ||
1482 | switch (op) | |
1483 | { | |
1484 | /* This case is handled specially | |
1485 | so that we avoid creating a value for the result type. | |
1486 | If the result type is very big, it's desirable not to | |
1487 | create a value unnecessarily. */ | |
1488 | case UNOP_IND: | |
1489 | (*pos)++; | |
1490 | val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
2ccb3837 | 1491 | return value_from_longest (builtin_type_int, (LONGEST) |
bd5635a1 RP |
1492 | TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val)))); |
1493 | ||
1494 | case UNOP_MEMVAL: | |
1495 | (*pos) += 3; | |
2ccb3837 | 1496 | return value_from_longest (builtin_type_int, |
bd5635a1 RP |
1497 | (LONGEST) TYPE_LENGTH (exp->elts[pc + 1].type)); |
1498 | ||
1499 | case OP_VAR_VALUE: | |
479fdd26 JK |
1500 | (*pos) += 4; |
1501 | return | |
1502 | value_from_longest | |
1503 | (builtin_type_int, | |
1504 | (LONGEST) TYPE_LENGTH (SYMBOL_TYPE (exp->elts[pc + 2].symbol))); | |
bd5635a1 RP |
1505 | |
1506 | default: | |
1507 | val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); | |
2ccb3837 | 1508 | return value_from_longest (builtin_type_int, |
bd5635a1 RP |
1509 | (LONGEST) TYPE_LENGTH (VALUE_TYPE (val))); |
1510 | } | |
1511 | } | |
0a5d35ed SG |
1512 | |
1513 | /* Parse a type expression in the string [P..P+LENGTH). */ | |
1514 | ||
1515 | struct type * | |
1516 | parse_and_eval_type (p, length) | |
1517 | char *p; | |
1518 | int length; | |
1519 | { | |
1520 | char *tmp = (char *)alloca (length + 4); | |
1521 | struct expression *expr; | |
1522 | tmp[0] = '('; | |
35fcebce | 1523 | memcpy (tmp+1, p, length); |
0a5d35ed SG |
1524 | tmp[length+1] = ')'; |
1525 | tmp[length+2] = '0'; | |
1526 | tmp[length+3] = '\0'; | |
1527 | expr = parse_expression (tmp); | |
1528 | if (expr->elts[0].opcode != UNOP_CAST) | |
1529 | error ("Internal error in eval_type."); | |
1530 | return expr->elts[1].type; | |
1531 | } | |
2d67c7e9 PB |
1532 | |
1533 | int | |
1534 | calc_f77_array_dims (array_type) | |
1535 | struct type *array_type; | |
1536 | { | |
1537 | int ndimen = 1; | |
1538 | struct type *tmp_type; | |
1539 | ||
1540 | if ((TYPE_CODE(array_type) != TYPE_CODE_ARRAY)) | |
1541 | error ("Can't get dimensions for a non-array type"); | |
1542 | ||
1543 | tmp_type = array_type; | |
1544 | ||
1545 | while (tmp_type = TYPE_TARGET_TYPE (tmp_type)) | |
1546 | { | |
1547 | if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY) | |
1548 | ++ndimen; | |
1549 | } | |
1550 | return ndimen; | |
1551 | } |