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