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