]>
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 | { | |
1279 | fill_in_vptr_fieldno (TYPE_BASECLASS (type, i)); | |
1280 | if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0) | |
1281 | { | |
1282 | TYPE_VPTR_FIELDNO (type) | |
1283 | = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)); | |
1284 | TYPE_VPTR_BASETYPE (type) | |
1285 | = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i)); | |
1286 | break; | |
1287 | } | |
1288 | } | |
1289 | } | |
1290 | } | |
1291 | ||
1292 | /* Find the method and field indices for the destructor in class type T. | |
1293 | Return 1 if the destructor was found, otherwise, return 0. */ | |
1294 | ||
1295 | int | |
fba45db2 | 1296 | get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp) |
c906108c SS |
1297 | { |
1298 | int i; | |
1299 | ||
1300 | for (i = 0; i < TYPE_NFN_FIELDS (t); i++) | |
1301 | { | |
1302 | int j; | |
1303 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); | |
1304 | ||
1305 | for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++) | |
1306 | { | |
015a42b4 | 1307 | if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0) |
c906108c SS |
1308 | { |
1309 | *method_indexp = i; | |
1310 | *field_indexp = j; | |
1311 | return 1; | |
1312 | } | |
1313 | } | |
1314 | } | |
1315 | return 0; | |
1316 | } | |
1317 | ||
1318 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. | |
1319 | ||
1320 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
1321 | we can find a full definition in some other file. If so, copy this | |
1322 | definition, so we can use it in future. There used to be a comment (but | |
1323 | not any code) that if we don't find a full definition, we'd set a flag | |
1324 | so we don't spend time in the future checking the same type. That would | |
1325 | be a mistake, though--we might load in more symbols which contain a | |
1326 | full definition for the type. | |
1327 | ||
7b83ea04 | 1328 | This used to be coded as a macro, but I don't think it is called |
c906108c SS |
1329 | often enough to merit such treatment. */ |
1330 | ||
1331 | struct complaint stub_noname_complaint = | |
c5aa993b | 1332 | {"stub type has NULL name", 0, 0}; |
c906108c SS |
1333 | |
1334 | struct type * | |
a02fd225 | 1335 | check_typedef (struct type *type) |
c906108c SS |
1336 | { |
1337 | struct type *orig_type = type; | |
a02fd225 DJ |
1338 | int is_const, is_volatile; |
1339 | ||
c906108c SS |
1340 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
1341 | { | |
1342 | if (!TYPE_TARGET_TYPE (type)) | |
1343 | { | |
c5aa993b | 1344 | char *name; |
c906108c SS |
1345 | struct symbol *sym; |
1346 | ||
1347 | /* It is dangerous to call lookup_symbol if we are currently | |
1348 | reading a symtab. Infinite recursion is one danger. */ | |
1349 | if (currently_reading_symtab) | |
1350 | return type; | |
1351 | ||
1352 | name = type_name_no_tag (type); | |
1353 | /* FIXME: shouldn't we separately check the TYPE_NAME and the | |
1354 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE | |
1355 | as appropriate? (this code was written before TYPE_NAME and | |
1356 | TYPE_TAG_NAME were separate). */ | |
1357 | if (name == NULL) | |
1358 | { | |
1359 | complain (&stub_noname_complaint); | |
1360 | return type; | |
1361 | } | |
c5aa993b | 1362 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, |
c906108c SS |
1363 | (struct symtab **) NULL); |
1364 | if (sym) | |
1365 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); | |
1366 | else | |
c5aa993b | 1367 | TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */ |
c906108c SS |
1368 | } |
1369 | type = TYPE_TARGET_TYPE (type); | |
1370 | } | |
1371 | ||
a02fd225 DJ |
1372 | is_const = TYPE_CONST (type); |
1373 | is_volatile = TYPE_VOLATILE (type); | |
1374 | ||
c906108c SS |
1375 | /* If this is a struct/class/union with no fields, then check whether a |
1376 | full definition exists somewhere else. This is for systems where a | |
1377 | type definition with no fields is issued for such types, instead of | |
c5aa993b JM |
1378 | identifying them as stub types in the first place */ |
1379 | ||
c906108c SS |
1380 | if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab) |
1381 | { | |
c5aa993b JM |
1382 | char *name = type_name_no_tag (type); |
1383 | struct type *newtype; | |
c906108c SS |
1384 | if (name == NULL) |
1385 | { | |
1386 | complain (&stub_noname_complaint); | |
1387 | return type; | |
1388 | } | |
1389 | newtype = lookup_transparent_type (name); | |
1390 | if (newtype) | |
a02fd225 | 1391 | make_cv_type (is_const, is_volatile, newtype, &type); |
c906108c SS |
1392 | } |
1393 | /* Otherwise, rely on the stub flag being set for opaque/stubbed types */ | |
74a9bb82 | 1394 | else if (TYPE_STUB (type) && !currently_reading_symtab) |
c906108c | 1395 | { |
c5aa993b | 1396 | char *name = type_name_no_tag (type); |
c906108c | 1397 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
7b83ea04 AC |
1398 | TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE |
1399 | as appropriate? (this code was written before TYPE_NAME and | |
1400 | TYPE_TAG_NAME were separate). */ | |
c906108c SS |
1401 | struct symbol *sym; |
1402 | if (name == NULL) | |
1403 | { | |
1404 | complain (&stub_noname_complaint); | |
1405 | return type; | |
1406 | } | |
1407 | sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL); | |
1408 | if (sym) | |
a02fd225 | 1409 | make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type); |
c906108c SS |
1410 | } |
1411 | ||
74a9bb82 | 1412 | if (TYPE_TARGET_STUB (type)) |
c906108c SS |
1413 | { |
1414 | struct type *range_type; | |
1415 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1416 | ||
74a9bb82 | 1417 | if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type)) |
c5aa993b JM |
1418 | { |
1419 | } | |
c906108c SS |
1420 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
1421 | && TYPE_NFIELDS (type) == 1 | |
1422 | && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0)) | |
1423 | == TYPE_CODE_RANGE)) | |
1424 | { | |
1425 | /* Now recompute the length of the array type, based on its | |
1426 | number of elements and the target type's length. */ | |
1427 | TYPE_LENGTH (type) = | |
1428 | ((TYPE_FIELD_BITPOS (range_type, 1) | |
1429 | - TYPE_FIELD_BITPOS (range_type, 0) | |
1430 | + 1) | |
1431 | * TYPE_LENGTH (target_type)); | |
1432 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1433 | } | |
1434 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) | |
1435 | { | |
1436 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); | |
1437 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1438 | } | |
1439 | } | |
1440 | /* Cache TYPE_LENGTH for future use. */ | |
1441 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); | |
1442 | return type; | |
1443 | } | |
1444 | ||
1445 | /* New code added to support parsing of Cfront stabs strings */ | |
c906108c SS |
1446 | #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; } |
1447 | #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; } | |
1448 | ||
c5aa993b | 1449 | static void |
fba45db2 | 1450 | add_name (struct extra *pextras, char *n) |
c906108c SS |
1451 | { |
1452 | int nlen; | |
1453 | ||
c5aa993b | 1454 | if ((nlen = (n ? strlen (n) : 0)) == 0) |
c906108c | 1455 | return; |
c5aa993b JM |
1456 | sprintf (pextras->str + pextras->len, "%d%s", nlen, n); |
1457 | pextras->len = strlen (pextras->str); | |
c906108c SS |
1458 | } |
1459 | ||
c5aa993b | 1460 | static void |
fba45db2 | 1461 | add_mangled_type (struct extra *pextras, struct type *t) |
c906108c SS |
1462 | { |
1463 | enum type_code tcode; | |
1464 | int tlen, tflags; | |
c5aa993b | 1465 | char *tname; |
c906108c | 1466 | |
c5aa993b JM |
1467 | tcode = TYPE_CODE (t); |
1468 | tlen = TYPE_LENGTH (t); | |
1469 | tflags = TYPE_FLAGS (t); | |
1470 | tname = TYPE_NAME (t); | |
c906108c SS |
1471 | /* args of "..." seem to get mangled as "e" */ |
1472 | ||
c5aa993b JM |
1473 | switch (tcode) |
1474 | { | |
1475 | case TYPE_CODE_INT: | |
1476 | if (tflags == 1) | |
1477 | ADD_EXTRA ('U'); | |
1478 | switch (tlen) | |
1479 | { | |
1480 | case 1: | |
1481 | ADD_EXTRA ('c'); | |
1482 | break; | |
1483 | case 2: | |
1484 | ADD_EXTRA ('s'); | |
1485 | break; | |
1486 | case 4: | |
1487 | { | |
1488 | char *pname; | |
1489 | if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long")) | |
9846de1b JM |
1490 | { |
1491 | ADD_EXTRA ('l'); | |
1492 | } | |
1493 | else | |
1494 | { | |
1495 | ADD_EXTRA ('i'); | |
1496 | } | |
c5aa993b JM |
1497 | } |
1498 | break; | |
1499 | default: | |
1500 | { | |
1501 | ||
1502 | static struct complaint msg = | |
1503 | {"Bad int type code length x%x\n", 0, 0}; | |
1504 | ||
1505 | complain (&msg, tlen); | |
1506 | ||
1507 | } | |
1508 | } | |
1509 | break; | |
1510 | case TYPE_CODE_FLT: | |
1511 | switch (tlen) | |
1512 | { | |
1513 | case 4: | |
1514 | ADD_EXTRA ('f'); | |
1515 | break; | |
1516 | case 8: | |
1517 | ADD_EXTRA ('d'); | |
1518 | break; | |
1519 | case 16: | |
1520 | ADD_EXTRA ('r'); | |
1521 | break; | |
1522 | default: | |
1523 | { | |
1524 | static struct complaint msg = | |
1525 | {"Bad float type code length x%x\n", 0, 0}; | |
1526 | complain (&msg, tlen); | |
1527 | } | |
1528 | } | |
1529 | break; | |
1530 | case TYPE_CODE_REF: | |
1531 | ADD_EXTRA ('R'); | |
1532 | /* followed by what it's a ref to */ | |
1533 | break; | |
1534 | case TYPE_CODE_PTR: | |
1535 | ADD_EXTRA ('P'); | |
1536 | /* followed by what it's a ptr to */ | |
1537 | break; | |
1538 | case TYPE_CODE_TYPEDEF: | |
1539 | { | |
1540 | static struct complaint msg = | |
1541 | {"Typedefs in overloaded functions not yet supported\n", 0, 0}; | |
1542 | complain (&msg); | |
1543 | } | |
c906108c SS |
1544 | /* followed by type bytes & name */ |
1545 | break; | |
1546 | case TYPE_CODE_FUNC: | |
c5aa993b | 1547 | ADD_EXTRA ('F'); |
c906108c SS |
1548 | /* followed by func's arg '_' & ret types */ |
1549 | break; | |
1550 | case TYPE_CODE_VOID: | |
c5aa993b | 1551 | ADD_EXTRA ('v'); |
c906108c SS |
1552 | break; |
1553 | case TYPE_CODE_METHOD: | |
c5aa993b | 1554 | ADD_EXTRA ('M'); |
c906108c | 1555 | /* followed by name of class and func's arg '_' & ret types */ |
c5aa993b JM |
1556 | add_name (pextras, tname); |
1557 | ADD_EXTRA ('F'); /* then mangle function */ | |
c906108c | 1558 | break; |
c5aa993b JM |
1559 | case TYPE_CODE_STRUCT: /* C struct */ |
1560 | case TYPE_CODE_UNION: /* C union */ | |
1561 | case TYPE_CODE_ENUM: /* Enumeration type */ | |
c906108c | 1562 | /* followed by name of type */ |
c5aa993b | 1563 | add_name (pextras, tname); |
c906108c SS |
1564 | break; |
1565 | ||
c5aa993b JM |
1566 | /* errors possible types/not supported */ |
1567 | case TYPE_CODE_CHAR: | |
1568 | case TYPE_CODE_ARRAY: /* Array type */ | |
1569 | case TYPE_CODE_MEMBER: /* Member type */ | |
c906108c | 1570 | case TYPE_CODE_BOOL: |
c5aa993b | 1571 | case TYPE_CODE_COMPLEX: /* Complex float */ |
c906108c | 1572 | case TYPE_CODE_UNDEF: |
c5aa993b JM |
1573 | case TYPE_CODE_SET: /* Pascal sets */ |
1574 | case TYPE_CODE_RANGE: | |
c906108c SS |
1575 | case TYPE_CODE_STRING: |
1576 | case TYPE_CODE_BITSTRING: | |
1577 | case TYPE_CODE_ERROR: | |
c5aa993b | 1578 | default: |
c906108c | 1579 | { |
c5aa993b JM |
1580 | static struct complaint msg = |
1581 | {"Unknown type code x%x\n", 0, 0}; | |
1582 | complain (&msg, tcode); | |
c906108c SS |
1583 | } |
1584 | } | |
0004e5a2 DJ |
1585 | if (TYPE_TARGET_TYPE (t)) |
1586 | add_mangled_type (pextras, TYPE_TARGET_TYPE (t)); | |
c906108c SS |
1587 | } |
1588 | ||
1589 | #if 0 | |
1590 | void | |
fba45db2 | 1591 | cfront_mangle_name (struct type *type, int i, int j) |
c906108c | 1592 | { |
c5aa993b JM |
1593 | struct fn_field *f; |
1594 | char *mangled_name = gdb_mangle_name (type, i, j); | |
1595 | ||
1596 | f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */ | |
1597 | ||
7b83ea04 | 1598 | /* kludge to support cfront methods - gdb expects to find "F" for |
c5aa993b JM |
1599 | ARM_mangled names, so when we mangle, we have to add it here */ |
1600 | if (ARM_DEMANGLING) | |
1601 | { | |
1602 | int k; | |
1603 | char *arm_mangled_name; | |
1604 | struct fn_field *method = &f[j]; | |
1605 | char *field_name = TYPE_FN_FIELDLIST_NAME (type, i); | |
1606 | char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); | |
1607 | char *newname = type_name_no_tag (type); | |
1608 | ||
1609 | struct type *ftype = TYPE_FN_FIELD_TYPE (f, j); | |
1610 | int nargs = TYPE_NFIELDS (ftype); /* number of args */ | |
1611 | struct extra extras, *pextras = &extras; | |
1612 | INIT_EXTRA | |
c906108c SS |
1613 | |
1614 | if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */ | |
c5aa993b JM |
1615 | ADD_EXTRA ('S') |
1616 | ADD_EXTRA ('F') | |
c906108c | 1617 | /* add args here! */ |
c5aa993b JM |
1618 | if (nargs <= 1) /* no args besides this */ |
1619 | ADD_EXTRA ('v') | |
1620 | else | |
1621 | { | |
1622 | for (k = 1; k < nargs; k++) | |
1623 | { | |
1624 | struct type *t; | |
1625 | t = TYPE_FIELD_TYPE (ftype, k); | |
1626 | add_mangled_type (pextras, t); | |
1627 | } | |
1628 | } | |
1629 | ADD_EXTRA ('\0') | |
1630 | printf ("add_mangled_type: %s\n", extras.str); /* FIXME */ | |
3c37485b | 1631 | xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str); |
b8c9b27d | 1632 | xfree (mangled_name); |
c5aa993b JM |
1633 | mangled_name = arm_mangled_name; |
1634 | } | |
c906108c | 1635 | } |
c5aa993b | 1636 | #endif /* 0 */ |
c906108c SS |
1637 | |
1638 | #undef ADD_EXTRA | |
1639 | /* End of new code added to support parsing of Cfront stabs strings */ | |
1640 | ||
c91ecb25 ND |
1641 | /* Parse a type expression in the string [P..P+LENGTH). If an error occurs, |
1642 | silently return builtin_type_void. */ | |
1643 | ||
1644 | struct type * | |
1645 | safe_parse_type (char *p, int length) | |
1646 | { | |
1647 | struct ui_file *saved_gdb_stderr; | |
1648 | struct type *type; | |
1649 | ||
1650 | /* Suppress error messages. */ | |
1651 | saved_gdb_stderr = gdb_stderr; | |
1652 | gdb_stderr = ui_file_new (); | |
1653 | ||
1654 | /* Call parse_and_eval_type() without fear of longjmp()s. */ | |
1655 | if (!gdb_parse_and_eval_type (p, length, &type)) | |
1656 | type = builtin_type_void; | |
1657 | ||
1658 | /* Stop suppressing error messages. */ | |
1659 | ui_file_delete (gdb_stderr); | |
1660 | gdb_stderr = saved_gdb_stderr; | |
1661 | ||
1662 | return type; | |
1663 | } | |
1664 | ||
c906108c SS |
1665 | /* Ugly hack to convert method stubs into method types. |
1666 | ||
1667 | He ain't kiddin'. This demangles the name of the method into a string | |
1668 | including argument types, parses out each argument type, generates | |
1669 | a string casting a zero to that type, evaluates the string, and stuffs | |
1670 | the resulting type into an argtype vector!!! Then it knows the type | |
1671 | of the whole function (including argument types for overloading), | |
1672 | which info used to be in the stab's but was removed to hack back | |
1673 | the space required for them. */ | |
1674 | ||
de17c821 | 1675 | static void |
fba45db2 | 1676 | check_stub_method (struct type *type, int method_id, int signature_id) |
c906108c SS |
1677 | { |
1678 | struct fn_field *f; | |
1679 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); | |
1680 | char *demangled_name = cplus_demangle (mangled_name, | |
1681 | DMGL_PARAMS | DMGL_ANSI); | |
1682 | char *argtypetext, *p; | |
1683 | int depth = 0, argcount = 1; | |
ad2f7632 | 1684 | struct field *argtypes; |
c906108c SS |
1685 | struct type *mtype; |
1686 | ||
1687 | /* Make sure we got back a function string that we can use. */ | |
1688 | if (demangled_name) | |
1689 | p = strchr (demangled_name, '('); | |
502dcf4e AC |
1690 | else |
1691 | p = NULL; | |
c906108c SS |
1692 | |
1693 | if (demangled_name == NULL || p == NULL) | |
1694 | error ("Internal: Cannot demangle mangled name `%s'.", mangled_name); | |
1695 | ||
1696 | /* Now, read in the parameters that define this type. */ | |
1697 | p += 1; | |
1698 | argtypetext = p; | |
1699 | while (*p) | |
1700 | { | |
070ad9f0 | 1701 | if (*p == '(' || *p == '<') |
c906108c SS |
1702 | { |
1703 | depth += 1; | |
1704 | } | |
070ad9f0 | 1705 | else if (*p == ')' || *p == '>') |
c906108c SS |
1706 | { |
1707 | depth -= 1; | |
1708 | } | |
1709 | else if (*p == ',' && depth == 0) | |
1710 | { | |
1711 | argcount += 1; | |
1712 | } | |
1713 | ||
1714 | p += 1; | |
1715 | } | |
1716 | ||
ad2f7632 DJ |
1717 | /* If we read one argument and it was ``void'', don't count it. */ |
1718 | if (strncmp (argtypetext, "(void)", 6) == 0) | |
1719 | argcount -= 1; | |
c906108c | 1720 | |
ad2f7632 DJ |
1721 | /* We need one extra slot, for the THIS pointer. */ |
1722 | ||
1723 | argtypes = (struct field *) | |
1724 | TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field)); | |
c906108c | 1725 | p = argtypetext; |
4a1970e4 DJ |
1726 | |
1727 | /* Add THIS pointer for non-static methods. */ | |
1728 | f = TYPE_FN_FIELDLIST1 (type, method_id); | |
1729 | if (TYPE_FN_FIELD_STATIC_P (f, signature_id)) | |
1730 | argcount = 0; | |
1731 | else | |
1732 | { | |
ad2f7632 | 1733 | argtypes[0].type = lookup_pointer_type (type); |
4a1970e4 DJ |
1734 | argcount = 1; |
1735 | } | |
c906108c | 1736 | |
c5aa993b | 1737 | if (*p != ')') /* () means no args, skip while */ |
c906108c SS |
1738 | { |
1739 | depth = 0; | |
1740 | while (*p) | |
1741 | { | |
1742 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
1743 | { | |
ad2f7632 DJ |
1744 | /* Avoid parsing of ellipsis, they will be handled below. |
1745 | Also avoid ``void'' as above. */ | |
1746 | if (strncmp (argtypetext, "...", p - argtypetext) != 0 | |
1747 | && strncmp (argtypetext, "void", p - argtypetext) != 0) | |
c906108c | 1748 | { |
ad2f7632 | 1749 | argtypes[argcount].type = |
c91ecb25 | 1750 | safe_parse_type (argtypetext, p - argtypetext); |
c906108c SS |
1751 | argcount += 1; |
1752 | } | |
1753 | argtypetext = p + 1; | |
1754 | } | |
1755 | ||
070ad9f0 | 1756 | if (*p == '(' || *p == '<') |
c906108c SS |
1757 | { |
1758 | depth += 1; | |
1759 | } | |
070ad9f0 | 1760 | else if (*p == ')' || *p == '>') |
c906108c SS |
1761 | { |
1762 | depth -= 1; | |
1763 | } | |
1764 | ||
1765 | p += 1; | |
1766 | } | |
1767 | } | |
1768 | ||
c906108c SS |
1769 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; |
1770 | ||
1771 | /* Now update the old "stub" type into a real type. */ | |
1772 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); | |
1773 | TYPE_DOMAIN_TYPE (mtype) = type; | |
ad2f7632 DJ |
1774 | TYPE_FIELDS (mtype) = argtypes; |
1775 | TYPE_NFIELDS (mtype) = argcount; | |
c906108c SS |
1776 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; |
1777 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; | |
ad2f7632 DJ |
1778 | if (p[-2] == '.') |
1779 | TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS; | |
1780 | ||
1781 | xfree (demangled_name); | |
c906108c SS |
1782 | } |
1783 | ||
de17c821 DJ |
1784 | /* This is the external interface to check_stub_method, above. This function |
1785 | unstubs all of the signatures for TYPE's METHOD_ID method name. After | |
1786 | calling this function TYPE_FN_FIELD_STUB will be cleared for each signature | |
1787 | and TYPE_FN_FIELDLIST_NAME will be correct. | |
1788 | ||
1789 | This function unfortunately can not die until stabs do. */ | |
1790 | ||
1791 | void | |
1792 | check_stub_method_group (struct type *type, int method_id) | |
1793 | { | |
1794 | int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id); | |
1795 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id); | |
1796 | int j, found_stub; | |
1797 | ||
1798 | for (j = 0; j < len; j++) | |
1799 | if (TYPE_FN_FIELD_STUB (f, j)) | |
1800 | { | |
1801 | found_stub = 1; | |
1802 | check_stub_method (type, method_id, j); | |
1803 | } | |
1804 | ||
1805 | /* GNU v3 methods with incorrect names were corrected when we read in | |
1806 | type information, because it was cheaper to do it then. The only GNU v2 | |
1807 | methods with incorrect method names are operators and destructors; | |
1808 | destructors were also corrected when we read in type information. | |
1809 | ||
1810 | Therefore the only thing we need to handle here are v2 operator | |
1811 | names. */ | |
1812 | if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0) | |
1813 | { | |
1814 | int ret; | |
1815 | char dem_opname[256]; | |
1816 | ||
1817 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id), | |
1818 | dem_opname, DMGL_ANSI); | |
1819 | if (!ret) | |
1820 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id), | |
1821 | dem_opname, 0); | |
1822 | if (ret) | |
1823 | TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname); | |
1824 | } | |
1825 | } | |
1826 | ||
c906108c SS |
1827 | const struct cplus_struct_type cplus_struct_default; |
1828 | ||
1829 | void | |
fba45db2 | 1830 | allocate_cplus_struct_type (struct type *type) |
c906108c SS |
1831 | { |
1832 | if (!HAVE_CPLUS_STRUCT (type)) | |
1833 | { | |
1834 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
1835 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); | |
c5aa993b | 1836 | *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default; |
c906108c SS |
1837 | } |
1838 | } | |
1839 | ||
1840 | /* Helper function to initialize the standard scalar types. | |
1841 | ||
1842 | If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy | |
1843 | of the string pointed to by name in the type_obstack for that objfile, | |
1844 | and initialize the type name to that copy. There are places (mipsread.c | |
1845 | in particular, where init_type is called with a NULL value for NAME). */ | |
1846 | ||
1847 | struct type * | |
fba45db2 KB |
1848 | init_type (enum type_code code, int length, int flags, char *name, |
1849 | struct objfile *objfile) | |
c906108c SS |
1850 | { |
1851 | register struct type *type; | |
1852 | ||
1853 | type = alloc_type (objfile); | |
1854 | TYPE_CODE (type) = code; | |
1855 | TYPE_LENGTH (type) = length; | |
1856 | TYPE_FLAGS (type) |= flags; | |
1857 | if ((name != NULL) && (objfile != NULL)) | |
1858 | { | |
1859 | TYPE_NAME (type) = | |
c5aa993b | 1860 | obsavestring (name, strlen (name), &objfile->type_obstack); |
c906108c SS |
1861 | } |
1862 | else | |
1863 | { | |
1864 | TYPE_NAME (type) = name; | |
1865 | } | |
1866 | ||
1867 | /* C++ fancies. */ | |
1868 | ||
1869 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) | |
1870 | { | |
1871 | INIT_CPLUS_SPECIFIC (type); | |
1872 | } | |
1873 | return (type); | |
1874 | } | |
1875 | ||
0e101458 AC |
1876 | /* Helper function. Create an empty composite type. */ |
1877 | ||
1878 | struct type * | |
1879 | init_composite_type (char *name, enum type_code code) | |
1880 | { | |
1881 | struct type *t; | |
1882 | gdb_assert (code == TYPE_CODE_STRUCT | |
1883 | || code == TYPE_CODE_UNION); | |
1884 | t = init_type (code, 0, 0, NULL, NULL); | |
1885 | TYPE_TAG_NAME (t) = name; | |
1886 | return t; | |
1887 | } | |
1888 | ||
1889 | /* Helper function. Append a field to a composite type. */ | |
1890 | ||
1891 | void | |
1892 | append_composite_type_field (struct type *t, char *name, struct type *field) | |
1893 | { | |
1894 | struct field *f; | |
1895 | TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1; | |
1896 | TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t), | |
1897 | sizeof (struct field) * TYPE_NFIELDS (t)); | |
1898 | f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]); | |
1899 | memset (f, 0, sizeof f[0]); | |
1900 | FIELD_TYPE (f[0]) = field; | |
1901 | FIELD_NAME (f[0]) = name; | |
1902 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
1903 | { | |
73d322b1 | 1904 | if (TYPE_LENGTH (t) < TYPE_LENGTH (field)) |
0e101458 AC |
1905 | TYPE_LENGTH (t) = TYPE_LENGTH (field); |
1906 | } | |
1907 | else if (TYPE_CODE (t) == TYPE_CODE_STRUCT) | |
1908 | { | |
1909 | TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field); | |
1910 | if (TYPE_NFIELDS (t) > 1) | |
1911 | { | |
1912 | FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1]) | |
1913 | + TYPE_LENGTH (field) * TARGET_CHAR_BIT); | |
1914 | } | |
1915 | } | |
1916 | } | |
1917 | ||
c906108c SS |
1918 | /* Look up a fundamental type for the specified objfile. |
1919 | May need to construct such a type if this is the first use. | |
1920 | ||
1921 | Some object file formats (ELF, COFF, etc) do not define fundamental | |
1922 | types such as "int" or "double". Others (stabs for example), do | |
1923 | define fundamental types. | |
1924 | ||
1925 | For the formats which don't provide fundamental types, gdb can create | |
1926 | such types, using defaults reasonable for the current language and | |
1927 | the current target machine. | |
1928 | ||
1929 | NOTE: This routine is obsolescent. Each debugging format reader | |
1930 | should manage it's own fundamental types, either creating them from | |
1931 | suitable defaults or reading them from the debugging information, | |
1932 | whichever is appropriate. The DWARF reader has already been | |
1933 | fixed to do this. Once the other readers are fixed, this routine | |
1934 | will go away. Also note that fundamental types should be managed | |
1935 | on a compilation unit basis in a multi-language environment, not | |
1936 | on a linkage unit basis as is done here. */ | |
1937 | ||
1938 | ||
1939 | struct type * | |
fba45db2 | 1940 | lookup_fundamental_type (struct objfile *objfile, int typeid) |
c906108c SS |
1941 | { |
1942 | register struct type **typep; | |
1943 | register int nbytes; | |
1944 | ||
1945 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
1946 | { | |
1947 | error ("internal error - invalid fundamental type id %d", typeid); | |
1948 | } | |
1949 | ||
1950 | /* If this is the first time we need a fundamental type for this objfile | |
1951 | then we need to initialize the vector of type pointers. */ | |
c5aa993b JM |
1952 | |
1953 | if (objfile->fundamental_types == NULL) | |
c906108c SS |
1954 | { |
1955 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); | |
c5aa993b JM |
1956 | objfile->fundamental_types = (struct type **) |
1957 | obstack_alloc (&objfile->type_obstack, nbytes); | |
1958 | memset ((char *) objfile->fundamental_types, 0, nbytes); | |
c906108c SS |
1959 | OBJSTAT (objfile, n_types += FT_NUM_MEMBERS); |
1960 | } | |
1961 | ||
1962 | /* Look for this particular type in the fundamental type vector. If one is | |
1963 | not found, create and install one appropriate for the current language. */ | |
1964 | ||
c5aa993b | 1965 | typep = objfile->fundamental_types + typeid; |
c906108c SS |
1966 | if (*typep == NULL) |
1967 | { | |
1968 | *typep = create_fundamental_type (objfile, typeid); | |
1969 | } | |
1970 | ||
1971 | return (*typep); | |
1972 | } | |
1973 | ||
1974 | int | |
fba45db2 | 1975 | can_dereference (struct type *t) |
c906108c SS |
1976 | { |
1977 | /* FIXME: Should we return true for references as well as pointers? */ | |
1978 | CHECK_TYPEDEF (t); | |
1979 | return | |
1980 | (t != NULL | |
1981 | && TYPE_CODE (t) == TYPE_CODE_PTR | |
1982 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); | |
1983 | } | |
1984 | ||
adf40b2e | 1985 | int |
fba45db2 | 1986 | is_integral_type (struct type *t) |
adf40b2e JM |
1987 | { |
1988 | CHECK_TYPEDEF (t); | |
1989 | return | |
1990 | ((t != NULL) | |
d4f3574e SS |
1991 | && ((TYPE_CODE (t) == TYPE_CODE_INT) |
1992 | || (TYPE_CODE (t) == TYPE_CODE_ENUM) | |
1993 | || (TYPE_CODE (t) == TYPE_CODE_CHAR) | |
1994 | || (TYPE_CODE (t) == TYPE_CODE_RANGE) | |
1995 | || (TYPE_CODE (t) == TYPE_CODE_BOOL))); | |
adf40b2e JM |
1996 | } |
1997 | ||
db034ac5 AC |
1998 | /* (OBSOLETE) Chill (OBSOLETE) varying string and arrays are |
1999 | represented as follows: | |
c906108c SS |
2000 | |
2001 | struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data}; | |
2002 | ||
db034ac5 AC |
2003 | Return true if TYPE is such a (OBSOLETE) Chill (OBSOLETE) varying |
2004 | type. */ | |
2005 | ||
2006 | /* OBSOLETE int */ | |
2007 | /* OBSOLETE chill_varying_type (struct type *type) */ | |
2008 | /* OBSOLETE { */ | |
2009 | /* OBSOLETE if (TYPE_CODE (type) != TYPE_CODE_STRUCT */ | |
2010 | /* OBSOLETE || TYPE_NFIELDS (type) != 2 */ | |
2011 | /* OBSOLETE || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0) */ | |
2012 | /* OBSOLETE return 0; */ | |
2013 | /* OBSOLETE return 1; */ | |
2014 | /* OBSOLETE } */ | |
c906108c | 2015 | |
7b83ea04 | 2016 | /* Check whether BASE is an ancestor or base class or DCLASS |
c906108c SS |
2017 | Return 1 if so, and 0 if not. |
2018 | Note: callers may want to check for identity of the types before | |
2019 | calling this function -- identical types are considered to satisfy | |
2020 | the ancestor relationship even if they're identical */ | |
2021 | ||
2022 | int | |
fba45db2 | 2023 | is_ancestor (struct type *base, struct type *dclass) |
c906108c SS |
2024 | { |
2025 | int i; | |
c5aa993b | 2026 | |
c906108c SS |
2027 | CHECK_TYPEDEF (base); |
2028 | CHECK_TYPEDEF (dclass); | |
2029 | ||
2030 | if (base == dclass) | |
2031 | return 1; | |
6b1ba9a0 ND |
2032 | if (TYPE_NAME (base) && TYPE_NAME (dclass) && |
2033 | !strcmp (TYPE_NAME (base), TYPE_NAME (dclass))) | |
2034 | return 1; | |
c906108c SS |
2035 | |
2036 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
2037 | if (is_ancestor (base, TYPE_BASECLASS (dclass, i))) | |
2038 | return 1; | |
2039 | ||
2040 | return 0; | |
2041 | } | |
2042 | ||
2043 | ||
2044 | ||
2045 | /* See whether DCLASS has a virtual table. This routine is aimed at | |
2046 | the HP/Taligent ANSI C++ runtime model, and may not work with other | |
2047 | runtime models. Return 1 => Yes, 0 => No. */ | |
2048 | ||
2049 | int | |
fba45db2 | 2050 | has_vtable (struct type *dclass) |
c906108c SS |
2051 | { |
2052 | /* In the HP ANSI C++ runtime model, a class has a vtable only if it | |
2053 | has virtual functions or virtual bases. */ | |
2054 | ||
2055 | register int i; | |
2056 | ||
c5aa993b | 2057 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c | 2058 | return 0; |
c5aa993b | 2059 | |
c906108c | 2060 | /* First check for the presence of virtual bases */ |
c5aa993b JM |
2061 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) |
2062 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
2063 | if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) | |
2064 | return 1; | |
2065 | ||
c906108c | 2066 | /* Next check for virtual functions */ |
c5aa993b JM |
2067 | if (TYPE_FN_FIELDLISTS (dclass)) |
2068 | for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++) | |
2069 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0)) | |
c906108c | 2070 | return 1; |
c5aa993b JM |
2071 | |
2072 | /* Recurse on non-virtual bases to see if any of them needs a vtable */ | |
2073 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) | |
2074 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
2075 | if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) && | |
2076 | (has_vtable (TYPE_FIELD_TYPE (dclass, i)))) | |
2077 | return 1; | |
2078 | ||
2079 | /* Well, maybe we don't need a virtual table */ | |
c906108c SS |
2080 | return 0; |
2081 | } | |
2082 | ||
2083 | /* Return a pointer to the "primary base class" of DCLASS. | |
c5aa993b | 2084 | |
c906108c SS |
2085 | A NULL return indicates that DCLASS has no primary base, or that it |
2086 | couldn't be found (insufficient information). | |
c5aa993b | 2087 | |
c906108c SS |
2088 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
2089 | and may not work with other runtime models. */ | |
2090 | ||
2091 | struct type * | |
fba45db2 | 2092 | primary_base_class (struct type *dclass) |
c906108c SS |
2093 | { |
2094 | /* In HP ANSI C++'s runtime model, a "primary base class" of a class | |
2095 | is the first directly inherited, non-virtual base class that | |
2096 | requires a virtual table */ | |
2097 | ||
2098 | register int i; | |
2099 | ||
c5aa993b | 2100 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c SS |
2101 | return NULL; |
2102 | ||
c5aa993b JM |
2103 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
2104 | if (!TYPE_FIELD_VIRTUAL (dclass, i) && | |
2105 | has_vtable (TYPE_FIELD_TYPE (dclass, i))) | |
2106 | return TYPE_FIELD_TYPE (dclass, i); | |
c906108c SS |
2107 | |
2108 | return NULL; | |
2109 | } | |
2110 | ||
2111 | /* Global manipulated by virtual_base_list[_aux]() */ | |
2112 | ||
c5aa993b | 2113 | static struct vbase *current_vbase_list = NULL; |
c906108c SS |
2114 | |
2115 | /* Return a pointer to a null-terminated list of struct vbase | |
2116 | items. The vbasetype pointer of each item in the list points to the | |
2117 | type information for a virtual base of the argument DCLASS. | |
c5aa993b | 2118 | |
7b83ea04 | 2119 | Helper function for virtual_base_list(). |
c906108c SS |
2120 | Note: the list goes backward, right-to-left. virtual_base_list() |
2121 | copies the items out in reverse order. */ | |
2122 | ||
7a292a7a | 2123 | static void |
fba45db2 | 2124 | virtual_base_list_aux (struct type *dclass) |
c906108c | 2125 | { |
c5aa993b | 2126 | struct vbase *tmp_vbase; |
c906108c SS |
2127 | register int i; |
2128 | ||
c5aa993b | 2129 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
7a292a7a | 2130 | return; |
c906108c SS |
2131 | |
2132 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
2133 | { | |
2134 | /* Recurse on this ancestor, first */ | |
c5aa993b | 2135 | virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i)); |
c906108c SS |
2136 | |
2137 | /* If this current base is itself virtual, add it to the list */ | |
c5aa993b JM |
2138 | if (BASETYPE_VIA_VIRTUAL (dclass, i)) |
2139 | { | |
2140 | struct type *basetype = TYPE_FIELD_TYPE (dclass, i); | |
2141 | ||
2142 | /* Check if base already recorded */ | |
2143 | tmp_vbase = current_vbase_list; | |
2144 | while (tmp_vbase) | |
2145 | { | |
2146 | if (tmp_vbase->vbasetype == basetype) | |
2147 | break; /* found it */ | |
2148 | tmp_vbase = tmp_vbase->next; | |
2149 | } | |
2150 | ||
2151 | if (!tmp_vbase) /* normal exit from loop */ | |
2152 | { | |
2153 | /* Allocate new item for this virtual base */ | |
2154 | tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase)); | |
2155 | ||
2156 | /* Stick it on at the end of the list */ | |
2157 | tmp_vbase->vbasetype = basetype; | |
2158 | tmp_vbase->next = current_vbase_list; | |
2159 | current_vbase_list = tmp_vbase; | |
2160 | } | |
2161 | } /* if virtual */ | |
2162 | } /* for loop over bases */ | |
c906108c SS |
2163 | } |
2164 | ||
2165 | ||
2166 | /* Compute the list of virtual bases in the right order. Virtual | |
2167 | bases are laid out in the object's memory area in order of their | |
2168 | occurrence in a depth-first, left-to-right search through the | |
2169 | ancestors. | |
c5aa993b | 2170 | |
c906108c SS |
2171 | Argument DCLASS is the type whose virtual bases are required. |
2172 | Return value is the address of a null-terminated array of pointers | |
2173 | to struct type items. | |
c5aa993b | 2174 | |
c906108c SS |
2175 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
2176 | and may not work with other runtime models. | |
c5aa993b | 2177 | |
c906108c SS |
2178 | This routine merely hands off the argument to virtual_base_list_aux() |
2179 | and then copies the result into an array to save space. */ | |
2180 | ||
2181 | struct type ** | |
fba45db2 | 2182 | virtual_base_list (struct type *dclass) |
c906108c | 2183 | { |
c5aa993b JM |
2184 | register struct vbase *tmp_vbase; |
2185 | register struct vbase *tmp_vbase_2; | |
c906108c SS |
2186 | register int i; |
2187 | int count; | |
c5aa993b | 2188 | struct type **vbase_array; |
c906108c SS |
2189 | |
2190 | current_vbase_list = NULL; | |
c5aa993b | 2191 | virtual_base_list_aux (dclass); |
c906108c | 2192 | |
c5aa993b | 2193 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
c906108c SS |
2194 | /* no body */ ; |
2195 | ||
2196 | count = i; | |
2197 | ||
c5aa993b | 2198 | vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *)); |
c906108c | 2199 | |
c5aa993b | 2200 | for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next) |
c906108c SS |
2201 | vbase_array[i] = tmp_vbase->vbasetype; |
2202 | ||
2203 | /* Get rid of constructed chain */ | |
2204 | tmp_vbase_2 = tmp_vbase = current_vbase_list; | |
2205 | while (tmp_vbase) | |
2206 | { | |
2207 | tmp_vbase = tmp_vbase->next; | |
b8c9b27d | 2208 | xfree (tmp_vbase_2); |
c906108c SS |
2209 | tmp_vbase_2 = tmp_vbase; |
2210 | } | |
c5aa993b | 2211 | |
c906108c SS |
2212 | vbase_array[count] = NULL; |
2213 | return vbase_array; | |
2214 | } | |
2215 | ||
2216 | /* Return the length of the virtual base list of the type DCLASS. */ | |
2217 | ||
2218 | int | |
fba45db2 | 2219 | virtual_base_list_length (struct type *dclass) |
c906108c SS |
2220 | { |
2221 | register int i; | |
c5aa993b JM |
2222 | register struct vbase *tmp_vbase; |
2223 | ||
c906108c | 2224 | current_vbase_list = NULL; |
c5aa993b | 2225 | virtual_base_list_aux (dclass); |
c906108c | 2226 | |
c5aa993b | 2227 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
c906108c SS |
2228 | /* no body */ ; |
2229 | return i; | |
2230 | } | |
2231 | ||
2232 | /* Return the number of elements of the virtual base list of the type | |
2233 | DCLASS, ignoring those appearing in the primary base (and its | |
2234 | primary base, recursively). */ | |
2235 | ||
2236 | int | |
fba45db2 | 2237 | virtual_base_list_length_skip_primaries (struct type *dclass) |
c906108c SS |
2238 | { |
2239 | register int i; | |
c5aa993b JM |
2240 | register struct vbase *tmp_vbase; |
2241 | struct type *primary; | |
c906108c SS |
2242 | |
2243 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; | |
2244 | ||
2245 | if (!primary) | |
2246 | return virtual_base_list_length (dclass); | |
2247 | ||
2248 | current_vbase_list = NULL; | |
c5aa993b | 2249 | virtual_base_list_aux (dclass); |
c906108c | 2250 | |
c5aa993b | 2251 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next) |
c906108c SS |
2252 | { |
2253 | if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0) | |
c5aa993b | 2254 | continue; |
c906108c SS |
2255 | i++; |
2256 | } | |
2257 | return i; | |
2258 | } | |
2259 | ||
2260 | ||
2261 | /* Return the index (position) of type BASE, which is a virtual base | |
2262 | class of DCLASS, in the latter's virtual base list. A return of -1 | |
2263 | indicates "not found" or a problem. */ | |
2264 | ||
2265 | int | |
fba45db2 | 2266 | virtual_base_index (struct type *base, struct type *dclass) |
c906108c | 2267 | { |
c5aa993b | 2268 | register struct type *vbase; |
c906108c SS |
2269 | register int i; |
2270 | ||
c5aa993b JM |
2271 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
2272 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
2273 | return -1; |
2274 | ||
2275 | i = 0; | |
015a42b4 | 2276 | vbase = virtual_base_list (dclass)[0]; |
c906108c SS |
2277 | while (vbase) |
2278 | { | |
2279 | if (vbase == base) | |
c5aa993b | 2280 | break; |
015a42b4 | 2281 | vbase = virtual_base_list (dclass)[++i]; |
c906108c SS |
2282 | } |
2283 | ||
2284 | return vbase ? i : -1; | |
2285 | } | |
2286 | ||
2287 | ||
2288 | ||
2289 | /* Return the index (position) of type BASE, which is a virtual base | |
2290 | class of DCLASS, in the latter's virtual base list. Skip over all | |
2291 | bases that may appear in the virtual base list of the primary base | |
2292 | class of DCLASS (recursively). A return of -1 indicates "not | |
2293 | found" or a problem. */ | |
2294 | ||
2295 | int | |
fba45db2 | 2296 | virtual_base_index_skip_primaries (struct type *base, struct type *dclass) |
c906108c | 2297 | { |
c5aa993b | 2298 | register struct type *vbase; |
c906108c | 2299 | register int i, j; |
c5aa993b | 2300 | struct type *primary; |
c906108c | 2301 | |
c5aa993b JM |
2302 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
2303 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
2304 | return -1; |
2305 | ||
c5aa993b | 2306 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; |
c906108c SS |
2307 | |
2308 | j = -1; | |
2309 | i = 0; | |
015a42b4 | 2310 | vbase = virtual_base_list (dclass)[0]; |
c906108c SS |
2311 | while (vbase) |
2312 | { | |
c5aa993b JM |
2313 | if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0)) |
2314 | j++; | |
c906108c | 2315 | if (vbase == base) |
c5aa993b | 2316 | break; |
015a42b4 | 2317 | vbase = virtual_base_list (dclass)[++i]; |
c906108c SS |
2318 | } |
2319 | ||
2320 | return vbase ? j : -1; | |
2321 | } | |
2322 | ||
2323 | /* Return position of a derived class DCLASS in the list of | |
2324 | * primary bases starting with the remotest ancestor. | |
2325 | * Position returned is 0-based. */ | |
2326 | ||
2327 | int | |
fba45db2 | 2328 | class_index_in_primary_list (struct type *dclass) |
c906108c | 2329 | { |
c5aa993b | 2330 | struct type *pbc; /* primary base class */ |
c906108c | 2331 | |
c5aa993b | 2332 | /* Simply recurse on primary base */ |
c906108c SS |
2333 | pbc = TYPE_PRIMARY_BASE (dclass); |
2334 | if (pbc) | |
2335 | return 1 + class_index_in_primary_list (pbc); | |
2336 | else | |
2337 | return 0; | |
2338 | } | |
2339 | ||
2340 | /* Return a count of the number of virtual functions a type has. | |
2341 | * This includes all the virtual functions it inherits from its | |
2342 | * base classes too. | |
2343 | */ | |
2344 | ||
2345 | /* pai: FIXME This doesn't do the right thing: count redefined virtual | |
2346 | * functions only once (latest redefinition) | |
2347 | */ | |
2348 | ||
2349 | int | |
fba45db2 | 2350 | count_virtual_fns (struct type *dclass) |
c906108c | 2351 | { |
c5aa993b | 2352 | int fn, oi; /* function and overloaded instance indices */ |
c5aa993b JM |
2353 | int vfuncs; /* count to return */ |
2354 | ||
2355 | /* recurse on bases that can share virtual table */ | |
2356 | struct type *pbc = primary_base_class (dclass); | |
c906108c SS |
2357 | if (pbc) |
2358 | vfuncs = count_virtual_fns (pbc); | |
7f7e9482 AC |
2359 | else |
2360 | vfuncs = 0; | |
c5aa993b | 2361 | |
c906108c SS |
2362 | for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++) |
2363 | for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++) | |
2364 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi)) | |
c5aa993b | 2365 | vfuncs++; |
c906108c SS |
2366 | |
2367 | return vfuncs; | |
2368 | } | |
c906108c SS |
2369 | \f |
2370 | ||
c5aa993b | 2371 | |
c906108c SS |
2372 | /* Functions for overload resolution begin here */ |
2373 | ||
2374 | /* Compare two badness vectors A and B and return the result. | |
2375 | * 0 => A and B are identical | |
2376 | * 1 => A and B are incomparable | |
2377 | * 2 => A is better than B | |
2378 | * 3 => A is worse than B */ | |
2379 | ||
2380 | int | |
fba45db2 | 2381 | compare_badness (struct badness_vector *a, struct badness_vector *b) |
c906108c SS |
2382 | { |
2383 | int i; | |
2384 | int tmp; | |
c5aa993b JM |
2385 | short found_pos = 0; /* any positives in c? */ |
2386 | short found_neg = 0; /* any negatives in c? */ | |
2387 | ||
2388 | /* differing lengths => incomparable */ | |
c906108c SS |
2389 | if (a->length != b->length) |
2390 | return 1; | |
2391 | ||
c5aa993b JM |
2392 | /* Subtract b from a */ |
2393 | for (i = 0; i < a->length; i++) | |
c906108c SS |
2394 | { |
2395 | tmp = a->rank[i] - b->rank[i]; | |
2396 | if (tmp > 0) | |
c5aa993b | 2397 | found_pos = 1; |
c906108c | 2398 | else if (tmp < 0) |
c5aa993b | 2399 | found_neg = 1; |
c906108c SS |
2400 | } |
2401 | ||
2402 | if (found_pos) | |
2403 | { | |
2404 | if (found_neg) | |
c5aa993b | 2405 | return 1; /* incomparable */ |
c906108c | 2406 | else |
c5aa993b | 2407 | return 3; /* A > B */ |
c906108c | 2408 | } |
c5aa993b JM |
2409 | else |
2410 | /* no positives */ | |
c906108c SS |
2411 | { |
2412 | if (found_neg) | |
c5aa993b | 2413 | return 2; /* A < B */ |
c906108c | 2414 | else |
c5aa993b | 2415 | return 0; /* A == B */ |
c906108c SS |
2416 | } |
2417 | } | |
2418 | ||
2419 | /* Rank a function by comparing its parameter types (PARMS, length NPARMS), | |
2420 | * to the types of an argument list (ARGS, length NARGS). | |
2421 | * Return a pointer to a badness vector. This has NARGS + 1 entries. */ | |
2422 | ||
2423 | struct badness_vector * | |
fba45db2 | 2424 | rank_function (struct type **parms, int nparms, struct type **args, int nargs) |
c906108c SS |
2425 | { |
2426 | int i; | |
c5aa993b | 2427 | struct badness_vector *bv; |
c906108c SS |
2428 | int min_len = nparms < nargs ? nparms : nargs; |
2429 | ||
2430 | bv = xmalloc (sizeof (struct badness_vector)); | |
c5aa993b | 2431 | bv->length = nargs + 1; /* add 1 for the length-match rank */ |
c906108c SS |
2432 | bv->rank = xmalloc ((nargs + 1) * sizeof (int)); |
2433 | ||
2434 | /* First compare the lengths of the supplied lists. | |
2435 | * If there is a mismatch, set it to a high value. */ | |
c5aa993b | 2436 | |
c906108c SS |
2437 | /* pai/1997-06-03 FIXME: when we have debug info about default |
2438 | * arguments and ellipsis parameter lists, we should consider those | |
2439 | * and rank the length-match more finely. */ | |
2440 | ||
2441 | LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0; | |
2442 | ||
2443 | /* Now rank all the parameters of the candidate function */ | |
74cc24b0 DB |
2444 | for (i = 1; i <= min_len; i++) |
2445 | bv->rank[i] = rank_one_type (parms[i-1], args[i-1]); | |
c906108c | 2446 | |
c5aa993b JM |
2447 | /* If more arguments than parameters, add dummy entries */ |
2448 | for (i = min_len + 1; i <= nargs; i++) | |
c906108c SS |
2449 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
2450 | ||
2451 | return bv; | |
2452 | } | |
2453 | ||
2454 | /* Compare one type (PARM) for compatibility with another (ARG). | |
2455 | * PARM is intended to be the parameter type of a function; and | |
2456 | * ARG is the supplied argument's type. This function tests if | |
2457 | * the latter can be converted to the former. | |
2458 | * | |
2459 | * Return 0 if they are identical types; | |
2460 | * Otherwise, return an integer which corresponds to how compatible | |
2461 | * PARM is to ARG. The higher the return value, the worse the match. | |
2462 | * Generally the "bad" conversions are all uniformly assigned a 100 */ | |
2463 | ||
2464 | int | |
fba45db2 | 2465 | rank_one_type (struct type *parm, struct type *arg) |
c906108c SS |
2466 | { |
2467 | /* Identical type pointers */ | |
2468 | /* However, this still doesn't catch all cases of same type for arg | |
2469 | * and param. The reason is that builtin types are different from | |
2470 | * the same ones constructed from the object. */ | |
2471 | if (parm == arg) | |
2472 | return 0; | |
2473 | ||
2474 | /* Resolve typedefs */ | |
2475 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) | |
2476 | parm = check_typedef (parm); | |
2477 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) | |
2478 | arg = check_typedef (arg); | |
2479 | ||
070ad9f0 DB |
2480 | /* |
2481 | Well, damnit, if the names are exactly the same, | |
2482 | i'll say they are exactly the same. This happens when we generate | |
2483 | method stubs. The types won't point to the same address, but they | |
2484 | really are the same. | |
2485 | */ | |
2486 | ||
6b1ba9a0 ND |
2487 | if (TYPE_NAME (parm) && TYPE_NAME (arg) && |
2488 | !strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) | |
070ad9f0 DB |
2489 | return 0; |
2490 | ||
c906108c SS |
2491 | /* Check if identical after resolving typedefs */ |
2492 | if (parm == arg) | |
2493 | return 0; | |
2494 | ||
db577aea AC |
2495 | /* See through references, since we can almost make non-references |
2496 | references. */ | |
2497 | if (TYPE_CODE (arg) == TYPE_CODE_REF) | |
6b1ba9a0 | 2498 | return (rank_one_type (parm, TYPE_TARGET_TYPE (arg)) |
db577aea AC |
2499 | + REFERENCE_CONVERSION_BADNESS); |
2500 | if (TYPE_CODE (parm) == TYPE_CODE_REF) | |
6b1ba9a0 | 2501 | return (rank_one_type (TYPE_TARGET_TYPE (parm), arg) |
db577aea | 2502 | + REFERENCE_CONVERSION_BADNESS); |
5d161b24 | 2503 | if (overload_debug) |
db577aea | 2504 | /* Debugging only. */ |
5d161b24 DB |
2505 | fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n", |
2506 | TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm)); | |
c906108c SS |
2507 | |
2508 | /* x -> y means arg of type x being supplied for parameter of type y */ | |
2509 | ||
2510 | switch (TYPE_CODE (parm)) | |
2511 | { | |
c5aa993b JM |
2512 | case TYPE_CODE_PTR: |
2513 | switch (TYPE_CODE (arg)) | |
2514 | { | |
2515 | case TYPE_CODE_PTR: | |
2516 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) | |
2517 | return VOID_PTR_CONVERSION_BADNESS; | |
2518 | else | |
2519 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2520 | case TYPE_CODE_ARRAY: | |
2521 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2522 | case TYPE_CODE_FUNC: | |
2523 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg); | |
2524 | case TYPE_CODE_INT: | |
2525 | case TYPE_CODE_ENUM: | |
2526 | case TYPE_CODE_CHAR: | |
2527 | case TYPE_CODE_RANGE: | |
2528 | case TYPE_CODE_BOOL: | |
2529 | return POINTER_CONVERSION_BADNESS; | |
2530 | default: | |
2531 | return INCOMPATIBLE_TYPE_BADNESS; | |
2532 | } | |
2533 | case TYPE_CODE_ARRAY: | |
2534 | switch (TYPE_CODE (arg)) | |
2535 | { | |
2536 | case TYPE_CODE_PTR: | |
2537 | case TYPE_CODE_ARRAY: | |
2538 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2539 | default: | |
2540 | return INCOMPATIBLE_TYPE_BADNESS; | |
2541 | } | |
2542 | case TYPE_CODE_FUNC: | |
2543 | switch (TYPE_CODE (arg)) | |
2544 | { | |
2545 | case TYPE_CODE_PTR: /* funcptr -> func */ | |
2546 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg)); | |
2547 | default: | |
2548 | return INCOMPATIBLE_TYPE_BADNESS; | |
2549 | } | |
2550 | case TYPE_CODE_INT: | |
2551 | switch (TYPE_CODE (arg)) | |
2552 | { | |
2553 | case TYPE_CODE_INT: | |
2554 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2555 | { | |
2556 | /* Deal with signed, unsigned, and plain chars and | |
7b83ea04 | 2557 | signed and unsigned ints */ |
c5aa993b JM |
2558 | if (TYPE_NOSIGN (parm)) |
2559 | { | |
2560 | /* This case only for character types */ | |
2561 | if (TYPE_NOSIGN (arg)) /* plain char -> plain char */ | |
2562 | return 0; | |
2563 | else | |
2564 | return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */ | |
2565 | } | |
2566 | else if (TYPE_UNSIGNED (parm)) | |
2567 | { | |
2568 | if (TYPE_UNSIGNED (arg)) | |
2569 | { | |
db577aea | 2570 | if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg))) |
c5aa993b | 2571 | return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */ |
db577aea | 2572 | else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long")) |
c5aa993b JM |
2573 | return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */ |
2574 | else | |
2575 | return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */ | |
2576 | } | |
2577 | else | |
2578 | { | |
db577aea | 2579 | if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int")) |
c5aa993b JM |
2580 | return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */ |
2581 | else | |
2582 | return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */ | |
2583 | } | |
2584 | } | |
2585 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2586 | { | |
db577aea | 2587 | if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg))) |
c5aa993b | 2588 | return 0; |
db577aea | 2589 | else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long")) |
c5aa993b JM |
2590 | return INTEGER_PROMOTION_BADNESS; |
2591 | else | |
2592 | return INTEGER_COERCION_BADNESS; | |
2593 | } | |
2594 | else | |
2595 | return INTEGER_COERCION_BADNESS; | |
2596 | } | |
2597 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2598 | return INTEGER_PROMOTION_BADNESS; | |
2599 | else | |
2600 | return INTEGER_COERCION_BADNESS; | |
2601 | case TYPE_CODE_ENUM: | |
2602 | case TYPE_CODE_CHAR: | |
2603 | case TYPE_CODE_RANGE: | |
2604 | case TYPE_CODE_BOOL: | |
2605 | return INTEGER_PROMOTION_BADNESS; | |
2606 | case TYPE_CODE_FLT: | |
2607 | return INT_FLOAT_CONVERSION_BADNESS; | |
2608 | case TYPE_CODE_PTR: | |
2609 | return NS_POINTER_CONVERSION_BADNESS; | |
2610 | default: | |
2611 | return INCOMPATIBLE_TYPE_BADNESS; | |
2612 | } | |
2613 | break; | |
2614 | case TYPE_CODE_ENUM: | |
2615 | switch (TYPE_CODE (arg)) | |
2616 | { | |
2617 | case TYPE_CODE_INT: | |
2618 | case TYPE_CODE_CHAR: | |
2619 | case TYPE_CODE_RANGE: | |
2620 | case TYPE_CODE_BOOL: | |
2621 | case TYPE_CODE_ENUM: | |
2622 | return INTEGER_COERCION_BADNESS; | |
2623 | case TYPE_CODE_FLT: | |
2624 | return INT_FLOAT_CONVERSION_BADNESS; | |
2625 | default: | |
2626 | return INCOMPATIBLE_TYPE_BADNESS; | |
2627 | } | |
2628 | break; | |
2629 | case TYPE_CODE_CHAR: | |
2630 | switch (TYPE_CODE (arg)) | |
2631 | { | |
2632 | case TYPE_CODE_RANGE: | |
2633 | case TYPE_CODE_BOOL: | |
2634 | case TYPE_CODE_ENUM: | |
2635 | return INTEGER_COERCION_BADNESS; | |
2636 | case TYPE_CODE_FLT: | |
2637 | return INT_FLOAT_CONVERSION_BADNESS; | |
2638 | case TYPE_CODE_INT: | |
2639 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) | |
2640 | return INTEGER_COERCION_BADNESS; | |
2641 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2642 | return INTEGER_PROMOTION_BADNESS; | |
2643 | /* >>> !! else fall through !! <<< */ | |
2644 | case TYPE_CODE_CHAR: | |
2645 | /* Deal with signed, unsigned, and plain chars for C++ | |
2646 | and with int cases falling through from previous case */ | |
2647 | if (TYPE_NOSIGN (parm)) | |
2648 | { | |
2649 | if (TYPE_NOSIGN (arg)) | |
2650 | return 0; | |
2651 | else | |
2652 | return INTEGER_COERCION_BADNESS; | |
2653 | } | |
2654 | else if (TYPE_UNSIGNED (parm)) | |
2655 | { | |
2656 | if (TYPE_UNSIGNED (arg)) | |
2657 | return 0; | |
2658 | else | |
2659 | return INTEGER_PROMOTION_BADNESS; | |
2660 | } | |
2661 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2662 | return 0; | |
2663 | else | |
2664 | return INTEGER_COERCION_BADNESS; | |
2665 | default: | |
2666 | return INCOMPATIBLE_TYPE_BADNESS; | |
2667 | } | |
2668 | break; | |
2669 | case TYPE_CODE_RANGE: | |
2670 | switch (TYPE_CODE (arg)) | |
2671 | { | |
2672 | case TYPE_CODE_INT: | |
2673 | case TYPE_CODE_CHAR: | |
2674 | case TYPE_CODE_RANGE: | |
2675 | case TYPE_CODE_BOOL: | |
2676 | case TYPE_CODE_ENUM: | |
2677 | return INTEGER_COERCION_BADNESS; | |
2678 | case TYPE_CODE_FLT: | |
2679 | return INT_FLOAT_CONVERSION_BADNESS; | |
2680 | default: | |
2681 | return INCOMPATIBLE_TYPE_BADNESS; | |
2682 | } | |
2683 | break; | |
2684 | case TYPE_CODE_BOOL: | |
2685 | switch (TYPE_CODE (arg)) | |
2686 | { | |
2687 | case TYPE_CODE_INT: | |
2688 | case TYPE_CODE_CHAR: | |
2689 | case TYPE_CODE_RANGE: | |
2690 | case TYPE_CODE_ENUM: | |
2691 | case TYPE_CODE_FLT: | |
2692 | case TYPE_CODE_PTR: | |
2693 | return BOOLEAN_CONVERSION_BADNESS; | |
2694 | case TYPE_CODE_BOOL: | |
2695 | return 0; | |
2696 | default: | |
2697 | return INCOMPATIBLE_TYPE_BADNESS; | |
2698 | } | |
2699 | break; | |
2700 | case TYPE_CODE_FLT: | |
2701 | switch (TYPE_CODE (arg)) | |
2702 | { | |
2703 | case TYPE_CODE_FLT: | |
2704 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2705 | return FLOAT_PROMOTION_BADNESS; | |
2706 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2707 | return 0; | |
2708 | else | |
2709 | return FLOAT_CONVERSION_BADNESS; | |
2710 | case TYPE_CODE_INT: | |
2711 | case TYPE_CODE_BOOL: | |
2712 | case TYPE_CODE_ENUM: | |
2713 | case TYPE_CODE_RANGE: | |
2714 | case TYPE_CODE_CHAR: | |
2715 | return INT_FLOAT_CONVERSION_BADNESS; | |
2716 | default: | |
2717 | return INCOMPATIBLE_TYPE_BADNESS; | |
2718 | } | |
2719 | break; | |
2720 | case TYPE_CODE_COMPLEX: | |
2721 | switch (TYPE_CODE (arg)) | |
2722 | { /* Strictly not needed for C++, but... */ | |
2723 | case TYPE_CODE_FLT: | |
2724 | return FLOAT_PROMOTION_BADNESS; | |
2725 | case TYPE_CODE_COMPLEX: | |
2726 | return 0; | |
2727 | default: | |
2728 | return INCOMPATIBLE_TYPE_BADNESS; | |
2729 | } | |
2730 | break; | |
2731 | case TYPE_CODE_STRUCT: | |
c906108c | 2732 | /* currently same as TYPE_CODE_CLASS */ |
c5aa993b JM |
2733 | switch (TYPE_CODE (arg)) |
2734 | { | |
2735 | case TYPE_CODE_STRUCT: | |
2736 | /* Check for derivation */ | |
2737 | if (is_ancestor (parm, arg)) | |
2738 | return BASE_CONVERSION_BADNESS; | |
2739 | /* else fall through */ | |
2740 | default: | |
2741 | return INCOMPATIBLE_TYPE_BADNESS; | |
2742 | } | |
2743 | break; | |
2744 | case TYPE_CODE_UNION: | |
2745 | switch (TYPE_CODE (arg)) | |
2746 | { | |
2747 | case TYPE_CODE_UNION: | |
2748 | default: | |
2749 | return INCOMPATIBLE_TYPE_BADNESS; | |
2750 | } | |
2751 | break; | |
2752 | case TYPE_CODE_MEMBER: | |
2753 | switch (TYPE_CODE (arg)) | |
2754 | { | |
2755 | default: | |
2756 | return INCOMPATIBLE_TYPE_BADNESS; | |
2757 | } | |
2758 | break; | |
2759 | case TYPE_CODE_METHOD: | |
2760 | switch (TYPE_CODE (arg)) | |
2761 | { | |
2762 | ||
2763 | default: | |
2764 | return INCOMPATIBLE_TYPE_BADNESS; | |
2765 | } | |
2766 | break; | |
2767 | case TYPE_CODE_REF: | |
2768 | switch (TYPE_CODE (arg)) | |
2769 | { | |
2770 | ||
2771 | default: | |
2772 | return INCOMPATIBLE_TYPE_BADNESS; | |
2773 | } | |
2774 | ||
2775 | break; | |
2776 | case TYPE_CODE_SET: | |
2777 | switch (TYPE_CODE (arg)) | |
2778 | { | |
2779 | /* Not in C++ */ | |
2780 | case TYPE_CODE_SET: | |
2781 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0)); | |
2782 | default: | |
2783 | return INCOMPATIBLE_TYPE_BADNESS; | |
2784 | } | |
2785 | break; | |
2786 | case TYPE_CODE_VOID: | |
2787 | default: | |
2788 | return INCOMPATIBLE_TYPE_BADNESS; | |
2789 | } /* switch (TYPE_CODE (arg)) */ | |
c906108c SS |
2790 | } |
2791 | ||
c5aa993b JM |
2792 | |
2793 | /* End of functions for overload resolution */ | |
c906108c | 2794 | |
c906108c | 2795 | static void |
fba45db2 | 2796 | print_bit_vector (B_TYPE *bits, int nbits) |
c906108c SS |
2797 | { |
2798 | int bitno; | |
2799 | ||
2800 | for (bitno = 0; bitno < nbits; bitno++) | |
2801 | { | |
2802 | if ((bitno % 8) == 0) | |
2803 | { | |
2804 | puts_filtered (" "); | |
2805 | } | |
2806 | if (B_TST (bits, bitno)) | |
2807 | { | |
2808 | printf_filtered ("1"); | |
2809 | } | |
2810 | else | |
2811 | { | |
2812 | printf_filtered ("0"); | |
2813 | } | |
2814 | } | |
2815 | } | |
2816 | ||
ad2f7632 DJ |
2817 | /* Note the first arg should be the "this" pointer, we may not want to |
2818 | include it since we may get into a infinitely recursive situation. */ | |
c906108c SS |
2819 | |
2820 | static void | |
ad2f7632 | 2821 | print_arg_types (struct field *args, int nargs, int spaces) |
c906108c SS |
2822 | { |
2823 | if (args != NULL) | |
2824 | { | |
ad2f7632 DJ |
2825 | int i; |
2826 | ||
2827 | for (i = 0; i < nargs; i++) | |
2828 | recursive_dump_type (args[i].type, spaces + 2); | |
c906108c SS |
2829 | } |
2830 | } | |
2831 | ||
2832 | static void | |
fba45db2 | 2833 | dump_fn_fieldlists (struct type *type, int spaces) |
c906108c SS |
2834 | { |
2835 | int method_idx; | |
2836 | int overload_idx; | |
2837 | struct fn_field *f; | |
2838 | ||
2839 | printfi_filtered (spaces, "fn_fieldlists "); | |
d4f3574e | 2840 | gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
c906108c SS |
2841 | printf_filtered ("\n"); |
2842 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) | |
2843 | { | |
2844 | f = TYPE_FN_FIELDLIST1 (type, method_idx); | |
2845 | printfi_filtered (spaces + 2, "[%d] name '%s' (", | |
2846 | method_idx, | |
2847 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); | |
d4f3574e SS |
2848 | gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
2849 | gdb_stdout); | |
c906108c SS |
2850 | printf_filtered (") length %d\n", |
2851 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); | |
2852 | for (overload_idx = 0; | |
2853 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); | |
2854 | overload_idx++) | |
2855 | { | |
2856 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", | |
2857 | overload_idx, | |
2858 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); | |
d4f3574e SS |
2859 | gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
2860 | gdb_stdout); | |
c906108c SS |
2861 | printf_filtered (")\n"); |
2862 | printfi_filtered (spaces + 8, "type "); | |
d4f3574e | 2863 | gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout); |
c906108c SS |
2864 | printf_filtered ("\n"); |
2865 | ||
2866 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), | |
2867 | spaces + 8 + 2); | |
2868 | ||
2869 | printfi_filtered (spaces + 8, "args "); | |
d4f3574e | 2870 | gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout); |
c906108c SS |
2871 | printf_filtered ("\n"); |
2872 | ||
ad2f7632 DJ |
2873 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), |
2874 | TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)), | |
2875 | spaces); | |
c906108c | 2876 | printfi_filtered (spaces + 8, "fcontext "); |
d4f3574e SS |
2877 | gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
2878 | gdb_stdout); | |
c906108c SS |
2879 | printf_filtered ("\n"); |
2880 | ||
2881 | printfi_filtered (spaces + 8, "is_const %d\n", | |
2882 | TYPE_FN_FIELD_CONST (f, overload_idx)); | |
2883 | printfi_filtered (spaces + 8, "is_volatile %d\n", | |
2884 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); | |
2885 | printfi_filtered (spaces + 8, "is_private %d\n", | |
2886 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); | |
2887 | printfi_filtered (spaces + 8, "is_protected %d\n", | |
2888 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); | |
2889 | printfi_filtered (spaces + 8, "is_stub %d\n", | |
2890 | TYPE_FN_FIELD_STUB (f, overload_idx)); | |
2891 | printfi_filtered (spaces + 8, "voffset %u\n", | |
2892 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); | |
2893 | } | |
2894 | } | |
2895 | } | |
2896 | ||
2897 | static void | |
fba45db2 | 2898 | print_cplus_stuff (struct type *type, int spaces) |
c906108c SS |
2899 | { |
2900 | printfi_filtered (spaces, "n_baseclasses %d\n", | |
2901 | TYPE_N_BASECLASSES (type)); | |
2902 | printfi_filtered (spaces, "nfn_fields %d\n", | |
2903 | TYPE_NFN_FIELDS (type)); | |
2904 | printfi_filtered (spaces, "nfn_fields_total %d\n", | |
2905 | TYPE_NFN_FIELDS_TOTAL (type)); | |
2906 | if (TYPE_N_BASECLASSES (type) > 0) | |
2907 | { | |
2908 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", | |
2909 | TYPE_N_BASECLASSES (type)); | |
d4f3574e | 2910 | gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout); |
c906108c SS |
2911 | printf_filtered (")"); |
2912 | ||
2913 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), | |
2914 | TYPE_N_BASECLASSES (type)); | |
2915 | puts_filtered ("\n"); | |
2916 | } | |
2917 | if (TYPE_NFIELDS (type) > 0) | |
2918 | { | |
2919 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) | |
2920 | { | |
2921 | printfi_filtered (spaces, "private_field_bits (%d bits at *", | |
2922 | TYPE_NFIELDS (type)); | |
d4f3574e | 2923 | gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout); |
c906108c SS |
2924 | printf_filtered (")"); |
2925 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), | |
2926 | TYPE_NFIELDS (type)); | |
2927 | puts_filtered ("\n"); | |
2928 | } | |
2929 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) | |
2930 | { | |
2931 | printfi_filtered (spaces, "protected_field_bits (%d bits at *", | |
2932 | TYPE_NFIELDS (type)); | |
d4f3574e | 2933 | gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout); |
c906108c SS |
2934 | printf_filtered (")"); |
2935 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), | |
2936 | TYPE_NFIELDS (type)); | |
2937 | puts_filtered ("\n"); | |
2938 | } | |
2939 | } | |
2940 | if (TYPE_NFN_FIELDS (type) > 0) | |
2941 | { | |
2942 | dump_fn_fieldlists (type, spaces); | |
2943 | } | |
2944 | } | |
2945 | ||
e9e79dd9 FF |
2946 | static void |
2947 | print_bound_type (int bt) | |
2948 | { | |
2949 | switch (bt) | |
2950 | { | |
2951 | case BOUND_CANNOT_BE_DETERMINED: | |
2952 | printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)"); | |
2953 | break; | |
2954 | case BOUND_BY_REF_ON_STACK: | |
2955 | printf_filtered ("(BOUND_BY_REF_ON_STACK)"); | |
2956 | break; | |
2957 | case BOUND_BY_VALUE_ON_STACK: | |
2958 | printf_filtered ("(BOUND_BY_VALUE_ON_STACK)"); | |
2959 | break; | |
2960 | case BOUND_BY_REF_IN_REG: | |
2961 | printf_filtered ("(BOUND_BY_REF_IN_REG)"); | |
2962 | break; | |
2963 | case BOUND_BY_VALUE_IN_REG: | |
2964 | printf_filtered ("(BOUND_BY_VALUE_IN_REG)"); | |
2965 | break; | |
2966 | case BOUND_SIMPLE: | |
2967 | printf_filtered ("(BOUND_SIMPLE)"); | |
2968 | break; | |
2969 | default: | |
2970 | printf_filtered ("(unknown bound type)"); | |
2971 | break; | |
2972 | } | |
2973 | } | |
2974 | ||
c906108c SS |
2975 | static struct obstack dont_print_type_obstack; |
2976 | ||
2977 | void | |
fba45db2 | 2978 | recursive_dump_type (struct type *type, int spaces) |
c906108c SS |
2979 | { |
2980 | int idx; | |
2981 | ||
2982 | if (spaces == 0) | |
2983 | obstack_begin (&dont_print_type_obstack, 0); | |
2984 | ||
2985 | if (TYPE_NFIELDS (type) > 0 | |
2986 | || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0)) | |
2987 | { | |
2988 | struct type **first_dont_print | |
c5aa993b | 2989 | = (struct type **) obstack_base (&dont_print_type_obstack); |
c906108c | 2990 | |
c5aa993b JM |
2991 | int i = (struct type **) obstack_next_free (&dont_print_type_obstack) |
2992 | - first_dont_print; | |
c906108c SS |
2993 | |
2994 | while (--i >= 0) | |
2995 | { | |
2996 | if (type == first_dont_print[i]) | |
2997 | { | |
2998 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2999 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
3000 | printf_filtered (" <same as already seen type>\n"); |
3001 | return; | |
3002 | } | |
3003 | } | |
3004 | ||
3005 | obstack_ptr_grow (&dont_print_type_obstack, type); | |
3006 | } | |
3007 | ||
3008 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 3009 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
3010 | printf_filtered ("\n"); |
3011 | printfi_filtered (spaces, "name '%s' (", | |
3012 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); | |
d4f3574e | 3013 | gdb_print_host_address (TYPE_NAME (type), gdb_stdout); |
c906108c | 3014 | printf_filtered (")\n"); |
e9e79dd9 FF |
3015 | printfi_filtered (spaces, "tagname '%s' (", |
3016 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>"); | |
3017 | gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout); | |
3018 | printf_filtered (")\n"); | |
c906108c SS |
3019 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); |
3020 | switch (TYPE_CODE (type)) | |
3021 | { | |
c5aa993b JM |
3022 | case TYPE_CODE_UNDEF: |
3023 | printf_filtered ("(TYPE_CODE_UNDEF)"); | |
3024 | break; | |
3025 | case TYPE_CODE_PTR: | |
3026 | printf_filtered ("(TYPE_CODE_PTR)"); | |
3027 | break; | |
3028 | case TYPE_CODE_ARRAY: | |
3029 | printf_filtered ("(TYPE_CODE_ARRAY)"); | |
3030 | break; | |
3031 | case TYPE_CODE_STRUCT: | |
3032 | printf_filtered ("(TYPE_CODE_STRUCT)"); | |
3033 | break; | |
3034 | case TYPE_CODE_UNION: | |
3035 | printf_filtered ("(TYPE_CODE_UNION)"); | |
3036 | break; | |
3037 | case TYPE_CODE_ENUM: | |
3038 | printf_filtered ("(TYPE_CODE_ENUM)"); | |
3039 | break; | |
3040 | case TYPE_CODE_FUNC: | |
3041 | printf_filtered ("(TYPE_CODE_FUNC)"); | |
3042 | break; | |
3043 | case TYPE_CODE_INT: | |
3044 | printf_filtered ("(TYPE_CODE_INT)"); | |
3045 | break; | |
3046 | case TYPE_CODE_FLT: | |
3047 | printf_filtered ("(TYPE_CODE_FLT)"); | |
3048 | break; | |
3049 | case TYPE_CODE_VOID: | |
3050 | printf_filtered ("(TYPE_CODE_VOID)"); | |
3051 | break; | |
3052 | case TYPE_CODE_SET: | |
3053 | printf_filtered ("(TYPE_CODE_SET)"); | |
3054 | break; | |
3055 | case TYPE_CODE_RANGE: | |
3056 | printf_filtered ("(TYPE_CODE_RANGE)"); | |
3057 | break; | |
3058 | case TYPE_CODE_STRING: | |
3059 | printf_filtered ("(TYPE_CODE_STRING)"); | |
3060 | break; | |
e9e79dd9 FF |
3061 | case TYPE_CODE_BITSTRING: |
3062 | printf_filtered ("(TYPE_CODE_BITSTRING)"); | |
3063 | break; | |
c5aa993b JM |
3064 | case TYPE_CODE_ERROR: |
3065 | printf_filtered ("(TYPE_CODE_ERROR)"); | |
3066 | break; | |
3067 | case TYPE_CODE_MEMBER: | |
3068 | printf_filtered ("(TYPE_CODE_MEMBER)"); | |
3069 | break; | |
3070 | case TYPE_CODE_METHOD: | |
3071 | printf_filtered ("(TYPE_CODE_METHOD)"); | |
3072 | break; | |
3073 | case TYPE_CODE_REF: | |
3074 | printf_filtered ("(TYPE_CODE_REF)"); | |
3075 | break; | |
3076 | case TYPE_CODE_CHAR: | |
3077 | printf_filtered ("(TYPE_CODE_CHAR)"); | |
3078 | break; | |
3079 | case TYPE_CODE_BOOL: | |
3080 | printf_filtered ("(TYPE_CODE_BOOL)"); | |
3081 | break; | |
e9e79dd9 FF |
3082 | case TYPE_CODE_COMPLEX: |
3083 | printf_filtered ("(TYPE_CODE_COMPLEX)"); | |
3084 | break; | |
c5aa993b JM |
3085 | case TYPE_CODE_TYPEDEF: |
3086 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); | |
3087 | break; | |
e9e79dd9 FF |
3088 | case TYPE_CODE_TEMPLATE: |
3089 | printf_filtered ("(TYPE_CODE_TEMPLATE)"); | |
3090 | break; | |
3091 | case TYPE_CODE_TEMPLATE_ARG: | |
3092 | printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)"); | |
3093 | break; | |
c5aa993b JM |
3094 | default: |
3095 | printf_filtered ("(UNKNOWN TYPE CODE)"); | |
3096 | break; | |
c906108c SS |
3097 | } |
3098 | puts_filtered ("\n"); | |
3099 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); | |
e9e79dd9 FF |
3100 | printfi_filtered (spaces, "upper_bound_type 0x%x ", |
3101 | TYPE_ARRAY_UPPER_BOUND_TYPE (type)); | |
3102 | print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type)); | |
3103 | puts_filtered ("\n"); | |
3104 | printfi_filtered (spaces, "lower_bound_type 0x%x ", | |
3105 | TYPE_ARRAY_LOWER_BOUND_TYPE (type)); | |
3106 | print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type)); | |
3107 | puts_filtered ("\n"); | |
c906108c | 3108 | printfi_filtered (spaces, "objfile "); |
d4f3574e | 3109 | gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout); |
c906108c SS |
3110 | printf_filtered ("\n"); |
3111 | printfi_filtered (spaces, "target_type "); | |
d4f3574e | 3112 | gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
c906108c SS |
3113 | printf_filtered ("\n"); |
3114 | if (TYPE_TARGET_TYPE (type) != NULL) | |
3115 | { | |
3116 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); | |
3117 | } | |
3118 | printfi_filtered (spaces, "pointer_type "); | |
d4f3574e | 3119 | gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
c906108c SS |
3120 | printf_filtered ("\n"); |
3121 | printfi_filtered (spaces, "reference_type "); | |
d4f3574e | 3122 | gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
c906108c | 3123 | printf_filtered ("\n"); |
2fdde8f8 DJ |
3124 | printfi_filtered (spaces, "type_chain "); |
3125 | gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout); | |
e9e79dd9 | 3126 | printf_filtered ("\n"); |
2fdde8f8 DJ |
3127 | printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type)); |
3128 | if (TYPE_CONST (type)) | |
3129 | { | |
3130 | puts_filtered (" TYPE_FLAG_CONST"); | |
3131 | } | |
3132 | if (TYPE_VOLATILE (type)) | |
3133 | { | |
3134 | puts_filtered (" TYPE_FLAG_VOLATILE"); | |
3135 | } | |
3136 | if (TYPE_CODE_SPACE (type)) | |
3137 | { | |
3138 | puts_filtered (" TYPE_FLAG_CODE_SPACE"); | |
3139 | } | |
3140 | if (TYPE_DATA_SPACE (type)) | |
3141 | { | |
3142 | puts_filtered (" TYPE_FLAG_DATA_SPACE"); | |
3143 | } | |
3144 | puts_filtered ("\n"); | |
c906108c | 3145 | printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type)); |
762a036f | 3146 | if (TYPE_UNSIGNED (type)) |
c906108c SS |
3147 | { |
3148 | puts_filtered (" TYPE_FLAG_UNSIGNED"); | |
3149 | } | |
762a036f FF |
3150 | if (TYPE_NOSIGN (type)) |
3151 | { | |
3152 | puts_filtered (" TYPE_FLAG_NOSIGN"); | |
3153 | } | |
3154 | if (TYPE_STUB (type)) | |
c906108c SS |
3155 | { |
3156 | puts_filtered (" TYPE_FLAG_STUB"); | |
3157 | } | |
762a036f FF |
3158 | if (TYPE_TARGET_STUB (type)) |
3159 | { | |
3160 | puts_filtered (" TYPE_FLAG_TARGET_STUB"); | |
3161 | } | |
3162 | if (TYPE_STATIC (type)) | |
3163 | { | |
3164 | puts_filtered (" TYPE_FLAG_STATIC"); | |
3165 | } | |
762a036f FF |
3166 | if (TYPE_PROTOTYPED (type)) |
3167 | { | |
3168 | puts_filtered (" TYPE_FLAG_PROTOTYPED"); | |
3169 | } | |
3170 | if (TYPE_INCOMPLETE (type)) | |
3171 | { | |
3172 | puts_filtered (" TYPE_FLAG_INCOMPLETE"); | |
3173 | } | |
762a036f FF |
3174 | if (TYPE_VARARGS (type)) |
3175 | { | |
3176 | puts_filtered (" TYPE_FLAG_VARARGS"); | |
3177 | } | |
f5f8a009 EZ |
3178 | /* This is used for things like AltiVec registers on ppc. Gcc emits |
3179 | an attribute for the array type, which tells whether or not we | |
3180 | have a vector, instead of a regular array. */ | |
3181 | if (TYPE_VECTOR (type)) | |
3182 | { | |
3183 | puts_filtered (" TYPE_FLAG_VECTOR"); | |
3184 | } | |
c906108c SS |
3185 | puts_filtered ("\n"); |
3186 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); | |
d4f3574e | 3187 | gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout); |
c906108c SS |
3188 | puts_filtered ("\n"); |
3189 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) | |
3190 | { | |
3191 | printfi_filtered (spaces + 2, | |
3192 | "[%d] bitpos %d bitsize %d type ", | |
3193 | idx, TYPE_FIELD_BITPOS (type, idx), | |
3194 | TYPE_FIELD_BITSIZE (type, idx)); | |
d4f3574e | 3195 | gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
c906108c SS |
3196 | printf_filtered (" name '%s' (", |
3197 | TYPE_FIELD_NAME (type, idx) != NULL | |
3198 | ? TYPE_FIELD_NAME (type, idx) | |
3199 | : "<NULL>"); | |
d4f3574e | 3200 | gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
c906108c SS |
3201 | printf_filtered (")\n"); |
3202 | if (TYPE_FIELD_TYPE (type, idx) != NULL) | |
3203 | { | |
3204 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); | |
3205 | } | |
3206 | } | |
3207 | printfi_filtered (spaces, "vptr_basetype "); | |
d4f3574e | 3208 | gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); |
c906108c SS |
3209 | puts_filtered ("\n"); |
3210 | if (TYPE_VPTR_BASETYPE (type) != NULL) | |
3211 | { | |
3212 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); | |
3213 | } | |
3214 | printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type)); | |
3215 | switch (TYPE_CODE (type)) | |
3216 | { | |
c5aa993b JM |
3217 | case TYPE_CODE_STRUCT: |
3218 | printfi_filtered (spaces, "cplus_stuff "); | |
d4f3574e | 3219 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
3220 | puts_filtered ("\n"); |
3221 | print_cplus_stuff (type, spaces); | |
3222 | break; | |
c906108c | 3223 | |
701c159d AC |
3224 | case TYPE_CODE_FLT: |
3225 | printfi_filtered (spaces, "floatformat "); | |
3226 | if (TYPE_FLOATFORMAT (type) == NULL | |
3227 | || TYPE_FLOATFORMAT (type)->name == NULL) | |
3228 | puts_filtered ("(null)"); | |
3229 | else | |
3230 | puts_filtered (TYPE_FLOATFORMAT (type)->name); | |
3231 | puts_filtered ("\n"); | |
3232 | break; | |
3233 | ||
c5aa993b JM |
3234 | default: |
3235 | /* We have to pick one of the union types to be able print and test | |
7b83ea04 AC |
3236 | the value. Pick cplus_struct_type, even though we know it isn't |
3237 | any particular one. */ | |
c5aa993b | 3238 | printfi_filtered (spaces, "type_specific "); |
d4f3574e | 3239 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
3240 | if (TYPE_CPLUS_SPECIFIC (type) != NULL) |
3241 | { | |
3242 | printf_filtered (" (unknown data form)"); | |
3243 | } | |
3244 | printf_filtered ("\n"); | |
3245 | break; | |
c906108c SS |
3246 | |
3247 | } | |
3248 | if (spaces == 0) | |
3249 | obstack_free (&dont_print_type_obstack, NULL); | |
3250 | } | |
3251 | ||
a14ed312 | 3252 | static void build_gdbtypes (void); |
c906108c | 3253 | static void |
fba45db2 | 3254 | build_gdbtypes (void) |
c906108c SS |
3255 | { |
3256 | builtin_type_void = | |
3257 | init_type (TYPE_CODE_VOID, 1, | |
3258 | 0, | |
3259 | "void", (struct objfile *) NULL); | |
3260 | builtin_type_char = | |
3261 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
4e409299 JB |
3262 | (TYPE_FLAG_NOSIGN |
3263 | | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)), | |
c906108c | 3264 | "char", (struct objfile *) NULL); |
c5aa993b | 3265 | builtin_type_true_char = |
9e0b60a8 JM |
3266 | init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
3267 | 0, | |
3268 | "true character", (struct objfile *) NULL); | |
c906108c SS |
3269 | builtin_type_signed_char = |
3270 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3271 | 0, | |
3272 | "signed char", (struct objfile *) NULL); | |
3273 | builtin_type_unsigned_char = | |
3274 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3275 | TYPE_FLAG_UNSIGNED, | |
3276 | "unsigned char", (struct objfile *) NULL); | |
3277 | builtin_type_short = | |
3278 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
3279 | 0, | |
3280 | "short", (struct objfile *) NULL); | |
3281 | builtin_type_unsigned_short = | |
3282 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
3283 | TYPE_FLAG_UNSIGNED, | |
3284 | "unsigned short", (struct objfile *) NULL); | |
3285 | builtin_type_int = | |
3286 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
3287 | 0, | |
3288 | "int", (struct objfile *) NULL); | |
3289 | builtin_type_unsigned_int = | |
3290 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
3291 | TYPE_FLAG_UNSIGNED, | |
3292 | "unsigned int", (struct objfile *) NULL); | |
3293 | builtin_type_long = | |
3294 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
3295 | 0, | |
3296 | "long", (struct objfile *) NULL); | |
3297 | builtin_type_unsigned_long = | |
3298 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
3299 | TYPE_FLAG_UNSIGNED, | |
3300 | "unsigned long", (struct objfile *) NULL); | |
3301 | builtin_type_long_long = | |
3302 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
3303 | 0, | |
3304 | "long long", (struct objfile *) NULL); | |
c5aa993b | 3305 | builtin_type_unsigned_long_long = |
c906108c SS |
3306 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
3307 | TYPE_FLAG_UNSIGNED, | |
3308 | "unsigned long long", (struct objfile *) NULL); | |
3309 | builtin_type_float = | |
3310 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
3311 | 0, | |
3312 | "float", (struct objfile *) NULL); | |
9c9532c9 CV |
3313 | /* [email protected] 2002-02-08: |
3314 | The below lines are disabled since they are doing the wrong | |
3315 | thing for non-multiarch targets. They are setting the correct | |
3316 | type of floats for the target but while on multiarch targets | |
3317 | this is done everytime the architecture changes, it's done on | |
3318 | non-multiarch targets only on startup, leaving the wrong values | |
3319 | in even if the architecture changes (eg. from big-endian to | |
3320 | little-endian). */ | |
3321 | #if 0 | |
701c159d | 3322 | TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT; |
9c9532c9 | 3323 | #endif |
c906108c SS |
3324 | builtin_type_double = |
3325 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
3326 | 0, | |
3327 | "double", (struct objfile *) NULL); | |
9c9532c9 | 3328 | #if 0 |
701c159d | 3329 | TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT; |
9c9532c9 | 3330 | #endif |
c906108c SS |
3331 | builtin_type_long_double = |
3332 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
3333 | 0, | |
3334 | "long double", (struct objfile *) NULL); | |
9c9532c9 | 3335 | #if 0 |
701c159d | 3336 | TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT; |
9c9532c9 | 3337 | #endif |
c906108c SS |
3338 | builtin_type_complex = |
3339 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
3340 | 0, | |
3341 | "complex", (struct objfile *) NULL); | |
3342 | TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float; | |
3343 | builtin_type_double_complex = | |
3344 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
3345 | 0, | |
3346 | "double complex", (struct objfile *) NULL); | |
3347 | TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double; | |
3348 | builtin_type_string = | |
3349 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3350 | 0, | |
3351 | "string", (struct objfile *) NULL); | |
3352 | builtin_type_int8 = | |
3353 | init_type (TYPE_CODE_INT, 8 / 8, | |
3354 | 0, | |
3355 | "int8_t", (struct objfile *) NULL); | |
3356 | builtin_type_uint8 = | |
3357 | init_type (TYPE_CODE_INT, 8 / 8, | |
3358 | TYPE_FLAG_UNSIGNED, | |
3359 | "uint8_t", (struct objfile *) NULL); | |
3360 | builtin_type_int16 = | |
3361 | init_type (TYPE_CODE_INT, 16 / 8, | |
3362 | 0, | |
3363 | "int16_t", (struct objfile *) NULL); | |
3364 | builtin_type_uint16 = | |
3365 | init_type (TYPE_CODE_INT, 16 / 8, | |
3366 | TYPE_FLAG_UNSIGNED, | |
3367 | "uint16_t", (struct objfile *) NULL); | |
3368 | builtin_type_int32 = | |
3369 | init_type (TYPE_CODE_INT, 32 / 8, | |
3370 | 0, | |
3371 | "int32_t", (struct objfile *) NULL); | |
3372 | builtin_type_uint32 = | |
3373 | init_type (TYPE_CODE_INT, 32 / 8, | |
3374 | TYPE_FLAG_UNSIGNED, | |
3375 | "uint32_t", (struct objfile *) NULL); | |
3376 | builtin_type_int64 = | |
3377 | init_type (TYPE_CODE_INT, 64 / 8, | |
3378 | 0, | |
3379 | "int64_t", (struct objfile *) NULL); | |
3380 | builtin_type_uint64 = | |
3381 | init_type (TYPE_CODE_INT, 64 / 8, | |
3382 | TYPE_FLAG_UNSIGNED, | |
3383 | "uint64_t", (struct objfile *) NULL); | |
8b982acf EZ |
3384 | builtin_type_int128 = |
3385 | init_type (TYPE_CODE_INT, 128 / 8, | |
3386 | 0, | |
3387 | "int128_t", (struct objfile *) NULL); | |
3388 | builtin_type_uint128 = | |
3389 | init_type (TYPE_CODE_INT, 128 / 8, | |
3390 | TYPE_FLAG_UNSIGNED, | |
3391 | "uint128_t", (struct objfile *) NULL); | |
c906108c SS |
3392 | builtin_type_bool = |
3393 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3394 | 0, | |
3395 | "bool", (struct objfile *) NULL); | |
3396 | ||
c5aa993b | 3397 | /* Add user knob for controlling resolution of opaque types */ |
c906108c | 3398 | add_show_from_set |
c5aa993b | 3399 | (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution, |
c906108c SS |
3400 | "Set resolution of opaque struct/class/union types (if set before loading symbols).", |
3401 | &setlist), | |
3402 | &showlist); | |
3403 | opaque_type_resolution = 1; | |
3404 | ||
917317f4 JM |
3405 | /* Build SIMD types. */ |
3406 | builtin_type_v4sf | |
3407 | = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4); | |
c2d11a7d JM |
3408 | builtin_type_v4si |
3409 | = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4); | |
08cf96df EZ |
3410 | builtin_type_v16qi |
3411 | = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16); | |
c2d11a7d JM |
3412 | builtin_type_v8qi |
3413 | = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8); | |
08cf96df EZ |
3414 | builtin_type_v8hi |
3415 | = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8); | |
c2d11a7d JM |
3416 | builtin_type_v4hi |
3417 | = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4); | |
3418 | builtin_type_v2si | |
3419 | = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2); | |
c4093a6a | 3420 | |
ac3aafc7 | 3421 | /* 128 bit vectors. */ |
3139facc | 3422 | builtin_type_v2_double = init_vector_type (builtin_type_double, 2); |
ac3aafc7 | 3423 | builtin_type_v4_float = init_vector_type (builtin_type_float, 4); |
3139facc | 3424 | builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2); |
ac3aafc7 EZ |
3425 | builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4); |
3426 | builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8); | |
3427 | builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16); | |
3428 | /* 64 bit vectors. */ | |
6599f021 | 3429 | builtin_type_v2_float = init_vector_type (builtin_type_float, 2); |
ac3aafc7 EZ |
3430 | builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2); |
3431 | builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4); | |
3432 | builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8); | |
3433 | ||
b063e7a2 AC |
3434 | /* Vector types. */ |
3435 | builtin_type_vec64 = build_builtin_type_vec64 (); | |
3436 | builtin_type_vec64i = build_builtin_type_vec64i (); | |
ac3aafc7 | 3437 | builtin_type_vec128 = build_builtin_type_vec128 (); |
3139facc | 3438 | builtin_type_vec128i = build_builtin_type_vec128i (); |
08cf96df | 3439 | |
c4093a6a | 3440 | /* Pointer/Address types. */ |
ee3a7b7f JB |
3441 | |
3442 | /* NOTE: on some targets, addresses and pointers are not necessarily | |
3443 | the same --- for example, on the D10V, pointers are 16 bits long, | |
3444 | but addresses are 32 bits long. See doc/gdbint.texinfo, | |
3445 | ``Pointers Are Not Always Addresses''. | |
3446 | ||
3447 | The upshot is: | |
3448 | - gdb's `struct type' always describes the target's | |
3449 | representation. | |
3450 | - gdb's `struct value' objects should always hold values in | |
3451 | target form. | |
3452 | - gdb's CORE_ADDR values are addresses in the unified virtual | |
3453 | address space that the assembler and linker work with. Thus, | |
3454 | since target_read_memory takes a CORE_ADDR as an argument, it | |
3455 | can access any memory on the target, even if the processor has | |
3456 | separate code and data address spaces. | |
3457 | ||
3458 | So, for example: | |
3459 | - If v is a value holding a D10V code pointer, its contents are | |
3460 | in target form: a big-endian address left-shifted two bits. | |
3461 | - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as | |
3462 | sizeof (void *) == 2 on the target. | |
3463 | ||
3464 | In this context, builtin_type_CORE_ADDR is a bit odd: it's a | |
3465 | target type for a value the target will never see. It's only | |
3466 | used to hold the values of (typeless) linker symbols, which are | |
3467 | indeed in the unified virtual address space. */ | |
090a2205 | 3468 | builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL); |
ee3a7b7f JB |
3469 | builtin_type_void_func_ptr |
3470 | = lookup_pointer_type (lookup_function_type (builtin_type_void)); | |
c4093a6a | 3471 | builtin_type_CORE_ADDR = |
52204a0b | 3472 | init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8, |
c4093a6a JM |
3473 | TYPE_FLAG_UNSIGNED, |
3474 | "__CORE_ADDR", (struct objfile *) NULL); | |
3475 | builtin_type_bfd_vma = | |
3476 | init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8, | |
3477 | TYPE_FLAG_UNSIGNED, | |
3478 | "__bfd_vma", (struct objfile *) NULL); | |
c906108c SS |
3479 | } |
3480 | ||
a14ed312 | 3481 | extern void _initialize_gdbtypes (void); |
c906108c | 3482 | void |
fba45db2 | 3483 | _initialize_gdbtypes (void) |
c906108c | 3484 | { |
5d161b24 | 3485 | struct cmd_list_element *c; |
c906108c | 3486 | build_gdbtypes (); |
0f71a2f6 JM |
3487 | |
3488 | /* FIXME - For the moment, handle types by swapping them in and out. | |
3489 | Should be using the per-architecture data-pointer and a large | |
3490 | struct. */ | |
c5aa993b JM |
3491 | register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL); |
3492 | register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL); | |
3493 | register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL); | |
3494 | register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL); | |
3495 | register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL); | |
3496 | register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL); | |
3497 | register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL); | |
3498 | register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL); | |
3499 | register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL); | |
3500 | register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL); | |
3501 | register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL); | |
3502 | register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL); | |
3503 | register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL); | |
3504 | register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL); | |
3505 | register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL); | |
3506 | register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL); | |
3507 | register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL); | |
3508 | register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL); | |
3509 | register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL); | |
3510 | register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL); | |
3511 | register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL); | |
3512 | register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL); | |
3513 | register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL); | |
3514 | register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL); | |
3515 | register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL); | |
3516 | register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL); | |
8b982acf EZ |
3517 | register_gdbarch_swap (&builtin_type_int128, sizeof (struct type *), NULL); |
3518 | register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type *), NULL); | |
917317f4 | 3519 | register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL); |
c2d11a7d | 3520 | register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL); |
08cf96df | 3521 | register_gdbarch_swap (&builtin_type_v16qi, sizeof (struct type *), NULL); |
c2d11a7d | 3522 | register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL); |
08cf96df | 3523 | register_gdbarch_swap (&builtin_type_v8hi, sizeof (struct type *), NULL); |
c2d11a7d JM |
3524 | register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL); |
3525 | register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL); | |
3139facc | 3526 | register_gdbarch_swap (&builtin_type_v2_double, sizeof (struct type *), NULL); |
ac3aafc7 | 3527 | register_gdbarch_swap (&builtin_type_v4_float, sizeof (struct type *), NULL); |
3139facc | 3528 | register_gdbarch_swap (&builtin_type_v2_int64, sizeof (struct type *), NULL); |
ac3aafc7 EZ |
3529 | register_gdbarch_swap (&builtin_type_v4_int32, sizeof (struct type *), NULL); |
3530 | register_gdbarch_swap (&builtin_type_v8_int16, sizeof (struct type *), NULL); | |
3531 | register_gdbarch_swap (&builtin_type_v16_int8, sizeof (struct type *), NULL); | |
6599f021 | 3532 | register_gdbarch_swap (&builtin_type_v2_float, sizeof (struct type *), NULL); |
ac3aafc7 EZ |
3533 | register_gdbarch_swap (&builtin_type_v2_int32, sizeof (struct type *), NULL); |
3534 | register_gdbarch_swap (&builtin_type_v8_int8, sizeof (struct type *), NULL); | |
3535 | register_gdbarch_swap (&builtin_type_v4_int16, sizeof (struct type *), NULL); | |
08cf96df | 3536 | register_gdbarch_swap (&builtin_type_vec128, sizeof (struct type *), NULL); |
3139facc | 3537 | register_gdbarch_swap (&builtin_type_vec128i, sizeof (struct type *), NULL); |
090a2205 | 3538 | REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr); |
ee3a7b7f | 3539 | REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr); |
c4093a6a JM |
3540 | REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR); |
3541 | REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma); | |
0f71a2f6 | 3542 | register_gdbarch_swap (NULL, 0, build_gdbtypes); |
5d161b24 | 3543 | |
598f52df AC |
3544 | /* Note: These types do not need to be swapped - they are target |
3545 | neutral. */ | |
3546 | builtin_type_ieee_single_big = | |
3547 | init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8, | |
3548 | 0, "builtin_type_ieee_single_big", NULL); | |
3549 | TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big; | |
3550 | builtin_type_ieee_single_little = | |
3551 | init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8, | |
3552 | 0, "builtin_type_ieee_single_little", NULL); | |
069e84fd | 3553 | TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little; |
598f52df AC |
3554 | builtin_type_ieee_double_big = |
3555 | init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8, | |
3556 | 0, "builtin_type_ieee_double_big", NULL); | |
069e84fd | 3557 | TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big; |
598f52df AC |
3558 | builtin_type_ieee_double_little = |
3559 | init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8, | |
3560 | 0, "builtin_type_ieee_double_little", NULL); | |
069e84fd | 3561 | TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little; |
598f52df AC |
3562 | builtin_type_ieee_double_littlebyte_bigword = |
3563 | init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8, | |
3564 | 0, "builtin_type_ieee_double_littlebyte_bigword", NULL); | |
069e84fd | 3565 | TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword; |
598f52df AC |
3566 | builtin_type_i387_ext = |
3567 | init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8, | |
3568 | 0, "builtin_type_i387_ext", NULL); | |
e371b258 | 3569 | TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext; |
598f52df AC |
3570 | builtin_type_m68881_ext = |
3571 | init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8, | |
3572 | 0, "builtin_type_m68881_ext", NULL); | |
069e84fd | 3573 | TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext; |
598f52df AC |
3574 | builtin_type_i960_ext = |
3575 | init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8, | |
3576 | 0, "builtin_type_i960_ext", NULL); | |
069e84fd | 3577 | TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext; |
598f52df AC |
3578 | builtin_type_m88110_ext = |
3579 | init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8, | |
3580 | 0, "builtin_type_m88110_ext", NULL); | |
069e84fd | 3581 | TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext; |
598f52df AC |
3582 | builtin_type_m88110_harris_ext = |
3583 | init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8, | |
3584 | 0, "builtin_type_m88110_harris_ext", NULL); | |
069e84fd | 3585 | TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext; |
598f52df AC |
3586 | builtin_type_arm_ext_big = |
3587 | init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8, | |
3588 | 0, "builtin_type_arm_ext_big", NULL); | |
069e84fd | 3589 | TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big; |
598f52df AC |
3590 | builtin_type_arm_ext_littlebyte_bigword = |
3591 | init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8, | |
3592 | 0, "builtin_type_arm_ext_littlebyte_bigword", NULL); | |
069e84fd | 3593 | TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword; |
598f52df AC |
3594 | builtin_type_ia64_spill_big = |
3595 | init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8, | |
3596 | 0, "builtin_type_ia64_spill_big", NULL); | |
069e84fd | 3597 | TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big; |
598f52df AC |
3598 | builtin_type_ia64_spill_little = |
3599 | init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8, | |
3600 | 0, "builtin_type_ia64_spill_little", NULL); | |
069e84fd | 3601 | TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little; |
598f52df AC |
3602 | builtin_type_ia64_quad_big = |
3603 | init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8, | |
3604 | 0, "builtin_type_ia64_quad_big", NULL); | |
069e84fd | 3605 | TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big; |
598f52df AC |
3606 | builtin_type_ia64_quad_little = |
3607 | init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8, | |
3608 | 0, "builtin_type_ia64_quad_little", NULL); | |
069e84fd | 3609 | TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little; |
598f52df | 3610 | |
5d161b24 DB |
3611 | add_show_from_set ( |
3612 | add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug, | |
3613 | "Set debugging of C++ overloading.\n\ | |
3614 | When enabled, ranking of the functions\n\ | |
3615 | is displayed.", &setdebuglist), | |
3616 | &showdebuglist); | |
c906108c | 3617 | } |