| 1 | /* Support routines for manipulating internal types for GDB. |
| 2 | Copyright (C) 1992, 93, 94, 95, 96, 1998 Free Software Foundation, Inc. |
| 3 | Contributed by Cygnus Support, using pieces from other GDB modules. |
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "gdb_string.h" |
| 23 | #include "bfd.h" |
| 24 | #include "symtab.h" |
| 25 | #include "symfile.h" |
| 26 | #include "objfiles.h" |
| 27 | #include "gdbtypes.h" |
| 28 | #include "expression.h" |
| 29 | #include "language.h" |
| 30 | #include "target.h" |
| 31 | #include "value.h" |
| 32 | #include "demangle.h" |
| 33 | #include "complaints.h" |
| 34 | #include "gdbcmd.h" |
| 35 | |
| 36 | /* These variables point to the objects |
| 37 | representing the predefined C data types. */ |
| 38 | |
| 39 | struct type *builtin_type_void; |
| 40 | struct type *builtin_type_char; |
| 41 | struct type *builtin_type_short; |
| 42 | struct type *builtin_type_int; |
| 43 | struct type *builtin_type_long; |
| 44 | struct type *builtin_type_long_long; |
| 45 | struct type *builtin_type_signed_char; |
| 46 | struct type *builtin_type_unsigned_char; |
| 47 | struct type *builtin_type_unsigned_short; |
| 48 | struct type *builtin_type_unsigned_int; |
| 49 | struct type *builtin_type_unsigned_long; |
| 50 | struct type *builtin_type_unsigned_long_long; |
| 51 | struct type *builtin_type_float; |
| 52 | struct type *builtin_type_double; |
| 53 | struct type *builtin_type_long_double; |
| 54 | struct type *builtin_type_complex; |
| 55 | struct type *builtin_type_double_complex; |
| 56 | struct type *builtin_type_string; |
| 57 | struct type *builtin_type_int8; |
| 58 | struct type *builtin_type_uint8; |
| 59 | struct type *builtin_type_int16; |
| 60 | struct type *builtin_type_uint16; |
| 61 | struct type *builtin_type_int32; |
| 62 | struct type *builtin_type_uint32; |
| 63 | struct type *builtin_type_int64; |
| 64 | struct type *builtin_type_uint64; |
| 65 | struct type *builtin_type_bool; |
| 66 | /* start-sanitize-r5900 */ |
| 67 | struct type *builtin_type_int128; |
| 68 | struct type *builtin_type_uint128; |
| 69 | /* end-sanitize-r5900 */ |
| 70 | |
| 71 | int opaque_type_resolution = 1; |
| 72 | |
| 73 | |
| 74 | struct extra { char str[128]; int len; }; /* maximum extention is 128! FIXME */ |
| 75 | |
| 76 | static void add_name PARAMS ((struct extra *, char *)); |
| 77 | static void add_mangled_type PARAMS ((struct extra *, struct type *)); |
| 78 | #if 0 |
| 79 | static void cfront_mangle_name PARAMS ((struct type *, int, int)); |
| 80 | #endif |
| 81 | static void print_bit_vector PARAMS ((B_TYPE *, int)); |
| 82 | static void print_arg_types PARAMS ((struct type **, int)); |
| 83 | static void dump_fn_fieldlists PARAMS ((struct type *, int)); |
| 84 | static void print_cplus_stuff PARAMS ((struct type *, int)); |
| 85 | |
| 86 | /* Alloc a new type structure and fill it with some defaults. If |
| 87 | OBJFILE is non-NULL, then allocate the space for the type structure |
| 88 | in that objfile's type_obstack. */ |
| 89 | |
| 90 | struct type * |
| 91 | alloc_type (objfile) |
| 92 | struct objfile *objfile; |
| 93 | { |
| 94 | register struct type *type; |
| 95 | |
| 96 | /* Alloc the structure and start off with all fields zeroed. */ |
| 97 | |
| 98 | if (objfile == NULL) |
| 99 | { |
| 100 | type = (struct type *) xmalloc (sizeof (struct type)); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | type = (struct type *) obstack_alloc (&objfile -> type_obstack, |
| 105 | sizeof (struct type)); |
| 106 | OBJSTAT (objfile, n_types++); |
| 107 | } |
| 108 | memset ((char *) type, 0, sizeof (struct type)); |
| 109 | |
| 110 | /* Initialize the fields that might not be zero. */ |
| 111 | |
| 112 | TYPE_CODE (type) = TYPE_CODE_UNDEF; |
| 113 | TYPE_OBJFILE (type) = objfile; |
| 114 | TYPE_VPTR_FIELDNO (type) = -1; |
| 115 | TYPE_CV_TYPE (type) = type; /* chain back to itself */ |
| 116 | |
| 117 | return (type); |
| 118 | } |
| 119 | |
| 120 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points |
| 121 | to a pointer to memory where the pointer type should be stored. |
| 122 | If *TYPEPTR is zero, update it to point to the pointer type we return. |
| 123 | We allocate new memory if needed. */ |
| 124 | |
| 125 | struct type * |
| 126 | make_pointer_type (type, typeptr) |
| 127 | struct type *type; |
| 128 | struct type **typeptr; |
| 129 | { |
| 130 | register struct type *ntype; /* New type */ |
| 131 | struct objfile *objfile; |
| 132 | |
| 133 | ntype = TYPE_POINTER_TYPE (type); |
| 134 | |
| 135 | if (ntype) |
| 136 | { |
| 137 | if (typeptr == 0) |
| 138 | return ntype; /* Don't care about alloc, and have new type. */ |
| 139 | else if (*typeptr == 0) |
| 140 | { |
| 141 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
| 142 | return ntype; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ |
| 147 | { |
| 148 | ntype = alloc_type (TYPE_OBJFILE (type)); |
| 149 | if (typeptr) |
| 150 | *typeptr = ntype; |
| 151 | } |
| 152 | else /* We have storage, but need to reset it. */ |
| 153 | { |
| 154 | ntype = *typeptr; |
| 155 | objfile = TYPE_OBJFILE (ntype); |
| 156 | memset ((char *) ntype, 0, sizeof (struct type)); |
| 157 | TYPE_OBJFILE (ntype) = objfile; |
| 158 | } |
| 159 | |
| 160 | TYPE_TARGET_TYPE (ntype) = type; |
| 161 | TYPE_POINTER_TYPE (type) = ntype; |
| 162 | |
| 163 | /* FIXME! Assume the machine has only one representation for pointers! */ |
| 164 | |
| 165 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; |
| 166 | TYPE_CODE (ntype) = TYPE_CODE_PTR; |
| 167 | |
| 168 | /* pointers are unsigned */ |
| 169 | TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED; |
| 170 | |
| 171 | if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */ |
| 172 | TYPE_POINTER_TYPE (type) = ntype; |
| 173 | |
| 174 | return ntype; |
| 175 | } |
| 176 | |
| 177 | /* Given a type TYPE, return a type of pointers to that type. |
| 178 | May need to construct such a type if this is the first use. */ |
| 179 | |
| 180 | struct type * |
| 181 | lookup_pointer_type (type) |
| 182 | struct type *type; |
| 183 | { |
| 184 | return make_pointer_type (type, (struct type **)0); |
| 185 | } |
| 186 | |
| 187 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points |
| 188 | to a pointer to memory where the reference type should be stored. |
| 189 | If *TYPEPTR is zero, update it to point to the reference type we return. |
| 190 | We allocate new memory if needed. */ |
| 191 | |
| 192 | struct type * |
| 193 | make_reference_type (type, typeptr) |
| 194 | struct type *type; |
| 195 | struct type **typeptr; |
| 196 | { |
| 197 | register struct type *ntype; /* New type */ |
| 198 | struct objfile *objfile; |
| 199 | |
| 200 | ntype = TYPE_REFERENCE_TYPE (type); |
| 201 | |
| 202 | if (ntype) |
| 203 | { |
| 204 | if (typeptr == 0) |
| 205 | return ntype; /* Don't care about alloc, and have new type. */ |
| 206 | else if (*typeptr == 0) |
| 207 | { |
| 208 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
| 209 | return ntype; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ |
| 214 | { |
| 215 | ntype = alloc_type (TYPE_OBJFILE (type)); |
| 216 | if (typeptr) |
| 217 | *typeptr = ntype; |
| 218 | } |
| 219 | else /* We have storage, but need to reset it. */ |
| 220 | { |
| 221 | ntype = *typeptr; |
| 222 | objfile = TYPE_OBJFILE (ntype); |
| 223 | memset ((char *) ntype, 0, sizeof (struct type)); |
| 224 | TYPE_OBJFILE (ntype) = objfile; |
| 225 | } |
| 226 | |
| 227 | TYPE_TARGET_TYPE (ntype) = type; |
| 228 | TYPE_REFERENCE_TYPE (type) = ntype; |
| 229 | |
| 230 | /* FIXME! Assume the machine has only one representation for references, |
| 231 | and that it matches the (only) representation for pointers! */ |
| 232 | |
| 233 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; |
| 234 | TYPE_CODE (ntype) = TYPE_CODE_REF; |
| 235 | |
| 236 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ |
| 237 | TYPE_REFERENCE_TYPE (type) = ntype; |
| 238 | |
| 239 | return ntype; |
| 240 | } |
| 241 | |
| 242 | /* Same as above, but caller doesn't care about memory allocation details. */ |
| 243 | |
| 244 | struct type * |
| 245 | lookup_reference_type (type) |
| 246 | struct type *type; |
| 247 | { |
| 248 | return make_reference_type (type, (struct type **)0); |
| 249 | } |
| 250 | |
| 251 | /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points |
| 252 | to a pointer to memory where the function type should be stored. |
| 253 | If *TYPEPTR is zero, update it to point to the function type we return. |
| 254 | We allocate new memory if needed. */ |
| 255 | |
| 256 | struct type * |
| 257 | make_function_type (type, typeptr) |
| 258 | struct type *type; |
| 259 | struct type **typeptr; |
| 260 | { |
| 261 | register struct type *ntype; /* New type */ |
| 262 | struct objfile *objfile; |
| 263 | |
| 264 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ |
| 265 | { |
| 266 | ntype = alloc_type (TYPE_OBJFILE (type)); |
| 267 | if (typeptr) |
| 268 | *typeptr = ntype; |
| 269 | } |
| 270 | else /* We have storage, but need to reset it. */ |
| 271 | { |
| 272 | ntype = *typeptr; |
| 273 | objfile = TYPE_OBJFILE (ntype); |
| 274 | memset ((char *) ntype, 0, sizeof (struct type)); |
| 275 | TYPE_OBJFILE (ntype) = objfile; |
| 276 | } |
| 277 | |
| 278 | TYPE_TARGET_TYPE (ntype) = type; |
| 279 | |
| 280 | TYPE_LENGTH (ntype) = 1; |
| 281 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; |
| 282 | |
| 283 | return ntype; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | /* Given a type TYPE, return a type of functions that return that type. |
| 288 | May need to construct such a type if this is the first use. */ |
| 289 | |
| 290 | struct type * |
| 291 | lookup_function_type (type) |
| 292 | struct type *type; |
| 293 | { |
| 294 | return make_function_type (type, (struct type **)0); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | /* Make a "c-v" variant of a type -- a type that is identical to the |
| 299 | one supplied except that it may have const or volatile attributes |
| 300 | CNST is a flag for setting the const attribute |
| 301 | VOLTL is a flag for setting the volatile attribute |
| 302 | TYPE is the base type whose variant we are creating. |
| 303 | TYPEPTR, if nonzero, points |
| 304 | to a pointer to memory where the reference type should be stored. |
| 305 | If *TYPEPTR is zero, update it to point to the reference type we return. |
| 306 | We allocate new memory if needed. */ |
| 307 | |
| 308 | struct type * |
| 309 | make_cv_type (cnst, voltl, type, typeptr) |
| 310 | int cnst; |
| 311 | int voltl; |
| 312 | struct type *type; |
| 313 | struct type **typeptr; |
| 314 | { |
| 315 | register struct type *ntype; /* New type */ |
| 316 | register struct type *tmp_type = type; /* tmp type */ |
| 317 | struct objfile *objfile; |
| 318 | |
| 319 | ntype = TYPE_CV_TYPE (type); |
| 320 | |
| 321 | while (ntype != type) |
| 322 | { |
| 323 | if ((TYPE_CONST (ntype) == cnst) && |
| 324 | (TYPE_VOLATILE (ntype) == voltl)) |
| 325 | { |
| 326 | if (typeptr == 0) |
| 327 | return ntype; |
| 328 | else if (*typeptr == 0) |
| 329 | { |
| 330 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
| 331 | return ntype; |
| 332 | } |
| 333 | } |
| 334 | tmp_type = ntype; |
| 335 | ntype = TYPE_CV_TYPE (ntype); |
| 336 | } |
| 337 | |
| 338 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ |
| 339 | { |
| 340 | ntype = alloc_type (TYPE_OBJFILE (type)); |
| 341 | if (typeptr) |
| 342 | *typeptr = ntype; |
| 343 | } |
| 344 | else /* We have storage, but need to reset it. */ |
| 345 | { |
| 346 | ntype = *typeptr; |
| 347 | objfile = TYPE_OBJFILE (ntype); |
| 348 | /* memset ((char *) ntype, 0, sizeof (struct type)); */ |
| 349 | TYPE_OBJFILE (ntype) = objfile; |
| 350 | } |
| 351 | |
| 352 | /* Copy original type */ |
| 353 | memcpy ((char *) ntype, (char *) type, sizeof (struct type)); |
| 354 | /* But zero out fields that shouldn't be copied */ |
| 355 | TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */ |
| 356 | TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */ |
| 357 | /* Note: TYPE_TARGET_TYPE can be left as is */ |
| 358 | |
| 359 | /* Set flags appropriately */ |
| 360 | if (cnst) |
| 361 | TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST; |
| 362 | else |
| 363 | TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST; |
| 364 | |
| 365 | if (voltl) |
| 366 | TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE; |
| 367 | else |
| 368 | TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE; |
| 369 | |
| 370 | /* Fix the chain of cv variants */ |
| 371 | TYPE_CV_TYPE (ntype) = type; |
| 372 | TYPE_CV_TYPE (tmp_type) = ntype; |
| 373 | |
| 374 | return ntype; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | /* Implement direct support for MEMBER_TYPE in GNU C++. |
| 381 | May need to construct such a type if this is the first use. |
| 382 | The TYPE is the type of the member. The DOMAIN is the type |
| 383 | of the aggregate that the member belongs to. */ |
| 384 | |
| 385 | struct type * |
| 386 | lookup_member_type (type, domain) |
| 387 | struct type *type; |
| 388 | struct type *domain; |
| 389 | { |
| 390 | register struct type *mtype; |
| 391 | |
| 392 | mtype = alloc_type (TYPE_OBJFILE (type)); |
| 393 | smash_to_member_type (mtype, domain, type); |
| 394 | return (mtype); |
| 395 | } |
| 396 | |
| 397 | /* Allocate a stub method whose return type is TYPE. |
| 398 | This apparently happens for speed of symbol reading, since parsing |
| 399 | out the arguments to the method is cpu-intensive, the way we are doing |
| 400 | it. So, we will fill in arguments later. |
| 401 | This always returns a fresh type. */ |
| 402 | |
| 403 | struct type * |
| 404 | allocate_stub_method (type) |
| 405 | struct type *type; |
| 406 | { |
| 407 | struct type *mtype; |
| 408 | |
| 409 | mtype = alloc_type (TYPE_OBJFILE (type)); |
| 410 | TYPE_TARGET_TYPE (mtype) = type; |
| 411 | /* _DOMAIN_TYPE (mtype) = unknown yet */ |
| 412 | /* _ARG_TYPES (mtype) = unknown yet */ |
| 413 | TYPE_FLAGS (mtype) = TYPE_FLAG_STUB; |
| 414 | TYPE_CODE (mtype) = TYPE_CODE_METHOD; |
| 415 | TYPE_LENGTH (mtype) = 1; |
| 416 | return (mtype); |
| 417 | } |
| 418 | |
| 419 | /* Create a range type using either a blank type supplied in RESULT_TYPE, |
| 420 | or creating a new type, inheriting the objfile from INDEX_TYPE. |
| 421 | |
| 422 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to |
| 423 | HIGH_BOUND, inclusive. |
| 424 | |
| 425 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
| 426 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ |
| 427 | |
| 428 | struct type * |
| 429 | create_range_type (result_type, index_type, low_bound, high_bound) |
| 430 | struct type *result_type; |
| 431 | struct type *index_type; |
| 432 | int low_bound; |
| 433 | int high_bound; |
| 434 | { |
| 435 | if (result_type == NULL) |
| 436 | { |
| 437 | result_type = alloc_type (TYPE_OBJFILE (index_type)); |
| 438 | } |
| 439 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; |
| 440 | TYPE_TARGET_TYPE (result_type) = index_type; |
| 441 | if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB) |
| 442 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; |
| 443 | else |
| 444 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); |
| 445 | TYPE_NFIELDS (result_type) = 2; |
| 446 | TYPE_FIELDS (result_type) = (struct field *) |
| 447 | TYPE_ALLOC (result_type, 2 * sizeof (struct field)); |
| 448 | memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field)); |
| 449 | TYPE_FIELD_BITPOS (result_type, 0) = low_bound; |
| 450 | TYPE_FIELD_BITPOS (result_type, 1) = high_bound; |
| 451 | TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */ |
| 452 | TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */ |
| 453 | |
| 454 | if(low_bound >= 0) |
| 455 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
| 456 | |
| 457 | return (result_type); |
| 458 | } |
| 459 | |
| 460 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE. |
| 461 | Return 1 of type is a range type, 0 if it is discrete (and bounds |
| 462 | will fit in LONGEST), or -1 otherwise. */ |
| 463 | |
| 464 | int |
| 465 | get_discrete_bounds (type, lowp, highp) |
| 466 | struct type *type; |
| 467 | LONGEST *lowp, *highp; |
| 468 | { |
| 469 | CHECK_TYPEDEF (type); |
| 470 | switch (TYPE_CODE (type)) |
| 471 | { |
| 472 | case TYPE_CODE_RANGE: |
| 473 | *lowp = TYPE_LOW_BOUND (type); |
| 474 | *highp = TYPE_HIGH_BOUND (type); |
| 475 | return 1; |
| 476 | case TYPE_CODE_ENUM: |
| 477 | if (TYPE_NFIELDS (type) > 0) |
| 478 | { |
| 479 | /* The enums may not be sorted by value, so search all |
| 480 | entries */ |
| 481 | int i; |
| 482 | |
| 483 | *lowp = *highp = TYPE_FIELD_BITPOS (type, 0); |
| 484 | for (i = 0; i < TYPE_NFIELDS (type); i++) |
| 485 | { |
| 486 | if (TYPE_FIELD_BITPOS (type, i) < *lowp) |
| 487 | *lowp = TYPE_FIELD_BITPOS (type, i); |
| 488 | if (TYPE_FIELD_BITPOS (type, i) > *highp) |
| 489 | *highp = TYPE_FIELD_BITPOS (type, i); |
| 490 | } |
| 491 | |
| 492 | /* Set unsigned indicator if warranted. */ |
| 493 | if(*lowp >= 0) |
| 494 | { |
| 495 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; |
| 496 | } |
| 497 | } |
| 498 | else |
| 499 | { |
| 500 | *lowp = 0; |
| 501 | *highp = -1; |
| 502 | } |
| 503 | return 0; |
| 504 | case TYPE_CODE_BOOL: |
| 505 | *lowp = 0; |
| 506 | *highp = 1; |
| 507 | return 0; |
| 508 | case TYPE_CODE_INT: |
| 509 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
| 510 | return -1; |
| 511 | if (!TYPE_UNSIGNED (type)) |
| 512 | { |
| 513 | *lowp = - (1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); |
| 514 | *highp = -*lowp - 1; |
| 515 | return 0; |
| 516 | } |
| 517 | /* ... fall through for unsigned ints ... */ |
| 518 | case TYPE_CODE_CHAR: |
| 519 | *lowp = 0; |
| 520 | /* This round-about calculation is to avoid shifting by |
| 521 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work |
| 522 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ |
| 523 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); |
| 524 | *highp = (*highp - 1) | *highp; |
| 525 | return 0; |
| 526 | default: |
| 527 | return -1; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /* Create an array type using either a blank type supplied in RESULT_TYPE, |
| 532 | or creating a new type, inheriting the objfile from RANGE_TYPE. |
| 533 | |
| 534 | Elements will be of type ELEMENT_TYPE, the indices will be of type |
| 535 | RANGE_TYPE. |
| 536 | |
| 537 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
| 538 | sure it is TYPE_CODE_UNDEF before we bash it into an array type? */ |
| 539 | |
| 540 | struct type * |
| 541 | create_array_type (result_type, element_type, range_type) |
| 542 | struct type *result_type; |
| 543 | struct type *element_type; |
| 544 | struct type *range_type; |
| 545 | { |
| 546 | LONGEST low_bound, high_bound; |
| 547 | |
| 548 | if (result_type == NULL) |
| 549 | { |
| 550 | result_type = alloc_type (TYPE_OBJFILE (range_type)); |
| 551 | } |
| 552 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; |
| 553 | TYPE_TARGET_TYPE (result_type) = element_type; |
| 554 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) |
| 555 | low_bound = high_bound = 0; |
| 556 | CHECK_TYPEDEF (element_type); |
| 557 | TYPE_LENGTH (result_type) = |
| 558 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); |
| 559 | TYPE_NFIELDS (result_type) = 1; |
| 560 | TYPE_FIELDS (result_type) = |
| 561 | (struct field *) TYPE_ALLOC (result_type, sizeof (struct field)); |
| 562 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); |
| 563 | TYPE_FIELD_TYPE (result_type, 0) = range_type; |
| 564 | TYPE_VPTR_FIELDNO (result_type) = -1; |
| 565 | |
| 566 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */ |
| 567 | if (TYPE_LENGTH (result_type) == 0) |
| 568 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; |
| 569 | |
| 570 | return (result_type); |
| 571 | } |
| 572 | |
| 573 | /* Create a string type using either a blank type supplied in RESULT_TYPE, |
| 574 | or creating a new type. String types are similar enough to array of |
| 575 | char types that we can use create_array_type to build the basic type |
| 576 | and then bash it into a string type. |
| 577 | |
| 578 | For fixed length strings, the range type contains 0 as the lower |
| 579 | bound and the length of the string minus one as the upper bound. |
| 580 | |
| 581 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
| 582 | sure it is TYPE_CODE_UNDEF before we bash it into a string type? */ |
| 583 | |
| 584 | struct type * |
| 585 | create_string_type (result_type, range_type) |
| 586 | struct type *result_type; |
| 587 | struct type *range_type; |
| 588 | { |
| 589 | result_type = create_array_type (result_type, |
| 590 | *current_language->string_char_type, |
| 591 | range_type); |
| 592 | TYPE_CODE (result_type) = TYPE_CODE_STRING; |
| 593 | return (result_type); |
| 594 | } |
| 595 | |
| 596 | struct type * |
| 597 | create_set_type (result_type, domain_type) |
| 598 | struct type *result_type; |
| 599 | struct type *domain_type; |
| 600 | { |
| 601 | LONGEST low_bound, high_bound, bit_length; |
| 602 | if (result_type == NULL) |
| 603 | { |
| 604 | result_type = alloc_type (TYPE_OBJFILE (domain_type)); |
| 605 | } |
| 606 | TYPE_CODE (result_type) = TYPE_CODE_SET; |
| 607 | TYPE_NFIELDS (result_type) = 1; |
| 608 | TYPE_FIELDS (result_type) = (struct field *) |
| 609 | TYPE_ALLOC (result_type, 1 * sizeof (struct field)); |
| 610 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); |
| 611 | |
| 612 | if (! (TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB)) |
| 613 | { |
| 614 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) |
| 615 | low_bound = high_bound = 0; |
| 616 | bit_length = high_bound - low_bound + 1; |
| 617 | TYPE_LENGTH (result_type) |
| 618 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; |
| 619 | } |
| 620 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; |
| 621 | |
| 622 | if(low_bound >= 0) |
| 623 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
| 624 | |
| 625 | return (result_type); |
| 626 | } |
| 627 | |
| 628 | /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. |
| 629 | A MEMBER is a wierd thing -- it amounts to a typed offset into |
| 630 | a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't |
| 631 | include the offset (that's the value of the MEMBER itself), but does |
| 632 | include the structure type into which it points (for some reason). |
| 633 | |
| 634 | When "smashing" the type, we preserve the objfile that the |
| 635 | old type pointed to, since we aren't changing where the type is actually |
| 636 | allocated. */ |
| 637 | |
| 638 | void |
| 639 | smash_to_member_type (type, domain, to_type) |
| 640 | struct type *type; |
| 641 | struct type *domain; |
| 642 | struct type *to_type; |
| 643 | { |
| 644 | struct objfile *objfile; |
| 645 | |
| 646 | objfile = TYPE_OBJFILE (type); |
| 647 | |
| 648 | memset ((char *) type, 0, sizeof (struct type)); |
| 649 | TYPE_OBJFILE (type) = objfile; |
| 650 | TYPE_TARGET_TYPE (type) = to_type; |
| 651 | TYPE_DOMAIN_TYPE (type) = domain; |
| 652 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
| 653 | TYPE_CODE (type) = TYPE_CODE_MEMBER; |
| 654 | } |
| 655 | |
| 656 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. |
| 657 | METHOD just means `function that gets an extra "this" argument'. |
| 658 | |
| 659 | When "smashing" the type, we preserve the objfile that the |
| 660 | old type pointed to, since we aren't changing where the type is actually |
| 661 | allocated. */ |
| 662 | |
| 663 | void |
| 664 | smash_to_method_type (type, domain, to_type, args) |
| 665 | struct type *type; |
| 666 | struct type *domain; |
| 667 | struct type *to_type; |
| 668 | struct type **args; |
| 669 | { |
| 670 | struct objfile *objfile; |
| 671 | |
| 672 | objfile = TYPE_OBJFILE (type); |
| 673 | |
| 674 | memset ((char *) type, 0, sizeof (struct type)); |
| 675 | TYPE_OBJFILE (type) = objfile; |
| 676 | TYPE_TARGET_TYPE (type) = to_type; |
| 677 | TYPE_DOMAIN_TYPE (type) = domain; |
| 678 | TYPE_ARG_TYPES (type) = args; |
| 679 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
| 680 | TYPE_CODE (type) = TYPE_CODE_METHOD; |
| 681 | } |
| 682 | |
| 683 | /* Return a typename for a struct/union/enum type without "struct ", |
| 684 | "union ", or "enum ". If the type has a NULL name, return NULL. */ |
| 685 | |
| 686 | char * |
| 687 | type_name_no_tag (type) |
| 688 | register const struct type *type; |
| 689 | { |
| 690 | if (TYPE_TAG_NAME (type) != NULL) |
| 691 | return TYPE_TAG_NAME (type); |
| 692 | |
| 693 | /* Is there code which expects this to return the name if there is no |
| 694 | tag name? My guess is that this is mainly used for C++ in cases where |
| 695 | the two will always be the same. */ |
| 696 | return TYPE_NAME (type); |
| 697 | } |
| 698 | |
| 699 | /* Lookup a primitive type named NAME. |
| 700 | Return zero if NAME is not a primitive type.*/ |
| 701 | |
| 702 | struct type * |
| 703 | lookup_primitive_typename (name) |
| 704 | char *name; |
| 705 | { |
| 706 | struct type ** const *p; |
| 707 | |
| 708 | for (p = current_language -> la_builtin_type_vector; *p != NULL; p++) |
| 709 | { |
| 710 | if (STREQ ((**p) -> name, name)) |
| 711 | { |
| 712 | return (**p); |
| 713 | } |
| 714 | } |
| 715 | return (NULL); |
| 716 | } |
| 717 | |
| 718 | /* Lookup a typedef or primitive type named NAME, |
| 719 | visible in lexical block BLOCK. |
| 720 | If NOERR is nonzero, return zero if NAME is not suitably defined. */ |
| 721 | |
| 722 | struct type * |
| 723 | lookup_typename (name, block, noerr) |
| 724 | char *name; |
| 725 | struct block *block; |
| 726 | int noerr; |
| 727 | { |
| 728 | register struct symbol *sym; |
| 729 | register struct type *tmp; |
| 730 | |
| 731 | sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL); |
| 732 | if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) |
| 733 | { |
| 734 | tmp = lookup_primitive_typename (name); |
| 735 | if (tmp) |
| 736 | { |
| 737 | return (tmp); |
| 738 | } |
| 739 | else if (!tmp && noerr) |
| 740 | { |
| 741 | return (NULL); |
| 742 | } |
| 743 | else |
| 744 | { |
| 745 | error ("No type named %s.", name); |
| 746 | } |
| 747 | } |
| 748 | return (SYMBOL_TYPE (sym)); |
| 749 | } |
| 750 | |
| 751 | struct type * |
| 752 | lookup_unsigned_typename (name) |
| 753 | char *name; |
| 754 | { |
| 755 | char *uns = alloca (strlen (name) + 10); |
| 756 | |
| 757 | strcpy (uns, "unsigned "); |
| 758 | strcpy (uns + 9, name); |
| 759 | return (lookup_typename (uns, (struct block *) NULL, 0)); |
| 760 | } |
| 761 | |
| 762 | struct type * |
| 763 | lookup_signed_typename (name) |
| 764 | char *name; |
| 765 | { |
| 766 | struct type *t; |
| 767 | char *uns = alloca (strlen (name) + 8); |
| 768 | |
| 769 | strcpy (uns, "signed "); |
| 770 | strcpy (uns + 7, name); |
| 771 | t = lookup_typename (uns, (struct block *) NULL, 1); |
| 772 | /* If we don't find "signed FOO" just try again with plain "FOO". */ |
| 773 | if (t != NULL) |
| 774 | return t; |
| 775 | return lookup_typename (name, (struct block *) NULL, 0); |
| 776 | } |
| 777 | |
| 778 | /* Lookup a structure type named "struct NAME", |
| 779 | visible in lexical block BLOCK. */ |
| 780 | |
| 781 | struct type * |
| 782 | lookup_struct (name, block) |
| 783 | char *name; |
| 784 | struct block *block; |
| 785 | { |
| 786 | register struct symbol *sym; |
| 787 | |
| 788 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, |
| 789 | (struct symtab **) NULL); |
| 790 | |
| 791 | if (sym == NULL) |
| 792 | { |
| 793 | error ("No struct type named %s.", name); |
| 794 | } |
| 795 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) |
| 796 | { |
| 797 | error ("This context has class, union or enum %s, not a struct.", name); |
| 798 | } |
| 799 | return (SYMBOL_TYPE (sym)); |
| 800 | } |
| 801 | |
| 802 | /* Lookup a union type named "union NAME", |
| 803 | visible in lexical block BLOCK. */ |
| 804 | |
| 805 | struct type * |
| 806 | lookup_union (name, block) |
| 807 | char *name; |
| 808 | struct block *block; |
| 809 | { |
| 810 | register struct symbol *sym; |
| 811 | struct type * t; |
| 812 | |
| 813 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, |
| 814 | (struct symtab **) NULL); |
| 815 | |
| 816 | if (sym == NULL) |
| 817 | error ("No union type named %s.", name); |
| 818 | |
| 819 | t = SYMBOL_TYPE(sym); |
| 820 | |
| 821 | if (TYPE_CODE (t) == TYPE_CODE_UNION) |
| 822 | return (t); |
| 823 | |
| 824 | /* C++ unions may come out with TYPE_CODE_CLASS, but we look at |
| 825 | * a further "declared_type" field to discover it is really a union. |
| 826 | */ |
| 827 | if (HAVE_CPLUS_STRUCT (t)) |
| 828 | if (TYPE_DECLARED_TYPE(t) == DECLARED_TYPE_UNION) |
| 829 | return (t); |
| 830 | |
| 831 | /* If we get here, it's not a union */ |
| 832 | error ("This context has class, struct or enum %s, not a union.", name); |
| 833 | } |
| 834 | |
| 835 | |
| 836 | /* Lookup an enum type named "enum NAME", |
| 837 | visible in lexical block BLOCK. */ |
| 838 | |
| 839 | struct type * |
| 840 | lookup_enum (name, block) |
| 841 | char *name; |
| 842 | struct block *block; |
| 843 | { |
| 844 | register struct symbol *sym; |
| 845 | |
| 846 | sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0, |
| 847 | (struct symtab **) NULL); |
| 848 | if (sym == NULL) |
| 849 | { |
| 850 | error ("No enum type named %s.", name); |
| 851 | } |
| 852 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) |
| 853 | { |
| 854 | error ("This context has class, struct or union %s, not an enum.", name); |
| 855 | } |
| 856 | return (SYMBOL_TYPE (sym)); |
| 857 | } |
| 858 | |
| 859 | /* Lookup a template type named "template NAME<TYPE>", |
| 860 | visible in lexical block BLOCK. */ |
| 861 | |
| 862 | struct type * |
| 863 | lookup_template_type (name, type, block) |
| 864 | char *name; |
| 865 | struct type *type; |
| 866 | struct block *block; |
| 867 | { |
| 868 | struct symbol *sym; |
| 869 | char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4); |
| 870 | strcpy (nam, name); |
| 871 | strcat (nam, "<"); |
| 872 | strcat (nam, type->name); |
| 873 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ |
| 874 | |
| 875 | sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL); |
| 876 | |
| 877 | if (sym == NULL) |
| 878 | { |
| 879 | error ("No template type named %s.", name); |
| 880 | } |
| 881 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) |
| 882 | { |
| 883 | error ("This context has class, union or enum %s, not a struct.", name); |
| 884 | } |
| 885 | return (SYMBOL_TYPE (sym)); |
| 886 | } |
| 887 | |
| 888 | /* Given a type TYPE, lookup the type of the component of type named NAME. |
| 889 | |
| 890 | TYPE can be either a struct or union, or a pointer or reference to a struct or |
| 891 | union. If it is a pointer or reference, its target type is automatically used. |
| 892 | Thus '.' and '->' are interchangable, as specified for the definitions of the |
| 893 | expression element types STRUCTOP_STRUCT and STRUCTOP_PTR. |
| 894 | |
| 895 | If NOERR is nonzero, return zero if NAME is not suitably defined. |
| 896 | If NAME is the name of a baseclass type, return that type. */ |
| 897 | |
| 898 | struct type * |
| 899 | lookup_struct_elt_type (type, name, noerr) |
| 900 | struct type *type; |
| 901 | char *name; |
| 902 | int noerr; |
| 903 | { |
| 904 | int i; |
| 905 | |
| 906 | for (;;) |
| 907 | { |
| 908 | CHECK_TYPEDEF (type); |
| 909 | if (TYPE_CODE (type) != TYPE_CODE_PTR |
| 910 | && TYPE_CODE (type) != TYPE_CODE_REF) |
| 911 | break; |
| 912 | type = TYPE_TARGET_TYPE (type); |
| 913 | } |
| 914 | |
| 915 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT && |
| 916 | TYPE_CODE (type) != TYPE_CODE_UNION) |
| 917 | { |
| 918 | target_terminal_ours (); |
| 919 | gdb_flush (gdb_stdout); |
| 920 | fprintf_unfiltered (gdb_stderr, "Type "); |
| 921 | type_print (type, "", gdb_stderr, -1); |
| 922 | error (" is not a structure or union type."); |
| 923 | } |
| 924 | |
| 925 | #if 0 |
| 926 | /* FIXME: This change put in by Michael seems incorrect for the case where |
| 927 | the structure tag name is the same as the member name. I.E. when doing |
| 928 | "ptype bell->bar" for "struct foo { int bar; int foo; } bell;" |
| 929 | Disabled by fnf. */ |
| 930 | { |
| 931 | char *typename; |
| 932 | |
| 933 | typename = type_name_no_tag (type); |
| 934 | if (typename != NULL && STREQ (typename, name)) |
| 935 | return type; |
| 936 | } |
| 937 | #endif |
| 938 | |
| 939 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) |
| 940 | { |
| 941 | char *t_field_name = TYPE_FIELD_NAME (type, i); |
| 942 | |
| 943 | if (t_field_name && STREQ (t_field_name, name)) |
| 944 | { |
| 945 | return TYPE_FIELD_TYPE (type, i); |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | /* OK, it's not in this class. Recursively check the baseclasses. */ |
| 950 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) |
| 951 | { |
| 952 | struct type *t; |
| 953 | |
| 954 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr); |
| 955 | if (t != NULL) |
| 956 | { |
| 957 | return t; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | if (noerr) |
| 962 | { |
| 963 | return NULL; |
| 964 | } |
| 965 | |
| 966 | target_terminal_ours (); |
| 967 | gdb_flush (gdb_stdout); |
| 968 | fprintf_unfiltered (gdb_stderr, "Type "); |
| 969 | type_print (type, "", gdb_stderr, -1); |
| 970 | fprintf_unfiltered (gdb_stderr, " has no component named "); |
| 971 | fputs_filtered (name, gdb_stderr); |
| 972 | error ("."); |
| 973 | return (struct type *)-1; /* For lint */ |
| 974 | } |
| 975 | |
| 976 | /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE |
| 977 | valid. Callers should be aware that in some cases (for example, |
| 978 | the type or one of its baseclasses is a stub type and we are |
| 979 | debugging a .o file), this function will not be able to find the virtual |
| 980 | function table pointer, and vptr_fieldno will remain -1 and vptr_basetype |
| 981 | will remain NULL. */ |
| 982 | |
| 983 | void |
| 984 | fill_in_vptr_fieldno (type) |
| 985 | struct type *type; |
| 986 | { |
| 987 | CHECK_TYPEDEF (type); |
| 988 | |
| 989 | if (TYPE_VPTR_FIELDNO (type) < 0) |
| 990 | { |
| 991 | int i; |
| 992 | |
| 993 | /* We must start at zero in case the first (and only) baseclass is |
| 994 | virtual (and hence we cannot share the table pointer). */ |
| 995 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
| 996 | { |
| 997 | fill_in_vptr_fieldno (TYPE_BASECLASS (type, i)); |
| 998 | if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0) |
| 999 | { |
| 1000 | TYPE_VPTR_FIELDNO (type) |
| 1001 | = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)); |
| 1002 | TYPE_VPTR_BASETYPE (type) |
| 1003 | = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i)); |
| 1004 | break; |
| 1005 | } |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | /* Find the method and field indices for the destructor in class type T. |
| 1011 | Return 1 if the destructor was found, otherwise, return 0. */ |
| 1012 | |
| 1013 | int |
| 1014 | get_destructor_fn_field (t, method_indexp, field_indexp) |
| 1015 | struct type *t; |
| 1016 | int *method_indexp; |
| 1017 | int *field_indexp; |
| 1018 | { |
| 1019 | int i; |
| 1020 | |
| 1021 | for (i = 0; i < TYPE_NFN_FIELDS (t); i++) |
| 1022 | { |
| 1023 | int j; |
| 1024 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); |
| 1025 | |
| 1026 | for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++) |
| 1027 | { |
| 1028 | if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j))) |
| 1029 | { |
| 1030 | *method_indexp = i; |
| 1031 | *field_indexp = j; |
| 1032 | return 1; |
| 1033 | } |
| 1034 | } |
| 1035 | } |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. |
| 1040 | |
| 1041 | If this is a stubbed struct (i.e. declared as struct foo *), see if |
| 1042 | we can find a full definition in some other file. If so, copy this |
| 1043 | definition, so we can use it in future. There used to be a comment (but |
| 1044 | not any code) that if we don't find a full definition, we'd set a flag |
| 1045 | so we don't spend time in the future checking the same type. That would |
| 1046 | be a mistake, though--we might load in more symbols which contain a |
| 1047 | full definition for the type. |
| 1048 | |
| 1049 | This used to be coded as a macro, but I don't think it is called |
| 1050 | often enough to merit such treatment. */ |
| 1051 | |
| 1052 | struct complaint stub_noname_complaint = |
| 1053 | {"stub type has NULL name", 0, 0}; |
| 1054 | |
| 1055 | struct type * |
| 1056 | check_typedef (type) |
| 1057 | register struct type *type; |
| 1058 | { |
| 1059 | struct type *orig_type = type; |
| 1060 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
| 1061 | { |
| 1062 | if (!TYPE_TARGET_TYPE (type)) |
| 1063 | { |
| 1064 | char* name; |
| 1065 | struct symbol *sym; |
| 1066 | |
| 1067 | /* It is dangerous to call lookup_symbol if we are currently |
| 1068 | reading a symtab. Infinite recursion is one danger. */ |
| 1069 | if (currently_reading_symtab) |
| 1070 | return type; |
| 1071 | |
| 1072 | name = type_name_no_tag (type); |
| 1073 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
| 1074 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE |
| 1075 | as appropriate? (this code was written before TYPE_NAME and |
| 1076 | TYPE_TAG_NAME were separate). */ |
| 1077 | if (name == NULL) |
| 1078 | { |
| 1079 | complain (&stub_noname_complaint); |
| 1080 | return type; |
| 1081 | } |
| 1082 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, |
| 1083 | (struct symtab **) NULL); |
| 1084 | if (sym) |
| 1085 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); |
| 1086 | else |
| 1087 | TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */ |
| 1088 | } |
| 1089 | type = TYPE_TARGET_TYPE (type); |
| 1090 | } |
| 1091 | |
| 1092 | /* If this is a struct/class/union with no fields, then check whether a |
| 1093 | full definition exists somewhere else. This is for systems where a |
| 1094 | type definition with no fields is issued for such types, instead of |
| 1095 | identifying them as stub types in the first place */ |
| 1096 | |
| 1097 | if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab) |
| 1098 | { |
| 1099 | char * name = type_name_no_tag (type); |
| 1100 | struct type * newtype; |
| 1101 | if (name == NULL) |
| 1102 | { |
| 1103 | complain (&stub_noname_complaint); |
| 1104 | return type; |
| 1105 | } |
| 1106 | newtype = lookup_transparent_type (name); |
| 1107 | if (newtype) |
| 1108 | { |
| 1109 | memcpy ((char *) type, (char *) newtype, sizeof (struct type)); |
| 1110 | } |
| 1111 | } |
| 1112 | /* Otherwise, rely on the stub flag being set for opaque/stubbed types */ |
| 1113 | else if ((TYPE_FLAGS(type) & TYPE_FLAG_STUB) && ! currently_reading_symtab) |
| 1114 | { |
| 1115 | char* name = type_name_no_tag (type); |
| 1116 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
| 1117 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE |
| 1118 | as appropriate? (this code was written before TYPE_NAME and |
| 1119 | TYPE_TAG_NAME were separate). */ |
| 1120 | struct symbol *sym; |
| 1121 | if (name == NULL) |
| 1122 | { |
| 1123 | complain (&stub_noname_complaint); |
| 1124 | return type; |
| 1125 | } |
| 1126 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL); |
| 1127 | if (sym) |
| 1128 | { |
| 1129 | memcpy ((char *)type, (char *)SYMBOL_TYPE(sym), sizeof (struct type)); |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB) |
| 1134 | { |
| 1135 | struct type *range_type; |
| 1136 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); |
| 1137 | |
| 1138 | if (TYPE_FLAGS (target_type) & (TYPE_FLAG_STUB | TYPE_FLAG_TARGET_STUB)) |
| 1139 | { } |
| 1140 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
| 1141 | && TYPE_NFIELDS (type) == 1 |
| 1142 | && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0)) |
| 1143 | == TYPE_CODE_RANGE)) |
| 1144 | { |
| 1145 | /* Now recompute the length of the array type, based on its |
| 1146 | number of elements and the target type's length. */ |
| 1147 | TYPE_LENGTH (type) = |
| 1148 | ((TYPE_FIELD_BITPOS (range_type, 1) |
| 1149 | - TYPE_FIELD_BITPOS (range_type, 0) |
| 1150 | + 1) |
| 1151 | * TYPE_LENGTH (target_type)); |
| 1152 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; |
| 1153 | } |
| 1154 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
| 1155 | { |
| 1156 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); |
| 1157 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; |
| 1158 | } |
| 1159 | } |
| 1160 | /* Cache TYPE_LENGTH for future use. */ |
| 1161 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); |
| 1162 | return type; |
| 1163 | } |
| 1164 | |
| 1165 | /* New code added to support parsing of Cfront stabs strings */ |
| 1166 | #include <ctype.h> |
| 1167 | #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; } |
| 1168 | #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; } |
| 1169 | |
| 1170 | static void |
| 1171 | add_name(pextras,n) |
| 1172 | struct extra * pextras; |
| 1173 | char * n; |
| 1174 | { |
| 1175 | int nlen; |
| 1176 | |
| 1177 | if ((nlen = (n ? strlen(n) : 0))==0) |
| 1178 | return; |
| 1179 | sprintf(pextras->str+pextras->len,"%d%s",nlen,n); |
| 1180 | pextras->len=strlen(pextras->str); |
| 1181 | } |
| 1182 | |
| 1183 | static void |
| 1184 | add_mangled_type(pextras,t) |
| 1185 | struct extra * pextras; |
| 1186 | struct type * t; |
| 1187 | { |
| 1188 | enum type_code tcode; |
| 1189 | int tlen, tflags; |
| 1190 | char * tname; |
| 1191 | |
| 1192 | tcode = TYPE_CODE(t); |
| 1193 | tlen = TYPE_LENGTH(t); |
| 1194 | tflags = TYPE_FLAGS(t); |
| 1195 | tname = TYPE_NAME(t); |
| 1196 | /* args of "..." seem to get mangled as "e" */ |
| 1197 | |
| 1198 | switch (tcode) |
| 1199 | { |
| 1200 | case TYPE_CODE_INT: |
| 1201 | if (tflags==1) |
| 1202 | ADD_EXTRA('U'); |
| 1203 | switch (tlen) |
| 1204 | { |
| 1205 | case 1: |
| 1206 | ADD_EXTRA('c'); |
| 1207 | break; |
| 1208 | case 2: |
| 1209 | ADD_EXTRA('s'); |
| 1210 | break; |
| 1211 | case 4: |
| 1212 | { |
| 1213 | char* pname; |
| 1214 | if ((pname=strrchr(tname,'l'),pname) && !strcmp(pname,"long")) |
| 1215 | ADD_EXTRA('l') |
| 1216 | else |
| 1217 | ADD_EXTRA('i') |
| 1218 | } |
| 1219 | break; |
| 1220 | default: |
| 1221 | { |
| 1222 | |
| 1223 | static struct complaint msg = {"Bad int type code length x%x\n",0,0}; |
| 1224 | |
| 1225 | complain (&msg, tlen); |
| 1226 | |
| 1227 | } |
| 1228 | } |
| 1229 | break; |
| 1230 | case TYPE_CODE_FLT: |
| 1231 | switch (tlen) |
| 1232 | { |
| 1233 | case 4: |
| 1234 | ADD_EXTRA('f'); |
| 1235 | break; |
| 1236 | case 8: |
| 1237 | ADD_EXTRA('d'); |
| 1238 | break; |
| 1239 | case 16: |
| 1240 | ADD_EXTRA('r'); |
| 1241 | break; |
| 1242 | default: |
| 1243 | { |
| 1244 | static struct complaint msg = {"Bad float type code length x%x\n",0,0}; |
| 1245 | complain (&msg, tlen); |
| 1246 | } |
| 1247 | } |
| 1248 | break; |
| 1249 | case TYPE_CODE_REF: |
| 1250 | ADD_EXTRA('R'); |
| 1251 | /* followed by what it's a ref to */ |
| 1252 | break; |
| 1253 | case TYPE_CODE_PTR: |
| 1254 | ADD_EXTRA('P'); |
| 1255 | /* followed by what it's a ptr to */ |
| 1256 | break; |
| 1257 | case TYPE_CODE_TYPEDEF: |
| 1258 | { |
| 1259 | static struct complaint msg = {"Typedefs in overloaded functions not yet supported\n",0,0}; |
| 1260 | complain (&msg); |
| 1261 | } |
| 1262 | /* followed by type bytes & name */ |
| 1263 | break; |
| 1264 | case TYPE_CODE_FUNC: |
| 1265 | ADD_EXTRA('F'); |
| 1266 | /* followed by func's arg '_' & ret types */ |
| 1267 | break; |
| 1268 | case TYPE_CODE_VOID: |
| 1269 | ADD_EXTRA('v'); |
| 1270 | break; |
| 1271 | case TYPE_CODE_METHOD: |
| 1272 | ADD_EXTRA('M'); |
| 1273 | /* followed by name of class and func's arg '_' & ret types */ |
| 1274 | add_name(pextras,tname); |
| 1275 | ADD_EXTRA('F'); /* then mangle function */ |
| 1276 | break; |
| 1277 | case TYPE_CODE_STRUCT: /* C struct */ |
| 1278 | case TYPE_CODE_UNION: /* C union */ |
| 1279 | case TYPE_CODE_ENUM: /* Enumeration type */ |
| 1280 | /* followed by name of type */ |
| 1281 | add_name(pextras,tname); |
| 1282 | break; |
| 1283 | |
| 1284 | /* errors possible types/not supported */ |
| 1285 | case TYPE_CODE_CHAR: |
| 1286 | case TYPE_CODE_ARRAY: /* Array type */ |
| 1287 | case TYPE_CODE_MEMBER: /* Member type */ |
| 1288 | case TYPE_CODE_BOOL: |
| 1289 | case TYPE_CODE_COMPLEX: /* Complex float */ |
| 1290 | case TYPE_CODE_UNDEF: |
| 1291 | case TYPE_CODE_SET: /* Pascal sets */ |
| 1292 | case TYPE_CODE_RANGE: |
| 1293 | case TYPE_CODE_STRING: |
| 1294 | case TYPE_CODE_BITSTRING: |
| 1295 | case TYPE_CODE_ERROR: |
| 1296 | default: |
| 1297 | { |
| 1298 | static struct complaint msg = {"Unknown type code x%x\n",0,0}; |
| 1299 | complain (&msg, tcode); |
| 1300 | } |
| 1301 | } |
| 1302 | if (t->target_type) |
| 1303 | add_mangled_type(pextras,t->target_type); |
| 1304 | } |
| 1305 | |
| 1306 | #if 0 |
| 1307 | void |
| 1308 | cfront_mangle_name(type, i, j) |
| 1309 | struct type *type; |
| 1310 | int i; |
| 1311 | int j; |
| 1312 | { |
| 1313 | struct fn_field *f; |
| 1314 | char *mangled_name = gdb_mangle_name (type, i, j); |
| 1315 | |
| 1316 | f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */ |
| 1317 | |
| 1318 | /* kludge to support cfront methods - gdb expects to find "F" for |
| 1319 | ARM_mangled names, so when we mangle, we have to add it here */ |
| 1320 | if (ARM_DEMANGLING) |
| 1321 | { |
| 1322 | int k; |
| 1323 | char * arm_mangled_name; |
| 1324 | struct fn_field *method = &f[j]; |
| 1325 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, i); |
| 1326 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); |
| 1327 | char *newname = type_name_no_tag (type); |
| 1328 | |
| 1329 | struct type *ftype = TYPE_FN_FIELD_TYPE (f, j); |
| 1330 | int nargs = TYPE_NFIELDS(ftype); /* number of args */ |
| 1331 | struct extra extras, * pextras = &extras; |
| 1332 | INIT_EXTRA |
| 1333 | |
| 1334 | if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */ |
| 1335 | ADD_EXTRA('S') |
| 1336 | ADD_EXTRA('F') |
| 1337 | /* add args here! */ |
| 1338 | if (nargs <= 1) /* no args besides this */ |
| 1339 | ADD_EXTRA('v') |
| 1340 | else { |
| 1341 | for (k=1; k<nargs; k++) |
| 1342 | { |
| 1343 | struct type * t; |
| 1344 | t = TYPE_FIELD_TYPE(ftype,k); |
| 1345 | add_mangled_type(pextras,t); |
| 1346 | } |
| 1347 | } |
| 1348 | ADD_EXTRA('\0') |
| 1349 | printf("add_mangled_type: %s\n",extras.str); /* FIXME */ |
| 1350 | arm_mangled_name = malloc(strlen(mangled_name)+extras.len); |
| 1351 | sprintf(arm_mangled_name,"%s%s",mangled_name,extras.str); |
| 1352 | free(mangled_name); |
| 1353 | mangled_name = arm_mangled_name; |
| 1354 | } |
| 1355 | } |
| 1356 | #endif /* 0 */ |
| 1357 | |
| 1358 | #undef ADD_EXTRA |
| 1359 | /* End of new code added to support parsing of Cfront stabs strings */ |
| 1360 | |
| 1361 | /* Ugly hack to convert method stubs into method types. |
| 1362 | |
| 1363 | He ain't kiddin'. This demangles the name of the method into a string |
| 1364 | including argument types, parses out each argument type, generates |
| 1365 | a string casting a zero to that type, evaluates the string, and stuffs |
| 1366 | the resulting type into an argtype vector!!! Then it knows the type |
| 1367 | of the whole function (including argument types for overloading), |
| 1368 | which info used to be in the stab's but was removed to hack back |
| 1369 | the space required for them. */ |
| 1370 | |
| 1371 | void |
| 1372 | check_stub_method (type, method_id, signature_id) |
| 1373 | struct type *type; |
| 1374 | int method_id; |
| 1375 | int signature_id; |
| 1376 | { |
| 1377 | struct fn_field *f; |
| 1378 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); |
| 1379 | char *demangled_name = cplus_demangle (mangled_name, |
| 1380 | DMGL_PARAMS | DMGL_ANSI); |
| 1381 | char *argtypetext, *p; |
| 1382 | int depth = 0, argcount = 1; |
| 1383 | struct type **argtypes; |
| 1384 | struct type *mtype; |
| 1385 | |
| 1386 | /* Make sure we got back a function string that we can use. */ |
| 1387 | if (demangled_name) |
| 1388 | p = strchr (demangled_name, '('); |
| 1389 | |
| 1390 | if (demangled_name == NULL || p == NULL) |
| 1391 | error ("Internal: Cannot demangle mangled name `%s'.", mangled_name); |
| 1392 | |
| 1393 | /* Now, read in the parameters that define this type. */ |
| 1394 | p += 1; |
| 1395 | argtypetext = p; |
| 1396 | while (*p) |
| 1397 | { |
| 1398 | if (*p == '(') |
| 1399 | { |
| 1400 | depth += 1; |
| 1401 | } |
| 1402 | else if (*p == ')') |
| 1403 | { |
| 1404 | depth -= 1; |
| 1405 | } |
| 1406 | else if (*p == ',' && depth == 0) |
| 1407 | { |
| 1408 | argcount += 1; |
| 1409 | } |
| 1410 | |
| 1411 | p += 1; |
| 1412 | } |
| 1413 | |
| 1414 | /* We need two more slots: one for the THIS pointer, and one for the |
| 1415 | NULL [...] or void [end of arglist]. */ |
| 1416 | |
| 1417 | argtypes = (struct type **) |
| 1418 | TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *)); |
| 1419 | p = argtypetext; |
| 1420 | /* FIXME: This is wrong for static member functions. */ |
| 1421 | argtypes[0] = lookup_pointer_type (type); |
| 1422 | argcount = 1; |
| 1423 | |
| 1424 | if (*p != ')') /* () means no args, skip while */ |
| 1425 | { |
| 1426 | depth = 0; |
| 1427 | while (*p) |
| 1428 | { |
| 1429 | if (depth <= 0 && (*p == ',' || *p == ')')) |
| 1430 | { |
| 1431 | /* Avoid parsing of ellipsis, they will be handled below. */ |
| 1432 | if (strncmp (argtypetext, "...", p - argtypetext) != 0) |
| 1433 | { |
| 1434 | argtypes[argcount] = |
| 1435 | parse_and_eval_type (argtypetext, p - argtypetext); |
| 1436 | argcount += 1; |
| 1437 | } |
| 1438 | argtypetext = p + 1; |
| 1439 | } |
| 1440 | |
| 1441 | if (*p == '(') |
| 1442 | { |
| 1443 | depth += 1; |
| 1444 | } |
| 1445 | else if (*p == ')') |
| 1446 | { |
| 1447 | depth -= 1; |
| 1448 | } |
| 1449 | |
| 1450 | p += 1; |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | if (p[-2] != '.') /* Not '...' */ |
| 1455 | { |
| 1456 | argtypes[argcount] = builtin_type_void; /* List terminator */ |
| 1457 | } |
| 1458 | else |
| 1459 | { |
| 1460 | argtypes[argcount] = NULL; /* Ellist terminator */ |
| 1461 | } |
| 1462 | |
| 1463 | free (demangled_name); |
| 1464 | |
| 1465 | f = TYPE_FN_FIELDLIST1 (type, method_id); |
| 1466 | |
| 1467 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; |
| 1468 | |
| 1469 | /* Now update the old "stub" type into a real type. */ |
| 1470 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); |
| 1471 | TYPE_DOMAIN_TYPE (mtype) = type; |
| 1472 | TYPE_ARG_TYPES (mtype) = argtypes; |
| 1473 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; |
| 1474 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; |
| 1475 | } |
| 1476 | |
| 1477 | const struct cplus_struct_type cplus_struct_default; |
| 1478 | |
| 1479 | void |
| 1480 | allocate_cplus_struct_type (type) |
| 1481 | struct type *type; |
| 1482 | { |
| 1483 | if (!HAVE_CPLUS_STRUCT (type)) |
| 1484 | { |
| 1485 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) |
| 1486 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); |
| 1487 | *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default; |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | /* Helper function to initialize the standard scalar types. |
| 1492 | |
| 1493 | If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy |
| 1494 | of the string pointed to by name in the type_obstack for that objfile, |
| 1495 | and initialize the type name to that copy. There are places (mipsread.c |
| 1496 | in particular, where init_type is called with a NULL value for NAME). */ |
| 1497 | |
| 1498 | struct type * |
| 1499 | init_type (code, length, flags, name, objfile) |
| 1500 | enum type_code code; |
| 1501 | int length; |
| 1502 | int flags; |
| 1503 | char *name; |
| 1504 | struct objfile *objfile; |
| 1505 | { |
| 1506 | register struct type *type; |
| 1507 | |
| 1508 | type = alloc_type (objfile); |
| 1509 | TYPE_CODE (type) = code; |
| 1510 | TYPE_LENGTH (type) = length; |
| 1511 | TYPE_FLAGS (type) |= flags; |
| 1512 | if ((name != NULL) && (objfile != NULL)) |
| 1513 | { |
| 1514 | TYPE_NAME (type) = |
| 1515 | obsavestring (name, strlen (name), &objfile -> type_obstack); |
| 1516 | } |
| 1517 | else |
| 1518 | { |
| 1519 | TYPE_NAME (type) = name; |
| 1520 | } |
| 1521 | |
| 1522 | /* C++ fancies. */ |
| 1523 | |
| 1524 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) |
| 1525 | { |
| 1526 | INIT_CPLUS_SPECIFIC (type); |
| 1527 | } |
| 1528 | return (type); |
| 1529 | } |
| 1530 | |
| 1531 | /* Look up a fundamental type for the specified objfile. |
| 1532 | May need to construct such a type if this is the first use. |
| 1533 | |
| 1534 | Some object file formats (ELF, COFF, etc) do not define fundamental |
| 1535 | types such as "int" or "double". Others (stabs for example), do |
| 1536 | define fundamental types. |
| 1537 | |
| 1538 | For the formats which don't provide fundamental types, gdb can create |
| 1539 | such types, using defaults reasonable for the current language and |
| 1540 | the current target machine. |
| 1541 | |
| 1542 | NOTE: This routine is obsolescent. Each debugging format reader |
| 1543 | should manage it's own fundamental types, either creating them from |
| 1544 | suitable defaults or reading them from the debugging information, |
| 1545 | whichever is appropriate. The DWARF reader has already been |
| 1546 | fixed to do this. Once the other readers are fixed, this routine |
| 1547 | will go away. Also note that fundamental types should be managed |
| 1548 | on a compilation unit basis in a multi-language environment, not |
| 1549 | on a linkage unit basis as is done here. */ |
| 1550 | |
| 1551 | |
| 1552 | struct type * |
| 1553 | lookup_fundamental_type (objfile, typeid) |
| 1554 | struct objfile *objfile; |
| 1555 | int typeid; |
| 1556 | { |
| 1557 | register struct type **typep; |
| 1558 | register int nbytes; |
| 1559 | |
| 1560 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) |
| 1561 | { |
| 1562 | error ("internal error - invalid fundamental type id %d", typeid); |
| 1563 | } |
| 1564 | |
| 1565 | /* If this is the first time we need a fundamental type for this objfile |
| 1566 | then we need to initialize the vector of type pointers. */ |
| 1567 | |
| 1568 | if (objfile -> fundamental_types == NULL) |
| 1569 | { |
| 1570 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); |
| 1571 | objfile -> fundamental_types = (struct type **) |
| 1572 | obstack_alloc (&objfile -> type_obstack, nbytes); |
| 1573 | memset ((char *) objfile -> fundamental_types, 0, nbytes); |
| 1574 | OBJSTAT (objfile, n_types += FT_NUM_MEMBERS); |
| 1575 | } |
| 1576 | |
| 1577 | /* Look for this particular type in the fundamental type vector. If one is |
| 1578 | not found, create and install one appropriate for the current language. */ |
| 1579 | |
| 1580 | typep = objfile -> fundamental_types + typeid; |
| 1581 | if (*typep == NULL) |
| 1582 | { |
| 1583 | *typep = create_fundamental_type (objfile, typeid); |
| 1584 | } |
| 1585 | |
| 1586 | return (*typep); |
| 1587 | } |
| 1588 | |
| 1589 | int |
| 1590 | can_dereference (t) |
| 1591 | struct type *t; |
| 1592 | { |
| 1593 | /* FIXME: Should we return true for references as well as pointers? */ |
| 1594 | CHECK_TYPEDEF (t); |
| 1595 | return |
| 1596 | (t != NULL |
| 1597 | && TYPE_CODE (t) == TYPE_CODE_PTR |
| 1598 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); |
| 1599 | } |
| 1600 | |
| 1601 | /* Chill varying string and arrays are represented as follows: |
| 1602 | |
| 1603 | struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data}; |
| 1604 | |
| 1605 | Return true if TYPE is such a Chill varying type. */ |
| 1606 | |
| 1607 | int |
| 1608 | chill_varying_type (type) |
| 1609 | struct type *type; |
| 1610 | { |
| 1611 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
| 1612 | || TYPE_NFIELDS (type) != 2 |
| 1613 | || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0) |
| 1614 | return 0; |
| 1615 | return 1; |
| 1616 | } |
| 1617 | |
| 1618 | /* Check whether BASE is an ancestor or base class or DCLASS |
| 1619 | Return 1 if so, and 0 if not. |
| 1620 | Note: callers may want to check for identity of the types before |
| 1621 | calling this function -- identical types are considered to satisfy |
| 1622 | the ancestor relationship even if they're identical */ |
| 1623 | |
| 1624 | int |
| 1625 | is_ancestor (base, dclass) |
| 1626 | struct type * base; |
| 1627 | struct type * dclass; |
| 1628 | { |
| 1629 | int i; |
| 1630 | |
| 1631 | CHECK_TYPEDEF (base); |
| 1632 | CHECK_TYPEDEF (dclass); |
| 1633 | |
| 1634 | if (base == dclass) |
| 1635 | return 1; |
| 1636 | |
| 1637 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
| 1638 | if (is_ancestor (base, TYPE_BASECLASS (dclass, i))) |
| 1639 | return 1; |
| 1640 | |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | /* See whether DCLASS has a virtual table. This routine is aimed at |
| 1647 | the HP/Taligent ANSI C++ runtime model, and may not work with other |
| 1648 | runtime models. Return 1 => Yes, 0 => No. */ |
| 1649 | |
| 1650 | int |
| 1651 | has_vtable (dclass) |
| 1652 | struct type * dclass; |
| 1653 | { |
| 1654 | /* In the HP ANSI C++ runtime model, a class has a vtable only if it |
| 1655 | has virtual functions or virtual bases. */ |
| 1656 | |
| 1657 | register int i; |
| 1658 | |
| 1659 | if (TYPE_CODE(dclass) != TYPE_CODE_CLASS) |
| 1660 | return 0; |
| 1661 | |
| 1662 | /* First check for the presence of virtual bases */ |
| 1663 | if (TYPE_FIELD_VIRTUAL_BITS(dclass)) |
| 1664 | for (i=0; i < TYPE_N_BASECLASSES(dclass); i++) |
| 1665 | if (B_TST(TYPE_FIELD_VIRTUAL_BITS(dclass), i)) |
| 1666 | return 1; |
| 1667 | |
| 1668 | /* Next check for virtual functions */ |
| 1669 | if (TYPE_FN_FIELDLISTS(dclass)) |
| 1670 | for (i=0; i < TYPE_NFN_FIELDS(dclass); i++) |
| 1671 | if (TYPE_FN_FIELD_VIRTUAL_P(TYPE_FN_FIELDLIST1(dclass, i), 0)) |
| 1672 | return 1; |
| 1673 | |
| 1674 | /* Recurse on non-virtual bases to see if any of them needs a vtable */ |
| 1675 | if (TYPE_FIELD_VIRTUAL_BITS(dclass)) |
| 1676 | for (i=0; i < TYPE_N_BASECLASSES(dclass); i++) |
| 1677 | if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS(dclass), i)) && |
| 1678 | (has_vtable (TYPE_FIELD_TYPE(dclass, i)))) |
| 1679 | return 1; |
| 1680 | |
| 1681 | /* Well, maybe we don't need a virtual table */ |
| 1682 | return 0; |
| 1683 | } |
| 1684 | |
| 1685 | /* Return a pointer to the "primary base class" of DCLASS. |
| 1686 | |
| 1687 | A NULL return indicates that DCLASS has no primary base, or that it |
| 1688 | couldn't be found (insufficient information). |
| 1689 | |
| 1690 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
| 1691 | and may not work with other runtime models. */ |
| 1692 | |
| 1693 | struct type * |
| 1694 | primary_base_class (dclass) |
| 1695 | struct type * dclass; |
| 1696 | { |
| 1697 | /* In HP ANSI C++'s runtime model, a "primary base class" of a class |
| 1698 | is the first directly inherited, non-virtual base class that |
| 1699 | requires a virtual table */ |
| 1700 | |
| 1701 | register int i; |
| 1702 | |
| 1703 | if (TYPE_CODE(dclass) != TYPE_CODE_CLASS) |
| 1704 | return NULL; |
| 1705 | |
| 1706 | for (i=0; i < TYPE_N_BASECLASSES(dclass); i++) |
| 1707 | if (!TYPE_FIELD_VIRTUAL(dclass, i) && |
| 1708 | has_vtable(TYPE_FIELD_TYPE(dclass, i))) |
| 1709 | return TYPE_FIELD_TYPE(dclass, i); |
| 1710 | |
| 1711 | return NULL; |
| 1712 | } |
| 1713 | |
| 1714 | /* Global manipulated by virtual_base_list[_aux]() */ |
| 1715 | |
| 1716 | static struct vbase * current_vbase_list = NULL; |
| 1717 | |
| 1718 | /* Return a pointer to a null-terminated list of struct vbase |
| 1719 | items. The vbasetype pointer of each item in the list points to the |
| 1720 | type information for a virtual base of the argument DCLASS. |
| 1721 | |
| 1722 | Helper function for virtual_base_list(). |
| 1723 | Note: the list goes backward, right-to-left. virtual_base_list() |
| 1724 | copies the items out in reverse order. */ |
| 1725 | |
| 1726 | struct vbase * |
| 1727 | virtual_base_list_aux (dclass) |
| 1728 | struct type * dclass; |
| 1729 | { |
| 1730 | struct vbase * tmp_vbase; |
| 1731 | register int i; |
| 1732 | |
| 1733 | if (TYPE_CODE(dclass) != TYPE_CODE_CLASS) |
| 1734 | return NULL; |
| 1735 | |
| 1736 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
| 1737 | { |
| 1738 | /* Recurse on this ancestor, first */ |
| 1739 | virtual_base_list_aux(TYPE_FIELD_TYPE(dclass, i)); |
| 1740 | |
| 1741 | /* If this current base is itself virtual, add it to the list */ |
| 1742 | if (BASETYPE_VIA_VIRTUAL(dclass, i)) |
| 1743 | { |
| 1744 | struct type * basetype = TYPE_FIELD_TYPE (dclass, i); |
| 1745 | |
| 1746 | /* Check if base already recorded */ |
| 1747 | tmp_vbase = current_vbase_list; |
| 1748 | while (tmp_vbase) |
| 1749 | { |
| 1750 | if (tmp_vbase->vbasetype == basetype) |
| 1751 | break; /* found it */ |
| 1752 | tmp_vbase = tmp_vbase->next; |
| 1753 | } |
| 1754 | |
| 1755 | if (!tmp_vbase) /* normal exit from loop */ |
| 1756 | { |
| 1757 | /* Allocate new item for this virtual base */ |
| 1758 | tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase)); |
| 1759 | |
| 1760 | /* Stick it on at the end of the list */ |
| 1761 | tmp_vbase->vbasetype = basetype; |
| 1762 | tmp_vbase->next = current_vbase_list; |
| 1763 | current_vbase_list = tmp_vbase; |
| 1764 | } |
| 1765 | } /* if virtual */ |
| 1766 | } /* for loop over bases */ |
| 1767 | } |
| 1768 | |
| 1769 | |
| 1770 | /* Compute the list of virtual bases in the right order. Virtual |
| 1771 | bases are laid out in the object's memory area in order of their |
| 1772 | occurrence in a depth-first, left-to-right search through the |
| 1773 | ancestors. |
| 1774 | |
| 1775 | Argument DCLASS is the type whose virtual bases are required. |
| 1776 | Return value is the address of a null-terminated array of pointers |
| 1777 | to struct type items. |
| 1778 | |
| 1779 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
| 1780 | and may not work with other runtime models. |
| 1781 | |
| 1782 | This routine merely hands off the argument to virtual_base_list_aux() |
| 1783 | and then copies the result into an array to save space. */ |
| 1784 | |
| 1785 | struct type ** |
| 1786 | virtual_base_list (dclass) |
| 1787 | struct type * dclass; |
| 1788 | { |
| 1789 | register struct vbase * tmp_vbase; |
| 1790 | register struct vbase * tmp_vbase_2; |
| 1791 | register int i; |
| 1792 | int count; |
| 1793 | struct type ** vbase_array; |
| 1794 | |
| 1795 | current_vbase_list = NULL; |
| 1796 | virtual_base_list_aux(dclass); |
| 1797 | |
| 1798 | for (i=0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
| 1799 | /* no body */ ; |
| 1800 | |
| 1801 | count = i; |
| 1802 | |
| 1803 | vbase_array = (struct type **) xmalloc((count + 1) * sizeof (struct type *)); |
| 1804 | |
| 1805 | for (i=count -1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next) |
| 1806 | vbase_array[i] = tmp_vbase->vbasetype; |
| 1807 | |
| 1808 | /* Get rid of constructed chain */ |
| 1809 | tmp_vbase_2 = tmp_vbase = current_vbase_list; |
| 1810 | while (tmp_vbase) |
| 1811 | { |
| 1812 | tmp_vbase = tmp_vbase->next; |
| 1813 | free(tmp_vbase_2); |
| 1814 | tmp_vbase_2 = tmp_vbase; |
| 1815 | } |
| 1816 | |
| 1817 | vbase_array[count] = NULL; |
| 1818 | return vbase_array; |
| 1819 | } |
| 1820 | |
| 1821 | /* Return the length of the virtual base list of the type DCLASS. */ |
| 1822 | |
| 1823 | int |
| 1824 | virtual_base_list_length (dclass) |
| 1825 | struct type * dclass; |
| 1826 | { |
| 1827 | register int i; |
| 1828 | register struct vbase * tmp_vbase; |
| 1829 | |
| 1830 | current_vbase_list = NULL; |
| 1831 | virtual_base_list_aux(dclass); |
| 1832 | |
| 1833 | for (i=0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
| 1834 | /* no body */ ; |
| 1835 | return i; |
| 1836 | } |
| 1837 | |
| 1838 | /* Return the number of elements of the virtual base list of the type |
| 1839 | DCLASS, ignoring those appearing in the primary base (and its |
| 1840 | primary base, recursively). */ |
| 1841 | |
| 1842 | int |
| 1843 | virtual_base_list_length_skip_primaries (dclass) |
| 1844 | struct type * dclass; |
| 1845 | { |
| 1846 | register int i; |
| 1847 | register struct vbase * tmp_vbase; |
| 1848 | struct type * primary; |
| 1849 | |
| 1850 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; |
| 1851 | |
| 1852 | if (!primary) |
| 1853 | return virtual_base_list_length (dclass); |
| 1854 | |
| 1855 | current_vbase_list = NULL; |
| 1856 | virtual_base_list_aux(dclass); |
| 1857 | |
| 1858 | for (i=0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next) |
| 1859 | { |
| 1860 | if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0) |
| 1861 | continue; |
| 1862 | i++; |
| 1863 | } |
| 1864 | return i; |
| 1865 | } |
| 1866 | |
| 1867 | |
| 1868 | /* Return the index (position) of type BASE, which is a virtual base |
| 1869 | class of DCLASS, in the latter's virtual base list. A return of -1 |
| 1870 | indicates "not found" or a problem. */ |
| 1871 | |
| 1872 | int |
| 1873 | virtual_base_index(base, dclass) |
| 1874 | struct type * base; |
| 1875 | struct type * dclass; |
| 1876 | { |
| 1877 | register struct type * vbase; |
| 1878 | register int i; |
| 1879 | |
| 1880 | if ((TYPE_CODE(dclass) != TYPE_CODE_CLASS) || |
| 1881 | (TYPE_CODE(base) != TYPE_CODE_CLASS)) |
| 1882 | return -1; |
| 1883 | |
| 1884 | i = 0; |
| 1885 | vbase = TYPE_VIRTUAL_BASE_LIST(dclass)[0]; |
| 1886 | while (vbase) |
| 1887 | { |
| 1888 | if (vbase == base) |
| 1889 | break; |
| 1890 | vbase = TYPE_VIRTUAL_BASE_LIST(dclass)[++i]; |
| 1891 | } |
| 1892 | |
| 1893 | return vbase ? i : -1; |
| 1894 | } |
| 1895 | |
| 1896 | |
| 1897 | |
| 1898 | /* Return the index (position) of type BASE, which is a virtual base |
| 1899 | class of DCLASS, in the latter's virtual base list. Skip over all |
| 1900 | bases that may appear in the virtual base list of the primary base |
| 1901 | class of DCLASS (recursively). A return of -1 indicates "not |
| 1902 | found" or a problem. */ |
| 1903 | |
| 1904 | int |
| 1905 | virtual_base_index_skip_primaries(base, dclass) |
| 1906 | struct type * base; |
| 1907 | struct type * dclass; |
| 1908 | { |
| 1909 | register struct type * vbase; |
| 1910 | register int i, j; |
| 1911 | struct type * primary; |
| 1912 | |
| 1913 | if ((TYPE_CODE(dclass) != TYPE_CODE_CLASS) || |
| 1914 | (TYPE_CODE(base) != TYPE_CODE_CLASS)) |
| 1915 | return -1; |
| 1916 | |
| 1917 | primary = TYPE_RUNTIME_PTR(dclass) ? TYPE_PRIMARY_BASE(dclass) : NULL; |
| 1918 | |
| 1919 | j = -1; |
| 1920 | i = 0; |
| 1921 | vbase = TYPE_VIRTUAL_BASE_LIST(dclass)[0]; |
| 1922 | while (vbase) |
| 1923 | { |
| 1924 | if (!primary || (virtual_base_index_skip_primaries(vbase, primary) < 0)) |
| 1925 | j++; |
| 1926 | if (vbase == base) |
| 1927 | break; |
| 1928 | vbase = TYPE_VIRTUAL_BASE_LIST(dclass)[++i]; |
| 1929 | } |
| 1930 | |
| 1931 | return vbase ? j : -1; |
| 1932 | } |
| 1933 | |
| 1934 | /* Return position of a derived class DCLASS in the list of |
| 1935 | * primary bases starting with the remotest ancestor. |
| 1936 | * Position returned is 0-based. */ |
| 1937 | |
| 1938 | int |
| 1939 | class_index_in_primary_list (dclass) |
| 1940 | struct type * dclass; |
| 1941 | { |
| 1942 | struct type * pbc; /* primary base class */ |
| 1943 | |
| 1944 | /* Simply recurse on primary base */ |
| 1945 | pbc = TYPE_PRIMARY_BASE (dclass); |
| 1946 | if (pbc) |
| 1947 | return 1 + class_index_in_primary_list (pbc); |
| 1948 | else |
| 1949 | return 0; |
| 1950 | } |
| 1951 | |
| 1952 | /* Return a count of the number of virtual functions a type has. |
| 1953 | * This includes all the virtual functions it inherits from its |
| 1954 | * base classes too. |
| 1955 | */ |
| 1956 | |
| 1957 | /* pai: FIXME This doesn't do the right thing: count redefined virtual |
| 1958 | * functions only once (latest redefinition) |
| 1959 | */ |
| 1960 | |
| 1961 | int |
| 1962 | count_virtual_fns (dclass) |
| 1963 | struct type * dclass; |
| 1964 | { |
| 1965 | int base; /* index for base classes */ |
| 1966 | int fn, oi; /* function and overloaded instance indices */ |
| 1967 | |
| 1968 | int vfuncs; /* count to return */ |
| 1969 | |
| 1970 | /* recurse on bases that can share virtual table */ |
| 1971 | struct type * pbc = primary_base_class (dclass); |
| 1972 | if (pbc) |
| 1973 | vfuncs = count_virtual_fns (pbc); |
| 1974 | |
| 1975 | for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++) |
| 1976 | for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++) |
| 1977 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi)) |
| 1978 | vfuncs++; |
| 1979 | |
| 1980 | return vfuncs; |
| 1981 | } |
| 1982 | |
| 1983 | \f |
| 1984 | |
| 1985 | /* Functions for overload resolution begin here */ |
| 1986 | |
| 1987 | /* Compare two badness vectors A and B and return the result. |
| 1988 | * 0 => A and B are identical |
| 1989 | * 1 => A and B are incomparable |
| 1990 | * 2 => A is better than B |
| 1991 | * 3 => A is worse than B */ |
| 1992 | |
| 1993 | int |
| 1994 | compare_badness (a, b) |
| 1995 | struct badness_vector * a; |
| 1996 | struct badness_vector * b; |
| 1997 | { |
| 1998 | int i; |
| 1999 | int tmp; |
| 2000 | short found_pos = 0; /* any positives in c? */ |
| 2001 | short found_neg = 0; /* any negatives in c? */ |
| 2002 | |
| 2003 | /* differing lengths => incomparable */ |
| 2004 | if (a->length != b->length) |
| 2005 | return 1; |
| 2006 | |
| 2007 | /* Subtract b from a */ |
| 2008 | for (i=0; i < a->length; i++) |
| 2009 | { |
| 2010 | tmp = a->rank[i] - b->rank[i]; |
| 2011 | if (tmp > 0) |
| 2012 | found_pos = 1; |
| 2013 | else if (tmp < 0) |
| 2014 | found_neg = 1; |
| 2015 | } |
| 2016 | |
| 2017 | if (found_pos) |
| 2018 | { |
| 2019 | if (found_neg) |
| 2020 | return 1; /* incomparable */ |
| 2021 | else |
| 2022 | return 3; /* A > B */ |
| 2023 | } |
| 2024 | else /* no positives */ |
| 2025 | { |
| 2026 | if (found_neg) |
| 2027 | return 2; /* A < B */ |
| 2028 | else |
| 2029 | return 0; /* A == B */ |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | /* Rank a function by comparing its parameter types (PARMS, length NPARMS), |
| 2034 | * to the types of an argument list (ARGS, length NARGS). |
| 2035 | * Return a pointer to a badness vector. This has NARGS + 1 entries. */ |
| 2036 | |
| 2037 | struct badness_vector * |
| 2038 | rank_function (parms, nparms, args, nargs) |
| 2039 | struct type ** parms; |
| 2040 | int nparms; |
| 2041 | struct type ** args; |
| 2042 | int nargs; |
| 2043 | { |
| 2044 | int i; |
| 2045 | struct badness_vector * bv; |
| 2046 | int min_len = nparms < nargs ? nparms : nargs; |
| 2047 | |
| 2048 | bv = xmalloc (sizeof (struct badness_vector)); |
| 2049 | bv->length = nargs + 1; /* add 1 for the length-match rank */ |
| 2050 | bv->rank = xmalloc ((nargs + 1) * sizeof (int)); |
| 2051 | |
| 2052 | /* First compare the lengths of the supplied lists. |
| 2053 | * If there is a mismatch, set it to a high value. */ |
| 2054 | |
| 2055 | /* pai/1997-06-03 FIXME: when we have debug info about default |
| 2056 | * arguments and ellipsis parameter lists, we should consider those |
| 2057 | * and rank the length-match more finely. */ |
| 2058 | |
| 2059 | LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0; |
| 2060 | |
| 2061 | /* Now rank all the parameters of the candidate function */ |
| 2062 | for (i=1; i <= min_len; i++) |
| 2063 | bv->rank[i] = rank_one_type (parms[i-1], args[i-1]); |
| 2064 | |
| 2065 | /* If more arguments than parameters, add dummy entries */ |
| 2066 | for (i = min_len +1; i <= nargs; i++) |
| 2067 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
| 2068 | |
| 2069 | return bv; |
| 2070 | } |
| 2071 | |
| 2072 | /* Compare one type (PARM) for compatibility with another (ARG). |
| 2073 | * PARM is intended to be the parameter type of a function; and |
| 2074 | * ARG is the supplied argument's type. This function tests if |
| 2075 | * the latter can be converted to the former. |
| 2076 | * |
| 2077 | * Return 0 if they are identical types; |
| 2078 | * Otherwise, return an integer which corresponds to how compatible |
| 2079 | * PARM is to ARG. The higher the return value, the worse the match. |
| 2080 | * Generally the "bad" conversions are all uniformly assigned a 100 */ |
| 2081 | |
| 2082 | int |
| 2083 | rank_one_type (parm, arg) |
| 2084 | struct type * parm; |
| 2085 | struct type * arg; |
| 2086 | { |
| 2087 | /* Identical type pointers */ |
| 2088 | /* However, this still doesn't catch all cases of same type for arg |
| 2089 | * and param. The reason is that builtin types are different from |
| 2090 | * the same ones constructed from the object. */ |
| 2091 | if (parm == arg) |
| 2092 | return 0; |
| 2093 | |
| 2094 | /* Resolve typedefs */ |
| 2095 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) |
| 2096 | parm = check_typedef (parm); |
| 2097 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) |
| 2098 | arg = check_typedef (arg); |
| 2099 | |
| 2100 | /* Check if identical after resolving typedefs */ |
| 2101 | if (parm == arg) |
| 2102 | return 0; |
| 2103 | |
| 2104 | #if 0 |
| 2105 | /* Debugging only */ |
| 2106 | printf("------ Arg is %s [%d], parm is %s [%d]\n", |
| 2107 | TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm)); |
| 2108 | #endif |
| 2109 | |
| 2110 | /* x -> y means arg of type x being supplied for parameter of type y */ |
| 2111 | |
| 2112 | switch (TYPE_CODE (parm)) |
| 2113 | { |
| 2114 | case TYPE_CODE_PTR: |
| 2115 | switch (TYPE_CODE (arg)) |
| 2116 | { |
| 2117 | case TYPE_CODE_PTR: |
| 2118 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) |
| 2119 | return VOID_PTR_CONVERSION_BADNESS; |
| 2120 | else |
| 2121 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); |
| 2122 | case TYPE_CODE_ARRAY: |
| 2123 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); |
| 2124 | case TYPE_CODE_FUNC: |
| 2125 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg); |
| 2126 | case TYPE_CODE_INT: |
| 2127 | case TYPE_CODE_ENUM: |
| 2128 | case TYPE_CODE_CHAR: |
| 2129 | case TYPE_CODE_RANGE: |
| 2130 | case TYPE_CODE_BOOL: |
| 2131 | return POINTER_CONVERSION_BADNESS; |
| 2132 | default: |
| 2133 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2134 | } |
| 2135 | case TYPE_CODE_ARRAY: |
| 2136 | switch (TYPE_CODE (arg)) |
| 2137 | { |
| 2138 | case TYPE_CODE_PTR: |
| 2139 | case TYPE_CODE_ARRAY: |
| 2140 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); |
| 2141 | default: |
| 2142 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2143 | } |
| 2144 | case TYPE_CODE_FUNC: |
| 2145 | switch (TYPE_CODE (arg)) |
| 2146 | { |
| 2147 | case TYPE_CODE_PTR: /* funcptr -> func */ |
| 2148 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg)); |
| 2149 | default: |
| 2150 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2151 | } |
| 2152 | case TYPE_CODE_INT: |
| 2153 | switch (TYPE_CODE (arg)) |
| 2154 | { |
| 2155 | case TYPE_CODE_INT: |
| 2156 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) |
| 2157 | { |
| 2158 | /* Deal with signed, unsigned, and plain chars and |
| 2159 | signed and unsigned ints */ |
| 2160 | if (TYPE_NOSIGN (parm)) |
| 2161 | { |
| 2162 | /* This case only for character types */ |
| 2163 | if (TYPE_NOSIGN (arg)) /* plain char -> plain char */ |
| 2164 | return 0; |
| 2165 | else |
| 2166 | return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */ |
| 2167 | } |
| 2168 | else if (TYPE_UNSIGNED (parm)) |
| 2169 | { |
| 2170 | if (TYPE_UNSIGNED (arg)) |
| 2171 | { |
| 2172 | if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) |
| 2173 | return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */ |
| 2174 | else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long")) |
| 2175 | return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */ |
| 2176 | else |
| 2177 | return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */ |
| 2178 | } |
| 2179 | else |
| 2180 | { |
| 2181 | if (!strcmp (TYPE_NAME (arg), "long") && !strcmp (TYPE_NAME (parm), "int")) |
| 2182 | return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */ |
| 2183 | else |
| 2184 | return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */ |
| 2185 | } |
| 2186 | } |
| 2187 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) |
| 2188 | { |
| 2189 | if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) |
| 2190 | return 0; |
| 2191 | else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long")) |
| 2192 | return INTEGER_PROMOTION_BADNESS; |
| 2193 | else |
| 2194 | return INTEGER_COERCION_BADNESS; |
| 2195 | } |
| 2196 | else |
| 2197 | return INTEGER_COERCION_BADNESS; |
| 2198 | } |
| 2199 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
| 2200 | return INTEGER_PROMOTION_BADNESS; |
| 2201 | else |
| 2202 | return INTEGER_COERCION_BADNESS; |
| 2203 | case TYPE_CODE_ENUM: |
| 2204 | case TYPE_CODE_CHAR: |
| 2205 | case TYPE_CODE_RANGE: |
| 2206 | case TYPE_CODE_BOOL: |
| 2207 | return INTEGER_PROMOTION_BADNESS; |
| 2208 | case TYPE_CODE_FLT: |
| 2209 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2210 | case TYPE_CODE_PTR: |
| 2211 | return NS_POINTER_CONVERSION_BADNESS; |
| 2212 | default: |
| 2213 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2214 | } |
| 2215 | break; |
| 2216 | case TYPE_CODE_ENUM: |
| 2217 | switch (TYPE_CODE (arg)) |
| 2218 | { |
| 2219 | case TYPE_CODE_INT: |
| 2220 | case TYPE_CODE_CHAR: |
| 2221 | case TYPE_CODE_RANGE: |
| 2222 | case TYPE_CODE_BOOL: |
| 2223 | case TYPE_CODE_ENUM: |
| 2224 | return INTEGER_COERCION_BADNESS; |
| 2225 | case TYPE_CODE_FLT: |
| 2226 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2227 | default: |
| 2228 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2229 | } |
| 2230 | break; |
| 2231 | case TYPE_CODE_CHAR: |
| 2232 | switch (TYPE_CODE (arg)) |
| 2233 | { |
| 2234 | case TYPE_CODE_RANGE: |
| 2235 | case TYPE_CODE_BOOL: |
| 2236 | case TYPE_CODE_ENUM: |
| 2237 | return INTEGER_COERCION_BADNESS; |
| 2238 | case TYPE_CODE_FLT: |
| 2239 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2240 | case TYPE_CODE_INT: |
| 2241 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) |
| 2242 | return INTEGER_COERCION_BADNESS; |
| 2243 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
| 2244 | return INTEGER_PROMOTION_BADNESS; |
| 2245 | /* >>> !! else fall through !! <<< */ |
| 2246 | case TYPE_CODE_CHAR: |
| 2247 | /* Deal with signed, unsigned, and plain chars for C++ |
| 2248 | and with int cases falling through from previous case */ |
| 2249 | if (TYPE_NOSIGN (parm)) |
| 2250 | { |
| 2251 | if (TYPE_NOSIGN (arg)) |
| 2252 | return 0; |
| 2253 | else |
| 2254 | return INTEGER_COERCION_BADNESS; |
| 2255 | } |
| 2256 | else if (TYPE_UNSIGNED (parm)) |
| 2257 | { |
| 2258 | if (TYPE_UNSIGNED (arg)) |
| 2259 | return 0; |
| 2260 | else |
| 2261 | return INTEGER_PROMOTION_BADNESS; |
| 2262 | } |
| 2263 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) |
| 2264 | return 0; |
| 2265 | else |
| 2266 | return INTEGER_COERCION_BADNESS; |
| 2267 | default: |
| 2268 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2269 | } |
| 2270 | break; |
| 2271 | case TYPE_CODE_RANGE: |
| 2272 | switch (TYPE_CODE (arg)) |
| 2273 | { |
| 2274 | case TYPE_CODE_INT: |
| 2275 | case TYPE_CODE_CHAR: |
| 2276 | case TYPE_CODE_RANGE: |
| 2277 | case TYPE_CODE_BOOL: |
| 2278 | case TYPE_CODE_ENUM: |
| 2279 | return INTEGER_COERCION_BADNESS; |
| 2280 | case TYPE_CODE_FLT: |
| 2281 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2282 | default: |
| 2283 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2284 | } |
| 2285 | break; |
| 2286 | case TYPE_CODE_BOOL: |
| 2287 | switch (TYPE_CODE (arg)) |
| 2288 | { |
| 2289 | case TYPE_CODE_INT: |
| 2290 | case TYPE_CODE_CHAR: |
| 2291 | case TYPE_CODE_RANGE: |
| 2292 | case TYPE_CODE_ENUM: |
| 2293 | case TYPE_CODE_FLT: |
| 2294 | case TYPE_CODE_PTR: |
| 2295 | return BOOLEAN_CONVERSION_BADNESS; |
| 2296 | case TYPE_CODE_BOOL: |
| 2297 | return 0; |
| 2298 | default: |
| 2299 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2300 | } |
| 2301 | break; |
| 2302 | case TYPE_CODE_FLT: |
| 2303 | switch (TYPE_CODE (arg)) |
| 2304 | { |
| 2305 | case TYPE_CODE_FLT: |
| 2306 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
| 2307 | return FLOAT_PROMOTION_BADNESS; |
| 2308 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) |
| 2309 | return 0; |
| 2310 | else |
| 2311 | return FLOAT_CONVERSION_BADNESS; |
| 2312 | case TYPE_CODE_INT: |
| 2313 | case TYPE_CODE_BOOL: |
| 2314 | case TYPE_CODE_ENUM: |
| 2315 | case TYPE_CODE_RANGE: |
| 2316 | case TYPE_CODE_CHAR: |
| 2317 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2318 | default: |
| 2319 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2320 | } |
| 2321 | break; |
| 2322 | case TYPE_CODE_COMPLEX: |
| 2323 | switch (TYPE_CODE (arg)) |
| 2324 | { /* Strictly not needed for C++, but... */ |
| 2325 | case TYPE_CODE_FLT: |
| 2326 | return FLOAT_PROMOTION_BADNESS; |
| 2327 | case TYPE_CODE_COMPLEX: |
| 2328 | return 0; |
| 2329 | default: |
| 2330 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2331 | } |
| 2332 | break; |
| 2333 | case TYPE_CODE_STRUCT: |
| 2334 | /* currently same as TYPE_CODE_CLASS */ |
| 2335 | switch (TYPE_CODE (arg)) |
| 2336 | { |
| 2337 | case TYPE_CODE_STRUCT: |
| 2338 | /* Check for derivation */ |
| 2339 | if (is_ancestor (parm, arg)) |
| 2340 | return BASE_CONVERSION_BADNESS; |
| 2341 | /* else fall through */ |
| 2342 | default: |
| 2343 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2344 | } |
| 2345 | break; |
| 2346 | case TYPE_CODE_UNION: |
| 2347 | switch (TYPE_CODE (arg)) |
| 2348 | { |
| 2349 | case TYPE_CODE_UNION: |
| 2350 | default: |
| 2351 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2352 | } |
| 2353 | break; |
| 2354 | case TYPE_CODE_MEMBER: |
| 2355 | switch (TYPE_CODE (arg)) |
| 2356 | { |
| 2357 | default: |
| 2358 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2359 | } |
| 2360 | break; |
| 2361 | case TYPE_CODE_METHOD: |
| 2362 | switch (TYPE_CODE (arg)) |
| 2363 | { |
| 2364 | |
| 2365 | default: |
| 2366 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2367 | } |
| 2368 | break; |
| 2369 | case TYPE_CODE_REF: |
| 2370 | switch (TYPE_CODE (arg)) |
| 2371 | { |
| 2372 | |
| 2373 | default: |
| 2374 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2375 | } |
| 2376 | |
| 2377 | break; |
| 2378 | case TYPE_CODE_SET: |
| 2379 | switch (TYPE_CODE (arg)) |
| 2380 | { |
| 2381 | /* Not in C++ */ |
| 2382 | case TYPE_CODE_SET: |
| 2383 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0)); |
| 2384 | default: |
| 2385 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2386 | } |
| 2387 | break; |
| 2388 | case TYPE_CODE_VOID: |
| 2389 | default: |
| 2390 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2391 | } /* switch (TYPE_CODE (arg)) */ |
| 2392 | } |
| 2393 | |
| 2394 | |
| 2395 | /* End of functions for overload resolution */ |
| 2396 | |
| 2397 | |
| 2398 | |
| 2399 | #if MAINTENANCE_CMDS |
| 2400 | |
| 2401 | static void |
| 2402 | print_bit_vector (bits, nbits) |
| 2403 | B_TYPE *bits; |
| 2404 | int nbits; |
| 2405 | { |
| 2406 | int bitno; |
| 2407 | |
| 2408 | for (bitno = 0; bitno < nbits; bitno++) |
| 2409 | { |
| 2410 | if ((bitno % 8) == 0) |
| 2411 | { |
| 2412 | puts_filtered (" "); |
| 2413 | } |
| 2414 | if (B_TST (bits, bitno)) |
| 2415 | { |
| 2416 | printf_filtered ("1"); |
| 2417 | } |
| 2418 | else |
| 2419 | { |
| 2420 | printf_filtered ("0"); |
| 2421 | } |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | /* The args list is a strange beast. It is either terminated by a NULL |
| 2426 | pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID |
| 2427 | type for normal fixed argcount functions. (FIXME someday) |
| 2428 | Also note the first arg should be the "this" pointer, we may not want to |
| 2429 | include it since we may get into a infinitely recursive situation. */ |
| 2430 | |
| 2431 | static void |
| 2432 | print_arg_types (args, spaces) |
| 2433 | struct type **args; |
| 2434 | int spaces; |
| 2435 | { |
| 2436 | if (args != NULL) |
| 2437 | { |
| 2438 | while (*args != NULL) |
| 2439 | { |
| 2440 | recursive_dump_type (*args, spaces + 2); |
| 2441 | if ((*args++) -> code == TYPE_CODE_VOID) |
| 2442 | { |
| 2443 | break; |
| 2444 | } |
| 2445 | } |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | static void |
| 2450 | dump_fn_fieldlists (type, spaces) |
| 2451 | struct type *type; |
| 2452 | int spaces; |
| 2453 | { |
| 2454 | int method_idx; |
| 2455 | int overload_idx; |
| 2456 | struct fn_field *f; |
| 2457 | |
| 2458 | printfi_filtered (spaces, "fn_fieldlists "); |
| 2459 | gdb_print_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
| 2460 | printf_filtered ("\n"); |
| 2461 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) |
| 2462 | { |
| 2463 | f = TYPE_FN_FIELDLIST1 (type, method_idx); |
| 2464 | printfi_filtered (spaces + 2, "[%d] name '%s' (", |
| 2465 | method_idx, |
| 2466 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); |
| 2467 | gdb_print_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
| 2468 | gdb_stdout); |
| 2469 | printf_filtered (") length %d\n", |
| 2470 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); |
| 2471 | for (overload_idx = 0; |
| 2472 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); |
| 2473 | overload_idx++) |
| 2474 | { |
| 2475 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", |
| 2476 | overload_idx, |
| 2477 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); |
| 2478 | gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
| 2479 | gdb_stdout); |
| 2480 | printf_filtered (")\n"); |
| 2481 | printfi_filtered (spaces + 8, "type "); |
| 2482 | gdb_print_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout); |
| 2483 | printf_filtered ("\n"); |
| 2484 | |
| 2485 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), |
| 2486 | spaces + 8 + 2); |
| 2487 | |
| 2488 | printfi_filtered (spaces + 8, "args "); |
| 2489 | gdb_print_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout); |
| 2490 | printf_filtered ("\n"); |
| 2491 | |
| 2492 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces); |
| 2493 | printfi_filtered (spaces + 8, "fcontext "); |
| 2494 | gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
| 2495 | gdb_stdout); |
| 2496 | printf_filtered ("\n"); |
| 2497 | |
| 2498 | printfi_filtered (spaces + 8, "is_const %d\n", |
| 2499 | TYPE_FN_FIELD_CONST (f, overload_idx)); |
| 2500 | printfi_filtered (spaces + 8, "is_volatile %d\n", |
| 2501 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); |
| 2502 | printfi_filtered (spaces + 8, "is_private %d\n", |
| 2503 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); |
| 2504 | printfi_filtered (spaces + 8, "is_protected %d\n", |
| 2505 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); |
| 2506 | printfi_filtered (spaces + 8, "is_stub %d\n", |
| 2507 | TYPE_FN_FIELD_STUB (f, overload_idx)); |
| 2508 | printfi_filtered (spaces + 8, "voffset %u\n", |
| 2509 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); |
| 2510 | } |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | static void |
| 2515 | print_cplus_stuff (type, spaces) |
| 2516 | struct type *type; |
| 2517 | int spaces; |
| 2518 | { |
| 2519 | printfi_filtered (spaces, "n_baseclasses %d\n", |
| 2520 | TYPE_N_BASECLASSES (type)); |
| 2521 | printfi_filtered (spaces, "nfn_fields %d\n", |
| 2522 | TYPE_NFN_FIELDS (type)); |
| 2523 | printfi_filtered (spaces, "nfn_fields_total %d\n", |
| 2524 | TYPE_NFN_FIELDS_TOTAL (type)); |
| 2525 | if (TYPE_N_BASECLASSES (type) > 0) |
| 2526 | { |
| 2527 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", |
| 2528 | TYPE_N_BASECLASSES (type)); |
| 2529 | gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout); |
| 2530 | printf_filtered (")"); |
| 2531 | |
| 2532 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), |
| 2533 | TYPE_N_BASECLASSES (type)); |
| 2534 | puts_filtered ("\n"); |
| 2535 | } |
| 2536 | if (TYPE_NFIELDS (type) > 0) |
| 2537 | { |
| 2538 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) |
| 2539 | { |
| 2540 | printfi_filtered (spaces, "private_field_bits (%d bits at *", |
| 2541 | TYPE_NFIELDS (type)); |
| 2542 | gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout); |
| 2543 | printf_filtered (")"); |
| 2544 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), |
| 2545 | TYPE_NFIELDS (type)); |
| 2546 | puts_filtered ("\n"); |
| 2547 | } |
| 2548 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) |
| 2549 | { |
| 2550 | printfi_filtered (spaces, "protected_field_bits (%d bits at *", |
| 2551 | TYPE_NFIELDS (type)); |
| 2552 | gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout); |
| 2553 | printf_filtered (")"); |
| 2554 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), |
| 2555 | TYPE_NFIELDS (type)); |
| 2556 | puts_filtered ("\n"); |
| 2557 | } |
| 2558 | } |
| 2559 | if (TYPE_NFN_FIELDS (type) > 0) |
| 2560 | { |
| 2561 | dump_fn_fieldlists (type, spaces); |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | static struct obstack dont_print_type_obstack; |
| 2566 | |
| 2567 | void |
| 2568 | recursive_dump_type (type, spaces) |
| 2569 | struct type *type; |
| 2570 | int spaces; |
| 2571 | { |
| 2572 | int idx; |
| 2573 | |
| 2574 | if (spaces == 0) |
| 2575 | obstack_begin (&dont_print_type_obstack, 0); |
| 2576 | |
| 2577 | if (TYPE_NFIELDS (type) > 0 |
| 2578 | || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0)) |
| 2579 | { |
| 2580 | struct type **first_dont_print |
| 2581 | = (struct type **)obstack_base (&dont_print_type_obstack); |
| 2582 | |
| 2583 | int i = (struct type **)obstack_next_free (&dont_print_type_obstack) |
| 2584 | - first_dont_print; |
| 2585 | |
| 2586 | while (--i >= 0) |
| 2587 | { |
| 2588 | if (type == first_dont_print[i]) |
| 2589 | { |
| 2590 | printfi_filtered (spaces, "type node "); |
| 2591 | gdb_print_address (type, gdb_stdout); |
| 2592 | printf_filtered (" <same as already seen type>\n"); |
| 2593 | return; |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | obstack_ptr_grow (&dont_print_type_obstack, type); |
| 2598 | } |
| 2599 | |
| 2600 | printfi_filtered (spaces, "type node "); |
| 2601 | gdb_print_address (type, gdb_stdout); |
| 2602 | printf_filtered ("\n"); |
| 2603 | printfi_filtered (spaces, "name '%s' (", |
| 2604 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); |
| 2605 | gdb_print_address (TYPE_NAME (type), gdb_stdout); |
| 2606 | printf_filtered (")\n"); |
| 2607 | if (TYPE_TAG_NAME (type) != NULL) |
| 2608 | { |
| 2609 | printfi_filtered (spaces, "tagname '%s' (", |
| 2610 | TYPE_TAG_NAME (type)); |
| 2611 | gdb_print_address (TYPE_TAG_NAME (type), gdb_stdout); |
| 2612 | printf_filtered (")\n"); |
| 2613 | } |
| 2614 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); |
| 2615 | switch (TYPE_CODE (type)) |
| 2616 | { |
| 2617 | case TYPE_CODE_UNDEF: |
| 2618 | printf_filtered ("(TYPE_CODE_UNDEF)"); |
| 2619 | break; |
| 2620 | case TYPE_CODE_PTR: |
| 2621 | printf_filtered ("(TYPE_CODE_PTR)"); |
| 2622 | break; |
| 2623 | case TYPE_CODE_ARRAY: |
| 2624 | printf_filtered ("(TYPE_CODE_ARRAY)"); |
| 2625 | break; |
| 2626 | case TYPE_CODE_STRUCT: |
| 2627 | printf_filtered ("(TYPE_CODE_STRUCT)"); |
| 2628 | break; |
| 2629 | case TYPE_CODE_UNION: |
| 2630 | printf_filtered ("(TYPE_CODE_UNION)"); |
| 2631 | break; |
| 2632 | case TYPE_CODE_ENUM: |
| 2633 | printf_filtered ("(TYPE_CODE_ENUM)"); |
| 2634 | break; |
| 2635 | case TYPE_CODE_FUNC: |
| 2636 | printf_filtered ("(TYPE_CODE_FUNC)"); |
| 2637 | break; |
| 2638 | case TYPE_CODE_INT: |
| 2639 | printf_filtered ("(TYPE_CODE_INT)"); |
| 2640 | break; |
| 2641 | case TYPE_CODE_FLT: |
| 2642 | printf_filtered ("(TYPE_CODE_FLT)"); |
| 2643 | break; |
| 2644 | case TYPE_CODE_VOID: |
| 2645 | printf_filtered ("(TYPE_CODE_VOID)"); |
| 2646 | break; |
| 2647 | case TYPE_CODE_SET: |
| 2648 | printf_filtered ("(TYPE_CODE_SET)"); |
| 2649 | break; |
| 2650 | case TYPE_CODE_RANGE: |
| 2651 | printf_filtered ("(TYPE_CODE_RANGE)"); |
| 2652 | break; |
| 2653 | case TYPE_CODE_STRING: |
| 2654 | printf_filtered ("(TYPE_CODE_STRING)"); |
| 2655 | break; |
| 2656 | case TYPE_CODE_ERROR: |
| 2657 | printf_filtered ("(TYPE_CODE_ERROR)"); |
| 2658 | break; |
| 2659 | case TYPE_CODE_MEMBER: |
| 2660 | printf_filtered ("(TYPE_CODE_MEMBER)"); |
| 2661 | break; |
| 2662 | case TYPE_CODE_METHOD: |
| 2663 | printf_filtered ("(TYPE_CODE_METHOD)"); |
| 2664 | break; |
| 2665 | case TYPE_CODE_REF: |
| 2666 | printf_filtered ("(TYPE_CODE_REF)"); |
| 2667 | break; |
| 2668 | case TYPE_CODE_CHAR: |
| 2669 | printf_filtered ("(TYPE_CODE_CHAR)"); |
| 2670 | break; |
| 2671 | case TYPE_CODE_BOOL: |
| 2672 | printf_filtered ("(TYPE_CODE_BOOL)"); |
| 2673 | break; |
| 2674 | case TYPE_CODE_TYPEDEF: |
| 2675 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); |
| 2676 | break; |
| 2677 | default: |
| 2678 | printf_filtered ("(UNKNOWN TYPE CODE)"); |
| 2679 | break; |
| 2680 | } |
| 2681 | puts_filtered ("\n"); |
| 2682 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); |
| 2683 | printfi_filtered (spaces, "objfile "); |
| 2684 | gdb_print_address (TYPE_OBJFILE (type), gdb_stdout); |
| 2685 | printf_filtered ("\n"); |
| 2686 | printfi_filtered (spaces, "target_type "); |
| 2687 | gdb_print_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
| 2688 | printf_filtered ("\n"); |
| 2689 | if (TYPE_TARGET_TYPE (type) != NULL) |
| 2690 | { |
| 2691 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); |
| 2692 | } |
| 2693 | printfi_filtered (spaces, "pointer_type "); |
| 2694 | gdb_print_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
| 2695 | printf_filtered ("\n"); |
| 2696 | printfi_filtered (spaces, "reference_type "); |
| 2697 | gdb_print_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
| 2698 | printf_filtered ("\n"); |
| 2699 | printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type)); |
| 2700 | if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED) |
| 2701 | { |
| 2702 | puts_filtered (" TYPE_FLAG_UNSIGNED"); |
| 2703 | } |
| 2704 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) |
| 2705 | { |
| 2706 | puts_filtered (" TYPE_FLAG_STUB"); |
| 2707 | } |
| 2708 | puts_filtered ("\n"); |
| 2709 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); |
| 2710 | gdb_print_address (TYPE_FIELDS (type), gdb_stdout); |
| 2711 | puts_filtered ("\n"); |
| 2712 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) |
| 2713 | { |
| 2714 | printfi_filtered (spaces + 2, |
| 2715 | "[%d] bitpos %d bitsize %d type ", |
| 2716 | idx, TYPE_FIELD_BITPOS (type, idx), |
| 2717 | TYPE_FIELD_BITSIZE (type, idx)); |
| 2718 | gdb_print_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
| 2719 | printf_filtered (" name '%s' (", |
| 2720 | TYPE_FIELD_NAME (type, idx) != NULL |
| 2721 | ? TYPE_FIELD_NAME (type, idx) |
| 2722 | : "<NULL>"); |
| 2723 | gdb_print_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
| 2724 | printf_filtered (")\n"); |
| 2725 | if (TYPE_FIELD_TYPE (type, idx) != NULL) |
| 2726 | { |
| 2727 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); |
| 2728 | } |
| 2729 | } |
| 2730 | printfi_filtered (spaces, "vptr_basetype "); |
| 2731 | gdb_print_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); |
| 2732 | puts_filtered ("\n"); |
| 2733 | if (TYPE_VPTR_BASETYPE (type) != NULL) |
| 2734 | { |
| 2735 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); |
| 2736 | } |
| 2737 | printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type)); |
| 2738 | switch (TYPE_CODE (type)) |
| 2739 | { |
| 2740 | case TYPE_CODE_METHOD: |
| 2741 | case TYPE_CODE_FUNC: |
| 2742 | printfi_filtered (spaces, "arg_types "); |
| 2743 | gdb_print_address (TYPE_ARG_TYPES (type), gdb_stdout); |
| 2744 | puts_filtered ("\n"); |
| 2745 | print_arg_types (TYPE_ARG_TYPES (type), spaces); |
| 2746 | break; |
| 2747 | |
| 2748 | case TYPE_CODE_STRUCT: |
| 2749 | printfi_filtered (spaces, "cplus_stuff "); |
| 2750 | gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
| 2751 | puts_filtered ("\n"); |
| 2752 | print_cplus_stuff (type, spaces); |
| 2753 | break; |
| 2754 | |
| 2755 | default: |
| 2756 | /* We have to pick one of the union types to be able print and test |
| 2757 | the value. Pick cplus_struct_type, even though we know it isn't |
| 2758 | any particular one. */ |
| 2759 | printfi_filtered (spaces, "type_specific "); |
| 2760 | gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
| 2761 | if (TYPE_CPLUS_SPECIFIC (type) != NULL) |
| 2762 | { |
| 2763 | printf_filtered (" (unknown data form)"); |
| 2764 | } |
| 2765 | printf_filtered ("\n"); |
| 2766 | break; |
| 2767 | |
| 2768 | } |
| 2769 | if (spaces == 0) |
| 2770 | obstack_free (&dont_print_type_obstack, NULL); |
| 2771 | } |
| 2772 | |
| 2773 | #endif /* MAINTENANCE_CMDS */ |
| 2774 | |
| 2775 | |
| 2776 | static void build_gdbtypes PARAMS ((void)); |
| 2777 | static void |
| 2778 | build_gdbtypes () |
| 2779 | { |
| 2780 | builtin_type_void = |
| 2781 | init_type (TYPE_CODE_VOID, 1, |
| 2782 | 0, |
| 2783 | "void", (struct objfile *) NULL); |
| 2784 | builtin_type_char = |
| 2785 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 2786 | 0, |
| 2787 | "char", (struct objfile *) NULL); |
| 2788 | TYPE_FLAGS (builtin_type_char) |= TYPE_FLAG_NOSIGN; |
| 2789 | |
| 2790 | builtin_type_signed_char = |
| 2791 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 2792 | 0, |
| 2793 | "signed char", (struct objfile *) NULL); |
| 2794 | builtin_type_unsigned_char = |
| 2795 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 2796 | TYPE_FLAG_UNSIGNED, |
| 2797 | "unsigned char", (struct objfile *) NULL); |
| 2798 | builtin_type_short = |
| 2799 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 2800 | 0, |
| 2801 | "short", (struct objfile *) NULL); |
| 2802 | builtin_type_unsigned_short = |
| 2803 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 2804 | TYPE_FLAG_UNSIGNED, |
| 2805 | "unsigned short", (struct objfile *) NULL); |
| 2806 | builtin_type_int = |
| 2807 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 2808 | 0, |
| 2809 | "int", (struct objfile *) NULL); |
| 2810 | builtin_type_unsigned_int = |
| 2811 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 2812 | TYPE_FLAG_UNSIGNED, |
| 2813 | "unsigned int", (struct objfile *) NULL); |
| 2814 | builtin_type_long = |
| 2815 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 2816 | 0, |
| 2817 | "long", (struct objfile *) NULL); |
| 2818 | builtin_type_unsigned_long = |
| 2819 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 2820 | TYPE_FLAG_UNSIGNED, |
| 2821 | "unsigned long", (struct objfile *) NULL); |
| 2822 | builtin_type_long_long = |
| 2823 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
| 2824 | 0, |
| 2825 | "long long", (struct objfile *) NULL); |
| 2826 | builtin_type_unsigned_long_long = |
| 2827 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
| 2828 | TYPE_FLAG_UNSIGNED, |
| 2829 | "unsigned long long", (struct objfile *) NULL); |
| 2830 | builtin_type_float = |
| 2831 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
| 2832 | 0, |
| 2833 | "float", (struct objfile *) NULL); |
| 2834 | builtin_type_double = |
| 2835 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 2836 | 0, |
| 2837 | "double", (struct objfile *) NULL); |
| 2838 | builtin_type_long_double = |
| 2839 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 2840 | 0, |
| 2841 | "long double", (struct objfile *) NULL); |
| 2842 | builtin_type_complex = |
| 2843 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
| 2844 | 0, |
| 2845 | "complex", (struct objfile *) NULL); |
| 2846 | TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float; |
| 2847 | builtin_type_double_complex = |
| 2848 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 2849 | 0, |
| 2850 | "double complex", (struct objfile *) NULL); |
| 2851 | TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double; |
| 2852 | builtin_type_string = |
| 2853 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 2854 | 0, |
| 2855 | "string", (struct objfile *) NULL); |
| 2856 | builtin_type_int8 = |
| 2857 | init_type (TYPE_CODE_INT, 8 / 8, |
| 2858 | 0, |
| 2859 | "int8_t", (struct objfile *) NULL); |
| 2860 | builtin_type_uint8 = |
| 2861 | init_type (TYPE_CODE_INT, 8 / 8, |
| 2862 | TYPE_FLAG_UNSIGNED, |
| 2863 | "uint8_t", (struct objfile *) NULL); |
| 2864 | builtin_type_int16 = |
| 2865 | init_type (TYPE_CODE_INT, 16 / 8, |
| 2866 | 0, |
| 2867 | "int16_t", (struct objfile *) NULL); |
| 2868 | builtin_type_uint16 = |
| 2869 | init_type (TYPE_CODE_INT, 16 / 8, |
| 2870 | TYPE_FLAG_UNSIGNED, |
| 2871 | "uint16_t", (struct objfile *) NULL); |
| 2872 | builtin_type_int32 = |
| 2873 | init_type (TYPE_CODE_INT, 32 / 8, |
| 2874 | 0, |
| 2875 | "int32_t", (struct objfile *) NULL); |
| 2876 | builtin_type_uint32 = |
| 2877 | init_type (TYPE_CODE_INT, 32 / 8, |
| 2878 | TYPE_FLAG_UNSIGNED, |
| 2879 | "uint32_t", (struct objfile *) NULL); |
| 2880 | builtin_type_int64 = |
| 2881 | init_type (TYPE_CODE_INT, 64 / 8, |
| 2882 | 0, |
| 2883 | "int64_t", (struct objfile *) NULL); |
| 2884 | builtin_type_uint64 = |
| 2885 | init_type (TYPE_CODE_INT, 64 / 8, |
| 2886 | TYPE_FLAG_UNSIGNED, |
| 2887 | "uint64_t", (struct objfile *) NULL); |
| 2888 | builtin_type_bool = |
| 2889 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 2890 | 0, |
| 2891 | "bool", (struct objfile *) NULL); |
| 2892 | |
| 2893 | /* Add user knob for controlling resolution of opaque types */ |
| 2894 | add_show_from_set |
| 2895 | (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *)&opaque_type_resolution, |
| 2896 | "Set resolution of opaque struct/class/union types (if set before loading symbols).", |
| 2897 | &setlist), |
| 2898 | &showlist); |
| 2899 | opaque_type_resolution = 1; |
| 2900 | |
| 2901 | /* start-sanitize-r5900 */ |
| 2902 | builtin_type_int128 = |
| 2903 | init_type (TYPE_CODE_INT, 128 / 8, |
| 2904 | 0, |
| 2905 | "int128_t", (struct objfile *) NULL); |
| 2906 | builtin_type_uint128 = |
| 2907 | init_type (TYPE_CODE_INT, 128 / 8, |
| 2908 | TYPE_FLAG_UNSIGNED, |
| 2909 | "uint128_t", (struct objfile *) NULL); |
| 2910 | /* end-sanitize-r5900 */ |
| 2911 | } |
| 2912 | |
| 2913 | |
| 2914 | extern void _initialize_gdbtypes PARAMS ((void)); |
| 2915 | void |
| 2916 | _initialize_gdbtypes () |
| 2917 | { |
| 2918 | build_gdbtypes (); |
| 2919 | /* start-sanitize-carp start-sanitize-vr4xxx */ |
| 2920 | /* FIXME - For the moment, handle types by swapping them in and out. |
| 2921 | Should be using the per-architecture data-pointer and a large |
| 2922 | struct. */ |
| 2923 | register_gdbarch_swap (&builtin_type_void, sizeof (struct type*), NULL); |
| 2924 | register_gdbarch_swap (&builtin_type_char, sizeof (struct type*), NULL); |
| 2925 | register_gdbarch_swap (&builtin_type_short, sizeof (struct type*), NULL); |
| 2926 | register_gdbarch_swap (&builtin_type_int, sizeof (struct type*), NULL); |
| 2927 | register_gdbarch_swap (&builtin_type_long, sizeof (struct type*), NULL); |
| 2928 | register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type*), NULL); |
| 2929 | register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type*), NULL); |
| 2930 | register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type*), NULL); |
| 2931 | register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type*), NULL); |
| 2932 | register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type*), NULL); |
| 2933 | register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type*), NULL); |
| 2934 | register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type*), NULL); |
| 2935 | register_gdbarch_swap (&builtin_type_float, sizeof (struct type*), NULL); |
| 2936 | register_gdbarch_swap (&builtin_type_double, sizeof (struct type*), NULL); |
| 2937 | register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type*), NULL); |
| 2938 | register_gdbarch_swap (&builtin_type_complex, sizeof (struct type*), NULL); |
| 2939 | register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type*), NULL); |
| 2940 | register_gdbarch_swap (&builtin_type_string, sizeof (struct type*), NULL); |
| 2941 | register_gdbarch_swap (&builtin_type_int8, sizeof (struct type*), NULL); |
| 2942 | register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type*), NULL); |
| 2943 | register_gdbarch_swap (&builtin_type_int16, sizeof (struct type*), NULL); |
| 2944 | register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type*), NULL); |
| 2945 | register_gdbarch_swap (&builtin_type_int32, sizeof (struct type*), NULL); |
| 2946 | register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type*), NULL); |
| 2947 | register_gdbarch_swap (&builtin_type_int64, sizeof (struct type*), NULL); |
| 2948 | register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type*), NULL); |
| 2949 | /* start-sanitize-r5900 */ |
| 2950 | register_gdbarch_swap (&builtin_type_int128, sizeof (struct type*), NULL); |
| 2951 | register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type*), NULL); |
| 2952 | /* end-sanitize-r5900 */ |
| 2953 | register_gdbarch_swap (NULL, 0, build_gdbtypes); |
| 2954 | /* end-sanitize-carp end-sanitize-vr4xxx */ |
| 2955 | } |