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