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