119370Spst/* Support routines for manipulating internal types for GDB.
2130803Smarcel   Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
3130803Smarcel   2004 Free Software Foundation, Inc.
419370Spst   Contributed by Cygnus Support, using pieces from other GDB modules.
519370Spst
698944Sobrien   This file is part of GDB.
719370Spst
898944Sobrien   This program is free software; you can redistribute it and/or modify
998944Sobrien   it under the terms of the GNU General Public License as published by
1098944Sobrien   the Free Software Foundation; either version 2 of the License, or
1198944Sobrien   (at your option) any later version.
1219370Spst
1398944Sobrien   This program is distributed in the hope that it will be useful,
1498944Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1598944Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1698944Sobrien   GNU General Public License for more details.
1719370Spst
1898944Sobrien   You should have received a copy of the GNU General Public License
1998944Sobrien   along with this program; if not, write to the Free Software
2098944Sobrien   Foundation, Inc., 59 Temple Place - Suite 330,
2198944Sobrien   Boston, MA 02111-1307, USA.  */
2219370Spst
2319370Spst#include "defs.h"
2419370Spst#include "gdb_string.h"
2519370Spst#include "bfd.h"
2619370Spst#include "symtab.h"
2719370Spst#include "symfile.h"
2819370Spst#include "objfiles.h"
2919370Spst#include "gdbtypes.h"
3019370Spst#include "expression.h"
3119370Spst#include "language.h"
3219370Spst#include "target.h"
3319370Spst#include "value.h"
3419370Spst#include "demangle.h"
3519370Spst#include "complaints.h"
3646283Sdfr#include "gdbcmd.h"
3798944Sobrien#include "wrapper.h"
3898944Sobrien#include "cp-abi.h"
3998944Sobrien#include "gdb_assert.h"
4019370Spst
4119370Spst/* These variables point to the objects
4219370Spst   representing the predefined C data types.  */
4319370Spst
4419370Spststruct type *builtin_type_void;
4519370Spststruct type *builtin_type_char;
4698944Sobrienstruct type *builtin_type_true_char;
4719370Spststruct type *builtin_type_short;
4819370Spststruct type *builtin_type_int;
4919370Spststruct type *builtin_type_long;
5019370Spststruct type *builtin_type_long_long;
5119370Spststruct type *builtin_type_signed_char;
5219370Spststruct type *builtin_type_unsigned_char;
5319370Spststruct type *builtin_type_unsigned_short;
5419370Spststruct type *builtin_type_unsigned_int;
5519370Spststruct type *builtin_type_unsigned_long;
5619370Spststruct type *builtin_type_unsigned_long_long;
5719370Spststruct type *builtin_type_float;
5819370Spststruct type *builtin_type_double;
5919370Spststruct type *builtin_type_long_double;
6019370Spststruct type *builtin_type_complex;
6119370Spststruct type *builtin_type_double_complex;
6219370Spststruct type *builtin_type_string;
63130803Smarcelstruct type *builtin_type_int0;
6446283Sdfrstruct type *builtin_type_int8;
6546283Sdfrstruct type *builtin_type_uint8;
6646283Sdfrstruct type *builtin_type_int16;
6746283Sdfrstruct type *builtin_type_uint16;
6846283Sdfrstruct type *builtin_type_int32;
6946283Sdfrstruct type *builtin_type_uint32;
7046283Sdfrstruct type *builtin_type_int64;
7146283Sdfrstruct type *builtin_type_uint64;
7298944Sobrienstruct type *builtin_type_int128;
7398944Sobrienstruct type *builtin_type_uint128;
7446283Sdfrstruct type *builtin_type_bool;
75130803Smarcel
76130803Smarcel/* 128 bit long vector types */
77130803Smarcelstruct type *builtin_type_v2_double;
78130803Smarcelstruct type *builtin_type_v4_float;
79130803Smarcelstruct type *builtin_type_v2_int64;
80130803Smarcelstruct type *builtin_type_v4_int32;
81130803Smarcelstruct type *builtin_type_v8_int16;
82130803Smarcelstruct type *builtin_type_v16_int8;
83130803Smarcel/* 64 bit long vector types */
84130803Smarcelstruct type *builtin_type_v2_float;
85130803Smarcelstruct type *builtin_type_v2_int32;
86130803Smarcelstruct type *builtin_type_v4_int16;
87130803Smarcelstruct type *builtin_type_v8_int8;
88130803Smarcel
8998944Sobrienstruct type *builtin_type_v4sf;
9098944Sobrienstruct type *builtin_type_v4si;
9198944Sobrienstruct type *builtin_type_v16qi;
9298944Sobrienstruct type *builtin_type_v8qi;
9398944Sobrienstruct type *builtin_type_v8hi;
9498944Sobrienstruct type *builtin_type_v4hi;
9598944Sobrienstruct type *builtin_type_v2si;
96130803Smarcelstruct type *builtin_type_vec64;
97130803Smarcelstruct type *builtin_type_vec64i;
9898944Sobrienstruct type *builtin_type_vec128;
99130803Smarcelstruct type *builtin_type_vec128i;
10098944Sobrienstruct type *builtin_type_ieee_single_big;
10198944Sobrienstruct type *builtin_type_ieee_single_little;
10298944Sobrienstruct type *builtin_type_ieee_double_big;
10398944Sobrienstruct type *builtin_type_ieee_double_little;
10498944Sobrienstruct type *builtin_type_ieee_double_littlebyte_bigword;
10598944Sobrienstruct type *builtin_type_i387_ext;
10698944Sobrienstruct type *builtin_type_m68881_ext;
10798944Sobrienstruct type *builtin_type_i960_ext;
10898944Sobrienstruct type *builtin_type_m88110_ext;
10998944Sobrienstruct type *builtin_type_m88110_harris_ext;
11098944Sobrienstruct type *builtin_type_arm_ext_big;
11198944Sobrienstruct type *builtin_type_arm_ext_littlebyte_bigword;
11298944Sobrienstruct type *builtin_type_ia64_spill_big;
11398944Sobrienstruct type *builtin_type_ia64_spill_little;
11498944Sobrienstruct type *builtin_type_ia64_quad_big;
11598944Sobrienstruct type *builtin_type_ia64_quad_little;
11698944Sobrienstruct type *builtin_type_void_data_ptr;
11798944Sobrienstruct type *builtin_type_void_func_ptr;
11898944Sobrienstruct type *builtin_type_CORE_ADDR;
11998944Sobrienstruct type *builtin_type_bfd_vma;
12019370Spst
12146283Sdfrint opaque_type_resolution = 1;
12298944Sobrienint overload_debug = 0;
12346283Sdfr
12498944Sobrienstruct extra
12598944Sobrien  {
12698944Sobrien    char str[128];
12798944Sobrien    int len;
12898944Sobrien  };				/* maximum extension is 128! FIXME */
12946283Sdfr
13098944Sobrienstatic void print_bit_vector (B_TYPE *, int);
131130803Smarcelstatic void print_arg_types (struct field *, int, int);
13298944Sobrienstatic void dump_fn_fieldlists (struct type *, int);
13398944Sobrienstatic void print_cplus_stuff (struct type *, int);
13498944Sobrienstatic void virtual_base_list_aux (struct type *dclass);
13546283Sdfr
13698944Sobrien
13719370Spst/* Alloc a new type structure and fill it with some defaults.  If
13819370Spst   OBJFILE is non-NULL, then allocate the space for the type structure
139130803Smarcel   in that objfile's objfile_obstack.  Otherwise allocate the new type structure
140130803Smarcel   by xmalloc () (for permanent types).  */
14119370Spst
14219370Spststruct type *
14398944Sobrienalloc_type (struct objfile *objfile)
14419370Spst{
145130803Smarcel  struct type *type;
14619370Spst
14719370Spst  /* Alloc the structure and start off with all fields zeroed. */
14819370Spst
14919370Spst  if (objfile == NULL)
15019370Spst    {
151130803Smarcel      type = xmalloc (sizeof (struct type));
152130803Smarcel      memset (type, 0, sizeof (struct type));
153130803Smarcel      TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
15419370Spst    }
15519370Spst  else
15619370Spst    {
157130803Smarcel      type = obstack_alloc (&objfile->objfile_obstack,
158130803Smarcel			    sizeof (struct type));
159130803Smarcel      memset (type, 0, sizeof (struct type));
160130803Smarcel      TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
161130803Smarcel					     sizeof (struct main_type));
16219370Spst      OBJSTAT (objfile, n_types++);
16319370Spst    }
164130803Smarcel  memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
16519370Spst
16619370Spst  /* Initialize the fields that might not be zero. */
16719370Spst
16819370Spst  TYPE_CODE (type) = TYPE_CODE_UNDEF;
16919370Spst  TYPE_OBJFILE (type) = objfile;
17019370Spst  TYPE_VPTR_FIELDNO (type) = -1;
171130803Smarcel  TYPE_CHAIN (type) = type;	/* Chain back to itself.  */
17219370Spst
17319370Spst  return (type);
17419370Spst}
17519370Spst
176130803Smarcel/* Alloc a new type instance structure, fill it with some defaults,
177130803Smarcel   and point it at OLDTYPE.  Allocate the new type instance from the
178130803Smarcel   same place as OLDTYPE.  */
179130803Smarcel
180130803Smarcelstatic struct type *
181130803Smarcelalloc_type_instance (struct type *oldtype)
182130803Smarcel{
183130803Smarcel  struct type *type;
184130803Smarcel
185130803Smarcel  /* Allocate the structure.  */
186130803Smarcel
187130803Smarcel  if (TYPE_OBJFILE (oldtype) == NULL)
188130803Smarcel    {
189130803Smarcel      type = xmalloc (sizeof (struct type));
190130803Smarcel      memset (type, 0, sizeof (struct type));
191130803Smarcel    }
192130803Smarcel  else
193130803Smarcel    {
194130803Smarcel      type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
195130803Smarcel			    sizeof (struct type));
196130803Smarcel      memset (type, 0, sizeof (struct type));
197130803Smarcel    }
198130803Smarcel  TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
199130803Smarcel
200130803Smarcel  TYPE_CHAIN (type) = type;	/* Chain back to itself for now.  */
201130803Smarcel
202130803Smarcel  return (type);
203130803Smarcel}
204130803Smarcel
205130803Smarcel/* Clear all remnants of the previous type at TYPE, in preparation for
206130803Smarcel   replacing it with something else.  */
207130803Smarcelstatic void
208130803Smarcelsmash_type (struct type *type)
209130803Smarcel{
210130803Smarcel  memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
211130803Smarcel
212130803Smarcel  /* For now, delete the rings.  */
213130803Smarcel  TYPE_CHAIN (type) = type;
214130803Smarcel
215130803Smarcel  /* For now, leave the pointer/reference types alone.  */
216130803Smarcel}
217130803Smarcel
21819370Spst/* Lookup a pointer to a type TYPE.  TYPEPTR, if nonzero, points
21919370Spst   to a pointer to memory where the pointer type should be stored.
22019370Spst   If *TYPEPTR is zero, update it to point to the pointer type we return.
22119370Spst   We allocate new memory if needed.  */
22219370Spst
22319370Spststruct type *
22498944Sobrienmake_pointer_type (struct type *type, struct type **typeptr)
22519370Spst{
226130803Smarcel  struct type *ntype;	/* New type */
22719370Spst  struct objfile *objfile;
22819370Spst
22919370Spst  ntype = TYPE_POINTER_TYPE (type);
23019370Spst
23198944Sobrien  if (ntype)
23246283Sdfr    {
23398944Sobrien      if (typeptr == 0)
23498944Sobrien	return ntype;		/* Don't care about alloc, and have new type.  */
23546283Sdfr      else if (*typeptr == 0)
23698944Sobrien	{
23746283Sdfr	  *typeptr = ntype;	/* Tracking alloc, and we have new type.  */
23846283Sdfr	  return ntype;
23998944Sobrien	}
24046283Sdfr    }
24119370Spst
24219370Spst  if (typeptr == 0 || *typeptr == 0)	/* We'll need to allocate one.  */
24319370Spst    {
24419370Spst      ntype = alloc_type (TYPE_OBJFILE (type));
24519370Spst      if (typeptr)
24619370Spst	*typeptr = ntype;
24719370Spst    }
24898944Sobrien  else
24998944Sobrien    /* We have storage, but need to reset it.  */
25019370Spst    {
25119370Spst      ntype = *typeptr;
25219370Spst      objfile = TYPE_OBJFILE (ntype);
253130803Smarcel      smash_type (ntype);
25419370Spst      TYPE_OBJFILE (ntype) = objfile;
25519370Spst    }
25619370Spst
25719370Spst  TYPE_TARGET_TYPE (ntype) = type;
25819370Spst  TYPE_POINTER_TYPE (type) = ntype;
25919370Spst
26019370Spst  /* FIXME!  Assume the machine has only one representation for pointers!  */
26119370Spst
26219370Spst  TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
26319370Spst  TYPE_CODE (ntype) = TYPE_CODE_PTR;
26419370Spst
26598944Sobrien  /* Mark pointers as unsigned.  The target converts between pointers
26698944Sobrien     and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
26798944Sobrien     ADDRESS_TO_POINTER(). */
26819370Spst  TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
26998944Sobrien
27019370Spst  if (!TYPE_POINTER_TYPE (type))	/* Remember it, if don't have one.  */
27119370Spst    TYPE_POINTER_TYPE (type) = ntype;
27219370Spst
27319370Spst  return ntype;
27419370Spst}
27519370Spst
27619370Spst/* Given a type TYPE, return a type of pointers to that type.
27719370Spst   May need to construct such a type if this is the first use.  */
27819370Spst
27919370Spststruct type *
28098944Sobrienlookup_pointer_type (struct type *type)
28119370Spst{
28298944Sobrien  return make_pointer_type (type, (struct type **) 0);
28319370Spst}
28419370Spst
28519370Spst/* Lookup a C++ `reference' to a type TYPE.  TYPEPTR, if nonzero, points
28619370Spst   to a pointer to memory where the reference type should be stored.
28719370Spst   If *TYPEPTR is zero, update it to point to the reference type we return.
28819370Spst   We allocate new memory if needed.  */
28919370Spst
29019370Spststruct type *
29198944Sobrienmake_reference_type (struct type *type, struct type **typeptr)
29219370Spst{
293130803Smarcel  struct type *ntype;	/* New type */
29419370Spst  struct objfile *objfile;
29519370Spst
29619370Spst  ntype = TYPE_REFERENCE_TYPE (type);
29719370Spst
29898944Sobrien  if (ntype)
29946283Sdfr    {
30098944Sobrien      if (typeptr == 0)
30198944Sobrien	return ntype;		/* Don't care about alloc, and have new type.  */
30246283Sdfr      else if (*typeptr == 0)
30398944Sobrien	{
30446283Sdfr	  *typeptr = ntype;	/* Tracking alloc, and we have new type.  */
30546283Sdfr	  return ntype;
30698944Sobrien	}
30746283Sdfr    }
30819370Spst
30919370Spst  if (typeptr == 0 || *typeptr == 0)	/* We'll need to allocate one.  */
31019370Spst    {
31119370Spst      ntype = alloc_type (TYPE_OBJFILE (type));
31219370Spst      if (typeptr)
31319370Spst	*typeptr = ntype;
31419370Spst    }
31598944Sobrien  else
31698944Sobrien    /* We have storage, but need to reset it.  */
31719370Spst    {
31819370Spst      ntype = *typeptr;
31919370Spst      objfile = TYPE_OBJFILE (ntype);
320130803Smarcel      smash_type (ntype);
32119370Spst      TYPE_OBJFILE (ntype) = objfile;
32219370Spst    }
32319370Spst
32419370Spst  TYPE_TARGET_TYPE (ntype) = type;
32519370Spst  TYPE_REFERENCE_TYPE (type) = ntype;
32619370Spst
32719370Spst  /* FIXME!  Assume the machine has only one representation for references,
32819370Spst     and that it matches the (only) representation for pointers!  */
32919370Spst
33019370Spst  TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
33119370Spst  TYPE_CODE (ntype) = TYPE_CODE_REF;
33298944Sobrien
33319370Spst  if (!TYPE_REFERENCE_TYPE (type))	/* Remember it, if don't have one.  */
33419370Spst    TYPE_REFERENCE_TYPE (type) = ntype;
33519370Spst
33619370Spst  return ntype;
33719370Spst}
33819370Spst
33919370Spst/* Same as above, but caller doesn't care about memory allocation details.  */
34019370Spst
34119370Spststruct type *
34298944Sobrienlookup_reference_type (struct type *type)
34319370Spst{
34498944Sobrien  return make_reference_type (type, (struct type **) 0);
34519370Spst}
34619370Spst
34719370Spst/* Lookup a function type that returns type TYPE.  TYPEPTR, if nonzero, points
34819370Spst   to a pointer to memory where the function type should be stored.
34919370Spst   If *TYPEPTR is zero, update it to point to the function type we return.
35019370Spst   We allocate new memory if needed.  */
35119370Spst
35219370Spststruct type *
35398944Sobrienmake_function_type (struct type *type, struct type **typeptr)
35419370Spst{
355130803Smarcel  struct type *ntype;	/* New type */
35619370Spst  struct objfile *objfile;
35719370Spst
35819370Spst  if (typeptr == 0 || *typeptr == 0)	/* We'll need to allocate one.  */
35919370Spst    {
36019370Spst      ntype = alloc_type (TYPE_OBJFILE (type));
36119370Spst      if (typeptr)
36219370Spst	*typeptr = ntype;
36319370Spst    }
36498944Sobrien  else
36598944Sobrien    /* We have storage, but need to reset it.  */
36619370Spst    {
36719370Spst      ntype = *typeptr;
36819370Spst      objfile = TYPE_OBJFILE (ntype);
369130803Smarcel      smash_type (ntype);
37019370Spst      TYPE_OBJFILE (ntype) = objfile;
37119370Spst    }
37219370Spst
37319370Spst  TYPE_TARGET_TYPE (ntype) = type;
37419370Spst
37519370Spst  TYPE_LENGTH (ntype) = 1;
37619370Spst  TYPE_CODE (ntype) = TYPE_CODE_FUNC;
37798944Sobrien
37819370Spst  return ntype;
37919370Spst}
38019370Spst
38119370Spst
38219370Spst/* Given a type TYPE, return a type of functions that return that type.
38319370Spst   May need to construct such a type if this is the first use.  */
38419370Spst
38519370Spststruct type *
38698944Sobrienlookup_function_type (struct type *type)
38719370Spst{
38898944Sobrien  return make_function_type (type, (struct type **) 0);
38919370Spst}
39019370Spst
39198944Sobrien/* Identify address space identifier by name --
39298944Sobrien   return the integer flag defined in gdbtypes.h.  */
39398944Sobrienextern int
39498944Sobrienaddress_space_name_to_int (char *space_identifier)
39598944Sobrien{
396130803Smarcel  struct gdbarch *gdbarch = current_gdbarch;
397130803Smarcel  int type_flags;
39898944Sobrien  /* Check for known address space delimiters. */
39998944Sobrien  if (!strcmp (space_identifier, "code"))
40098944Sobrien    return TYPE_FLAG_CODE_SPACE;
40198944Sobrien  else if (!strcmp (space_identifier, "data"))
40298944Sobrien    return TYPE_FLAG_DATA_SPACE;
403130803Smarcel  else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
404130803Smarcel           && gdbarch_address_class_name_to_type_flags (gdbarch,
405130803Smarcel							space_identifier,
406130803Smarcel							&type_flags))
407130803Smarcel    return type_flags;
40898944Sobrien  else
40998944Sobrien    error ("Unknown address space specifier: \"%s\"", space_identifier);
41098944Sobrien}
41146283Sdfr
41298944Sobrien/* Identify address space identifier by integer flag as defined in
41398944Sobrien   gdbtypes.h -- return the string version of the adress space name. */
41498944Sobrien
415130803Smarcelconst char *
41698944Sobrienaddress_space_int_to_name (int space_flag)
41798944Sobrien{
418130803Smarcel  struct gdbarch *gdbarch = current_gdbarch;
41998944Sobrien  if (space_flag & TYPE_FLAG_CODE_SPACE)
42098944Sobrien    return "code";
42198944Sobrien  else if (space_flag & TYPE_FLAG_DATA_SPACE)
42298944Sobrien    return "data";
423130803Smarcel  else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
424130803Smarcel           && gdbarch_address_class_type_flags_to_name_p (gdbarch))
425130803Smarcel    return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
42698944Sobrien  else
42798944Sobrien    return NULL;
42898944Sobrien}
42998944Sobrien
430130803Smarcel/* Create a new type with instance flags NEW_FLAGS, based on TYPE.
431130803Smarcel   If STORAGE is non-NULL, create the new type instance there.  */
43298944Sobrien
433130803Smarcelstatic struct type *
434130803Smarcelmake_qualified_type (struct type *type, int new_flags,
435130803Smarcel		     struct type *storage)
43698944Sobrien{
43798944Sobrien  struct type *ntype;
43898944Sobrien
43998944Sobrien  ntype = type;
44098944Sobrien  do {
441130803Smarcel    if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
44298944Sobrien      return ntype;
443130803Smarcel    ntype = TYPE_CHAIN (ntype);
44498944Sobrien  } while (ntype != type);
44598944Sobrien
446130803Smarcel  /* Create a new type instance.  */
447130803Smarcel  if (storage == NULL)
448130803Smarcel    ntype = alloc_type_instance (type);
449130803Smarcel  else
450130803Smarcel    {
451130803Smarcel      ntype = storage;
452130803Smarcel      TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
453130803Smarcel      TYPE_CHAIN (ntype) = ntype;
454130803Smarcel    }
45598944Sobrien
45698944Sobrien  /* Pointers or references to the original type are not relevant to
457130803Smarcel     the new type.  */
45898944Sobrien  TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
45998944Sobrien  TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
46098944Sobrien
461130803Smarcel  /* Chain the new qualified type to the old type.  */
462130803Smarcel  TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
463130803Smarcel  TYPE_CHAIN (type) = ntype;
46498944Sobrien
465130803Smarcel  /* Now set the instance flags and return the new type.  */
466130803Smarcel  TYPE_INSTANCE_FLAGS (ntype) = new_flags;
467130803Smarcel
468130803Smarcel  /* Set length of new type to that of the original type.  */
469130803Smarcel  TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
470130803Smarcel
47198944Sobrien  return ntype;
47298944Sobrien}
47398944Sobrien
474130803Smarcel/* Make an address-space-delimited variant of a type -- a type that
475130803Smarcel   is identical to the one supplied except that it has an address
476130803Smarcel   space attribute attached to it (such as "code" or "data").
47798944Sobrien
478130803Smarcel   The space attributes "code" and "data" are for Harvard architectures.
479130803Smarcel   The address space attributes are for architectures which have
480130803Smarcel   alternately sized pointers or pointers with alternate representations.  */
481130803Smarcel
482130803Smarcelstruct type *
483130803Smarcelmake_type_with_address_space (struct type *type, int space_flag)
484130803Smarcel{
485130803Smarcel  struct type *ntype;
486130803Smarcel  int new_flags = ((TYPE_INSTANCE_FLAGS (type)
487130803Smarcel		    & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
488130803Smarcel		        | TYPE_FLAG_ADDRESS_CLASS_ALL))
489130803Smarcel		   | space_flag);
490130803Smarcel
491130803Smarcel  return make_qualified_type (type, new_flags, NULL);
492130803Smarcel}
493130803Smarcel
49446283Sdfr/* Make a "c-v" variant of a type -- a type that is identical to the
49546283Sdfr   one supplied except that it may have const or volatile attributes
49646283Sdfr   CNST is a flag for setting the const attribute
49746283Sdfr   VOLTL is a flag for setting the volatile attribute
49846283Sdfr   TYPE is the base type whose variant we are creating.
49946283Sdfr   TYPEPTR, if nonzero, points
50046283Sdfr   to a pointer to memory where the reference type should be stored.
50146283Sdfr   If *TYPEPTR is zero, update it to point to the reference type we return.
50246283Sdfr   We allocate new memory if needed.  */
50346283Sdfr
50446283Sdfrstruct type *
505256851Semastemake_cvr_type (int cnst, int voltl, int restrct, struct type *type,
506256851Semaste               struct type **typeptr)
50746283Sdfr{
508130803Smarcel  struct type *ntype;	/* New type */
509130803Smarcel  struct type *tmp_type = type;	/* tmp type */
51046283Sdfr  struct objfile *objfile;
51146283Sdfr
512130803Smarcel  int new_flags = (TYPE_INSTANCE_FLAGS (type)
513130803Smarcel		   & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
51446283Sdfr
51546283Sdfr  if (cnst)
516130803Smarcel    new_flags |= TYPE_FLAG_CONST;
51746283Sdfr
51846283Sdfr  if (voltl)
519130803Smarcel    new_flags |= TYPE_FLAG_VOLATILE;
52046283Sdfr
521256851Semaste  if (restrct)
522256851Semaste    new_flags |= TYPE_FLAG_RESTRICT;
523256851Semaste
524130803Smarcel  if (typeptr && *typeptr != NULL)
52598944Sobrien    {
526130803Smarcel      /* Objfile is per-core-type.  This const-qualified type had best
527130803Smarcel	 belong to the same objfile as the type it is qualifying, unless
528130803Smarcel	 we are overwriting a stub type, in which case the safest thing
529130803Smarcel	 to do is to copy the core type into the new objfile.  */
53098944Sobrien
531130803Smarcel      gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)
532130803Smarcel		  || TYPE_STUB (*typeptr));
533130803Smarcel      if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type))
534130803Smarcel	{
535130803Smarcel	  TYPE_MAIN_TYPE (*typeptr)
536130803Smarcel	    = TYPE_ALLOC (*typeptr, sizeof (struct main_type));
537130803Smarcel	  *TYPE_MAIN_TYPE (*typeptr)
538130803Smarcel	    = *TYPE_MAIN_TYPE (type);
539130803Smarcel	}
540130803Smarcel    }
541130803Smarcel
542130803Smarcel  ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
54398944Sobrien
544130803Smarcel  if (typeptr != NULL)
545130803Smarcel    *typeptr = ntype;
54698944Sobrien
547130803Smarcel  return ntype;
54898944Sobrien}
54998944Sobrien
550130803Smarcel/* Replace the contents of ntype with the type *type.  This changes the
551130803Smarcel   contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
552130803Smarcel   the changes are propogated to all types in the TYPE_CHAIN.
55398944Sobrien
554130803Smarcel   In order to build recursive types, it's inevitable that we'll need
555130803Smarcel   to update types in place --- but this sort of indiscriminate
556130803Smarcel   smashing is ugly, and needs to be replaced with something more
557130803Smarcel   controlled.  TYPE_MAIN_TYPE is a step in this direction; it's not
558130803Smarcel   clear if more steps are needed.  */
55998944Sobrienvoid
56098944Sobrienreplace_type (struct type *ntype, struct type *type)
56198944Sobrien{
562130803Smarcel  struct type *chain;
56398944Sobrien
564130803Smarcel  *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
56598944Sobrien
566130803Smarcel  /* The type length is not a part of the main type.  Update it for each
567130803Smarcel     type on the variant chain.  */
568130803Smarcel  chain = ntype;
569130803Smarcel  do {
570130803Smarcel    /* Assert that this element of the chain has no address-class bits
571130803Smarcel       set in its flags.  Such type variants might have type lengths
572130803Smarcel       which are supposed to be different from the non-address-class
573130803Smarcel       variants.  This assertion shouldn't ever be triggered because
574130803Smarcel       symbol readers which do construct address-class variants don't
575130803Smarcel       call replace_type().  */
576130803Smarcel    gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
57798944Sobrien
578130803Smarcel    TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
579130803Smarcel    chain = TYPE_CHAIN (chain);
580130803Smarcel  } while (ntype != chain);
58198944Sobrien
582130803Smarcel  /* Assert that the two types have equivalent instance qualifiers.
583130803Smarcel     This should be true for at least all of our debug readers.  */
584130803Smarcel  gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
58598944Sobrien}
58698944Sobrien
58719370Spst/* Implement direct support for MEMBER_TYPE in GNU C++.
58819370Spst   May need to construct such a type if this is the first use.
58919370Spst   The TYPE is the type of the member.  The DOMAIN is the type
59019370Spst   of the aggregate that the member belongs to.  */
59119370Spst
59219370Spststruct type *
59398944Sobrienlookup_member_type (struct type *type, struct type *domain)
59419370Spst{
595130803Smarcel  struct type *mtype;
59619370Spst
59719370Spst  mtype = alloc_type (TYPE_OBJFILE (type));
59819370Spst  smash_to_member_type (mtype, domain, type);
59919370Spst  return (mtype);
60019370Spst}
60119370Spst
60219370Spst/* Allocate a stub method whose return type is TYPE.
60319370Spst   This apparently happens for speed of symbol reading, since parsing
60419370Spst   out the arguments to the method is cpu-intensive, the way we are doing
60519370Spst   it.  So, we will fill in arguments later.
60619370Spst   This always returns a fresh type.   */
60719370Spst
60819370Spststruct type *
60998944Sobrienallocate_stub_method (struct type *type)
61019370Spst{
61119370Spst  struct type *mtype;
61219370Spst
61398944Sobrien  mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
61498944Sobrien		     TYPE_OBJFILE (type));
61519370Spst  TYPE_TARGET_TYPE (mtype) = type;
61619370Spst  /*  _DOMAIN_TYPE (mtype) = unknown yet */
61719370Spst  return (mtype);
61819370Spst}
61919370Spst
62019370Spst/* Create a range type using either a blank type supplied in RESULT_TYPE,
62119370Spst   or creating a new type, inheriting the objfile from INDEX_TYPE.
62219370Spst
62319370Spst   Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
62419370Spst   HIGH_BOUND, inclusive.
62519370Spst
62619370Spst   FIXME:  Maybe we should check the TYPE_CODE of RESULT_TYPE to make
62719370Spst   sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
62819370Spst
62919370Spststruct type *
63098944Sobriencreate_range_type (struct type *result_type, struct type *index_type,
63198944Sobrien		   int low_bound, int high_bound)
63219370Spst{
63319370Spst  if (result_type == NULL)
63419370Spst    {
63519370Spst      result_type = alloc_type (TYPE_OBJFILE (index_type));
63619370Spst    }
63719370Spst  TYPE_CODE (result_type) = TYPE_CODE_RANGE;
63819370Spst  TYPE_TARGET_TYPE (result_type) = index_type;
63998944Sobrien  if (TYPE_STUB (index_type))
64019370Spst    TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
64119370Spst  else
64219370Spst    TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
64319370Spst  TYPE_NFIELDS (result_type) = 2;
64419370Spst  TYPE_FIELDS (result_type) = (struct field *)
64519370Spst    TYPE_ALLOC (result_type, 2 * sizeof (struct field));
64619370Spst  memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
64719370Spst  TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
64819370Spst  TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
64998944Sobrien  TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int;	/* FIXME */
65098944Sobrien  TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int;	/* FIXME */
65119370Spst
65298944Sobrien  if (low_bound >= 0)
65346283Sdfr    TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
65446283Sdfr
65519370Spst  return (result_type);
65619370Spst}
65719370Spst
65819370Spst/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
65919370Spst   Return 1 of type is a range type, 0 if it is discrete (and bounds
66019370Spst   will fit in LONGEST), or -1 otherwise. */
66119370Spst
66219370Spstint
66398944Sobrienget_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
66419370Spst{
66519370Spst  CHECK_TYPEDEF (type);
66619370Spst  switch (TYPE_CODE (type))
66719370Spst    {
66819370Spst    case TYPE_CODE_RANGE:
66919370Spst      *lowp = TYPE_LOW_BOUND (type);
67019370Spst      *highp = TYPE_HIGH_BOUND (type);
67119370Spst      return 1;
67219370Spst    case TYPE_CODE_ENUM:
67319370Spst      if (TYPE_NFIELDS (type) > 0)
67419370Spst	{
67519370Spst	  /* The enums may not be sorted by value, so search all
67619370Spst	     entries */
67719370Spst	  int i;
67819370Spst
67919370Spst	  *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
68019370Spst	  for (i = 0; i < TYPE_NFIELDS (type); i++)
68119370Spst	    {
68219370Spst	      if (TYPE_FIELD_BITPOS (type, i) < *lowp)
68319370Spst		*lowp = TYPE_FIELD_BITPOS (type, i);
68419370Spst	      if (TYPE_FIELD_BITPOS (type, i) > *highp)
68519370Spst		*highp = TYPE_FIELD_BITPOS (type, i);
68619370Spst	    }
68746283Sdfr
68846283Sdfr	  /* Set unsigned indicator if warranted. */
68998944Sobrien	  if (*lowp >= 0)
69046283Sdfr	    {
69146283Sdfr	      TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
69246283Sdfr	    }
69319370Spst	}
69419370Spst      else
69519370Spst	{
69619370Spst	  *lowp = 0;
69719370Spst	  *highp = -1;
69819370Spst	}
69919370Spst      return 0;
70019370Spst    case TYPE_CODE_BOOL:
70119370Spst      *lowp = 0;
70219370Spst      *highp = 1;
70319370Spst      return 0;
70419370Spst    case TYPE_CODE_INT:
70598944Sobrien      if (TYPE_LENGTH (type) > sizeof (LONGEST))	/* Too big */
70619370Spst	return -1;
70719370Spst      if (!TYPE_UNSIGNED (type))
70819370Spst	{
70998944Sobrien	  *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
71019370Spst	  *highp = -*lowp - 1;
71119370Spst	  return 0;
71219370Spst	}
71319370Spst      /* ... fall through for unsigned ints ... */
71419370Spst    case TYPE_CODE_CHAR:
71519370Spst      *lowp = 0;
71619370Spst      /* This round-about calculation is to avoid shifting by
71798944Sobrien         TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
71898944Sobrien         if TYPE_LENGTH (type) == sizeof (LONGEST). */
71919370Spst      *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
72019370Spst      *highp = (*highp - 1) | *highp;
72119370Spst      return 0;
72219370Spst    default:
72319370Spst      return -1;
72419370Spst    }
72519370Spst}
72619370Spst
72719370Spst/* Create an array type using either a blank type supplied in RESULT_TYPE,
72819370Spst   or creating a new type, inheriting the objfile from RANGE_TYPE.
72919370Spst
73019370Spst   Elements will be of type ELEMENT_TYPE, the indices will be of type
73119370Spst   RANGE_TYPE.
73219370Spst
73319370Spst   FIXME:  Maybe we should check the TYPE_CODE of RESULT_TYPE to make
73419370Spst   sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
73519370Spst
73619370Spststruct type *
73798944Sobriencreate_array_type (struct type *result_type, struct type *element_type,
73898944Sobrien		   struct type *range_type)
73919370Spst{
74019370Spst  LONGEST low_bound, high_bound;
74119370Spst
74219370Spst  if (result_type == NULL)
74319370Spst    {
74419370Spst      result_type = alloc_type (TYPE_OBJFILE (range_type));
74519370Spst    }
74619370Spst  TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
74719370Spst  TYPE_TARGET_TYPE (result_type) = element_type;
74819370Spst  if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
74919370Spst    low_bound = high_bound = 0;
75019370Spst  CHECK_TYPEDEF (element_type);
75119370Spst  TYPE_LENGTH (result_type) =
75219370Spst    TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
75319370Spst  TYPE_NFIELDS (result_type) = 1;
75419370Spst  TYPE_FIELDS (result_type) =
75519370Spst    (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
75619370Spst  memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
75719370Spst  TYPE_FIELD_TYPE (result_type, 0) = range_type;
75819370Spst  TYPE_VPTR_FIELDNO (result_type) = -1;
75919370Spst
76046283Sdfr  /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
76146283Sdfr  if (TYPE_LENGTH (result_type) == 0)
76246283Sdfr    TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
76346283Sdfr
76419370Spst  return (result_type);
76519370Spst}
76619370Spst
76719370Spst/* Create a string type using either a blank type supplied in RESULT_TYPE,
76819370Spst   or creating a new type.  String types are similar enough to array of
76919370Spst   char types that we can use create_array_type to build the basic type
77019370Spst   and then bash it into a string type.
77119370Spst
77219370Spst   For fixed length strings, the range type contains 0 as the lower
77319370Spst   bound and the length of the string minus one as the upper bound.
77419370Spst
77519370Spst   FIXME:  Maybe we should check the TYPE_CODE of RESULT_TYPE to make
77619370Spst   sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
77719370Spst
77819370Spststruct type *
77998944Sobriencreate_string_type (struct type *result_type, struct type *range_type)
78019370Spst{
78119370Spst  result_type = create_array_type (result_type,
78219370Spst				   *current_language->string_char_type,
78319370Spst				   range_type);
78419370Spst  TYPE_CODE (result_type) = TYPE_CODE_STRING;
78519370Spst  return (result_type);
78619370Spst}
78719370Spst
78819370Spststruct type *
78998944Sobriencreate_set_type (struct type *result_type, struct type *domain_type)
79019370Spst{
79119370Spst  LONGEST low_bound, high_bound, bit_length;
79219370Spst  if (result_type == NULL)
79319370Spst    {
79419370Spst      result_type = alloc_type (TYPE_OBJFILE (domain_type));
79519370Spst    }
79619370Spst  TYPE_CODE (result_type) = TYPE_CODE_SET;
79719370Spst  TYPE_NFIELDS (result_type) = 1;
79819370Spst  TYPE_FIELDS (result_type) = (struct field *)
79919370Spst    TYPE_ALLOC (result_type, 1 * sizeof (struct field));
80019370Spst  memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
80119370Spst
80298944Sobrien  if (!TYPE_STUB (domain_type))
80319370Spst    {
80419370Spst      if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
80519370Spst	low_bound = high_bound = 0;
80619370Spst      bit_length = high_bound - low_bound + 1;
80719370Spst      TYPE_LENGTH (result_type)
80819370Spst	= (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
80919370Spst    }
81019370Spst  TYPE_FIELD_TYPE (result_type, 0) = domain_type;
81146283Sdfr
81298944Sobrien  if (low_bound >= 0)
81346283Sdfr    TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
81446283Sdfr
81519370Spst  return (result_type);
81619370Spst}
81719370Spst
81898944Sobrien/* Construct and return a type of the form:
81998944Sobrien	struct NAME { ELT_TYPE ELT_NAME[N]; }
82098944Sobrien   We use these types for SIMD registers.  For example, the type of
82198944Sobrien   the SSE registers on the late x86-family processors is:
82298944Sobrien	struct __builtin_v4sf { float f[4]; }
82398944Sobrien   built by the function call:
82498944Sobrien	init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
82598944Sobrien   The type returned is a permanent type, allocated using malloc; it
82698944Sobrien   doesn't live in any objfile's obstack.  */
82798944Sobrienstatic struct type *
82898944Sobrieninit_simd_type (char *name,
82998944Sobrien		struct type *elt_type,
83098944Sobrien		char *elt_name,
83198944Sobrien		int n)
83298944Sobrien{
833130803Smarcel  struct type *simd_type;
834130803Smarcel  struct type *array_type;
835130803Smarcel
836130803Smarcel  simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
837130803Smarcel  array_type = create_array_type (0, elt_type,
838130803Smarcel				  create_range_type (0, builtin_type_int,
839130803Smarcel						     0, n-1));
840130803Smarcel  append_composite_type_field (simd_type, elt_name, array_type);
841130803Smarcel  return simd_type;
842130803Smarcel}
843130803Smarcel
844130803Smarcelstatic struct type *
845130803Smarcelinit_vector_type (struct type *elt_type, int n)
846130803Smarcel{
847130803Smarcel  struct type *array_type;
848130803Smarcel
849130803Smarcel  array_type = create_array_type (0, elt_type,
850130803Smarcel				  create_range_type (0, builtin_type_int,
851130803Smarcel						     0, n-1));
852130803Smarcel  TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
853130803Smarcel  return array_type;
854130803Smarcel}
855130803Smarcel
856130803Smarcelstatic struct type *
857130803Smarcelbuild_builtin_type_vec64 (void)
858130803Smarcel{
859130803Smarcel  /* Construct a type for the 64 bit registers.  The type we're
860130803Smarcel     building is this: */
861130803Smarcel#if 0
862130803Smarcel  union __gdb_builtin_type_vec64
863130803Smarcel  {
864130803Smarcel    int64_t uint64;
865130803Smarcel    float v2_float[2];
866130803Smarcel    int32_t v2_int32[2];
867130803Smarcel    int16_t v4_int16[4];
868130803Smarcel    int8_t v8_int8[8];
869130803Smarcel  };
870130803Smarcel#endif
871130803Smarcel
87298944Sobrien  struct type *t;
87398944Sobrien
874130803Smarcel  t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION);
875130803Smarcel  append_composite_type_field (t, "uint64", builtin_type_int64);
876130803Smarcel  append_composite_type_field (t, "v2_float", builtin_type_v2_float);
877130803Smarcel  append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
878130803Smarcel  append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
879130803Smarcel  append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
88098944Sobrien
881130803Smarcel  TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
882130803Smarcel  TYPE_NAME (t) = "builtin_type_vec64";
883130803Smarcel  return t;
884130803Smarcel}
88598944Sobrien
886130803Smarcelstatic struct type *
887130803Smarcelbuild_builtin_type_vec64i (void)
888130803Smarcel{
889130803Smarcel  /* Construct a type for the 64 bit registers.  The type we're
890130803Smarcel     building is this: */
891130803Smarcel#if 0
892130803Smarcel  union __gdb_builtin_type_vec64i
893130803Smarcel  {
894130803Smarcel    int64_t uint64;
895130803Smarcel    int32_t v2_int32[2];
896130803Smarcel    int16_t v4_int16[4];
897130803Smarcel    int8_t v8_int8[8];
898130803Smarcel  };
899130803Smarcel#endif
900130803Smarcel
901130803Smarcel  struct type *t;
902130803Smarcel
903130803Smarcel  t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
904130803Smarcel  append_composite_type_field (t, "uint64", builtin_type_int64);
905130803Smarcel  append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
906130803Smarcel  append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
907130803Smarcel  append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
908130803Smarcel
909130803Smarcel  TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
910130803Smarcel  TYPE_NAME (t) = "builtin_type_vec64i";
91198944Sobrien  return t;
91298944Sobrien}
91398944Sobrien
91498944Sobrienstatic struct type *
91598944Sobrienbuild_builtin_type_vec128 (void)
91698944Sobrien{
91798944Sobrien  /* Construct a type for the 128 bit registers.  The type we're
91898944Sobrien     building is this: */
91998944Sobrien#if 0
920130803Smarcel union __gdb_builtin_type_vec128
92198944Sobrien  {
922130803Smarcel    int128_t uint128;
923130803Smarcel    float v4_float[4];
924130803Smarcel    int32_t v4_int32[4];
925130803Smarcel    int16_t v8_int16[8];
926130803Smarcel    int8_t v16_int8[16];
92798944Sobrien  };
92898944Sobrien#endif
92998944Sobrien
93098944Sobrien  struct type *t;
93198944Sobrien
932130803Smarcel  t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
933130803Smarcel  append_composite_type_field (t, "uint128", builtin_type_int128);
934130803Smarcel  append_composite_type_field (t, "v4_float", builtin_type_v4_float);
935130803Smarcel  append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
936130803Smarcel  append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
937130803Smarcel  append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
93898944Sobrien
939130803Smarcel  TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
940130803Smarcel  TYPE_NAME (t) = "builtin_type_vec128";
941130803Smarcel  return t;
942130803Smarcel}
94398944Sobrien
944130803Smarcelstatic struct type *
945130803Smarcelbuild_builtin_type_vec128i (void)
946130803Smarcel{
947130803Smarcel  /* 128-bit Intel SIMD registers */
948130803Smarcel  struct type *t;
94998944Sobrien
950130803Smarcel  t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
951130803Smarcel  append_composite_type_field (t, "v4_float", builtin_type_v4_float);
952130803Smarcel  append_composite_type_field (t, "v2_double", builtin_type_v2_double);
953130803Smarcel  append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
954130803Smarcel  append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
955130803Smarcel  append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
956130803Smarcel  append_composite_type_field (t, "v2_int64", builtin_type_v2_int64);
957130803Smarcel  append_composite_type_field (t, "uint128", builtin_type_int128);
95898944Sobrien
959130803Smarcel  TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
960130803Smarcel  TYPE_NAME (t) = "builtin_type_vec128i";
96198944Sobrien  return t;
96298944Sobrien}
96398944Sobrien
96419370Spst/* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
96519370Spst   A MEMBER is a wierd thing -- it amounts to a typed offset into
96619370Spst   a struct, e.g. "an int at offset 8".  A MEMBER TYPE doesn't
96719370Spst   include the offset (that's the value of the MEMBER itself), but does
96819370Spst   include the structure type into which it points (for some reason).
96919370Spst
97019370Spst   When "smashing" the type, we preserve the objfile that the
97119370Spst   old type pointed to, since we aren't changing where the type is actually
97219370Spst   allocated.  */
97319370Spst
97419370Spstvoid
97598944Sobriensmash_to_member_type (struct type *type, struct type *domain,
97698944Sobrien		      struct type *to_type)
97719370Spst{
97819370Spst  struct objfile *objfile;
97919370Spst
98019370Spst  objfile = TYPE_OBJFILE (type);
98119370Spst
982130803Smarcel  smash_type (type);
98319370Spst  TYPE_OBJFILE (type) = objfile;
98419370Spst  TYPE_TARGET_TYPE (type) = to_type;
98519370Spst  TYPE_DOMAIN_TYPE (type) = domain;
98619370Spst  TYPE_LENGTH (type) = 1;	/* In practice, this is never needed.  */
98719370Spst  TYPE_CODE (type) = TYPE_CODE_MEMBER;
98819370Spst}
98919370Spst
99019370Spst/* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
99119370Spst   METHOD just means `function that gets an extra "this" argument'.
99219370Spst
99319370Spst   When "smashing" the type, we preserve the objfile that the
99419370Spst   old type pointed to, since we aren't changing where the type is actually
99519370Spst   allocated.  */
99619370Spst
99719370Spstvoid
99898944Sobriensmash_to_method_type (struct type *type, struct type *domain,
999130803Smarcel		      struct type *to_type, struct field *args,
1000130803Smarcel		      int nargs, int varargs)
100119370Spst{
100219370Spst  struct objfile *objfile;
100319370Spst
100419370Spst  objfile = TYPE_OBJFILE (type);
100519370Spst
1006130803Smarcel  smash_type (type);
100719370Spst  TYPE_OBJFILE (type) = objfile;
100819370Spst  TYPE_TARGET_TYPE (type) = to_type;
100919370Spst  TYPE_DOMAIN_TYPE (type) = domain;
1010130803Smarcel  TYPE_FIELDS (type) = args;
1011130803Smarcel  TYPE_NFIELDS (type) = nargs;
1012130803Smarcel  if (varargs)
1013130803Smarcel    TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
101419370Spst  TYPE_LENGTH (type) = 1;	/* In practice, this is never needed.  */
101519370Spst  TYPE_CODE (type) = TYPE_CODE_METHOD;
101619370Spst}
101719370Spst
101819370Spst/* Return a typename for a struct/union/enum type without "struct ",
101919370Spst   "union ", or "enum ".  If the type has a NULL name, return NULL.  */
102019370Spst
102119370Spstchar *
1022130803Smarceltype_name_no_tag (const struct type *type)
102319370Spst{
102419370Spst  if (TYPE_TAG_NAME (type) != NULL)
102519370Spst    return TYPE_TAG_NAME (type);
102619370Spst
102719370Spst  /* Is there code which expects this to return the name if there is no
102819370Spst     tag name?  My guess is that this is mainly used for C++ in cases where
102919370Spst     the two will always be the same.  */
103019370Spst  return TYPE_NAME (type);
103119370Spst}
103219370Spst
103319370Spst/* Lookup a primitive type named NAME.
103498944Sobrien   Return zero if NAME is not a primitive type. */
103519370Spst
103619370Spststruct type *
103798944Sobrienlookup_primitive_typename (char *name)
103819370Spst{
103998944Sobrien  struct type **const *p;
104019370Spst
104198944Sobrien  for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
104298944Sobrien    {
1043130803Smarcel      if (strcmp (TYPE_NAME (**p), name) == 0)
104498944Sobrien	{
104598944Sobrien	  return (**p);
104698944Sobrien	}
104798944Sobrien    }
104898944Sobrien  return (NULL);
104919370Spst}
105019370Spst
105119370Spst/* Lookup a typedef or primitive type named NAME,
105219370Spst   visible in lexical block BLOCK.
105319370Spst   If NOERR is nonzero, return zero if NAME is not suitably defined.  */
105419370Spst
105519370Spststruct type *
105698944Sobrienlookup_typename (char *name, struct block *block, int noerr)
105719370Spst{
1058130803Smarcel  struct symbol *sym;
1059130803Smarcel  struct type *tmp;
106019370Spst
1061130803Smarcel  sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
106219370Spst  if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
106319370Spst    {
106419370Spst      tmp = lookup_primitive_typename (name);
106519370Spst      if (tmp)
106619370Spst	{
106719370Spst	  return (tmp);
106819370Spst	}
106919370Spst      else if (!tmp && noerr)
107019370Spst	{
107119370Spst	  return (NULL);
107219370Spst	}
107319370Spst      else
107419370Spst	{
107519370Spst	  error ("No type named %s.", name);
107619370Spst	}
107719370Spst    }
107819370Spst  return (SYMBOL_TYPE (sym));
107919370Spst}
108019370Spst
108119370Spststruct type *
108298944Sobrienlookup_unsigned_typename (char *name)
108319370Spst{
108419370Spst  char *uns = alloca (strlen (name) + 10);
108519370Spst
108619370Spst  strcpy (uns, "unsigned ");
108719370Spst  strcpy (uns + 9, name);
108819370Spst  return (lookup_typename (uns, (struct block *) NULL, 0));
108919370Spst}
109019370Spst
109119370Spststruct type *
109298944Sobrienlookup_signed_typename (char *name)
109319370Spst{
109419370Spst  struct type *t;
109519370Spst  char *uns = alloca (strlen (name) + 8);
109619370Spst
109719370Spst  strcpy (uns, "signed ");
109819370Spst  strcpy (uns + 7, name);
109919370Spst  t = lookup_typename (uns, (struct block *) NULL, 1);
110019370Spst  /* If we don't find "signed FOO" just try again with plain "FOO". */
110119370Spst  if (t != NULL)
110219370Spst    return t;
110319370Spst  return lookup_typename (name, (struct block *) NULL, 0);
110419370Spst}
110519370Spst
110619370Spst/* Lookup a structure type named "struct NAME",
110719370Spst   visible in lexical block BLOCK.  */
110819370Spst
110919370Spststruct type *
111098944Sobrienlookup_struct (char *name, struct block *block)
111119370Spst{
1112130803Smarcel  struct symbol *sym;
111319370Spst
1114130803Smarcel  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
111519370Spst		       (struct symtab **) NULL);
111619370Spst
111719370Spst  if (sym == NULL)
111819370Spst    {
111919370Spst      error ("No struct type named %s.", name);
112019370Spst    }
112119370Spst  if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
112219370Spst    {
112319370Spst      error ("This context has class, union or enum %s, not a struct.", name);
112419370Spst    }
112519370Spst  return (SYMBOL_TYPE (sym));
112619370Spst}
112719370Spst
112819370Spst/* Lookup a union type named "union NAME",
112919370Spst   visible in lexical block BLOCK.  */
113019370Spst
113119370Spststruct type *
113298944Sobrienlookup_union (char *name, struct block *block)
113319370Spst{
1134130803Smarcel  struct symbol *sym;
113598944Sobrien  struct type *t;
113619370Spst
1137130803Smarcel  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
113819370Spst		       (struct symtab **) NULL);
113919370Spst
114019370Spst  if (sym == NULL)
114146283Sdfr    error ("No union type named %s.", name);
114246283Sdfr
114398944Sobrien  t = SYMBOL_TYPE (sym);
114446283Sdfr
114546283Sdfr  if (TYPE_CODE (t) == TYPE_CODE_UNION)
114646283Sdfr    return (t);
114746283Sdfr
114846283Sdfr  /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
114946283Sdfr   * a further "declared_type" field to discover it is really a union.
115046283Sdfr   */
115198944Sobrien  if (HAVE_CPLUS_STRUCT (t))
115298944Sobrien    if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
115346283Sdfr      return (t);
115446283Sdfr
115546283Sdfr  /* If we get here, it's not a union */
115646283Sdfr  error ("This context has class, struct or enum %s, not a union.", name);
115719370Spst}
115819370Spst
115946283Sdfr
116019370Spst/* Lookup an enum type named "enum NAME",
116119370Spst   visible in lexical block BLOCK.  */
116219370Spst
116319370Spststruct type *
116498944Sobrienlookup_enum (char *name, struct block *block)
116519370Spst{
1166130803Smarcel  struct symbol *sym;
116719370Spst
1168130803Smarcel  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
116919370Spst		       (struct symtab **) NULL);
117019370Spst  if (sym == NULL)
117119370Spst    {
117219370Spst      error ("No enum type named %s.", name);
117319370Spst    }
117419370Spst  if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
117519370Spst    {
117619370Spst      error ("This context has class, struct or union %s, not an enum.", name);
117719370Spst    }
117819370Spst  return (SYMBOL_TYPE (sym));
117919370Spst}
118019370Spst
118119370Spst/* Lookup a template type named "template NAME<TYPE>",
118219370Spst   visible in lexical block BLOCK.  */
118319370Spst
118419370Spststruct type *
118598944Sobrienlookup_template_type (char *name, struct type *type, struct block *block)
118619370Spst{
118719370Spst  struct symbol *sym;
1188130803Smarcel  char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
118919370Spst  strcpy (nam, name);
119019370Spst  strcat (nam, "<");
1191130803Smarcel  strcat (nam, TYPE_NAME (type));
119298944Sobrien  strcat (nam, " >");		/* FIXME, extra space still introduced in gcc? */
119319370Spst
1194130803Smarcel  sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL);
119519370Spst
119619370Spst  if (sym == NULL)
119719370Spst    {
119819370Spst      error ("No template type named %s.", name);
119919370Spst    }
120019370Spst  if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
120119370Spst    {
120219370Spst      error ("This context has class, union or enum %s, not a struct.", name);
120319370Spst    }
120419370Spst  return (SYMBOL_TYPE (sym));
120519370Spst}
120619370Spst
120719370Spst/* Given a type TYPE, lookup the type of the component of type named NAME.
120819370Spst
120919370Spst   TYPE can be either a struct or union, or a pointer or reference to a struct or
121019370Spst   union.  If it is a pointer or reference, its target type is automatically used.
121119370Spst   Thus '.' and '->' are interchangable, as specified for the definitions of the
121219370Spst   expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
121319370Spst
121419370Spst   If NOERR is nonzero, return zero if NAME is not suitably defined.
121519370Spst   If NAME is the name of a baseclass type, return that type.  */
121619370Spst
121719370Spststruct type *
121898944Sobrienlookup_struct_elt_type (struct type *type, char *name, int noerr)
121919370Spst{
122019370Spst  int i;
122119370Spst
122219370Spst  for (;;)
122319370Spst    {
122419370Spst      CHECK_TYPEDEF (type);
122519370Spst      if (TYPE_CODE (type) != TYPE_CODE_PTR
122619370Spst	  && TYPE_CODE (type) != TYPE_CODE_REF)
122719370Spst	break;
122819370Spst      type = TYPE_TARGET_TYPE (type);
122919370Spst    }
123019370Spst
123119370Spst  if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
123219370Spst      TYPE_CODE (type) != TYPE_CODE_UNION)
123319370Spst    {
123419370Spst      target_terminal_ours ();
123519370Spst      gdb_flush (gdb_stdout);
123619370Spst      fprintf_unfiltered (gdb_stderr, "Type ");
123719370Spst      type_print (type, "", gdb_stderr, -1);
123819370Spst      error (" is not a structure or union type.");
123919370Spst    }
124019370Spst
124119370Spst#if 0
124219370Spst  /* FIXME:  This change put in by Michael seems incorrect for the case where
124319370Spst     the structure tag name is the same as the member name.  I.E. when doing
124419370Spst     "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
124519370Spst     Disabled by fnf. */
124619370Spst  {
124719370Spst    char *typename;
124819370Spst
124919370Spst    typename = type_name_no_tag (type);
1250130803Smarcel    if (typename != NULL && strcmp (typename, name) == 0)
125119370Spst      return type;
125219370Spst  }
125319370Spst#endif
125419370Spst
125519370Spst  for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
125619370Spst    {
125719370Spst      char *t_field_name = TYPE_FIELD_NAME (type, i);
125819370Spst
125998944Sobrien      if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
126019370Spst	{
126119370Spst	  return TYPE_FIELD_TYPE (type, i);
126219370Spst	}
126319370Spst    }
126419370Spst
126519370Spst  /* OK, it's not in this class.  Recursively check the baseclasses.  */
126619370Spst  for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
126719370Spst    {
126819370Spst      struct type *t;
126919370Spst
127019370Spst      t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
127119370Spst      if (t != NULL)
127219370Spst	{
127319370Spst	  return t;
127419370Spst	}
127519370Spst    }
127619370Spst
127719370Spst  if (noerr)
127819370Spst    {
127919370Spst      return NULL;
128019370Spst    }
128198944Sobrien
128219370Spst  target_terminal_ours ();
128319370Spst  gdb_flush (gdb_stdout);
128419370Spst  fprintf_unfiltered (gdb_stderr, "Type ");
128519370Spst  type_print (type, "", gdb_stderr, -1);
128619370Spst  fprintf_unfiltered (gdb_stderr, " has no component named ");
128719370Spst  fputs_filtered (name, gdb_stderr);
128819370Spst  error (".");
128998944Sobrien  return (struct type *) -1;	/* For lint */
129019370Spst}
129119370Spst
129219370Spst/* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
129319370Spst   valid.  Callers should be aware that in some cases (for example,
129419370Spst   the type or one of its baseclasses is a stub type and we are
129519370Spst   debugging a .o file), this function will not be able to find the virtual
129619370Spst   function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
129719370Spst   will remain NULL.  */
129819370Spst
129919370Spstvoid
130098944Sobrienfill_in_vptr_fieldno (struct type *type)
130119370Spst{
130219370Spst  CHECK_TYPEDEF (type);
130319370Spst
130419370Spst  if (TYPE_VPTR_FIELDNO (type) < 0)
130519370Spst    {
130619370Spst      int i;
130719370Spst
130819370Spst      /* We must start at zero in case the first (and only) baseclass is
130998944Sobrien         virtual (and hence we cannot share the table pointer).  */
131019370Spst      for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
131119370Spst	{
1312130803Smarcel	  struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1313130803Smarcel	  fill_in_vptr_fieldno (baseclass);
1314130803Smarcel	  if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
131519370Spst	    {
1316130803Smarcel	      TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
1317130803Smarcel	      TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
131819370Spst	      break;
131919370Spst	    }
132019370Spst	}
132119370Spst    }
132219370Spst}
132319370Spst
132446283Sdfr/* Find the method and field indices for the destructor in class type T.
132546283Sdfr   Return 1 if the destructor was found, otherwise, return 0.  */
132646283Sdfr
132746283Sdfrint
132898944Sobrienget_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
132946283Sdfr{
133046283Sdfr  int i;
133146283Sdfr
133246283Sdfr  for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
133346283Sdfr    {
133446283Sdfr      int j;
133546283Sdfr      struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
133646283Sdfr
133746283Sdfr      for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
133846283Sdfr	{
133998944Sobrien	  if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
134046283Sdfr	    {
134146283Sdfr	      *method_indexp = i;
134246283Sdfr	      *field_indexp = j;
134346283Sdfr	      return 1;
134446283Sdfr	    }
134546283Sdfr	}
134646283Sdfr    }
134746283Sdfr  return 0;
134846283Sdfr}
134946283Sdfr
1350130803Smarcelstatic void
1351130803Smarcelstub_noname_complaint (void)
1352130803Smarcel{
1353130803Smarcel  complaint (&symfile_complaints, "stub type has NULL name");
1354130803Smarcel}
1355130803Smarcel
135619370Spst/* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
135719370Spst
135819370Spst   If this is a stubbed struct (i.e. declared as struct foo *), see if
135919370Spst   we can find a full definition in some other file. If so, copy this
136019370Spst   definition, so we can use it in future.  There used to be a comment (but
136119370Spst   not any code) that if we don't find a full definition, we'd set a flag
136219370Spst   so we don't spend time in the future checking the same type.  That would
136319370Spst   be a mistake, though--we might load in more symbols which contain a
136419370Spst   full definition for the type.
136519370Spst
136619370Spst   This used to be coded as a macro, but I don't think it is called
136719370Spst   often enough to merit such treatment.  */
136819370Spst
1369130803Smarcel/* Find the real type of TYPE.  This function returns the real type, after
1370130803Smarcel   removing all layers of typedefs and completing opaque or stub types.
1371130803Smarcel   Completion changes the TYPE argument, but stripping of typedefs does
1372130803Smarcel   not.  */
137319370Spst
137419370Spststruct type *
137598944Sobriencheck_typedef (struct type *type)
137619370Spst{
137719370Spst  struct type *orig_type = type;
1378256851Semaste  int is_const, is_volatile, is_restrict;
137998944Sobrien
138019370Spst  while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
138119370Spst    {
138219370Spst      if (!TYPE_TARGET_TYPE (type))
138319370Spst	{
138498944Sobrien	  char *name;
138519370Spst	  struct symbol *sym;
138619370Spst
138719370Spst	  /* It is dangerous to call lookup_symbol if we are currently
138819370Spst	     reading a symtab.  Infinite recursion is one danger. */
138919370Spst	  if (currently_reading_symtab)
139019370Spst	    return type;
139119370Spst
139219370Spst	  name = type_name_no_tag (type);
139319370Spst	  /* FIXME: shouldn't we separately check the TYPE_NAME and the
1394130803Smarcel	     TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
139519370Spst	     as appropriate?  (this code was written before TYPE_NAME and
139619370Spst	     TYPE_TAG_NAME were separate).  */
139719370Spst	  if (name == NULL)
139819370Spst	    {
1399130803Smarcel	      stub_noname_complaint ();
140019370Spst	      return type;
140119370Spst	    }
1402130803Smarcel	  sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
140319370Spst			       (struct symtab **) NULL);
140419370Spst	  if (sym)
140519370Spst	    TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
140619370Spst	  else
140798944Sobrien	    TYPE_TARGET_TYPE (type) = alloc_type (NULL);	/* TYPE_CODE_UNDEF */
140819370Spst	}
140919370Spst      type = TYPE_TARGET_TYPE (type);
141019370Spst    }
141119370Spst
141298944Sobrien  is_const = TYPE_CONST (type);
141398944Sobrien  is_volatile = TYPE_VOLATILE (type);
1414256851Semaste  is_restrict = TYPE_RESTRICT (type);
141598944Sobrien
141646283Sdfr  /* If this is a struct/class/union with no fields, then check whether a
141746283Sdfr     full definition exists somewhere else.  This is for systems where a
141846283Sdfr     type definition with no fields is issued for such types, instead of
141998944Sobrien     identifying them as stub types in the first place */
142098944Sobrien
142146283Sdfr  if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
142219370Spst    {
142398944Sobrien      char *name = type_name_no_tag (type);
142498944Sobrien      struct type *newtype;
142546283Sdfr      if (name == NULL)
142646283Sdfr	{
1427130803Smarcel	  stub_noname_complaint ();
142846283Sdfr	  return type;
142946283Sdfr	}
143046283Sdfr      newtype = lookup_transparent_type (name);
143146283Sdfr      if (newtype)
1432256851Semaste	make_cvr_type (is_const, is_volatile, is_restrict, newtype, &type);
143346283Sdfr    }
143446283Sdfr  /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
143598944Sobrien  else if (TYPE_STUB (type) && !currently_reading_symtab)
143646283Sdfr    {
143798944Sobrien      char *name = type_name_no_tag (type);
143819370Spst      /* FIXME: shouldn't we separately check the TYPE_NAME and the
1439130803Smarcel         TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
144098944Sobrien         as appropriate?  (this code was written before TYPE_NAME and
144198944Sobrien         TYPE_TAG_NAME were separate).  */
144219370Spst      struct symbol *sym;
144319370Spst      if (name == NULL)
144419370Spst	{
1445130803Smarcel	  stub_noname_complaint ();
144619370Spst	  return type;
144719370Spst	}
1448130803Smarcel      sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL);
144919370Spst      if (sym)
1450256851Semaste	make_cvr_type (is_const, is_volatile, is_restrict, SYMBOL_TYPE (sym),
1451256851Semaste                       &type);
145219370Spst    }
145319370Spst
145498944Sobrien  if (TYPE_TARGET_STUB (type))
145519370Spst    {
145619370Spst      struct type *range_type;
145719370Spst      struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
145819370Spst
145998944Sobrien      if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
146098944Sobrien	{
146198944Sobrien	}
146219370Spst      else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
146319370Spst	       && TYPE_NFIELDS (type) == 1
146419370Spst	       && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
146519370Spst		   == TYPE_CODE_RANGE))
146619370Spst	{
146719370Spst	  /* Now recompute the length of the array type, based on its
146819370Spst	     number of elements and the target type's length.  */
146919370Spst	  TYPE_LENGTH (type) =
147019370Spst	    ((TYPE_FIELD_BITPOS (range_type, 1)
147119370Spst	      - TYPE_FIELD_BITPOS (range_type, 0)
147219370Spst	      + 1)
147319370Spst	     * TYPE_LENGTH (target_type));
147419370Spst	  TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
147519370Spst	}
147619370Spst      else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
147719370Spst	{
147819370Spst	  TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
147919370Spst	  TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
148019370Spst	}
148119370Spst    }
148219370Spst  /* Cache TYPE_LENGTH for future use. */
148319370Spst  TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
148419370Spst  return type;
148519370Spst}
148619370Spst
148798944Sobrien/* Parse a type expression in the string [P..P+LENGTH).  If an error occurs,
148898944Sobrien   silently return builtin_type_void. */
148998944Sobrien
1490130803Smarcelstatic struct type *
149198944Sobriensafe_parse_type (char *p, int length)
149298944Sobrien{
149398944Sobrien  struct ui_file *saved_gdb_stderr;
149498944Sobrien  struct type *type;
149598944Sobrien
149698944Sobrien  /* Suppress error messages. */
149798944Sobrien  saved_gdb_stderr = gdb_stderr;
149898944Sobrien  gdb_stderr = ui_file_new ();
149998944Sobrien
150098944Sobrien  /* Call parse_and_eval_type() without fear of longjmp()s. */
150198944Sobrien  if (!gdb_parse_and_eval_type (p, length, &type))
150298944Sobrien    type = builtin_type_void;
150398944Sobrien
150498944Sobrien  /* Stop suppressing error messages. */
150598944Sobrien  ui_file_delete (gdb_stderr);
150698944Sobrien  gdb_stderr = saved_gdb_stderr;
150798944Sobrien
150898944Sobrien  return type;
150998944Sobrien}
151098944Sobrien
151119370Spst/* Ugly hack to convert method stubs into method types.
151219370Spst
151319370Spst   He ain't kiddin'.  This demangles the name of the method into a string
151419370Spst   including argument types, parses out each argument type, generates
151519370Spst   a string casting a zero to that type, evaluates the string, and stuffs
151619370Spst   the resulting type into an argtype vector!!!  Then it knows the type
151719370Spst   of the whole function (including argument types for overloading),
151819370Spst   which info used to be in the stab's but was removed to hack back
151919370Spst   the space required for them.  */
152019370Spst
1521130803Smarcelstatic void
152298944Sobriencheck_stub_method (struct type *type, int method_id, int signature_id)
152319370Spst{
152419370Spst  struct fn_field *f;
152546283Sdfr  char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
152619370Spst  char *demangled_name = cplus_demangle (mangled_name,
152719370Spst					 DMGL_PARAMS | DMGL_ANSI);
152819370Spst  char *argtypetext, *p;
152919370Spst  int depth = 0, argcount = 1;
1530130803Smarcel  struct field *argtypes;
153119370Spst  struct type *mtype;
153219370Spst
153319370Spst  /* Make sure we got back a function string that we can use.  */
153419370Spst  if (demangled_name)
153519370Spst    p = strchr (demangled_name, '(');
153698944Sobrien  else
153798944Sobrien    p = NULL;
153819370Spst
153919370Spst  if (demangled_name == NULL || p == NULL)
154019370Spst    error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
154119370Spst
154219370Spst  /* Now, read in the parameters that define this type.  */
154319370Spst  p += 1;
154419370Spst  argtypetext = p;
154519370Spst  while (*p)
154619370Spst    {
154798944Sobrien      if (*p == '(' || *p == '<')
154819370Spst	{
154919370Spst	  depth += 1;
155019370Spst	}
155198944Sobrien      else if (*p == ')' || *p == '>')
155219370Spst	{
155319370Spst	  depth -= 1;
155419370Spst	}
155519370Spst      else if (*p == ',' && depth == 0)
155619370Spst	{
155719370Spst	  argcount += 1;
155819370Spst	}
155919370Spst
156019370Spst      p += 1;
156119370Spst    }
156219370Spst
1563130803Smarcel  /* If we read one argument and it was ``void'', don't count it.  */
1564130803Smarcel  if (strncmp (argtypetext, "(void)", 6) == 0)
1565130803Smarcel    argcount -= 1;
156619370Spst
1567130803Smarcel  /* We need one extra slot, for the THIS pointer.  */
1568130803Smarcel
1569130803Smarcel  argtypes = (struct field *)
1570130803Smarcel    TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
157119370Spst  p = argtypetext;
157219370Spst
1573130803Smarcel  /* Add THIS pointer for non-static methods.  */
1574130803Smarcel  f = TYPE_FN_FIELDLIST1 (type, method_id);
1575130803Smarcel  if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
1576130803Smarcel    argcount = 0;
1577130803Smarcel  else
1578130803Smarcel    {
1579130803Smarcel      argtypes[0].type = lookup_pointer_type (type);
1580130803Smarcel      argcount = 1;
1581130803Smarcel    }
1582130803Smarcel
158398944Sobrien  if (*p != ')')		/* () means no args, skip while */
158419370Spst    {
158519370Spst      depth = 0;
158619370Spst      while (*p)
158719370Spst	{
158819370Spst	  if (depth <= 0 && (*p == ',' || *p == ')'))
158919370Spst	    {
1590130803Smarcel	      /* Avoid parsing of ellipsis, they will be handled below.
1591130803Smarcel	         Also avoid ``void'' as above.  */
1592130803Smarcel	      if (strncmp (argtypetext, "...", p - argtypetext) != 0
1593130803Smarcel		  && strncmp (argtypetext, "void", p - argtypetext) != 0)
159419370Spst		{
1595130803Smarcel		  argtypes[argcount].type =
159698944Sobrien		    safe_parse_type (argtypetext, p - argtypetext);
159719370Spst		  argcount += 1;
159819370Spst		}
159919370Spst	      argtypetext = p + 1;
160019370Spst	    }
160119370Spst
160298944Sobrien	  if (*p == '(' || *p == '<')
160319370Spst	    {
160419370Spst	      depth += 1;
160519370Spst	    }
160698944Sobrien	  else if (*p == ')' || *p == '>')
160719370Spst	    {
160819370Spst	      depth -= 1;
160919370Spst	    }
161019370Spst
161119370Spst	  p += 1;
161219370Spst	}
161319370Spst    }
161419370Spst
161546283Sdfr  TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
161646283Sdfr
161719370Spst  /* Now update the old "stub" type into a real type.  */
161846283Sdfr  mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
161919370Spst  TYPE_DOMAIN_TYPE (mtype) = type;
1620130803Smarcel  TYPE_FIELDS (mtype) = argtypes;
1621130803Smarcel  TYPE_NFIELDS (mtype) = argcount;
162219370Spst  TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
162346283Sdfr  TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1624130803Smarcel  if (p[-2] == '.')
1625130803Smarcel    TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
1626130803Smarcel
1627130803Smarcel  xfree (demangled_name);
162819370Spst}
162919370Spst
1630130803Smarcel/* This is the external interface to check_stub_method, above.  This function
1631130803Smarcel   unstubs all of the signatures for TYPE's METHOD_ID method name.  After
1632130803Smarcel   calling this function TYPE_FN_FIELD_STUB will be cleared for each signature
1633130803Smarcel   and TYPE_FN_FIELDLIST_NAME will be correct.
1634130803Smarcel
1635130803Smarcel   This function unfortunately can not die until stabs do.  */
1636130803Smarcel
1637130803Smarcelvoid
1638130803Smarcelcheck_stub_method_group (struct type *type, int method_id)
1639130803Smarcel{
1640130803Smarcel  int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
1641130803Smarcel  struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
1642130803Smarcel  int j, found_stub = 0;
1643130803Smarcel
1644130803Smarcel  for (j = 0; j < len; j++)
1645130803Smarcel    if (TYPE_FN_FIELD_STUB (f, j))
1646130803Smarcel      {
1647130803Smarcel	found_stub = 1;
1648130803Smarcel	check_stub_method (type, method_id, j);
1649130803Smarcel      }
1650130803Smarcel
1651130803Smarcel  /* GNU v3 methods with incorrect names were corrected when we read in
1652130803Smarcel     type information, because it was cheaper to do it then.  The only GNU v2
1653130803Smarcel     methods with incorrect method names are operators and destructors;
1654130803Smarcel     destructors were also corrected when we read in type information.
1655130803Smarcel
1656130803Smarcel     Therefore the only thing we need to handle here are v2 operator
1657130803Smarcel     names.  */
1658130803Smarcel  if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
1659130803Smarcel    {
1660130803Smarcel      int ret;
1661130803Smarcel      char dem_opname[256];
1662130803Smarcel
1663130803Smarcel      ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1664130803Smarcel				   dem_opname, DMGL_ANSI);
1665130803Smarcel      if (!ret)
1666130803Smarcel	ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id),
1667130803Smarcel				     dem_opname, 0);
1668130803Smarcel      if (ret)
1669130803Smarcel	TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
1670130803Smarcel    }
1671130803Smarcel}
1672130803Smarcel
167319370Spstconst struct cplus_struct_type cplus_struct_default;
167419370Spst
167519370Spstvoid
167698944Sobrienallocate_cplus_struct_type (struct type *type)
167719370Spst{
167819370Spst  if (!HAVE_CPLUS_STRUCT (type))
167919370Spst    {
168019370Spst      TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
168119370Spst	TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
168298944Sobrien      *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
168319370Spst    }
168419370Spst}
168519370Spst
168619370Spst/* Helper function to initialize the standard scalar types.
168719370Spst
168819370Spst   If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1689130803Smarcel   of the string pointed to by name in the objfile_obstack for that objfile,
169019370Spst   and initialize the type name to that copy.  There are places (mipsread.c
169119370Spst   in particular, where init_type is called with a NULL value for NAME). */
169219370Spst
169319370Spststruct type *
169498944Sobrieninit_type (enum type_code code, int length, int flags, char *name,
169598944Sobrien	   struct objfile *objfile)
169619370Spst{
1697130803Smarcel  struct type *type;
169819370Spst
169919370Spst  type = alloc_type (objfile);
170019370Spst  TYPE_CODE (type) = code;
170119370Spst  TYPE_LENGTH (type) = length;
170219370Spst  TYPE_FLAGS (type) |= flags;
170319370Spst  if ((name != NULL) && (objfile != NULL))
170419370Spst    {
170519370Spst      TYPE_NAME (type) =
1706130803Smarcel	obsavestring (name, strlen (name), &objfile->objfile_obstack);
170719370Spst    }
170819370Spst  else
170919370Spst    {
171019370Spst      TYPE_NAME (type) = name;
171119370Spst    }
171219370Spst
171319370Spst  /* C++ fancies.  */
171419370Spst
1715130803Smarcel  if (name && strcmp (name, "char") == 0)
1716130803Smarcel    TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
1717130803Smarcel
1718130803Smarcel  if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
1719130803Smarcel      || code == TYPE_CODE_NAMESPACE)
172019370Spst    {
172119370Spst      INIT_CPLUS_SPECIFIC (type);
172219370Spst    }
172319370Spst  return (type);
172419370Spst}
172519370Spst
1726130803Smarcel/* Helper function.  Create an empty composite type.  */
1727130803Smarcel
1728130803Smarcelstruct type *
1729130803Smarcelinit_composite_type (char *name, enum type_code code)
1730130803Smarcel{
1731130803Smarcel  struct type *t;
1732130803Smarcel  gdb_assert (code == TYPE_CODE_STRUCT
1733130803Smarcel	      || code == TYPE_CODE_UNION);
1734130803Smarcel  t = init_type (code, 0, 0, NULL, NULL);
1735130803Smarcel  TYPE_TAG_NAME (t) = name;
1736130803Smarcel  return t;
1737130803Smarcel}
1738130803Smarcel
1739130803Smarcel/* Helper function.  Append a field to a composite type.  */
1740130803Smarcel
1741130803Smarcelvoid
1742130803Smarcelappend_composite_type_field (struct type *t, char *name, struct type *field)
1743130803Smarcel{
1744130803Smarcel  struct field *f;
1745130803Smarcel  TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
1746130803Smarcel  TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
1747130803Smarcel			      sizeof (struct field) * TYPE_NFIELDS (t));
1748130803Smarcel  f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
1749130803Smarcel  memset (f, 0, sizeof f[0]);
1750130803Smarcel  FIELD_TYPE (f[0]) = field;
1751130803Smarcel  FIELD_NAME (f[0]) = name;
1752130803Smarcel  if (TYPE_CODE (t) == TYPE_CODE_UNION)
1753130803Smarcel    {
1754130803Smarcel      if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
1755130803Smarcel	TYPE_LENGTH (t) = TYPE_LENGTH (field);
1756130803Smarcel    }
1757130803Smarcel  else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
1758130803Smarcel    {
1759130803Smarcel      TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
1760130803Smarcel      if (TYPE_NFIELDS (t) > 1)
1761130803Smarcel	{
1762130803Smarcel	  FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
1763130803Smarcel				 + TYPE_LENGTH (field) * TARGET_CHAR_BIT);
1764130803Smarcel	}
1765130803Smarcel    }
1766130803Smarcel}
1767130803Smarcel
176819370Spst/* Look up a fundamental type for the specified objfile.
176919370Spst   May need to construct such a type if this is the first use.
177019370Spst
177119370Spst   Some object file formats (ELF, COFF, etc) do not define fundamental
177219370Spst   types such as "int" or "double".  Others (stabs for example), do
177319370Spst   define fundamental types.
177419370Spst
177519370Spst   For the formats which don't provide fundamental types, gdb can create
177619370Spst   such types, using defaults reasonable for the current language and
177719370Spst   the current target machine.
177819370Spst
177919370Spst   NOTE:  This routine is obsolescent.  Each debugging format reader
178019370Spst   should manage it's own fundamental types, either creating them from
178119370Spst   suitable defaults or reading them from the debugging information,
178219370Spst   whichever is appropriate.  The DWARF reader has already been
178319370Spst   fixed to do this.  Once the other readers are fixed, this routine
178419370Spst   will go away.  Also note that fundamental types should be managed
178519370Spst   on a compilation unit basis in a multi-language environment, not
178619370Spst   on a linkage unit basis as is done here. */
178719370Spst
178819370Spst
178919370Spststruct type *
179098944Sobrienlookup_fundamental_type (struct objfile *objfile, int typeid)
179119370Spst{
1792130803Smarcel  struct type **typep;
1793130803Smarcel  int nbytes;
179419370Spst
179519370Spst  if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
179619370Spst    {
179719370Spst      error ("internal error - invalid fundamental type id %d", typeid);
179819370Spst    }
179919370Spst
180019370Spst  /* If this is the first time we need a fundamental type for this objfile
180119370Spst     then we need to initialize the vector of type pointers. */
180298944Sobrien
180398944Sobrien  if (objfile->fundamental_types == NULL)
180419370Spst    {
180519370Spst      nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
180698944Sobrien      objfile->fundamental_types = (struct type **)
1807130803Smarcel	obstack_alloc (&objfile->objfile_obstack, nbytes);
180898944Sobrien      memset ((char *) objfile->fundamental_types, 0, nbytes);
180919370Spst      OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
181019370Spst    }
181119370Spst
181219370Spst  /* Look for this particular type in the fundamental type vector.  If one is
181319370Spst     not found, create and install one appropriate for the current language. */
181419370Spst
181598944Sobrien  typep = objfile->fundamental_types + typeid;
181619370Spst  if (*typep == NULL)
181719370Spst    {
181819370Spst      *typep = create_fundamental_type (objfile, typeid);
181919370Spst    }
182019370Spst
182119370Spst  return (*typep);
182219370Spst}
182319370Spst
182419370Spstint
182598944Sobriencan_dereference (struct type *t)
182619370Spst{
182719370Spst  /* FIXME: Should we return true for references as well as pointers?  */
182819370Spst  CHECK_TYPEDEF (t);
182919370Spst  return
183019370Spst    (t != NULL
183119370Spst     && TYPE_CODE (t) == TYPE_CODE_PTR
183219370Spst     && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
183319370Spst}
183419370Spst
183598944Sobrienint
183698944Sobrienis_integral_type (struct type *t)
183798944Sobrien{
183898944Sobrien  CHECK_TYPEDEF (t);
183998944Sobrien  return
184098944Sobrien    ((t != NULL)
184198944Sobrien     && ((TYPE_CODE (t) == TYPE_CODE_INT)
184298944Sobrien	 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
184398944Sobrien	 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
184498944Sobrien	 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
184598944Sobrien	 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
184698944Sobrien}
184798944Sobrien
184846283Sdfr/* Check whether BASE is an ancestor or base class or DCLASS
184946283Sdfr   Return 1 if so, and 0 if not.
185046283Sdfr   Note: callers may want to check for identity of the types before
185146283Sdfr   calling this function -- identical types are considered to satisfy
185246283Sdfr   the ancestor relationship even if they're identical */
185346283Sdfr
185446283Sdfrint
185598944Sobrienis_ancestor (struct type *base, struct type *dclass)
185646283Sdfr{
185746283Sdfr  int i;
185898944Sobrien
185946283Sdfr  CHECK_TYPEDEF (base);
186046283Sdfr  CHECK_TYPEDEF (dclass);
186146283Sdfr
186246283Sdfr  if (base == dclass)
186346283Sdfr    return 1;
186498944Sobrien  if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
186598944Sobrien      !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
186698944Sobrien    return 1;
186746283Sdfr
186846283Sdfr  for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
186946283Sdfr    if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
187046283Sdfr      return 1;
187146283Sdfr
187246283Sdfr  return 0;
187346283Sdfr}
187446283Sdfr
187546283Sdfr
187646283Sdfr
187746283Sdfr/* See whether DCLASS has a virtual table.  This routine is aimed at
187846283Sdfr   the HP/Taligent ANSI C++ runtime model, and may not work with other
187946283Sdfr   runtime models.  Return 1 => Yes, 0 => No.  */
188046283Sdfr
188146283Sdfrint
188298944Sobrienhas_vtable (struct type *dclass)
188346283Sdfr{
188446283Sdfr  /* In the HP ANSI C++ runtime model, a class has a vtable only if it
188546283Sdfr     has virtual functions or virtual bases.  */
188646283Sdfr
1887130803Smarcel  int i;
188846283Sdfr
188998944Sobrien  if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
189046283Sdfr    return 0;
189198944Sobrien
189246283Sdfr  /* First check for the presence of virtual bases */
189398944Sobrien  if (TYPE_FIELD_VIRTUAL_BITS (dclass))
189498944Sobrien    for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
189598944Sobrien      if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
189698944Sobrien	return 1;
189798944Sobrien
189846283Sdfr  /* Next check for virtual functions */
189998944Sobrien  if (TYPE_FN_FIELDLISTS (dclass))
190098944Sobrien    for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
190198944Sobrien      if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
190298944Sobrien	return 1;
190346283Sdfr
190498944Sobrien  /* Recurse on non-virtual bases to see if any of them needs a vtable */
190598944Sobrien  if (TYPE_FIELD_VIRTUAL_BITS (dclass))
190698944Sobrien    for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
190798944Sobrien      if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
190898944Sobrien	  (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
190946283Sdfr	return 1;
191098944Sobrien
191198944Sobrien  /* Well, maybe we don't need a virtual table */
191246283Sdfr  return 0;
191346283Sdfr}
191446283Sdfr
191546283Sdfr/* Return a pointer to the "primary base class" of DCLASS.
191698944Sobrien
191746283Sdfr   A NULL return indicates that DCLASS has no primary base, or that it
191846283Sdfr   couldn't be found (insufficient information).
191998944Sobrien
192046283Sdfr   This routine is aimed at the HP/Taligent ANSI C++ runtime model,
192146283Sdfr   and may not work with other runtime models.  */
192246283Sdfr
192346283Sdfrstruct type *
192498944Sobrienprimary_base_class (struct type *dclass)
192546283Sdfr{
192646283Sdfr  /* In HP ANSI C++'s runtime model, a "primary base class" of a class
192746283Sdfr     is the first directly inherited, non-virtual base class that
192846283Sdfr     requires a virtual table */
192946283Sdfr
1930130803Smarcel  int i;
193146283Sdfr
193298944Sobrien  if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
193346283Sdfr    return NULL;
193446283Sdfr
193598944Sobrien  for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
193698944Sobrien    if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
193798944Sobrien	has_vtable (TYPE_FIELD_TYPE (dclass, i)))
193898944Sobrien      return TYPE_FIELD_TYPE (dclass, i);
193946283Sdfr
194046283Sdfr  return NULL;
194146283Sdfr}
194246283Sdfr
194346283Sdfr/* Global manipulated by virtual_base_list[_aux]() */
194446283Sdfr
194598944Sobrienstatic struct vbase *current_vbase_list = NULL;
194646283Sdfr
194746283Sdfr/* Return a pointer to a null-terminated list of struct vbase
194846283Sdfr   items. The vbasetype pointer of each item in the list points to the
194946283Sdfr   type information for a virtual base of the argument DCLASS.
195098944Sobrien
195146283Sdfr   Helper function for virtual_base_list().
195246283Sdfr   Note: the list goes backward, right-to-left. virtual_base_list()
195346283Sdfr   copies the items out in reverse order.  */
195446283Sdfr
195598944Sobrienstatic void
195698944Sobrienvirtual_base_list_aux (struct type *dclass)
195746283Sdfr{
195898944Sobrien  struct vbase *tmp_vbase;
1959130803Smarcel  int i;
196046283Sdfr
196198944Sobrien  if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
196298944Sobrien    return;
196346283Sdfr
196446283Sdfr  for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
196546283Sdfr    {
196646283Sdfr      /* Recurse on this ancestor, first */
196798944Sobrien      virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
196846283Sdfr
196946283Sdfr      /* If this current base is itself virtual, add it to the list */
197098944Sobrien      if (BASETYPE_VIA_VIRTUAL (dclass, i))
197198944Sobrien	{
197298944Sobrien	  struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
197346283Sdfr
197498944Sobrien	  /* Check if base already recorded */
197598944Sobrien	  tmp_vbase = current_vbase_list;
197698944Sobrien	  while (tmp_vbase)
197798944Sobrien	    {
197898944Sobrien	      if (tmp_vbase->vbasetype == basetype)
197998944Sobrien		break;		/* found it */
198098944Sobrien	      tmp_vbase = tmp_vbase->next;
198198944Sobrien	    }
198246283Sdfr
198398944Sobrien	  if (!tmp_vbase)	/* normal exit from loop */
198498944Sobrien	    {
198598944Sobrien	      /* Allocate new item for this virtual base */
198698944Sobrien	      tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
198798944Sobrien
198898944Sobrien	      /* Stick it on at the end of the list */
198998944Sobrien	      tmp_vbase->vbasetype = basetype;
199098944Sobrien	      tmp_vbase->next = current_vbase_list;
199198944Sobrien	      current_vbase_list = tmp_vbase;
199298944Sobrien	    }
199398944Sobrien	}			/* if virtual */
199498944Sobrien    }				/* for loop over bases */
199546283Sdfr}
199646283Sdfr
199746283Sdfr
199846283Sdfr/* Compute the list of virtual bases in the right order.  Virtual
199946283Sdfr   bases are laid out in the object's memory area in order of their
200046283Sdfr   occurrence in a depth-first, left-to-right search through the
200146283Sdfr   ancestors.
200298944Sobrien
200346283Sdfr   Argument DCLASS is the type whose virtual bases are required.
200446283Sdfr   Return value is the address of a null-terminated array of pointers
200546283Sdfr   to struct type items.
200698944Sobrien
200746283Sdfr   This routine is aimed at the HP/Taligent ANSI C++ runtime model,
200846283Sdfr   and may not work with other runtime models.
200998944Sobrien
201046283Sdfr   This routine merely hands off the argument to virtual_base_list_aux()
201146283Sdfr   and then copies the result into an array to save space.  */
201246283Sdfr
201346283Sdfrstruct type **
201498944Sobrienvirtual_base_list (struct type *dclass)
201546283Sdfr{
2016130803Smarcel  struct vbase *tmp_vbase;
2017130803Smarcel  struct vbase *tmp_vbase_2;
2018130803Smarcel  int i;
201946283Sdfr  int count;
202098944Sobrien  struct type **vbase_array;
202146283Sdfr
202246283Sdfr  current_vbase_list = NULL;
202398944Sobrien  virtual_base_list_aux (dclass);
202446283Sdfr
202598944Sobrien  for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
202646283Sdfr    /* no body */ ;
202746283Sdfr
202846283Sdfr  count = i;
202946283Sdfr
203098944Sobrien  vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
203146283Sdfr
203298944Sobrien  for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
203346283Sdfr    vbase_array[i] = tmp_vbase->vbasetype;
203446283Sdfr
203546283Sdfr  /* Get rid of constructed chain */
203646283Sdfr  tmp_vbase_2 = tmp_vbase = current_vbase_list;
203746283Sdfr  while (tmp_vbase)
203846283Sdfr    {
203946283Sdfr      tmp_vbase = tmp_vbase->next;
204098944Sobrien      xfree (tmp_vbase_2);
204146283Sdfr      tmp_vbase_2 = tmp_vbase;
204246283Sdfr    }
204398944Sobrien
204446283Sdfr  vbase_array[count] = NULL;
204546283Sdfr  return vbase_array;
204646283Sdfr}
204746283Sdfr
204846283Sdfr/* Return the length of the virtual base list of the type DCLASS.  */
204946283Sdfr
205046283Sdfrint
205198944Sobrienvirtual_base_list_length (struct type *dclass)
205246283Sdfr{
2053130803Smarcel  int i;
2054130803Smarcel  struct vbase *tmp_vbase;
205598944Sobrien
205646283Sdfr  current_vbase_list = NULL;
205798944Sobrien  virtual_base_list_aux (dclass);
205846283Sdfr
205998944Sobrien  for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
206046283Sdfr    /* no body */ ;
206146283Sdfr  return i;
206246283Sdfr}
206346283Sdfr
206446283Sdfr/* Return the number of elements of the virtual base list of the type
206546283Sdfr   DCLASS, ignoring those appearing in the primary base (and its
206646283Sdfr   primary base, recursively).  */
206746283Sdfr
206846283Sdfrint
206998944Sobrienvirtual_base_list_length_skip_primaries (struct type *dclass)
207046283Sdfr{
2071130803Smarcel  int i;
2072130803Smarcel  struct vbase *tmp_vbase;
207398944Sobrien  struct type *primary;
207446283Sdfr
207546283Sdfr  primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
207646283Sdfr
207746283Sdfr  if (!primary)
207846283Sdfr    return virtual_base_list_length (dclass);
207946283Sdfr
208046283Sdfr  current_vbase_list = NULL;
208198944Sobrien  virtual_base_list_aux (dclass);
208246283Sdfr
208398944Sobrien  for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
208446283Sdfr    {
208546283Sdfr      if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
208698944Sobrien	continue;
208746283Sdfr      i++;
208846283Sdfr    }
208946283Sdfr  return i;
209046283Sdfr}
209146283Sdfr
209246283Sdfr
209346283Sdfr/* Return the index (position) of type BASE, which is a virtual base
209446283Sdfr   class of DCLASS, in the latter's virtual base list.  A return of -1
209546283Sdfr   indicates "not found" or a problem.  */
209646283Sdfr
209746283Sdfrint
209898944Sobrienvirtual_base_index (struct type *base, struct type *dclass)
209946283Sdfr{
2100130803Smarcel  struct type *vbase;
2101130803Smarcel  int i;
210246283Sdfr
210398944Sobrien  if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
210498944Sobrien      (TYPE_CODE (base) != TYPE_CODE_CLASS))
210546283Sdfr    return -1;
210646283Sdfr
210746283Sdfr  i = 0;
210898944Sobrien  vbase = virtual_base_list (dclass)[0];
210946283Sdfr  while (vbase)
211046283Sdfr    {
211146283Sdfr      if (vbase == base)
211298944Sobrien	break;
211398944Sobrien      vbase = virtual_base_list (dclass)[++i];
211446283Sdfr    }
211546283Sdfr
211646283Sdfr  return vbase ? i : -1;
211746283Sdfr}
211846283Sdfr
211946283Sdfr
212046283Sdfr
212146283Sdfr/* Return the index (position) of type BASE, which is a virtual base
212246283Sdfr   class of DCLASS, in the latter's virtual base list. Skip over all
212346283Sdfr   bases that may appear in the virtual base list of the primary base
212446283Sdfr   class of DCLASS (recursively).  A return of -1 indicates "not
212546283Sdfr   found" or a problem.  */
212646283Sdfr
212746283Sdfrint
212898944Sobrienvirtual_base_index_skip_primaries (struct type *base, struct type *dclass)
212946283Sdfr{
2130130803Smarcel  struct type *vbase;
2131130803Smarcel  int i, j;
213298944Sobrien  struct type *primary;
213346283Sdfr
213498944Sobrien  if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
213598944Sobrien      (TYPE_CODE (base) != TYPE_CODE_CLASS))
213646283Sdfr    return -1;
213746283Sdfr
213898944Sobrien  primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
213946283Sdfr
214046283Sdfr  j = -1;
214146283Sdfr  i = 0;
214298944Sobrien  vbase = virtual_base_list (dclass)[0];
214346283Sdfr  while (vbase)
214446283Sdfr    {
214598944Sobrien      if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
214698944Sobrien	j++;
214746283Sdfr      if (vbase == base)
214898944Sobrien	break;
214998944Sobrien      vbase = virtual_base_list (dclass)[++i];
215046283Sdfr    }
215146283Sdfr
215246283Sdfr  return vbase ? j : -1;
215346283Sdfr}
215446283Sdfr
215546283Sdfr/* Return position of a derived class DCLASS in the list of
215646283Sdfr * primary bases starting with the remotest ancestor.
215746283Sdfr * Position returned is 0-based. */
215846283Sdfr
215946283Sdfrint
216098944Sobrienclass_index_in_primary_list (struct type *dclass)
216146283Sdfr{
216298944Sobrien  struct type *pbc;		/* primary base class */
216346283Sdfr
216498944Sobrien  /* Simply recurse on primary base */
216546283Sdfr  pbc = TYPE_PRIMARY_BASE (dclass);
216646283Sdfr  if (pbc)
216746283Sdfr    return 1 + class_index_in_primary_list (pbc);
216846283Sdfr  else
216946283Sdfr    return 0;
217046283Sdfr}
217146283Sdfr
217246283Sdfr/* Return a count of the number of virtual functions a type has.
217346283Sdfr * This includes all the virtual functions it inherits from its
217446283Sdfr * base classes too.
217546283Sdfr */
217646283Sdfr
217746283Sdfr/* pai: FIXME This doesn't do the right thing: count redefined virtual
217846283Sdfr * functions only once (latest redefinition)
217946283Sdfr */
218046283Sdfr
218146283Sdfrint
218298944Sobriencount_virtual_fns (struct type *dclass)
218346283Sdfr{
218498944Sobrien  int fn, oi;			/* function and overloaded instance indices */
218598944Sobrien  int vfuncs;			/* count to return */
218646283Sdfr
218798944Sobrien  /* recurse on bases that can share virtual table */
218898944Sobrien  struct type *pbc = primary_base_class (dclass);
218946283Sdfr  if (pbc)
219046283Sdfr    vfuncs = count_virtual_fns (pbc);
219198944Sobrien  else
219298944Sobrien    vfuncs = 0;
219398944Sobrien
219446283Sdfr  for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
219546283Sdfr    for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
219646283Sdfr      if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
219798944Sobrien	vfuncs++;
219846283Sdfr
219946283Sdfr  return vfuncs;
220046283Sdfr}
220146283Sdfr
220246283Sdfr
220398944Sobrien
220446283Sdfr/* Functions for overload resolution begin here */
220546283Sdfr
220646283Sdfr/* Compare two badness vectors A and B and return the result.
220746283Sdfr * 0 => A and B are identical
220846283Sdfr * 1 => A and B are incomparable
220946283Sdfr * 2 => A is better than B
221046283Sdfr * 3 => A is worse than B */
221146283Sdfr
221246283Sdfrint
221398944Sobriencompare_badness (struct badness_vector *a, struct badness_vector *b)
221446283Sdfr{
221546283Sdfr  int i;
221646283Sdfr  int tmp;
221798944Sobrien  short found_pos = 0;		/* any positives in c? */
221898944Sobrien  short found_neg = 0;		/* any negatives in c? */
221998944Sobrien
222098944Sobrien  /* differing lengths => incomparable */
222146283Sdfr  if (a->length != b->length)
222246283Sdfr    return 1;
222346283Sdfr
222498944Sobrien  /* Subtract b from a */
222598944Sobrien  for (i = 0; i < a->length; i++)
222646283Sdfr    {
222746283Sdfr      tmp = a->rank[i] - b->rank[i];
222846283Sdfr      if (tmp > 0)
222998944Sobrien	found_pos = 1;
223046283Sdfr      else if (tmp < 0)
223198944Sobrien	found_neg = 1;
223246283Sdfr    }
223346283Sdfr
223446283Sdfr  if (found_pos)
223546283Sdfr    {
223646283Sdfr      if (found_neg)
223798944Sobrien	return 1;		/* incomparable */
223846283Sdfr      else
223998944Sobrien	return 3;		/* A > B */
224046283Sdfr    }
224198944Sobrien  else
224298944Sobrien    /* no positives */
224346283Sdfr    {
224446283Sdfr      if (found_neg)
224598944Sobrien	return 2;		/* A < B */
224646283Sdfr      else
224798944Sobrien	return 0;		/* A == B */
224846283Sdfr    }
224946283Sdfr}
225046283Sdfr
225146283Sdfr/* Rank a function by comparing its parameter types (PARMS, length NPARMS),
225246283Sdfr * to the types of an argument list (ARGS, length NARGS).
225346283Sdfr * Return a pointer to a badness vector. This has NARGS + 1 entries. */
225446283Sdfr
225546283Sdfrstruct badness_vector *
225698944Sobrienrank_function (struct type **parms, int nparms, struct type **args, int nargs)
225746283Sdfr{
225846283Sdfr  int i;
225998944Sobrien  struct badness_vector *bv;
226046283Sdfr  int min_len = nparms < nargs ? nparms : nargs;
226146283Sdfr
226246283Sdfr  bv = xmalloc (sizeof (struct badness_vector));
226398944Sobrien  bv->length = nargs + 1;	/* add 1 for the length-match rank */
226446283Sdfr  bv->rank = xmalloc ((nargs + 1) * sizeof (int));
226546283Sdfr
226646283Sdfr  /* First compare the lengths of the supplied lists.
226746283Sdfr   * If there is a mismatch, set it to a high value. */
226898944Sobrien
226946283Sdfr  /* pai/1997-06-03 FIXME: when we have debug info about default
227046283Sdfr   * arguments and ellipsis parameter lists, we should consider those
227146283Sdfr   * and rank the length-match more finely. */
227246283Sdfr
227346283Sdfr  LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
227446283Sdfr
227546283Sdfr  /* Now rank all the parameters of the candidate function */
227698944Sobrien  for (i = 1; i <= min_len; i++)
227746283Sdfr    bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
227846283Sdfr
227998944Sobrien  /* If more arguments than parameters, add dummy entries */
228098944Sobrien  for (i = min_len + 1; i <= nargs; i++)
228146283Sdfr    bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
228246283Sdfr
228346283Sdfr  return bv;
228446283Sdfr}
228546283Sdfr
2286130803Smarcel/* Compare the names of two integer types, assuming that any sign
2287130803Smarcel   qualifiers have been checked already.  We do it this way because
2288130803Smarcel   there may be an "int" in the name of one of the types.  */
2289130803Smarcel
2290130803Smarcelstatic int
2291130803Smarcelinteger_types_same_name_p (const char *first, const char *second)
2292130803Smarcel{
2293130803Smarcel  int first_p, second_p;
2294130803Smarcel
2295130803Smarcel  /* If both are shorts, return 1; if neither is a short, keep checking.  */
2296130803Smarcel  first_p = (strstr (first, "short") != NULL);
2297130803Smarcel  second_p = (strstr (second, "short") != NULL);
2298130803Smarcel  if (first_p && second_p)
2299130803Smarcel    return 1;
2300130803Smarcel  if (first_p || second_p)
2301130803Smarcel    return 0;
2302130803Smarcel
2303130803Smarcel  /* Likewise for long.  */
2304130803Smarcel  first_p = (strstr (first, "long") != NULL);
2305130803Smarcel  second_p = (strstr (second, "long") != NULL);
2306130803Smarcel  if (first_p && second_p)
2307130803Smarcel    return 1;
2308130803Smarcel  if (first_p || second_p)
2309130803Smarcel    return 0;
2310130803Smarcel
2311130803Smarcel  /* Likewise for char.  */
2312130803Smarcel  first_p = (strstr (first, "char") != NULL);
2313130803Smarcel  second_p = (strstr (second, "char") != NULL);
2314130803Smarcel  if (first_p && second_p)
2315130803Smarcel    return 1;
2316130803Smarcel  if (first_p || second_p)
2317130803Smarcel    return 0;
2318130803Smarcel
2319130803Smarcel  /* They must both be ints.  */
2320130803Smarcel  return 1;
2321130803Smarcel}
2322130803Smarcel
232346283Sdfr/* Compare one type (PARM) for compatibility with another (ARG).
232446283Sdfr * PARM is intended to be the parameter type of a function; and
232546283Sdfr * ARG is the supplied argument's type.  This function tests if
232646283Sdfr * the latter can be converted to the former.
232746283Sdfr *
232846283Sdfr * Return 0 if they are identical types;
232946283Sdfr * Otherwise, return an integer which corresponds to how compatible
233046283Sdfr * PARM is to ARG. The higher the return value, the worse the match.
233146283Sdfr * Generally the "bad" conversions are all uniformly assigned a 100 */
233246283Sdfr
233346283Sdfrint
233498944Sobrienrank_one_type (struct type *parm, struct type *arg)
233546283Sdfr{
233646283Sdfr  /* Identical type pointers */
233746283Sdfr  /* However, this still doesn't catch all cases of same type for arg
233846283Sdfr   * and param. The reason is that builtin types are different from
233946283Sdfr   * the same ones constructed from the object. */
234046283Sdfr  if (parm == arg)
234146283Sdfr    return 0;
234246283Sdfr
234346283Sdfr  /* Resolve typedefs */
234446283Sdfr  if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
234546283Sdfr    parm = check_typedef (parm);
234646283Sdfr  if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
234746283Sdfr    arg = check_typedef (arg);
234846283Sdfr
234998944Sobrien  /*
235098944Sobrien     Well, damnit, if the names are exactly the same,
235198944Sobrien     i'll say they are exactly the same. This happens when we generate
235298944Sobrien     method stubs. The types won't point to the same address, but they
235398944Sobrien     really are the same.
235498944Sobrien  */
235598944Sobrien
235698944Sobrien  if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
235798944Sobrien      !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
235898944Sobrien      return 0;
235998944Sobrien
236046283Sdfr  /* Check if identical after resolving typedefs */
236146283Sdfr  if (parm == arg)
236246283Sdfr    return 0;
236346283Sdfr
236498944Sobrien  /* See through references, since we can almost make non-references
236598944Sobrien     references. */
236698944Sobrien  if (TYPE_CODE (arg) == TYPE_CODE_REF)
236798944Sobrien    return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
236898944Sobrien	    + REFERENCE_CONVERSION_BADNESS);
236998944Sobrien  if (TYPE_CODE (parm) == TYPE_CODE_REF)
237098944Sobrien    return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
237198944Sobrien	    + REFERENCE_CONVERSION_BADNESS);
237298944Sobrien  if (overload_debug)
237398944Sobrien  /* Debugging only. */
237498944Sobrien    fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
237598944Sobrien        TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
237646283Sdfr
237746283Sdfr  /* x -> y means arg of type x being supplied for parameter of type y */
237846283Sdfr
237946283Sdfr  switch (TYPE_CODE (parm))
238046283Sdfr    {
238198944Sobrien    case TYPE_CODE_PTR:
238298944Sobrien      switch (TYPE_CODE (arg))
238398944Sobrien	{
238498944Sobrien	case TYPE_CODE_PTR:
238598944Sobrien	  if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
238698944Sobrien	    return VOID_PTR_CONVERSION_BADNESS;
238798944Sobrien	  else
238898944Sobrien	    return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
238998944Sobrien	case TYPE_CODE_ARRAY:
239098944Sobrien	  return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
239198944Sobrien	case TYPE_CODE_FUNC:
239298944Sobrien	  return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
239398944Sobrien	case TYPE_CODE_INT:
239498944Sobrien	case TYPE_CODE_ENUM:
239598944Sobrien	case TYPE_CODE_CHAR:
239698944Sobrien	case TYPE_CODE_RANGE:
239798944Sobrien	case TYPE_CODE_BOOL:
239898944Sobrien	  return POINTER_CONVERSION_BADNESS;
239998944Sobrien	default:
240098944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
240198944Sobrien	}
240298944Sobrien    case TYPE_CODE_ARRAY:
240398944Sobrien      switch (TYPE_CODE (arg))
240498944Sobrien	{
240598944Sobrien	case TYPE_CODE_PTR:
240698944Sobrien	case TYPE_CODE_ARRAY:
240798944Sobrien	  return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
240898944Sobrien	default:
240998944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
241098944Sobrien	}
241198944Sobrien    case TYPE_CODE_FUNC:
241298944Sobrien      switch (TYPE_CODE (arg))
241398944Sobrien	{
241498944Sobrien	case TYPE_CODE_PTR:	/* funcptr -> func */
241598944Sobrien	  return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
241698944Sobrien	default:
241798944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
241898944Sobrien	}
241998944Sobrien    case TYPE_CODE_INT:
242098944Sobrien      switch (TYPE_CODE (arg))
242198944Sobrien	{
242298944Sobrien	case TYPE_CODE_INT:
242398944Sobrien	  if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
242498944Sobrien	    {
242598944Sobrien	      /* Deal with signed, unsigned, and plain chars and
242698944Sobrien	         signed and unsigned ints */
242798944Sobrien	      if (TYPE_NOSIGN (parm))
242898944Sobrien		{
242998944Sobrien		  /* This case only for character types */
243098944Sobrien		  if (TYPE_NOSIGN (arg))	/* plain char -> plain char */
243198944Sobrien		    return 0;
243298944Sobrien		  else
2433130803Smarcel		    return INTEGER_CONVERSION_BADNESS;	/* signed/unsigned char -> plain char */
243498944Sobrien		}
243598944Sobrien	      else if (TYPE_UNSIGNED (parm))
243698944Sobrien		{
243798944Sobrien		  if (TYPE_UNSIGNED (arg))
243898944Sobrien		    {
2439130803Smarcel		      /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2440130803Smarcel		      if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
2441130803Smarcel			return 0;
2442130803Smarcel		      else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2443130803Smarcel			       && integer_types_same_name_p (TYPE_NAME (parm), "long"))
244498944Sobrien			return INTEGER_PROMOTION_BADNESS;	/* unsigned int -> unsigned long */
244598944Sobrien		      else
2446130803Smarcel			return INTEGER_CONVERSION_BADNESS;	/* unsigned long -> unsigned int */
244798944Sobrien		    }
244898944Sobrien		  else
244998944Sobrien		    {
2450130803Smarcel		      if (integer_types_same_name_p (TYPE_NAME (arg), "long")
2451130803Smarcel			  && integer_types_same_name_p (TYPE_NAME (parm), "int"))
2452130803Smarcel			return INTEGER_CONVERSION_BADNESS;	/* signed long -> unsigned int */
245398944Sobrien		      else
245498944Sobrien			return INTEGER_CONVERSION_BADNESS;	/* signed int/long -> unsigned int/long */
245598944Sobrien		    }
245698944Sobrien		}
245798944Sobrien	      else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
245898944Sobrien		{
2459130803Smarcel		  if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
246098944Sobrien		    return 0;
2461130803Smarcel		  else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
2462130803Smarcel			   && integer_types_same_name_p (TYPE_NAME (parm), "long"))
246398944Sobrien		    return INTEGER_PROMOTION_BADNESS;
246498944Sobrien		  else
2465130803Smarcel		    return INTEGER_CONVERSION_BADNESS;
246698944Sobrien		}
246798944Sobrien	      else
2468130803Smarcel		return INTEGER_CONVERSION_BADNESS;
246998944Sobrien	    }
247098944Sobrien	  else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
247198944Sobrien	    return INTEGER_PROMOTION_BADNESS;
247298944Sobrien	  else
2473130803Smarcel	    return INTEGER_CONVERSION_BADNESS;
247498944Sobrien	case TYPE_CODE_ENUM:
247598944Sobrien	case TYPE_CODE_CHAR:
247698944Sobrien	case TYPE_CODE_RANGE:
247798944Sobrien	case TYPE_CODE_BOOL:
247898944Sobrien	  return INTEGER_PROMOTION_BADNESS;
247998944Sobrien	case TYPE_CODE_FLT:
248098944Sobrien	  return INT_FLOAT_CONVERSION_BADNESS;
248198944Sobrien	case TYPE_CODE_PTR:
248298944Sobrien	  return NS_POINTER_CONVERSION_BADNESS;
248398944Sobrien	default:
248498944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
248598944Sobrien	}
248698944Sobrien      break;
248798944Sobrien    case TYPE_CODE_ENUM:
248898944Sobrien      switch (TYPE_CODE (arg))
248998944Sobrien	{
249098944Sobrien	case TYPE_CODE_INT:
249198944Sobrien	case TYPE_CODE_CHAR:
249298944Sobrien	case TYPE_CODE_RANGE:
249398944Sobrien	case TYPE_CODE_BOOL:
249498944Sobrien	case TYPE_CODE_ENUM:
2495130803Smarcel	  return INTEGER_CONVERSION_BADNESS;
249698944Sobrien	case TYPE_CODE_FLT:
249798944Sobrien	  return INT_FLOAT_CONVERSION_BADNESS;
249898944Sobrien	default:
249998944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
250098944Sobrien	}
250198944Sobrien      break;
250298944Sobrien    case TYPE_CODE_CHAR:
250398944Sobrien      switch (TYPE_CODE (arg))
250498944Sobrien	{
250598944Sobrien	case TYPE_CODE_RANGE:
250698944Sobrien	case TYPE_CODE_BOOL:
250798944Sobrien	case TYPE_CODE_ENUM:
2508130803Smarcel	  return INTEGER_CONVERSION_BADNESS;
250998944Sobrien	case TYPE_CODE_FLT:
251098944Sobrien	  return INT_FLOAT_CONVERSION_BADNESS;
251198944Sobrien	case TYPE_CODE_INT:
251298944Sobrien	  if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2513130803Smarcel	    return INTEGER_CONVERSION_BADNESS;
251498944Sobrien	  else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
251598944Sobrien	    return INTEGER_PROMOTION_BADNESS;
251698944Sobrien	  /* >>> !! else fall through !! <<< */
251798944Sobrien	case TYPE_CODE_CHAR:
251898944Sobrien	  /* Deal with signed, unsigned, and plain chars for C++
251998944Sobrien	     and with int cases falling through from previous case */
252098944Sobrien	  if (TYPE_NOSIGN (parm))
252198944Sobrien	    {
252298944Sobrien	      if (TYPE_NOSIGN (arg))
252398944Sobrien		return 0;
252498944Sobrien	      else
2525130803Smarcel		return INTEGER_CONVERSION_BADNESS;
252698944Sobrien	    }
252798944Sobrien	  else if (TYPE_UNSIGNED (parm))
252898944Sobrien	    {
252998944Sobrien	      if (TYPE_UNSIGNED (arg))
253098944Sobrien		return 0;
253198944Sobrien	      else
253298944Sobrien		return INTEGER_PROMOTION_BADNESS;
253398944Sobrien	    }
253498944Sobrien	  else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
253598944Sobrien	    return 0;
253698944Sobrien	  else
2537130803Smarcel	    return INTEGER_CONVERSION_BADNESS;
253898944Sobrien	default:
253998944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
254098944Sobrien	}
254198944Sobrien      break;
254298944Sobrien    case TYPE_CODE_RANGE:
254398944Sobrien      switch (TYPE_CODE (arg))
254498944Sobrien	{
254598944Sobrien	case TYPE_CODE_INT:
254698944Sobrien	case TYPE_CODE_CHAR:
254798944Sobrien	case TYPE_CODE_RANGE:
254898944Sobrien	case TYPE_CODE_BOOL:
254998944Sobrien	case TYPE_CODE_ENUM:
2550130803Smarcel	  return INTEGER_CONVERSION_BADNESS;
255198944Sobrien	case TYPE_CODE_FLT:
255298944Sobrien	  return INT_FLOAT_CONVERSION_BADNESS;
255398944Sobrien	default:
255498944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
255598944Sobrien	}
255698944Sobrien      break;
255798944Sobrien    case TYPE_CODE_BOOL:
255898944Sobrien      switch (TYPE_CODE (arg))
255998944Sobrien	{
256098944Sobrien	case TYPE_CODE_INT:
256198944Sobrien	case TYPE_CODE_CHAR:
256298944Sobrien	case TYPE_CODE_RANGE:
256398944Sobrien	case TYPE_CODE_ENUM:
256498944Sobrien	case TYPE_CODE_FLT:
256598944Sobrien	case TYPE_CODE_PTR:
256698944Sobrien	  return BOOLEAN_CONVERSION_BADNESS;
256798944Sobrien	case TYPE_CODE_BOOL:
256898944Sobrien	  return 0;
256998944Sobrien	default:
257098944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
257198944Sobrien	}
257298944Sobrien      break;
257398944Sobrien    case TYPE_CODE_FLT:
257498944Sobrien      switch (TYPE_CODE (arg))
257598944Sobrien	{
257698944Sobrien	case TYPE_CODE_FLT:
257798944Sobrien	  if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
257898944Sobrien	    return FLOAT_PROMOTION_BADNESS;
257998944Sobrien	  else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
258098944Sobrien	    return 0;
258198944Sobrien	  else
258298944Sobrien	    return FLOAT_CONVERSION_BADNESS;
258398944Sobrien	case TYPE_CODE_INT:
258498944Sobrien	case TYPE_CODE_BOOL:
258598944Sobrien	case TYPE_CODE_ENUM:
258698944Sobrien	case TYPE_CODE_RANGE:
258798944Sobrien	case TYPE_CODE_CHAR:
258898944Sobrien	  return INT_FLOAT_CONVERSION_BADNESS;
258998944Sobrien	default:
259098944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
259198944Sobrien	}
259298944Sobrien      break;
259398944Sobrien    case TYPE_CODE_COMPLEX:
259498944Sobrien      switch (TYPE_CODE (arg))
259598944Sobrien	{			/* Strictly not needed for C++, but... */
259698944Sobrien	case TYPE_CODE_FLT:
259798944Sobrien	  return FLOAT_PROMOTION_BADNESS;
259898944Sobrien	case TYPE_CODE_COMPLEX:
259998944Sobrien	  return 0;
260098944Sobrien	default:
260198944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
260298944Sobrien	}
260398944Sobrien      break;
260498944Sobrien    case TYPE_CODE_STRUCT:
260546283Sdfr      /* currently same as TYPE_CODE_CLASS */
260698944Sobrien      switch (TYPE_CODE (arg))
260798944Sobrien	{
260898944Sobrien	case TYPE_CODE_STRUCT:
260998944Sobrien	  /* Check for derivation */
261098944Sobrien	  if (is_ancestor (parm, arg))
261198944Sobrien	    return BASE_CONVERSION_BADNESS;
261298944Sobrien	  /* else fall through */
261398944Sobrien	default:
261498944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
261598944Sobrien	}
261698944Sobrien      break;
261798944Sobrien    case TYPE_CODE_UNION:
261898944Sobrien      switch (TYPE_CODE (arg))
261998944Sobrien	{
262098944Sobrien	case TYPE_CODE_UNION:
262198944Sobrien	default:
262298944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
262398944Sobrien	}
262498944Sobrien      break;
262598944Sobrien    case TYPE_CODE_MEMBER:
262698944Sobrien      switch (TYPE_CODE (arg))
262798944Sobrien	{
262898944Sobrien	default:
262998944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
263098944Sobrien	}
263198944Sobrien      break;
263298944Sobrien    case TYPE_CODE_METHOD:
263398944Sobrien      switch (TYPE_CODE (arg))
263498944Sobrien	{
263546283Sdfr
263698944Sobrien	default:
263798944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
263898944Sobrien	}
263998944Sobrien      break;
264098944Sobrien    case TYPE_CODE_REF:
264198944Sobrien      switch (TYPE_CODE (arg))
264298944Sobrien	{
264346283Sdfr
264498944Sobrien	default:
264598944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
264698944Sobrien	}
264746283Sdfr
264898944Sobrien      break;
264998944Sobrien    case TYPE_CODE_SET:
265098944Sobrien      switch (TYPE_CODE (arg))
265198944Sobrien	{
265298944Sobrien	  /* Not in C++ */
265398944Sobrien	case TYPE_CODE_SET:
265498944Sobrien	  return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
265598944Sobrien	default:
265698944Sobrien	  return INCOMPATIBLE_TYPE_BADNESS;
265798944Sobrien	}
265898944Sobrien      break;
265998944Sobrien    case TYPE_CODE_VOID:
266098944Sobrien    default:
266198944Sobrien      return INCOMPATIBLE_TYPE_BADNESS;
266298944Sobrien    }				/* switch (TYPE_CODE (arg)) */
266398944Sobrien}
266446283Sdfr
266546283Sdfr
266698944Sobrien/* End of functions for overload resolution */
266719370Spst
266819370Spststatic void
266998944Sobrienprint_bit_vector (B_TYPE *bits, int nbits)
267019370Spst{
267119370Spst  int bitno;
267219370Spst
267319370Spst  for (bitno = 0; bitno < nbits; bitno++)
267419370Spst    {
267519370Spst      if ((bitno % 8) == 0)
267619370Spst	{
267719370Spst	  puts_filtered (" ");
267819370Spst	}
267919370Spst      if (B_TST (bits, bitno))
268019370Spst	{
268119370Spst	  printf_filtered ("1");
268219370Spst	}
268319370Spst      else
268419370Spst	{
268519370Spst	  printf_filtered ("0");
268619370Spst	}
268719370Spst    }
268819370Spst}
268919370Spst
2690130803Smarcel/* Note the first arg should be the "this" pointer, we may not want to
2691130803Smarcel   include it since we may get into a infinitely recursive situation.  */
269219370Spst
269319370Spststatic void
2694130803Smarcelprint_arg_types (struct field *args, int nargs, int spaces)
269519370Spst{
269619370Spst  if (args != NULL)
269719370Spst    {
2698130803Smarcel      int i;
2699130803Smarcel
2700130803Smarcel      for (i = 0; i < nargs; i++)
2701130803Smarcel	recursive_dump_type (args[i].type, spaces + 2);
270219370Spst    }
270319370Spst}
270419370Spst
270519370Spststatic void
270698944Sobriendump_fn_fieldlists (struct type *type, int spaces)
270719370Spst{
270819370Spst  int method_idx;
270919370Spst  int overload_idx;
271019370Spst  struct fn_field *f;
271119370Spst
271219370Spst  printfi_filtered (spaces, "fn_fieldlists ");
271398944Sobrien  gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
271419370Spst  printf_filtered ("\n");
271519370Spst  for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
271619370Spst    {
271719370Spst      f = TYPE_FN_FIELDLIST1 (type, method_idx);
271819370Spst      printfi_filtered (spaces + 2, "[%d] name '%s' (",
271919370Spst			method_idx,
272019370Spst			TYPE_FN_FIELDLIST_NAME (type, method_idx));
272198944Sobrien      gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
272298944Sobrien			      gdb_stdout);
272319370Spst      printf_filtered (") length %d\n",
272419370Spst		       TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
272519370Spst      for (overload_idx = 0;
272619370Spst	   overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
272719370Spst	   overload_idx++)
272819370Spst	{
272919370Spst	  printfi_filtered (spaces + 4, "[%d] physname '%s' (",
273019370Spst			    overload_idx,
273119370Spst			    TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
273298944Sobrien	  gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
273398944Sobrien				  gdb_stdout);
273419370Spst	  printf_filtered (")\n");
273519370Spst	  printfi_filtered (spaces + 8, "type ");
273698944Sobrien	  gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
273719370Spst	  printf_filtered ("\n");
273819370Spst
273919370Spst	  recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
274019370Spst			       spaces + 8 + 2);
274119370Spst
274219370Spst	  printfi_filtered (spaces + 8, "args ");
274398944Sobrien	  gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
274419370Spst	  printf_filtered ("\n");
274519370Spst
2746130803Smarcel	  print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
2747130803Smarcel			   TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
2748130803Smarcel			   spaces);
274919370Spst	  printfi_filtered (spaces + 8, "fcontext ");
275098944Sobrien	  gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
275198944Sobrien				  gdb_stdout);
275219370Spst	  printf_filtered ("\n");
275319370Spst
275419370Spst	  printfi_filtered (spaces + 8, "is_const %d\n",
275519370Spst			    TYPE_FN_FIELD_CONST (f, overload_idx));
275619370Spst	  printfi_filtered (spaces + 8, "is_volatile %d\n",
275719370Spst			    TYPE_FN_FIELD_VOLATILE (f, overload_idx));
275819370Spst	  printfi_filtered (spaces + 8, "is_private %d\n",
275919370Spst			    TYPE_FN_FIELD_PRIVATE (f, overload_idx));
276019370Spst	  printfi_filtered (spaces + 8, "is_protected %d\n",
276119370Spst			    TYPE_FN_FIELD_PROTECTED (f, overload_idx));
276219370Spst	  printfi_filtered (spaces + 8, "is_stub %d\n",
276319370Spst			    TYPE_FN_FIELD_STUB (f, overload_idx));
276419370Spst	  printfi_filtered (spaces + 8, "voffset %u\n",
276519370Spst			    TYPE_FN_FIELD_VOFFSET (f, overload_idx));
276619370Spst	}
276719370Spst    }
276819370Spst}
276919370Spst
277019370Spststatic void
277198944Sobrienprint_cplus_stuff (struct type *type, int spaces)
277219370Spst{
277319370Spst  printfi_filtered (spaces, "n_baseclasses %d\n",
277419370Spst		    TYPE_N_BASECLASSES (type));
277519370Spst  printfi_filtered (spaces, "nfn_fields %d\n",
277619370Spst		    TYPE_NFN_FIELDS (type));
277719370Spst  printfi_filtered (spaces, "nfn_fields_total %d\n",
277819370Spst		    TYPE_NFN_FIELDS_TOTAL (type));
277919370Spst  if (TYPE_N_BASECLASSES (type) > 0)
278019370Spst    {
278119370Spst      printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
278219370Spst			TYPE_N_BASECLASSES (type));
278398944Sobrien      gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
278419370Spst      printf_filtered (")");
278519370Spst
278619370Spst      print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
278719370Spst			TYPE_N_BASECLASSES (type));
278819370Spst      puts_filtered ("\n");
278919370Spst    }
279019370Spst  if (TYPE_NFIELDS (type) > 0)
279119370Spst    {
279219370Spst      if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
279319370Spst	{
279419370Spst	  printfi_filtered (spaces, "private_field_bits (%d bits at *",
279519370Spst			    TYPE_NFIELDS (type));
279698944Sobrien	  gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
279719370Spst	  printf_filtered (")");
279819370Spst	  print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
279919370Spst			    TYPE_NFIELDS (type));
280019370Spst	  puts_filtered ("\n");
280119370Spst	}
280219370Spst      if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
280319370Spst	{
280419370Spst	  printfi_filtered (spaces, "protected_field_bits (%d bits at *",
280519370Spst			    TYPE_NFIELDS (type));
280698944Sobrien	  gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
280719370Spst	  printf_filtered (")");
280819370Spst	  print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
280919370Spst			    TYPE_NFIELDS (type));
281019370Spst	  puts_filtered ("\n");
281119370Spst	}
281219370Spst    }
281319370Spst  if (TYPE_NFN_FIELDS (type) > 0)
281419370Spst    {
281519370Spst      dump_fn_fieldlists (type, spaces);
281619370Spst    }
281719370Spst}
281819370Spst
281998944Sobrienstatic void
282098944Sobrienprint_bound_type (int bt)
282198944Sobrien{
282298944Sobrien  switch (bt)
282398944Sobrien    {
282498944Sobrien    case BOUND_CANNOT_BE_DETERMINED:
282598944Sobrien      printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
282698944Sobrien      break;
282798944Sobrien    case BOUND_BY_REF_ON_STACK:
282898944Sobrien      printf_filtered ("(BOUND_BY_REF_ON_STACK)");
282998944Sobrien      break;
283098944Sobrien    case BOUND_BY_VALUE_ON_STACK:
283198944Sobrien      printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
283298944Sobrien      break;
283398944Sobrien    case BOUND_BY_REF_IN_REG:
283498944Sobrien      printf_filtered ("(BOUND_BY_REF_IN_REG)");
283598944Sobrien      break;
283698944Sobrien    case BOUND_BY_VALUE_IN_REG:
283798944Sobrien      printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
283898944Sobrien      break;
283998944Sobrien    case BOUND_SIMPLE:
284098944Sobrien      printf_filtered ("(BOUND_SIMPLE)");
284198944Sobrien      break;
284298944Sobrien    default:
284398944Sobrien      printf_filtered ("(unknown bound type)");
284498944Sobrien      break;
284598944Sobrien    }
284698944Sobrien}
284798944Sobrien
284819370Spststatic struct obstack dont_print_type_obstack;
284919370Spst
285019370Spstvoid
285198944Sobrienrecursive_dump_type (struct type *type, int spaces)
285219370Spst{
285319370Spst  int idx;
285419370Spst
285519370Spst  if (spaces == 0)
285619370Spst    obstack_begin (&dont_print_type_obstack, 0);
285719370Spst
285819370Spst  if (TYPE_NFIELDS (type) > 0
285919370Spst      || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
286019370Spst    {
286119370Spst      struct type **first_dont_print
286298944Sobrien      = (struct type **) obstack_base (&dont_print_type_obstack);
286319370Spst
286498944Sobrien      int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
286598944Sobrien      - first_dont_print;
286619370Spst
286719370Spst      while (--i >= 0)
286819370Spst	{
286919370Spst	  if (type == first_dont_print[i])
287019370Spst	    {
287119370Spst	      printfi_filtered (spaces, "type node ");
287298944Sobrien	      gdb_print_host_address (type, gdb_stdout);
287319370Spst	      printf_filtered (" <same as already seen type>\n");
287419370Spst	      return;
287519370Spst	    }
287619370Spst	}
287719370Spst
287819370Spst      obstack_ptr_grow (&dont_print_type_obstack, type);
287919370Spst    }
288019370Spst
288119370Spst  printfi_filtered (spaces, "type node ");
288298944Sobrien  gdb_print_host_address (type, gdb_stdout);
288319370Spst  printf_filtered ("\n");
288419370Spst  printfi_filtered (spaces, "name '%s' (",
288519370Spst		    TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
288698944Sobrien  gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
288719370Spst  printf_filtered (")\n");
288898944Sobrien  printfi_filtered (spaces, "tagname '%s' (",
288998944Sobrien		    TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
289098944Sobrien  gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
289198944Sobrien  printf_filtered (")\n");
289219370Spst  printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
289319370Spst  switch (TYPE_CODE (type))
289419370Spst    {
289598944Sobrien    case TYPE_CODE_UNDEF:
289698944Sobrien      printf_filtered ("(TYPE_CODE_UNDEF)");
289798944Sobrien      break;
289898944Sobrien    case TYPE_CODE_PTR:
289998944Sobrien      printf_filtered ("(TYPE_CODE_PTR)");
290098944Sobrien      break;
290198944Sobrien    case TYPE_CODE_ARRAY:
290298944Sobrien      printf_filtered ("(TYPE_CODE_ARRAY)");
290398944Sobrien      break;
290498944Sobrien    case TYPE_CODE_STRUCT:
290598944Sobrien      printf_filtered ("(TYPE_CODE_STRUCT)");
290698944Sobrien      break;
290798944Sobrien    case TYPE_CODE_UNION:
290898944Sobrien      printf_filtered ("(TYPE_CODE_UNION)");
290998944Sobrien      break;
291098944Sobrien    case TYPE_CODE_ENUM:
291198944Sobrien      printf_filtered ("(TYPE_CODE_ENUM)");
291298944Sobrien      break;
291398944Sobrien    case TYPE_CODE_FUNC:
291498944Sobrien      printf_filtered ("(TYPE_CODE_FUNC)");
291598944Sobrien      break;
291698944Sobrien    case TYPE_CODE_INT:
291798944Sobrien      printf_filtered ("(TYPE_CODE_INT)");
291898944Sobrien      break;
291998944Sobrien    case TYPE_CODE_FLT:
292098944Sobrien      printf_filtered ("(TYPE_CODE_FLT)");
292198944Sobrien      break;
292298944Sobrien    case TYPE_CODE_VOID:
292398944Sobrien      printf_filtered ("(TYPE_CODE_VOID)");
292498944Sobrien      break;
292598944Sobrien    case TYPE_CODE_SET:
292698944Sobrien      printf_filtered ("(TYPE_CODE_SET)");
292798944Sobrien      break;
292898944Sobrien    case TYPE_CODE_RANGE:
292998944Sobrien      printf_filtered ("(TYPE_CODE_RANGE)");
293098944Sobrien      break;
293198944Sobrien    case TYPE_CODE_STRING:
293298944Sobrien      printf_filtered ("(TYPE_CODE_STRING)");
293398944Sobrien      break;
293498944Sobrien    case TYPE_CODE_BITSTRING:
293598944Sobrien      printf_filtered ("(TYPE_CODE_BITSTRING)");
293698944Sobrien      break;
293798944Sobrien    case TYPE_CODE_ERROR:
293898944Sobrien      printf_filtered ("(TYPE_CODE_ERROR)");
293998944Sobrien      break;
294098944Sobrien    case TYPE_CODE_MEMBER:
294198944Sobrien      printf_filtered ("(TYPE_CODE_MEMBER)");
294298944Sobrien      break;
294398944Sobrien    case TYPE_CODE_METHOD:
294498944Sobrien      printf_filtered ("(TYPE_CODE_METHOD)");
294598944Sobrien      break;
294698944Sobrien    case TYPE_CODE_REF:
294798944Sobrien      printf_filtered ("(TYPE_CODE_REF)");
294898944Sobrien      break;
294998944Sobrien    case TYPE_CODE_CHAR:
295098944Sobrien      printf_filtered ("(TYPE_CODE_CHAR)");
295198944Sobrien      break;
295298944Sobrien    case TYPE_CODE_BOOL:
295398944Sobrien      printf_filtered ("(TYPE_CODE_BOOL)");
295498944Sobrien      break;
295598944Sobrien    case TYPE_CODE_COMPLEX:
295698944Sobrien      printf_filtered ("(TYPE_CODE_COMPLEX)");
295798944Sobrien      break;
295898944Sobrien    case TYPE_CODE_TYPEDEF:
295998944Sobrien      printf_filtered ("(TYPE_CODE_TYPEDEF)");
296098944Sobrien      break;
296198944Sobrien    case TYPE_CODE_TEMPLATE:
296298944Sobrien      printf_filtered ("(TYPE_CODE_TEMPLATE)");
296398944Sobrien      break;
296498944Sobrien    case TYPE_CODE_TEMPLATE_ARG:
296598944Sobrien      printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
296698944Sobrien      break;
2967130803Smarcel    case TYPE_CODE_NAMESPACE:
2968130803Smarcel      printf_filtered ("(TYPE_CODE_NAMESPACE)");
2969130803Smarcel      break;
297098944Sobrien    default:
297198944Sobrien      printf_filtered ("(UNKNOWN TYPE CODE)");
297298944Sobrien      break;
297319370Spst    }
297419370Spst  puts_filtered ("\n");
297519370Spst  printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
297698944Sobrien  printfi_filtered (spaces, "upper_bound_type 0x%x ",
297798944Sobrien		    TYPE_ARRAY_UPPER_BOUND_TYPE (type));
297898944Sobrien  print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
297998944Sobrien  puts_filtered ("\n");
298098944Sobrien  printfi_filtered (spaces, "lower_bound_type 0x%x ",
298198944Sobrien		    TYPE_ARRAY_LOWER_BOUND_TYPE (type));
298298944Sobrien  print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
298398944Sobrien  puts_filtered ("\n");
298419370Spst  printfi_filtered (spaces, "objfile ");
298598944Sobrien  gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
298619370Spst  printf_filtered ("\n");
298719370Spst  printfi_filtered (spaces, "target_type ");
298898944Sobrien  gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
298919370Spst  printf_filtered ("\n");
299019370Spst  if (TYPE_TARGET_TYPE (type) != NULL)
299119370Spst    {
299219370Spst      recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
299319370Spst    }
299419370Spst  printfi_filtered (spaces, "pointer_type ");
299598944Sobrien  gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
299619370Spst  printf_filtered ("\n");
299719370Spst  printfi_filtered (spaces, "reference_type ");
299898944Sobrien  gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
299919370Spst  printf_filtered ("\n");
3000130803Smarcel  printfi_filtered (spaces, "type_chain ");
3001130803Smarcel  gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
300298944Sobrien  printf_filtered ("\n");
3003130803Smarcel  printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type));
3004130803Smarcel  if (TYPE_CONST (type))
3005130803Smarcel    {
3006130803Smarcel      puts_filtered (" TYPE_FLAG_CONST");
3007130803Smarcel    }
3008130803Smarcel  if (TYPE_VOLATILE (type))
3009130803Smarcel    {
3010130803Smarcel      puts_filtered (" TYPE_FLAG_VOLATILE");
3011130803Smarcel    }
3012130803Smarcel  if (TYPE_CODE_SPACE (type))
3013130803Smarcel    {
3014130803Smarcel      puts_filtered (" TYPE_FLAG_CODE_SPACE");
3015130803Smarcel    }
3016130803Smarcel  if (TYPE_DATA_SPACE (type))
3017130803Smarcel    {
3018130803Smarcel      puts_filtered (" TYPE_FLAG_DATA_SPACE");
3019130803Smarcel    }
3020130803Smarcel  if (TYPE_ADDRESS_CLASS_1 (type))
3021130803Smarcel    {
3022130803Smarcel      puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
3023130803Smarcel    }
3024130803Smarcel  if (TYPE_ADDRESS_CLASS_2 (type))
3025130803Smarcel    {
3026130803Smarcel      puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
3027130803Smarcel    }
3028130803Smarcel  puts_filtered ("\n");
302919370Spst  printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
303098944Sobrien  if (TYPE_UNSIGNED (type))
303119370Spst    {
303219370Spst      puts_filtered (" TYPE_FLAG_UNSIGNED");
303319370Spst    }
303498944Sobrien  if (TYPE_NOSIGN (type))
303519370Spst    {
303698944Sobrien      puts_filtered (" TYPE_FLAG_NOSIGN");
303798944Sobrien    }
303898944Sobrien  if (TYPE_STUB (type))
303998944Sobrien    {
304019370Spst      puts_filtered (" TYPE_FLAG_STUB");
304119370Spst    }
304298944Sobrien  if (TYPE_TARGET_STUB (type))
304398944Sobrien    {
304498944Sobrien      puts_filtered (" TYPE_FLAG_TARGET_STUB");
304598944Sobrien    }
304698944Sobrien  if (TYPE_STATIC (type))
304798944Sobrien    {
304898944Sobrien      puts_filtered (" TYPE_FLAG_STATIC");
304998944Sobrien    }
305098944Sobrien  if (TYPE_PROTOTYPED (type))
305198944Sobrien    {
305298944Sobrien      puts_filtered (" TYPE_FLAG_PROTOTYPED");
305398944Sobrien    }
305498944Sobrien  if (TYPE_INCOMPLETE (type))
305598944Sobrien    {
305698944Sobrien      puts_filtered (" TYPE_FLAG_INCOMPLETE");
305798944Sobrien    }
3058130803Smarcel  if (TYPE_VARARGS (type))
305998944Sobrien    {
3060130803Smarcel      puts_filtered (" TYPE_FLAG_VARARGS");
306198944Sobrien    }
3062130803Smarcel  /* This is used for things like AltiVec registers on ppc.  Gcc emits
3063130803Smarcel     an attribute for the array type, which tells whether or not we
3064130803Smarcel     have a vector, instead of a regular array.  */
3065130803Smarcel  if (TYPE_VECTOR (type))
306698944Sobrien    {
3067130803Smarcel      puts_filtered (" TYPE_FLAG_VECTOR");
306898944Sobrien    }
306919370Spst  puts_filtered ("\n");
307019370Spst  printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
307198944Sobrien  gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
307219370Spst  puts_filtered ("\n");
307319370Spst  for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
307419370Spst    {
307519370Spst      printfi_filtered (spaces + 2,
307619370Spst			"[%d] bitpos %d bitsize %d type ",
307719370Spst			idx, TYPE_FIELD_BITPOS (type, idx),
307819370Spst			TYPE_FIELD_BITSIZE (type, idx));
307998944Sobrien      gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
308019370Spst      printf_filtered (" name '%s' (",
308119370Spst		       TYPE_FIELD_NAME (type, idx) != NULL
308219370Spst		       ? TYPE_FIELD_NAME (type, idx)
308319370Spst		       : "<NULL>");
308498944Sobrien      gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
308519370Spst      printf_filtered (")\n");
308619370Spst      if (TYPE_FIELD_TYPE (type, idx) != NULL)
308719370Spst	{
308819370Spst	  recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
308919370Spst	}
309019370Spst    }
309119370Spst  printfi_filtered (spaces, "vptr_basetype ");
309298944Sobrien  gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
309319370Spst  puts_filtered ("\n");
309419370Spst  if (TYPE_VPTR_BASETYPE (type) != NULL)
309519370Spst    {
309619370Spst      recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
309719370Spst    }
309819370Spst  printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
309919370Spst  switch (TYPE_CODE (type))
310019370Spst    {
310198944Sobrien    case TYPE_CODE_STRUCT:
310298944Sobrien      printfi_filtered (spaces, "cplus_stuff ");
310398944Sobrien      gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
310498944Sobrien      puts_filtered ("\n");
310598944Sobrien      print_cplus_stuff (type, spaces);
310698944Sobrien      break;
310719370Spst
310898944Sobrien    case TYPE_CODE_FLT:
310998944Sobrien      printfi_filtered (spaces, "floatformat ");
311098944Sobrien      if (TYPE_FLOATFORMAT (type) == NULL
311198944Sobrien	  || TYPE_FLOATFORMAT (type)->name == NULL)
311298944Sobrien	puts_filtered ("(null)");
311398944Sobrien      else
311498944Sobrien	puts_filtered (TYPE_FLOATFORMAT (type)->name);
311598944Sobrien      puts_filtered ("\n");
311698944Sobrien      break;
311719370Spst
311898944Sobrien    default:
311998944Sobrien      /* We have to pick one of the union types to be able print and test
312098944Sobrien         the value.  Pick cplus_struct_type, even though we know it isn't
312198944Sobrien         any particular one. */
312298944Sobrien      printfi_filtered (spaces, "type_specific ");
312398944Sobrien      gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
312498944Sobrien      if (TYPE_CPLUS_SPECIFIC (type) != NULL)
312598944Sobrien	{
312698944Sobrien	  printf_filtered (" (unknown data form)");
312798944Sobrien	}
312898944Sobrien      printf_filtered ("\n");
312998944Sobrien      break;
313098944Sobrien
313119370Spst    }
313219370Spst  if (spaces == 0)
313319370Spst    obstack_free (&dont_print_type_obstack, NULL);
313419370Spst}
313519370Spst
313698944Sobrienstatic void build_gdbtypes (void);
313746283Sdfrstatic void
313898944Sobrienbuild_gdbtypes (void)
313919370Spst{
314019370Spst  builtin_type_void =
314119370Spst    init_type (TYPE_CODE_VOID, 1,
314219370Spst	       0,
314319370Spst	       "void", (struct objfile *) NULL);
314419370Spst  builtin_type_char =
314519370Spst    init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
314698944Sobrien	       (TYPE_FLAG_NOSIGN
314798944Sobrien                | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)),
314898944Sobrien	       "char", (struct objfile *) NULL);
314998944Sobrien  builtin_type_true_char =
315098944Sobrien    init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
315119370Spst	       0,
315298944Sobrien	       "true character", (struct objfile *) NULL);
315319370Spst  builtin_type_signed_char =
315419370Spst    init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
315519370Spst	       0,
315619370Spst	       "signed char", (struct objfile *) NULL);
315719370Spst  builtin_type_unsigned_char =
315819370Spst    init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
315919370Spst	       TYPE_FLAG_UNSIGNED,
316019370Spst	       "unsigned char", (struct objfile *) NULL);
316119370Spst  builtin_type_short =
316219370Spst    init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
316319370Spst	       0,
316419370Spst	       "short", (struct objfile *) NULL);
316519370Spst  builtin_type_unsigned_short =
316619370Spst    init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
316719370Spst	       TYPE_FLAG_UNSIGNED,
316819370Spst	       "unsigned short", (struct objfile *) NULL);
316919370Spst  builtin_type_int =
317019370Spst    init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
317119370Spst	       0,
317219370Spst	       "int", (struct objfile *) NULL);
317319370Spst  builtin_type_unsigned_int =
317419370Spst    init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
317519370Spst	       TYPE_FLAG_UNSIGNED,
317619370Spst	       "unsigned int", (struct objfile *) NULL);
317719370Spst  builtin_type_long =
317819370Spst    init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
317919370Spst	       0,
318019370Spst	       "long", (struct objfile *) NULL);
318119370Spst  builtin_type_unsigned_long =
318219370Spst    init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
318319370Spst	       TYPE_FLAG_UNSIGNED,
318419370Spst	       "unsigned long", (struct objfile *) NULL);
318519370Spst  builtin_type_long_long =
318619370Spst    init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
318719370Spst	       0,
318819370Spst	       "long long", (struct objfile *) NULL);
318998944Sobrien  builtin_type_unsigned_long_long =
319019370Spst    init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
319119370Spst	       TYPE_FLAG_UNSIGNED,
319219370Spst	       "unsigned long long", (struct objfile *) NULL);
319319370Spst  builtin_type_float =
319419370Spst    init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
319519370Spst	       0,
319619370Spst	       "float", (struct objfile *) NULL);
319798944Sobrien/* vinschen@redhat.com 2002-02-08:
319898944Sobrien   The below lines are disabled since they are doing the wrong
319998944Sobrien   thing for non-multiarch targets.  They are setting the correct
320098944Sobrien   type of floats for the target but while on multiarch targets
320198944Sobrien   this is done everytime the architecture changes, it's done on
320298944Sobrien   non-multiarch targets only on startup, leaving the wrong values
320398944Sobrien   in even if the architecture changes (eg. from big-endian to
320498944Sobrien   little-endian).  */
320598944Sobrien#if 0
320698944Sobrien  TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
320798944Sobrien#endif
320819370Spst  builtin_type_double =
320919370Spst    init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
321019370Spst	       0,
321119370Spst	       "double", (struct objfile *) NULL);
321298944Sobrien#if 0
321398944Sobrien  TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
321498944Sobrien#endif
321519370Spst  builtin_type_long_double =
321619370Spst    init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
321719370Spst	       0,
321819370Spst	       "long double", (struct objfile *) NULL);
321998944Sobrien#if 0
322098944Sobrien  TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
322198944Sobrien#endif
322219370Spst  builtin_type_complex =
322319370Spst    init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
322419370Spst	       0,
322519370Spst	       "complex", (struct objfile *) NULL);
322619370Spst  TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
322719370Spst  builtin_type_double_complex =
322819370Spst    init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
322919370Spst	       0,
323019370Spst	       "double complex", (struct objfile *) NULL);
323119370Spst  TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
323219370Spst  builtin_type_string =
323319370Spst    init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
323419370Spst	       0,
323519370Spst	       "string", (struct objfile *) NULL);
3236130803Smarcel  builtin_type_int0 =
3237130803Smarcel    init_type (TYPE_CODE_INT, 0 / 8,
3238130803Smarcel	       0,
3239130803Smarcel	       "int0_t", (struct objfile *) NULL);
324046283Sdfr  builtin_type_int8 =
324146283Sdfr    init_type (TYPE_CODE_INT, 8 / 8,
324246283Sdfr	       0,
324346283Sdfr	       "int8_t", (struct objfile *) NULL);
324446283Sdfr  builtin_type_uint8 =
324546283Sdfr    init_type (TYPE_CODE_INT, 8 / 8,
324646283Sdfr	       TYPE_FLAG_UNSIGNED,
324746283Sdfr	       "uint8_t", (struct objfile *) NULL);
324846283Sdfr  builtin_type_int16 =
324946283Sdfr    init_type (TYPE_CODE_INT, 16 / 8,
325046283Sdfr	       0,
325146283Sdfr	       "int16_t", (struct objfile *) NULL);
325246283Sdfr  builtin_type_uint16 =
325346283Sdfr    init_type (TYPE_CODE_INT, 16 / 8,
325446283Sdfr	       TYPE_FLAG_UNSIGNED,
325546283Sdfr	       "uint16_t", (struct objfile *) NULL);
325646283Sdfr  builtin_type_int32 =
325746283Sdfr    init_type (TYPE_CODE_INT, 32 / 8,
325846283Sdfr	       0,
325946283Sdfr	       "int32_t", (struct objfile *) NULL);
326046283Sdfr  builtin_type_uint32 =
326146283Sdfr    init_type (TYPE_CODE_INT, 32 / 8,
326246283Sdfr	       TYPE_FLAG_UNSIGNED,
326346283Sdfr	       "uint32_t", (struct objfile *) NULL);
326446283Sdfr  builtin_type_int64 =
326546283Sdfr    init_type (TYPE_CODE_INT, 64 / 8,
326646283Sdfr	       0,
326746283Sdfr	       "int64_t", (struct objfile *) NULL);
326846283Sdfr  builtin_type_uint64 =
326946283Sdfr    init_type (TYPE_CODE_INT, 64 / 8,
327046283Sdfr	       TYPE_FLAG_UNSIGNED,
327146283Sdfr	       "uint64_t", (struct objfile *) NULL);
327298944Sobrien  builtin_type_int128 =
327398944Sobrien    init_type (TYPE_CODE_INT, 128 / 8,
327498944Sobrien	       0,
327598944Sobrien	       "int128_t", (struct objfile *) NULL);
327698944Sobrien  builtin_type_uint128 =
327798944Sobrien    init_type (TYPE_CODE_INT, 128 / 8,
327898944Sobrien	       TYPE_FLAG_UNSIGNED,
327998944Sobrien	       "uint128_t", (struct objfile *) NULL);
328046283Sdfr  builtin_type_bool =
328146283Sdfr    init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
328246283Sdfr	       0,
328346283Sdfr	       "bool", (struct objfile *) NULL);
328446283Sdfr
328598944Sobrien  /* Add user knob for controlling resolution of opaque types */
328646283Sdfr  add_show_from_set
328798944Sobrien    (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
328846283Sdfr		  "Set resolution of opaque struct/class/union types (if set before loading symbols).",
328946283Sdfr		  &setlist),
329046283Sdfr     &showlist);
329146283Sdfr  opaque_type_resolution = 1;
329246283Sdfr
329398944Sobrien  /* Build SIMD types.  */
329498944Sobrien  builtin_type_v4sf
329598944Sobrien    = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
329698944Sobrien  builtin_type_v4si
329798944Sobrien    = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
329898944Sobrien  builtin_type_v16qi
329998944Sobrien    = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
330098944Sobrien  builtin_type_v8qi
330198944Sobrien    = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
330298944Sobrien  builtin_type_v8hi
330398944Sobrien    = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
330498944Sobrien  builtin_type_v4hi
330598944Sobrien    = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
330698944Sobrien  builtin_type_v2si
330798944Sobrien    = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
330898944Sobrien
3309130803Smarcel  /* 128 bit vectors.  */
3310130803Smarcel  builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
3311130803Smarcel  builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
3312130803Smarcel  builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
3313130803Smarcel  builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
3314130803Smarcel  builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
3315130803Smarcel  builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
3316130803Smarcel  /* 64 bit vectors.  */
3317130803Smarcel  builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
3318130803Smarcel  builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
3319130803Smarcel  builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
3320130803Smarcel  builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
332198944Sobrien
3322130803Smarcel  /* Vector types.  */
3323130803Smarcel  builtin_type_vec64 = build_builtin_type_vec64 ();
3324130803Smarcel  builtin_type_vec64i = build_builtin_type_vec64i ();
3325130803Smarcel  builtin_type_vec128 = build_builtin_type_vec128 ();
3326130803Smarcel  builtin_type_vec128i = build_builtin_type_vec128i ();
3327130803Smarcel
332898944Sobrien  /* Pointer/Address types. */
332998944Sobrien
333098944Sobrien  /* NOTE: on some targets, addresses and pointers are not necessarily
333198944Sobrien     the same --- for example, on the D10V, pointers are 16 bits long,
333298944Sobrien     but addresses are 32 bits long.  See doc/gdbint.texinfo,
333398944Sobrien     ``Pointers Are Not Always Addresses''.
333498944Sobrien
333598944Sobrien     The upshot is:
333698944Sobrien     - gdb's `struct type' always describes the target's
333798944Sobrien       representation.
333898944Sobrien     - gdb's `struct value' objects should always hold values in
333998944Sobrien       target form.
334098944Sobrien     - gdb's CORE_ADDR values are addresses in the unified virtual
334198944Sobrien       address space that the assembler and linker work with.  Thus,
334298944Sobrien       since target_read_memory takes a CORE_ADDR as an argument, it
334398944Sobrien       can access any memory on the target, even if the processor has
334498944Sobrien       separate code and data address spaces.
334598944Sobrien
334698944Sobrien     So, for example:
334798944Sobrien     - If v is a value holding a D10V code pointer, its contents are
334898944Sobrien       in target form: a big-endian address left-shifted two bits.
334998944Sobrien     - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
335098944Sobrien       sizeof (void *) == 2 on the target.
335198944Sobrien
335298944Sobrien     In this context, builtin_type_CORE_ADDR is a bit odd: it's a
335398944Sobrien     target type for a value the target will never see.  It's only
335498944Sobrien     used to hold the values of (typeless) linker symbols, which are
335598944Sobrien     indeed in the unified virtual address space.  */
335698944Sobrien  builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
335798944Sobrien  builtin_type_void_func_ptr
335898944Sobrien    = lookup_pointer_type (lookup_function_type (builtin_type_void));
335998944Sobrien  builtin_type_CORE_ADDR =
336098944Sobrien    init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
336198944Sobrien	       TYPE_FLAG_UNSIGNED,
336298944Sobrien	       "__CORE_ADDR", (struct objfile *) NULL);
336398944Sobrien  builtin_type_bfd_vma =
336498944Sobrien    init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
336598944Sobrien	       TYPE_FLAG_UNSIGNED,
336698944Sobrien	       "__bfd_vma", (struct objfile *) NULL);
336719370Spst}
336846283Sdfr
336998944Sobrienextern void _initialize_gdbtypes (void);
337046283Sdfrvoid
337198944Sobrien_initialize_gdbtypes (void)
337246283Sdfr{
337398944Sobrien  struct cmd_list_element *c;
337446283Sdfr  build_gdbtypes ();
337598944Sobrien
337698944Sobrien  /* FIXME - For the moment, handle types by swapping them in and out.
337798944Sobrien     Should be using the per-architecture data-pointer and a large
337898944Sobrien     struct. */
3379130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void);
3380130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char);
3381130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short);
3382130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int);
3383130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long);
3384130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long);
3385130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char);
3386130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char);
3387130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short);
3388130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int);
3389130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long);
3390130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long);
3391130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float);
3392130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double);
3393130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double);
3394130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex);
3395130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex);
3396130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string);
3397130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int8);
3398130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint8);
3399130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int16);
3400130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint16);
3401130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int32);
3402130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint32);
3403130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int64);
3404130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint64);
3405130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int128);
3406130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_uint128);
3407130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf);
3408130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si);
3409130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi);
3410130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi);
3411130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi);
3412130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi);
3413130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si);
3414130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double);
3415130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float);
3416130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64);
3417130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32);
3418130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16);
3419130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8);
3420130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float);
3421130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32);
3422130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8);
3423130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16);
3424130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128);
3425130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128i);
3426130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3427130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3428130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3429130803Smarcel  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3430130803Smarcel  deprecated_register_gdbarch_swap (NULL, 0, build_gdbtypes);
343198944Sobrien
343298944Sobrien  /* Note: These types do not need to be swapped - they are target
343398944Sobrien     neutral.  */
343498944Sobrien  builtin_type_ieee_single_big =
343598944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
343698944Sobrien	       0, "builtin_type_ieee_single_big", NULL);
343798944Sobrien  TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
343898944Sobrien  builtin_type_ieee_single_little =
343998944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
344098944Sobrien	       0, "builtin_type_ieee_single_little", NULL);
344198944Sobrien  TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little;
344298944Sobrien  builtin_type_ieee_double_big =
344398944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
344498944Sobrien	       0, "builtin_type_ieee_double_big", NULL);
344598944Sobrien  TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big;
344698944Sobrien  builtin_type_ieee_double_little =
344798944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
344898944Sobrien	       0, "builtin_type_ieee_double_little", NULL);
344998944Sobrien  TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little;
345098944Sobrien  builtin_type_ieee_double_littlebyte_bigword =
345198944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
345298944Sobrien	       0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
345398944Sobrien  TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword;
345498944Sobrien  builtin_type_i387_ext =
345598944Sobrien    init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
345698944Sobrien	       0, "builtin_type_i387_ext", NULL);
345798944Sobrien  TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
345898944Sobrien  builtin_type_m68881_ext =
345998944Sobrien    init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
346098944Sobrien	       0, "builtin_type_m68881_ext", NULL);
346198944Sobrien  TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext;
346298944Sobrien  builtin_type_i960_ext =
346398944Sobrien    init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
346498944Sobrien	       0, "builtin_type_i960_ext", NULL);
346598944Sobrien  TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext;
346698944Sobrien  builtin_type_m88110_ext =
346798944Sobrien    init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
346898944Sobrien	       0, "builtin_type_m88110_ext", NULL);
346998944Sobrien  TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext;
347098944Sobrien  builtin_type_m88110_harris_ext =
347198944Sobrien    init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
347298944Sobrien	       0, "builtin_type_m88110_harris_ext", NULL);
347398944Sobrien  TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext;
347498944Sobrien  builtin_type_arm_ext_big =
347598944Sobrien    init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
347698944Sobrien	       0, "builtin_type_arm_ext_big", NULL);
347798944Sobrien  TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big;
347898944Sobrien  builtin_type_arm_ext_littlebyte_bigword =
347998944Sobrien    init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
348098944Sobrien	       0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
348198944Sobrien  TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword;
348298944Sobrien  builtin_type_ia64_spill_big =
348398944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
348498944Sobrien	       0, "builtin_type_ia64_spill_big", NULL);
348598944Sobrien  TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big;
348698944Sobrien  builtin_type_ia64_spill_little =
348798944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
348898944Sobrien	       0, "builtin_type_ia64_spill_little", NULL);
348998944Sobrien  TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little;
349098944Sobrien  builtin_type_ia64_quad_big =
349198944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
349298944Sobrien	       0, "builtin_type_ia64_quad_big", NULL);
349398944Sobrien  TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big;
349498944Sobrien  builtin_type_ia64_quad_little =
349598944Sobrien    init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
349698944Sobrien	       0, "builtin_type_ia64_quad_little", NULL);
349798944Sobrien  TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little;
349898944Sobrien
349998944Sobrien  add_show_from_set (
350098944Sobrien		     add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
350198944Sobrien				  "Set debugging of C++ overloading.\n\
350298944Sobrien			  When enabled, ranking of the functions\n\
350398944Sobrien			  is displayed.", &setdebuglist),
350498944Sobrien		     &showdebuglist);
350546283Sdfr}
3506