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