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