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