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