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