Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support routines for manipulating internal types for GDB. |
4f2aea11 | 2 | |
7ba81444 MS |
3 | Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, |
4 | 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. | |
4f2aea11 | 5 | |
c906108c SS |
6 | Contributed by Cygnus Support, using pieces from other GDB modules. |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b JM |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | Boston, MA 02110-1301, USA. */ | |
c906108c SS |
24 | |
25 | #include "defs.h" | |
26 | #include "gdb_string.h" | |
27 | #include "bfd.h" | |
28 | #include "symtab.h" | |
29 | #include "symfile.h" | |
30 | #include "objfiles.h" | |
31 | #include "gdbtypes.h" | |
32 | #include "expression.h" | |
33 | #include "language.h" | |
34 | #include "target.h" | |
35 | #include "value.h" | |
36 | #include "demangle.h" | |
37 | #include "complaints.h" | |
38 | #include "gdbcmd.h" | |
c91ecb25 | 39 | #include "wrapper.h" |
015a42b4 | 40 | #include "cp-abi.h" |
a02fd225 | 41 | #include "gdb_assert.h" |
ae5a43e0 | 42 | #include "hashtab.h" |
c906108c SS |
43 | |
44 | /* These variables point to the objects | |
45 | representing the predefined C data types. */ | |
46 | ||
449a5da4 | 47 | struct type *builtin_type_int0; |
c906108c SS |
48 | struct type *builtin_type_int8; |
49 | struct type *builtin_type_uint8; | |
50 | struct type *builtin_type_int16; | |
51 | struct type *builtin_type_uint16; | |
52 | struct type *builtin_type_int32; | |
53 | struct type *builtin_type_uint32; | |
54 | struct type *builtin_type_int64; | |
55 | struct type *builtin_type_uint64; | |
8b982acf EZ |
56 | struct type *builtin_type_int128; |
57 | struct type *builtin_type_uint128; | |
ac3aafc7 | 58 | |
8da61cc4 DJ |
59 | /* Floatformat pairs. */ |
60 | const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = { | |
61 | &floatformat_ieee_single_big, | |
62 | &floatformat_ieee_single_little | |
63 | }; | |
64 | const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = { | |
65 | &floatformat_ieee_double_big, | |
66 | &floatformat_ieee_double_little | |
67 | }; | |
68 | const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = { | |
69 | &floatformat_ieee_double_big, | |
70 | &floatformat_ieee_double_littlebyte_bigword | |
71 | }; | |
72 | const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = { | |
73 | &floatformat_i387_ext, | |
74 | &floatformat_i387_ext | |
75 | }; | |
76 | const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = { | |
77 | &floatformat_m68881_ext, | |
78 | &floatformat_m68881_ext | |
79 | }; | |
80 | const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = { | |
81 | &floatformat_arm_ext_big, | |
82 | &floatformat_arm_ext_littlebyte_bigword | |
83 | }; | |
84 | const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = { | |
85 | &floatformat_ia64_spill_big, | |
86 | &floatformat_ia64_spill_little | |
87 | }; | |
88 | const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = { | |
89 | &floatformat_ia64_quad_big, | |
90 | &floatformat_ia64_quad_little | |
91 | }; | |
92 | const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = { | |
93 | &floatformat_vax_f, | |
94 | &floatformat_vax_f | |
95 | }; | |
96 | const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = { | |
97 | &floatformat_vax_d, | |
98 | &floatformat_vax_d | |
99 | }; | |
100 | ||
101 | struct type *builtin_type_ieee_single; | |
102 | struct type *builtin_type_ieee_double; | |
598f52df AC |
103 | struct type *builtin_type_i387_ext; |
104 | struct type *builtin_type_m68881_ext; | |
8da61cc4 DJ |
105 | struct type *builtin_type_arm_ext; |
106 | struct type *builtin_type_ia64_spill; | |
107 | struct type *builtin_type_ia64_quad; | |
108 | ||
c906108c SS |
109 | |
110 | int opaque_type_resolution = 1; | |
920d2a44 AC |
111 | static void |
112 | show_opaque_type_resolution (struct ui_file *file, int from_tty, | |
7ba81444 MS |
113 | struct cmd_list_element *c, |
114 | const char *value) | |
920d2a44 AC |
115 | { |
116 | fprintf_filtered (file, _("\ | |
117 | Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"), | |
118 | value); | |
119 | } | |
120 | ||
5d161b24 | 121 | int overload_debug = 0; |
920d2a44 AC |
122 | static void |
123 | show_overload_debug (struct ui_file *file, int from_tty, | |
124 | struct cmd_list_element *c, const char *value) | |
125 | { | |
7ba81444 MS |
126 | fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"), |
127 | value); | |
920d2a44 | 128 | } |
c906108c | 129 | |
c5aa993b JM |
130 | struct extra |
131 | { | |
132 | char str[128]; | |
133 | int len; | |
7ba81444 | 134 | }; /* Maximum extension is 128! FIXME */ |
c906108c | 135 | |
a14ed312 | 136 | static void print_bit_vector (B_TYPE *, int); |
ad2f7632 | 137 | static void print_arg_types (struct field *, int, int); |
a14ed312 KB |
138 | static void dump_fn_fieldlists (struct type *, int); |
139 | static void print_cplus_stuff (struct type *, int); | |
140 | static void virtual_base_list_aux (struct type *dclass); | |
7a292a7a | 141 | |
c906108c SS |
142 | |
143 | /* Alloc a new type structure and fill it with some defaults. If | |
144 | OBJFILE is non-NULL, then allocate the space for the type structure | |
7ba81444 MS |
145 | in that objfile's objfile_obstack. Otherwise allocate the new type |
146 | structure by xmalloc () (for permanent types). */ | |
c906108c SS |
147 | |
148 | struct type * | |
fba45db2 | 149 | alloc_type (struct objfile *objfile) |
c906108c | 150 | { |
52f0bd74 | 151 | struct type *type; |
c906108c | 152 | |
7ba81444 | 153 | /* Alloc the structure and start off with all fields zeroed. */ |
c906108c SS |
154 | |
155 | if (objfile == NULL) | |
156 | { | |
2fdde8f8 DJ |
157 | type = xmalloc (sizeof (struct type)); |
158 | memset (type, 0, sizeof (struct type)); | |
159 | TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type)); | |
c906108c SS |
160 | } |
161 | else | |
162 | { | |
b99607ea | 163 | type = obstack_alloc (&objfile->objfile_obstack, |
2fdde8f8 DJ |
164 | sizeof (struct type)); |
165 | memset (type, 0, sizeof (struct type)); | |
b99607ea | 166 | TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack, |
2fdde8f8 | 167 | sizeof (struct main_type)); |
c906108c SS |
168 | OBJSTAT (objfile, n_types++); |
169 | } | |
2fdde8f8 | 170 | memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); |
c906108c | 171 | |
7ba81444 | 172 | /* Initialize the fields that might not be zero. */ |
c906108c SS |
173 | |
174 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
175 | TYPE_OBJFILE (type) = objfile; | |
176 | TYPE_VPTR_FIELDNO (type) = -1; | |
2fdde8f8 | 177 | TYPE_CHAIN (type) = type; /* Chain back to itself. */ |
c906108c SS |
178 | |
179 | return (type); | |
180 | } | |
181 | ||
2fdde8f8 DJ |
182 | /* Alloc a new type instance structure, fill it with some defaults, |
183 | and point it at OLDTYPE. Allocate the new type instance from the | |
184 | same place as OLDTYPE. */ | |
185 | ||
186 | static struct type * | |
187 | alloc_type_instance (struct type *oldtype) | |
188 | { | |
189 | struct type *type; | |
190 | ||
191 | /* Allocate the structure. */ | |
192 | ||
193 | if (TYPE_OBJFILE (oldtype) == NULL) | |
194 | { | |
195 | type = xmalloc (sizeof (struct type)); | |
196 | memset (type, 0, sizeof (struct type)); | |
197 | } | |
198 | else | |
199 | { | |
b99607ea | 200 | type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack, |
2fdde8f8 DJ |
201 | sizeof (struct type)); |
202 | memset (type, 0, sizeof (struct type)); | |
203 | } | |
204 | TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype); | |
205 | ||
206 | TYPE_CHAIN (type) = type; /* Chain back to itself for now. */ | |
207 | ||
208 | return (type); | |
209 | } | |
210 | ||
211 | /* Clear all remnants of the previous type at TYPE, in preparation for | |
212 | replacing it with something else. */ | |
213 | static void | |
214 | smash_type (struct type *type) | |
215 | { | |
216 | memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); | |
217 | ||
218 | /* For now, delete the rings. */ | |
219 | TYPE_CHAIN (type) = type; | |
220 | ||
221 | /* For now, leave the pointer/reference types alone. */ | |
222 | } | |
223 | ||
c906108c SS |
224 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points |
225 | to a pointer to memory where the pointer type should be stored. | |
226 | If *TYPEPTR is zero, update it to point to the pointer type we return. | |
227 | We allocate new memory if needed. */ | |
228 | ||
229 | struct type * | |
fba45db2 | 230 | make_pointer_type (struct type *type, struct type **typeptr) |
c906108c | 231 | { |
52f0bd74 | 232 | struct type *ntype; /* New type */ |
c906108c | 233 | struct objfile *objfile; |
053cb41b | 234 | struct type *chain; |
c906108c SS |
235 | |
236 | ntype = TYPE_POINTER_TYPE (type); | |
237 | ||
c5aa993b | 238 | if (ntype) |
c906108c | 239 | { |
c5aa993b | 240 | if (typeptr == 0) |
7ba81444 MS |
241 | return ntype; /* Don't care about alloc, |
242 | and have new type. */ | |
c906108c | 243 | else if (*typeptr == 0) |
c5aa993b | 244 | { |
7ba81444 | 245 | *typeptr = ntype; /* Tracking alloc, and have new type. */ |
c906108c | 246 | return ntype; |
c5aa993b | 247 | } |
c906108c SS |
248 | } |
249 | ||
250 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
251 | { | |
252 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
253 | if (typeptr) | |
254 | *typeptr = ntype; | |
255 | } | |
7ba81444 | 256 | else /* We have storage, but need to reset it. */ |
c906108c SS |
257 | { |
258 | ntype = *typeptr; | |
259 | objfile = TYPE_OBJFILE (ntype); | |
053cb41b | 260 | chain = TYPE_CHAIN (ntype); |
2fdde8f8 | 261 | smash_type (ntype); |
053cb41b | 262 | TYPE_CHAIN (ntype) = chain; |
c906108c SS |
263 | TYPE_OBJFILE (ntype) = objfile; |
264 | } | |
265 | ||
266 | TYPE_TARGET_TYPE (ntype) = type; | |
267 | TYPE_POINTER_TYPE (type) = ntype; | |
268 | ||
7ba81444 MS |
269 | /* FIXME! Assume the machine has only one representation for |
270 | pointers! */ | |
c906108c | 271 | |
7ba81444 MS |
272 | TYPE_LENGTH (ntype) = |
273 | gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT; | |
c906108c SS |
274 | TYPE_CODE (ntype) = TYPE_CODE_PTR; |
275 | ||
67b2adb2 | 276 | /* Mark pointers as unsigned. The target converts between pointers |
76e71323 | 277 | and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and |
7ba81444 | 278 | gdbarch_address_to_pointer. */ |
c906108c | 279 | TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED; |
c5aa993b | 280 | |
c906108c SS |
281 | if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */ |
282 | TYPE_POINTER_TYPE (type) = ntype; | |
283 | ||
053cb41b JB |
284 | /* Update the length of all the other variants of this type. */ |
285 | chain = TYPE_CHAIN (ntype); | |
286 | while (chain != ntype) | |
287 | { | |
288 | TYPE_LENGTH (chain) = TYPE_LENGTH (ntype); | |
289 | chain = TYPE_CHAIN (chain); | |
290 | } | |
291 | ||
c906108c SS |
292 | return ntype; |
293 | } | |
294 | ||
295 | /* Given a type TYPE, return a type of pointers to that type. | |
296 | May need to construct such a type if this is the first use. */ | |
297 | ||
298 | struct type * | |
fba45db2 | 299 | lookup_pointer_type (struct type *type) |
c906108c | 300 | { |
c5aa993b | 301 | return make_pointer_type (type, (struct type **) 0); |
c906108c SS |
302 | } |
303 | ||
7ba81444 MS |
304 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, |
305 | points to a pointer to memory where the reference type should be | |
306 | stored. If *TYPEPTR is zero, update it to point to the reference | |
307 | type we return. We allocate new memory if needed. */ | |
c906108c SS |
308 | |
309 | struct type * | |
fba45db2 | 310 | make_reference_type (struct type *type, struct type **typeptr) |
c906108c | 311 | { |
52f0bd74 | 312 | struct type *ntype; /* New type */ |
c906108c | 313 | struct objfile *objfile; |
1e98b326 | 314 | struct type *chain; |
c906108c SS |
315 | |
316 | ntype = TYPE_REFERENCE_TYPE (type); | |
317 | ||
c5aa993b | 318 | if (ntype) |
c906108c | 319 | { |
c5aa993b | 320 | if (typeptr == 0) |
7ba81444 MS |
321 | return ntype; /* Don't care about alloc, |
322 | and have new type. */ | |
c906108c | 323 | else if (*typeptr == 0) |
c5aa993b | 324 | { |
7ba81444 | 325 | *typeptr = ntype; /* Tracking alloc, and have new type. */ |
c906108c | 326 | return ntype; |
c5aa993b | 327 | } |
c906108c SS |
328 | } |
329 | ||
330 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
331 | { | |
332 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
333 | if (typeptr) | |
334 | *typeptr = ntype; | |
335 | } | |
7ba81444 | 336 | else /* We have storage, but need to reset it. */ |
c906108c SS |
337 | { |
338 | ntype = *typeptr; | |
339 | objfile = TYPE_OBJFILE (ntype); | |
1e98b326 | 340 | chain = TYPE_CHAIN (ntype); |
2fdde8f8 | 341 | smash_type (ntype); |
1e98b326 | 342 | TYPE_CHAIN (ntype) = chain; |
c906108c SS |
343 | TYPE_OBJFILE (ntype) = objfile; |
344 | } | |
345 | ||
346 | TYPE_TARGET_TYPE (ntype) = type; | |
347 | TYPE_REFERENCE_TYPE (type) = ntype; | |
348 | ||
7ba81444 MS |
349 | /* FIXME! Assume the machine has only one representation for |
350 | references, and that it matches the (only) representation for | |
351 | pointers! */ | |
c906108c | 352 | |
819844ad | 353 | TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT; |
c906108c | 354 | TYPE_CODE (ntype) = TYPE_CODE_REF; |
c5aa993b | 355 | |
c906108c SS |
356 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ |
357 | TYPE_REFERENCE_TYPE (type) = ntype; | |
358 | ||
1e98b326 JB |
359 | /* Update the length of all the other variants of this type. */ |
360 | chain = TYPE_CHAIN (ntype); | |
361 | while (chain != ntype) | |
362 | { | |
363 | TYPE_LENGTH (chain) = TYPE_LENGTH (ntype); | |
364 | chain = TYPE_CHAIN (chain); | |
365 | } | |
366 | ||
c906108c SS |
367 | return ntype; |
368 | } | |
369 | ||
7ba81444 MS |
370 | /* Same as above, but caller doesn't care about memory allocation |
371 | details. */ | |
c906108c SS |
372 | |
373 | struct type * | |
fba45db2 | 374 | lookup_reference_type (struct type *type) |
c906108c | 375 | { |
c5aa993b | 376 | return make_reference_type (type, (struct type **) 0); |
c906108c SS |
377 | } |
378 | ||
7ba81444 MS |
379 | /* Lookup a function type that returns type TYPE. TYPEPTR, if |
380 | nonzero, points to a pointer to memory where the function type | |
381 | should be stored. If *TYPEPTR is zero, update it to point to the | |
382 | function type we return. We allocate new memory if needed. */ | |
c906108c SS |
383 | |
384 | struct type * | |
fba45db2 | 385 | make_function_type (struct type *type, struct type **typeptr) |
c906108c | 386 | { |
52f0bd74 | 387 | struct type *ntype; /* New type */ |
c906108c SS |
388 | struct objfile *objfile; |
389 | ||
390 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
391 | { | |
392 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
393 | if (typeptr) | |
394 | *typeptr = ntype; | |
395 | } | |
7ba81444 | 396 | else /* We have storage, but need to reset it. */ |
c906108c SS |
397 | { |
398 | ntype = *typeptr; | |
399 | objfile = TYPE_OBJFILE (ntype); | |
2fdde8f8 | 400 | smash_type (ntype); |
c906108c SS |
401 | TYPE_OBJFILE (ntype) = objfile; |
402 | } | |
403 | ||
404 | TYPE_TARGET_TYPE (ntype) = type; | |
405 | ||
406 | TYPE_LENGTH (ntype) = 1; | |
407 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; | |
c5aa993b | 408 | |
c906108c SS |
409 | return ntype; |
410 | } | |
411 | ||
412 | ||
413 | /* Given a type TYPE, return a type of functions that return that type. | |
414 | May need to construct such a type if this is the first use. */ | |
415 | ||
416 | struct type * | |
fba45db2 | 417 | lookup_function_type (struct type *type) |
c906108c | 418 | { |
c5aa993b | 419 | return make_function_type (type, (struct type **) 0); |
c906108c SS |
420 | } |
421 | ||
47663de5 MS |
422 | /* Identify address space identifier by name -- |
423 | return the integer flag defined in gdbtypes.h. */ | |
424 | extern int | |
425 | address_space_name_to_int (char *space_identifier) | |
426 | { | |
5f11f355 | 427 | struct gdbarch *gdbarch = current_gdbarch; |
8b2dbe47 | 428 | int type_flags; |
7ba81444 | 429 | /* Check for known address space delimiters. */ |
47663de5 MS |
430 | if (!strcmp (space_identifier, "code")) |
431 | return TYPE_FLAG_CODE_SPACE; | |
432 | else if (!strcmp (space_identifier, "data")) | |
433 | return TYPE_FLAG_DATA_SPACE; | |
5f11f355 AC |
434 | else if (gdbarch_address_class_name_to_type_flags_p (gdbarch) |
435 | && gdbarch_address_class_name_to_type_flags (gdbarch, | |
436 | space_identifier, | |
437 | &type_flags)) | |
8b2dbe47 | 438 | return type_flags; |
47663de5 | 439 | else |
8a3fe4f8 | 440 | error (_("Unknown address space specifier: \"%s\""), space_identifier); |
47663de5 MS |
441 | } |
442 | ||
443 | /* Identify address space identifier by integer flag as defined in | |
7ba81444 | 444 | gdbtypes.h -- return the string version of the adress space name. */ |
47663de5 | 445 | |
321432c0 | 446 | const char * |
47663de5 MS |
447 | address_space_int_to_name (int space_flag) |
448 | { | |
5f11f355 | 449 | struct gdbarch *gdbarch = current_gdbarch; |
47663de5 MS |
450 | if (space_flag & TYPE_FLAG_CODE_SPACE) |
451 | return "code"; | |
452 | else if (space_flag & TYPE_FLAG_DATA_SPACE) | |
453 | return "data"; | |
8b2dbe47 | 454 | else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL) |
5f11f355 AC |
455 | && gdbarch_address_class_type_flags_to_name_p (gdbarch)) |
456 | return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag); | |
47663de5 MS |
457 | else |
458 | return NULL; | |
459 | } | |
460 | ||
2fdde8f8 | 461 | /* Create a new type with instance flags NEW_FLAGS, based on TYPE. |
ad766c0a JB |
462 | |
463 | If STORAGE is non-NULL, create the new type instance there. | |
464 | STORAGE must be in the same obstack as TYPE. */ | |
47663de5 | 465 | |
b9362cc7 | 466 | static struct type * |
2fdde8f8 DJ |
467 | make_qualified_type (struct type *type, int new_flags, |
468 | struct type *storage) | |
47663de5 MS |
469 | { |
470 | struct type *ntype; | |
471 | ||
472 | ntype = type; | |
473 | do { | |
2fdde8f8 | 474 | if (TYPE_INSTANCE_FLAGS (ntype) == new_flags) |
47663de5 | 475 | return ntype; |
2fdde8f8 | 476 | ntype = TYPE_CHAIN (ntype); |
47663de5 MS |
477 | } while (ntype != type); |
478 | ||
2fdde8f8 DJ |
479 | /* Create a new type instance. */ |
480 | if (storage == NULL) | |
481 | ntype = alloc_type_instance (type); | |
482 | else | |
483 | { | |
7ba81444 MS |
484 | /* If STORAGE was provided, it had better be in the same objfile |
485 | as TYPE. Otherwise, we can't link it into TYPE's cv chain: | |
486 | if one objfile is freed and the other kept, we'd have | |
487 | dangling pointers. */ | |
ad766c0a JB |
488 | gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage)); |
489 | ||
2fdde8f8 DJ |
490 | ntype = storage; |
491 | TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type); | |
492 | TYPE_CHAIN (ntype) = ntype; | |
493 | } | |
47663de5 MS |
494 | |
495 | /* Pointers or references to the original type are not relevant to | |
2fdde8f8 | 496 | the new type. */ |
47663de5 MS |
497 | TYPE_POINTER_TYPE (ntype) = (struct type *) 0; |
498 | TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; | |
47663de5 | 499 | |
2fdde8f8 DJ |
500 | /* Chain the new qualified type to the old type. */ |
501 | TYPE_CHAIN (ntype) = TYPE_CHAIN (type); | |
502 | TYPE_CHAIN (type) = ntype; | |
503 | ||
504 | /* Now set the instance flags and return the new type. */ | |
505 | TYPE_INSTANCE_FLAGS (ntype) = new_flags; | |
47663de5 | 506 | |
ab5d3da6 KB |
507 | /* Set length of new type to that of the original type. */ |
508 | TYPE_LENGTH (ntype) = TYPE_LENGTH (type); | |
509 | ||
47663de5 MS |
510 | return ntype; |
511 | } | |
512 | ||
2fdde8f8 DJ |
513 | /* Make an address-space-delimited variant of a type -- a type that |
514 | is identical to the one supplied except that it has an address | |
515 | space attribute attached to it (such as "code" or "data"). | |
516 | ||
7ba81444 MS |
517 | The space attributes "code" and "data" are for Harvard |
518 | architectures. The address space attributes are for architectures | |
519 | which have alternately sized pointers or pointers with alternate | |
520 | representations. */ | |
2fdde8f8 DJ |
521 | |
522 | struct type * | |
523 | make_type_with_address_space (struct type *type, int space_flag) | |
524 | { | |
525 | struct type *ntype; | |
526 | int new_flags = ((TYPE_INSTANCE_FLAGS (type) | |
8b2dbe47 KB |
527 | & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE |
528 | | TYPE_FLAG_ADDRESS_CLASS_ALL)) | |
2fdde8f8 DJ |
529 | | space_flag); |
530 | ||
531 | return make_qualified_type (type, new_flags, NULL); | |
532 | } | |
c906108c SS |
533 | |
534 | /* Make a "c-v" variant of a type -- a type that is identical to the | |
535 | one supplied except that it may have const or volatile attributes | |
536 | CNST is a flag for setting the const attribute | |
537 | VOLTL is a flag for setting the volatile attribute | |
538 | TYPE is the base type whose variant we are creating. | |
c906108c | 539 | |
ad766c0a JB |
540 | If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to |
541 | storage to hold the new qualified type; *TYPEPTR and TYPE must be | |
542 | in the same objfile. Otherwise, allocate fresh memory for the new | |
543 | type whereever TYPE lives. If TYPEPTR is non-zero, set it to the | |
544 | new type we construct. */ | |
c906108c | 545 | struct type * |
7ba81444 MS |
546 | make_cv_type (int cnst, int voltl, |
547 | struct type *type, | |
548 | struct type **typeptr) | |
c906108c | 549 | { |
52f0bd74 AC |
550 | struct type *ntype; /* New type */ |
551 | struct type *tmp_type = type; /* tmp type */ | |
c906108c SS |
552 | struct objfile *objfile; |
553 | ||
2fdde8f8 DJ |
554 | int new_flags = (TYPE_INSTANCE_FLAGS (type) |
555 | & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE)); | |
c906108c | 556 | |
c906108c | 557 | if (cnst) |
2fdde8f8 | 558 | new_flags |= TYPE_FLAG_CONST; |
c906108c SS |
559 | |
560 | if (voltl) | |
2fdde8f8 | 561 | new_flags |= TYPE_FLAG_VOLATILE; |
a02fd225 | 562 | |
2fdde8f8 | 563 | if (typeptr && *typeptr != NULL) |
a02fd225 | 564 | { |
ad766c0a JB |
565 | /* TYPE and *TYPEPTR must be in the same objfile. We can't have |
566 | a C-V variant chain that threads across objfiles: if one | |
567 | objfile gets freed, then the other has a broken C-V chain. | |
568 | ||
569 | This code used to try to copy over the main type from TYPE to | |
570 | *TYPEPTR if they were in different objfiles, but that's | |
571 | wrong, too: TYPE may have a field list or member function | |
572 | lists, which refer to types of their own, etc. etc. The | |
573 | whole shebang would need to be copied over recursively; you | |
574 | can't have inter-objfile pointers. The only thing to do is | |
575 | to leave stub types as stub types, and look them up afresh by | |
576 | name each time you encounter them. */ | |
577 | gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)); | |
2fdde8f8 DJ |
578 | } |
579 | ||
7ba81444 MS |
580 | ntype = make_qualified_type (type, new_flags, |
581 | typeptr ? *typeptr : NULL); | |
c906108c | 582 | |
2fdde8f8 DJ |
583 | if (typeptr != NULL) |
584 | *typeptr = ntype; | |
a02fd225 | 585 | |
2fdde8f8 | 586 | return ntype; |
a02fd225 | 587 | } |
c906108c | 588 | |
2fdde8f8 DJ |
589 | /* Replace the contents of ntype with the type *type. This changes the |
590 | contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus | |
591 | the changes are propogated to all types in the TYPE_CHAIN. | |
dd6bda65 | 592 | |
cda6c68a JB |
593 | In order to build recursive types, it's inevitable that we'll need |
594 | to update types in place --- but this sort of indiscriminate | |
595 | smashing is ugly, and needs to be replaced with something more | |
2fdde8f8 DJ |
596 | controlled. TYPE_MAIN_TYPE is a step in this direction; it's not |
597 | clear if more steps are needed. */ | |
dd6bda65 DJ |
598 | void |
599 | replace_type (struct type *ntype, struct type *type) | |
600 | { | |
ab5d3da6 | 601 | struct type *chain; |
dd6bda65 | 602 | |
ad766c0a JB |
603 | /* These two types had better be in the same objfile. Otherwise, |
604 | the assignment of one type's main type structure to the other | |
605 | will produce a type with references to objects (names; field | |
606 | lists; etc.) allocated on an objfile other than its own. */ | |
607 | gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype)); | |
608 | ||
2fdde8f8 | 609 | *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type); |
dd6bda65 | 610 | |
7ba81444 MS |
611 | /* The type length is not a part of the main type. Update it for |
612 | each type on the variant chain. */ | |
ab5d3da6 KB |
613 | chain = ntype; |
614 | do { | |
615 | /* Assert that this element of the chain has no address-class bits | |
616 | set in its flags. Such type variants might have type lengths | |
617 | which are supposed to be different from the non-address-class | |
618 | variants. This assertion shouldn't ever be triggered because | |
619 | symbol readers which do construct address-class variants don't | |
620 | call replace_type(). */ | |
621 | gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0); | |
622 | ||
787cbe14 | 623 | TYPE_LENGTH (chain) = TYPE_LENGTH (type); |
ab5d3da6 KB |
624 | chain = TYPE_CHAIN (chain); |
625 | } while (ntype != chain); | |
626 | ||
2fdde8f8 DJ |
627 | /* Assert that the two types have equivalent instance qualifiers. |
628 | This should be true for at least all of our debug readers. */ | |
629 | gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type)); | |
dd6bda65 DJ |
630 | } |
631 | ||
c906108c SS |
632 | /* Implement direct support for MEMBER_TYPE in GNU C++. |
633 | May need to construct such a type if this is the first use. | |
634 | The TYPE is the type of the member. The DOMAIN is the type | |
635 | of the aggregate that the member belongs to. */ | |
636 | ||
637 | struct type * | |
0d5de010 | 638 | lookup_memberptr_type (struct type *type, struct type *domain) |
c906108c | 639 | { |
52f0bd74 | 640 | struct type *mtype; |
c906108c SS |
641 | |
642 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
0d5de010 | 643 | smash_to_memberptr_type (mtype, domain, type); |
c906108c SS |
644 | return (mtype); |
645 | } | |
646 | ||
0d5de010 DJ |
647 | /* Return a pointer-to-method type, for a method of type TO_TYPE. */ |
648 | ||
649 | struct type * | |
650 | lookup_methodptr_type (struct type *to_type) | |
651 | { | |
652 | struct type *mtype; | |
653 | ||
654 | mtype = alloc_type (TYPE_OBJFILE (to_type)); | |
655 | TYPE_TARGET_TYPE (mtype) = to_type; | |
656 | TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type); | |
657 | TYPE_LENGTH (mtype) = cplus_method_ptr_size (); | |
658 | TYPE_CODE (mtype) = TYPE_CODE_METHODPTR; | |
659 | return mtype; | |
660 | } | |
661 | ||
7ba81444 MS |
662 | /* Allocate a stub method whose return type is TYPE. This apparently |
663 | happens for speed of symbol reading, since parsing out the | |
664 | arguments to the method is cpu-intensive, the way we are doing it. | |
665 | So, we will fill in arguments later. This always returns a fresh | |
666 | type. */ | |
c906108c SS |
667 | |
668 | struct type * | |
fba45db2 | 669 | allocate_stub_method (struct type *type) |
c906108c SS |
670 | { |
671 | struct type *mtype; | |
672 | ||
7e956337 FF |
673 | mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL, |
674 | TYPE_OBJFILE (type)); | |
c906108c SS |
675 | TYPE_TARGET_TYPE (mtype) = type; |
676 | /* _DOMAIN_TYPE (mtype) = unknown yet */ | |
c906108c SS |
677 | return (mtype); |
678 | } | |
679 | ||
7ba81444 MS |
680 | /* Create a range type using either a blank type supplied in |
681 | RESULT_TYPE, or creating a new type, inheriting the objfile from | |
682 | INDEX_TYPE. | |
c906108c | 683 | |
7ba81444 MS |
684 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND |
685 | to HIGH_BOUND, inclusive. | |
c906108c | 686 | |
7ba81444 MS |
687 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
688 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ | |
c906108c SS |
689 | |
690 | struct type * | |
fba45db2 KB |
691 | create_range_type (struct type *result_type, struct type *index_type, |
692 | int low_bound, int high_bound) | |
c906108c SS |
693 | { |
694 | if (result_type == NULL) | |
695 | { | |
696 | result_type = alloc_type (TYPE_OBJFILE (index_type)); | |
697 | } | |
698 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; | |
699 | TYPE_TARGET_TYPE (result_type) = index_type; | |
74a9bb82 | 700 | if (TYPE_STUB (index_type)) |
c906108c SS |
701 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; |
702 | else | |
703 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); | |
704 | TYPE_NFIELDS (result_type) = 2; | |
705 | TYPE_FIELDS (result_type) = (struct field *) | |
706 | TYPE_ALLOC (result_type, 2 * sizeof (struct field)); | |
707 | memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field)); | |
708 | TYPE_FIELD_BITPOS (result_type, 0) = low_bound; | |
709 | TYPE_FIELD_BITPOS (result_type, 1) = high_bound; | |
c5aa993b JM |
710 | TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */ |
711 | TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */ | |
c906108c | 712 | |
c5aa993b | 713 | if (low_bound >= 0) |
c906108c SS |
714 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
715 | ||
716 | return (result_type); | |
717 | } | |
718 | ||
7ba81444 MS |
719 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type |
720 | TYPE. Return 1 if type is a range type, 0 if it is discrete (and | |
721 | bounds will fit in LONGEST), or -1 otherwise. */ | |
c906108c SS |
722 | |
723 | int | |
fba45db2 | 724 | get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) |
c906108c SS |
725 | { |
726 | CHECK_TYPEDEF (type); | |
727 | switch (TYPE_CODE (type)) | |
728 | { | |
729 | case TYPE_CODE_RANGE: | |
730 | *lowp = TYPE_LOW_BOUND (type); | |
731 | *highp = TYPE_HIGH_BOUND (type); | |
732 | return 1; | |
733 | case TYPE_CODE_ENUM: | |
734 | if (TYPE_NFIELDS (type) > 0) | |
735 | { | |
736 | /* The enums may not be sorted by value, so search all | |
737 | entries */ | |
738 | int i; | |
739 | ||
740 | *lowp = *highp = TYPE_FIELD_BITPOS (type, 0); | |
741 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
742 | { | |
743 | if (TYPE_FIELD_BITPOS (type, i) < *lowp) | |
744 | *lowp = TYPE_FIELD_BITPOS (type, i); | |
745 | if (TYPE_FIELD_BITPOS (type, i) > *highp) | |
746 | *highp = TYPE_FIELD_BITPOS (type, i); | |
747 | } | |
748 | ||
7ba81444 | 749 | /* Set unsigned indicator if warranted. */ |
c5aa993b | 750 | if (*lowp >= 0) |
c906108c SS |
751 | { |
752 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; | |
753 | } | |
754 | } | |
755 | else | |
756 | { | |
757 | *lowp = 0; | |
758 | *highp = -1; | |
759 | } | |
760 | return 0; | |
761 | case TYPE_CODE_BOOL: | |
762 | *lowp = 0; | |
763 | *highp = 1; | |
764 | return 0; | |
765 | case TYPE_CODE_INT: | |
c5aa993b | 766 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
c906108c SS |
767 | return -1; |
768 | if (!TYPE_UNSIGNED (type)) | |
769 | { | |
c5aa993b | 770 | *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); |
c906108c SS |
771 | *highp = -*lowp - 1; |
772 | return 0; | |
773 | } | |
7ba81444 | 774 | /* ... fall through for unsigned ints ... */ |
c906108c SS |
775 | case TYPE_CODE_CHAR: |
776 | *lowp = 0; | |
777 | /* This round-about calculation is to avoid shifting by | |
7b83ea04 | 778 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work |
7ba81444 | 779 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ |
c906108c SS |
780 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); |
781 | *highp = (*highp - 1) | *highp; | |
782 | return 0; | |
783 | default: | |
784 | return -1; | |
785 | } | |
786 | } | |
787 | ||
7ba81444 MS |
788 | /* Create an array type using either a blank type supplied in |
789 | RESULT_TYPE, or creating a new type, inheriting the objfile from | |
790 | RANGE_TYPE. | |
c906108c SS |
791 | |
792 | Elements will be of type ELEMENT_TYPE, the indices will be of type | |
793 | RANGE_TYPE. | |
794 | ||
7ba81444 MS |
795 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
796 | sure it is TYPE_CODE_UNDEF before we bash it into an array | |
797 | type? */ | |
c906108c SS |
798 | |
799 | struct type * | |
7ba81444 MS |
800 | create_array_type (struct type *result_type, |
801 | struct type *element_type, | |
fba45db2 | 802 | struct type *range_type) |
c906108c SS |
803 | { |
804 | LONGEST low_bound, high_bound; | |
805 | ||
806 | if (result_type == NULL) | |
807 | { | |
808 | result_type = alloc_type (TYPE_OBJFILE (range_type)); | |
809 | } | |
810 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; | |
811 | TYPE_TARGET_TYPE (result_type) = element_type; | |
812 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) | |
813 | low_bound = high_bound = 0; | |
814 | CHECK_TYPEDEF (element_type); | |
815 | TYPE_LENGTH (result_type) = | |
816 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); | |
817 | TYPE_NFIELDS (result_type) = 1; | |
818 | TYPE_FIELDS (result_type) = | |
819 | (struct field *) TYPE_ALLOC (result_type, sizeof (struct field)); | |
820 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
821 | TYPE_FIELD_TYPE (result_type, 0) = range_type; | |
822 | TYPE_VPTR_FIELDNO (result_type) = -1; | |
823 | ||
824 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */ | |
825 | if (TYPE_LENGTH (result_type) == 0) | |
826 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; | |
827 | ||
828 | return (result_type); | |
829 | } | |
830 | ||
7ba81444 MS |
831 | /* Create a string type using either a blank type supplied in |
832 | RESULT_TYPE, or creating a new type. String types are similar | |
833 | enough to array of char types that we can use create_array_type to | |
834 | build the basic type and then bash it into a string type. | |
c906108c SS |
835 | |
836 | For fixed length strings, the range type contains 0 as the lower | |
837 | bound and the length of the string minus one as the upper bound. | |
838 | ||
7ba81444 MS |
839 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
840 | sure it is TYPE_CODE_UNDEF before we bash it into a string | |
841 | type? */ | |
c906108c SS |
842 | |
843 | struct type * | |
7ba81444 MS |
844 | create_string_type (struct type *result_type, |
845 | struct type *range_type) | |
c906108c | 846 | { |
f290d38e AC |
847 | struct type *string_char_type; |
848 | ||
849 | string_char_type = language_string_char_type (current_language, | |
850 | current_gdbarch); | |
c906108c | 851 | result_type = create_array_type (result_type, |
f290d38e | 852 | string_char_type, |
c906108c SS |
853 | range_type); |
854 | TYPE_CODE (result_type) = TYPE_CODE_STRING; | |
855 | return (result_type); | |
856 | } | |
857 | ||
858 | struct type * | |
fba45db2 | 859 | create_set_type (struct type *result_type, struct type *domain_type) |
c906108c | 860 | { |
c906108c SS |
861 | if (result_type == NULL) |
862 | { | |
863 | result_type = alloc_type (TYPE_OBJFILE (domain_type)); | |
864 | } | |
865 | TYPE_CODE (result_type) = TYPE_CODE_SET; | |
866 | TYPE_NFIELDS (result_type) = 1; | |
867 | TYPE_FIELDS (result_type) = (struct field *) | |
868 | TYPE_ALLOC (result_type, 1 * sizeof (struct field)); | |
869 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
870 | ||
74a9bb82 | 871 | if (!TYPE_STUB (domain_type)) |
c906108c | 872 | { |
f9780d5b | 873 | LONGEST low_bound, high_bound, bit_length; |
c906108c SS |
874 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) |
875 | low_bound = high_bound = 0; | |
876 | bit_length = high_bound - low_bound + 1; | |
877 | TYPE_LENGTH (result_type) | |
878 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; | |
f9780d5b MS |
879 | if (low_bound >= 0) |
880 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; | |
c906108c SS |
881 | } |
882 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; | |
883 | ||
c906108c SS |
884 | return (result_type); |
885 | } | |
886 | ||
4f2aea11 MK |
887 | void |
888 | append_flags_type_flag (struct type *type, int bitpos, char *name) | |
889 | { | |
890 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS); | |
891 | gdb_assert (bitpos < TYPE_NFIELDS (type)); | |
892 | gdb_assert (bitpos >= 0); | |
893 | ||
894 | if (name) | |
895 | { | |
896 | TYPE_FIELD_NAME (type, bitpos) = xstrdup (name); | |
897 | TYPE_FIELD_BITPOS (type, bitpos) = bitpos; | |
898 | } | |
899 | else | |
900 | { | |
901 | /* Don't show this field to the user. */ | |
902 | TYPE_FIELD_BITPOS (type, bitpos) = -1; | |
903 | } | |
904 | } | |
905 | ||
906 | struct type * | |
907 | init_flags_type (char *name, int length) | |
908 | { | |
909 | int nfields = length * TARGET_CHAR_BIT; | |
910 | struct type *type; | |
911 | ||
7ba81444 MS |
912 | type = init_type (TYPE_CODE_FLAGS, length, |
913 | TYPE_FLAG_UNSIGNED, name, NULL); | |
4f2aea11 | 914 | TYPE_NFIELDS (type) = nfields; |
7ba81444 MS |
915 | TYPE_FIELDS (type) = TYPE_ALLOC (type, |
916 | nfields * sizeof (struct field)); | |
76b7178d | 917 | memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field)); |
4f2aea11 MK |
918 | |
919 | return type; | |
920 | } | |
921 | ||
794ac428 | 922 | struct type * |
ac3aafc7 EZ |
923 | init_vector_type (struct type *elt_type, int n) |
924 | { | |
925 | struct type *array_type; | |
926 | ||
927 | array_type = create_array_type (0, elt_type, | |
7ba81444 MS |
928 | create_range_type (0, |
929 | builtin_type_int, | |
ac3aafc7 EZ |
930 | 0, n-1)); |
931 | TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR; | |
932 | return array_type; | |
933 | } | |
934 | ||
0d5de010 DJ |
935 | /* Smash TYPE to be a type of pointers to members of DOMAIN with type |
936 | TO_TYPE. A member pointer is a wierd thing -- it amounts to a | |
937 | typed offset into a struct, e.g. "an int at offset 8". A MEMBER | |
938 | TYPE doesn't include the offset (that's the value of the MEMBER | |
939 | itself), but does include the structure type into which it points | |
940 | (for some reason). | |
c906108c | 941 | |
7ba81444 MS |
942 | When "smashing" the type, we preserve the objfile that the old type |
943 | pointed to, since we aren't changing where the type is actually | |
c906108c SS |
944 | allocated. */ |
945 | ||
946 | void | |
0d5de010 DJ |
947 | smash_to_memberptr_type (struct type *type, struct type *domain, |
948 | struct type *to_type) | |
c906108c SS |
949 | { |
950 | struct objfile *objfile; | |
951 | ||
952 | objfile = TYPE_OBJFILE (type); | |
953 | ||
2fdde8f8 | 954 | smash_type (type); |
c906108c SS |
955 | TYPE_OBJFILE (type) = objfile; |
956 | TYPE_TARGET_TYPE (type) = to_type; | |
957 | TYPE_DOMAIN_TYPE (type) = domain; | |
0d5de010 DJ |
958 | /* Assume that a data member pointer is the same size as a normal |
959 | pointer. */ | |
819844ad | 960 | TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT; |
0d5de010 | 961 | TYPE_CODE (type) = TYPE_CODE_MEMBERPTR; |
c906108c SS |
962 | } |
963 | ||
964 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. | |
965 | METHOD just means `function that gets an extra "this" argument'. | |
966 | ||
7ba81444 MS |
967 | When "smashing" the type, we preserve the objfile that the old type |
968 | pointed to, since we aren't changing where the type is actually | |
c906108c SS |
969 | allocated. */ |
970 | ||
971 | void | |
fba45db2 | 972 | smash_to_method_type (struct type *type, struct type *domain, |
ad2f7632 DJ |
973 | struct type *to_type, struct field *args, |
974 | int nargs, int varargs) | |
c906108c SS |
975 | { |
976 | struct objfile *objfile; | |
977 | ||
978 | objfile = TYPE_OBJFILE (type); | |
979 | ||
2fdde8f8 | 980 | smash_type (type); |
c906108c SS |
981 | TYPE_OBJFILE (type) = objfile; |
982 | TYPE_TARGET_TYPE (type) = to_type; | |
983 | TYPE_DOMAIN_TYPE (type) = domain; | |
ad2f7632 DJ |
984 | TYPE_FIELDS (type) = args; |
985 | TYPE_NFIELDS (type) = nargs; | |
986 | if (varargs) | |
987 | TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS; | |
c906108c SS |
988 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
989 | TYPE_CODE (type) = TYPE_CODE_METHOD; | |
990 | } | |
991 | ||
992 | /* Return a typename for a struct/union/enum type without "struct ", | |
993 | "union ", or "enum ". If the type has a NULL name, return NULL. */ | |
994 | ||
995 | char * | |
aa1ee363 | 996 | type_name_no_tag (const struct type *type) |
c906108c SS |
997 | { |
998 | if (TYPE_TAG_NAME (type) != NULL) | |
999 | return TYPE_TAG_NAME (type); | |
1000 | ||
7ba81444 MS |
1001 | /* Is there code which expects this to return the name if there is |
1002 | no tag name? My guess is that this is mainly used for C++ in | |
1003 | cases where the two will always be the same. */ | |
c906108c SS |
1004 | return TYPE_NAME (type); |
1005 | } | |
1006 | ||
7ba81444 MS |
1007 | /* Lookup a typedef or primitive type named NAME, visible in lexical |
1008 | block BLOCK. If NOERR is nonzero, return zero if NAME is not | |
1009 | suitably defined. */ | |
c906108c SS |
1010 | |
1011 | struct type * | |
fba45db2 | 1012 | lookup_typename (char *name, struct block *block, int noerr) |
c906108c | 1013 | { |
52f0bd74 AC |
1014 | struct symbol *sym; |
1015 | struct type *tmp; | |
c906108c | 1016 | |
7ba81444 MS |
1017 | sym = lookup_symbol (name, block, VAR_DOMAIN, 0, |
1018 | (struct symtab **) NULL); | |
c906108c SS |
1019 | if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) |
1020 | { | |
54a5b07d AC |
1021 | tmp = language_lookup_primitive_type_by_name (current_language, |
1022 | current_gdbarch, | |
1023 | name); | |
c906108c SS |
1024 | if (tmp) |
1025 | { | |
1026 | return (tmp); | |
1027 | } | |
1028 | else if (!tmp && noerr) | |
1029 | { | |
1030 | return (NULL); | |
1031 | } | |
1032 | else | |
1033 | { | |
8a3fe4f8 | 1034 | error (_("No type named %s."), name); |
c906108c SS |
1035 | } |
1036 | } | |
1037 | return (SYMBOL_TYPE (sym)); | |
1038 | } | |
1039 | ||
1040 | struct type * | |
fba45db2 | 1041 | lookup_unsigned_typename (char *name) |
c906108c SS |
1042 | { |
1043 | char *uns = alloca (strlen (name) + 10); | |
1044 | ||
1045 | strcpy (uns, "unsigned "); | |
1046 | strcpy (uns + 9, name); | |
1047 | return (lookup_typename (uns, (struct block *) NULL, 0)); | |
1048 | } | |
1049 | ||
1050 | struct type * | |
fba45db2 | 1051 | lookup_signed_typename (char *name) |
c906108c SS |
1052 | { |
1053 | struct type *t; | |
1054 | char *uns = alloca (strlen (name) + 8); | |
1055 | ||
1056 | strcpy (uns, "signed "); | |
1057 | strcpy (uns + 7, name); | |
1058 | t = lookup_typename (uns, (struct block *) NULL, 1); | |
7ba81444 | 1059 | /* If we don't find "signed FOO" just try again with plain "FOO". */ |
c906108c SS |
1060 | if (t != NULL) |
1061 | return t; | |
1062 | return lookup_typename (name, (struct block *) NULL, 0); | |
1063 | } | |
1064 | ||
1065 | /* Lookup a structure type named "struct NAME", | |
1066 | visible in lexical block BLOCK. */ | |
1067 | ||
1068 | struct type * | |
fba45db2 | 1069 | lookup_struct (char *name, struct block *block) |
c906108c | 1070 | { |
52f0bd74 | 1071 | struct symbol *sym; |
c906108c | 1072 | |
176620f1 | 1073 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
c906108c SS |
1074 | (struct symtab **) NULL); |
1075 | ||
1076 | if (sym == NULL) | |
1077 | { | |
8a3fe4f8 | 1078 | error (_("No struct type named %s."), name); |
c906108c SS |
1079 | } |
1080 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
1081 | { | |
7ba81444 MS |
1082 | error (_("This context has class, union or enum %s, not a struct."), |
1083 | name); | |
c906108c SS |
1084 | } |
1085 | return (SYMBOL_TYPE (sym)); | |
1086 | } | |
1087 | ||
1088 | /* Lookup a union type named "union NAME", | |
1089 | visible in lexical block BLOCK. */ | |
1090 | ||
1091 | struct type * | |
fba45db2 | 1092 | lookup_union (char *name, struct block *block) |
c906108c | 1093 | { |
52f0bd74 | 1094 | struct symbol *sym; |
c5aa993b | 1095 | struct type *t; |
c906108c | 1096 | |
176620f1 | 1097 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
c906108c SS |
1098 | (struct symtab **) NULL); |
1099 | ||
1100 | if (sym == NULL) | |
8a3fe4f8 | 1101 | error (_("No union type named %s."), name); |
c906108c | 1102 | |
c5aa993b | 1103 | t = SYMBOL_TYPE (sym); |
c906108c SS |
1104 | |
1105 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
1106 | return (t); | |
1107 | ||
1108 | /* C++ unions may come out with TYPE_CODE_CLASS, but we look at | |
1109 | * a further "declared_type" field to discover it is really a union. | |
1110 | */ | |
c5aa993b JM |
1111 | if (HAVE_CPLUS_STRUCT (t)) |
1112 | if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION) | |
c906108c SS |
1113 | return (t); |
1114 | ||
7ba81444 MS |
1115 | /* If we get here, it's not a union. */ |
1116 | error (_("This context has class, struct or enum %s, not a union."), | |
1117 | name); | |
c906108c SS |
1118 | } |
1119 | ||
1120 | ||
1121 | /* Lookup an enum type named "enum NAME", | |
1122 | visible in lexical block BLOCK. */ | |
1123 | ||
1124 | struct type * | |
fba45db2 | 1125 | lookup_enum (char *name, struct block *block) |
c906108c | 1126 | { |
52f0bd74 | 1127 | struct symbol *sym; |
c906108c | 1128 | |
176620f1 | 1129 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
c906108c SS |
1130 | (struct symtab **) NULL); |
1131 | if (sym == NULL) | |
1132 | { | |
8a3fe4f8 | 1133 | error (_("No enum type named %s."), name); |
c906108c SS |
1134 | } |
1135 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) | |
1136 | { | |
7ba81444 MS |
1137 | error (_("This context has class, struct or union %s, not an enum."), |
1138 | name); | |
c906108c SS |
1139 | } |
1140 | return (SYMBOL_TYPE (sym)); | |
1141 | } | |
1142 | ||
1143 | /* Lookup a template type named "template NAME<TYPE>", | |
1144 | visible in lexical block BLOCK. */ | |
1145 | ||
1146 | struct type * | |
7ba81444 MS |
1147 | lookup_template_type (char *name, struct type *type, |
1148 | struct block *block) | |
c906108c SS |
1149 | { |
1150 | struct symbol *sym; | |
7ba81444 MS |
1151 | char *nam = (char *) |
1152 | alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4); | |
c906108c SS |
1153 | strcpy (nam, name); |
1154 | strcat (nam, "<"); | |
0004e5a2 | 1155 | strcat (nam, TYPE_NAME (type)); |
7ba81444 | 1156 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ |
c906108c | 1157 | |
7ba81444 MS |
1158 | sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, |
1159 | (struct symtab **) NULL); | |
c906108c SS |
1160 | |
1161 | if (sym == NULL) | |
1162 | { | |
8a3fe4f8 | 1163 | error (_("No template type named %s."), name); |
c906108c SS |
1164 | } |
1165 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
1166 | { | |
7ba81444 MS |
1167 | error (_("This context has class, union or enum %s, not a struct."), |
1168 | name); | |
c906108c SS |
1169 | } |
1170 | return (SYMBOL_TYPE (sym)); | |
1171 | } | |
1172 | ||
7ba81444 MS |
1173 | /* Given a type TYPE, lookup the type of the component of type named |
1174 | NAME. | |
c906108c | 1175 | |
7ba81444 MS |
1176 | TYPE can be either a struct or union, or a pointer or reference to |
1177 | a struct or union. If it is a pointer or reference, its target | |
1178 | type is automatically used. Thus '.' and '->' are interchangable, | |
1179 | as specified for the definitions of the expression element types | |
1180 | STRUCTOP_STRUCT and STRUCTOP_PTR. | |
c906108c SS |
1181 | |
1182 | If NOERR is nonzero, return zero if NAME is not suitably defined. | |
1183 | If NAME is the name of a baseclass type, return that type. */ | |
1184 | ||
1185 | struct type * | |
fba45db2 | 1186 | lookup_struct_elt_type (struct type *type, char *name, int noerr) |
c906108c SS |
1187 | { |
1188 | int i; | |
1189 | ||
1190 | for (;;) | |
1191 | { | |
1192 | CHECK_TYPEDEF (type); | |
1193 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
1194 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
1195 | break; | |
1196 | type = TYPE_TARGET_TYPE (type); | |
1197 | } | |
1198 | ||
687d6395 MS |
1199 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
1200 | && TYPE_CODE (type) != TYPE_CODE_UNION) | |
c906108c SS |
1201 | { |
1202 | target_terminal_ours (); | |
1203 | gdb_flush (gdb_stdout); | |
1204 | fprintf_unfiltered (gdb_stderr, "Type "); | |
1205 | type_print (type, "", gdb_stderr, -1); | |
8a3fe4f8 | 1206 | error (_(" is not a structure or union type.")); |
c906108c SS |
1207 | } |
1208 | ||
1209 | #if 0 | |
7ba81444 MS |
1210 | /* FIXME: This change put in by Michael seems incorrect for the case |
1211 | where the structure tag name is the same as the member name. | |
1212 | I.E. when doing "ptype bell->bar" for "struct foo { int bar; int | |
1213 | foo; } bell;" Disabled by fnf. */ | |
c906108c SS |
1214 | { |
1215 | char *typename; | |
1216 | ||
1217 | typename = type_name_no_tag (type); | |
762f08a3 | 1218 | if (typename != NULL && strcmp (typename, name) == 0) |
c906108c SS |
1219 | return type; |
1220 | } | |
1221 | #endif | |
1222 | ||
1223 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
1224 | { | |
1225 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
1226 | ||
db577aea | 1227 | if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) |
c906108c SS |
1228 | { |
1229 | return TYPE_FIELD_TYPE (type, i); | |
1230 | } | |
1231 | } | |
1232 | ||
1233 | /* OK, it's not in this class. Recursively check the baseclasses. */ | |
1234 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
1235 | { | |
1236 | struct type *t; | |
1237 | ||
9733fc94 | 1238 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1); |
c906108c SS |
1239 | if (t != NULL) |
1240 | { | |
1241 | return t; | |
1242 | } | |
1243 | } | |
1244 | ||
1245 | if (noerr) | |
1246 | { | |
1247 | return NULL; | |
1248 | } | |
c5aa993b | 1249 | |
c906108c SS |
1250 | target_terminal_ours (); |
1251 | gdb_flush (gdb_stdout); | |
1252 | fprintf_unfiltered (gdb_stderr, "Type "); | |
1253 | type_print (type, "", gdb_stderr, -1); | |
1254 | fprintf_unfiltered (gdb_stderr, " has no component named "); | |
1255 | fputs_filtered (name, gdb_stderr); | |
8a3fe4f8 | 1256 | error ((".")); |
c5aa993b | 1257 | return (struct type *) -1; /* For lint */ |
c906108c SS |
1258 | } |
1259 | ||
1260 | /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE | |
1261 | valid. Callers should be aware that in some cases (for example, | |
1262 | the type or one of its baseclasses is a stub type and we are | |
7ba81444 MS |
1263 | debugging a .o file), this function will not be able to find the |
1264 | virtual function table pointer, and vptr_fieldno will remain -1 and | |
1265 | vptr_basetype will remain NULL. */ | |
c906108c SS |
1266 | |
1267 | void | |
fba45db2 | 1268 | fill_in_vptr_fieldno (struct type *type) |
c906108c SS |
1269 | { |
1270 | CHECK_TYPEDEF (type); | |
1271 | ||
1272 | if (TYPE_VPTR_FIELDNO (type) < 0) | |
1273 | { | |
1274 | int i; | |
1275 | ||
7ba81444 MS |
1276 | /* We must start at zero in case the first (and only) baseclass |
1277 | is virtual (and hence we cannot share the table pointer). */ | |
c906108c SS |
1278 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
1279 | { | |
7ba81444 MS |
1280 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, |
1281 | i)); | |
cef4f5dd DJ |
1282 | fill_in_vptr_fieldno (baseclass); |
1283 | if (TYPE_VPTR_FIELDNO (baseclass) >= 0) | |
c906108c | 1284 | { |
cef4f5dd DJ |
1285 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass); |
1286 | TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass); | |
c906108c SS |
1287 | break; |
1288 | } | |
1289 | } | |
1290 | } | |
1291 | } | |
1292 | ||
1293 | /* Find the method and field indices for the destructor in class type T. | |
1294 | Return 1 if the destructor was found, otherwise, return 0. */ | |
1295 | ||
1296 | int | |
7ba81444 MS |
1297 | get_destructor_fn_field (struct type *t, |
1298 | int *method_indexp, | |
1299 | int *field_indexp) | |
c906108c SS |
1300 | { |
1301 | int i; | |
1302 | ||
1303 | for (i = 0; i < TYPE_NFN_FIELDS (t); i++) | |
1304 | { | |
1305 | int j; | |
1306 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); | |
1307 | ||
1308 | for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++) | |
1309 | { | |
015a42b4 | 1310 | if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0) |
c906108c SS |
1311 | { |
1312 | *method_indexp = i; | |
1313 | *field_indexp = j; | |
1314 | return 1; | |
1315 | } | |
1316 | } | |
1317 | } | |
1318 | return 0; | |
1319 | } | |
1320 | ||
44e1a9eb DJ |
1321 | static void |
1322 | stub_noname_complaint (void) | |
1323 | { | |
e2e0b3e5 | 1324 | complaint (&symfile_complaints, _("stub type has NULL name")); |
44e1a9eb DJ |
1325 | } |
1326 | ||
c906108c SS |
1327 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. |
1328 | ||
1329 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
1330 | we can find a full definition in some other file. If so, copy this | |
7ba81444 MS |
1331 | definition, so we can use it in future. There used to be a comment |
1332 | (but not any code) that if we don't find a full definition, we'd | |
1333 | set a flag so we don't spend time in the future checking the same | |
1334 | type. That would be a mistake, though--we might load in more | |
1335 | symbols which contain a full definition for the type. | |
c906108c | 1336 | |
7b83ea04 | 1337 | This used to be coded as a macro, but I don't think it is called |
c906108c SS |
1338 | often enough to merit such treatment. */ |
1339 | ||
7ba81444 MS |
1340 | /* Find the real type of TYPE. This function returns the real type, |
1341 | after removing all layers of typedefs and completing opaque or stub | |
1342 | types. Completion changes the TYPE argument, but stripping of | |
1343 | typedefs does not. */ | |
c906108c SS |
1344 | |
1345 | struct type * | |
a02fd225 | 1346 | check_typedef (struct type *type) |
c906108c SS |
1347 | { |
1348 | struct type *orig_type = type; | |
a02fd225 DJ |
1349 | int is_const, is_volatile; |
1350 | ||
423c0af8 MS |
1351 | gdb_assert (type); |
1352 | ||
c906108c SS |
1353 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
1354 | { | |
1355 | if (!TYPE_TARGET_TYPE (type)) | |
1356 | { | |
c5aa993b | 1357 | char *name; |
c906108c SS |
1358 | struct symbol *sym; |
1359 | ||
1360 | /* It is dangerous to call lookup_symbol if we are currently | |
7ba81444 | 1361 | reading a symtab. Infinite recursion is one danger. */ |
c906108c SS |
1362 | if (currently_reading_symtab) |
1363 | return type; | |
1364 | ||
1365 | name = type_name_no_tag (type); | |
7ba81444 MS |
1366 | /* FIXME: shouldn't we separately check the TYPE_NAME and |
1367 | the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or | |
1368 | VAR_DOMAIN as appropriate? (this code was written before | |
1369 | TYPE_NAME and TYPE_TAG_NAME were separate). */ | |
c906108c SS |
1370 | if (name == NULL) |
1371 | { | |
23136709 | 1372 | stub_noname_complaint (); |
c906108c SS |
1373 | return type; |
1374 | } | |
176620f1 | 1375 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, |
c906108c SS |
1376 | (struct symtab **) NULL); |
1377 | if (sym) | |
1378 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); | |
7ba81444 MS |
1379 | else /* TYPE_CODE_UNDEF */ |
1380 | TYPE_TARGET_TYPE (type) = alloc_type (NULL); | |
c906108c SS |
1381 | } |
1382 | type = TYPE_TARGET_TYPE (type); | |
1383 | } | |
1384 | ||
a02fd225 DJ |
1385 | is_const = TYPE_CONST (type); |
1386 | is_volatile = TYPE_VOLATILE (type); | |
1387 | ||
7ba81444 MS |
1388 | /* If this is a struct/class/union with no fields, then check |
1389 | whether a full definition exists somewhere else. This is for | |
1390 | systems where a type definition with no fields is issued for such | |
1391 | types, instead of identifying them as stub types in the first | |
1392 | place. */ | |
c5aa993b | 1393 | |
7ba81444 MS |
1394 | if (TYPE_IS_OPAQUE (type) |
1395 | && opaque_type_resolution | |
1396 | && !currently_reading_symtab) | |
c906108c | 1397 | { |
c5aa993b JM |
1398 | char *name = type_name_no_tag (type); |
1399 | struct type *newtype; | |
c906108c SS |
1400 | if (name == NULL) |
1401 | { | |
23136709 | 1402 | stub_noname_complaint (); |
c906108c SS |
1403 | return type; |
1404 | } | |
1405 | newtype = lookup_transparent_type (name); | |
ad766c0a | 1406 | |
c906108c | 1407 | if (newtype) |
ad766c0a | 1408 | { |
7ba81444 MS |
1409 | /* If the resolved type and the stub are in the same |
1410 | objfile, then replace the stub type with the real deal. | |
1411 | But if they're in separate objfiles, leave the stub | |
1412 | alone; we'll just look up the transparent type every time | |
1413 | we call check_typedef. We can't create pointers between | |
1414 | types allocated to different objfiles, since they may | |
1415 | have different lifetimes. Trying to copy NEWTYPE over to | |
1416 | TYPE's objfile is pointless, too, since you'll have to | |
1417 | move over any other types NEWTYPE refers to, which could | |
1418 | be an unbounded amount of stuff. */ | |
ad766c0a JB |
1419 | if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type)) |
1420 | make_cv_type (is_const, is_volatile, newtype, &type); | |
1421 | else | |
1422 | type = newtype; | |
1423 | } | |
c906108c | 1424 | } |
7ba81444 MS |
1425 | /* Otherwise, rely on the stub flag being set for opaque/stubbed |
1426 | types. */ | |
74a9bb82 | 1427 | else if (TYPE_STUB (type) && !currently_reading_symtab) |
c906108c | 1428 | { |
c5aa993b | 1429 | char *name = type_name_no_tag (type); |
c906108c | 1430 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
176620f1 | 1431 | TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN |
7b83ea04 AC |
1432 | as appropriate? (this code was written before TYPE_NAME and |
1433 | TYPE_TAG_NAME were separate). */ | |
c906108c SS |
1434 | struct symbol *sym; |
1435 | if (name == NULL) | |
1436 | { | |
23136709 | 1437 | stub_noname_complaint (); |
c906108c SS |
1438 | return type; |
1439 | } | |
7ba81444 MS |
1440 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, |
1441 | 0, (struct symtab **) NULL); | |
c906108c | 1442 | if (sym) |
c26f2453 JB |
1443 | { |
1444 | /* Same as above for opaque types, we can replace the stub | |
1445 | with the complete type only if they are int the same | |
1446 | objfile. */ | |
1447 | if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type)) | |
7ba81444 MS |
1448 | make_cv_type (is_const, is_volatile, |
1449 | SYMBOL_TYPE (sym), &type); | |
c26f2453 JB |
1450 | else |
1451 | type = SYMBOL_TYPE (sym); | |
1452 | } | |
c906108c SS |
1453 | } |
1454 | ||
74a9bb82 | 1455 | if (TYPE_TARGET_STUB (type)) |
c906108c SS |
1456 | { |
1457 | struct type *range_type; | |
1458 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1459 | ||
74a9bb82 | 1460 | if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type)) |
c5aa993b | 1461 | { |
7ba81444 | 1462 | /* Empty. */ |
c5aa993b | 1463 | } |
c906108c SS |
1464 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
1465 | && TYPE_NFIELDS (type) == 1 | |
1466 | && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0)) | |
1467 | == TYPE_CODE_RANGE)) | |
1468 | { | |
1469 | /* Now recompute the length of the array type, based on its | |
1470 | number of elements and the target type's length. */ | |
1471 | TYPE_LENGTH (type) = | |
1472 | ((TYPE_FIELD_BITPOS (range_type, 1) | |
7ba81444 | 1473 | - TYPE_FIELD_BITPOS (range_type, 0) + 1) |
c906108c SS |
1474 | * TYPE_LENGTH (target_type)); |
1475 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1476 | } | |
1477 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) | |
1478 | { | |
1479 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); | |
1480 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1481 | } | |
1482 | } | |
7ba81444 | 1483 | /* Cache TYPE_LENGTH for future use. */ |
c906108c SS |
1484 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); |
1485 | return type; | |
1486 | } | |
1487 | ||
7ba81444 MS |
1488 | /* Parse a type expression in the string [P..P+LENGTH). If an error |
1489 | occurs, silently return builtin_type_void. */ | |
c91ecb25 | 1490 | |
b9362cc7 | 1491 | static struct type * |
c91ecb25 ND |
1492 | safe_parse_type (char *p, int length) |
1493 | { | |
1494 | struct ui_file *saved_gdb_stderr; | |
1495 | struct type *type; | |
1496 | ||
7ba81444 | 1497 | /* Suppress error messages. */ |
c91ecb25 ND |
1498 | saved_gdb_stderr = gdb_stderr; |
1499 | gdb_stderr = ui_file_new (); | |
1500 | ||
7ba81444 | 1501 | /* Call parse_and_eval_type() without fear of longjmp()s. */ |
c91ecb25 ND |
1502 | if (!gdb_parse_and_eval_type (p, length, &type)) |
1503 | type = builtin_type_void; | |
1504 | ||
7ba81444 | 1505 | /* Stop suppressing error messages. */ |
c91ecb25 ND |
1506 | ui_file_delete (gdb_stderr); |
1507 | gdb_stderr = saved_gdb_stderr; | |
1508 | ||
1509 | return type; | |
1510 | } | |
1511 | ||
c906108c SS |
1512 | /* Ugly hack to convert method stubs into method types. |
1513 | ||
7ba81444 MS |
1514 | He ain't kiddin'. This demangles the name of the method into a |
1515 | string including argument types, parses out each argument type, | |
1516 | generates a string casting a zero to that type, evaluates the | |
1517 | string, and stuffs the resulting type into an argtype vector!!! | |
1518 | Then it knows the type of the whole function (including argument | |
1519 | types for overloading), which info used to be in the stab's but was | |
1520 | removed to hack back the space required for them. */ | |
c906108c | 1521 | |
de17c821 | 1522 | static void |
fba45db2 | 1523 | check_stub_method (struct type *type, int method_id, int signature_id) |
c906108c SS |
1524 | { |
1525 | struct fn_field *f; | |
1526 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); | |
1527 | char *demangled_name = cplus_demangle (mangled_name, | |
1528 | DMGL_PARAMS | DMGL_ANSI); | |
1529 | char *argtypetext, *p; | |
1530 | int depth = 0, argcount = 1; | |
ad2f7632 | 1531 | struct field *argtypes; |
c906108c SS |
1532 | struct type *mtype; |
1533 | ||
1534 | /* Make sure we got back a function string that we can use. */ | |
1535 | if (demangled_name) | |
1536 | p = strchr (demangled_name, '('); | |
502dcf4e AC |
1537 | else |
1538 | p = NULL; | |
c906108c SS |
1539 | |
1540 | if (demangled_name == NULL || p == NULL) | |
7ba81444 MS |
1541 | error (_("Internal: Cannot demangle mangled name `%s'."), |
1542 | mangled_name); | |
c906108c SS |
1543 | |
1544 | /* Now, read in the parameters that define this type. */ | |
1545 | p += 1; | |
1546 | argtypetext = p; | |
1547 | while (*p) | |
1548 | { | |
070ad9f0 | 1549 | if (*p == '(' || *p == '<') |
c906108c SS |
1550 | { |
1551 | depth += 1; | |
1552 | } | |
070ad9f0 | 1553 | else if (*p == ')' || *p == '>') |
c906108c SS |
1554 | { |
1555 | depth -= 1; | |
1556 | } | |
1557 | else if (*p == ',' && depth == 0) | |
1558 | { | |
1559 | argcount += 1; | |
1560 | } | |
1561 | ||
1562 | p += 1; | |
1563 | } | |
1564 | ||
ad2f7632 DJ |
1565 | /* If we read one argument and it was ``void'', don't count it. */ |
1566 | if (strncmp (argtypetext, "(void)", 6) == 0) | |
1567 | argcount -= 1; | |
c906108c | 1568 | |
ad2f7632 DJ |
1569 | /* We need one extra slot, for the THIS pointer. */ |
1570 | ||
1571 | argtypes = (struct field *) | |
1572 | TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field)); | |
c906108c | 1573 | p = argtypetext; |
4a1970e4 DJ |
1574 | |
1575 | /* Add THIS pointer for non-static methods. */ | |
1576 | f = TYPE_FN_FIELDLIST1 (type, method_id); | |
1577 | if (TYPE_FN_FIELD_STATIC_P (f, signature_id)) | |
1578 | argcount = 0; | |
1579 | else | |
1580 | { | |
ad2f7632 | 1581 | argtypes[0].type = lookup_pointer_type (type); |
4a1970e4 DJ |
1582 | argcount = 1; |
1583 | } | |
c906108c | 1584 | |
c5aa993b | 1585 | if (*p != ')') /* () means no args, skip while */ |
c906108c SS |
1586 | { |
1587 | depth = 0; | |
1588 | while (*p) | |
1589 | { | |
1590 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
1591 | { | |
ad2f7632 DJ |
1592 | /* Avoid parsing of ellipsis, they will be handled below. |
1593 | Also avoid ``void'' as above. */ | |
1594 | if (strncmp (argtypetext, "...", p - argtypetext) != 0 | |
1595 | && strncmp (argtypetext, "void", p - argtypetext) != 0) | |
c906108c | 1596 | { |
ad2f7632 | 1597 | argtypes[argcount].type = |
c91ecb25 | 1598 | safe_parse_type (argtypetext, p - argtypetext); |
c906108c SS |
1599 | argcount += 1; |
1600 | } | |
1601 | argtypetext = p + 1; | |
1602 | } | |
1603 | ||
070ad9f0 | 1604 | if (*p == '(' || *p == '<') |
c906108c SS |
1605 | { |
1606 | depth += 1; | |
1607 | } | |
070ad9f0 | 1608 | else if (*p == ')' || *p == '>') |
c906108c SS |
1609 | { |
1610 | depth -= 1; | |
1611 | } | |
1612 | ||
1613 | p += 1; | |
1614 | } | |
1615 | } | |
1616 | ||
c906108c SS |
1617 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; |
1618 | ||
1619 | /* Now update the old "stub" type into a real type. */ | |
1620 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); | |
1621 | TYPE_DOMAIN_TYPE (mtype) = type; | |
ad2f7632 DJ |
1622 | TYPE_FIELDS (mtype) = argtypes; |
1623 | TYPE_NFIELDS (mtype) = argcount; | |
c906108c SS |
1624 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; |
1625 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; | |
ad2f7632 DJ |
1626 | if (p[-2] == '.') |
1627 | TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS; | |
1628 | ||
1629 | xfree (demangled_name); | |
c906108c SS |
1630 | } |
1631 | ||
7ba81444 MS |
1632 | /* This is the external interface to check_stub_method, above. This |
1633 | function unstubs all of the signatures for TYPE's METHOD_ID method | |
1634 | name. After calling this function TYPE_FN_FIELD_STUB will be | |
1635 | cleared for each signature and TYPE_FN_FIELDLIST_NAME will be | |
1636 | correct. | |
de17c821 DJ |
1637 | |
1638 | This function unfortunately can not die until stabs do. */ | |
1639 | ||
1640 | void | |
1641 | check_stub_method_group (struct type *type, int method_id) | |
1642 | { | |
1643 | int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id); | |
1644 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id); | |
f710f4fc | 1645 | int j, found_stub = 0; |
de17c821 DJ |
1646 | |
1647 | for (j = 0; j < len; j++) | |
1648 | if (TYPE_FN_FIELD_STUB (f, j)) | |
1649 | { | |
1650 | found_stub = 1; | |
1651 | check_stub_method (type, method_id, j); | |
1652 | } | |
1653 | ||
7ba81444 MS |
1654 | /* GNU v3 methods with incorrect names were corrected when we read |
1655 | in type information, because it was cheaper to do it then. The | |
1656 | only GNU v2 methods with incorrect method names are operators and | |
1657 | destructors; destructors were also corrected when we read in type | |
1658 | information. | |
de17c821 DJ |
1659 | |
1660 | Therefore the only thing we need to handle here are v2 operator | |
1661 | names. */ | |
1662 | if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0) | |
1663 | { | |
1664 | int ret; | |
1665 | char dem_opname[256]; | |
1666 | ||
7ba81444 MS |
1667 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, |
1668 | method_id), | |
de17c821 DJ |
1669 | dem_opname, DMGL_ANSI); |
1670 | if (!ret) | |
7ba81444 MS |
1671 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, |
1672 | method_id), | |
de17c821 DJ |
1673 | dem_opname, 0); |
1674 | if (ret) | |
1675 | TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname); | |
1676 | } | |
1677 | } | |
1678 | ||
c906108c SS |
1679 | const struct cplus_struct_type cplus_struct_default; |
1680 | ||
1681 | void | |
fba45db2 | 1682 | allocate_cplus_struct_type (struct type *type) |
c906108c SS |
1683 | { |
1684 | if (!HAVE_CPLUS_STRUCT (type)) | |
1685 | { | |
1686 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
1687 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); | |
c5aa993b | 1688 | *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default; |
c906108c SS |
1689 | } |
1690 | } | |
1691 | ||
1692 | /* Helper function to initialize the standard scalar types. | |
1693 | ||
7ba81444 MS |
1694 | If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of |
1695 | the string pointed to by name in the objfile_obstack for that | |
1696 | objfile, and initialize the type name to that copy. There are | |
1697 | places (mipsread.c in particular, where init_type is called with a | |
1698 | NULL value for NAME). */ | |
c906108c SS |
1699 | |
1700 | struct type * | |
7ba81444 MS |
1701 | init_type (enum type_code code, int length, int flags, |
1702 | char *name, struct objfile *objfile) | |
c906108c | 1703 | { |
52f0bd74 | 1704 | struct type *type; |
c906108c SS |
1705 | |
1706 | type = alloc_type (objfile); | |
1707 | TYPE_CODE (type) = code; | |
1708 | TYPE_LENGTH (type) = length; | |
1709 | TYPE_FLAGS (type) |= flags; | |
1710 | if ((name != NULL) && (objfile != NULL)) | |
1711 | { | |
7ba81444 MS |
1712 | TYPE_NAME (type) = obsavestring (name, strlen (name), |
1713 | &objfile->objfile_obstack); | |
c906108c SS |
1714 | } |
1715 | else | |
1716 | { | |
1717 | TYPE_NAME (type) = name; | |
1718 | } | |
1719 | ||
1720 | /* C++ fancies. */ | |
1721 | ||
973ccf8b DJ |
1722 | if (name && strcmp (name, "char") == 0) |
1723 | TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN; | |
1724 | ||
5c4e30ca DC |
1725 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION |
1726 | || code == TYPE_CODE_NAMESPACE) | |
c906108c SS |
1727 | { |
1728 | INIT_CPLUS_SPECIFIC (type); | |
1729 | } | |
1730 | return (type); | |
1731 | } | |
1732 | ||
0e101458 AC |
1733 | /* Helper function. Create an empty composite type. */ |
1734 | ||
1735 | struct type * | |
1736 | init_composite_type (char *name, enum type_code code) | |
1737 | { | |
1738 | struct type *t; | |
1739 | gdb_assert (code == TYPE_CODE_STRUCT | |
1740 | || code == TYPE_CODE_UNION); | |
1741 | t = init_type (code, 0, 0, NULL, NULL); | |
1742 | TYPE_TAG_NAME (t) = name; | |
1743 | return t; | |
1744 | } | |
1745 | ||
1746 | /* Helper function. Append a field to a composite type. */ | |
1747 | ||
1748 | void | |
7ba81444 MS |
1749 | append_composite_type_field (struct type *t, char *name, |
1750 | struct type *field) | |
0e101458 AC |
1751 | { |
1752 | struct field *f; | |
1753 | TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1; | |
1754 | TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t), | |
1755 | sizeof (struct field) * TYPE_NFIELDS (t)); | |
1756 | f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]); | |
1757 | memset (f, 0, sizeof f[0]); | |
1758 | FIELD_TYPE (f[0]) = field; | |
1759 | FIELD_NAME (f[0]) = name; | |
1760 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
1761 | { | |
73d322b1 | 1762 | if (TYPE_LENGTH (t) < TYPE_LENGTH (field)) |
0e101458 AC |
1763 | TYPE_LENGTH (t) = TYPE_LENGTH (field); |
1764 | } | |
1765 | else if (TYPE_CODE (t) == TYPE_CODE_STRUCT) | |
1766 | { | |
1767 | TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field); | |
1768 | if (TYPE_NFIELDS (t) > 1) | |
1769 | { | |
1770 | FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1]) | |
1771 | + TYPE_LENGTH (field) * TARGET_CHAR_BIT); | |
1772 | } | |
1773 | } | |
1774 | } | |
1775 | ||
c906108c SS |
1776 | /* Look up a fundamental type for the specified objfile. |
1777 | May need to construct such a type if this is the first use. | |
1778 | ||
1779 | Some object file formats (ELF, COFF, etc) do not define fundamental | |
1780 | types such as "int" or "double". Others (stabs for example), do | |
1781 | define fundamental types. | |
1782 | ||
7ba81444 MS |
1783 | For the formats which don't provide fundamental types, gdb can |
1784 | create such types, using defaults reasonable for the current | |
1785 | language and the current target machine. | |
c906108c | 1786 | |
7ba81444 | 1787 | NOTE: This routine is obsolescent. Each debugging format reader |
c906108c SS |
1788 | should manage it's own fundamental types, either creating them from |
1789 | suitable defaults or reading them from the debugging information, | |
7ba81444 MS |
1790 | whichever is appropriate. The DWARF reader has already been fixed |
1791 | to do this. Once the other readers are fixed, this routine will go | |
1792 | away. Also note that fundamental types should be managed on a | |
1793 | compilation unit basis in a multi-language environment, not on a | |
1794 | linkage unit basis as is done here. */ | |
c906108c SS |
1795 | |
1796 | ||
1797 | struct type * | |
fba45db2 | 1798 | lookup_fundamental_type (struct objfile *objfile, int typeid) |
c906108c | 1799 | { |
52f0bd74 AC |
1800 | struct type **typep; |
1801 | int nbytes; | |
c906108c SS |
1802 | |
1803 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
1804 | { | |
7ba81444 MS |
1805 | error (_("internal error - invalid fundamental type id %d"), |
1806 | typeid); | |
c906108c SS |
1807 | } |
1808 | ||
7ba81444 MS |
1809 | /* If this is the first time we need a fundamental type for this |
1810 | objfile then we need to initialize the vector of type | |
1811 | pointers. */ | |
c5aa993b JM |
1812 | |
1813 | if (objfile->fundamental_types == NULL) | |
c906108c SS |
1814 | { |
1815 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); | |
c5aa993b | 1816 | objfile->fundamental_types = (struct type **) |
b99607ea | 1817 | obstack_alloc (&objfile->objfile_obstack, nbytes); |
c5aa993b | 1818 | memset ((char *) objfile->fundamental_types, 0, nbytes); |
c906108c SS |
1819 | OBJSTAT (objfile, n_types += FT_NUM_MEMBERS); |
1820 | } | |
1821 | ||
7ba81444 MS |
1822 | /* Look for this particular type in the fundamental type vector. If |
1823 | one is not found, create and install one appropriate for the | |
1824 | current language. */ | |
c906108c | 1825 | |
c5aa993b | 1826 | typep = objfile->fundamental_types + typeid; |
c906108c SS |
1827 | if (*typep == NULL) |
1828 | { | |
1829 | *typep = create_fundamental_type (objfile, typeid); | |
1830 | } | |
1831 | ||
1832 | return (*typep); | |
1833 | } | |
1834 | ||
1835 | int | |
fba45db2 | 1836 | can_dereference (struct type *t) |
c906108c | 1837 | { |
7ba81444 MS |
1838 | /* FIXME: Should we return true for references as well as |
1839 | pointers? */ | |
c906108c SS |
1840 | CHECK_TYPEDEF (t); |
1841 | return | |
1842 | (t != NULL | |
1843 | && TYPE_CODE (t) == TYPE_CODE_PTR | |
1844 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); | |
1845 | } | |
1846 | ||
adf40b2e | 1847 | int |
fba45db2 | 1848 | is_integral_type (struct type *t) |
adf40b2e JM |
1849 | { |
1850 | CHECK_TYPEDEF (t); | |
1851 | return | |
1852 | ((t != NULL) | |
d4f3574e SS |
1853 | && ((TYPE_CODE (t) == TYPE_CODE_INT) |
1854 | || (TYPE_CODE (t) == TYPE_CODE_ENUM) | |
4f2aea11 | 1855 | || (TYPE_CODE (t) == TYPE_CODE_FLAGS) |
d4f3574e SS |
1856 | || (TYPE_CODE (t) == TYPE_CODE_CHAR) |
1857 | || (TYPE_CODE (t) == TYPE_CODE_RANGE) | |
1858 | || (TYPE_CODE (t) == TYPE_CODE_BOOL))); | |
adf40b2e JM |
1859 | } |
1860 | ||
7b83ea04 | 1861 | /* Check whether BASE is an ancestor or base class or DCLASS |
c906108c SS |
1862 | Return 1 if so, and 0 if not. |
1863 | Note: callers may want to check for identity of the types before | |
1864 | calling this function -- identical types are considered to satisfy | |
7ba81444 | 1865 | the ancestor relationship even if they're identical. */ |
c906108c SS |
1866 | |
1867 | int | |
fba45db2 | 1868 | is_ancestor (struct type *base, struct type *dclass) |
c906108c SS |
1869 | { |
1870 | int i; | |
c5aa993b | 1871 | |
c906108c SS |
1872 | CHECK_TYPEDEF (base); |
1873 | CHECK_TYPEDEF (dclass); | |
1874 | ||
1875 | if (base == dclass) | |
1876 | return 1; | |
687d6395 MS |
1877 | if (TYPE_NAME (base) && TYPE_NAME (dclass) |
1878 | && !strcmp (TYPE_NAME (base), TYPE_NAME (dclass))) | |
6b1ba9a0 | 1879 | return 1; |
c906108c SS |
1880 | |
1881 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1882 | if (is_ancestor (base, TYPE_BASECLASS (dclass, i))) | |
1883 | return 1; | |
1884 | ||
1885 | return 0; | |
1886 | } | |
1887 | ||
1888 | ||
1889 | ||
1890 | /* See whether DCLASS has a virtual table. This routine is aimed at | |
1891 | the HP/Taligent ANSI C++ runtime model, and may not work with other | |
1892 | runtime models. Return 1 => Yes, 0 => No. */ | |
1893 | ||
1894 | int | |
fba45db2 | 1895 | has_vtable (struct type *dclass) |
c906108c SS |
1896 | { |
1897 | /* In the HP ANSI C++ runtime model, a class has a vtable only if it | |
1898 | has virtual functions or virtual bases. */ | |
1899 | ||
52f0bd74 | 1900 | int i; |
c906108c | 1901 | |
c5aa993b | 1902 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c | 1903 | return 0; |
c5aa993b | 1904 | |
7ba81444 | 1905 | /* First check for the presence of virtual bases. */ |
c5aa993b JM |
1906 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) |
1907 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1908 | if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) | |
1909 | return 1; | |
1910 | ||
7ba81444 | 1911 | /* Next check for virtual functions. */ |
c5aa993b JM |
1912 | if (TYPE_FN_FIELDLISTS (dclass)) |
1913 | for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++) | |
1914 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0)) | |
c906108c | 1915 | return 1; |
c5aa993b | 1916 | |
7ba81444 MS |
1917 | /* Recurse on non-virtual bases to see if any of them needs a |
1918 | vtable. */ | |
c5aa993b JM |
1919 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) |
1920 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
687d6395 MS |
1921 | if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) |
1922 | && (has_vtable (TYPE_FIELD_TYPE (dclass, i)))) | |
c5aa993b JM |
1923 | return 1; |
1924 | ||
7ba81444 | 1925 | /* Well, maybe we don't need a virtual table. */ |
c906108c SS |
1926 | return 0; |
1927 | } | |
1928 | ||
1929 | /* Return a pointer to the "primary base class" of DCLASS. | |
c5aa993b | 1930 | |
c906108c SS |
1931 | A NULL return indicates that DCLASS has no primary base, or that it |
1932 | couldn't be found (insufficient information). | |
c5aa993b | 1933 | |
c906108c SS |
1934 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
1935 | and may not work with other runtime models. */ | |
1936 | ||
1937 | struct type * | |
fba45db2 | 1938 | primary_base_class (struct type *dclass) |
c906108c SS |
1939 | { |
1940 | /* In HP ANSI C++'s runtime model, a "primary base class" of a class | |
1941 | is the first directly inherited, non-virtual base class that | |
7ba81444 | 1942 | requires a virtual table. */ |
c906108c | 1943 | |
52f0bd74 | 1944 | int i; |
c906108c | 1945 | |
c5aa993b | 1946 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c SS |
1947 | return NULL; |
1948 | ||
c5aa993b | 1949 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
687d6395 MS |
1950 | if (!TYPE_FIELD_VIRTUAL (dclass, i) |
1951 | && has_vtable (TYPE_FIELD_TYPE (dclass, i))) | |
c5aa993b | 1952 | return TYPE_FIELD_TYPE (dclass, i); |
c906108c SS |
1953 | |
1954 | return NULL; | |
1955 | } | |
1956 | ||
7ba81444 | 1957 | /* Global manipulated by virtual_base_list[_aux](). */ |
c906108c | 1958 | |
c5aa993b | 1959 | static struct vbase *current_vbase_list = NULL; |
c906108c | 1960 | |
7ba81444 MS |
1961 | /* Return a pointer to a null-terminated list of struct vbase items. |
1962 | The vbasetype pointer of each item in the list points to the type | |
1963 | information for a virtual base of the argument DCLASS. | |
c5aa993b | 1964 | |
7b83ea04 | 1965 | Helper function for virtual_base_list(). |
7ba81444 MS |
1966 | Note: the list goes backward, right-to-left. |
1967 | virtual_base_list() copies the items out in reverse order. */ | |
c906108c | 1968 | |
7a292a7a | 1969 | static void |
fba45db2 | 1970 | virtual_base_list_aux (struct type *dclass) |
c906108c | 1971 | { |
c5aa993b | 1972 | struct vbase *tmp_vbase; |
52f0bd74 | 1973 | int i; |
c906108c | 1974 | |
c5aa993b | 1975 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
7a292a7a | 1976 | return; |
c906108c SS |
1977 | |
1978 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1979 | { | |
1980 | /* Recurse on this ancestor, first */ | |
c5aa993b | 1981 | virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i)); |
c906108c SS |
1982 | |
1983 | /* If this current base is itself virtual, add it to the list */ | |
c5aa993b JM |
1984 | if (BASETYPE_VIA_VIRTUAL (dclass, i)) |
1985 | { | |
1986 | struct type *basetype = TYPE_FIELD_TYPE (dclass, i); | |
1987 | ||
1988 | /* Check if base already recorded */ | |
1989 | tmp_vbase = current_vbase_list; | |
1990 | while (tmp_vbase) | |
1991 | { | |
1992 | if (tmp_vbase->vbasetype == basetype) | |
1993 | break; /* found it */ | |
1994 | tmp_vbase = tmp_vbase->next; | |
1995 | } | |
1996 | ||
1997 | if (!tmp_vbase) /* normal exit from loop */ | |
1998 | { | |
1999 | /* Allocate new item for this virtual base */ | |
2000 | tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase)); | |
2001 | ||
2002 | /* Stick it on at the end of the list */ | |
2003 | tmp_vbase->vbasetype = basetype; | |
2004 | tmp_vbase->next = current_vbase_list; | |
2005 | current_vbase_list = tmp_vbase; | |
2006 | } | |
2007 | } /* if virtual */ | |
2008 | } /* for loop over bases */ | |
c906108c SS |
2009 | } |
2010 | ||
2011 | ||
2012 | /* Compute the list of virtual bases in the right order. Virtual | |
2013 | bases are laid out in the object's memory area in order of their | |
2014 | occurrence in a depth-first, left-to-right search through the | |
2015 | ancestors. | |
c5aa993b | 2016 | |
c906108c SS |
2017 | Argument DCLASS is the type whose virtual bases are required. |
2018 | Return value is the address of a null-terminated array of pointers | |
2019 | to struct type items. | |
c5aa993b | 2020 | |
c906108c SS |
2021 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
2022 | and may not work with other runtime models. | |
c5aa993b | 2023 | |
c906108c SS |
2024 | This routine merely hands off the argument to virtual_base_list_aux() |
2025 | and then copies the result into an array to save space. */ | |
2026 | ||
2027 | struct type ** | |
fba45db2 | 2028 | virtual_base_list (struct type *dclass) |
c906108c | 2029 | { |
52f0bd74 AC |
2030 | struct vbase *tmp_vbase; |
2031 | struct vbase *tmp_vbase_2; | |
2032 | int i; | |
c906108c | 2033 | int count; |
c5aa993b | 2034 | struct type **vbase_array; |
c906108c SS |
2035 | |
2036 | current_vbase_list = NULL; | |
c5aa993b | 2037 | virtual_base_list_aux (dclass); |
c906108c | 2038 | |
7ba81444 MS |
2039 | for (i = 0, tmp_vbase = current_vbase_list; |
2040 | tmp_vbase != NULL; | |
2041 | i++, tmp_vbase = tmp_vbase->next) | |
c906108c SS |
2042 | /* no body */ ; |
2043 | ||
2044 | count = i; | |
2045 | ||
7ba81444 MS |
2046 | vbase_array = (struct type **) |
2047 | xmalloc ((count + 1) * sizeof (struct type *)); | |
c906108c | 2048 | |
7ba81444 MS |
2049 | for (i = count - 1, tmp_vbase = current_vbase_list; |
2050 | i >= 0; i--, | |
2051 | tmp_vbase = tmp_vbase->next) | |
c906108c SS |
2052 | vbase_array[i] = tmp_vbase->vbasetype; |
2053 | ||
7ba81444 | 2054 | /* Get rid of constructed chain. */ |
c906108c SS |
2055 | tmp_vbase_2 = tmp_vbase = current_vbase_list; |
2056 | while (tmp_vbase) | |
2057 | { | |
2058 | tmp_vbase = tmp_vbase->next; | |
b8c9b27d | 2059 | xfree (tmp_vbase_2); |
c906108c SS |
2060 | tmp_vbase_2 = tmp_vbase; |
2061 | } | |
c5aa993b | 2062 | |
c906108c SS |
2063 | vbase_array[count] = NULL; |
2064 | return vbase_array; | |
2065 | } | |
2066 | ||
2067 | /* Return the length of the virtual base list of the type DCLASS. */ | |
2068 | ||
2069 | int | |
fba45db2 | 2070 | virtual_base_list_length (struct type *dclass) |
c906108c | 2071 | { |
52f0bd74 AC |
2072 | int i; |
2073 | struct vbase *tmp_vbase; | |
c5aa993b | 2074 | |
c906108c | 2075 | current_vbase_list = NULL; |
c5aa993b | 2076 | virtual_base_list_aux (dclass); |
c906108c | 2077 | |
7ba81444 MS |
2078 | for (i = 0, tmp_vbase = current_vbase_list; |
2079 | tmp_vbase != NULL; | |
2080 | i++, tmp_vbase = tmp_vbase->next) | |
c906108c SS |
2081 | /* no body */ ; |
2082 | return i; | |
2083 | } | |
2084 | ||
2085 | /* Return the number of elements of the virtual base list of the type | |
2086 | DCLASS, ignoring those appearing in the primary base (and its | |
2087 | primary base, recursively). */ | |
2088 | ||
2089 | int | |
fba45db2 | 2090 | virtual_base_list_length_skip_primaries (struct type *dclass) |
c906108c | 2091 | { |
52f0bd74 AC |
2092 | int i; |
2093 | struct vbase *tmp_vbase; | |
c5aa993b | 2094 | struct type *primary; |
c906108c SS |
2095 | |
2096 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; | |
2097 | ||
2098 | if (!primary) | |
2099 | return virtual_base_list_length (dclass); | |
2100 | ||
2101 | current_vbase_list = NULL; | |
c5aa993b | 2102 | virtual_base_list_aux (dclass); |
c906108c | 2103 | |
7ba81444 MS |
2104 | for (i = 0, tmp_vbase = current_vbase_list; |
2105 | tmp_vbase != NULL; | |
2106 | tmp_vbase = tmp_vbase->next) | |
c906108c SS |
2107 | { |
2108 | if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0) | |
c5aa993b | 2109 | continue; |
c906108c SS |
2110 | i++; |
2111 | } | |
2112 | return i; | |
2113 | } | |
2114 | ||
2115 | ||
2116 | /* Return the index (position) of type BASE, which is a virtual base | |
2117 | class of DCLASS, in the latter's virtual base list. A return of -1 | |
2118 | indicates "not found" or a problem. */ | |
2119 | ||
2120 | int | |
fba45db2 | 2121 | virtual_base_index (struct type *base, struct type *dclass) |
c906108c | 2122 | { |
52f0bd74 AC |
2123 | struct type *vbase; |
2124 | int i; | |
c906108c | 2125 | |
687d6395 MS |
2126 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
2127 | || (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
2128 | return -1; |
2129 | ||
2130 | i = 0; | |
015a42b4 | 2131 | vbase = virtual_base_list (dclass)[0]; |
c906108c SS |
2132 | while (vbase) |
2133 | { | |
2134 | if (vbase == base) | |
c5aa993b | 2135 | break; |
015a42b4 | 2136 | vbase = virtual_base_list (dclass)[++i]; |
c906108c SS |
2137 | } |
2138 | ||
2139 | return vbase ? i : -1; | |
2140 | } | |
2141 | ||
2142 | ||
2143 | ||
2144 | /* Return the index (position) of type BASE, which is a virtual base | |
7ba81444 | 2145 | class of DCLASS, in the latter's virtual base list. Skip over all |
c906108c SS |
2146 | bases that may appear in the virtual base list of the primary base |
2147 | class of DCLASS (recursively). A return of -1 indicates "not | |
2148 | found" or a problem. */ | |
2149 | ||
2150 | int | |
7ba81444 MS |
2151 | virtual_base_index_skip_primaries (struct type *base, |
2152 | struct type *dclass) | |
c906108c | 2153 | { |
52f0bd74 AC |
2154 | struct type *vbase; |
2155 | int i, j; | |
c5aa993b | 2156 | struct type *primary; |
c906108c | 2157 | |
687d6395 MS |
2158 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
2159 | || (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
2160 | return -1; |
2161 | ||
c5aa993b | 2162 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; |
c906108c SS |
2163 | |
2164 | j = -1; | |
2165 | i = 0; | |
015a42b4 | 2166 | vbase = virtual_base_list (dclass)[0]; |
c906108c SS |
2167 | while (vbase) |
2168 | { | |
7ba81444 MS |
2169 | if (!primary |
2170 | || (virtual_base_index_skip_primaries (vbase, primary) < 0)) | |
c5aa993b | 2171 | j++; |
c906108c | 2172 | if (vbase == base) |
c5aa993b | 2173 | break; |
015a42b4 | 2174 | vbase = virtual_base_list (dclass)[++i]; |
c906108c SS |
2175 | } |
2176 | ||
2177 | return vbase ? j : -1; | |
2178 | } | |
2179 | ||
7ba81444 MS |
2180 | /* Return position of a derived class DCLASS in the list of primary |
2181 | bases starting with the remotest ancestor. Position returned is | |
2182 | 0-based. */ | |
c906108c SS |
2183 | |
2184 | int | |
fba45db2 | 2185 | class_index_in_primary_list (struct type *dclass) |
c906108c | 2186 | { |
c5aa993b | 2187 | struct type *pbc; /* primary base class */ |
c906108c | 2188 | |
c5aa993b | 2189 | /* Simply recurse on primary base */ |
c906108c SS |
2190 | pbc = TYPE_PRIMARY_BASE (dclass); |
2191 | if (pbc) | |
2192 | return 1 + class_index_in_primary_list (pbc); | |
2193 | else | |
2194 | return 0; | |
2195 | } | |
2196 | ||
7ba81444 MS |
2197 | /* Return a count of the number of virtual functions a type has. This |
2198 | includes all the virtual functions it inherits from its base | |
2199 | classes too. */ | |
c906108c SS |
2200 | |
2201 | /* pai: FIXME This doesn't do the right thing: count redefined virtual | |
7ba81444 | 2202 | functions only once (latest redefinition). */ |
c906108c SS |
2203 | |
2204 | int | |
fba45db2 | 2205 | count_virtual_fns (struct type *dclass) |
c906108c | 2206 | { |
c5aa993b | 2207 | int fn, oi; /* function and overloaded instance indices */ |
c5aa993b JM |
2208 | int vfuncs; /* count to return */ |
2209 | ||
2210 | /* recurse on bases that can share virtual table */ | |
2211 | struct type *pbc = primary_base_class (dclass); | |
c906108c SS |
2212 | if (pbc) |
2213 | vfuncs = count_virtual_fns (pbc); | |
7f7e9482 AC |
2214 | else |
2215 | vfuncs = 0; | |
c5aa993b | 2216 | |
c906108c SS |
2217 | for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++) |
2218 | for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++) | |
2219 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi)) | |
c5aa993b | 2220 | vfuncs++; |
c906108c SS |
2221 | |
2222 | return vfuncs; | |
2223 | } | |
c906108c SS |
2224 | \f |
2225 | ||
c5aa993b | 2226 | |
c906108c SS |
2227 | /* Functions for overload resolution begin here */ |
2228 | ||
2229 | /* Compare two badness vectors A and B and return the result. | |
7ba81444 MS |
2230 | 0 => A and B are identical |
2231 | 1 => A and B are incomparable | |
2232 | 2 => A is better than B | |
2233 | 3 => A is worse than B */ | |
c906108c SS |
2234 | |
2235 | int | |
fba45db2 | 2236 | compare_badness (struct badness_vector *a, struct badness_vector *b) |
c906108c SS |
2237 | { |
2238 | int i; | |
2239 | int tmp; | |
c5aa993b JM |
2240 | short found_pos = 0; /* any positives in c? */ |
2241 | short found_neg = 0; /* any negatives in c? */ | |
2242 | ||
2243 | /* differing lengths => incomparable */ | |
c906108c SS |
2244 | if (a->length != b->length) |
2245 | return 1; | |
2246 | ||
c5aa993b JM |
2247 | /* Subtract b from a */ |
2248 | for (i = 0; i < a->length; i++) | |
c906108c SS |
2249 | { |
2250 | tmp = a->rank[i] - b->rank[i]; | |
2251 | if (tmp > 0) | |
c5aa993b | 2252 | found_pos = 1; |
c906108c | 2253 | else if (tmp < 0) |
c5aa993b | 2254 | found_neg = 1; |
c906108c SS |
2255 | } |
2256 | ||
2257 | if (found_pos) | |
2258 | { | |
2259 | if (found_neg) | |
c5aa993b | 2260 | return 1; /* incomparable */ |
c906108c | 2261 | else |
c5aa993b | 2262 | return 3; /* A > B */ |
c906108c | 2263 | } |
c5aa993b JM |
2264 | else |
2265 | /* no positives */ | |
c906108c SS |
2266 | { |
2267 | if (found_neg) | |
c5aa993b | 2268 | return 2; /* A < B */ |
c906108c | 2269 | else |
c5aa993b | 2270 | return 0; /* A == B */ |
c906108c SS |
2271 | } |
2272 | } | |
2273 | ||
7ba81444 MS |
2274 | /* Rank a function by comparing its parameter types (PARMS, length |
2275 | NPARMS), to the types of an argument list (ARGS, length NARGS). | |
2276 | Return a pointer to a badness vector. This has NARGS + 1 | |
2277 | entries. */ | |
c906108c SS |
2278 | |
2279 | struct badness_vector * | |
7ba81444 MS |
2280 | rank_function (struct type **parms, int nparms, |
2281 | struct type **args, int nargs) | |
c906108c SS |
2282 | { |
2283 | int i; | |
c5aa993b | 2284 | struct badness_vector *bv; |
c906108c SS |
2285 | int min_len = nparms < nargs ? nparms : nargs; |
2286 | ||
2287 | bv = xmalloc (sizeof (struct badness_vector)); | |
c5aa993b | 2288 | bv->length = nargs + 1; /* add 1 for the length-match rank */ |
c906108c SS |
2289 | bv->rank = xmalloc ((nargs + 1) * sizeof (int)); |
2290 | ||
2291 | /* First compare the lengths of the supplied lists. | |
7ba81444 | 2292 | If there is a mismatch, set it to a high value. */ |
c5aa993b | 2293 | |
c906108c | 2294 | /* pai/1997-06-03 FIXME: when we have debug info about default |
7ba81444 MS |
2295 | arguments and ellipsis parameter lists, we should consider those |
2296 | and rank the length-match more finely. */ | |
c906108c SS |
2297 | |
2298 | LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0; | |
2299 | ||
2300 | /* Now rank all the parameters of the candidate function */ | |
74cc24b0 DB |
2301 | for (i = 1; i <= min_len; i++) |
2302 | bv->rank[i] = rank_one_type (parms[i-1], args[i-1]); | |
c906108c | 2303 | |
c5aa993b JM |
2304 | /* If more arguments than parameters, add dummy entries */ |
2305 | for (i = min_len + 1; i <= nargs; i++) | |
c906108c SS |
2306 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
2307 | ||
2308 | return bv; | |
2309 | } | |
2310 | ||
973ccf8b DJ |
2311 | /* Compare the names of two integer types, assuming that any sign |
2312 | qualifiers have been checked already. We do it this way because | |
2313 | there may be an "int" in the name of one of the types. */ | |
2314 | ||
2315 | static int | |
2316 | integer_types_same_name_p (const char *first, const char *second) | |
2317 | { | |
2318 | int first_p, second_p; | |
2319 | ||
7ba81444 MS |
2320 | /* If both are shorts, return 1; if neither is a short, keep |
2321 | checking. */ | |
973ccf8b DJ |
2322 | first_p = (strstr (first, "short") != NULL); |
2323 | second_p = (strstr (second, "short") != NULL); | |
2324 | if (first_p && second_p) | |
2325 | return 1; | |
2326 | if (first_p || second_p) | |
2327 | return 0; | |
2328 | ||
2329 | /* Likewise for long. */ | |
2330 | first_p = (strstr (first, "long") != NULL); | |
2331 | second_p = (strstr (second, "long") != NULL); | |
2332 | if (first_p && second_p) | |
2333 | return 1; | |
2334 | if (first_p || second_p) | |
2335 | return 0; | |
2336 | ||
2337 | /* Likewise for char. */ | |
2338 | first_p = (strstr (first, "char") != NULL); | |
2339 | second_p = (strstr (second, "char") != NULL); | |
2340 | if (first_p && second_p) | |
2341 | return 1; | |
2342 | if (first_p || second_p) | |
2343 | return 0; | |
2344 | ||
2345 | /* They must both be ints. */ | |
2346 | return 1; | |
2347 | } | |
2348 | ||
c906108c SS |
2349 | /* Compare one type (PARM) for compatibility with another (ARG). |
2350 | * PARM is intended to be the parameter type of a function; and | |
2351 | * ARG is the supplied argument's type. This function tests if | |
2352 | * the latter can be converted to the former. | |
2353 | * | |
2354 | * Return 0 if they are identical types; | |
2355 | * Otherwise, return an integer which corresponds to how compatible | |
7ba81444 MS |
2356 | * PARM is to ARG. The higher the return value, the worse the match. |
2357 | * Generally the "bad" conversions are all uniformly assigned a 100. */ | |
c906108c SS |
2358 | |
2359 | int | |
fba45db2 | 2360 | rank_one_type (struct type *parm, struct type *arg) |
c906108c | 2361 | { |
7ba81444 | 2362 | /* Identical type pointers. */ |
c906108c | 2363 | /* However, this still doesn't catch all cases of same type for arg |
7ba81444 MS |
2364 | and param. The reason is that builtin types are different from |
2365 | the same ones constructed from the object. */ | |
c906108c SS |
2366 | if (parm == arg) |
2367 | return 0; | |
2368 | ||
2369 | /* Resolve typedefs */ | |
2370 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) | |
2371 | parm = check_typedef (parm); | |
2372 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) | |
2373 | arg = check_typedef (arg); | |
2374 | ||
070ad9f0 | 2375 | /* |
7ba81444 MS |
2376 | Well, damnit, if the names are exactly the same, I'll say they |
2377 | are exactly the same. This happens when we generate method | |
2378 | stubs. The types won't point to the same address, but they | |
070ad9f0 DB |
2379 | really are the same. |
2380 | */ | |
2381 | ||
687d6395 MS |
2382 | if (TYPE_NAME (parm) && TYPE_NAME (arg) |
2383 | && !strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) | |
7ba81444 | 2384 | return 0; |
070ad9f0 | 2385 | |
7ba81444 | 2386 | /* Check if identical after resolving typedefs. */ |
c906108c SS |
2387 | if (parm == arg) |
2388 | return 0; | |
2389 | ||
db577aea | 2390 | /* See through references, since we can almost make non-references |
7ba81444 | 2391 | references. */ |
db577aea | 2392 | if (TYPE_CODE (arg) == TYPE_CODE_REF) |
6b1ba9a0 | 2393 | return (rank_one_type (parm, TYPE_TARGET_TYPE (arg)) |
db577aea AC |
2394 | + REFERENCE_CONVERSION_BADNESS); |
2395 | if (TYPE_CODE (parm) == TYPE_CODE_REF) | |
6b1ba9a0 | 2396 | return (rank_one_type (TYPE_TARGET_TYPE (parm), arg) |
db577aea | 2397 | + REFERENCE_CONVERSION_BADNESS); |
5d161b24 | 2398 | if (overload_debug) |
7ba81444 MS |
2399 | /* Debugging only. */ |
2400 | fprintf_filtered (gdb_stderr, | |
2401 | "------ Arg is %s [%d], parm is %s [%d]\n", | |
2402 | TYPE_NAME (arg), TYPE_CODE (arg), | |
2403 | TYPE_NAME (parm), TYPE_CODE (parm)); | |
c906108c SS |
2404 | |
2405 | /* x -> y means arg of type x being supplied for parameter of type y */ | |
2406 | ||
2407 | switch (TYPE_CODE (parm)) | |
2408 | { | |
c5aa993b JM |
2409 | case TYPE_CODE_PTR: |
2410 | switch (TYPE_CODE (arg)) | |
2411 | { | |
2412 | case TYPE_CODE_PTR: | |
2413 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) | |
2414 | return VOID_PTR_CONVERSION_BADNESS; | |
2415 | else | |
7ba81444 MS |
2416 | return rank_one_type (TYPE_TARGET_TYPE (parm), |
2417 | TYPE_TARGET_TYPE (arg)); | |
c5aa993b | 2418 | case TYPE_CODE_ARRAY: |
7ba81444 MS |
2419 | return rank_one_type (TYPE_TARGET_TYPE (parm), |
2420 | TYPE_TARGET_TYPE (arg)); | |
c5aa993b JM |
2421 | case TYPE_CODE_FUNC: |
2422 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg); | |
2423 | case TYPE_CODE_INT: | |
2424 | case TYPE_CODE_ENUM: | |
4f2aea11 | 2425 | case TYPE_CODE_FLAGS: |
c5aa993b JM |
2426 | case TYPE_CODE_CHAR: |
2427 | case TYPE_CODE_RANGE: | |
2428 | case TYPE_CODE_BOOL: | |
2429 | return POINTER_CONVERSION_BADNESS; | |
2430 | default: | |
2431 | return INCOMPATIBLE_TYPE_BADNESS; | |
2432 | } | |
2433 | case TYPE_CODE_ARRAY: | |
2434 | switch (TYPE_CODE (arg)) | |
2435 | { | |
2436 | case TYPE_CODE_PTR: | |
2437 | case TYPE_CODE_ARRAY: | |
7ba81444 MS |
2438 | return rank_one_type (TYPE_TARGET_TYPE (parm), |
2439 | TYPE_TARGET_TYPE (arg)); | |
c5aa993b JM |
2440 | default: |
2441 | return INCOMPATIBLE_TYPE_BADNESS; | |
2442 | } | |
2443 | case TYPE_CODE_FUNC: | |
2444 | switch (TYPE_CODE (arg)) | |
2445 | { | |
2446 | case TYPE_CODE_PTR: /* funcptr -> func */ | |
2447 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg)); | |
2448 | default: | |
2449 | return INCOMPATIBLE_TYPE_BADNESS; | |
2450 | } | |
2451 | case TYPE_CODE_INT: | |
2452 | switch (TYPE_CODE (arg)) | |
2453 | { | |
2454 | case TYPE_CODE_INT: | |
2455 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2456 | { | |
2457 | /* Deal with signed, unsigned, and plain chars and | |
7ba81444 | 2458 | signed and unsigned ints. */ |
c5aa993b JM |
2459 | if (TYPE_NOSIGN (parm)) |
2460 | { | |
2461 | /* This case only for character types */ | |
7ba81444 MS |
2462 | if (TYPE_NOSIGN (arg)) |
2463 | return 0; /* plain char -> plain char */ | |
2464 | else /* signed/unsigned char -> plain char */ | |
2465 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b JM |
2466 | } |
2467 | else if (TYPE_UNSIGNED (parm)) | |
2468 | { | |
2469 | if (TYPE_UNSIGNED (arg)) | |
2470 | { | |
7ba81444 MS |
2471 | /* unsigned int -> unsigned int, or |
2472 | unsigned long -> unsigned long */ | |
2473 | if (integer_types_same_name_p (TYPE_NAME (parm), | |
2474 | TYPE_NAME (arg))) | |
973ccf8b | 2475 | return 0; |
7ba81444 MS |
2476 | else if (integer_types_same_name_p (TYPE_NAME (arg), |
2477 | "int") | |
2478 | && integer_types_same_name_p (TYPE_NAME (parm), | |
2479 | "long")) | |
c5aa993b JM |
2480 | return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */ |
2481 | else | |
1c5cb38e | 2482 | return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */ |
c5aa993b JM |
2483 | } |
2484 | else | |
2485 | { | |
7ba81444 MS |
2486 | if (integer_types_same_name_p (TYPE_NAME (arg), |
2487 | "long") | |
2488 | && integer_types_same_name_p (TYPE_NAME (parm), | |
2489 | "int")) | |
1c5cb38e | 2490 | return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */ |
c5aa993b JM |
2491 | else |
2492 | return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */ | |
2493 | } | |
2494 | } | |
2495 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2496 | { | |
7ba81444 MS |
2497 | if (integer_types_same_name_p (TYPE_NAME (parm), |
2498 | TYPE_NAME (arg))) | |
c5aa993b | 2499 | return 0; |
7ba81444 MS |
2500 | else if (integer_types_same_name_p (TYPE_NAME (arg), |
2501 | "int") | |
2502 | && integer_types_same_name_p (TYPE_NAME (parm), | |
2503 | "long")) | |
c5aa993b JM |
2504 | return INTEGER_PROMOTION_BADNESS; |
2505 | else | |
1c5cb38e | 2506 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2507 | } |
2508 | else | |
1c5cb38e | 2509 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2510 | } |
2511 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2512 | return INTEGER_PROMOTION_BADNESS; | |
2513 | else | |
1c5cb38e | 2514 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b | 2515 | case TYPE_CODE_ENUM: |
4f2aea11 | 2516 | case TYPE_CODE_FLAGS: |
c5aa993b JM |
2517 | case TYPE_CODE_CHAR: |
2518 | case TYPE_CODE_RANGE: | |
2519 | case TYPE_CODE_BOOL: | |
2520 | return INTEGER_PROMOTION_BADNESS; | |
2521 | case TYPE_CODE_FLT: | |
2522 | return INT_FLOAT_CONVERSION_BADNESS; | |
2523 | case TYPE_CODE_PTR: | |
2524 | return NS_POINTER_CONVERSION_BADNESS; | |
2525 | default: | |
2526 | return INCOMPATIBLE_TYPE_BADNESS; | |
2527 | } | |
2528 | break; | |
2529 | case TYPE_CODE_ENUM: | |
2530 | switch (TYPE_CODE (arg)) | |
2531 | { | |
2532 | case TYPE_CODE_INT: | |
2533 | case TYPE_CODE_CHAR: | |
2534 | case TYPE_CODE_RANGE: | |
2535 | case TYPE_CODE_BOOL: | |
2536 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2537 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2538 | case TYPE_CODE_FLT: |
2539 | return INT_FLOAT_CONVERSION_BADNESS; | |
2540 | default: | |
2541 | return INCOMPATIBLE_TYPE_BADNESS; | |
2542 | } | |
2543 | break; | |
2544 | case TYPE_CODE_CHAR: | |
2545 | switch (TYPE_CODE (arg)) | |
2546 | { | |
2547 | case TYPE_CODE_RANGE: | |
2548 | case TYPE_CODE_BOOL: | |
2549 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2550 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2551 | case TYPE_CODE_FLT: |
2552 | return INT_FLOAT_CONVERSION_BADNESS; | |
2553 | case TYPE_CODE_INT: | |
2554 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) | |
1c5cb38e | 2555 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2556 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
2557 | return INTEGER_PROMOTION_BADNESS; | |
2558 | /* >>> !! else fall through !! <<< */ | |
2559 | case TYPE_CODE_CHAR: | |
7ba81444 MS |
2560 | /* Deal with signed, unsigned, and plain chars for C++ and |
2561 | with int cases falling through from previous case. */ | |
c5aa993b JM |
2562 | if (TYPE_NOSIGN (parm)) |
2563 | { | |
2564 | if (TYPE_NOSIGN (arg)) | |
2565 | return 0; | |
2566 | else | |
1c5cb38e | 2567 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2568 | } |
2569 | else if (TYPE_UNSIGNED (parm)) | |
2570 | { | |
2571 | if (TYPE_UNSIGNED (arg)) | |
2572 | return 0; | |
2573 | else | |
2574 | return INTEGER_PROMOTION_BADNESS; | |
2575 | } | |
2576 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2577 | return 0; | |
2578 | else | |
1c5cb38e | 2579 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2580 | default: |
2581 | return INCOMPATIBLE_TYPE_BADNESS; | |
2582 | } | |
2583 | break; | |
2584 | case TYPE_CODE_RANGE: | |
2585 | switch (TYPE_CODE (arg)) | |
2586 | { | |
2587 | case TYPE_CODE_INT: | |
2588 | case TYPE_CODE_CHAR: | |
2589 | case TYPE_CODE_RANGE: | |
2590 | case TYPE_CODE_BOOL: | |
2591 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2592 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2593 | case TYPE_CODE_FLT: |
2594 | return INT_FLOAT_CONVERSION_BADNESS; | |
2595 | default: | |
2596 | return INCOMPATIBLE_TYPE_BADNESS; | |
2597 | } | |
2598 | break; | |
2599 | case TYPE_CODE_BOOL: | |
2600 | switch (TYPE_CODE (arg)) | |
2601 | { | |
2602 | case TYPE_CODE_INT: | |
2603 | case TYPE_CODE_CHAR: | |
2604 | case TYPE_CODE_RANGE: | |
2605 | case TYPE_CODE_ENUM: | |
2606 | case TYPE_CODE_FLT: | |
2607 | case TYPE_CODE_PTR: | |
2608 | return BOOLEAN_CONVERSION_BADNESS; | |
2609 | case TYPE_CODE_BOOL: | |
2610 | return 0; | |
2611 | default: | |
2612 | return INCOMPATIBLE_TYPE_BADNESS; | |
2613 | } | |
2614 | break; | |
2615 | case TYPE_CODE_FLT: | |
2616 | switch (TYPE_CODE (arg)) | |
2617 | { | |
2618 | case TYPE_CODE_FLT: | |
2619 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2620 | return FLOAT_PROMOTION_BADNESS; | |
2621 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2622 | return 0; | |
2623 | else | |
2624 | return FLOAT_CONVERSION_BADNESS; | |
2625 | case TYPE_CODE_INT: | |
2626 | case TYPE_CODE_BOOL: | |
2627 | case TYPE_CODE_ENUM: | |
2628 | case TYPE_CODE_RANGE: | |
2629 | case TYPE_CODE_CHAR: | |
2630 | return INT_FLOAT_CONVERSION_BADNESS; | |
2631 | default: | |
2632 | return INCOMPATIBLE_TYPE_BADNESS; | |
2633 | } | |
2634 | break; | |
2635 | case TYPE_CODE_COMPLEX: | |
2636 | switch (TYPE_CODE (arg)) | |
7ba81444 | 2637 | { /* Strictly not needed for C++, but... */ |
c5aa993b JM |
2638 | case TYPE_CODE_FLT: |
2639 | return FLOAT_PROMOTION_BADNESS; | |
2640 | case TYPE_CODE_COMPLEX: | |
2641 | return 0; | |
2642 | default: | |
2643 | return INCOMPATIBLE_TYPE_BADNESS; | |
2644 | } | |
2645 | break; | |
2646 | case TYPE_CODE_STRUCT: | |
c906108c | 2647 | /* currently same as TYPE_CODE_CLASS */ |
c5aa993b JM |
2648 | switch (TYPE_CODE (arg)) |
2649 | { | |
2650 | case TYPE_CODE_STRUCT: | |
2651 | /* Check for derivation */ | |
2652 | if (is_ancestor (parm, arg)) | |
2653 | return BASE_CONVERSION_BADNESS; | |
2654 | /* else fall through */ | |
2655 | default: | |
2656 | return INCOMPATIBLE_TYPE_BADNESS; | |
2657 | } | |
2658 | break; | |
2659 | case TYPE_CODE_UNION: | |
2660 | switch (TYPE_CODE (arg)) | |
2661 | { | |
2662 | case TYPE_CODE_UNION: | |
2663 | default: | |
2664 | return INCOMPATIBLE_TYPE_BADNESS; | |
2665 | } | |
2666 | break; | |
0d5de010 | 2667 | case TYPE_CODE_MEMBERPTR: |
c5aa993b JM |
2668 | switch (TYPE_CODE (arg)) |
2669 | { | |
2670 | default: | |
2671 | return INCOMPATIBLE_TYPE_BADNESS; | |
2672 | } | |
2673 | break; | |
2674 | case TYPE_CODE_METHOD: | |
2675 | switch (TYPE_CODE (arg)) | |
2676 | { | |
2677 | ||
2678 | default: | |
2679 | return INCOMPATIBLE_TYPE_BADNESS; | |
2680 | } | |
2681 | break; | |
2682 | case TYPE_CODE_REF: | |
2683 | switch (TYPE_CODE (arg)) | |
2684 | { | |
2685 | ||
2686 | default: | |
2687 | return INCOMPATIBLE_TYPE_BADNESS; | |
2688 | } | |
2689 | ||
2690 | break; | |
2691 | case TYPE_CODE_SET: | |
2692 | switch (TYPE_CODE (arg)) | |
2693 | { | |
2694 | /* Not in C++ */ | |
2695 | case TYPE_CODE_SET: | |
7ba81444 MS |
2696 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), |
2697 | TYPE_FIELD_TYPE (arg, 0)); | |
c5aa993b JM |
2698 | default: |
2699 | return INCOMPATIBLE_TYPE_BADNESS; | |
2700 | } | |
2701 | break; | |
2702 | case TYPE_CODE_VOID: | |
2703 | default: | |
2704 | return INCOMPATIBLE_TYPE_BADNESS; | |
2705 | } /* switch (TYPE_CODE (arg)) */ | |
c906108c SS |
2706 | } |
2707 | ||
c5aa993b JM |
2708 | |
2709 | /* End of functions for overload resolution */ | |
c906108c | 2710 | |
c906108c | 2711 | static void |
fba45db2 | 2712 | print_bit_vector (B_TYPE *bits, int nbits) |
c906108c SS |
2713 | { |
2714 | int bitno; | |
2715 | ||
2716 | for (bitno = 0; bitno < nbits; bitno++) | |
2717 | { | |
2718 | if ((bitno % 8) == 0) | |
2719 | { | |
2720 | puts_filtered (" "); | |
2721 | } | |
2722 | if (B_TST (bits, bitno)) | |
a3f17187 | 2723 | printf_filtered (("1")); |
c906108c | 2724 | else |
a3f17187 | 2725 | printf_filtered (("0")); |
c906108c SS |
2726 | } |
2727 | } | |
2728 | ||
ad2f7632 | 2729 | /* Note the first arg should be the "this" pointer, we may not want to |
7ba81444 MS |
2730 | include it since we may get into a infinitely recursive |
2731 | situation. */ | |
c906108c SS |
2732 | |
2733 | static void | |
ad2f7632 | 2734 | print_arg_types (struct field *args, int nargs, int spaces) |
c906108c SS |
2735 | { |
2736 | if (args != NULL) | |
2737 | { | |
ad2f7632 DJ |
2738 | int i; |
2739 | ||
2740 | for (i = 0; i < nargs; i++) | |
2741 | recursive_dump_type (args[i].type, spaces + 2); | |
c906108c SS |
2742 | } |
2743 | } | |
2744 | ||
2745 | static void | |
fba45db2 | 2746 | dump_fn_fieldlists (struct type *type, int spaces) |
c906108c SS |
2747 | { |
2748 | int method_idx; | |
2749 | int overload_idx; | |
2750 | struct fn_field *f; | |
2751 | ||
2752 | printfi_filtered (spaces, "fn_fieldlists "); | |
d4f3574e | 2753 | gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
c906108c SS |
2754 | printf_filtered ("\n"); |
2755 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) | |
2756 | { | |
2757 | f = TYPE_FN_FIELDLIST1 (type, method_idx); | |
2758 | printfi_filtered (spaces + 2, "[%d] name '%s' (", | |
2759 | method_idx, | |
2760 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); | |
d4f3574e SS |
2761 | gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
2762 | gdb_stdout); | |
a3f17187 | 2763 | printf_filtered (_(") length %d\n"), |
c906108c SS |
2764 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); |
2765 | for (overload_idx = 0; | |
2766 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); | |
2767 | overload_idx++) | |
2768 | { | |
2769 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", | |
2770 | overload_idx, | |
2771 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); | |
d4f3574e SS |
2772 | gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
2773 | gdb_stdout); | |
c906108c SS |
2774 | printf_filtered (")\n"); |
2775 | printfi_filtered (spaces + 8, "type "); | |
7ba81444 MS |
2776 | gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), |
2777 | gdb_stdout); | |
c906108c SS |
2778 | printf_filtered ("\n"); |
2779 | ||
2780 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), | |
2781 | spaces + 8 + 2); | |
2782 | ||
2783 | printfi_filtered (spaces + 8, "args "); | |
7ba81444 MS |
2784 | gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), |
2785 | gdb_stdout); | |
c906108c SS |
2786 | printf_filtered ("\n"); |
2787 | ||
ad2f7632 | 2788 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), |
7ba81444 MS |
2789 | TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, |
2790 | overload_idx)), | |
ad2f7632 | 2791 | spaces); |
c906108c | 2792 | printfi_filtered (spaces + 8, "fcontext "); |
d4f3574e SS |
2793 | gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
2794 | gdb_stdout); | |
c906108c SS |
2795 | printf_filtered ("\n"); |
2796 | ||
2797 | printfi_filtered (spaces + 8, "is_const %d\n", | |
2798 | TYPE_FN_FIELD_CONST (f, overload_idx)); | |
2799 | printfi_filtered (spaces + 8, "is_volatile %d\n", | |
2800 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); | |
2801 | printfi_filtered (spaces + 8, "is_private %d\n", | |
2802 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); | |
2803 | printfi_filtered (spaces + 8, "is_protected %d\n", | |
2804 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); | |
2805 | printfi_filtered (spaces + 8, "is_stub %d\n", | |
2806 | TYPE_FN_FIELD_STUB (f, overload_idx)); | |
2807 | printfi_filtered (spaces + 8, "voffset %u\n", | |
2808 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); | |
2809 | } | |
2810 | } | |
2811 | } | |
2812 | ||
2813 | static void | |
fba45db2 | 2814 | print_cplus_stuff (struct type *type, int spaces) |
c906108c SS |
2815 | { |
2816 | printfi_filtered (spaces, "n_baseclasses %d\n", | |
2817 | TYPE_N_BASECLASSES (type)); | |
2818 | printfi_filtered (spaces, "nfn_fields %d\n", | |
2819 | TYPE_NFN_FIELDS (type)); | |
2820 | printfi_filtered (spaces, "nfn_fields_total %d\n", | |
2821 | TYPE_NFN_FIELDS_TOTAL (type)); | |
2822 | if (TYPE_N_BASECLASSES (type) > 0) | |
2823 | { | |
2824 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", | |
2825 | TYPE_N_BASECLASSES (type)); | |
7ba81444 MS |
2826 | gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), |
2827 | gdb_stdout); | |
c906108c SS |
2828 | printf_filtered (")"); |
2829 | ||
2830 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), | |
2831 | TYPE_N_BASECLASSES (type)); | |
2832 | puts_filtered ("\n"); | |
2833 | } | |
2834 | if (TYPE_NFIELDS (type) > 0) | |
2835 | { | |
2836 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) | |
2837 | { | |
7ba81444 MS |
2838 | printfi_filtered (spaces, |
2839 | "private_field_bits (%d bits at *", | |
c906108c | 2840 | TYPE_NFIELDS (type)); |
7ba81444 MS |
2841 | gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), |
2842 | gdb_stdout); | |
c906108c SS |
2843 | printf_filtered (")"); |
2844 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), | |
2845 | TYPE_NFIELDS (type)); | |
2846 | puts_filtered ("\n"); | |
2847 | } | |
2848 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) | |
2849 | { | |
7ba81444 MS |
2850 | printfi_filtered (spaces, |
2851 | "protected_field_bits (%d bits at *", | |
c906108c | 2852 | TYPE_NFIELDS (type)); |
7ba81444 MS |
2853 | gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), |
2854 | gdb_stdout); | |
c906108c SS |
2855 | printf_filtered (")"); |
2856 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), | |
2857 | TYPE_NFIELDS (type)); | |
2858 | puts_filtered ("\n"); | |
2859 | } | |
2860 | } | |
2861 | if (TYPE_NFN_FIELDS (type) > 0) | |
2862 | { | |
2863 | dump_fn_fieldlists (type, spaces); | |
2864 | } | |
2865 | } | |
2866 | ||
e9e79dd9 FF |
2867 | static void |
2868 | print_bound_type (int bt) | |
2869 | { | |
2870 | switch (bt) | |
2871 | { | |
2872 | case BOUND_CANNOT_BE_DETERMINED: | |
2873 | printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)"); | |
2874 | break; | |
2875 | case BOUND_BY_REF_ON_STACK: | |
2876 | printf_filtered ("(BOUND_BY_REF_ON_STACK)"); | |
2877 | break; | |
2878 | case BOUND_BY_VALUE_ON_STACK: | |
2879 | printf_filtered ("(BOUND_BY_VALUE_ON_STACK)"); | |
2880 | break; | |
2881 | case BOUND_BY_REF_IN_REG: | |
2882 | printf_filtered ("(BOUND_BY_REF_IN_REG)"); | |
2883 | break; | |
2884 | case BOUND_BY_VALUE_IN_REG: | |
2885 | printf_filtered ("(BOUND_BY_VALUE_IN_REG)"); | |
2886 | break; | |
2887 | case BOUND_SIMPLE: | |
2888 | printf_filtered ("(BOUND_SIMPLE)"); | |
2889 | break; | |
2890 | default: | |
a3f17187 | 2891 | printf_filtered (_("(unknown bound type)")); |
e9e79dd9 FF |
2892 | break; |
2893 | } | |
2894 | } | |
2895 | ||
c906108c SS |
2896 | static struct obstack dont_print_type_obstack; |
2897 | ||
2898 | void | |
fba45db2 | 2899 | recursive_dump_type (struct type *type, int spaces) |
c906108c SS |
2900 | { |
2901 | int idx; | |
2902 | ||
2903 | if (spaces == 0) | |
2904 | obstack_begin (&dont_print_type_obstack, 0); | |
2905 | ||
2906 | if (TYPE_NFIELDS (type) > 0 | |
2907 | || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0)) | |
2908 | { | |
2909 | struct type **first_dont_print | |
7ba81444 | 2910 | = (struct type **) obstack_base (&dont_print_type_obstack); |
c906108c | 2911 | |
7ba81444 MS |
2912 | int i = (struct type **) |
2913 | obstack_next_free (&dont_print_type_obstack) - first_dont_print; | |
c906108c SS |
2914 | |
2915 | while (--i >= 0) | |
2916 | { | |
2917 | if (type == first_dont_print[i]) | |
2918 | { | |
2919 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2920 | gdb_print_host_address (type, gdb_stdout); |
a3f17187 | 2921 | printf_filtered (_(" <same as already seen type>\n")); |
c906108c SS |
2922 | return; |
2923 | } | |
2924 | } | |
2925 | ||
2926 | obstack_ptr_grow (&dont_print_type_obstack, type); | |
2927 | } | |
2928 | ||
2929 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2930 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
2931 | printf_filtered ("\n"); |
2932 | printfi_filtered (spaces, "name '%s' (", | |
2933 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); | |
d4f3574e | 2934 | gdb_print_host_address (TYPE_NAME (type), gdb_stdout); |
c906108c | 2935 | printf_filtered (")\n"); |
e9e79dd9 FF |
2936 | printfi_filtered (spaces, "tagname '%s' (", |
2937 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>"); | |
2938 | gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout); | |
2939 | printf_filtered (")\n"); | |
c906108c SS |
2940 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); |
2941 | switch (TYPE_CODE (type)) | |
2942 | { | |
c5aa993b JM |
2943 | case TYPE_CODE_UNDEF: |
2944 | printf_filtered ("(TYPE_CODE_UNDEF)"); | |
2945 | break; | |
2946 | case TYPE_CODE_PTR: | |
2947 | printf_filtered ("(TYPE_CODE_PTR)"); | |
2948 | break; | |
2949 | case TYPE_CODE_ARRAY: | |
2950 | printf_filtered ("(TYPE_CODE_ARRAY)"); | |
2951 | break; | |
2952 | case TYPE_CODE_STRUCT: | |
2953 | printf_filtered ("(TYPE_CODE_STRUCT)"); | |
2954 | break; | |
2955 | case TYPE_CODE_UNION: | |
2956 | printf_filtered ("(TYPE_CODE_UNION)"); | |
2957 | break; | |
2958 | case TYPE_CODE_ENUM: | |
2959 | printf_filtered ("(TYPE_CODE_ENUM)"); | |
2960 | break; | |
4f2aea11 MK |
2961 | case TYPE_CODE_FLAGS: |
2962 | printf_filtered ("(TYPE_CODE_FLAGS)"); | |
2963 | break; | |
c5aa993b JM |
2964 | case TYPE_CODE_FUNC: |
2965 | printf_filtered ("(TYPE_CODE_FUNC)"); | |
2966 | break; | |
2967 | case TYPE_CODE_INT: | |
2968 | printf_filtered ("(TYPE_CODE_INT)"); | |
2969 | break; | |
2970 | case TYPE_CODE_FLT: | |
2971 | printf_filtered ("(TYPE_CODE_FLT)"); | |
2972 | break; | |
2973 | case TYPE_CODE_VOID: | |
2974 | printf_filtered ("(TYPE_CODE_VOID)"); | |
2975 | break; | |
2976 | case TYPE_CODE_SET: | |
2977 | printf_filtered ("(TYPE_CODE_SET)"); | |
2978 | break; | |
2979 | case TYPE_CODE_RANGE: | |
2980 | printf_filtered ("(TYPE_CODE_RANGE)"); | |
2981 | break; | |
2982 | case TYPE_CODE_STRING: | |
2983 | printf_filtered ("(TYPE_CODE_STRING)"); | |
2984 | break; | |
e9e79dd9 FF |
2985 | case TYPE_CODE_BITSTRING: |
2986 | printf_filtered ("(TYPE_CODE_BITSTRING)"); | |
2987 | break; | |
c5aa993b JM |
2988 | case TYPE_CODE_ERROR: |
2989 | printf_filtered ("(TYPE_CODE_ERROR)"); | |
2990 | break; | |
0d5de010 DJ |
2991 | case TYPE_CODE_MEMBERPTR: |
2992 | printf_filtered ("(TYPE_CODE_MEMBERPTR)"); | |
2993 | break; | |
2994 | case TYPE_CODE_METHODPTR: | |
2995 | printf_filtered ("(TYPE_CODE_METHODPTR)"); | |
c5aa993b JM |
2996 | break; |
2997 | case TYPE_CODE_METHOD: | |
2998 | printf_filtered ("(TYPE_CODE_METHOD)"); | |
2999 | break; | |
3000 | case TYPE_CODE_REF: | |
3001 | printf_filtered ("(TYPE_CODE_REF)"); | |
3002 | break; | |
3003 | case TYPE_CODE_CHAR: | |
3004 | printf_filtered ("(TYPE_CODE_CHAR)"); | |
3005 | break; | |
3006 | case TYPE_CODE_BOOL: | |
3007 | printf_filtered ("(TYPE_CODE_BOOL)"); | |
3008 | break; | |
e9e79dd9 FF |
3009 | case TYPE_CODE_COMPLEX: |
3010 | printf_filtered ("(TYPE_CODE_COMPLEX)"); | |
3011 | break; | |
c5aa993b JM |
3012 | case TYPE_CODE_TYPEDEF: |
3013 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); | |
3014 | break; | |
e9e79dd9 FF |
3015 | case TYPE_CODE_TEMPLATE: |
3016 | printf_filtered ("(TYPE_CODE_TEMPLATE)"); | |
3017 | break; | |
3018 | case TYPE_CODE_TEMPLATE_ARG: | |
3019 | printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)"); | |
3020 | break; | |
5c4e30ca DC |
3021 | case TYPE_CODE_NAMESPACE: |
3022 | printf_filtered ("(TYPE_CODE_NAMESPACE)"); | |
3023 | break; | |
c5aa993b JM |
3024 | default: |
3025 | printf_filtered ("(UNKNOWN TYPE CODE)"); | |
3026 | break; | |
c906108c SS |
3027 | } |
3028 | puts_filtered ("\n"); | |
3029 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); | |
e9e79dd9 FF |
3030 | printfi_filtered (spaces, "upper_bound_type 0x%x ", |
3031 | TYPE_ARRAY_UPPER_BOUND_TYPE (type)); | |
3032 | print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type)); | |
3033 | puts_filtered ("\n"); | |
3034 | printfi_filtered (spaces, "lower_bound_type 0x%x ", | |
3035 | TYPE_ARRAY_LOWER_BOUND_TYPE (type)); | |
3036 | print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type)); | |
3037 | puts_filtered ("\n"); | |
c906108c | 3038 | printfi_filtered (spaces, "objfile "); |
d4f3574e | 3039 | gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout); |
c906108c SS |
3040 | printf_filtered ("\n"); |
3041 | printfi_filtered (spaces, "target_type "); | |
d4f3574e | 3042 | gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
c906108c SS |
3043 | printf_filtered ("\n"); |
3044 | if (TYPE_TARGET_TYPE (type) != NULL) | |
3045 | { | |
3046 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); | |
3047 | } | |
3048 | printfi_filtered (spaces, "pointer_type "); | |
d4f3574e | 3049 | gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
c906108c SS |
3050 | printf_filtered ("\n"); |
3051 | printfi_filtered (spaces, "reference_type "); | |
d4f3574e | 3052 | gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
c906108c | 3053 | printf_filtered ("\n"); |
2fdde8f8 DJ |
3054 | printfi_filtered (spaces, "type_chain "); |
3055 | gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout); | |
e9e79dd9 | 3056 | printf_filtered ("\n"); |
7ba81444 MS |
3057 | printfi_filtered (spaces, "instance_flags 0x%x", |
3058 | TYPE_INSTANCE_FLAGS (type)); | |
2fdde8f8 DJ |
3059 | if (TYPE_CONST (type)) |
3060 | { | |
3061 | puts_filtered (" TYPE_FLAG_CONST"); | |
3062 | } | |
3063 | if (TYPE_VOLATILE (type)) | |
3064 | { | |
3065 | puts_filtered (" TYPE_FLAG_VOLATILE"); | |
3066 | } | |
3067 | if (TYPE_CODE_SPACE (type)) | |
3068 | { | |
3069 | puts_filtered (" TYPE_FLAG_CODE_SPACE"); | |
3070 | } | |
3071 | if (TYPE_DATA_SPACE (type)) | |
3072 | { | |
3073 | puts_filtered (" TYPE_FLAG_DATA_SPACE"); | |
3074 | } | |
8b2dbe47 KB |
3075 | if (TYPE_ADDRESS_CLASS_1 (type)) |
3076 | { | |
3077 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1"); | |
3078 | } | |
3079 | if (TYPE_ADDRESS_CLASS_2 (type)) | |
3080 | { | |
3081 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2"); | |
3082 | } | |
2fdde8f8 | 3083 | puts_filtered ("\n"); |
c906108c | 3084 | printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type)); |
762a036f | 3085 | if (TYPE_UNSIGNED (type)) |
c906108c SS |
3086 | { |
3087 | puts_filtered (" TYPE_FLAG_UNSIGNED"); | |
3088 | } | |
762a036f FF |
3089 | if (TYPE_NOSIGN (type)) |
3090 | { | |
3091 | puts_filtered (" TYPE_FLAG_NOSIGN"); | |
3092 | } | |
3093 | if (TYPE_STUB (type)) | |
c906108c SS |
3094 | { |
3095 | puts_filtered (" TYPE_FLAG_STUB"); | |
3096 | } | |
762a036f FF |
3097 | if (TYPE_TARGET_STUB (type)) |
3098 | { | |
3099 | puts_filtered (" TYPE_FLAG_TARGET_STUB"); | |
3100 | } | |
3101 | if (TYPE_STATIC (type)) | |
3102 | { | |
3103 | puts_filtered (" TYPE_FLAG_STATIC"); | |
3104 | } | |
762a036f FF |
3105 | if (TYPE_PROTOTYPED (type)) |
3106 | { | |
3107 | puts_filtered (" TYPE_FLAG_PROTOTYPED"); | |
3108 | } | |
3109 | if (TYPE_INCOMPLETE (type)) | |
3110 | { | |
3111 | puts_filtered (" TYPE_FLAG_INCOMPLETE"); | |
3112 | } | |
762a036f FF |
3113 | if (TYPE_VARARGS (type)) |
3114 | { | |
3115 | puts_filtered (" TYPE_FLAG_VARARGS"); | |
3116 | } | |
f5f8a009 EZ |
3117 | /* This is used for things like AltiVec registers on ppc. Gcc emits |
3118 | an attribute for the array type, which tells whether or not we | |
3119 | have a vector, instead of a regular array. */ | |
3120 | if (TYPE_VECTOR (type)) | |
3121 | { | |
3122 | puts_filtered (" TYPE_FLAG_VECTOR"); | |
3123 | } | |
c906108c SS |
3124 | puts_filtered ("\n"); |
3125 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); | |
d4f3574e | 3126 | gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout); |
c906108c SS |
3127 | puts_filtered ("\n"); |
3128 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) | |
3129 | { | |
3130 | printfi_filtered (spaces + 2, | |
3131 | "[%d] bitpos %d bitsize %d type ", | |
3132 | idx, TYPE_FIELD_BITPOS (type, idx), | |
3133 | TYPE_FIELD_BITSIZE (type, idx)); | |
d4f3574e | 3134 | gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
c906108c SS |
3135 | printf_filtered (" name '%s' (", |
3136 | TYPE_FIELD_NAME (type, idx) != NULL | |
3137 | ? TYPE_FIELD_NAME (type, idx) | |
3138 | : "<NULL>"); | |
d4f3574e | 3139 | gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
c906108c SS |
3140 | printf_filtered (")\n"); |
3141 | if (TYPE_FIELD_TYPE (type, idx) != NULL) | |
3142 | { | |
3143 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); | |
3144 | } | |
3145 | } | |
3146 | printfi_filtered (spaces, "vptr_basetype "); | |
d4f3574e | 3147 | gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); |
c906108c SS |
3148 | puts_filtered ("\n"); |
3149 | if (TYPE_VPTR_BASETYPE (type) != NULL) | |
3150 | { | |
3151 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); | |
3152 | } | |
7ba81444 MS |
3153 | printfi_filtered (spaces, "vptr_fieldno %d\n", |
3154 | TYPE_VPTR_FIELDNO (type)); | |
c906108c SS |
3155 | switch (TYPE_CODE (type)) |
3156 | { | |
c5aa993b JM |
3157 | case TYPE_CODE_STRUCT: |
3158 | printfi_filtered (spaces, "cplus_stuff "); | |
7ba81444 MS |
3159 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), |
3160 | gdb_stdout); | |
c5aa993b JM |
3161 | puts_filtered ("\n"); |
3162 | print_cplus_stuff (type, spaces); | |
3163 | break; | |
c906108c | 3164 | |
701c159d AC |
3165 | case TYPE_CODE_FLT: |
3166 | printfi_filtered (spaces, "floatformat "); | |
8da61cc4 | 3167 | if (TYPE_FLOATFORMAT (type) == NULL) |
701c159d AC |
3168 | puts_filtered ("(null)"); |
3169 | else | |
8da61cc4 DJ |
3170 | { |
3171 | puts_filtered ("{ "); | |
3172 | if (TYPE_FLOATFORMAT (type)[0] == NULL | |
3173 | || TYPE_FLOATFORMAT (type)[0]->name == NULL) | |
3174 | puts_filtered ("(null)"); | |
3175 | else | |
3176 | puts_filtered (TYPE_FLOATFORMAT (type)[0]->name); | |
3177 | ||
3178 | puts_filtered (", "); | |
3179 | if (TYPE_FLOATFORMAT (type)[1] == NULL | |
3180 | || TYPE_FLOATFORMAT (type)[1]->name == NULL) | |
3181 | puts_filtered ("(null)"); | |
3182 | else | |
3183 | puts_filtered (TYPE_FLOATFORMAT (type)[1]->name); | |
3184 | ||
3185 | puts_filtered (" }"); | |
3186 | } | |
701c159d AC |
3187 | puts_filtered ("\n"); |
3188 | break; | |
3189 | ||
c5aa993b | 3190 | default: |
7ba81444 MS |
3191 | /* We have to pick one of the union types to be able print and |
3192 | test the value. Pick cplus_struct_type, even though we know | |
3193 | it isn't any particular one. */ | |
c5aa993b | 3194 | printfi_filtered (spaces, "type_specific "); |
d4f3574e | 3195 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
3196 | if (TYPE_CPLUS_SPECIFIC (type) != NULL) |
3197 | { | |
a3f17187 | 3198 | printf_filtered (_(" (unknown data form)")); |
c5aa993b JM |
3199 | } |
3200 | printf_filtered ("\n"); | |
3201 | break; | |
c906108c SS |
3202 | |
3203 | } | |
3204 | if (spaces == 0) | |
3205 | obstack_free (&dont_print_type_obstack, NULL); | |
3206 | } | |
3207 | ||
ae5a43e0 DJ |
3208 | /* Trivial helpers for the libiberty hash table, for mapping one |
3209 | type to another. */ | |
3210 | ||
3211 | struct type_pair | |
3212 | { | |
3213 | struct type *old, *new; | |
3214 | }; | |
3215 | ||
3216 | static hashval_t | |
3217 | type_pair_hash (const void *item) | |
3218 | { | |
3219 | const struct type_pair *pair = item; | |
3220 | return htab_hash_pointer (pair->old); | |
3221 | } | |
3222 | ||
3223 | static int | |
3224 | type_pair_eq (const void *item_lhs, const void *item_rhs) | |
3225 | { | |
3226 | const struct type_pair *lhs = item_lhs, *rhs = item_rhs; | |
3227 | return lhs->old == rhs->old; | |
3228 | } | |
3229 | ||
3230 | /* Allocate the hash table used by copy_type_recursive to walk | |
3231 | types without duplicates. We use OBJFILE's obstack, because | |
3232 | OBJFILE is about to be deleted. */ | |
3233 | ||
3234 | htab_t | |
3235 | create_copied_types_hash (struct objfile *objfile) | |
3236 | { | |
3237 | return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq, | |
3238 | NULL, &objfile->objfile_obstack, | |
3239 | hashtab_obstack_allocate, | |
3240 | dummy_obstack_deallocate); | |
3241 | } | |
3242 | ||
7ba81444 MS |
3243 | /* Recursively copy (deep copy) TYPE, if it is associated with |
3244 | OBJFILE. Return a new type allocated using malloc, a saved type if | |
3245 | we have already visited TYPE (using COPIED_TYPES), or TYPE if it is | |
3246 | not associated with OBJFILE. */ | |
ae5a43e0 DJ |
3247 | |
3248 | struct type * | |
7ba81444 MS |
3249 | copy_type_recursive (struct objfile *objfile, |
3250 | struct type *type, | |
ae5a43e0 DJ |
3251 | htab_t copied_types) |
3252 | { | |
3253 | struct type_pair *stored, pair; | |
3254 | void **slot; | |
3255 | struct type *new_type; | |
3256 | ||
3257 | if (TYPE_OBJFILE (type) == NULL) | |
3258 | return type; | |
3259 | ||
7ba81444 MS |
3260 | /* This type shouldn't be pointing to any types in other objfiles; |
3261 | if it did, the type might disappear unexpectedly. */ | |
ae5a43e0 DJ |
3262 | gdb_assert (TYPE_OBJFILE (type) == objfile); |
3263 | ||
3264 | pair.old = type; | |
3265 | slot = htab_find_slot (copied_types, &pair, INSERT); | |
3266 | if (*slot != NULL) | |
3267 | return ((struct type_pair *) *slot)->new; | |
3268 | ||
3269 | new_type = alloc_type (NULL); | |
3270 | ||
3271 | /* We must add the new type to the hash table immediately, in case | |
3272 | we encounter this type again during a recursive call below. */ | |
3273 | stored = xmalloc (sizeof (struct type_pair)); | |
3274 | stored->old = type; | |
3275 | stored->new = new_type; | |
3276 | *slot = stored; | |
3277 | ||
3278 | /* Copy the common fields of types. */ | |
3279 | TYPE_CODE (new_type) = TYPE_CODE (type); | |
7ba81444 MS |
3280 | TYPE_ARRAY_UPPER_BOUND_TYPE (new_type) = |
3281 | TYPE_ARRAY_UPPER_BOUND_TYPE (type); | |
3282 | TYPE_ARRAY_LOWER_BOUND_TYPE (new_type) = | |
3283 | TYPE_ARRAY_LOWER_BOUND_TYPE (type); | |
ae5a43e0 DJ |
3284 | if (TYPE_NAME (type)) |
3285 | TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type)); | |
3286 | if (TYPE_TAG_NAME (type)) | |
3287 | TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type)); | |
3288 | TYPE_FLAGS (new_type) = TYPE_FLAGS (type); | |
3289 | TYPE_VPTR_FIELDNO (new_type) = TYPE_VPTR_FIELDNO (type); | |
3290 | ||
3291 | TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type); | |
3292 | TYPE_LENGTH (new_type) = TYPE_LENGTH (type); | |
3293 | ||
3294 | /* Copy the fields. */ | |
3295 | TYPE_NFIELDS (new_type) = TYPE_NFIELDS (type); | |
3296 | if (TYPE_NFIELDS (type)) | |
3297 | { | |
3298 | int i, nfields; | |
3299 | ||
3300 | nfields = TYPE_NFIELDS (type); | |
3301 | TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields); | |
3302 | for (i = 0; i < nfields; i++) | |
3303 | { | |
7ba81444 MS |
3304 | TYPE_FIELD_ARTIFICIAL (new_type, i) = |
3305 | TYPE_FIELD_ARTIFICIAL (type, i); | |
ae5a43e0 DJ |
3306 | TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i); |
3307 | if (TYPE_FIELD_TYPE (type, i)) | |
3308 | TYPE_FIELD_TYPE (new_type, i) | |
3309 | = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i), | |
3310 | copied_types); | |
3311 | if (TYPE_FIELD_NAME (type, i)) | |
7ba81444 MS |
3312 | TYPE_FIELD_NAME (new_type, i) = |
3313 | xstrdup (TYPE_FIELD_NAME (type, i)); | |
ae5a43e0 DJ |
3314 | if (TYPE_FIELD_STATIC_HAS_ADDR (type, i)) |
3315 | SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i), | |
3316 | TYPE_FIELD_STATIC_PHYSADDR (type, i)); | |
3317 | else if (TYPE_FIELD_STATIC (type, i)) | |
3318 | SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i), | |
7ba81444 MS |
3319 | xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type, |
3320 | i))); | |
ae5a43e0 DJ |
3321 | else |
3322 | { | |
7ba81444 MS |
3323 | TYPE_FIELD_BITPOS (new_type, i) = |
3324 | TYPE_FIELD_BITPOS (type, i); | |
ae5a43e0 DJ |
3325 | TYPE_FIELD_STATIC_KIND (new_type, i) = 0; |
3326 | } | |
3327 | } | |
3328 | } | |
3329 | ||
3330 | /* Copy pointers to other types. */ | |
3331 | if (TYPE_TARGET_TYPE (type)) | |
7ba81444 MS |
3332 | TYPE_TARGET_TYPE (new_type) = |
3333 | copy_type_recursive (objfile, | |
3334 | TYPE_TARGET_TYPE (type), | |
3335 | copied_types); | |
ae5a43e0 | 3336 | if (TYPE_VPTR_BASETYPE (type)) |
7ba81444 MS |
3337 | TYPE_VPTR_BASETYPE (new_type) = |
3338 | copy_type_recursive (objfile, | |
3339 | TYPE_VPTR_BASETYPE (type), | |
3340 | copied_types); | |
ae5a43e0 DJ |
3341 | /* Maybe copy the type_specific bits. |
3342 | ||
3343 | NOTE drow/2005-12-09: We do not copy the C++-specific bits like | |
3344 | base classes and methods. There's no fundamental reason why we | |
3345 | can't, but at the moment it is not needed. */ | |
3346 | ||
3347 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
d5d6fca5 | 3348 | TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type); |
ae5a43e0 DJ |
3349 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
3350 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
3351 | || TYPE_CODE (type) == TYPE_CODE_TEMPLATE | |
3352 | || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) | |
3353 | INIT_CPLUS_SPECIFIC (new_type); | |
3354 | ||
3355 | return new_type; | |
3356 | } | |
3357 | ||
8da61cc4 DJ |
3358 | static struct type * |
3359 | build_flt (int bit, char *name, const struct floatformat **floatformats) | |
3360 | { | |
3361 | struct type *t; | |
3362 | ||
3363 | if (bit == -1) | |
3364 | { | |
3365 | gdb_assert (floatformats != NULL); | |
3366 | gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL); | |
3367 | bit = floatformats[0]->totalsize; | |
3368 | } | |
3369 | gdb_assert (bit >= 0); | |
3370 | ||
3371 | t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, 0, name, NULL); | |
3372 | TYPE_FLOATFORMAT (t) = floatformats; | |
3373 | return t; | |
3374 | } | |
3375 | ||
000177f0 AC |
3376 | static struct gdbarch_data *gdbtypes_data; |
3377 | ||
3378 | const struct builtin_type * | |
3379 | builtin_type (struct gdbarch *gdbarch) | |
3380 | { | |
3381 | return gdbarch_data (gdbarch, gdbtypes_data); | |
3382 | } | |
3383 | ||
70bd8e24 | 3384 | |
70bd8e24 AC |
3385 | static struct type * |
3386 | build_complex (int bit, char *name, struct type *target_type) | |
3387 | { | |
3388 | struct type *t; | |
3389 | if (bit <= 0 || target_type == builtin_type_error) | |
3390 | { | |
3391 | gdb_assert (builtin_type_error != NULL); | |
3392 | return builtin_type_error; | |
3393 | } | |
3394 | t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT, | |
3395 | 0, name, (struct objfile *) NULL); | |
3396 | TYPE_TARGET_TYPE (t) = target_type; | |
3397 | return t; | |
3398 | } | |
3399 | ||
000177f0 AC |
3400 | static void * |
3401 | gdbtypes_post_init (struct gdbarch *gdbarch) | |
3402 | { | |
3403 | struct builtin_type *builtin_type | |
3404 | = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type); | |
3405 | ||
3406 | builtin_type->builtin_void = | |
3407 | init_type (TYPE_CODE_VOID, 1, | |
3408 | 0, | |
3409 | "void", (struct objfile *) NULL); | |
3410 | builtin_type->builtin_char = | |
3411 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3412 | (TYPE_FLAG_NOSIGN | |
6c6b19fd UW |
3413 | | (gdbarch_char_signed (current_gdbarch) ? |
3414 | 0 : TYPE_FLAG_UNSIGNED)), | |
000177f0 | 3415 | "char", (struct objfile *) NULL); |
685419e2 | 3416 | builtin_type->builtin_true_char = |
000177f0 AC |
3417 | init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
3418 | 0, | |
3419 | "true character", (struct objfile *) NULL); | |
3420 | builtin_type->builtin_signed_char = | |
3421 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3422 | 0, | |
3423 | "signed char", (struct objfile *) NULL); | |
3424 | builtin_type->builtin_unsigned_char = | |
3425 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3426 | TYPE_FLAG_UNSIGNED, | |
3427 | "unsigned char", (struct objfile *) NULL); | |
3428 | builtin_type->builtin_short = | |
7ba81444 MS |
3429 | init_type (TYPE_CODE_INT, |
3430 | gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3431 | 0, "short", (struct objfile *) NULL); | |
000177f0 | 3432 | builtin_type->builtin_unsigned_short = |
7ba81444 MS |
3433 | init_type (TYPE_CODE_INT, |
3434 | gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3435 | TYPE_FLAG_UNSIGNED, "unsigned short", | |
3436 | (struct objfile *) NULL); | |
000177f0 | 3437 | builtin_type->builtin_int = |
7ba81444 MS |
3438 | init_type (TYPE_CODE_INT, |
3439 | gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3440 | 0, "int", (struct objfile *) NULL); | |
000177f0 | 3441 | builtin_type->builtin_unsigned_int = |
7ba81444 MS |
3442 | init_type (TYPE_CODE_INT, |
3443 | gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3444 | TYPE_FLAG_UNSIGNED, "unsigned int", | |
3445 | (struct objfile *) NULL); | |
000177f0 | 3446 | builtin_type->builtin_long = |
7ba81444 MS |
3447 | init_type (TYPE_CODE_INT, |
3448 | gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3449 | 0, "long", (struct objfile *) NULL); | |
000177f0 | 3450 | builtin_type->builtin_unsigned_long = |
7ba81444 MS |
3451 | init_type (TYPE_CODE_INT, |
3452 | gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3453 | TYPE_FLAG_UNSIGNED, "unsigned long", | |
3454 | (struct objfile *) NULL); | |
000177f0 | 3455 | builtin_type->builtin_long_long = |
9a76efb6 UW |
3456 | init_type (TYPE_CODE_INT, |
3457 | gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3458 | 0, "long long", (struct objfile *) NULL); | |
000177f0 | 3459 | builtin_type->builtin_unsigned_long_long = |
9a76efb6 UW |
3460 | init_type (TYPE_CODE_INT, |
3461 | gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3462 | TYPE_FLAG_UNSIGNED, "unsigned long long", | |
3463 | (struct objfile *) NULL); | |
70bd8e24 AC |
3464 | builtin_type->builtin_float |
3465 | = build_flt (gdbarch_float_bit (gdbarch), "float", | |
3466 | gdbarch_float_format (gdbarch)); | |
3467 | builtin_type->builtin_double | |
3468 | = build_flt (gdbarch_double_bit (gdbarch), "double", | |
3469 | gdbarch_double_format (gdbarch)); | |
3470 | builtin_type->builtin_long_double | |
3471 | = build_flt (gdbarch_long_double_bit (gdbarch), "long double", | |
3472 | gdbarch_long_double_format (gdbarch)); | |
3473 | builtin_type->builtin_complex | |
3474 | = build_complex (gdbarch_float_bit (gdbarch), "complex", | |
3475 | builtin_type->builtin_float); | |
3476 | builtin_type->builtin_double_complex | |
3477 | = build_complex (gdbarch_double_bit (gdbarch), "double complex", | |
3478 | builtin_type->builtin_double); | |
000177f0 AC |
3479 | builtin_type->builtin_string = |
3480 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3481 | 0, | |
3482 | "string", (struct objfile *) NULL); | |
000177f0 AC |
3483 | builtin_type->builtin_bool = |
3484 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3485 | 0, | |
3486 | "bool", (struct objfile *) NULL); | |
3487 | ||
7ba81444 | 3488 | /* Pointer/Address types. */ |
000177f0 AC |
3489 | |
3490 | /* NOTE: on some targets, addresses and pointers are not necessarily | |
3491 | the same --- for example, on the D10V, pointers are 16 bits long, | |
3492 | but addresses are 32 bits long. See doc/gdbint.texinfo, | |
3493 | ``Pointers Are Not Always Addresses''. | |
3494 | ||
3495 | The upshot is: | |
3496 | - gdb's `struct type' always describes the target's | |
3497 | representation. | |
3498 | - gdb's `struct value' objects should always hold values in | |
3499 | target form. | |
3500 | - gdb's CORE_ADDR values are addresses in the unified virtual | |
3501 | address space that the assembler and linker work with. Thus, | |
3502 | since target_read_memory takes a CORE_ADDR as an argument, it | |
3503 | can access any memory on the target, even if the processor has | |
3504 | separate code and data address spaces. | |
3505 | ||
3506 | So, for example: | |
3507 | - If v is a value holding a D10V code pointer, its contents are | |
3508 | in target form: a big-endian address left-shifted two bits. | |
3509 | - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as | |
3510 | sizeof (void *) == 2 on the target. | |
3511 | ||
3512 | In this context, builtin_type->CORE_ADDR is a bit odd: it's a | |
3513 | target type for a value the target will never see. It's only | |
3514 | used to hold the values of (typeless) linker symbols, which are | |
3515 | indeed in the unified virtual address space. */ | |
7ba81444 MS |
3516 | |
3517 | builtin_type->builtin_data_ptr = | |
3518 | make_pointer_type (builtin_type->builtin_void, NULL); | |
3519 | builtin_type->builtin_func_ptr = | |
3520 | lookup_pointer_type (lookup_function_type (builtin_type->builtin_void)); | |
000177f0 | 3521 | builtin_type->builtin_core_addr = |
7ba81444 MS |
3522 | init_type (TYPE_CODE_INT, |
3523 | gdbarch_addr_bit (current_gdbarch) / 8, | |
000177f0 AC |
3524 | TYPE_FLAG_UNSIGNED, |
3525 | "__CORE_ADDR", (struct objfile *) NULL); | |
3526 | ||
64c50499 UW |
3527 | |
3528 | /* The following set of types is used for symbols with no | |
3529 | debug information. */ | |
7ba81444 MS |
3530 | builtin_type->nodebug_text_symbol = |
3531 | init_type (TYPE_CODE_FUNC, 1, 0, | |
3532 | "<text variable, no debug info>", NULL); | |
3533 | TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol) = | |
3534 | builtin_type->builtin_int; | |
3535 | builtin_type->nodebug_data_symbol = | |
3536 | init_type (TYPE_CODE_INT, | |
3537 | gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0, | |
3538 | "<data variable, no debug info>", NULL); | |
3539 | builtin_type->nodebug_unknown_symbol = | |
3540 | init_type (TYPE_CODE_INT, 1, 0, | |
3541 | "<variable (not text or data), no debug info>", NULL); | |
3542 | builtin_type->nodebug_tls_symbol = | |
3543 | init_type (TYPE_CODE_INT, | |
3544 | gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0, | |
3545 | "<thread local variable, no debug info>", NULL); | |
64c50499 | 3546 | |
000177f0 AC |
3547 | return builtin_type; |
3548 | } | |
3549 | ||
a14ed312 | 3550 | extern void _initialize_gdbtypes (void); |
c906108c | 3551 | void |
fba45db2 | 3552 | _initialize_gdbtypes (void) |
c906108c | 3553 | { |
5674de60 UW |
3554 | gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init); |
3555 | ||
7ba81444 MS |
3556 | /* FIXME: The following types are architecture-neutral. However, |
3557 | they contain pointer_type and reference_type fields potentially | |
3558 | caching pointer or reference types that *are* architecture | |
3559 | dependent. */ | |
7ad6570d AC |
3560 | |
3561 | builtin_type_int0 = | |
3562 | init_type (TYPE_CODE_INT, 0 / 8, | |
3563 | 0, | |
3564 | "int0_t", (struct objfile *) NULL); | |
3565 | builtin_type_int8 = | |
3566 | init_type (TYPE_CODE_INT, 8 / 8, | |
3567 | 0, | |
3568 | "int8_t", (struct objfile *) NULL); | |
3569 | builtin_type_uint8 = | |
3570 | init_type (TYPE_CODE_INT, 8 / 8, | |
3571 | TYPE_FLAG_UNSIGNED, | |
3572 | "uint8_t", (struct objfile *) NULL); | |
3573 | builtin_type_int16 = | |
3574 | init_type (TYPE_CODE_INT, 16 / 8, | |
3575 | 0, | |
3576 | "int16_t", (struct objfile *) NULL); | |
3577 | builtin_type_uint16 = | |
3578 | init_type (TYPE_CODE_INT, 16 / 8, | |
3579 | TYPE_FLAG_UNSIGNED, | |
3580 | "uint16_t", (struct objfile *) NULL); | |
3581 | builtin_type_int32 = | |
3582 | init_type (TYPE_CODE_INT, 32 / 8, | |
3583 | 0, | |
3584 | "int32_t", (struct objfile *) NULL); | |
3585 | builtin_type_uint32 = | |
3586 | init_type (TYPE_CODE_INT, 32 / 8, | |
3587 | TYPE_FLAG_UNSIGNED, | |
3588 | "uint32_t", (struct objfile *) NULL); | |
3589 | builtin_type_int64 = | |
3590 | init_type (TYPE_CODE_INT, 64 / 8, | |
3591 | 0, | |
3592 | "int64_t", (struct objfile *) NULL); | |
3593 | builtin_type_uint64 = | |
3594 | init_type (TYPE_CODE_INT, 64 / 8, | |
3595 | TYPE_FLAG_UNSIGNED, | |
3596 | "uint64_t", (struct objfile *) NULL); | |
3597 | builtin_type_int128 = | |
3598 | init_type (TYPE_CODE_INT, 128 / 8, | |
3599 | 0, | |
3600 | "int128_t", (struct objfile *) NULL); | |
3601 | builtin_type_uint128 = | |
3602 | init_type (TYPE_CODE_INT, 128 / 8, | |
3603 | TYPE_FLAG_UNSIGNED, | |
3604 | "uint128_t", (struct objfile *) NULL); | |
3605 | ||
7ba81444 MS |
3606 | builtin_type_ieee_single = |
3607 | build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single); | |
3608 | builtin_type_ieee_double = | |
3609 | build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double); | |
3610 | builtin_type_i387_ext = | |
3611 | build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext); | |
3612 | builtin_type_m68881_ext = | |
3613 | build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext); | |
3614 | builtin_type_arm_ext = | |
3615 | build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext); | |
3616 | builtin_type_ia64_spill = | |
3617 | build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill); | |
3618 | builtin_type_ia64_quad = | |
3619 | build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad); | |
598f52df | 3620 | |
85c07804 AC |
3621 | add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\ |
3622 | Set debugging of C++ overloading."), _("\ | |
3623 | Show debugging of C++ overloading."), _("\ | |
3624 | When enabled, ranking of the functions is displayed."), | |
3625 | NULL, | |
920d2a44 | 3626 | show_overload_debug, |
85c07804 | 3627 | &setdebuglist, &showdebuglist); |
5674de60 | 3628 | |
7ba81444 | 3629 | /* Add user knob for controlling resolution of opaque types. */ |
5674de60 UW |
3630 | add_setshow_boolean_cmd ("opaque-type-resolution", class_support, |
3631 | &opaque_type_resolution, _("\ | |
3632 | Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\ | |
3633 | Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL, | |
3634 | NULL, | |
3635 | show_opaque_type_resolution, | |
3636 | &setlist, &showlist); | |
c906108c | 3637 | } |