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