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