Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support routines for manipulating internal types for GDB. |
4f2aea11 | 2 | |
28e7fd62 | 3 | Copyright (C) 1992-2013 Free Software Foundation, Inc. |
4f2aea11 | 4 | |
c906108c SS |
5 | Contributed by Cygnus Support, using pieces from other GDB modules. |
6 | ||
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "gdb_string.h" | |
24 | #include "bfd.h" | |
25 | #include "symtab.h" | |
26 | #include "symfile.h" | |
27 | #include "objfiles.h" | |
28 | #include "gdbtypes.h" | |
29 | #include "expression.h" | |
30 | #include "language.h" | |
31 | #include "target.h" | |
32 | #include "value.h" | |
33 | #include "demangle.h" | |
34 | #include "complaints.h" | |
35 | #include "gdbcmd.h" | |
015a42b4 | 36 | #include "cp-abi.h" |
a02fd225 | 37 | #include "gdb_assert.h" |
ae5a43e0 | 38 | #include "hashtab.h" |
8e7b59a5 | 39 | #include "exceptions.h" |
8de20a37 | 40 | #include "cp-support.h" |
ac3aafc7 | 41 | |
6403aeea SW |
42 | /* Initialize BADNESS constants. */ |
43 | ||
a9d5ef47 | 44 | const struct rank LENGTH_MISMATCH_BADNESS = {100,0}; |
6403aeea | 45 | |
a9d5ef47 SW |
46 | const struct rank TOO_FEW_PARAMS_BADNESS = {100,0}; |
47 | const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0}; | |
6403aeea | 48 | |
a9d5ef47 | 49 | const struct rank EXACT_MATCH_BADNESS = {0,0}; |
6403aeea | 50 | |
a9d5ef47 SW |
51 | const struct rank INTEGER_PROMOTION_BADNESS = {1,0}; |
52 | const struct rank FLOAT_PROMOTION_BADNESS = {1,0}; | |
53 | const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0}; | |
54 | const struct rank INTEGER_CONVERSION_BADNESS = {2,0}; | |
55 | const struct rank FLOAT_CONVERSION_BADNESS = {2,0}; | |
56 | const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0}; | |
57 | const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0}; | |
5b4f6e25 | 58 | const struct rank BOOL_CONVERSION_BADNESS = {3,0}; |
a9d5ef47 SW |
59 | const struct rank BASE_CONVERSION_BADNESS = {2,0}; |
60 | const struct rank REFERENCE_CONVERSION_BADNESS = {2,0}; | |
da096638 | 61 | const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0}; |
a9d5ef47 | 62 | const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0}; |
a451cb65 | 63 | const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0}; |
6403aeea | 64 | |
8da61cc4 | 65 | /* Floatformat pairs. */ |
f9e9243a UW |
66 | const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = { |
67 | &floatformat_ieee_half_big, | |
68 | &floatformat_ieee_half_little | |
69 | }; | |
8da61cc4 DJ |
70 | const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = { |
71 | &floatformat_ieee_single_big, | |
72 | &floatformat_ieee_single_little | |
73 | }; | |
74 | const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = { | |
75 | &floatformat_ieee_double_big, | |
76 | &floatformat_ieee_double_little | |
77 | }; | |
78 | const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = { | |
79 | &floatformat_ieee_double_big, | |
80 | &floatformat_ieee_double_littlebyte_bigword | |
81 | }; | |
82 | const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = { | |
83 | &floatformat_i387_ext, | |
84 | &floatformat_i387_ext | |
85 | }; | |
86 | const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = { | |
87 | &floatformat_m68881_ext, | |
88 | &floatformat_m68881_ext | |
89 | }; | |
90 | const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = { | |
91 | &floatformat_arm_ext_big, | |
92 | &floatformat_arm_ext_littlebyte_bigword | |
93 | }; | |
94 | const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = { | |
95 | &floatformat_ia64_spill_big, | |
96 | &floatformat_ia64_spill_little | |
97 | }; | |
98 | const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = { | |
99 | &floatformat_ia64_quad_big, | |
100 | &floatformat_ia64_quad_little | |
101 | }; | |
102 | const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = { | |
103 | &floatformat_vax_f, | |
104 | &floatformat_vax_f | |
105 | }; | |
106 | const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = { | |
107 | &floatformat_vax_d, | |
108 | &floatformat_vax_d | |
109 | }; | |
b14d30e1 | 110 | const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = { |
f5aee5ee AM |
111 | &floatformat_ibm_long_double_big, |
112 | &floatformat_ibm_long_double_little | |
b14d30e1 | 113 | }; |
8da61cc4 | 114 | |
2873700e KS |
115 | /* Should opaque types be resolved? */ |
116 | ||
117 | static int opaque_type_resolution = 1; | |
118 | ||
119 | /* A flag to enable printing of debugging information of C++ | |
120 | overloading. */ | |
121 | ||
122 | unsigned int overload_debug = 0; | |
123 | ||
a451cb65 KS |
124 | /* A flag to enable strict type checking. */ |
125 | ||
126 | static int strict_type_checking = 1; | |
127 | ||
2873700e | 128 | /* A function to show whether opaque types are resolved. */ |
5212577a | 129 | |
920d2a44 AC |
130 | static void |
131 | show_opaque_type_resolution (struct ui_file *file, int from_tty, | |
7ba81444 MS |
132 | struct cmd_list_element *c, |
133 | const char *value) | |
920d2a44 | 134 | { |
3e43a32a MS |
135 | fprintf_filtered (file, _("Resolution of opaque struct/class/union types " |
136 | "(if set before loading symbols) is %s.\n"), | |
920d2a44 AC |
137 | value); |
138 | } | |
139 | ||
2873700e | 140 | /* A function to show whether C++ overload debugging is enabled. */ |
5212577a | 141 | |
920d2a44 AC |
142 | static void |
143 | show_overload_debug (struct ui_file *file, int from_tty, | |
144 | struct cmd_list_element *c, const char *value) | |
145 | { | |
7ba81444 MS |
146 | fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"), |
147 | value); | |
920d2a44 | 148 | } |
c906108c | 149 | |
a451cb65 KS |
150 | /* A function to show the status of strict type checking. */ |
151 | ||
152 | static void | |
153 | show_strict_type_checking (struct ui_file *file, int from_tty, | |
154 | struct cmd_list_element *c, const char *value) | |
155 | { | |
156 | fprintf_filtered (file, _("Strict type checking is %s.\n"), value); | |
157 | } | |
158 | ||
5212577a | 159 | \f |
e9bb382b UW |
160 | /* Allocate a new OBJFILE-associated type structure and fill it |
161 | with some defaults. Space for the type structure is allocated | |
162 | on the objfile's objfile_obstack. */ | |
c906108c SS |
163 | |
164 | struct type * | |
fba45db2 | 165 | alloc_type (struct objfile *objfile) |
c906108c | 166 | { |
52f0bd74 | 167 | struct type *type; |
c906108c | 168 | |
e9bb382b UW |
169 | gdb_assert (objfile != NULL); |
170 | ||
7ba81444 | 171 | /* Alloc the structure and start off with all fields zeroed. */ |
e9bb382b UW |
172 | type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type); |
173 | TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
174 | struct main_type); | |
175 | OBJSTAT (objfile, n_types++); | |
c906108c | 176 | |
e9bb382b UW |
177 | TYPE_OBJFILE_OWNED (type) = 1; |
178 | TYPE_OWNER (type).objfile = objfile; | |
c906108c | 179 | |
7ba81444 | 180 | /* Initialize the fields that might not be zero. */ |
c906108c SS |
181 | |
182 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
c906108c | 183 | TYPE_VPTR_FIELDNO (type) = -1; |
2fdde8f8 | 184 | TYPE_CHAIN (type) = type; /* Chain back to itself. */ |
c906108c | 185 | |
c16abbde | 186 | return type; |
c906108c SS |
187 | } |
188 | ||
e9bb382b UW |
189 | /* Allocate a new GDBARCH-associated type structure and fill it |
190 | with some defaults. Space for the type structure is allocated | |
191 | on the heap. */ | |
192 | ||
193 | struct type * | |
194 | alloc_type_arch (struct gdbarch *gdbarch) | |
195 | { | |
196 | struct type *type; | |
197 | ||
198 | gdb_assert (gdbarch != NULL); | |
199 | ||
200 | /* Alloc the structure and start off with all fields zeroed. */ | |
201 | ||
202 | type = XZALLOC (struct type); | |
203 | TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type); | |
204 | ||
205 | TYPE_OBJFILE_OWNED (type) = 0; | |
206 | TYPE_OWNER (type).gdbarch = gdbarch; | |
207 | ||
208 | /* Initialize the fields that might not be zero. */ | |
209 | ||
210 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
211 | TYPE_VPTR_FIELDNO (type) = -1; | |
212 | TYPE_CHAIN (type) = type; /* Chain back to itself. */ | |
213 | ||
214 | return type; | |
215 | } | |
216 | ||
217 | /* If TYPE is objfile-associated, allocate a new type structure | |
218 | associated with the same objfile. If TYPE is gdbarch-associated, | |
219 | allocate a new type structure associated with the same gdbarch. */ | |
220 | ||
221 | struct type * | |
222 | alloc_type_copy (const struct type *type) | |
223 | { | |
224 | if (TYPE_OBJFILE_OWNED (type)) | |
225 | return alloc_type (TYPE_OWNER (type).objfile); | |
226 | else | |
227 | return alloc_type_arch (TYPE_OWNER (type).gdbarch); | |
228 | } | |
229 | ||
230 | /* If TYPE is gdbarch-associated, return that architecture. | |
231 | If TYPE is objfile-associated, return that objfile's architecture. */ | |
232 | ||
233 | struct gdbarch * | |
234 | get_type_arch (const struct type *type) | |
235 | { | |
236 | if (TYPE_OBJFILE_OWNED (type)) | |
237 | return get_objfile_arch (TYPE_OWNER (type).objfile); | |
238 | else | |
239 | return TYPE_OWNER (type).gdbarch; | |
240 | } | |
241 | ||
99ad9427 YQ |
242 | /* See gdbtypes.h. */ |
243 | ||
244 | struct type * | |
245 | get_target_type (struct type *type) | |
246 | { | |
247 | if (type != NULL) | |
248 | { | |
249 | type = TYPE_TARGET_TYPE (type); | |
250 | if (type != NULL) | |
251 | type = check_typedef (type); | |
252 | } | |
253 | ||
254 | return type; | |
255 | } | |
256 | ||
2fdde8f8 DJ |
257 | /* Alloc a new type instance structure, fill it with some defaults, |
258 | and point it at OLDTYPE. Allocate the new type instance from the | |
259 | same place as OLDTYPE. */ | |
260 | ||
261 | static struct type * | |
262 | alloc_type_instance (struct type *oldtype) | |
263 | { | |
264 | struct type *type; | |
265 | ||
266 | /* Allocate the structure. */ | |
267 | ||
e9bb382b | 268 | if (! TYPE_OBJFILE_OWNED (oldtype)) |
1deafd4e | 269 | type = XZALLOC (struct type); |
2fdde8f8 | 270 | else |
1deafd4e PA |
271 | type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack, |
272 | struct type); | |
273 | ||
2fdde8f8 DJ |
274 | TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype); |
275 | ||
276 | TYPE_CHAIN (type) = type; /* Chain back to itself for now. */ | |
277 | ||
c16abbde | 278 | return type; |
2fdde8f8 DJ |
279 | } |
280 | ||
281 | /* Clear all remnants of the previous type at TYPE, in preparation for | |
e9bb382b | 282 | replacing it with something else. Preserve owner information. */ |
5212577a | 283 | |
2fdde8f8 DJ |
284 | static void |
285 | smash_type (struct type *type) | |
286 | { | |
e9bb382b UW |
287 | int objfile_owned = TYPE_OBJFILE_OWNED (type); |
288 | union type_owner owner = TYPE_OWNER (type); | |
289 | ||
2fdde8f8 DJ |
290 | memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); |
291 | ||
e9bb382b UW |
292 | /* Restore owner information. */ |
293 | TYPE_OBJFILE_OWNED (type) = objfile_owned; | |
294 | TYPE_OWNER (type) = owner; | |
295 | ||
2fdde8f8 DJ |
296 | /* For now, delete the rings. */ |
297 | TYPE_CHAIN (type) = type; | |
298 | ||
299 | /* For now, leave the pointer/reference types alone. */ | |
300 | } | |
301 | ||
c906108c SS |
302 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points |
303 | to a pointer to memory where the pointer type should be stored. | |
304 | If *TYPEPTR is zero, update it to point to the pointer type we return. | |
305 | We allocate new memory if needed. */ | |
306 | ||
307 | struct type * | |
fba45db2 | 308 | make_pointer_type (struct type *type, struct type **typeptr) |
c906108c | 309 | { |
52f0bd74 | 310 | struct type *ntype; /* New type */ |
053cb41b | 311 | struct type *chain; |
c906108c SS |
312 | |
313 | ntype = TYPE_POINTER_TYPE (type); | |
314 | ||
c5aa993b | 315 | if (ntype) |
c906108c | 316 | { |
c5aa993b | 317 | if (typeptr == 0) |
7ba81444 MS |
318 | return ntype; /* Don't care about alloc, |
319 | and have new type. */ | |
c906108c | 320 | else if (*typeptr == 0) |
c5aa993b | 321 | { |
7ba81444 | 322 | *typeptr = ntype; /* Tracking alloc, and have new type. */ |
c906108c | 323 | return ntype; |
c5aa993b | 324 | } |
c906108c SS |
325 | } |
326 | ||
327 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
328 | { | |
e9bb382b | 329 | ntype = alloc_type_copy (type); |
c906108c SS |
330 | if (typeptr) |
331 | *typeptr = ntype; | |
332 | } | |
7ba81444 | 333 | else /* We have storage, but need to reset it. */ |
c906108c SS |
334 | { |
335 | ntype = *typeptr; | |
053cb41b | 336 | chain = TYPE_CHAIN (ntype); |
2fdde8f8 | 337 | smash_type (ntype); |
053cb41b | 338 | TYPE_CHAIN (ntype) = chain; |
c906108c SS |
339 | } |
340 | ||
341 | TYPE_TARGET_TYPE (ntype) = type; | |
342 | TYPE_POINTER_TYPE (type) = ntype; | |
343 | ||
5212577a | 344 | /* FIXME! Assumes the machine has only one representation for pointers! */ |
c906108c | 345 | |
50810684 UW |
346 | TYPE_LENGTH (ntype) |
347 | = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT; | |
c906108c SS |
348 | TYPE_CODE (ntype) = TYPE_CODE_PTR; |
349 | ||
67b2adb2 | 350 | /* Mark pointers as unsigned. The target converts between pointers |
76e71323 | 351 | and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and |
7ba81444 | 352 | gdbarch_address_to_pointer. */ |
876cecd0 | 353 | TYPE_UNSIGNED (ntype) = 1; |
c5aa993b | 354 | |
053cb41b JB |
355 | /* Update the length of all the other variants of this type. */ |
356 | chain = TYPE_CHAIN (ntype); | |
357 | while (chain != ntype) | |
358 | { | |
359 | TYPE_LENGTH (chain) = TYPE_LENGTH (ntype); | |
360 | chain = TYPE_CHAIN (chain); | |
361 | } | |
362 | ||
c906108c SS |
363 | return ntype; |
364 | } | |
365 | ||
366 | /* Given a type TYPE, return a type of pointers to that type. | |
367 | May need to construct such a type if this is the first use. */ | |
368 | ||
369 | struct type * | |
fba45db2 | 370 | lookup_pointer_type (struct type *type) |
c906108c | 371 | { |
c5aa993b | 372 | return make_pointer_type (type, (struct type **) 0); |
c906108c SS |
373 | } |
374 | ||
7ba81444 MS |
375 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, |
376 | points to a pointer to memory where the reference type should be | |
377 | stored. If *TYPEPTR is zero, update it to point to the reference | |
378 | type we return. We allocate new memory if needed. */ | |
c906108c SS |
379 | |
380 | struct type * | |
fba45db2 | 381 | make_reference_type (struct type *type, struct type **typeptr) |
c906108c | 382 | { |
52f0bd74 | 383 | struct type *ntype; /* New type */ |
1e98b326 | 384 | struct type *chain; |
c906108c SS |
385 | |
386 | ntype = TYPE_REFERENCE_TYPE (type); | |
387 | ||
c5aa993b | 388 | if (ntype) |
c906108c | 389 | { |
c5aa993b | 390 | if (typeptr == 0) |
7ba81444 MS |
391 | return ntype; /* Don't care about alloc, |
392 | and have new type. */ | |
c906108c | 393 | else if (*typeptr == 0) |
c5aa993b | 394 | { |
7ba81444 | 395 | *typeptr = ntype; /* Tracking alloc, and have new type. */ |
c906108c | 396 | return ntype; |
c5aa993b | 397 | } |
c906108c SS |
398 | } |
399 | ||
400 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
401 | { | |
e9bb382b | 402 | ntype = alloc_type_copy (type); |
c906108c SS |
403 | if (typeptr) |
404 | *typeptr = ntype; | |
405 | } | |
7ba81444 | 406 | else /* We have storage, but need to reset it. */ |
c906108c SS |
407 | { |
408 | ntype = *typeptr; | |
1e98b326 | 409 | chain = TYPE_CHAIN (ntype); |
2fdde8f8 | 410 | smash_type (ntype); |
1e98b326 | 411 | TYPE_CHAIN (ntype) = chain; |
c906108c SS |
412 | } |
413 | ||
414 | TYPE_TARGET_TYPE (ntype) = type; | |
415 | TYPE_REFERENCE_TYPE (type) = ntype; | |
416 | ||
7ba81444 MS |
417 | /* FIXME! Assume the machine has only one representation for |
418 | references, and that it matches the (only) representation for | |
419 | pointers! */ | |
c906108c | 420 | |
50810684 UW |
421 | TYPE_LENGTH (ntype) = |
422 | gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT; | |
c906108c | 423 | TYPE_CODE (ntype) = TYPE_CODE_REF; |
c5aa993b | 424 | |
c906108c SS |
425 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ |
426 | TYPE_REFERENCE_TYPE (type) = ntype; | |
427 | ||
1e98b326 JB |
428 | /* Update the length of all the other variants of this type. */ |
429 | chain = TYPE_CHAIN (ntype); | |
430 | while (chain != ntype) | |
431 | { | |
432 | TYPE_LENGTH (chain) = TYPE_LENGTH (ntype); | |
433 | chain = TYPE_CHAIN (chain); | |
434 | } | |
435 | ||
c906108c SS |
436 | return ntype; |
437 | } | |
438 | ||
7ba81444 MS |
439 | /* Same as above, but caller doesn't care about memory allocation |
440 | details. */ | |
c906108c SS |
441 | |
442 | struct type * | |
fba45db2 | 443 | lookup_reference_type (struct type *type) |
c906108c | 444 | { |
c5aa993b | 445 | return make_reference_type (type, (struct type **) 0); |
c906108c SS |
446 | } |
447 | ||
7ba81444 MS |
448 | /* Lookup a function type that returns type TYPE. TYPEPTR, if |
449 | nonzero, points to a pointer to memory where the function type | |
450 | should be stored. If *TYPEPTR is zero, update it to point to the | |
0c8b41f1 | 451 | function type we return. We allocate new memory if needed. */ |
c906108c SS |
452 | |
453 | struct type * | |
0c8b41f1 | 454 | make_function_type (struct type *type, struct type **typeptr) |
c906108c | 455 | { |
52f0bd74 | 456 | struct type *ntype; /* New type */ |
c906108c SS |
457 | |
458 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
459 | { | |
e9bb382b | 460 | ntype = alloc_type_copy (type); |
c906108c SS |
461 | if (typeptr) |
462 | *typeptr = ntype; | |
463 | } | |
7ba81444 | 464 | else /* We have storage, but need to reset it. */ |
c906108c SS |
465 | { |
466 | ntype = *typeptr; | |
2fdde8f8 | 467 | smash_type (ntype); |
c906108c SS |
468 | } |
469 | ||
470 | TYPE_TARGET_TYPE (ntype) = type; | |
471 | ||
472 | TYPE_LENGTH (ntype) = 1; | |
473 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; | |
c5aa993b | 474 | |
b6cdc2c1 JK |
475 | INIT_FUNC_SPECIFIC (ntype); |
476 | ||
c906108c SS |
477 | return ntype; |
478 | } | |
479 | ||
c906108c SS |
480 | /* Given a type TYPE, return a type of functions that return that type. |
481 | May need to construct such a type if this is the first use. */ | |
482 | ||
483 | struct type * | |
fba45db2 | 484 | lookup_function_type (struct type *type) |
c906108c | 485 | { |
0c8b41f1 | 486 | return make_function_type (type, (struct type **) 0); |
c906108c SS |
487 | } |
488 | ||
71918a86 | 489 | /* Given a type TYPE and argument types, return the appropriate |
a6fb9c08 TT |
490 | function type. If the final type in PARAM_TYPES is NULL, make a |
491 | varargs function. */ | |
71918a86 TT |
492 | |
493 | struct type * | |
494 | lookup_function_type_with_arguments (struct type *type, | |
495 | int nparams, | |
496 | struct type **param_types) | |
497 | { | |
498 | struct type *fn = make_function_type (type, (struct type **) 0); | |
499 | int i; | |
500 | ||
e314d629 | 501 | if (nparams > 0) |
a6fb9c08 | 502 | { |
e314d629 TT |
503 | if (param_types[nparams - 1] == NULL) |
504 | { | |
505 | --nparams; | |
506 | TYPE_VARARGS (fn) = 1; | |
507 | } | |
508 | else if (TYPE_CODE (check_typedef (param_types[nparams - 1])) | |
509 | == TYPE_CODE_VOID) | |
510 | { | |
511 | --nparams; | |
512 | /* Caller should have ensured this. */ | |
513 | gdb_assert (nparams == 0); | |
514 | TYPE_PROTOTYPED (fn) = 1; | |
515 | } | |
a6fb9c08 TT |
516 | } |
517 | ||
71918a86 TT |
518 | TYPE_NFIELDS (fn) = nparams; |
519 | TYPE_FIELDS (fn) = TYPE_ZALLOC (fn, nparams * sizeof (struct field)); | |
520 | for (i = 0; i < nparams; ++i) | |
521 | TYPE_FIELD_TYPE (fn, i) = param_types[i]; | |
522 | ||
523 | return fn; | |
524 | } | |
525 | ||
47663de5 MS |
526 | /* Identify address space identifier by name -- |
527 | return the integer flag defined in gdbtypes.h. */ | |
5212577a DE |
528 | |
529 | int | |
50810684 | 530 | address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier) |
47663de5 | 531 | { |
8b2dbe47 | 532 | int type_flags; |
d8734c88 | 533 | |
7ba81444 | 534 | /* Check for known address space delimiters. */ |
47663de5 | 535 | if (!strcmp (space_identifier, "code")) |
876cecd0 | 536 | return TYPE_INSTANCE_FLAG_CODE_SPACE; |
47663de5 | 537 | else if (!strcmp (space_identifier, "data")) |
876cecd0 | 538 | return TYPE_INSTANCE_FLAG_DATA_SPACE; |
5f11f355 AC |
539 | else if (gdbarch_address_class_name_to_type_flags_p (gdbarch) |
540 | && gdbarch_address_class_name_to_type_flags (gdbarch, | |
541 | space_identifier, | |
542 | &type_flags)) | |
8b2dbe47 | 543 | return type_flags; |
47663de5 | 544 | else |
8a3fe4f8 | 545 | error (_("Unknown address space specifier: \"%s\""), space_identifier); |
47663de5 MS |
546 | } |
547 | ||
548 | /* Identify address space identifier by integer flag as defined in | |
7ba81444 | 549 | gdbtypes.h -- return the string version of the adress space name. */ |
47663de5 | 550 | |
321432c0 | 551 | const char * |
50810684 | 552 | address_space_int_to_name (struct gdbarch *gdbarch, int space_flag) |
47663de5 | 553 | { |
876cecd0 | 554 | if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE) |
47663de5 | 555 | return "code"; |
876cecd0 | 556 | else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE) |
47663de5 | 557 | return "data"; |
876cecd0 | 558 | else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
5f11f355 AC |
559 | && gdbarch_address_class_type_flags_to_name_p (gdbarch)) |
560 | return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag); | |
47663de5 MS |
561 | else |
562 | return NULL; | |
563 | } | |
564 | ||
2fdde8f8 | 565 | /* Create a new type with instance flags NEW_FLAGS, based on TYPE. |
ad766c0a JB |
566 | |
567 | If STORAGE is non-NULL, create the new type instance there. | |
568 | STORAGE must be in the same obstack as TYPE. */ | |
47663de5 | 569 | |
b9362cc7 | 570 | static struct type * |
2fdde8f8 DJ |
571 | make_qualified_type (struct type *type, int new_flags, |
572 | struct type *storage) | |
47663de5 MS |
573 | { |
574 | struct type *ntype; | |
575 | ||
576 | ntype = type; | |
5f61c20e JK |
577 | do |
578 | { | |
579 | if (TYPE_INSTANCE_FLAGS (ntype) == new_flags) | |
580 | return ntype; | |
581 | ntype = TYPE_CHAIN (ntype); | |
582 | } | |
583 | while (ntype != type); | |
47663de5 | 584 | |
2fdde8f8 DJ |
585 | /* Create a new type instance. */ |
586 | if (storage == NULL) | |
587 | ntype = alloc_type_instance (type); | |
588 | else | |
589 | { | |
7ba81444 MS |
590 | /* If STORAGE was provided, it had better be in the same objfile |
591 | as TYPE. Otherwise, we can't link it into TYPE's cv chain: | |
592 | if one objfile is freed and the other kept, we'd have | |
593 | dangling pointers. */ | |
ad766c0a JB |
594 | gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage)); |
595 | ||
2fdde8f8 DJ |
596 | ntype = storage; |
597 | TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type); | |
598 | TYPE_CHAIN (ntype) = ntype; | |
599 | } | |
47663de5 MS |
600 | |
601 | /* Pointers or references to the original type are not relevant to | |
2fdde8f8 | 602 | the new type. */ |
47663de5 MS |
603 | TYPE_POINTER_TYPE (ntype) = (struct type *) 0; |
604 | TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; | |
47663de5 | 605 | |
2fdde8f8 DJ |
606 | /* Chain the new qualified type to the old type. */ |
607 | TYPE_CHAIN (ntype) = TYPE_CHAIN (type); | |
608 | TYPE_CHAIN (type) = ntype; | |
609 | ||
610 | /* Now set the instance flags and return the new type. */ | |
611 | TYPE_INSTANCE_FLAGS (ntype) = new_flags; | |
47663de5 | 612 | |
ab5d3da6 KB |
613 | /* Set length of new type to that of the original type. */ |
614 | TYPE_LENGTH (ntype) = TYPE_LENGTH (type); | |
615 | ||
47663de5 MS |
616 | return ntype; |
617 | } | |
618 | ||
2fdde8f8 DJ |
619 | /* Make an address-space-delimited variant of a type -- a type that |
620 | is identical to the one supplied except that it has an address | |
621 | space attribute attached to it (such as "code" or "data"). | |
622 | ||
7ba81444 MS |
623 | The space attributes "code" and "data" are for Harvard |
624 | architectures. The address space attributes are for architectures | |
625 | which have alternately sized pointers or pointers with alternate | |
626 | representations. */ | |
2fdde8f8 DJ |
627 | |
628 | struct type * | |
629 | make_type_with_address_space (struct type *type, int space_flag) | |
630 | { | |
2fdde8f8 | 631 | int new_flags = ((TYPE_INSTANCE_FLAGS (type) |
876cecd0 TT |
632 | & ~(TYPE_INSTANCE_FLAG_CODE_SPACE |
633 | | TYPE_INSTANCE_FLAG_DATA_SPACE | |
634 | | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)) | |
2fdde8f8 DJ |
635 | | space_flag); |
636 | ||
637 | return make_qualified_type (type, new_flags, NULL); | |
638 | } | |
c906108c SS |
639 | |
640 | /* Make a "c-v" variant of a type -- a type that is identical to the | |
641 | one supplied except that it may have const or volatile attributes | |
642 | CNST is a flag for setting the const attribute | |
643 | VOLTL is a flag for setting the volatile attribute | |
644 | TYPE is the base type whose variant we are creating. | |
c906108c | 645 | |
ad766c0a JB |
646 | If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to |
647 | storage to hold the new qualified type; *TYPEPTR and TYPE must be | |
648 | in the same objfile. Otherwise, allocate fresh memory for the new | |
649 | type whereever TYPE lives. If TYPEPTR is non-zero, set it to the | |
650 | new type we construct. */ | |
5212577a | 651 | |
c906108c | 652 | struct type * |
7ba81444 MS |
653 | make_cv_type (int cnst, int voltl, |
654 | struct type *type, | |
655 | struct type **typeptr) | |
c906108c | 656 | { |
52f0bd74 | 657 | struct type *ntype; /* New type */ |
c906108c | 658 | |
2fdde8f8 | 659 | int new_flags = (TYPE_INSTANCE_FLAGS (type) |
308d96ed MS |
660 | & ~(TYPE_INSTANCE_FLAG_CONST |
661 | | TYPE_INSTANCE_FLAG_VOLATILE)); | |
c906108c | 662 | |
c906108c | 663 | if (cnst) |
876cecd0 | 664 | new_flags |= TYPE_INSTANCE_FLAG_CONST; |
c906108c SS |
665 | |
666 | if (voltl) | |
876cecd0 | 667 | new_flags |= TYPE_INSTANCE_FLAG_VOLATILE; |
a02fd225 | 668 | |
2fdde8f8 | 669 | if (typeptr && *typeptr != NULL) |
a02fd225 | 670 | { |
ad766c0a JB |
671 | /* TYPE and *TYPEPTR must be in the same objfile. We can't have |
672 | a C-V variant chain that threads across objfiles: if one | |
673 | objfile gets freed, then the other has a broken C-V chain. | |
674 | ||
675 | This code used to try to copy over the main type from TYPE to | |
676 | *TYPEPTR if they were in different objfiles, but that's | |
677 | wrong, too: TYPE may have a field list or member function | |
678 | lists, which refer to types of their own, etc. etc. The | |
679 | whole shebang would need to be copied over recursively; you | |
680 | can't have inter-objfile pointers. The only thing to do is | |
681 | to leave stub types as stub types, and look them up afresh by | |
682 | name each time you encounter them. */ | |
683 | gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)); | |
2fdde8f8 DJ |
684 | } |
685 | ||
7ba81444 MS |
686 | ntype = make_qualified_type (type, new_flags, |
687 | typeptr ? *typeptr : NULL); | |
c906108c | 688 | |
2fdde8f8 DJ |
689 | if (typeptr != NULL) |
690 | *typeptr = ntype; | |
a02fd225 | 691 | |
2fdde8f8 | 692 | return ntype; |
a02fd225 | 693 | } |
c906108c | 694 | |
06d66ee9 TT |
695 | /* Make a 'restrict'-qualified version of TYPE. */ |
696 | ||
697 | struct type * | |
698 | make_restrict_type (struct type *type) | |
699 | { | |
700 | return make_qualified_type (type, | |
701 | (TYPE_INSTANCE_FLAGS (type) | |
702 | | TYPE_INSTANCE_FLAG_RESTRICT), | |
703 | NULL); | |
704 | } | |
705 | ||
2fdde8f8 DJ |
706 | /* Replace the contents of ntype with the type *type. This changes the |
707 | contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus | |
708 | the changes are propogated to all types in the TYPE_CHAIN. | |
dd6bda65 | 709 | |
cda6c68a JB |
710 | In order to build recursive types, it's inevitable that we'll need |
711 | to update types in place --- but this sort of indiscriminate | |
712 | smashing is ugly, and needs to be replaced with something more | |
2fdde8f8 DJ |
713 | controlled. TYPE_MAIN_TYPE is a step in this direction; it's not |
714 | clear if more steps are needed. */ | |
5212577a | 715 | |
dd6bda65 DJ |
716 | void |
717 | replace_type (struct type *ntype, struct type *type) | |
718 | { | |
ab5d3da6 | 719 | struct type *chain; |
dd6bda65 | 720 | |
ad766c0a JB |
721 | /* These two types had better be in the same objfile. Otherwise, |
722 | the assignment of one type's main type structure to the other | |
723 | will produce a type with references to objects (names; field | |
724 | lists; etc.) allocated on an objfile other than its own. */ | |
725 | gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype)); | |
726 | ||
2fdde8f8 | 727 | *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type); |
dd6bda65 | 728 | |
7ba81444 MS |
729 | /* The type length is not a part of the main type. Update it for |
730 | each type on the variant chain. */ | |
ab5d3da6 | 731 | chain = ntype; |
5f61c20e JK |
732 | do |
733 | { | |
734 | /* Assert that this element of the chain has no address-class bits | |
735 | set in its flags. Such type variants might have type lengths | |
736 | which are supposed to be different from the non-address-class | |
737 | variants. This assertion shouldn't ever be triggered because | |
738 | symbol readers which do construct address-class variants don't | |
739 | call replace_type(). */ | |
740 | gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0); | |
741 | ||
742 | TYPE_LENGTH (chain) = TYPE_LENGTH (type); | |
743 | chain = TYPE_CHAIN (chain); | |
744 | } | |
745 | while (ntype != chain); | |
ab5d3da6 | 746 | |
2fdde8f8 DJ |
747 | /* Assert that the two types have equivalent instance qualifiers. |
748 | This should be true for at least all of our debug readers. */ | |
749 | gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type)); | |
dd6bda65 DJ |
750 | } |
751 | ||
c906108c SS |
752 | /* Implement direct support for MEMBER_TYPE in GNU C++. |
753 | May need to construct such a type if this is the first use. | |
754 | The TYPE is the type of the member. The DOMAIN is the type | |
755 | of the aggregate that the member belongs to. */ | |
756 | ||
757 | struct type * | |
0d5de010 | 758 | lookup_memberptr_type (struct type *type, struct type *domain) |
c906108c | 759 | { |
52f0bd74 | 760 | struct type *mtype; |
c906108c | 761 | |
e9bb382b | 762 | mtype = alloc_type_copy (type); |
0d5de010 | 763 | smash_to_memberptr_type (mtype, domain, type); |
c16abbde | 764 | return mtype; |
c906108c SS |
765 | } |
766 | ||
0d5de010 DJ |
767 | /* Return a pointer-to-method type, for a method of type TO_TYPE. */ |
768 | ||
769 | struct type * | |
770 | lookup_methodptr_type (struct type *to_type) | |
771 | { | |
772 | struct type *mtype; | |
773 | ||
e9bb382b | 774 | mtype = alloc_type_copy (to_type); |
0b92b5bb | 775 | smash_to_methodptr_type (mtype, to_type); |
0d5de010 DJ |
776 | return mtype; |
777 | } | |
778 | ||
7ba81444 MS |
779 | /* Allocate a stub method whose return type is TYPE. This apparently |
780 | happens for speed of symbol reading, since parsing out the | |
781 | arguments to the method is cpu-intensive, the way we are doing it. | |
782 | So, we will fill in arguments later. This always returns a fresh | |
783 | type. */ | |
c906108c SS |
784 | |
785 | struct type * | |
fba45db2 | 786 | allocate_stub_method (struct type *type) |
c906108c SS |
787 | { |
788 | struct type *mtype; | |
789 | ||
e9bb382b UW |
790 | mtype = alloc_type_copy (type); |
791 | TYPE_CODE (mtype) = TYPE_CODE_METHOD; | |
792 | TYPE_LENGTH (mtype) = 1; | |
793 | TYPE_STUB (mtype) = 1; | |
c906108c SS |
794 | TYPE_TARGET_TYPE (mtype) = type; |
795 | /* _DOMAIN_TYPE (mtype) = unknown yet */ | |
c16abbde | 796 | return mtype; |
c906108c SS |
797 | } |
798 | ||
7ba81444 MS |
799 | /* Create a range type using either a blank type supplied in |
800 | RESULT_TYPE, or creating a new type, inheriting the objfile from | |
801 | INDEX_TYPE. | |
c906108c | 802 | |
7ba81444 MS |
803 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND |
804 | to HIGH_BOUND, inclusive. | |
c906108c | 805 | |
7ba81444 MS |
806 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
807 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ | |
c906108c SS |
808 | |
809 | struct type * | |
fba45db2 | 810 | create_range_type (struct type *result_type, struct type *index_type, |
43bbcdc2 | 811 | LONGEST low_bound, LONGEST high_bound) |
c906108c SS |
812 | { |
813 | if (result_type == NULL) | |
e9bb382b | 814 | result_type = alloc_type_copy (index_type); |
c906108c SS |
815 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; |
816 | TYPE_TARGET_TYPE (result_type) = index_type; | |
74a9bb82 | 817 | if (TYPE_STUB (index_type)) |
876cecd0 | 818 | TYPE_TARGET_STUB (result_type) = 1; |
c906108c SS |
819 | else |
820 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); | |
43bbcdc2 PH |
821 | TYPE_RANGE_DATA (result_type) = (struct range_bounds *) |
822 | TYPE_ZALLOC (result_type, sizeof (struct range_bounds)); | |
262452ec JK |
823 | TYPE_LOW_BOUND (result_type) = low_bound; |
824 | TYPE_HIGH_BOUND (result_type) = high_bound; | |
c906108c | 825 | |
c5aa993b | 826 | if (low_bound >= 0) |
876cecd0 | 827 | TYPE_UNSIGNED (result_type) = 1; |
c906108c | 828 | |
262452ec | 829 | return result_type; |
c906108c SS |
830 | } |
831 | ||
7ba81444 MS |
832 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type |
833 | TYPE. Return 1 if type is a range type, 0 if it is discrete (and | |
834 | bounds will fit in LONGEST), or -1 otherwise. */ | |
c906108c SS |
835 | |
836 | int | |
fba45db2 | 837 | get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) |
c906108c SS |
838 | { |
839 | CHECK_TYPEDEF (type); | |
840 | switch (TYPE_CODE (type)) | |
841 | { | |
842 | case TYPE_CODE_RANGE: | |
843 | *lowp = TYPE_LOW_BOUND (type); | |
844 | *highp = TYPE_HIGH_BOUND (type); | |
845 | return 1; | |
846 | case TYPE_CODE_ENUM: | |
847 | if (TYPE_NFIELDS (type) > 0) | |
848 | { | |
849 | /* The enums may not be sorted by value, so search all | |
0963b4bd | 850 | entries. */ |
c906108c SS |
851 | int i; |
852 | ||
14e75d8e | 853 | *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0); |
c906108c SS |
854 | for (i = 0; i < TYPE_NFIELDS (type); i++) |
855 | { | |
14e75d8e JK |
856 | if (TYPE_FIELD_ENUMVAL (type, i) < *lowp) |
857 | *lowp = TYPE_FIELD_ENUMVAL (type, i); | |
858 | if (TYPE_FIELD_ENUMVAL (type, i) > *highp) | |
859 | *highp = TYPE_FIELD_ENUMVAL (type, i); | |
c906108c SS |
860 | } |
861 | ||
7ba81444 | 862 | /* Set unsigned indicator if warranted. */ |
c5aa993b | 863 | if (*lowp >= 0) |
c906108c | 864 | { |
876cecd0 | 865 | TYPE_UNSIGNED (type) = 1; |
c906108c SS |
866 | } |
867 | } | |
868 | else | |
869 | { | |
870 | *lowp = 0; | |
871 | *highp = -1; | |
872 | } | |
873 | return 0; | |
874 | case TYPE_CODE_BOOL: | |
875 | *lowp = 0; | |
876 | *highp = 1; | |
877 | return 0; | |
878 | case TYPE_CODE_INT: | |
c5aa993b | 879 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
c906108c SS |
880 | return -1; |
881 | if (!TYPE_UNSIGNED (type)) | |
882 | { | |
c5aa993b | 883 | *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); |
c906108c SS |
884 | *highp = -*lowp - 1; |
885 | return 0; | |
886 | } | |
7ba81444 | 887 | /* ... fall through for unsigned ints ... */ |
c906108c SS |
888 | case TYPE_CODE_CHAR: |
889 | *lowp = 0; | |
890 | /* This round-about calculation is to avoid shifting by | |
7b83ea04 | 891 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work |
7ba81444 | 892 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ |
c906108c SS |
893 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); |
894 | *highp = (*highp - 1) | *highp; | |
895 | return 0; | |
896 | default: | |
897 | return -1; | |
898 | } | |
899 | } | |
900 | ||
dbc98a8b KW |
901 | /* Assuming TYPE is a simple, non-empty array type, compute its upper |
902 | and lower bound. Save the low bound into LOW_BOUND if not NULL. | |
903 | Save the high bound into HIGH_BOUND if not NULL. | |
904 | ||
0963b4bd | 905 | Return 1 if the operation was successful. Return zero otherwise, |
dbc98a8b KW |
906 | in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified. |
907 | ||
908 | We now simply use get_discrete_bounds call to get the values | |
909 | of the low and high bounds. | |
910 | get_discrete_bounds can return three values: | |
911 | 1, meaning that index is a range, | |
912 | 0, meaning that index is a discrete type, | |
913 | or -1 for failure. */ | |
914 | ||
915 | int | |
916 | get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound) | |
917 | { | |
918 | struct type *index = TYPE_INDEX_TYPE (type); | |
919 | LONGEST low = 0; | |
920 | LONGEST high = 0; | |
921 | int res; | |
922 | ||
923 | if (index == NULL) | |
924 | return 0; | |
925 | ||
926 | res = get_discrete_bounds (index, &low, &high); | |
927 | if (res == -1) | |
928 | return 0; | |
929 | ||
930 | /* Check if the array bounds are undefined. */ | |
931 | if (res == 1 | |
932 | && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type)) | |
933 | || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)))) | |
934 | return 0; | |
935 | ||
936 | if (low_bound) | |
937 | *low_bound = low; | |
938 | ||
939 | if (high_bound) | |
940 | *high_bound = high; | |
941 | ||
942 | return 1; | |
943 | } | |
944 | ||
7ba81444 MS |
945 | /* Create an array type using either a blank type supplied in |
946 | RESULT_TYPE, or creating a new type, inheriting the objfile from | |
947 | RANGE_TYPE. | |
c906108c SS |
948 | |
949 | Elements will be of type ELEMENT_TYPE, the indices will be of type | |
950 | RANGE_TYPE. | |
951 | ||
7ba81444 MS |
952 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
953 | sure it is TYPE_CODE_UNDEF before we bash it into an array | |
954 | type? */ | |
c906108c SS |
955 | |
956 | struct type * | |
7ba81444 MS |
957 | create_array_type (struct type *result_type, |
958 | struct type *element_type, | |
fba45db2 | 959 | struct type *range_type) |
c906108c SS |
960 | { |
961 | LONGEST low_bound, high_bound; | |
962 | ||
963 | if (result_type == NULL) | |
e9bb382b UW |
964 | result_type = alloc_type_copy (range_type); |
965 | ||
c906108c SS |
966 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; |
967 | TYPE_TARGET_TYPE (result_type) = element_type; | |
968 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) | |
969 | low_bound = high_bound = 0; | |
970 | CHECK_TYPEDEF (element_type); | |
ab0d6e0d JB |
971 | /* Be careful when setting the array length. Ada arrays can be |
972 | empty arrays with the high_bound being smaller than the low_bound. | |
973 | In such cases, the array length should be zero. */ | |
974 | if (high_bound < low_bound) | |
975 | TYPE_LENGTH (result_type) = 0; | |
976 | else | |
977 | TYPE_LENGTH (result_type) = | |
978 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); | |
c906108c SS |
979 | TYPE_NFIELDS (result_type) = 1; |
980 | TYPE_FIELDS (result_type) = | |
1deafd4e | 981 | (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)); |
262452ec | 982 | TYPE_INDEX_TYPE (result_type) = range_type; |
c906108c SS |
983 | TYPE_VPTR_FIELDNO (result_type) = -1; |
984 | ||
0963b4bd | 985 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */ |
c906108c | 986 | if (TYPE_LENGTH (result_type) == 0) |
876cecd0 | 987 | TYPE_TARGET_STUB (result_type) = 1; |
c906108c | 988 | |
c16abbde | 989 | return result_type; |
c906108c SS |
990 | } |
991 | ||
e3506a9f UW |
992 | struct type * |
993 | lookup_array_range_type (struct type *element_type, | |
63375b74 | 994 | LONGEST low_bound, LONGEST high_bound) |
e3506a9f | 995 | { |
50810684 | 996 | struct gdbarch *gdbarch = get_type_arch (element_type); |
e3506a9f UW |
997 | struct type *index_type = builtin_type (gdbarch)->builtin_int; |
998 | struct type *range_type | |
999 | = create_range_type (NULL, index_type, low_bound, high_bound); | |
d8734c88 | 1000 | |
e3506a9f UW |
1001 | return create_array_type (NULL, element_type, range_type); |
1002 | } | |
1003 | ||
7ba81444 MS |
1004 | /* Create a string type using either a blank type supplied in |
1005 | RESULT_TYPE, or creating a new type. String types are similar | |
1006 | enough to array of char types that we can use create_array_type to | |
1007 | build the basic type and then bash it into a string type. | |
c906108c SS |
1008 | |
1009 | For fixed length strings, the range type contains 0 as the lower | |
1010 | bound and the length of the string minus one as the upper bound. | |
1011 | ||
7ba81444 MS |
1012 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
1013 | sure it is TYPE_CODE_UNDEF before we bash it into a string | |
1014 | type? */ | |
c906108c SS |
1015 | |
1016 | struct type * | |
3b7538c0 UW |
1017 | create_string_type (struct type *result_type, |
1018 | struct type *string_char_type, | |
7ba81444 | 1019 | struct type *range_type) |
c906108c SS |
1020 | { |
1021 | result_type = create_array_type (result_type, | |
f290d38e | 1022 | string_char_type, |
c906108c SS |
1023 | range_type); |
1024 | TYPE_CODE (result_type) = TYPE_CODE_STRING; | |
c16abbde | 1025 | return result_type; |
c906108c SS |
1026 | } |
1027 | ||
e3506a9f UW |
1028 | struct type * |
1029 | lookup_string_range_type (struct type *string_char_type, | |
63375b74 | 1030 | LONGEST low_bound, LONGEST high_bound) |
e3506a9f UW |
1031 | { |
1032 | struct type *result_type; | |
d8734c88 | 1033 | |
e3506a9f UW |
1034 | result_type = lookup_array_range_type (string_char_type, |
1035 | low_bound, high_bound); | |
1036 | TYPE_CODE (result_type) = TYPE_CODE_STRING; | |
1037 | return result_type; | |
1038 | } | |
1039 | ||
c906108c | 1040 | struct type * |
fba45db2 | 1041 | create_set_type (struct type *result_type, struct type *domain_type) |
c906108c | 1042 | { |
c906108c | 1043 | if (result_type == NULL) |
e9bb382b UW |
1044 | result_type = alloc_type_copy (domain_type); |
1045 | ||
c906108c SS |
1046 | TYPE_CODE (result_type) = TYPE_CODE_SET; |
1047 | TYPE_NFIELDS (result_type) = 1; | |
1deafd4e | 1048 | TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field)); |
c906108c | 1049 | |
74a9bb82 | 1050 | if (!TYPE_STUB (domain_type)) |
c906108c | 1051 | { |
f9780d5b | 1052 | LONGEST low_bound, high_bound, bit_length; |
d8734c88 | 1053 | |
c906108c SS |
1054 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) |
1055 | low_bound = high_bound = 0; | |
1056 | bit_length = high_bound - low_bound + 1; | |
1057 | TYPE_LENGTH (result_type) | |
1058 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; | |
f9780d5b | 1059 | if (low_bound >= 0) |
876cecd0 | 1060 | TYPE_UNSIGNED (result_type) = 1; |
c906108c SS |
1061 | } |
1062 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; | |
1063 | ||
c16abbde | 1064 | return result_type; |
c906108c SS |
1065 | } |
1066 | ||
ea37ba09 DJ |
1067 | /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE |
1068 | and any array types nested inside it. */ | |
1069 | ||
1070 | void | |
1071 | make_vector_type (struct type *array_type) | |
1072 | { | |
1073 | struct type *inner_array, *elt_type; | |
1074 | int flags; | |
1075 | ||
1076 | /* Find the innermost array type, in case the array is | |
1077 | multi-dimensional. */ | |
1078 | inner_array = array_type; | |
1079 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
1080 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
1081 | ||
1082 | elt_type = TYPE_TARGET_TYPE (inner_array); | |
1083 | if (TYPE_CODE (elt_type) == TYPE_CODE_INT) | |
1084 | { | |
2844d6b5 | 1085 | flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT; |
ea37ba09 DJ |
1086 | elt_type = make_qualified_type (elt_type, flags, NULL); |
1087 | TYPE_TARGET_TYPE (inner_array) = elt_type; | |
1088 | } | |
1089 | ||
876cecd0 | 1090 | TYPE_VECTOR (array_type) = 1; |
ea37ba09 DJ |
1091 | } |
1092 | ||
794ac428 | 1093 | struct type * |
ac3aafc7 EZ |
1094 | init_vector_type (struct type *elt_type, int n) |
1095 | { | |
1096 | struct type *array_type; | |
d8734c88 | 1097 | |
e3506a9f | 1098 | array_type = lookup_array_range_type (elt_type, 0, n - 1); |
ea37ba09 | 1099 | make_vector_type (array_type); |
ac3aafc7 EZ |
1100 | return array_type; |
1101 | } | |
1102 | ||
0d5de010 DJ |
1103 | /* Smash TYPE to be a type of pointers to members of DOMAIN with type |
1104 | TO_TYPE. A member pointer is a wierd thing -- it amounts to a | |
1105 | typed offset into a struct, e.g. "an int at offset 8". A MEMBER | |
1106 | TYPE doesn't include the offset (that's the value of the MEMBER | |
1107 | itself), but does include the structure type into which it points | |
1108 | (for some reason). | |
c906108c | 1109 | |
7ba81444 MS |
1110 | When "smashing" the type, we preserve the objfile that the old type |
1111 | pointed to, since we aren't changing where the type is actually | |
c906108c SS |
1112 | allocated. */ |
1113 | ||
1114 | void | |
0d5de010 DJ |
1115 | smash_to_memberptr_type (struct type *type, struct type *domain, |
1116 | struct type *to_type) | |
c906108c | 1117 | { |
2fdde8f8 | 1118 | smash_type (type); |
c906108c SS |
1119 | TYPE_TARGET_TYPE (type) = to_type; |
1120 | TYPE_DOMAIN_TYPE (type) = domain; | |
0d5de010 DJ |
1121 | /* Assume that a data member pointer is the same size as a normal |
1122 | pointer. */ | |
50810684 UW |
1123 | TYPE_LENGTH (type) |
1124 | = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT; | |
0d5de010 | 1125 | TYPE_CODE (type) = TYPE_CODE_MEMBERPTR; |
c906108c SS |
1126 | } |
1127 | ||
0b92b5bb TT |
1128 | /* Smash TYPE to be a type of pointer to methods type TO_TYPE. |
1129 | ||
1130 | When "smashing" the type, we preserve the objfile that the old type | |
1131 | pointed to, since we aren't changing where the type is actually | |
1132 | allocated. */ | |
1133 | ||
1134 | void | |
1135 | smash_to_methodptr_type (struct type *type, struct type *to_type) | |
1136 | { | |
1137 | smash_type (type); | |
1138 | TYPE_TARGET_TYPE (type) = to_type; | |
1139 | TYPE_DOMAIN_TYPE (type) = TYPE_DOMAIN_TYPE (to_type); | |
1140 | TYPE_LENGTH (type) = cplus_method_ptr_size (to_type); | |
1141 | TYPE_CODE (type) = TYPE_CODE_METHODPTR; | |
1142 | } | |
1143 | ||
c906108c SS |
1144 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. |
1145 | METHOD just means `function that gets an extra "this" argument'. | |
1146 | ||
7ba81444 MS |
1147 | When "smashing" the type, we preserve the objfile that the old type |
1148 | pointed to, since we aren't changing where the type is actually | |
c906108c SS |
1149 | allocated. */ |
1150 | ||
1151 | void | |
fba45db2 | 1152 | smash_to_method_type (struct type *type, struct type *domain, |
ad2f7632 DJ |
1153 | struct type *to_type, struct field *args, |
1154 | int nargs, int varargs) | |
c906108c | 1155 | { |
2fdde8f8 | 1156 | smash_type (type); |
c906108c SS |
1157 | TYPE_TARGET_TYPE (type) = to_type; |
1158 | TYPE_DOMAIN_TYPE (type) = domain; | |
ad2f7632 DJ |
1159 | TYPE_FIELDS (type) = args; |
1160 | TYPE_NFIELDS (type) = nargs; | |
1161 | if (varargs) | |
876cecd0 | 1162 | TYPE_VARARGS (type) = 1; |
c906108c SS |
1163 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
1164 | TYPE_CODE (type) = TYPE_CODE_METHOD; | |
1165 | } | |
1166 | ||
1167 | /* Return a typename for a struct/union/enum type without "struct ", | |
1168 | "union ", or "enum ". If the type has a NULL name, return NULL. */ | |
1169 | ||
0d5cff50 | 1170 | const char * |
aa1ee363 | 1171 | type_name_no_tag (const struct type *type) |
c906108c SS |
1172 | { |
1173 | if (TYPE_TAG_NAME (type) != NULL) | |
1174 | return TYPE_TAG_NAME (type); | |
1175 | ||
7ba81444 MS |
1176 | /* Is there code which expects this to return the name if there is |
1177 | no tag name? My guess is that this is mainly used for C++ in | |
1178 | cases where the two will always be the same. */ | |
c906108c SS |
1179 | return TYPE_NAME (type); |
1180 | } | |
1181 | ||
d8228535 JK |
1182 | /* A wrapper of type_name_no_tag which calls error if the type is anonymous. |
1183 | Since GCC PR debug/47510 DWARF provides associated information to detect the | |
1184 | anonymous class linkage name from its typedef. | |
1185 | ||
1186 | Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will | |
1187 | apply it itself. */ | |
1188 | ||
1189 | const char * | |
1190 | type_name_no_tag_or_error (struct type *type) | |
1191 | { | |
1192 | struct type *saved_type = type; | |
1193 | const char *name; | |
1194 | struct objfile *objfile; | |
1195 | ||
1196 | CHECK_TYPEDEF (type); | |
1197 | ||
1198 | name = type_name_no_tag (type); | |
1199 | if (name != NULL) | |
1200 | return name; | |
1201 | ||
1202 | name = type_name_no_tag (saved_type); | |
1203 | objfile = TYPE_OBJFILE (saved_type); | |
1204 | error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"), | |
4262abfb JK |
1205 | name ? name : "<anonymous>", |
1206 | objfile ? objfile_name (objfile) : "<arch>"); | |
d8228535 JK |
1207 | } |
1208 | ||
7ba81444 MS |
1209 | /* Lookup a typedef or primitive type named NAME, visible in lexical |
1210 | block BLOCK. If NOERR is nonzero, return zero if NAME is not | |
1211 | suitably defined. */ | |
c906108c SS |
1212 | |
1213 | struct type * | |
e6c014f2 | 1214 | lookup_typename (const struct language_defn *language, |
ddd49eee | 1215 | struct gdbarch *gdbarch, const char *name, |
34eaf542 | 1216 | const struct block *block, int noerr) |
c906108c | 1217 | { |
52f0bd74 | 1218 | struct symbol *sym; |
659c9f3a | 1219 | struct type *type; |
c906108c | 1220 | |
774b6a14 | 1221 | sym = lookup_symbol (name, block, VAR_DOMAIN, 0); |
c51fe631 DE |
1222 | if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
1223 | return SYMBOL_TYPE (sym); | |
1224 | ||
659c9f3a DE |
1225 | type = language_lookup_primitive_type_by_name (language, gdbarch, name); |
1226 | if (type) | |
1227 | return type; | |
c51fe631 DE |
1228 | |
1229 | if (noerr) | |
1230 | return NULL; | |
1231 | error (_("No type named %s."), name); | |
c906108c SS |
1232 | } |
1233 | ||
1234 | struct type * | |
e6c014f2 | 1235 | lookup_unsigned_typename (const struct language_defn *language, |
0d5cff50 | 1236 | struct gdbarch *gdbarch, const char *name) |
c906108c SS |
1237 | { |
1238 | char *uns = alloca (strlen (name) + 10); | |
1239 | ||
1240 | strcpy (uns, "unsigned "); | |
1241 | strcpy (uns + 9, name); | |
e6c014f2 | 1242 | return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0); |
c906108c SS |
1243 | } |
1244 | ||
1245 | struct type * | |
e6c014f2 | 1246 | lookup_signed_typename (const struct language_defn *language, |
0d5cff50 | 1247 | struct gdbarch *gdbarch, const char *name) |
c906108c SS |
1248 | { |
1249 | struct type *t; | |
1250 | char *uns = alloca (strlen (name) + 8); | |
1251 | ||
1252 | strcpy (uns, "signed "); | |
1253 | strcpy (uns + 7, name); | |
e6c014f2 | 1254 | t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1); |
7ba81444 | 1255 | /* If we don't find "signed FOO" just try again with plain "FOO". */ |
c906108c SS |
1256 | if (t != NULL) |
1257 | return t; | |
e6c014f2 | 1258 | return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0); |
c906108c SS |
1259 | } |
1260 | ||
1261 | /* Lookup a structure type named "struct NAME", | |
1262 | visible in lexical block BLOCK. */ | |
1263 | ||
1264 | struct type * | |
270140bd | 1265 | lookup_struct (const char *name, const struct block *block) |
c906108c | 1266 | { |
52f0bd74 | 1267 | struct symbol *sym; |
c906108c | 1268 | |
2570f2b7 | 1269 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0); |
c906108c SS |
1270 | |
1271 | if (sym == NULL) | |
1272 | { | |
8a3fe4f8 | 1273 | error (_("No struct type named %s."), name); |
c906108c SS |
1274 | } |
1275 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
1276 | { | |
7ba81444 MS |
1277 | error (_("This context has class, union or enum %s, not a struct."), |
1278 | name); | |
c906108c SS |
1279 | } |
1280 | return (SYMBOL_TYPE (sym)); | |
1281 | } | |
1282 | ||
1283 | /* Lookup a union type named "union NAME", | |
1284 | visible in lexical block BLOCK. */ | |
1285 | ||
1286 | struct type * | |
270140bd | 1287 | lookup_union (const char *name, const struct block *block) |
c906108c | 1288 | { |
52f0bd74 | 1289 | struct symbol *sym; |
c5aa993b | 1290 | struct type *t; |
c906108c | 1291 | |
2570f2b7 | 1292 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0); |
c906108c SS |
1293 | |
1294 | if (sym == NULL) | |
8a3fe4f8 | 1295 | error (_("No union type named %s."), name); |
c906108c | 1296 | |
c5aa993b | 1297 | t = SYMBOL_TYPE (sym); |
c906108c SS |
1298 | |
1299 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
c16abbde | 1300 | return t; |
c906108c | 1301 | |
7ba81444 MS |
1302 | /* If we get here, it's not a union. */ |
1303 | error (_("This context has class, struct or enum %s, not a union."), | |
1304 | name); | |
c906108c SS |
1305 | } |
1306 | ||
c906108c SS |
1307 | /* Lookup an enum type named "enum NAME", |
1308 | visible in lexical block BLOCK. */ | |
1309 | ||
1310 | struct type * | |
270140bd | 1311 | lookup_enum (const char *name, const struct block *block) |
c906108c | 1312 | { |
52f0bd74 | 1313 | struct symbol *sym; |
c906108c | 1314 | |
2570f2b7 | 1315 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0); |
c906108c SS |
1316 | if (sym == NULL) |
1317 | { | |
8a3fe4f8 | 1318 | error (_("No enum type named %s."), name); |
c906108c SS |
1319 | } |
1320 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) | |
1321 | { | |
7ba81444 MS |
1322 | error (_("This context has class, struct or union %s, not an enum."), |
1323 | name); | |
c906108c SS |
1324 | } |
1325 | return (SYMBOL_TYPE (sym)); | |
1326 | } | |
1327 | ||
1328 | /* Lookup a template type named "template NAME<TYPE>", | |
1329 | visible in lexical block BLOCK. */ | |
1330 | ||
1331 | struct type * | |
7ba81444 | 1332 | lookup_template_type (char *name, struct type *type, |
270140bd | 1333 | const struct block *block) |
c906108c SS |
1334 | { |
1335 | struct symbol *sym; | |
7ba81444 MS |
1336 | char *nam = (char *) |
1337 | alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4); | |
d8734c88 | 1338 | |
c906108c SS |
1339 | strcpy (nam, name); |
1340 | strcat (nam, "<"); | |
0004e5a2 | 1341 | strcat (nam, TYPE_NAME (type)); |
0963b4bd | 1342 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ |
c906108c | 1343 | |
2570f2b7 | 1344 | sym = lookup_symbol (nam, block, VAR_DOMAIN, 0); |
c906108c SS |
1345 | |
1346 | if (sym == NULL) | |
1347 | { | |
8a3fe4f8 | 1348 | error (_("No template type named %s."), name); |
c906108c SS |
1349 | } |
1350 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
1351 | { | |
7ba81444 MS |
1352 | error (_("This context has class, union or enum %s, not a struct."), |
1353 | name); | |
c906108c SS |
1354 | } |
1355 | return (SYMBOL_TYPE (sym)); | |
1356 | } | |
1357 | ||
7ba81444 MS |
1358 | /* Given a type TYPE, lookup the type of the component of type named |
1359 | NAME. | |
c906108c | 1360 | |
7ba81444 MS |
1361 | TYPE can be either a struct or union, or a pointer or reference to |
1362 | a struct or union. If it is a pointer or reference, its target | |
1363 | type is automatically used. Thus '.' and '->' are interchangable, | |
1364 | as specified for the definitions of the expression element types | |
1365 | STRUCTOP_STRUCT and STRUCTOP_PTR. | |
c906108c SS |
1366 | |
1367 | If NOERR is nonzero, return zero if NAME is not suitably defined. | |
1368 | If NAME is the name of a baseclass type, return that type. */ | |
1369 | ||
1370 | struct type * | |
d7561cbb | 1371 | lookup_struct_elt_type (struct type *type, const char *name, int noerr) |
c906108c SS |
1372 | { |
1373 | int i; | |
c92817ce | 1374 | char *typename; |
c906108c SS |
1375 | |
1376 | for (;;) | |
1377 | { | |
1378 | CHECK_TYPEDEF (type); | |
1379 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
1380 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
1381 | break; | |
1382 | type = TYPE_TARGET_TYPE (type); | |
1383 | } | |
1384 | ||
687d6395 MS |
1385 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
1386 | && TYPE_CODE (type) != TYPE_CODE_UNION) | |
c906108c | 1387 | { |
c92817ce TT |
1388 | typename = type_to_string (type); |
1389 | make_cleanup (xfree, typename); | |
1390 | error (_("Type %s is not a structure or union type."), typename); | |
c906108c SS |
1391 | } |
1392 | ||
1393 | #if 0 | |
7ba81444 MS |
1394 | /* FIXME: This change put in by Michael seems incorrect for the case |
1395 | where the structure tag name is the same as the member name. | |
0963b4bd | 1396 | I.e. when doing "ptype bell->bar" for "struct foo { int bar; int |
7ba81444 | 1397 | foo; } bell;" Disabled by fnf. */ |
c906108c SS |
1398 | { |
1399 | char *typename; | |
1400 | ||
1401 | typename = type_name_no_tag (type); | |
762f08a3 | 1402 | if (typename != NULL && strcmp (typename, name) == 0) |
c906108c SS |
1403 | return type; |
1404 | } | |
1405 | #endif | |
1406 | ||
1407 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
1408 | { | |
0d5cff50 | 1409 | const char *t_field_name = TYPE_FIELD_NAME (type, i); |
c906108c | 1410 | |
db577aea | 1411 | if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) |
c906108c SS |
1412 | { |
1413 | return TYPE_FIELD_TYPE (type, i); | |
1414 | } | |
f5a010c0 PM |
1415 | else if (!t_field_name || *t_field_name == '\0') |
1416 | { | |
d8734c88 MS |
1417 | struct type *subtype |
1418 | = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1); | |
1419 | ||
f5a010c0 PM |
1420 | if (subtype != NULL) |
1421 | return subtype; | |
1422 | } | |
c906108c SS |
1423 | } |
1424 | ||
1425 | /* OK, it's not in this class. Recursively check the baseclasses. */ | |
1426 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
1427 | { | |
1428 | struct type *t; | |
1429 | ||
9733fc94 | 1430 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1); |
c906108c SS |
1431 | if (t != NULL) |
1432 | { | |
1433 | return t; | |
1434 | } | |
1435 | } | |
1436 | ||
1437 | if (noerr) | |
1438 | { | |
1439 | return NULL; | |
1440 | } | |
c5aa993b | 1441 | |
c92817ce TT |
1442 | typename = type_to_string (type); |
1443 | make_cleanup (xfree, typename); | |
1444 | error (_("Type %s has no component named %s."), typename, name); | |
c906108c SS |
1445 | } |
1446 | ||
81fe8080 DE |
1447 | /* Lookup the vptr basetype/fieldno values for TYPE. |
1448 | If found store vptr_basetype in *BASETYPEP if non-NULL, and return | |
1449 | vptr_fieldno. Also, if found and basetype is from the same objfile, | |
1450 | cache the results. | |
1451 | If not found, return -1 and ignore BASETYPEP. | |
1452 | Callers should be aware that in some cases (for example, | |
c906108c | 1453 | the type or one of its baseclasses is a stub type and we are |
d48cc9dd DJ |
1454 | debugging a .o file, or the compiler uses DWARF-2 and is not GCC), |
1455 | this function will not be able to find the | |
7ba81444 | 1456 | virtual function table pointer, and vptr_fieldno will remain -1 and |
81fe8080 | 1457 | vptr_basetype will remain NULL or incomplete. */ |
c906108c | 1458 | |
81fe8080 DE |
1459 | int |
1460 | get_vptr_fieldno (struct type *type, struct type **basetypep) | |
c906108c SS |
1461 | { |
1462 | CHECK_TYPEDEF (type); | |
1463 | ||
1464 | if (TYPE_VPTR_FIELDNO (type) < 0) | |
1465 | { | |
1466 | int i; | |
1467 | ||
7ba81444 MS |
1468 | /* We must start at zero in case the first (and only) baseclass |
1469 | is virtual (and hence we cannot share the table pointer). */ | |
c906108c SS |
1470 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
1471 | { | |
81fe8080 DE |
1472 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); |
1473 | int fieldno; | |
1474 | struct type *basetype; | |
1475 | ||
1476 | fieldno = get_vptr_fieldno (baseclass, &basetype); | |
1477 | if (fieldno >= 0) | |
c906108c | 1478 | { |
81fe8080 | 1479 | /* If the type comes from a different objfile we can't cache |
0963b4bd | 1480 | it, it may have a different lifetime. PR 2384 */ |
5ef73790 | 1481 | if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype)) |
81fe8080 DE |
1482 | { |
1483 | TYPE_VPTR_FIELDNO (type) = fieldno; | |
1484 | TYPE_VPTR_BASETYPE (type) = basetype; | |
1485 | } | |
1486 | if (basetypep) | |
1487 | *basetypep = basetype; | |
1488 | return fieldno; | |
c906108c SS |
1489 | } |
1490 | } | |
81fe8080 DE |
1491 | |
1492 | /* Not found. */ | |
1493 | return -1; | |
1494 | } | |
1495 | else | |
1496 | { | |
1497 | if (basetypep) | |
1498 | *basetypep = TYPE_VPTR_BASETYPE (type); | |
1499 | return TYPE_VPTR_FIELDNO (type); | |
c906108c SS |
1500 | } |
1501 | } | |
1502 | ||
44e1a9eb DJ |
1503 | static void |
1504 | stub_noname_complaint (void) | |
1505 | { | |
e2e0b3e5 | 1506 | complaint (&symfile_complaints, _("stub type has NULL name")); |
44e1a9eb DJ |
1507 | } |
1508 | ||
92163a10 JK |
1509 | /* Find the real type of TYPE. This function returns the real type, |
1510 | after removing all layers of typedefs, and completing opaque or stub | |
1511 | types. Completion changes the TYPE argument, but stripping of | |
1512 | typedefs does not. | |
1513 | ||
1514 | Instance flags (e.g. const/volatile) are preserved as typedefs are | |
1515 | stripped. If necessary a new qualified form of the underlying type | |
1516 | is created. | |
1517 | ||
1518 | NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has | |
1519 | not been computed and we're either in the middle of reading symbols, or | |
1520 | there was no name for the typedef in the debug info. | |
1521 | ||
9bc118a5 DE |
1522 | NOTE: Lookup of opaque types can throw errors for invalid symbol files. |
1523 | QUITs in the symbol reading code can also throw. | |
1524 | Thus this function can throw an exception. | |
1525 | ||
92163a10 JK |
1526 | If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of |
1527 | the target type. | |
c906108c SS |
1528 | |
1529 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
0963b4bd | 1530 | we can find a full definition in some other file. If so, copy this |
7ba81444 MS |
1531 | definition, so we can use it in future. There used to be a comment |
1532 | (but not any code) that if we don't find a full definition, we'd | |
1533 | set a flag so we don't spend time in the future checking the same | |
1534 | type. That would be a mistake, though--we might load in more | |
92163a10 | 1535 | symbols which contain a full definition for the type. */ |
c906108c SS |
1536 | |
1537 | struct type * | |
a02fd225 | 1538 | check_typedef (struct type *type) |
c906108c SS |
1539 | { |
1540 | struct type *orig_type = type; | |
92163a10 JK |
1541 | /* While we're removing typedefs, we don't want to lose qualifiers. |
1542 | E.g., const/volatile. */ | |
1543 | int instance_flags = TYPE_INSTANCE_FLAGS (type); | |
a02fd225 | 1544 | |
423c0af8 MS |
1545 | gdb_assert (type); |
1546 | ||
c906108c SS |
1547 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
1548 | { | |
1549 | if (!TYPE_TARGET_TYPE (type)) | |
1550 | { | |
0d5cff50 | 1551 | const char *name; |
c906108c SS |
1552 | struct symbol *sym; |
1553 | ||
1554 | /* It is dangerous to call lookup_symbol if we are currently | |
7ba81444 | 1555 | reading a symtab. Infinite recursion is one danger. */ |
c906108c | 1556 | if (currently_reading_symtab) |
92163a10 | 1557 | return make_qualified_type (type, instance_flags, NULL); |
c906108c SS |
1558 | |
1559 | name = type_name_no_tag (type); | |
7ba81444 MS |
1560 | /* FIXME: shouldn't we separately check the TYPE_NAME and |
1561 | the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or | |
1562 | VAR_DOMAIN as appropriate? (this code was written before | |
1563 | TYPE_NAME and TYPE_TAG_NAME were separate). */ | |
c906108c SS |
1564 | if (name == NULL) |
1565 | { | |
23136709 | 1566 | stub_noname_complaint (); |
92163a10 | 1567 | return make_qualified_type (type, instance_flags, NULL); |
c906108c | 1568 | } |
2570f2b7 | 1569 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0); |
c906108c SS |
1570 | if (sym) |
1571 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); | |
7ba81444 | 1572 | else /* TYPE_CODE_UNDEF */ |
e9bb382b | 1573 | TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type)); |
c906108c SS |
1574 | } |
1575 | type = TYPE_TARGET_TYPE (type); | |
c906108c | 1576 | |
92163a10 JK |
1577 | /* Preserve the instance flags as we traverse down the typedef chain. |
1578 | ||
1579 | Handling address spaces/classes is nasty, what do we do if there's a | |
1580 | conflict? | |
1581 | E.g., what if an outer typedef marks the type as class_1 and an inner | |
1582 | typedef marks the type as class_2? | |
1583 | This is the wrong place to do such error checking. We leave it to | |
1584 | the code that created the typedef in the first place to flag the | |
1585 | error. We just pick the outer address space (akin to letting the | |
1586 | outer cast in a chain of casting win), instead of assuming | |
1587 | "it can't happen". */ | |
1588 | { | |
1589 | const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE | |
1590 | | TYPE_INSTANCE_FLAG_DATA_SPACE); | |
1591 | const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL; | |
1592 | int new_instance_flags = TYPE_INSTANCE_FLAGS (type); | |
1593 | ||
1594 | /* Treat code vs data spaces and address classes separately. */ | |
1595 | if ((instance_flags & ALL_SPACES) != 0) | |
1596 | new_instance_flags &= ~ALL_SPACES; | |
1597 | if ((instance_flags & ALL_CLASSES) != 0) | |
1598 | new_instance_flags &= ~ALL_CLASSES; | |
1599 | ||
1600 | instance_flags |= new_instance_flags; | |
1601 | } | |
1602 | } | |
a02fd225 | 1603 | |
7ba81444 MS |
1604 | /* If this is a struct/class/union with no fields, then check |
1605 | whether a full definition exists somewhere else. This is for | |
1606 | systems where a type definition with no fields is issued for such | |
1607 | types, instead of identifying them as stub types in the first | |
1608 | place. */ | |
c5aa993b | 1609 | |
7ba81444 MS |
1610 | if (TYPE_IS_OPAQUE (type) |
1611 | && opaque_type_resolution | |
1612 | && !currently_reading_symtab) | |
c906108c | 1613 | { |
0d5cff50 | 1614 | const char *name = type_name_no_tag (type); |
c5aa993b | 1615 | struct type *newtype; |
d8734c88 | 1616 | |
c906108c SS |
1617 | if (name == NULL) |
1618 | { | |
23136709 | 1619 | stub_noname_complaint (); |
92163a10 | 1620 | return make_qualified_type (type, instance_flags, NULL); |
c906108c SS |
1621 | } |
1622 | newtype = lookup_transparent_type (name); | |
ad766c0a | 1623 | |
c906108c | 1624 | if (newtype) |
ad766c0a | 1625 | { |
7ba81444 MS |
1626 | /* If the resolved type and the stub are in the same |
1627 | objfile, then replace the stub type with the real deal. | |
1628 | But if they're in separate objfiles, leave the stub | |
1629 | alone; we'll just look up the transparent type every time | |
1630 | we call check_typedef. We can't create pointers between | |
1631 | types allocated to different objfiles, since they may | |
1632 | have different lifetimes. Trying to copy NEWTYPE over to | |
1633 | TYPE's objfile is pointless, too, since you'll have to | |
1634 | move over any other types NEWTYPE refers to, which could | |
1635 | be an unbounded amount of stuff. */ | |
ad766c0a | 1636 | if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type)) |
92163a10 JK |
1637 | type = make_qualified_type (newtype, |
1638 | TYPE_INSTANCE_FLAGS (type), | |
1639 | type); | |
ad766c0a JB |
1640 | else |
1641 | type = newtype; | |
1642 | } | |
c906108c | 1643 | } |
7ba81444 MS |
1644 | /* Otherwise, rely on the stub flag being set for opaque/stubbed |
1645 | types. */ | |
74a9bb82 | 1646 | else if (TYPE_STUB (type) && !currently_reading_symtab) |
c906108c | 1647 | { |
0d5cff50 | 1648 | const char *name = type_name_no_tag (type); |
c906108c | 1649 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
176620f1 | 1650 | TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN |
7b83ea04 AC |
1651 | as appropriate? (this code was written before TYPE_NAME and |
1652 | TYPE_TAG_NAME were separate). */ | |
c906108c | 1653 | struct symbol *sym; |
d8734c88 | 1654 | |
c906108c SS |
1655 | if (name == NULL) |
1656 | { | |
23136709 | 1657 | stub_noname_complaint (); |
92163a10 | 1658 | return make_qualified_type (type, instance_flags, NULL); |
c906108c | 1659 | } |
2570f2b7 | 1660 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0); |
c906108c | 1661 | if (sym) |
c26f2453 JB |
1662 | { |
1663 | /* Same as above for opaque types, we can replace the stub | |
92163a10 | 1664 | with the complete type only if they are in the same |
c26f2453 JB |
1665 | objfile. */ |
1666 | if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type)) | |
92163a10 JK |
1667 | type = make_qualified_type (SYMBOL_TYPE (sym), |
1668 | TYPE_INSTANCE_FLAGS (type), | |
1669 | type); | |
c26f2453 JB |
1670 | else |
1671 | type = SYMBOL_TYPE (sym); | |
1672 | } | |
c906108c SS |
1673 | } |
1674 | ||
74a9bb82 | 1675 | if (TYPE_TARGET_STUB (type)) |
c906108c SS |
1676 | { |
1677 | struct type *range_type; | |
1678 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1679 | ||
74a9bb82 | 1680 | if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type)) |
c5aa993b | 1681 | { |
73e2eb35 | 1682 | /* Nothing we can do. */ |
c5aa993b | 1683 | } |
c906108c SS |
1684 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
1685 | && TYPE_NFIELDS (type) == 1 | |
262452ec | 1686 | && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type)) |
c906108c SS |
1687 | == TYPE_CODE_RANGE)) |
1688 | { | |
1689 | /* Now recompute the length of the array type, based on its | |
ab0d6e0d JB |
1690 | number of elements and the target type's length. |
1691 | Watch out for Ada null Ada arrays where the high bound | |
0963b4bd | 1692 | is smaller than the low bound. */ |
43bbcdc2 PH |
1693 | const LONGEST low_bound = TYPE_LOW_BOUND (range_type); |
1694 | const LONGEST high_bound = TYPE_HIGH_BOUND (range_type); | |
1695 | ULONGEST len; | |
1696 | ||
ab0d6e0d | 1697 | if (high_bound < low_bound) |
43bbcdc2 | 1698 | len = 0; |
d8734c88 MS |
1699 | else |
1700 | { | |
1701 | /* For now, we conservatively take the array length to be 0 | |
1702 | if its length exceeds UINT_MAX. The code below assumes | |
1703 | that for x < 0, (ULONGEST) x == -x + ULONGEST_MAX + 1, | |
1704 | which is technically not guaranteed by C, but is usually true | |
1705 | (because it would be true if x were unsigned with its | |
0963b4bd | 1706 | high-order bit on). It uses the fact that |
d8734c88 MS |
1707 | high_bound-low_bound is always representable in |
1708 | ULONGEST and that if high_bound-low_bound+1 overflows, | |
1709 | it overflows to 0. We must change these tests if we | |
1710 | decide to increase the representation of TYPE_LENGTH | |
0963b4bd | 1711 | from unsigned int to ULONGEST. */ |
d8734c88 MS |
1712 | ULONGEST ulow = low_bound, uhigh = high_bound; |
1713 | ULONGEST tlen = TYPE_LENGTH (target_type); | |
1714 | ||
1715 | len = tlen * (uhigh - ulow + 1); | |
1716 | if (tlen == 0 || (len / tlen - 1 + ulow) != uhigh | |
1717 | || len > UINT_MAX) | |
1718 | len = 0; | |
1719 | } | |
43bbcdc2 | 1720 | TYPE_LENGTH (type) = len; |
876cecd0 | 1721 | TYPE_TARGET_STUB (type) = 0; |
c906108c SS |
1722 | } |
1723 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) | |
1724 | { | |
1725 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); | |
876cecd0 | 1726 | TYPE_TARGET_STUB (type) = 0; |
c906108c SS |
1727 | } |
1728 | } | |
92163a10 JK |
1729 | |
1730 | type = make_qualified_type (type, instance_flags, NULL); | |
1731 | ||
7ba81444 | 1732 | /* Cache TYPE_LENGTH for future use. */ |
c906108c | 1733 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); |
92163a10 | 1734 | |
c906108c SS |
1735 | return type; |
1736 | } | |
1737 | ||
7ba81444 | 1738 | /* Parse a type expression in the string [P..P+LENGTH). If an error |
48319d1f | 1739 | occurs, silently return a void type. */ |
c91ecb25 | 1740 | |
b9362cc7 | 1741 | static struct type * |
48319d1f | 1742 | safe_parse_type (struct gdbarch *gdbarch, char *p, int length) |
c91ecb25 ND |
1743 | { |
1744 | struct ui_file *saved_gdb_stderr; | |
34365054 | 1745 | struct type *type = NULL; /* Initialize to keep gcc happy. */ |
8e7b59a5 | 1746 | volatile struct gdb_exception except; |
c91ecb25 | 1747 | |
7ba81444 | 1748 | /* Suppress error messages. */ |
c91ecb25 ND |
1749 | saved_gdb_stderr = gdb_stderr; |
1750 | gdb_stderr = ui_file_new (); | |
1751 | ||
7ba81444 | 1752 | /* Call parse_and_eval_type() without fear of longjmp()s. */ |
8e7b59a5 KS |
1753 | TRY_CATCH (except, RETURN_MASK_ERROR) |
1754 | { | |
1755 | type = parse_and_eval_type (p, length); | |
1756 | } | |
1757 | ||
1758 | if (except.reason < 0) | |
48319d1f | 1759 | type = builtin_type (gdbarch)->builtin_void; |
c91ecb25 | 1760 | |
7ba81444 | 1761 | /* Stop suppressing error messages. */ |
c91ecb25 ND |
1762 | ui_file_delete (gdb_stderr); |
1763 | gdb_stderr = saved_gdb_stderr; | |
1764 | ||
1765 | return type; | |
1766 | } | |
1767 | ||
c906108c SS |
1768 | /* Ugly hack to convert method stubs into method types. |
1769 | ||
7ba81444 MS |
1770 | He ain't kiddin'. This demangles the name of the method into a |
1771 | string including argument types, parses out each argument type, | |
1772 | generates a string casting a zero to that type, evaluates the | |
1773 | string, and stuffs the resulting type into an argtype vector!!! | |
1774 | Then it knows the type of the whole function (including argument | |
1775 | types for overloading), which info used to be in the stab's but was | |
1776 | removed to hack back the space required for them. */ | |
c906108c | 1777 | |
de17c821 | 1778 | static void |
fba45db2 | 1779 | check_stub_method (struct type *type, int method_id, int signature_id) |
c906108c | 1780 | { |
50810684 | 1781 | struct gdbarch *gdbarch = get_type_arch (type); |
c906108c SS |
1782 | struct fn_field *f; |
1783 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); | |
8de20a37 TT |
1784 | char *demangled_name = gdb_demangle (mangled_name, |
1785 | DMGL_PARAMS | DMGL_ANSI); | |
c906108c SS |
1786 | char *argtypetext, *p; |
1787 | int depth = 0, argcount = 1; | |
ad2f7632 | 1788 | struct field *argtypes; |
c906108c SS |
1789 | struct type *mtype; |
1790 | ||
1791 | /* Make sure we got back a function string that we can use. */ | |
1792 | if (demangled_name) | |
1793 | p = strchr (demangled_name, '('); | |
502dcf4e AC |
1794 | else |
1795 | p = NULL; | |
c906108c SS |
1796 | |
1797 | if (demangled_name == NULL || p == NULL) | |
7ba81444 MS |
1798 | error (_("Internal: Cannot demangle mangled name `%s'."), |
1799 | mangled_name); | |
c906108c SS |
1800 | |
1801 | /* Now, read in the parameters that define this type. */ | |
1802 | p += 1; | |
1803 | argtypetext = p; | |
1804 | while (*p) | |
1805 | { | |
070ad9f0 | 1806 | if (*p == '(' || *p == '<') |
c906108c SS |
1807 | { |
1808 | depth += 1; | |
1809 | } | |
070ad9f0 | 1810 | else if (*p == ')' || *p == '>') |
c906108c SS |
1811 | { |
1812 | depth -= 1; | |
1813 | } | |
1814 | else if (*p == ',' && depth == 0) | |
1815 | { | |
1816 | argcount += 1; | |
1817 | } | |
1818 | ||
1819 | p += 1; | |
1820 | } | |
1821 | ||
ad2f7632 DJ |
1822 | /* If we read one argument and it was ``void'', don't count it. */ |
1823 | if (strncmp (argtypetext, "(void)", 6) == 0) | |
1824 | argcount -= 1; | |
c906108c | 1825 | |
ad2f7632 DJ |
1826 | /* We need one extra slot, for the THIS pointer. */ |
1827 | ||
1828 | argtypes = (struct field *) | |
1829 | TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field)); | |
c906108c | 1830 | p = argtypetext; |
4a1970e4 DJ |
1831 | |
1832 | /* Add THIS pointer for non-static methods. */ | |
1833 | f = TYPE_FN_FIELDLIST1 (type, method_id); | |
1834 | if (TYPE_FN_FIELD_STATIC_P (f, signature_id)) | |
1835 | argcount = 0; | |
1836 | else | |
1837 | { | |
ad2f7632 | 1838 | argtypes[0].type = lookup_pointer_type (type); |
4a1970e4 DJ |
1839 | argcount = 1; |
1840 | } | |
c906108c | 1841 | |
0963b4bd | 1842 | if (*p != ')') /* () means no args, skip while. */ |
c906108c SS |
1843 | { |
1844 | depth = 0; | |
1845 | while (*p) | |
1846 | { | |
1847 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
1848 | { | |
ad2f7632 DJ |
1849 | /* Avoid parsing of ellipsis, they will be handled below. |
1850 | Also avoid ``void'' as above. */ | |
1851 | if (strncmp (argtypetext, "...", p - argtypetext) != 0 | |
1852 | && strncmp (argtypetext, "void", p - argtypetext) != 0) | |
c906108c | 1853 | { |
ad2f7632 | 1854 | argtypes[argcount].type = |
48319d1f | 1855 | safe_parse_type (gdbarch, argtypetext, p - argtypetext); |
c906108c SS |
1856 | argcount += 1; |
1857 | } | |
1858 | argtypetext = p + 1; | |
1859 | } | |
1860 | ||
070ad9f0 | 1861 | if (*p == '(' || *p == '<') |
c906108c SS |
1862 | { |
1863 | depth += 1; | |
1864 | } | |
070ad9f0 | 1865 | else if (*p == ')' || *p == '>') |
c906108c SS |
1866 | { |
1867 | depth -= 1; | |
1868 | } | |
1869 | ||
1870 | p += 1; | |
1871 | } | |
1872 | } | |
1873 | ||
c906108c SS |
1874 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; |
1875 | ||
1876 | /* Now update the old "stub" type into a real type. */ | |
1877 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); | |
1878 | TYPE_DOMAIN_TYPE (mtype) = type; | |
ad2f7632 DJ |
1879 | TYPE_FIELDS (mtype) = argtypes; |
1880 | TYPE_NFIELDS (mtype) = argcount; | |
876cecd0 | 1881 | TYPE_STUB (mtype) = 0; |
c906108c | 1882 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; |
ad2f7632 | 1883 | if (p[-2] == '.') |
876cecd0 | 1884 | TYPE_VARARGS (mtype) = 1; |
ad2f7632 DJ |
1885 | |
1886 | xfree (demangled_name); | |
c906108c SS |
1887 | } |
1888 | ||
7ba81444 MS |
1889 | /* This is the external interface to check_stub_method, above. This |
1890 | function unstubs all of the signatures for TYPE's METHOD_ID method | |
1891 | name. After calling this function TYPE_FN_FIELD_STUB will be | |
1892 | cleared for each signature and TYPE_FN_FIELDLIST_NAME will be | |
1893 | correct. | |
de17c821 DJ |
1894 | |
1895 | This function unfortunately can not die until stabs do. */ | |
1896 | ||
1897 | void | |
1898 | check_stub_method_group (struct type *type, int method_id) | |
1899 | { | |
1900 | int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id); | |
1901 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id); | |
f710f4fc | 1902 | int j, found_stub = 0; |
de17c821 DJ |
1903 | |
1904 | for (j = 0; j < len; j++) | |
1905 | if (TYPE_FN_FIELD_STUB (f, j)) | |
1906 | { | |
1907 | found_stub = 1; | |
1908 | check_stub_method (type, method_id, j); | |
1909 | } | |
1910 | ||
7ba81444 MS |
1911 | /* GNU v3 methods with incorrect names were corrected when we read |
1912 | in type information, because it was cheaper to do it then. The | |
1913 | only GNU v2 methods with incorrect method names are operators and | |
1914 | destructors; destructors were also corrected when we read in type | |
1915 | information. | |
de17c821 DJ |
1916 | |
1917 | Therefore the only thing we need to handle here are v2 operator | |
1918 | names. */ | |
1919 | if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0) | |
1920 | { | |
1921 | int ret; | |
1922 | char dem_opname[256]; | |
1923 | ||
7ba81444 MS |
1924 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, |
1925 | method_id), | |
de17c821 DJ |
1926 | dem_opname, DMGL_ANSI); |
1927 | if (!ret) | |
7ba81444 MS |
1928 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, |
1929 | method_id), | |
de17c821 DJ |
1930 | dem_opname, 0); |
1931 | if (ret) | |
1932 | TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname); | |
1933 | } | |
1934 | } | |
1935 | ||
9655fd1a JK |
1936 | /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */ |
1937 | const struct cplus_struct_type cplus_struct_default = { }; | |
c906108c SS |
1938 | |
1939 | void | |
fba45db2 | 1940 | allocate_cplus_struct_type (struct type *type) |
c906108c | 1941 | { |
b4ba55a1 JB |
1942 | if (HAVE_CPLUS_STRUCT (type)) |
1943 | /* Structure was already allocated. Nothing more to do. */ | |
1944 | return; | |
1945 | ||
1946 | TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF; | |
1947 | TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
1948 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); | |
1949 | *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default; | |
c906108c SS |
1950 | } |
1951 | ||
b4ba55a1 JB |
1952 | const struct gnat_aux_type gnat_aux_default = |
1953 | { NULL }; | |
1954 | ||
1955 | /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF, | |
1956 | and allocate the associated gnat-specific data. The gnat-specific | |
1957 | data is also initialized to gnat_aux_default. */ | |
5212577a | 1958 | |
b4ba55a1 JB |
1959 | void |
1960 | allocate_gnat_aux_type (struct type *type) | |
1961 | { | |
1962 | TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF; | |
1963 | TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *) | |
1964 | TYPE_ALLOC (type, sizeof (struct gnat_aux_type)); | |
1965 | *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default; | |
1966 | } | |
1967 | ||
c906108c SS |
1968 | /* Helper function to initialize the standard scalar types. |
1969 | ||
86f62fd7 TT |
1970 | If NAME is non-NULL, then it is used to initialize the type name. |
1971 | Note that NAME is not copied; it is required to have a lifetime at | |
1972 | least as long as OBJFILE. */ | |
c906108c SS |
1973 | |
1974 | struct type * | |
7ba81444 | 1975 | init_type (enum type_code code, int length, int flags, |
748e18ae | 1976 | const char *name, struct objfile *objfile) |
c906108c | 1977 | { |
52f0bd74 | 1978 | struct type *type; |
c906108c SS |
1979 | |
1980 | type = alloc_type (objfile); | |
1981 | TYPE_CODE (type) = code; | |
1982 | TYPE_LENGTH (type) = length; | |
876cecd0 TT |
1983 | |
1984 | gdb_assert (!(flags & (TYPE_FLAG_MIN - 1))); | |
1985 | if (flags & TYPE_FLAG_UNSIGNED) | |
1986 | TYPE_UNSIGNED (type) = 1; | |
1987 | if (flags & TYPE_FLAG_NOSIGN) | |
1988 | TYPE_NOSIGN (type) = 1; | |
1989 | if (flags & TYPE_FLAG_STUB) | |
1990 | TYPE_STUB (type) = 1; | |
1991 | if (flags & TYPE_FLAG_TARGET_STUB) | |
1992 | TYPE_TARGET_STUB (type) = 1; | |
1993 | if (flags & TYPE_FLAG_STATIC) | |
1994 | TYPE_STATIC (type) = 1; | |
1995 | if (flags & TYPE_FLAG_PROTOTYPED) | |
1996 | TYPE_PROTOTYPED (type) = 1; | |
1997 | if (flags & TYPE_FLAG_INCOMPLETE) | |
1998 | TYPE_INCOMPLETE (type) = 1; | |
1999 | if (flags & TYPE_FLAG_VARARGS) | |
2000 | TYPE_VARARGS (type) = 1; | |
2001 | if (flags & TYPE_FLAG_VECTOR) | |
2002 | TYPE_VECTOR (type) = 1; | |
2003 | if (flags & TYPE_FLAG_STUB_SUPPORTED) | |
2004 | TYPE_STUB_SUPPORTED (type) = 1; | |
876cecd0 TT |
2005 | if (flags & TYPE_FLAG_FIXED_INSTANCE) |
2006 | TYPE_FIXED_INSTANCE (type) = 1; | |
0875794a JK |
2007 | if (flags & TYPE_FLAG_GNU_IFUNC) |
2008 | TYPE_GNU_IFUNC (type) = 1; | |
876cecd0 | 2009 | |
86f62fd7 | 2010 | TYPE_NAME (type) = name; |
c906108c SS |
2011 | |
2012 | /* C++ fancies. */ | |
2013 | ||
973ccf8b | 2014 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 2015 | TYPE_NOSIGN (type) = 1; |
973ccf8b | 2016 | |
b4ba55a1 | 2017 | switch (code) |
c906108c | 2018 | { |
b4ba55a1 JB |
2019 | case TYPE_CODE_STRUCT: |
2020 | case TYPE_CODE_UNION: | |
2021 | case TYPE_CODE_NAMESPACE: | |
2022 | INIT_CPLUS_SPECIFIC (type); | |
2023 | break; | |
2024 | case TYPE_CODE_FLT: | |
2025 | TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT; | |
2026 | break; | |
2027 | case TYPE_CODE_FUNC: | |
b6cdc2c1 | 2028 | INIT_FUNC_SPECIFIC (type); |
b4ba55a1 | 2029 | break; |
c906108c | 2030 | } |
c16abbde | 2031 | return type; |
c906108c | 2032 | } |
5212577a DE |
2033 | \f |
2034 | /* Queries on types. */ | |
c906108c | 2035 | |
c906108c | 2036 | int |
fba45db2 | 2037 | can_dereference (struct type *t) |
c906108c | 2038 | { |
7ba81444 MS |
2039 | /* FIXME: Should we return true for references as well as |
2040 | pointers? */ | |
c906108c SS |
2041 | CHECK_TYPEDEF (t); |
2042 | return | |
2043 | (t != NULL | |
2044 | && TYPE_CODE (t) == TYPE_CODE_PTR | |
2045 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); | |
2046 | } | |
2047 | ||
adf40b2e | 2048 | int |
fba45db2 | 2049 | is_integral_type (struct type *t) |
adf40b2e JM |
2050 | { |
2051 | CHECK_TYPEDEF (t); | |
2052 | return | |
2053 | ((t != NULL) | |
d4f3574e SS |
2054 | && ((TYPE_CODE (t) == TYPE_CODE_INT) |
2055 | || (TYPE_CODE (t) == TYPE_CODE_ENUM) | |
4f2aea11 | 2056 | || (TYPE_CODE (t) == TYPE_CODE_FLAGS) |
d4f3574e SS |
2057 | || (TYPE_CODE (t) == TYPE_CODE_CHAR) |
2058 | || (TYPE_CODE (t) == TYPE_CODE_RANGE) | |
2059 | || (TYPE_CODE (t) == TYPE_CODE_BOOL))); | |
adf40b2e JM |
2060 | } |
2061 | ||
e09342b5 TJB |
2062 | /* Return true if TYPE is scalar. */ |
2063 | ||
2064 | static int | |
2065 | is_scalar_type (struct type *type) | |
2066 | { | |
2067 | CHECK_TYPEDEF (type); | |
2068 | ||
2069 | switch (TYPE_CODE (type)) | |
2070 | { | |
2071 | case TYPE_CODE_ARRAY: | |
2072 | case TYPE_CODE_STRUCT: | |
2073 | case TYPE_CODE_UNION: | |
2074 | case TYPE_CODE_SET: | |
2075 | case TYPE_CODE_STRING: | |
e09342b5 TJB |
2076 | return 0; |
2077 | default: | |
2078 | return 1; | |
2079 | } | |
2080 | } | |
2081 | ||
2082 | /* Return true if T is scalar, or a composite type which in practice has | |
90e4670f TJB |
2083 | the memory layout of a scalar type. E.g., an array or struct with only |
2084 | one scalar element inside it, or a union with only scalar elements. */ | |
e09342b5 TJB |
2085 | |
2086 | int | |
2087 | is_scalar_type_recursive (struct type *t) | |
2088 | { | |
2089 | CHECK_TYPEDEF (t); | |
2090 | ||
2091 | if (is_scalar_type (t)) | |
2092 | return 1; | |
2093 | /* Are we dealing with an array or string of known dimensions? */ | |
2094 | else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY | |
2095 | || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1 | |
2096 | && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE) | |
2097 | { | |
2098 | LONGEST low_bound, high_bound; | |
2099 | struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t)); | |
2100 | ||
2101 | get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound); | |
2102 | ||
2103 | return high_bound == low_bound && is_scalar_type_recursive (elt_type); | |
2104 | } | |
2105 | /* Are we dealing with a struct with one element? */ | |
2106 | else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1) | |
2107 | return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0)); | |
2108 | else if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
2109 | { | |
2110 | int i, n = TYPE_NFIELDS (t); | |
2111 | ||
2112 | /* If all elements of the union are scalar, then the union is scalar. */ | |
2113 | for (i = 0; i < n; i++) | |
2114 | if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i))) | |
2115 | return 0; | |
2116 | ||
2117 | return 1; | |
2118 | } | |
2119 | ||
2120 | return 0; | |
2121 | } | |
2122 | ||
4e8f195d TT |
2123 | /* A helper function which returns true if types A and B represent the |
2124 | "same" class type. This is true if the types have the same main | |
2125 | type, or the same name. */ | |
2126 | ||
2127 | int | |
2128 | class_types_same_p (const struct type *a, const struct type *b) | |
2129 | { | |
2130 | return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b) | |
2131 | || (TYPE_NAME (a) && TYPE_NAME (b) | |
2132 | && !strcmp (TYPE_NAME (a), TYPE_NAME (b)))); | |
2133 | } | |
2134 | ||
a9d5ef47 SW |
2135 | /* If BASE is an ancestor of DCLASS return the distance between them. |
2136 | otherwise return -1; | |
2137 | eg: | |
2138 | ||
2139 | class A {}; | |
2140 | class B: public A {}; | |
2141 | class C: public B {}; | |
2142 | class D: C {}; | |
2143 | ||
2144 | distance_to_ancestor (A, A, 0) = 0 | |
2145 | distance_to_ancestor (A, B, 0) = 1 | |
2146 | distance_to_ancestor (A, C, 0) = 2 | |
2147 | distance_to_ancestor (A, D, 0) = 3 | |
2148 | ||
2149 | If PUBLIC is 1 then only public ancestors are considered, | |
2150 | and the function returns the distance only if BASE is a public ancestor | |
2151 | of DCLASS. | |
2152 | Eg: | |
2153 | ||
0963b4bd | 2154 | distance_to_ancestor (A, D, 1) = -1. */ |
c906108c | 2155 | |
0526b37a | 2156 | static int |
a9d5ef47 | 2157 | distance_to_ancestor (struct type *base, struct type *dclass, int public) |
c906108c SS |
2158 | { |
2159 | int i; | |
a9d5ef47 | 2160 | int d; |
c5aa993b | 2161 | |
c906108c SS |
2162 | CHECK_TYPEDEF (base); |
2163 | CHECK_TYPEDEF (dclass); | |
2164 | ||
4e8f195d | 2165 | if (class_types_same_p (base, dclass)) |
a9d5ef47 | 2166 | return 0; |
c906108c SS |
2167 | |
2168 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
4e8f195d | 2169 | { |
0526b37a SW |
2170 | if (public && ! BASETYPE_VIA_PUBLIC (dclass, i)) |
2171 | continue; | |
2172 | ||
a9d5ef47 SW |
2173 | d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), public); |
2174 | if (d >= 0) | |
2175 | return 1 + d; | |
4e8f195d | 2176 | } |
c906108c | 2177 | |
a9d5ef47 | 2178 | return -1; |
c906108c | 2179 | } |
4e8f195d | 2180 | |
0526b37a SW |
2181 | /* Check whether BASE is an ancestor or base class or DCLASS |
2182 | Return 1 if so, and 0 if not. | |
2183 | Note: If BASE and DCLASS are of the same type, this function | |
2184 | will return 1. So for some class A, is_ancestor (A, A) will | |
2185 | return 1. */ | |
2186 | ||
2187 | int | |
2188 | is_ancestor (struct type *base, struct type *dclass) | |
2189 | { | |
a9d5ef47 | 2190 | return distance_to_ancestor (base, dclass, 0) >= 0; |
0526b37a SW |
2191 | } |
2192 | ||
4e8f195d TT |
2193 | /* Like is_ancestor, but only returns true when BASE is a public |
2194 | ancestor of DCLASS. */ | |
2195 | ||
2196 | int | |
2197 | is_public_ancestor (struct type *base, struct type *dclass) | |
2198 | { | |
a9d5ef47 | 2199 | return distance_to_ancestor (base, dclass, 1) >= 0; |
4e8f195d TT |
2200 | } |
2201 | ||
2202 | /* A helper function for is_unique_ancestor. */ | |
2203 | ||
2204 | static int | |
2205 | is_unique_ancestor_worker (struct type *base, struct type *dclass, | |
2206 | int *offset, | |
8af8e3bc PA |
2207 | const gdb_byte *valaddr, int embedded_offset, |
2208 | CORE_ADDR address, struct value *val) | |
4e8f195d TT |
2209 | { |
2210 | int i, count = 0; | |
2211 | ||
2212 | CHECK_TYPEDEF (base); | |
2213 | CHECK_TYPEDEF (dclass); | |
2214 | ||
2215 | for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i) | |
2216 | { | |
8af8e3bc PA |
2217 | struct type *iter; |
2218 | int this_offset; | |
4e8f195d | 2219 | |
8af8e3bc PA |
2220 | iter = check_typedef (TYPE_BASECLASS (dclass, i)); |
2221 | ||
2222 | this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset, | |
2223 | address, val); | |
4e8f195d TT |
2224 | |
2225 | if (class_types_same_p (base, iter)) | |
2226 | { | |
2227 | /* If this is the first subclass, set *OFFSET and set count | |
2228 | to 1. Otherwise, if this is at the same offset as | |
2229 | previous instances, do nothing. Otherwise, increment | |
2230 | count. */ | |
2231 | if (*offset == -1) | |
2232 | { | |
2233 | *offset = this_offset; | |
2234 | count = 1; | |
2235 | } | |
2236 | else if (this_offset == *offset) | |
2237 | { | |
2238 | /* Nothing. */ | |
2239 | } | |
2240 | else | |
2241 | ++count; | |
2242 | } | |
2243 | else | |
2244 | count += is_unique_ancestor_worker (base, iter, offset, | |
8af8e3bc PA |
2245 | valaddr, |
2246 | embedded_offset + this_offset, | |
2247 | address, val); | |
4e8f195d TT |
2248 | } |
2249 | ||
2250 | return count; | |
2251 | } | |
2252 | ||
2253 | /* Like is_ancestor, but only returns true if BASE is a unique base | |
2254 | class of the type of VAL. */ | |
2255 | ||
2256 | int | |
2257 | is_unique_ancestor (struct type *base, struct value *val) | |
2258 | { | |
2259 | int offset = -1; | |
2260 | ||
2261 | return is_unique_ancestor_worker (base, value_type (val), &offset, | |
8af8e3bc PA |
2262 | value_contents_for_printing (val), |
2263 | value_embedded_offset (val), | |
2264 | value_address (val), val) == 1; | |
4e8f195d TT |
2265 | } |
2266 | ||
c906108c | 2267 | \f |
5212577a | 2268 | /* Overload resolution. */ |
c906108c | 2269 | |
6403aeea SW |
2270 | /* Return the sum of the rank of A with the rank of B. */ |
2271 | ||
2272 | struct rank | |
2273 | sum_ranks (struct rank a, struct rank b) | |
2274 | { | |
2275 | struct rank c; | |
2276 | c.rank = a.rank + b.rank; | |
a9d5ef47 | 2277 | c.subrank = a.subrank + b.subrank; |
6403aeea SW |
2278 | return c; |
2279 | } | |
2280 | ||
2281 | /* Compare rank A and B and return: | |
2282 | 0 if a = b | |
2283 | 1 if a is better than b | |
2284 | -1 if b is better than a. */ | |
2285 | ||
2286 | int | |
2287 | compare_ranks (struct rank a, struct rank b) | |
2288 | { | |
2289 | if (a.rank == b.rank) | |
a9d5ef47 SW |
2290 | { |
2291 | if (a.subrank == b.subrank) | |
2292 | return 0; | |
2293 | if (a.subrank < b.subrank) | |
2294 | return 1; | |
2295 | if (a.subrank > b.subrank) | |
2296 | return -1; | |
2297 | } | |
6403aeea SW |
2298 | |
2299 | if (a.rank < b.rank) | |
2300 | return 1; | |
2301 | ||
0963b4bd | 2302 | /* a.rank > b.rank */ |
6403aeea SW |
2303 | return -1; |
2304 | } | |
c5aa993b | 2305 | |
0963b4bd | 2306 | /* Functions for overload resolution begin here. */ |
c906108c SS |
2307 | |
2308 | /* Compare two badness vectors A and B and return the result. | |
7ba81444 MS |
2309 | 0 => A and B are identical |
2310 | 1 => A and B are incomparable | |
2311 | 2 => A is better than B | |
2312 | 3 => A is worse than B */ | |
c906108c SS |
2313 | |
2314 | int | |
fba45db2 | 2315 | compare_badness (struct badness_vector *a, struct badness_vector *b) |
c906108c SS |
2316 | { |
2317 | int i; | |
2318 | int tmp; | |
c5aa993b JM |
2319 | short found_pos = 0; /* any positives in c? */ |
2320 | short found_neg = 0; /* any negatives in c? */ | |
2321 | ||
2322 | /* differing lengths => incomparable */ | |
c906108c SS |
2323 | if (a->length != b->length) |
2324 | return 1; | |
2325 | ||
c5aa993b JM |
2326 | /* Subtract b from a */ |
2327 | for (i = 0; i < a->length; i++) | |
c906108c | 2328 | { |
6403aeea | 2329 | tmp = compare_ranks (b->rank[i], a->rank[i]); |
c906108c | 2330 | if (tmp > 0) |
c5aa993b | 2331 | found_pos = 1; |
c906108c | 2332 | else if (tmp < 0) |
c5aa993b | 2333 | found_neg = 1; |
c906108c SS |
2334 | } |
2335 | ||
2336 | if (found_pos) | |
2337 | { | |
2338 | if (found_neg) | |
c5aa993b | 2339 | return 1; /* incomparable */ |
c906108c | 2340 | else |
c5aa993b | 2341 | return 3; /* A > B */ |
c906108c | 2342 | } |
c5aa993b JM |
2343 | else |
2344 | /* no positives */ | |
c906108c SS |
2345 | { |
2346 | if (found_neg) | |
c5aa993b | 2347 | return 2; /* A < B */ |
c906108c | 2348 | else |
c5aa993b | 2349 | return 0; /* A == B */ |
c906108c SS |
2350 | } |
2351 | } | |
2352 | ||
7ba81444 MS |
2353 | /* Rank a function by comparing its parameter types (PARMS, length |
2354 | NPARMS), to the types of an argument list (ARGS, length NARGS). | |
2355 | Return a pointer to a badness vector. This has NARGS + 1 | |
2356 | entries. */ | |
c906108c SS |
2357 | |
2358 | struct badness_vector * | |
7ba81444 | 2359 | rank_function (struct type **parms, int nparms, |
da096638 | 2360 | struct value **args, int nargs) |
c906108c SS |
2361 | { |
2362 | int i; | |
c5aa993b | 2363 | struct badness_vector *bv; |
c906108c SS |
2364 | int min_len = nparms < nargs ? nparms : nargs; |
2365 | ||
2366 | bv = xmalloc (sizeof (struct badness_vector)); | |
0963b4bd | 2367 | bv->length = nargs + 1; /* add 1 for the length-match rank. */ |
c906108c SS |
2368 | bv->rank = xmalloc ((nargs + 1) * sizeof (int)); |
2369 | ||
2370 | /* First compare the lengths of the supplied lists. | |
7ba81444 | 2371 | If there is a mismatch, set it to a high value. */ |
c5aa993b | 2372 | |
c906108c | 2373 | /* pai/1997-06-03 FIXME: when we have debug info about default |
7ba81444 MS |
2374 | arguments and ellipsis parameter lists, we should consider those |
2375 | and rank the length-match more finely. */ | |
c906108c | 2376 | |
6403aeea SW |
2377 | LENGTH_MATCH (bv) = (nargs != nparms) |
2378 | ? LENGTH_MISMATCH_BADNESS | |
2379 | : EXACT_MATCH_BADNESS; | |
c906108c | 2380 | |
0963b4bd | 2381 | /* Now rank all the parameters of the candidate function. */ |
74cc24b0 | 2382 | for (i = 1; i <= min_len; i++) |
da096638 KS |
2383 | bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]), |
2384 | args[i - 1]); | |
c906108c | 2385 | |
0963b4bd | 2386 | /* If more arguments than parameters, add dummy entries. */ |
c5aa993b | 2387 | for (i = min_len + 1; i <= nargs; i++) |
c906108c SS |
2388 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
2389 | ||
2390 | return bv; | |
2391 | } | |
2392 | ||
973ccf8b DJ |
2393 | /* Compare the names of two integer types, assuming that any sign |
2394 | qualifiers have been checked already. We do it this way because | |
2395 | there may be an "int" in the name of one of the types. */ | |
2396 | ||
2397 | static int | |
2398 | integer_types_same_name_p (const char *first, const char *second) | |
2399 | { | |
2400 | int first_p, second_p; | |
2401 | ||
7ba81444 MS |
2402 | /* If both are shorts, return 1; if neither is a short, keep |
2403 | checking. */ | |
973ccf8b DJ |
2404 | first_p = (strstr (first, "short") != NULL); |
2405 | second_p = (strstr (second, "short") != NULL); | |
2406 | if (first_p && second_p) | |
2407 | return 1; | |
2408 | if (first_p || second_p) | |
2409 | return 0; | |
2410 | ||
2411 | /* Likewise for long. */ | |
2412 | first_p = (strstr (first, "long") != NULL); | |
2413 | second_p = (strstr (second, "long") != NULL); | |
2414 | if (first_p && second_p) | |
2415 | return 1; | |
2416 | if (first_p || second_p) | |
2417 | return 0; | |
2418 | ||
2419 | /* Likewise for char. */ | |
2420 | first_p = (strstr (first, "char") != NULL); | |
2421 | second_p = (strstr (second, "char") != NULL); | |
2422 | if (first_p && second_p) | |
2423 | return 1; | |
2424 | if (first_p || second_p) | |
2425 | return 0; | |
2426 | ||
2427 | /* They must both be ints. */ | |
2428 | return 1; | |
2429 | } | |
2430 | ||
7062b0a0 SW |
2431 | /* Compares type A to type B returns 1 if the represent the same type |
2432 | 0 otherwise. */ | |
2433 | ||
bd69fc68 | 2434 | int |
7062b0a0 SW |
2435 | types_equal (struct type *a, struct type *b) |
2436 | { | |
2437 | /* Identical type pointers. */ | |
2438 | /* However, this still doesn't catch all cases of same type for b | |
2439 | and a. The reason is that builtin types are different from | |
2440 | the same ones constructed from the object. */ | |
2441 | if (a == b) | |
2442 | return 1; | |
2443 | ||
2444 | /* Resolve typedefs */ | |
2445 | if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF) | |
2446 | a = check_typedef (a); | |
2447 | if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF) | |
2448 | b = check_typedef (b); | |
2449 | ||
2450 | /* If after resolving typedefs a and b are not of the same type | |
2451 | code then they are not equal. */ | |
2452 | if (TYPE_CODE (a) != TYPE_CODE (b)) | |
2453 | return 0; | |
2454 | ||
2455 | /* If a and b are both pointers types or both reference types then | |
2456 | they are equal of the same type iff the objects they refer to are | |
2457 | of the same type. */ | |
2458 | if (TYPE_CODE (a) == TYPE_CODE_PTR | |
2459 | || TYPE_CODE (a) == TYPE_CODE_REF) | |
2460 | return types_equal (TYPE_TARGET_TYPE (a), | |
2461 | TYPE_TARGET_TYPE (b)); | |
2462 | ||
0963b4bd | 2463 | /* Well, damnit, if the names are exactly the same, I'll say they |
7062b0a0 SW |
2464 | are exactly the same. This happens when we generate method |
2465 | stubs. The types won't point to the same address, but they | |
0963b4bd | 2466 | really are the same. */ |
7062b0a0 SW |
2467 | |
2468 | if (TYPE_NAME (a) && TYPE_NAME (b) | |
2469 | && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0) | |
2470 | return 1; | |
2471 | ||
2472 | /* Check if identical after resolving typedefs. */ | |
2473 | if (a == b) | |
2474 | return 1; | |
2475 | ||
9ce98649 TT |
2476 | /* Two function types are equal if their argument and return types |
2477 | are equal. */ | |
2478 | if (TYPE_CODE (a) == TYPE_CODE_FUNC) | |
2479 | { | |
2480 | int i; | |
2481 | ||
2482 | if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b)) | |
2483 | return 0; | |
2484 | ||
2485 | if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b))) | |
2486 | return 0; | |
2487 | ||
2488 | for (i = 0; i < TYPE_NFIELDS (a); ++i) | |
2489 | if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i))) | |
2490 | return 0; | |
2491 | ||
2492 | return 1; | |
2493 | } | |
2494 | ||
7062b0a0 SW |
2495 | return 0; |
2496 | } | |
2497 | ||
c906108c SS |
2498 | /* Compare one type (PARM) for compatibility with another (ARG). |
2499 | * PARM is intended to be the parameter type of a function; and | |
2500 | * ARG is the supplied argument's type. This function tests if | |
2501 | * the latter can be converted to the former. | |
da096638 | 2502 | * VALUE is the argument's value or NULL if none (or called recursively) |
c906108c SS |
2503 | * |
2504 | * Return 0 if they are identical types; | |
2505 | * Otherwise, return an integer which corresponds to how compatible | |
7ba81444 MS |
2506 | * PARM is to ARG. The higher the return value, the worse the match. |
2507 | * Generally the "bad" conversions are all uniformly assigned a 100. */ | |
c906108c | 2508 | |
6403aeea | 2509 | struct rank |
da096638 | 2510 | rank_one_type (struct type *parm, struct type *arg, struct value *value) |
c906108c | 2511 | { |
a9d5ef47 | 2512 | struct rank rank = {0,0}; |
7062b0a0 SW |
2513 | |
2514 | if (types_equal (parm, arg)) | |
6403aeea | 2515 | return EXACT_MATCH_BADNESS; |
c906108c SS |
2516 | |
2517 | /* Resolve typedefs */ | |
2518 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) | |
2519 | parm = check_typedef (parm); | |
2520 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) | |
2521 | arg = check_typedef (arg); | |
2522 | ||
db577aea | 2523 | /* See through references, since we can almost make non-references |
7ba81444 | 2524 | references. */ |
db577aea | 2525 | if (TYPE_CODE (arg) == TYPE_CODE_REF) |
da096638 | 2526 | return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL), |
6403aeea | 2527 | REFERENCE_CONVERSION_BADNESS)); |
db577aea | 2528 | if (TYPE_CODE (parm) == TYPE_CODE_REF) |
da096638 | 2529 | return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL), |
6403aeea | 2530 | REFERENCE_CONVERSION_BADNESS)); |
5d161b24 | 2531 | if (overload_debug) |
7ba81444 MS |
2532 | /* Debugging only. */ |
2533 | fprintf_filtered (gdb_stderr, | |
2534 | "------ Arg is %s [%d], parm is %s [%d]\n", | |
2535 | TYPE_NAME (arg), TYPE_CODE (arg), | |
2536 | TYPE_NAME (parm), TYPE_CODE (parm)); | |
c906108c | 2537 | |
0963b4bd | 2538 | /* x -> y means arg of type x being supplied for parameter of type y. */ |
c906108c SS |
2539 | |
2540 | switch (TYPE_CODE (parm)) | |
2541 | { | |
c5aa993b JM |
2542 | case TYPE_CODE_PTR: |
2543 | switch (TYPE_CODE (arg)) | |
2544 | { | |
2545 | case TYPE_CODE_PTR: | |
7062b0a0 SW |
2546 | |
2547 | /* Allowed pointer conversions are: | |
2548 | (a) pointer to void-pointer conversion. */ | |
2549 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) | |
c5aa993b | 2550 | return VOID_PTR_CONVERSION_BADNESS; |
7062b0a0 SW |
2551 | |
2552 | /* (b) pointer to ancestor-pointer conversion. */ | |
a9d5ef47 SW |
2553 | rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm), |
2554 | TYPE_TARGET_TYPE (arg), | |
2555 | 0); | |
2556 | if (rank.subrank >= 0) | |
2557 | return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank); | |
7062b0a0 SW |
2558 | |
2559 | return INCOMPATIBLE_TYPE_BADNESS; | |
c5aa993b | 2560 | case TYPE_CODE_ARRAY: |
7062b0a0 SW |
2561 | if (types_equal (TYPE_TARGET_TYPE (parm), |
2562 | TYPE_TARGET_TYPE (arg))) | |
6403aeea | 2563 | return EXACT_MATCH_BADNESS; |
7062b0a0 | 2564 | return INCOMPATIBLE_TYPE_BADNESS; |
c5aa993b | 2565 | case TYPE_CODE_FUNC: |
da096638 | 2566 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL); |
c5aa993b | 2567 | case TYPE_CODE_INT: |
a451cb65 | 2568 | if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT) |
da096638 | 2569 | { |
a451cb65 KS |
2570 | if (value_as_long (value) == 0) |
2571 | { | |
2572 | /* Null pointer conversion: allow it to be cast to a pointer. | |
2573 | [4.10.1 of C++ standard draft n3290] */ | |
2574 | return NULL_POINTER_CONVERSION_BADNESS; | |
2575 | } | |
2576 | else | |
2577 | { | |
2578 | /* If type checking is disabled, allow the conversion. */ | |
2579 | if (!strict_type_checking) | |
2580 | return NS_INTEGER_POINTER_CONVERSION_BADNESS; | |
2581 | } | |
da096638 KS |
2582 | } |
2583 | /* fall through */ | |
c5aa993b | 2584 | case TYPE_CODE_ENUM: |
4f2aea11 | 2585 | case TYPE_CODE_FLAGS: |
c5aa993b JM |
2586 | case TYPE_CODE_CHAR: |
2587 | case TYPE_CODE_RANGE: | |
2588 | case TYPE_CODE_BOOL: | |
c5aa993b JM |
2589 | default: |
2590 | return INCOMPATIBLE_TYPE_BADNESS; | |
2591 | } | |
2592 | case TYPE_CODE_ARRAY: | |
2593 | switch (TYPE_CODE (arg)) | |
2594 | { | |
2595 | case TYPE_CODE_PTR: | |
2596 | case TYPE_CODE_ARRAY: | |
7ba81444 | 2597 | return rank_one_type (TYPE_TARGET_TYPE (parm), |
da096638 | 2598 | TYPE_TARGET_TYPE (arg), NULL); |
c5aa993b JM |
2599 | default: |
2600 | return INCOMPATIBLE_TYPE_BADNESS; | |
2601 | } | |
2602 | case TYPE_CODE_FUNC: | |
2603 | switch (TYPE_CODE (arg)) | |
2604 | { | |
2605 | case TYPE_CODE_PTR: /* funcptr -> func */ | |
da096638 | 2606 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL); |
c5aa993b JM |
2607 | default: |
2608 | return INCOMPATIBLE_TYPE_BADNESS; | |
2609 | } | |
2610 | case TYPE_CODE_INT: | |
2611 | switch (TYPE_CODE (arg)) | |
2612 | { | |
2613 | case TYPE_CODE_INT: | |
2614 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2615 | { | |
2616 | /* Deal with signed, unsigned, and plain chars and | |
7ba81444 | 2617 | signed and unsigned ints. */ |
c5aa993b JM |
2618 | if (TYPE_NOSIGN (parm)) |
2619 | { | |
0963b4bd | 2620 | /* This case only for character types. */ |
7ba81444 | 2621 | if (TYPE_NOSIGN (arg)) |
6403aeea | 2622 | return EXACT_MATCH_BADNESS; /* plain char -> plain char */ |
7ba81444 MS |
2623 | else /* signed/unsigned char -> plain char */ |
2624 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b JM |
2625 | } |
2626 | else if (TYPE_UNSIGNED (parm)) | |
2627 | { | |
2628 | if (TYPE_UNSIGNED (arg)) | |
2629 | { | |
7ba81444 MS |
2630 | /* unsigned int -> unsigned int, or |
2631 | unsigned long -> unsigned long */ | |
2632 | if (integer_types_same_name_p (TYPE_NAME (parm), | |
2633 | TYPE_NAME (arg))) | |
6403aeea | 2634 | return EXACT_MATCH_BADNESS; |
7ba81444 MS |
2635 | else if (integer_types_same_name_p (TYPE_NAME (arg), |
2636 | "int") | |
2637 | && integer_types_same_name_p (TYPE_NAME (parm), | |
2638 | "long")) | |
3e43a32a MS |
2639 | /* unsigned int -> unsigned long */ |
2640 | return INTEGER_PROMOTION_BADNESS; | |
c5aa993b | 2641 | else |
3e43a32a MS |
2642 | /* unsigned long -> unsigned int */ |
2643 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b JM |
2644 | } |
2645 | else | |
2646 | { | |
7ba81444 MS |
2647 | if (integer_types_same_name_p (TYPE_NAME (arg), |
2648 | "long") | |
2649 | && integer_types_same_name_p (TYPE_NAME (parm), | |
2650 | "int")) | |
3e43a32a MS |
2651 | /* signed long -> unsigned int */ |
2652 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b | 2653 | else |
3e43a32a MS |
2654 | /* signed int/long -> unsigned int/long */ |
2655 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b JM |
2656 | } |
2657 | } | |
2658 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2659 | { | |
7ba81444 MS |
2660 | if (integer_types_same_name_p (TYPE_NAME (parm), |
2661 | TYPE_NAME (arg))) | |
6403aeea | 2662 | return EXACT_MATCH_BADNESS; |
7ba81444 MS |
2663 | else if (integer_types_same_name_p (TYPE_NAME (arg), |
2664 | "int") | |
2665 | && integer_types_same_name_p (TYPE_NAME (parm), | |
2666 | "long")) | |
c5aa993b JM |
2667 | return INTEGER_PROMOTION_BADNESS; |
2668 | else | |
1c5cb38e | 2669 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2670 | } |
2671 | else | |
1c5cb38e | 2672 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2673 | } |
2674 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2675 | return INTEGER_PROMOTION_BADNESS; | |
2676 | else | |
1c5cb38e | 2677 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b | 2678 | case TYPE_CODE_ENUM: |
4f2aea11 | 2679 | case TYPE_CODE_FLAGS: |
c5aa993b JM |
2680 | case TYPE_CODE_CHAR: |
2681 | case TYPE_CODE_RANGE: | |
2682 | case TYPE_CODE_BOOL: | |
2683 | return INTEGER_PROMOTION_BADNESS; | |
2684 | case TYPE_CODE_FLT: | |
2685 | return INT_FLOAT_CONVERSION_BADNESS; | |
2686 | case TYPE_CODE_PTR: | |
2687 | return NS_POINTER_CONVERSION_BADNESS; | |
2688 | default: | |
2689 | return INCOMPATIBLE_TYPE_BADNESS; | |
2690 | } | |
2691 | break; | |
2692 | case TYPE_CODE_ENUM: | |
2693 | switch (TYPE_CODE (arg)) | |
2694 | { | |
2695 | case TYPE_CODE_INT: | |
2696 | case TYPE_CODE_CHAR: | |
2697 | case TYPE_CODE_RANGE: | |
2698 | case TYPE_CODE_BOOL: | |
2699 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2700 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2701 | case TYPE_CODE_FLT: |
2702 | return INT_FLOAT_CONVERSION_BADNESS; | |
2703 | default: | |
2704 | return INCOMPATIBLE_TYPE_BADNESS; | |
2705 | } | |
2706 | break; | |
2707 | case TYPE_CODE_CHAR: | |
2708 | switch (TYPE_CODE (arg)) | |
2709 | { | |
2710 | case TYPE_CODE_RANGE: | |
2711 | case TYPE_CODE_BOOL: | |
2712 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2713 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2714 | case TYPE_CODE_FLT: |
2715 | return INT_FLOAT_CONVERSION_BADNESS; | |
2716 | case TYPE_CODE_INT: | |
2717 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) | |
1c5cb38e | 2718 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2719 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
2720 | return INTEGER_PROMOTION_BADNESS; | |
2721 | /* >>> !! else fall through !! <<< */ | |
2722 | case TYPE_CODE_CHAR: | |
7ba81444 MS |
2723 | /* Deal with signed, unsigned, and plain chars for C++ and |
2724 | with int cases falling through from previous case. */ | |
c5aa993b JM |
2725 | if (TYPE_NOSIGN (parm)) |
2726 | { | |
2727 | if (TYPE_NOSIGN (arg)) | |
6403aeea | 2728 | return EXACT_MATCH_BADNESS; |
c5aa993b | 2729 | else |
1c5cb38e | 2730 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2731 | } |
2732 | else if (TYPE_UNSIGNED (parm)) | |
2733 | { | |
2734 | if (TYPE_UNSIGNED (arg)) | |
6403aeea | 2735 | return EXACT_MATCH_BADNESS; |
c5aa993b JM |
2736 | else |
2737 | return INTEGER_PROMOTION_BADNESS; | |
2738 | } | |
2739 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
6403aeea | 2740 | return EXACT_MATCH_BADNESS; |
c5aa993b | 2741 | else |
1c5cb38e | 2742 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2743 | default: |
2744 | return INCOMPATIBLE_TYPE_BADNESS; | |
2745 | } | |
2746 | break; | |
2747 | case TYPE_CODE_RANGE: | |
2748 | switch (TYPE_CODE (arg)) | |
2749 | { | |
2750 | case TYPE_CODE_INT: | |
2751 | case TYPE_CODE_CHAR: | |
2752 | case TYPE_CODE_RANGE: | |
2753 | case TYPE_CODE_BOOL: | |
2754 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2755 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2756 | case TYPE_CODE_FLT: |
2757 | return INT_FLOAT_CONVERSION_BADNESS; | |
2758 | default: | |
2759 | return INCOMPATIBLE_TYPE_BADNESS; | |
2760 | } | |
2761 | break; | |
2762 | case TYPE_CODE_BOOL: | |
2763 | switch (TYPE_CODE (arg)) | |
2764 | { | |
5b4f6e25 KS |
2765 | /* n3290 draft, section 4.12.1 (conv.bool): |
2766 | ||
2767 | "A prvalue of arithmetic, unscoped enumeration, pointer, or | |
2768 | pointer to member type can be converted to a prvalue of type | |
2769 | bool. A zero value, null pointer value, or null member pointer | |
2770 | value is converted to false; any other value is converted to | |
2771 | true. A prvalue of type std::nullptr_t can be converted to a | |
2772 | prvalue of type bool; the resulting value is false." */ | |
c5aa993b JM |
2773 | case TYPE_CODE_INT: |
2774 | case TYPE_CODE_CHAR: | |
c5aa993b JM |
2775 | case TYPE_CODE_ENUM: |
2776 | case TYPE_CODE_FLT: | |
5b4f6e25 | 2777 | case TYPE_CODE_MEMBERPTR: |
c5aa993b | 2778 | case TYPE_CODE_PTR: |
5b4f6e25 KS |
2779 | return BOOL_CONVERSION_BADNESS; |
2780 | case TYPE_CODE_RANGE: | |
2781 | return INCOMPATIBLE_TYPE_BADNESS; | |
c5aa993b | 2782 | case TYPE_CODE_BOOL: |
6403aeea | 2783 | return EXACT_MATCH_BADNESS; |
c5aa993b JM |
2784 | default: |
2785 | return INCOMPATIBLE_TYPE_BADNESS; | |
2786 | } | |
2787 | break; | |
2788 | case TYPE_CODE_FLT: | |
2789 | switch (TYPE_CODE (arg)) | |
2790 | { | |
2791 | case TYPE_CODE_FLT: | |
2792 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2793 | return FLOAT_PROMOTION_BADNESS; | |
2794 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
6403aeea | 2795 | return EXACT_MATCH_BADNESS; |
c5aa993b JM |
2796 | else |
2797 | return FLOAT_CONVERSION_BADNESS; | |
2798 | case TYPE_CODE_INT: | |
2799 | case TYPE_CODE_BOOL: | |
2800 | case TYPE_CODE_ENUM: | |
2801 | case TYPE_CODE_RANGE: | |
2802 | case TYPE_CODE_CHAR: | |
2803 | return INT_FLOAT_CONVERSION_BADNESS; | |
2804 | default: | |
2805 | return INCOMPATIBLE_TYPE_BADNESS; | |
2806 | } | |
2807 | break; | |
2808 | case TYPE_CODE_COMPLEX: | |
2809 | switch (TYPE_CODE (arg)) | |
7ba81444 | 2810 | { /* Strictly not needed for C++, but... */ |
c5aa993b JM |
2811 | case TYPE_CODE_FLT: |
2812 | return FLOAT_PROMOTION_BADNESS; | |
2813 | case TYPE_CODE_COMPLEX: | |
6403aeea | 2814 | return EXACT_MATCH_BADNESS; |
c5aa993b JM |
2815 | default: |
2816 | return INCOMPATIBLE_TYPE_BADNESS; | |
2817 | } | |
2818 | break; | |
2819 | case TYPE_CODE_STRUCT: | |
0963b4bd | 2820 | /* currently same as TYPE_CODE_CLASS. */ |
c5aa993b JM |
2821 | switch (TYPE_CODE (arg)) |
2822 | { | |
2823 | case TYPE_CODE_STRUCT: | |
2824 | /* Check for derivation */ | |
a9d5ef47 SW |
2825 | rank.subrank = distance_to_ancestor (parm, arg, 0); |
2826 | if (rank.subrank >= 0) | |
2827 | return sum_ranks (BASE_CONVERSION_BADNESS, rank); | |
c5aa993b JM |
2828 | /* else fall through */ |
2829 | default: | |
2830 | return INCOMPATIBLE_TYPE_BADNESS; | |
2831 | } | |
2832 | break; | |
2833 | case TYPE_CODE_UNION: | |
2834 | switch (TYPE_CODE (arg)) | |
2835 | { | |
2836 | case TYPE_CODE_UNION: | |
2837 | default: | |
2838 | return INCOMPATIBLE_TYPE_BADNESS; | |
2839 | } | |
2840 | break; | |
0d5de010 | 2841 | case TYPE_CODE_MEMBERPTR: |
c5aa993b JM |
2842 | switch (TYPE_CODE (arg)) |
2843 | { | |
2844 | default: | |
2845 | return INCOMPATIBLE_TYPE_BADNESS; | |
2846 | } | |
2847 | break; | |
2848 | case TYPE_CODE_METHOD: | |
2849 | switch (TYPE_CODE (arg)) | |
2850 | { | |
2851 | ||
2852 | default: | |
2853 | return INCOMPATIBLE_TYPE_BADNESS; | |
2854 | } | |
2855 | break; | |
2856 | case TYPE_CODE_REF: | |
2857 | switch (TYPE_CODE (arg)) | |
2858 | { | |
2859 | ||
2860 | default: | |
2861 | return INCOMPATIBLE_TYPE_BADNESS; | |
2862 | } | |
2863 | ||
2864 | break; | |
2865 | case TYPE_CODE_SET: | |
2866 | switch (TYPE_CODE (arg)) | |
2867 | { | |
2868 | /* Not in C++ */ | |
2869 | case TYPE_CODE_SET: | |
7ba81444 | 2870 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), |
da096638 | 2871 | TYPE_FIELD_TYPE (arg, 0), NULL); |
c5aa993b JM |
2872 | default: |
2873 | return INCOMPATIBLE_TYPE_BADNESS; | |
2874 | } | |
2875 | break; | |
2876 | case TYPE_CODE_VOID: | |
2877 | default: | |
2878 | return INCOMPATIBLE_TYPE_BADNESS; | |
2879 | } /* switch (TYPE_CODE (arg)) */ | |
c906108c SS |
2880 | } |
2881 | ||
0963b4bd | 2882 | /* End of functions for overload resolution. */ |
5212577a DE |
2883 | \f |
2884 | /* Routines to pretty-print types. */ | |
c906108c | 2885 | |
c906108c | 2886 | static void |
fba45db2 | 2887 | print_bit_vector (B_TYPE *bits, int nbits) |
c906108c SS |
2888 | { |
2889 | int bitno; | |
2890 | ||
2891 | for (bitno = 0; bitno < nbits; bitno++) | |
2892 | { | |
2893 | if ((bitno % 8) == 0) | |
2894 | { | |
2895 | puts_filtered (" "); | |
2896 | } | |
2897 | if (B_TST (bits, bitno)) | |
a3f17187 | 2898 | printf_filtered (("1")); |
c906108c | 2899 | else |
a3f17187 | 2900 | printf_filtered (("0")); |
c906108c SS |
2901 | } |
2902 | } | |
2903 | ||
ad2f7632 | 2904 | /* Note the first arg should be the "this" pointer, we may not want to |
7ba81444 MS |
2905 | include it since we may get into a infinitely recursive |
2906 | situation. */ | |
c906108c SS |
2907 | |
2908 | static void | |
ad2f7632 | 2909 | print_arg_types (struct field *args, int nargs, int spaces) |
c906108c SS |
2910 | { |
2911 | if (args != NULL) | |
2912 | { | |
ad2f7632 DJ |
2913 | int i; |
2914 | ||
2915 | for (i = 0; i < nargs; i++) | |
2916 | recursive_dump_type (args[i].type, spaces + 2); | |
c906108c SS |
2917 | } |
2918 | } | |
2919 | ||
d6a843b5 JK |
2920 | int |
2921 | field_is_static (struct field *f) | |
2922 | { | |
2923 | /* "static" fields are the fields whose location is not relative | |
2924 | to the address of the enclosing struct. It would be nice to | |
2925 | have a dedicated flag that would be set for static fields when | |
2926 | the type is being created. But in practice, checking the field | |
254e6b9e | 2927 | loc_kind should give us an accurate answer. */ |
d6a843b5 JK |
2928 | return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME |
2929 | || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR); | |
2930 | } | |
2931 | ||
c906108c | 2932 | static void |
fba45db2 | 2933 | dump_fn_fieldlists (struct type *type, int spaces) |
c906108c SS |
2934 | { |
2935 | int method_idx; | |
2936 | int overload_idx; | |
2937 | struct fn_field *f; | |
2938 | ||
2939 | printfi_filtered (spaces, "fn_fieldlists "); | |
d4f3574e | 2940 | gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
c906108c SS |
2941 | printf_filtered ("\n"); |
2942 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) | |
2943 | { | |
2944 | f = TYPE_FN_FIELDLIST1 (type, method_idx); | |
2945 | printfi_filtered (spaces + 2, "[%d] name '%s' (", | |
2946 | method_idx, | |
2947 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); | |
d4f3574e SS |
2948 | gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
2949 | gdb_stdout); | |
a3f17187 | 2950 | printf_filtered (_(") length %d\n"), |
c906108c SS |
2951 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); |
2952 | for (overload_idx = 0; | |
2953 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); | |
2954 | overload_idx++) | |
2955 | { | |
2956 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", | |
2957 | overload_idx, | |
2958 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); | |
d4f3574e SS |
2959 | gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
2960 | gdb_stdout); | |
c906108c SS |
2961 | printf_filtered (")\n"); |
2962 | printfi_filtered (spaces + 8, "type "); | |
7ba81444 MS |
2963 | gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), |
2964 | gdb_stdout); | |
c906108c SS |
2965 | printf_filtered ("\n"); |
2966 | ||
2967 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), | |
2968 | spaces + 8 + 2); | |
2969 | ||
2970 | printfi_filtered (spaces + 8, "args "); | |
7ba81444 MS |
2971 | gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), |
2972 | gdb_stdout); | |
c906108c SS |
2973 | printf_filtered ("\n"); |
2974 | ||
ad2f7632 | 2975 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), |
7ba81444 MS |
2976 | TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, |
2977 | overload_idx)), | |
ad2f7632 | 2978 | spaces); |
c906108c | 2979 | printfi_filtered (spaces + 8, "fcontext "); |
d4f3574e SS |
2980 | gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
2981 | gdb_stdout); | |
c906108c SS |
2982 | printf_filtered ("\n"); |
2983 | ||
2984 | printfi_filtered (spaces + 8, "is_const %d\n", | |
2985 | TYPE_FN_FIELD_CONST (f, overload_idx)); | |
2986 | printfi_filtered (spaces + 8, "is_volatile %d\n", | |
2987 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); | |
2988 | printfi_filtered (spaces + 8, "is_private %d\n", | |
2989 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); | |
2990 | printfi_filtered (spaces + 8, "is_protected %d\n", | |
2991 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); | |
2992 | printfi_filtered (spaces + 8, "is_stub %d\n", | |
2993 | TYPE_FN_FIELD_STUB (f, overload_idx)); | |
2994 | printfi_filtered (spaces + 8, "voffset %u\n", | |
2995 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); | |
2996 | } | |
2997 | } | |
2998 | } | |
2999 | ||
3000 | static void | |
fba45db2 | 3001 | print_cplus_stuff (struct type *type, int spaces) |
c906108c SS |
3002 | { |
3003 | printfi_filtered (spaces, "n_baseclasses %d\n", | |
3004 | TYPE_N_BASECLASSES (type)); | |
3005 | printfi_filtered (spaces, "nfn_fields %d\n", | |
3006 | TYPE_NFN_FIELDS (type)); | |
c906108c SS |
3007 | if (TYPE_N_BASECLASSES (type) > 0) |
3008 | { | |
3009 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", | |
3010 | TYPE_N_BASECLASSES (type)); | |
7ba81444 MS |
3011 | gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), |
3012 | gdb_stdout); | |
c906108c SS |
3013 | printf_filtered (")"); |
3014 | ||
3015 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), | |
3016 | TYPE_N_BASECLASSES (type)); | |
3017 | puts_filtered ("\n"); | |
3018 | } | |
3019 | if (TYPE_NFIELDS (type) > 0) | |
3020 | { | |
3021 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) | |
3022 | { | |
7ba81444 MS |
3023 | printfi_filtered (spaces, |
3024 | "private_field_bits (%d bits at *", | |
c906108c | 3025 | TYPE_NFIELDS (type)); |
7ba81444 MS |
3026 | gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), |
3027 | gdb_stdout); | |
c906108c SS |
3028 | printf_filtered (")"); |
3029 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), | |
3030 | TYPE_NFIELDS (type)); | |
3031 | puts_filtered ("\n"); | |
3032 | } | |
3033 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) | |
3034 | { | |
7ba81444 MS |
3035 | printfi_filtered (spaces, |
3036 | "protected_field_bits (%d bits at *", | |
c906108c | 3037 | TYPE_NFIELDS (type)); |
7ba81444 MS |
3038 | gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), |
3039 | gdb_stdout); | |
c906108c SS |
3040 | printf_filtered (")"); |
3041 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), | |
3042 | TYPE_NFIELDS (type)); | |
3043 | puts_filtered ("\n"); | |
3044 | } | |
3045 | } | |
3046 | if (TYPE_NFN_FIELDS (type) > 0) | |
3047 | { | |
3048 | dump_fn_fieldlists (type, spaces); | |
3049 | } | |
3050 | } | |
3051 | ||
b4ba55a1 JB |
3052 | /* Print the contents of the TYPE's type_specific union, assuming that |
3053 | its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */ | |
3054 | ||
3055 | static void | |
3056 | print_gnat_stuff (struct type *type, int spaces) | |
3057 | { | |
3058 | struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type); | |
3059 | ||
3060 | recursive_dump_type (descriptive_type, spaces + 2); | |
3061 | } | |
3062 | ||
c906108c SS |
3063 | static struct obstack dont_print_type_obstack; |
3064 | ||
3065 | void | |
fba45db2 | 3066 | recursive_dump_type (struct type *type, int spaces) |
c906108c SS |
3067 | { |
3068 | int idx; | |
3069 | ||
3070 | if (spaces == 0) | |
3071 | obstack_begin (&dont_print_type_obstack, 0); | |
3072 | ||
3073 | if (TYPE_NFIELDS (type) > 0 | |
b4ba55a1 | 3074 | || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0)) |
c906108c SS |
3075 | { |
3076 | struct type **first_dont_print | |
7ba81444 | 3077 | = (struct type **) obstack_base (&dont_print_type_obstack); |
c906108c | 3078 | |
7ba81444 MS |
3079 | int i = (struct type **) |
3080 | obstack_next_free (&dont_print_type_obstack) - first_dont_print; | |
c906108c SS |
3081 | |
3082 | while (--i >= 0) | |
3083 | { | |
3084 | if (type == first_dont_print[i]) | |
3085 | { | |
3086 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 3087 | gdb_print_host_address (type, gdb_stdout); |
a3f17187 | 3088 | printf_filtered (_(" <same as already seen type>\n")); |
c906108c SS |
3089 | return; |
3090 | } | |
3091 | } | |
3092 | ||
3093 | obstack_ptr_grow (&dont_print_type_obstack, type); | |
3094 | } | |
3095 | ||
3096 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 3097 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
3098 | printf_filtered ("\n"); |
3099 | printfi_filtered (spaces, "name '%s' (", | |
3100 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); | |
d4f3574e | 3101 | gdb_print_host_address (TYPE_NAME (type), gdb_stdout); |
c906108c | 3102 | printf_filtered (")\n"); |
e9e79dd9 FF |
3103 | printfi_filtered (spaces, "tagname '%s' (", |
3104 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>"); | |
3105 | gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout); | |
3106 | printf_filtered (")\n"); | |
c906108c SS |
3107 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); |
3108 | switch (TYPE_CODE (type)) | |
3109 | { | |
c5aa993b JM |
3110 | case TYPE_CODE_UNDEF: |
3111 | printf_filtered ("(TYPE_CODE_UNDEF)"); | |
3112 | break; | |
3113 | case TYPE_CODE_PTR: | |
3114 | printf_filtered ("(TYPE_CODE_PTR)"); | |
3115 | break; | |
3116 | case TYPE_CODE_ARRAY: | |
3117 | printf_filtered ("(TYPE_CODE_ARRAY)"); | |
3118 | break; | |
3119 | case TYPE_CODE_STRUCT: | |
3120 | printf_filtered ("(TYPE_CODE_STRUCT)"); | |
3121 | break; | |
3122 | case TYPE_CODE_UNION: | |
3123 | printf_filtered ("(TYPE_CODE_UNION)"); | |
3124 | break; | |
3125 | case TYPE_CODE_ENUM: | |
3126 | printf_filtered ("(TYPE_CODE_ENUM)"); | |
3127 | break; | |
4f2aea11 MK |
3128 | case TYPE_CODE_FLAGS: |
3129 | printf_filtered ("(TYPE_CODE_FLAGS)"); | |
3130 | break; | |
c5aa993b JM |
3131 | case TYPE_CODE_FUNC: |
3132 | printf_filtered ("(TYPE_CODE_FUNC)"); | |
3133 | break; | |
3134 | case TYPE_CODE_INT: | |
3135 | printf_filtered ("(TYPE_CODE_INT)"); | |
3136 | break; | |
3137 | case TYPE_CODE_FLT: | |
3138 | printf_filtered ("(TYPE_CODE_FLT)"); | |
3139 | break; | |
3140 | case TYPE_CODE_VOID: | |
3141 | printf_filtered ("(TYPE_CODE_VOID)"); | |
3142 | break; | |
3143 | case TYPE_CODE_SET: | |
3144 | printf_filtered ("(TYPE_CODE_SET)"); | |
3145 | break; | |
3146 | case TYPE_CODE_RANGE: | |
3147 | printf_filtered ("(TYPE_CODE_RANGE)"); | |
3148 | break; | |
3149 | case TYPE_CODE_STRING: | |
3150 | printf_filtered ("(TYPE_CODE_STRING)"); | |
3151 | break; | |
3152 | case TYPE_CODE_ERROR: | |
3153 | printf_filtered ("(TYPE_CODE_ERROR)"); | |
3154 | break; | |
0d5de010 DJ |
3155 | case TYPE_CODE_MEMBERPTR: |
3156 | printf_filtered ("(TYPE_CODE_MEMBERPTR)"); | |
3157 | break; | |
3158 | case TYPE_CODE_METHODPTR: | |
3159 | printf_filtered ("(TYPE_CODE_METHODPTR)"); | |
c5aa993b JM |
3160 | break; |
3161 | case TYPE_CODE_METHOD: | |
3162 | printf_filtered ("(TYPE_CODE_METHOD)"); | |
3163 | break; | |
3164 | case TYPE_CODE_REF: | |
3165 | printf_filtered ("(TYPE_CODE_REF)"); | |
3166 | break; | |
3167 | case TYPE_CODE_CHAR: | |
3168 | printf_filtered ("(TYPE_CODE_CHAR)"); | |
3169 | break; | |
3170 | case TYPE_CODE_BOOL: | |
3171 | printf_filtered ("(TYPE_CODE_BOOL)"); | |
3172 | break; | |
e9e79dd9 FF |
3173 | case TYPE_CODE_COMPLEX: |
3174 | printf_filtered ("(TYPE_CODE_COMPLEX)"); | |
3175 | break; | |
c5aa993b JM |
3176 | case TYPE_CODE_TYPEDEF: |
3177 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); | |
3178 | break; | |
5c4e30ca DC |
3179 | case TYPE_CODE_NAMESPACE: |
3180 | printf_filtered ("(TYPE_CODE_NAMESPACE)"); | |
3181 | break; | |
c5aa993b JM |
3182 | default: |
3183 | printf_filtered ("(UNKNOWN TYPE CODE)"); | |
3184 | break; | |
c906108c SS |
3185 | } |
3186 | puts_filtered ("\n"); | |
3187 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); | |
e9bb382b UW |
3188 | if (TYPE_OBJFILE_OWNED (type)) |
3189 | { | |
3190 | printfi_filtered (spaces, "objfile "); | |
3191 | gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout); | |
3192 | } | |
3193 | else | |
3194 | { | |
3195 | printfi_filtered (spaces, "gdbarch "); | |
3196 | gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout); | |
3197 | } | |
c906108c SS |
3198 | printf_filtered ("\n"); |
3199 | printfi_filtered (spaces, "target_type "); | |
d4f3574e | 3200 | gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
c906108c SS |
3201 | printf_filtered ("\n"); |
3202 | if (TYPE_TARGET_TYPE (type) != NULL) | |
3203 | { | |
3204 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); | |
3205 | } | |
3206 | printfi_filtered (spaces, "pointer_type "); | |
d4f3574e | 3207 | gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
c906108c SS |
3208 | printf_filtered ("\n"); |
3209 | printfi_filtered (spaces, "reference_type "); | |
d4f3574e | 3210 | gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
c906108c | 3211 | printf_filtered ("\n"); |
2fdde8f8 DJ |
3212 | printfi_filtered (spaces, "type_chain "); |
3213 | gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout); | |
e9e79dd9 | 3214 | printf_filtered ("\n"); |
7ba81444 MS |
3215 | printfi_filtered (spaces, "instance_flags 0x%x", |
3216 | TYPE_INSTANCE_FLAGS (type)); | |
2fdde8f8 DJ |
3217 | if (TYPE_CONST (type)) |
3218 | { | |
3219 | puts_filtered (" TYPE_FLAG_CONST"); | |
3220 | } | |
3221 | if (TYPE_VOLATILE (type)) | |
3222 | { | |
3223 | puts_filtered (" TYPE_FLAG_VOLATILE"); | |
3224 | } | |
3225 | if (TYPE_CODE_SPACE (type)) | |
3226 | { | |
3227 | puts_filtered (" TYPE_FLAG_CODE_SPACE"); | |
3228 | } | |
3229 | if (TYPE_DATA_SPACE (type)) | |
3230 | { | |
3231 | puts_filtered (" TYPE_FLAG_DATA_SPACE"); | |
3232 | } | |
8b2dbe47 KB |
3233 | if (TYPE_ADDRESS_CLASS_1 (type)) |
3234 | { | |
3235 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1"); | |
3236 | } | |
3237 | if (TYPE_ADDRESS_CLASS_2 (type)) | |
3238 | { | |
3239 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2"); | |
3240 | } | |
06d66ee9 TT |
3241 | if (TYPE_RESTRICT (type)) |
3242 | { | |
3243 | puts_filtered (" TYPE_FLAG_RESTRICT"); | |
3244 | } | |
2fdde8f8 | 3245 | puts_filtered ("\n"); |
876cecd0 TT |
3246 | |
3247 | printfi_filtered (spaces, "flags"); | |
762a036f | 3248 | if (TYPE_UNSIGNED (type)) |
c906108c SS |
3249 | { |
3250 | puts_filtered (" TYPE_FLAG_UNSIGNED"); | |
3251 | } | |
762a036f FF |
3252 | if (TYPE_NOSIGN (type)) |
3253 | { | |
3254 | puts_filtered (" TYPE_FLAG_NOSIGN"); | |
3255 | } | |
3256 | if (TYPE_STUB (type)) | |
c906108c SS |
3257 | { |
3258 | puts_filtered (" TYPE_FLAG_STUB"); | |
3259 | } | |
762a036f FF |
3260 | if (TYPE_TARGET_STUB (type)) |
3261 | { | |
3262 | puts_filtered (" TYPE_FLAG_TARGET_STUB"); | |
3263 | } | |
3264 | if (TYPE_STATIC (type)) | |
3265 | { | |
3266 | puts_filtered (" TYPE_FLAG_STATIC"); | |
3267 | } | |
762a036f FF |
3268 | if (TYPE_PROTOTYPED (type)) |
3269 | { | |
3270 | puts_filtered (" TYPE_FLAG_PROTOTYPED"); | |
3271 | } | |
3272 | if (TYPE_INCOMPLETE (type)) | |
3273 | { | |
3274 | puts_filtered (" TYPE_FLAG_INCOMPLETE"); | |
3275 | } | |
762a036f FF |
3276 | if (TYPE_VARARGS (type)) |
3277 | { | |
3278 | puts_filtered (" TYPE_FLAG_VARARGS"); | |
3279 | } | |
f5f8a009 EZ |
3280 | /* This is used for things like AltiVec registers on ppc. Gcc emits |
3281 | an attribute for the array type, which tells whether or not we | |
3282 | have a vector, instead of a regular array. */ | |
3283 | if (TYPE_VECTOR (type)) | |
3284 | { | |
3285 | puts_filtered (" TYPE_FLAG_VECTOR"); | |
3286 | } | |
876cecd0 TT |
3287 | if (TYPE_FIXED_INSTANCE (type)) |
3288 | { | |
3289 | puts_filtered (" TYPE_FIXED_INSTANCE"); | |
3290 | } | |
3291 | if (TYPE_STUB_SUPPORTED (type)) | |
3292 | { | |
3293 | puts_filtered (" TYPE_STUB_SUPPORTED"); | |
3294 | } | |
3295 | if (TYPE_NOTTEXT (type)) | |
3296 | { | |
3297 | puts_filtered (" TYPE_NOTTEXT"); | |
3298 | } | |
c906108c SS |
3299 | puts_filtered ("\n"); |
3300 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); | |
d4f3574e | 3301 | gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout); |
c906108c SS |
3302 | puts_filtered ("\n"); |
3303 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) | |
3304 | { | |
14e75d8e JK |
3305 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) |
3306 | printfi_filtered (spaces + 2, | |
3307 | "[%d] enumval %s type ", | |
3308 | idx, plongest (TYPE_FIELD_ENUMVAL (type, idx))); | |
3309 | else | |
3310 | printfi_filtered (spaces + 2, | |
3311 | "[%d] bitpos %d bitsize %d type ", | |
3312 | idx, TYPE_FIELD_BITPOS (type, idx), | |
3313 | TYPE_FIELD_BITSIZE (type, idx)); | |
d4f3574e | 3314 | gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
c906108c SS |
3315 | printf_filtered (" name '%s' (", |
3316 | TYPE_FIELD_NAME (type, idx) != NULL | |
3317 | ? TYPE_FIELD_NAME (type, idx) | |
3318 | : "<NULL>"); | |
d4f3574e | 3319 | gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
c906108c SS |
3320 | printf_filtered (")\n"); |
3321 | if (TYPE_FIELD_TYPE (type, idx) != NULL) | |
3322 | { | |
3323 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); | |
3324 | } | |
3325 | } | |
43bbcdc2 PH |
3326 | if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
3327 | { | |
3328 | printfi_filtered (spaces, "low %s%s high %s%s\n", | |
3329 | plongest (TYPE_LOW_BOUND (type)), | |
3330 | TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "", | |
3331 | plongest (TYPE_HIGH_BOUND (type)), | |
3e43a32a MS |
3332 | TYPE_HIGH_BOUND_UNDEFINED (type) |
3333 | ? " (undefined)" : ""); | |
43bbcdc2 | 3334 | } |
c906108c | 3335 | printfi_filtered (spaces, "vptr_basetype "); |
d4f3574e | 3336 | gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); |
c906108c SS |
3337 | puts_filtered ("\n"); |
3338 | if (TYPE_VPTR_BASETYPE (type) != NULL) | |
3339 | { | |
3340 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); | |
3341 | } | |
7ba81444 MS |
3342 | printfi_filtered (spaces, "vptr_fieldno %d\n", |
3343 | TYPE_VPTR_FIELDNO (type)); | |
c906108c | 3344 | |
b4ba55a1 JB |
3345 | switch (TYPE_SPECIFIC_FIELD (type)) |
3346 | { | |
3347 | case TYPE_SPECIFIC_CPLUS_STUFF: | |
3348 | printfi_filtered (spaces, "cplus_stuff "); | |
3349 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), | |
3350 | gdb_stdout); | |
3351 | puts_filtered ("\n"); | |
3352 | print_cplus_stuff (type, spaces); | |
3353 | break; | |
8da61cc4 | 3354 | |
b4ba55a1 JB |
3355 | case TYPE_SPECIFIC_GNAT_STUFF: |
3356 | printfi_filtered (spaces, "gnat_stuff "); | |
3357 | gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout); | |
3358 | puts_filtered ("\n"); | |
3359 | print_gnat_stuff (type, spaces); | |
3360 | break; | |
701c159d | 3361 | |
b4ba55a1 JB |
3362 | case TYPE_SPECIFIC_FLOATFORMAT: |
3363 | printfi_filtered (spaces, "floatformat "); | |
3364 | if (TYPE_FLOATFORMAT (type) == NULL) | |
3365 | puts_filtered ("(null)"); | |
3366 | else | |
3367 | { | |
3368 | puts_filtered ("{ "); | |
3369 | if (TYPE_FLOATFORMAT (type)[0] == NULL | |
3370 | || TYPE_FLOATFORMAT (type)[0]->name == NULL) | |
3371 | puts_filtered ("(null)"); | |
3372 | else | |
3373 | puts_filtered (TYPE_FLOATFORMAT (type)[0]->name); | |
3374 | ||
3375 | puts_filtered (", "); | |
3376 | if (TYPE_FLOATFORMAT (type)[1] == NULL | |
3377 | || TYPE_FLOATFORMAT (type)[1]->name == NULL) | |
3378 | puts_filtered ("(null)"); | |
3379 | else | |
3380 | puts_filtered (TYPE_FLOATFORMAT (type)[1]->name); | |
3381 | ||
3382 | puts_filtered (" }"); | |
3383 | } | |
3384 | puts_filtered ("\n"); | |
3385 | break; | |
c906108c | 3386 | |
b6cdc2c1 | 3387 | case TYPE_SPECIFIC_FUNC: |
b4ba55a1 JB |
3388 | printfi_filtered (spaces, "calling_convention %d\n", |
3389 | TYPE_CALLING_CONVENTION (type)); | |
b6cdc2c1 | 3390 | /* tail_call_list is not printed. */ |
b4ba55a1 | 3391 | break; |
c906108c | 3392 | } |
b4ba55a1 | 3393 | |
c906108c SS |
3394 | if (spaces == 0) |
3395 | obstack_free (&dont_print_type_obstack, NULL); | |
3396 | } | |
5212577a | 3397 | \f |
ae5a43e0 DJ |
3398 | /* Trivial helpers for the libiberty hash table, for mapping one |
3399 | type to another. */ | |
3400 | ||
3401 | struct type_pair | |
3402 | { | |
3403 | struct type *old, *new; | |
3404 | }; | |
3405 | ||
3406 | static hashval_t | |
3407 | type_pair_hash (const void *item) | |
3408 | { | |
3409 | const struct type_pair *pair = item; | |
d8734c88 | 3410 | |
ae5a43e0 DJ |
3411 | return htab_hash_pointer (pair->old); |
3412 | } | |
3413 | ||
3414 | static int | |
3415 | type_pair_eq (const void *item_lhs, const void *item_rhs) | |
3416 | { | |
3417 | const struct type_pair *lhs = item_lhs, *rhs = item_rhs; | |
d8734c88 | 3418 | |
ae5a43e0 DJ |
3419 | return lhs->old == rhs->old; |
3420 | } | |
3421 | ||
3422 | /* Allocate the hash table used by copy_type_recursive to walk | |
3423 | types without duplicates. We use OBJFILE's obstack, because | |
3424 | OBJFILE is about to be deleted. */ | |
3425 | ||
3426 | htab_t | |
3427 | create_copied_types_hash (struct objfile *objfile) | |
3428 | { | |
3429 | return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq, | |
3430 | NULL, &objfile->objfile_obstack, | |
3431 | hashtab_obstack_allocate, | |
3432 | dummy_obstack_deallocate); | |
3433 | } | |
3434 | ||
7ba81444 MS |
3435 | /* Recursively copy (deep copy) TYPE, if it is associated with |
3436 | OBJFILE. Return a new type allocated using malloc, a saved type if | |
3437 | we have already visited TYPE (using COPIED_TYPES), or TYPE if it is | |
3438 | not associated with OBJFILE. */ | |
ae5a43e0 DJ |
3439 | |
3440 | struct type * | |
7ba81444 MS |
3441 | copy_type_recursive (struct objfile *objfile, |
3442 | struct type *type, | |
ae5a43e0 DJ |
3443 | htab_t copied_types) |
3444 | { | |
3445 | struct type_pair *stored, pair; | |
3446 | void **slot; | |
3447 | struct type *new_type; | |
3448 | ||
e9bb382b | 3449 | if (! TYPE_OBJFILE_OWNED (type)) |
ae5a43e0 DJ |
3450 | return type; |
3451 | ||
7ba81444 MS |
3452 | /* This type shouldn't be pointing to any types in other objfiles; |
3453 | if it did, the type might disappear unexpectedly. */ | |
ae5a43e0 DJ |
3454 | gdb_assert (TYPE_OBJFILE (type) == objfile); |
3455 | ||
3456 | pair.old = type; | |
3457 | slot = htab_find_slot (copied_types, &pair, INSERT); | |
3458 | if (*slot != NULL) | |
3459 | return ((struct type_pair *) *slot)->new; | |
3460 | ||
e9bb382b | 3461 | new_type = alloc_type_arch (get_type_arch (type)); |
ae5a43e0 DJ |
3462 | |
3463 | /* We must add the new type to the hash table immediately, in case | |
3464 | we encounter this type again during a recursive call below. */ | |
3e43a32a MS |
3465 | stored |
3466 | = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair)); | |
ae5a43e0 DJ |
3467 | stored->old = type; |
3468 | stored->new = new_type; | |
3469 | *slot = stored; | |
3470 | ||
876cecd0 TT |
3471 | /* Copy the common fields of types. For the main type, we simply |
3472 | copy the entire thing and then update specific fields as needed. */ | |
3473 | *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type); | |
e9bb382b UW |
3474 | TYPE_OBJFILE_OWNED (new_type) = 0; |
3475 | TYPE_OWNER (new_type).gdbarch = get_type_arch (type); | |
876cecd0 | 3476 | |
ae5a43e0 DJ |
3477 | if (TYPE_NAME (type)) |
3478 | TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type)); | |
3479 | if (TYPE_TAG_NAME (type)) | |
3480 | TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type)); | |
ae5a43e0 DJ |
3481 | |
3482 | TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type); | |
3483 | TYPE_LENGTH (new_type) = TYPE_LENGTH (type); | |
3484 | ||
3485 | /* Copy the fields. */ | |
ae5a43e0 DJ |
3486 | if (TYPE_NFIELDS (type)) |
3487 | { | |
3488 | int i, nfields; | |
3489 | ||
3490 | nfields = TYPE_NFIELDS (type); | |
1deafd4e | 3491 | TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field); |
ae5a43e0 DJ |
3492 | for (i = 0; i < nfields; i++) |
3493 | { | |
7ba81444 MS |
3494 | TYPE_FIELD_ARTIFICIAL (new_type, i) = |
3495 | TYPE_FIELD_ARTIFICIAL (type, i); | |
ae5a43e0 DJ |
3496 | TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i); |
3497 | if (TYPE_FIELD_TYPE (type, i)) | |
3498 | TYPE_FIELD_TYPE (new_type, i) | |
3499 | = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i), | |
3500 | copied_types); | |
3501 | if (TYPE_FIELD_NAME (type, i)) | |
7ba81444 MS |
3502 | TYPE_FIELD_NAME (new_type, i) = |
3503 | xstrdup (TYPE_FIELD_NAME (type, i)); | |
d6a843b5 | 3504 | switch (TYPE_FIELD_LOC_KIND (type, i)) |
ae5a43e0 | 3505 | { |
d6a843b5 JK |
3506 | case FIELD_LOC_KIND_BITPOS: |
3507 | SET_FIELD_BITPOS (TYPE_FIELD (new_type, i), | |
3508 | TYPE_FIELD_BITPOS (type, i)); | |
3509 | break; | |
14e75d8e JK |
3510 | case FIELD_LOC_KIND_ENUMVAL: |
3511 | SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i), | |
3512 | TYPE_FIELD_ENUMVAL (type, i)); | |
3513 | break; | |
d6a843b5 JK |
3514 | case FIELD_LOC_KIND_PHYSADDR: |
3515 | SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i), | |
3516 | TYPE_FIELD_STATIC_PHYSADDR (type, i)); | |
3517 | break; | |
3518 | case FIELD_LOC_KIND_PHYSNAME: | |
3519 | SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i), | |
3520 | xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type, | |
3521 | i))); | |
3522 | break; | |
3523 | default: | |
3524 | internal_error (__FILE__, __LINE__, | |
3525 | _("Unexpected type field location kind: %d"), | |
3526 | TYPE_FIELD_LOC_KIND (type, i)); | |
ae5a43e0 DJ |
3527 | } |
3528 | } | |
3529 | } | |
3530 | ||
0963b4bd | 3531 | /* For range types, copy the bounds information. */ |
43bbcdc2 PH |
3532 | if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
3533 | { | |
3534 | TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds)); | |
3535 | *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type); | |
3536 | } | |
3537 | ||
ae5a43e0 DJ |
3538 | /* Copy pointers to other types. */ |
3539 | if (TYPE_TARGET_TYPE (type)) | |
7ba81444 MS |
3540 | TYPE_TARGET_TYPE (new_type) = |
3541 | copy_type_recursive (objfile, | |
3542 | TYPE_TARGET_TYPE (type), | |
3543 | copied_types); | |
ae5a43e0 | 3544 | if (TYPE_VPTR_BASETYPE (type)) |
7ba81444 MS |
3545 | TYPE_VPTR_BASETYPE (new_type) = |
3546 | copy_type_recursive (objfile, | |
3547 | TYPE_VPTR_BASETYPE (type), | |
3548 | copied_types); | |
ae5a43e0 DJ |
3549 | /* Maybe copy the type_specific bits. |
3550 | ||
3551 | NOTE drow/2005-12-09: We do not copy the C++-specific bits like | |
3552 | base classes and methods. There's no fundamental reason why we | |
3553 | can't, but at the moment it is not needed. */ | |
3554 | ||
3555 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
d5d6fca5 | 3556 | TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type); |
ae5a43e0 DJ |
3557 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
3558 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
ae5a43e0 DJ |
3559 | || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) |
3560 | INIT_CPLUS_SPECIFIC (new_type); | |
3561 | ||
3562 | return new_type; | |
3563 | } | |
3564 | ||
4af88198 JB |
3565 | /* Make a copy of the given TYPE, except that the pointer & reference |
3566 | types are not preserved. | |
3567 | ||
3568 | This function assumes that the given type has an associated objfile. | |
3569 | This objfile is used to allocate the new type. */ | |
3570 | ||
3571 | struct type * | |
3572 | copy_type (const struct type *type) | |
3573 | { | |
3574 | struct type *new_type; | |
3575 | ||
e9bb382b | 3576 | gdb_assert (TYPE_OBJFILE_OWNED (type)); |
4af88198 | 3577 | |
e9bb382b | 3578 | new_type = alloc_type_copy (type); |
4af88198 JB |
3579 | TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type); |
3580 | TYPE_LENGTH (new_type) = TYPE_LENGTH (type); | |
3581 | memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type), | |
3582 | sizeof (struct main_type)); | |
3583 | ||
3584 | return new_type; | |
3585 | } | |
5212577a | 3586 | \f |
e9bb382b UW |
3587 | /* Helper functions to initialize architecture-specific types. */ |
3588 | ||
3589 | /* Allocate a type structure associated with GDBARCH and set its | |
3590 | CODE, LENGTH, and NAME fields. */ | |
5212577a | 3591 | |
e9bb382b UW |
3592 | struct type * |
3593 | arch_type (struct gdbarch *gdbarch, | |
3594 | enum type_code code, int length, char *name) | |
3595 | { | |
3596 | struct type *type; | |
3597 | ||
3598 | type = alloc_type_arch (gdbarch); | |
3599 | TYPE_CODE (type) = code; | |
3600 | TYPE_LENGTH (type) = length; | |
3601 | ||
3602 | if (name) | |
3603 | TYPE_NAME (type) = xstrdup (name); | |
3604 | ||
3605 | return type; | |
3606 | } | |
3607 | ||
3608 | /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH. | |
3609 | BIT is the type size in bits. If UNSIGNED_P is non-zero, set | |
3610 | the type's TYPE_UNSIGNED flag. NAME is the type name. */ | |
5212577a | 3611 | |
e9bb382b UW |
3612 | struct type * |
3613 | arch_integer_type (struct gdbarch *gdbarch, | |
3614 | int bit, int unsigned_p, char *name) | |
3615 | { | |
3616 | struct type *t; | |
3617 | ||
3618 | t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name); | |
3619 | if (unsigned_p) | |
3620 | TYPE_UNSIGNED (t) = 1; | |
3621 | if (name && strcmp (name, "char") == 0) | |
3622 | TYPE_NOSIGN (t) = 1; | |
3623 | ||
3624 | return t; | |
3625 | } | |
3626 | ||
3627 | /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH. | |
3628 | BIT is the type size in bits. If UNSIGNED_P is non-zero, set | |
3629 | the type's TYPE_UNSIGNED flag. NAME is the type name. */ | |
5212577a | 3630 | |
e9bb382b UW |
3631 | struct type * |
3632 | arch_character_type (struct gdbarch *gdbarch, | |
3633 | int bit, int unsigned_p, char *name) | |
3634 | { | |
3635 | struct type *t; | |
3636 | ||
3637 | t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name); | |
3638 | if (unsigned_p) | |
3639 | TYPE_UNSIGNED (t) = 1; | |
3640 | ||
3641 | return t; | |
3642 | } | |
3643 | ||
3644 | /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH. | |
3645 | BIT is the type size in bits. If UNSIGNED_P is non-zero, set | |
3646 | the type's TYPE_UNSIGNED flag. NAME is the type name. */ | |
5212577a | 3647 | |
e9bb382b UW |
3648 | struct type * |
3649 | arch_boolean_type (struct gdbarch *gdbarch, | |
3650 | int bit, int unsigned_p, char *name) | |
3651 | { | |
3652 | struct type *t; | |
3653 | ||
3654 | t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name); | |
3655 | if (unsigned_p) | |
3656 | TYPE_UNSIGNED (t) = 1; | |
3657 | ||
3658 | return t; | |
3659 | } | |
3660 | ||
3661 | /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH. | |
3662 | BIT is the type size in bits; if BIT equals -1, the size is | |
3663 | determined by the floatformat. NAME is the type name. Set the | |
3664 | TYPE_FLOATFORMAT from FLOATFORMATS. */ | |
5212577a | 3665 | |
27067745 | 3666 | struct type * |
e9bb382b UW |
3667 | arch_float_type (struct gdbarch *gdbarch, |
3668 | int bit, char *name, const struct floatformat **floatformats) | |
8da61cc4 DJ |
3669 | { |
3670 | struct type *t; | |
3671 | ||
3672 | if (bit == -1) | |
3673 | { | |
3674 | gdb_assert (floatformats != NULL); | |
3675 | gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL); | |
3676 | bit = floatformats[0]->totalsize; | |
3677 | } | |
3678 | gdb_assert (bit >= 0); | |
3679 | ||
e9bb382b | 3680 | t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name); |
8da61cc4 DJ |
3681 | TYPE_FLOATFORMAT (t) = floatformats; |
3682 | return t; | |
3683 | } | |
3684 | ||
e9bb382b UW |
3685 | /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH. |
3686 | NAME is the type name. TARGET_TYPE is the component float type. */ | |
5212577a | 3687 | |
27067745 | 3688 | struct type * |
e9bb382b UW |
3689 | arch_complex_type (struct gdbarch *gdbarch, |
3690 | char *name, struct type *target_type) | |
27067745 UW |
3691 | { |
3692 | struct type *t; | |
d8734c88 | 3693 | |
e9bb382b UW |
3694 | t = arch_type (gdbarch, TYPE_CODE_COMPLEX, |
3695 | 2 * TYPE_LENGTH (target_type), name); | |
27067745 UW |
3696 | TYPE_TARGET_TYPE (t) = target_type; |
3697 | return t; | |
3698 | } | |
3699 | ||
e9bb382b | 3700 | /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH. |
eb90ce83 | 3701 | NAME is the type name. LENGTH is the size of the flag word in bytes. */ |
5212577a | 3702 | |
e9bb382b UW |
3703 | struct type * |
3704 | arch_flags_type (struct gdbarch *gdbarch, char *name, int length) | |
3705 | { | |
3706 | int nfields = length * TARGET_CHAR_BIT; | |
3707 | struct type *type; | |
3708 | ||
3709 | type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name); | |
3710 | TYPE_UNSIGNED (type) = 1; | |
3711 | TYPE_NFIELDS (type) = nfields; | |
3712 | TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field)); | |
3713 | ||
3714 | return type; | |
3715 | } | |
3716 | ||
3717 | /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at | |
3718 | position BITPOS is called NAME. */ | |
5212577a | 3719 | |
e9bb382b UW |
3720 | void |
3721 | append_flags_type_flag (struct type *type, int bitpos, char *name) | |
3722 | { | |
3723 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS); | |
3724 | gdb_assert (bitpos < TYPE_NFIELDS (type)); | |
3725 | gdb_assert (bitpos >= 0); | |
3726 | ||
3727 | if (name) | |
3728 | { | |
3729 | TYPE_FIELD_NAME (type, bitpos) = xstrdup (name); | |
945b3a32 | 3730 | SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos); |
e9bb382b UW |
3731 | } |
3732 | else | |
3733 | { | |
3734 | /* Don't show this field to the user. */ | |
945b3a32 | 3735 | SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1); |
e9bb382b UW |
3736 | } |
3737 | } | |
3738 | ||
3739 | /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as | |
3740 | specified by CODE) associated with GDBARCH. NAME is the type name. */ | |
5212577a | 3741 | |
e9bb382b UW |
3742 | struct type * |
3743 | arch_composite_type (struct gdbarch *gdbarch, char *name, enum type_code code) | |
3744 | { | |
3745 | struct type *t; | |
d8734c88 | 3746 | |
e9bb382b UW |
3747 | gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION); |
3748 | t = arch_type (gdbarch, code, 0, NULL); | |
3749 | TYPE_TAG_NAME (t) = name; | |
3750 | INIT_CPLUS_SPECIFIC (t); | |
3751 | return t; | |
3752 | } | |
3753 | ||
3754 | /* Add new field with name NAME and type FIELD to composite type T. | |
f5dff777 DJ |
3755 | Do not set the field's position or adjust the type's length; |
3756 | the caller should do so. Return the new field. */ | |
5212577a | 3757 | |
f5dff777 DJ |
3758 | struct field * |
3759 | append_composite_type_field_raw (struct type *t, char *name, | |
3760 | struct type *field) | |
e9bb382b UW |
3761 | { |
3762 | struct field *f; | |
d8734c88 | 3763 | |
e9bb382b UW |
3764 | TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1; |
3765 | TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t), | |
3766 | sizeof (struct field) * TYPE_NFIELDS (t)); | |
3767 | f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]); | |
3768 | memset (f, 0, sizeof f[0]); | |
3769 | FIELD_TYPE (f[0]) = field; | |
3770 | FIELD_NAME (f[0]) = name; | |
f5dff777 DJ |
3771 | return f; |
3772 | } | |
3773 | ||
3774 | /* Add new field with name NAME and type FIELD to composite type T. | |
3775 | ALIGNMENT (if non-zero) specifies the minimum field alignment. */ | |
5212577a | 3776 | |
f5dff777 DJ |
3777 | void |
3778 | append_composite_type_field_aligned (struct type *t, char *name, | |
3779 | struct type *field, int alignment) | |
3780 | { | |
3781 | struct field *f = append_composite_type_field_raw (t, name, field); | |
d8734c88 | 3782 | |
e9bb382b UW |
3783 | if (TYPE_CODE (t) == TYPE_CODE_UNION) |
3784 | { | |
3785 | if (TYPE_LENGTH (t) < TYPE_LENGTH (field)) | |
3786 | TYPE_LENGTH (t) = TYPE_LENGTH (field); | |
3787 | } | |
3788 | else if (TYPE_CODE (t) == TYPE_CODE_STRUCT) | |
3789 | { | |
3790 | TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field); | |
3791 | if (TYPE_NFIELDS (t) > 1) | |
3792 | { | |
f41f5e61 PA |
3793 | SET_FIELD_BITPOS (f[0], |
3794 | (FIELD_BITPOS (f[-1]) | |
3795 | + (TYPE_LENGTH (FIELD_TYPE (f[-1])) | |
3796 | * TARGET_CHAR_BIT))); | |
e9bb382b UW |
3797 | |
3798 | if (alignment) | |
3799 | { | |
86c3c1fc AB |
3800 | int left; |
3801 | ||
3802 | alignment *= TARGET_CHAR_BIT; | |
3803 | left = FIELD_BITPOS (f[0]) % alignment; | |
d8734c88 | 3804 | |
e9bb382b UW |
3805 | if (left) |
3806 | { | |
f41f5e61 | 3807 | SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left)); |
86c3c1fc | 3808 | TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT; |
e9bb382b UW |
3809 | } |
3810 | } | |
3811 | } | |
3812 | } | |
3813 | } | |
3814 | ||
3815 | /* Add new field with name NAME and type FIELD to composite type T. */ | |
5212577a | 3816 | |
e9bb382b UW |
3817 | void |
3818 | append_composite_type_field (struct type *t, char *name, | |
3819 | struct type *field) | |
3820 | { | |
3821 | append_composite_type_field_aligned (t, name, field, 0); | |
3822 | } | |
3823 | ||
000177f0 AC |
3824 | static struct gdbarch_data *gdbtypes_data; |
3825 | ||
3826 | const struct builtin_type * | |
3827 | builtin_type (struct gdbarch *gdbarch) | |
3828 | { | |
3829 | return gdbarch_data (gdbarch, gdbtypes_data); | |
3830 | } | |
3831 | ||
3832 | static void * | |
3833 | gdbtypes_post_init (struct gdbarch *gdbarch) | |
3834 | { | |
3835 | struct builtin_type *builtin_type | |
3836 | = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type); | |
3837 | ||
46bf5051 | 3838 | /* Basic types. */ |
e9bb382b UW |
3839 | builtin_type->builtin_void |
3840 | = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"); | |
3841 | builtin_type->builtin_char | |
3842 | = arch_integer_type (gdbarch, TARGET_CHAR_BIT, | |
3843 | !gdbarch_char_signed (gdbarch), "char"); | |
3844 | builtin_type->builtin_signed_char | |
3845 | = arch_integer_type (gdbarch, TARGET_CHAR_BIT, | |
3846 | 0, "signed char"); | |
3847 | builtin_type->builtin_unsigned_char | |
3848 | = arch_integer_type (gdbarch, TARGET_CHAR_BIT, | |
3849 | 1, "unsigned char"); | |
3850 | builtin_type->builtin_short | |
3851 | = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), | |
3852 | 0, "short"); | |
3853 | builtin_type->builtin_unsigned_short | |
3854 | = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), | |
3855 | 1, "unsigned short"); | |
3856 | builtin_type->builtin_int | |
3857 | = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), | |
3858 | 0, "int"); | |
3859 | builtin_type->builtin_unsigned_int | |
3860 | = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), | |
3861 | 1, "unsigned int"); | |
3862 | builtin_type->builtin_long | |
3863 | = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), | |
3864 | 0, "long"); | |
3865 | builtin_type->builtin_unsigned_long | |
3866 | = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), | |
3867 | 1, "unsigned long"); | |
3868 | builtin_type->builtin_long_long | |
3869 | = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), | |
3870 | 0, "long long"); | |
3871 | builtin_type->builtin_unsigned_long_long | |
3872 | = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), | |
3873 | 1, "unsigned long long"); | |
70bd8e24 | 3874 | builtin_type->builtin_float |
e9bb382b | 3875 | = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch), |
27067745 | 3876 | "float", gdbarch_float_format (gdbarch)); |
70bd8e24 | 3877 | builtin_type->builtin_double |
e9bb382b | 3878 | = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch), |
27067745 | 3879 | "double", gdbarch_double_format (gdbarch)); |
70bd8e24 | 3880 | builtin_type->builtin_long_double |
e9bb382b | 3881 | = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch), |
27067745 | 3882 | "long double", gdbarch_long_double_format (gdbarch)); |
70bd8e24 | 3883 | builtin_type->builtin_complex |
e9bb382b UW |
3884 | = arch_complex_type (gdbarch, "complex", |
3885 | builtin_type->builtin_float); | |
70bd8e24 | 3886 | builtin_type->builtin_double_complex |
e9bb382b UW |
3887 | = arch_complex_type (gdbarch, "double complex", |
3888 | builtin_type->builtin_double); | |
3889 | builtin_type->builtin_string | |
3890 | = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string"); | |
3891 | builtin_type->builtin_bool | |
3892 | = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool"); | |
000177f0 | 3893 | |
7678ef8f TJB |
3894 | /* The following three are about decimal floating point types, which |
3895 | are 32-bits, 64-bits and 128-bits respectively. */ | |
3896 | builtin_type->builtin_decfloat | |
e9bb382b | 3897 | = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 32 / 8, "_Decimal32"); |
7678ef8f | 3898 | builtin_type->builtin_decdouble |
e9bb382b | 3899 | = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 64 / 8, "_Decimal64"); |
7678ef8f | 3900 | builtin_type->builtin_declong |
e9bb382b | 3901 | = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 128 / 8, "_Decimal128"); |
7678ef8f | 3902 | |
69feb676 | 3903 | /* "True" character types. */ |
e9bb382b UW |
3904 | builtin_type->builtin_true_char |
3905 | = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character"); | |
3906 | builtin_type->builtin_true_unsigned_char | |
3907 | = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character"); | |
69feb676 | 3908 | |
df4df182 | 3909 | /* Fixed-size integer types. */ |
e9bb382b UW |
3910 | builtin_type->builtin_int0 |
3911 | = arch_integer_type (gdbarch, 0, 0, "int0_t"); | |
3912 | builtin_type->builtin_int8 | |
3913 | = arch_integer_type (gdbarch, 8, 0, "int8_t"); | |
3914 | builtin_type->builtin_uint8 | |
3915 | = arch_integer_type (gdbarch, 8, 1, "uint8_t"); | |
3916 | builtin_type->builtin_int16 | |
3917 | = arch_integer_type (gdbarch, 16, 0, "int16_t"); | |
3918 | builtin_type->builtin_uint16 | |
3919 | = arch_integer_type (gdbarch, 16, 1, "uint16_t"); | |
3920 | builtin_type->builtin_int32 | |
3921 | = arch_integer_type (gdbarch, 32, 0, "int32_t"); | |
3922 | builtin_type->builtin_uint32 | |
3923 | = arch_integer_type (gdbarch, 32, 1, "uint32_t"); | |
3924 | builtin_type->builtin_int64 | |
3925 | = arch_integer_type (gdbarch, 64, 0, "int64_t"); | |
3926 | builtin_type->builtin_uint64 | |
3927 | = arch_integer_type (gdbarch, 64, 1, "uint64_t"); | |
3928 | builtin_type->builtin_int128 | |
3929 | = arch_integer_type (gdbarch, 128, 0, "int128_t"); | |
3930 | builtin_type->builtin_uint128 | |
3931 | = arch_integer_type (gdbarch, 128, 1, "uint128_t"); | |
2844d6b5 KW |
3932 | TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |= |
3933 | TYPE_INSTANCE_FLAG_NOTTEXT; | |
3934 | TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |= | |
3935 | TYPE_INSTANCE_FLAG_NOTTEXT; | |
df4df182 | 3936 | |
9a22f0d0 PM |
3937 | /* Wide character types. */ |
3938 | builtin_type->builtin_char16 | |
3939 | = arch_integer_type (gdbarch, 16, 0, "char16_t"); | |
3940 | builtin_type->builtin_char32 | |
3941 | = arch_integer_type (gdbarch, 32, 0, "char32_t"); | |
3942 | ||
3943 | ||
46bf5051 | 3944 | /* Default data/code pointer types. */ |
e9bb382b UW |
3945 | builtin_type->builtin_data_ptr |
3946 | = lookup_pointer_type (builtin_type->builtin_void); | |
3947 | builtin_type->builtin_func_ptr | |
3948 | = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void)); | |
0875794a JK |
3949 | builtin_type->builtin_func_func |
3950 | = lookup_function_type (builtin_type->builtin_func_ptr); | |
46bf5051 | 3951 | |
78267919 | 3952 | /* This type represents a GDB internal function. */ |
e9bb382b UW |
3953 | builtin_type->internal_fn |
3954 | = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0, | |
3955 | "<internal function>"); | |
78267919 | 3956 | |
46bf5051 UW |
3957 | return builtin_type; |
3958 | } | |
3959 | ||
46bf5051 UW |
3960 | /* This set of objfile-based types is intended to be used by symbol |
3961 | readers as basic types. */ | |
3962 | ||
3963 | static const struct objfile_data *objfile_type_data; | |
3964 | ||
3965 | const struct objfile_type * | |
3966 | objfile_type (struct objfile *objfile) | |
3967 | { | |
3968 | struct gdbarch *gdbarch; | |
3969 | struct objfile_type *objfile_type | |
3970 | = objfile_data (objfile, objfile_type_data); | |
3971 | ||
3972 | if (objfile_type) | |
3973 | return objfile_type; | |
3974 | ||
3975 | objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
3976 | 1, struct objfile_type); | |
3977 | ||
3978 | /* Use the objfile architecture to determine basic type properties. */ | |
3979 | gdbarch = get_objfile_arch (objfile); | |
3980 | ||
3981 | /* Basic types. */ | |
3982 | objfile_type->builtin_void | |
3983 | = init_type (TYPE_CODE_VOID, 1, | |
3984 | 0, | |
3985 | "void", objfile); | |
3986 | ||
3987 | objfile_type->builtin_char | |
3988 | = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3989 | (TYPE_FLAG_NOSIGN | |
3990 | | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)), | |
3991 | "char", objfile); | |
3992 | objfile_type->builtin_signed_char | |
3993 | = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3994 | 0, | |
3995 | "signed char", objfile); | |
3996 | objfile_type->builtin_unsigned_char | |
3997 | = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3998 | TYPE_FLAG_UNSIGNED, | |
3999 | "unsigned char", objfile); | |
4000 | objfile_type->builtin_short | |
4001 | = init_type (TYPE_CODE_INT, | |
4002 | gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT, | |
4003 | 0, "short", objfile); | |
4004 | objfile_type->builtin_unsigned_short | |
4005 | = init_type (TYPE_CODE_INT, | |
4006 | gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT, | |
4007 | TYPE_FLAG_UNSIGNED, "unsigned short", objfile); | |
4008 | objfile_type->builtin_int | |
4009 | = init_type (TYPE_CODE_INT, | |
4010 | gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT, | |
4011 | 0, "int", objfile); | |
4012 | objfile_type->builtin_unsigned_int | |
4013 | = init_type (TYPE_CODE_INT, | |
4014 | gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT, | |
4015 | TYPE_FLAG_UNSIGNED, "unsigned int", objfile); | |
4016 | objfile_type->builtin_long | |
4017 | = init_type (TYPE_CODE_INT, | |
4018 | gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT, | |
4019 | 0, "long", objfile); | |
4020 | objfile_type->builtin_unsigned_long | |
4021 | = init_type (TYPE_CODE_INT, | |
4022 | gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT, | |
4023 | TYPE_FLAG_UNSIGNED, "unsigned long", objfile); | |
4024 | objfile_type->builtin_long_long | |
4025 | = init_type (TYPE_CODE_INT, | |
4026 | gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT, | |
4027 | 0, "long long", objfile); | |
4028 | objfile_type->builtin_unsigned_long_long | |
4029 | = init_type (TYPE_CODE_INT, | |
4030 | gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT, | |
4031 | TYPE_FLAG_UNSIGNED, "unsigned long long", objfile); | |
4032 | ||
4033 | objfile_type->builtin_float | |
4034 | = init_type (TYPE_CODE_FLT, | |
4035 | gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, | |
4036 | 0, "float", objfile); | |
4037 | TYPE_FLOATFORMAT (objfile_type->builtin_float) | |
4038 | = gdbarch_float_format (gdbarch); | |
4039 | objfile_type->builtin_double | |
4040 | = init_type (TYPE_CODE_FLT, | |
4041 | gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, | |
4042 | 0, "double", objfile); | |
4043 | TYPE_FLOATFORMAT (objfile_type->builtin_double) | |
4044 | = gdbarch_double_format (gdbarch); | |
4045 | objfile_type->builtin_long_double | |
4046 | = init_type (TYPE_CODE_FLT, | |
4047 | gdbarch_long_double_bit (gdbarch) / TARGET_CHAR_BIT, | |
4048 | 0, "long double", objfile); | |
4049 | TYPE_FLOATFORMAT (objfile_type->builtin_long_double) | |
4050 | = gdbarch_long_double_format (gdbarch); | |
4051 | ||
4052 | /* This type represents a type that was unrecognized in symbol read-in. */ | |
4053 | objfile_type->builtin_error | |
4054 | = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>", objfile); | |
4055 | ||
4056 | /* The following set of types is used for symbols with no | |
4057 | debug information. */ | |
4058 | objfile_type->nodebug_text_symbol | |
4059 | = init_type (TYPE_CODE_FUNC, 1, 0, | |
4060 | "<text variable, no debug info>", objfile); | |
4061 | TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol) | |
4062 | = objfile_type->builtin_int; | |
0875794a JK |
4063 | objfile_type->nodebug_text_gnu_ifunc_symbol |
4064 | = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC, | |
4065 | "<text gnu-indirect-function variable, no debug info>", | |
4066 | objfile); | |
4067 | TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol) | |
4068 | = objfile_type->nodebug_text_symbol; | |
4069 | objfile_type->nodebug_got_plt_symbol | |
4070 | = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0, | |
4071 | "<text from jump slot in .got.plt, no debug info>", | |
4072 | objfile); | |
4073 | TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol) | |
4074 | = objfile_type->nodebug_text_symbol; | |
46bf5051 UW |
4075 | objfile_type->nodebug_data_symbol |
4076 | = init_type (TYPE_CODE_INT, | |
4077 | gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0, | |
4078 | "<data variable, no debug info>", objfile); | |
4079 | objfile_type->nodebug_unknown_symbol | |
4080 | = init_type (TYPE_CODE_INT, 1, 0, | |
4081 | "<variable (not text or data), no debug info>", objfile); | |
4082 | objfile_type->nodebug_tls_symbol | |
4083 | = init_type (TYPE_CODE_INT, | |
4084 | gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0, | |
4085 | "<thread local variable, no debug info>", objfile); | |
000177f0 AC |
4086 | |
4087 | /* NOTE: on some targets, addresses and pointers are not necessarily | |
0a7cfe2c | 4088 | the same. |
000177f0 AC |
4089 | |
4090 | The upshot is: | |
4091 | - gdb's `struct type' always describes the target's | |
4092 | representation. | |
4093 | - gdb's `struct value' objects should always hold values in | |
4094 | target form. | |
4095 | - gdb's CORE_ADDR values are addresses in the unified virtual | |
4096 | address space that the assembler and linker work with. Thus, | |
4097 | since target_read_memory takes a CORE_ADDR as an argument, it | |
4098 | can access any memory on the target, even if the processor has | |
4099 | separate code and data address spaces. | |
4100 | ||
46bf5051 UW |
4101 | In this context, objfile_type->builtin_core_addr is a bit odd: |
4102 | it's a target type for a value the target will never see. It's | |
4103 | only used to hold the values of (typeless) linker symbols, which | |
4104 | are indeed in the unified virtual address space. */ | |
000177f0 | 4105 | |
46bf5051 UW |
4106 | objfile_type->builtin_core_addr |
4107 | = init_type (TYPE_CODE_INT, | |
4108 | gdbarch_addr_bit (gdbarch) / 8, | |
4109 | TYPE_FLAG_UNSIGNED, "__CORE_ADDR", objfile); | |
64c50499 | 4110 | |
46bf5051 UW |
4111 | set_objfile_data (objfile, objfile_type_data, objfile_type); |
4112 | return objfile_type; | |
000177f0 AC |
4113 | } |
4114 | ||
5212577a | 4115 | extern initialize_file_ftype _initialize_gdbtypes; |
46bf5051 | 4116 | |
c906108c | 4117 | void |
fba45db2 | 4118 | _initialize_gdbtypes (void) |
c906108c | 4119 | { |
5674de60 | 4120 | gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init); |
46bf5051 | 4121 | objfile_type_data = register_objfile_data (); |
5674de60 | 4122 | |
ccce17b0 YQ |
4123 | add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug, |
4124 | _("Set debugging of C++ overloading."), | |
4125 | _("Show debugging of C++ overloading."), | |
4126 | _("When enabled, ranking of the " | |
4127 | "functions is displayed."), | |
4128 | NULL, | |
4129 | show_overload_debug, | |
4130 | &setdebuglist, &showdebuglist); | |
5674de60 | 4131 | |
7ba81444 | 4132 | /* Add user knob for controlling resolution of opaque types. */ |
5674de60 | 4133 | add_setshow_boolean_cmd ("opaque-type-resolution", class_support, |
3e43a32a MS |
4134 | &opaque_type_resolution, |
4135 | _("Set resolution of opaque struct/class/union" | |
4136 | " types (if set before loading symbols)."), | |
4137 | _("Show resolution of opaque struct/class/union" | |
4138 | " types (if set before loading symbols)."), | |
4139 | NULL, NULL, | |
5674de60 UW |
4140 | show_opaque_type_resolution, |
4141 | &setlist, &showlist); | |
a451cb65 KS |
4142 | |
4143 | /* Add an option to permit non-strict type checking. */ | |
4144 | add_setshow_boolean_cmd ("type", class_support, | |
4145 | &strict_type_checking, | |
4146 | _("Set strict type checking."), | |
4147 | _("Show strict type checking."), | |
4148 | NULL, NULL, | |
4149 | show_strict_type_checking, | |
4150 | &setchecklist, &showchecklist); | |
c906108c | 4151 | } |