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