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