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