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