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