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