Add self to write-after-approval list.
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 20166722d3f3d4b8de0524f7c9c9b5f29f60fa25..86499e2b683ce0c9b3f4bc71c442d074a3127c34 100644 (file)
@@ -1,5 +1,6 @@
 /* Support routines for manipulating internal types for GDB.
-   Copyright (C) 1992, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.
+   Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000
+   Free Software Foundation, Inc.
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
    This file is part of GDB.
@@ -33,6 +34,7 @@
 #include "demangle.h"
 #include "complaints.h"
 #include "gdbcmd.h"
+#include "wrapper.h"
 
 /* These variables point to the objects
    representing the predefined C data types.  */
@@ -75,24 +77,24 @@ struct type *builtin_type_CORE_ADDR;
 struct type *builtin_type_bfd_vma;
 
 int opaque_type_resolution = 1;
-
+int overload_debug = 0;
 
 struct extra
   {
     char str[128];
     int len;
-  };                           /* maximum extention is 128! FIXME */
+  };                           /* maximum extension is 128! FIXME */
 
-static void add_name PARAMS ((struct extra *, char *));
-static void add_mangled_type PARAMS ((struct extra *, struct type *));
+static void add_name (struct extra *, char *);
+static void add_mangled_type (struct extra *, struct type *);
 #if 0
-static void cfront_mangle_name PARAMS ((struct type *, int, int));
+static void cfront_mangle_name (struct type *, int, int);
 #endif
-static void print_bit_vector PARAMS ((B_TYPE *, int));
-static void print_arg_types PARAMS ((struct type **, int));
-static void dump_fn_fieldlists PARAMS ((struct type *, int));
-static void print_cplus_stuff PARAMS ((struct type *, int));
-static void virtual_base_list_aux PARAMS ((struct type * dclass));
+static void print_bit_vector (B_TYPE *, int);
+static void print_arg_types (struct type **, int);
+static void dump_fn_fieldlists (struct type *, int);
+static void print_cplus_stuff (struct type *, int);
+static void virtual_base_list_aux (struct type *dclass);
 
 
 /* Alloc a new type structure and fill it with some defaults.  If
@@ -100,8 +102,7 @@ static void virtual_base_list_aux PARAMS ((struct type * dclass));
    in that objfile's type_obstack. */
 
 struct type *
-alloc_type (objfile)
-     struct objfile *objfile;
+alloc_type (struct objfile *objfile)
 {
   register struct type *type;
 
@@ -135,9 +136,7 @@ alloc_type (objfile)
    We allocate new memory if needed.  */
 
 struct type *
-make_pointer_type (type, typeptr)
-     struct type *type;
-     struct type **typeptr;
+make_pointer_type (struct type *type, struct type **typeptr)
 {
   register struct type *ntype; /* New type */
   struct objfile *objfile;
@@ -178,7 +177,9 @@ make_pointer_type (type, typeptr)
   TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
   TYPE_CODE (ntype) = TYPE_CODE_PTR;
 
-  /* pointers are unsigned */
+  /* Mark pointers as unsigned.  The target converts between pointers
+     and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
+     ADDRESS_TO_POINTER(). */
   TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
 
   if (!TYPE_POINTER_TYPE (type))       /* Remember it, if don't have one.  */
@@ -191,8 +192,7 @@ make_pointer_type (type, typeptr)
    May need to construct such a type if this is the first use.  */
 
 struct type *
-lookup_pointer_type (type)
-     struct type *type;
+lookup_pointer_type (struct type *type)
 {
   return make_pointer_type (type, (struct type **) 0);
 }
@@ -203,9 +203,7 @@ lookup_pointer_type (type)
    We allocate new memory if needed.  */
 
 struct type *
-make_reference_type (type, typeptr)
-     struct type *type;
-     struct type **typeptr;
+make_reference_type (struct type *type, struct type **typeptr)
 {
   register struct type *ntype; /* New type */
   struct objfile *objfile;
@@ -256,8 +254,7 @@ make_reference_type (type, typeptr)
 /* Same as above, but caller doesn't care about memory allocation details.  */
 
 struct type *
-lookup_reference_type (type)
-     struct type *type;
+lookup_reference_type (struct type *type)
 {
   return make_reference_type (type, (struct type **) 0);
 }
@@ -268,9 +265,7 @@ lookup_reference_type (type)
    We allocate new memory if needed.  */
 
 struct type *
-make_function_type (type, typeptr)
-     struct type *type;
-     struct type **typeptr;
+make_function_type (struct type *type, struct type **typeptr)
 {
   register struct type *ntype; /* New type */
   struct objfile *objfile;
@@ -303,8 +298,7 @@ make_function_type (type, typeptr)
    May need to construct such a type if this is the first use.  */
 
 struct type *
-lookup_function_type (type)
-     struct type *type;
+lookup_function_type (struct type *type)
 {
   return make_function_type (type, (struct type **) 0);
 }
@@ -321,11 +315,7 @@ lookup_function_type (type)
    We allocate new memory if needed.  */
 
 struct type *
-make_cv_type (cnst, voltl, type, typeptr)
-     int cnst;
-     int voltl;
-     struct type *type;
-     struct type **typeptr;
+make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
 {
   register struct type *ntype; /* New type */
   register struct type *tmp_type = type;       /* tmp type */
@@ -399,9 +389,7 @@ make_cv_type (cnst, voltl, type, typeptr)
    of the aggregate that the member belongs to.  */
 
 struct type *
-lookup_member_type (type, domain)
-     struct type *type;
-     struct type *domain;
+lookup_member_type (struct type *type, struct type *domain)
 {
   register struct type *mtype;
 
@@ -417,8 +405,7 @@ lookup_member_type (type, domain)
    This always returns a fresh type.   */
 
 struct type *
-allocate_stub_method (type)
-     struct type *type;
+allocate_stub_method (struct type *type)
 {
   struct type *mtype;
 
@@ -442,11 +429,8 @@ allocate_stub_method (type)
    sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
 
 struct type *
-create_range_type (result_type, index_type, low_bound, high_bound)
-     struct type *result_type;
-     struct type *index_type;
-     int low_bound;
-     int high_bound;
+create_range_type (struct type *result_type, struct type *index_type,
+                  int low_bound, int high_bound)
 {
   if (result_type == NULL)
     {
@@ -478,9 +462,7 @@ create_range_type (result_type, index_type, low_bound, high_bound)
    will fit in LONGEST), or -1 otherwise. */
 
 int
-get_discrete_bounds (type, lowp, highp)
-     struct type *type;
-     LONGEST *lowp, *highp;
+get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
 {
   CHECK_TYPEDEF (type);
   switch (TYPE_CODE (type))
@@ -554,10 +536,8 @@ get_discrete_bounds (type, lowp, highp)
    sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
 
 struct type *
-create_array_type (result_type, element_type, range_type)
-     struct type *result_type;
-     struct type *element_type;
-     struct type *range_type;
+create_array_type (struct type *result_type, struct type *element_type,
+                  struct type *range_type)
 {
   LONGEST low_bound, high_bound;
 
@@ -598,9 +578,7 @@ create_array_type (result_type, element_type, range_type)
    sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
 
 struct type *
-create_string_type (result_type, range_type)
-     struct type *result_type;
-     struct type *range_type;
+create_string_type (struct type *result_type, struct type *range_type)
 {
   result_type = create_array_type (result_type,
                                   *current_language->string_char_type,
@@ -610,9 +588,7 @@ create_string_type (result_type, range_type)
 }
 
 struct type *
-create_set_type (result_type, domain_type)
-     struct type *result_type;
-     struct type *domain_type;
+create_set_type (struct type *result_type, struct type *domain_type)
 {
   LONGEST low_bound, high_bound, bit_length;
   if (result_type == NULL)
@@ -690,10 +666,8 @@ init_simd_type (char *name,
    allocated.  */
 
 void
-smash_to_member_type (type, domain, to_type)
-     struct type *type;
-     struct type *domain;
-     struct type *to_type;
+smash_to_member_type (struct type *type, struct type *domain,
+                     struct type *to_type)
 {
   struct objfile *objfile;
 
@@ -715,11 +689,8 @@ smash_to_member_type (type, domain, to_type)
    allocated.  */
 
 void
-smash_to_method_type (type, domain, to_type, args)
-     struct type *type;
-     struct type *domain;
-     struct type *to_type;
-     struct type **args;
+smash_to_method_type (struct type *type, struct type *domain,
+                     struct type *to_type, struct type **args)
 {
   struct objfile *objfile;
 
@@ -738,8 +709,7 @@ smash_to_method_type (type, domain, to_type, args)
    "union ", or "enum ".  If the type has a NULL name, return NULL.  */
 
 char *
-type_name_no_tag (type)
-     register const struct type *type;
+type_name_no_tag (register const struct type *type)
 {
   if (TYPE_TAG_NAME (type) != NULL)
     return TYPE_TAG_NAME (type);
@@ -754,8 +724,7 @@ type_name_no_tag (type)
    Return zero if NAME is not a primitive type. */
 
 struct type *
-lookup_primitive_typename (name)
-     char *name;
+lookup_primitive_typename (char *name)
 {
   struct type **const *p;
 
@@ -774,10 +743,7 @@ lookup_primitive_typename (name)
    If NOERR is nonzero, return zero if NAME is not suitably defined.  */
 
 struct type *
-lookup_typename (name, block, noerr)
-     char *name;
-     struct block *block;
-     int noerr;
+lookup_typename (char *name, struct block *block, int noerr)
 {
   register struct symbol *sym;
   register struct type *tmp;
@@ -803,8 +769,7 @@ lookup_typename (name, block, noerr)
 }
 
 struct type *
-lookup_unsigned_typename (name)
-     char *name;
+lookup_unsigned_typename (char *name)
 {
   char *uns = alloca (strlen (name) + 10);
 
@@ -814,8 +779,7 @@ lookup_unsigned_typename (name)
 }
 
 struct type *
-lookup_signed_typename (name)
-     char *name;
+lookup_signed_typename (char *name)
 {
   struct type *t;
   char *uns = alloca (strlen (name) + 8);
@@ -833,9 +797,7 @@ lookup_signed_typename (name)
    visible in lexical block BLOCK.  */
 
 struct type *
-lookup_struct (name, block)
-     char *name;
-     struct block *block;
+lookup_struct (char *name, struct block *block)
 {
   register struct symbol *sym;
 
@@ -857,9 +819,7 @@ lookup_struct (name, block)
    visible in lexical block BLOCK.  */
 
 struct type *
-lookup_union (name, block)
-     char *name;
-     struct block *block;
+lookup_union (char *name, struct block *block)
 {
   register struct symbol *sym;
   struct type *t;
@@ -891,9 +851,7 @@ lookup_union (name, block)
    visible in lexical block BLOCK.  */
 
 struct type *
-lookup_enum (name, block)
-     char *name;
-     struct block *block;
+lookup_enum (char *name, struct block *block)
 {
   register struct symbol *sym;
 
@@ -914,10 +872,7 @@ lookup_enum (name, block)
    visible in lexical block BLOCK.  */
 
 struct type *
-lookup_template_type (name, type, block)
-     char *name;
-     struct type *type;
-     struct block *block;
+lookup_template_type (char *name, struct type *type, struct block *block)
 {
   struct symbol *sym;
   char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4);
@@ -950,10 +905,7 @@ lookup_template_type (name, type, block)
    If NAME is the name of a baseclass type, return that type.  */
 
 struct type *
-lookup_struct_elt_type (type, name, noerr)
-     struct type *type;
-     char *name;
-     int noerr;
+lookup_struct_elt_type (struct type *type, char *name, int noerr)
 {
   int i;
 
@@ -994,7 +946,7 @@ lookup_struct_elt_type (type, name, noerr)
     {
       char *t_field_name = TYPE_FIELD_NAME (type, i);
 
-      if (t_field_name && STREQ (t_field_name, name))
+      if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
        {
          return TYPE_FIELD_TYPE (type, i);
        }
@@ -1035,8 +987,7 @@ lookup_struct_elt_type (type, name, noerr)
    will remain NULL.  */
 
 void
-fill_in_vptr_fieldno (type)
-     struct type *type;
+fill_in_vptr_fieldno (struct type *type)
 {
   CHECK_TYPEDEF (type);
 
@@ -1065,10 +1016,7 @@ fill_in_vptr_fieldno (type)
    Return 1 if the destructor was found, otherwise, return 0.  */
 
 int
-get_destructor_fn_field (t, method_indexp, field_indexp)
-     struct type *t;
-     int *method_indexp;
-     int *field_indexp;
+get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
 {
   int i;
 
@@ -1107,8 +1055,7 @@ struct complaint stub_noname_complaint =
 {"stub type has NULL name", 0, 0};
 
 struct type *
-check_typedef (type)
-     register struct type *type;
+check_typedef (register struct type *type)
 {
   struct type *orig_type = type;
   while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
@@ -1218,14 +1165,11 @@ check_typedef (type)
 }
 
 /* New code added to support parsing of Cfront stabs strings */
-#include <ctype.h>
 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
 
 static void
-add_name (pextras, n)
-     struct extra *pextras;
-     char *n;
+add_name (struct extra *pextras, char *n)
 {
   int nlen;
 
@@ -1236,9 +1180,7 @@ add_name (pextras, n)
 }
 
 static void
-add_mangled_type (pextras, t)
-     struct extra *pextras;
-     struct type *t;
+add_mangled_type (struct extra *pextras, struct type *t)
 {
   enum type_code tcode;
   int tlen, tflags;
@@ -1368,10 +1310,7 @@ add_mangled_type (pextras, t)
 
 #if 0
 void
-cfront_mangle_name (type, i, j)
-     struct type *type;
-     int i;
-     int j;
+cfront_mangle_name (struct type *type, int i, int j)
 {
   struct fn_field *f;
   char *mangled_name = gdb_mangle_name (type, i, j);
@@ -1411,9 +1350,8 @@ cfront_mangle_name (type, i, j)
          }
       ADD_EXTRA ('\0')
        printf ("add_mangled_type: %s\n", extras.str);  /* FIXME */
-      arm_mangled_name = malloc (strlen (mangled_name) + extras.len);
-      sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str);
-      free (mangled_name);
+      xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
+      xfree (mangled_name);
       mangled_name = arm_mangled_name;
     }
 }
@@ -1422,6 +1360,30 @@ cfront_mangle_name (type, i, j)
 #undef ADD_EXTRA
 /* End of new code added to support parsing of Cfront stabs strings */
 
+/* Parse a type expression in the string [P..P+LENGTH).  If an error occurs,
+   silently return builtin_type_void. */
+
+struct type *
+safe_parse_type (char *p, int length)
+{
+  struct ui_file *saved_gdb_stderr;
+  struct type *type;
+
+  /* Suppress error messages. */
+  saved_gdb_stderr = gdb_stderr;
+  gdb_stderr = ui_file_new ();
+
+  /* Call parse_and_eval_type() without fear of longjmp()s. */
+  if (!gdb_parse_and_eval_type (p, length, &type))
+    type = builtin_type_void;
+
+  /* Stop suppressing error messages. */
+  ui_file_delete (gdb_stderr);
+  gdb_stderr = saved_gdb_stderr;
+
+  return type;
+}
+
 /* Ugly hack to convert method stubs into method types.
 
    He ain't kiddin'.  This demangles the name of the method into a string
@@ -1433,10 +1395,7 @@ cfront_mangle_name (type, i, j)
    the space required for them.  */
 
 void
-check_stub_method (type, method_id, signature_id)
-     struct type *type;
-     int method_id;
-     int signature_id;
+check_stub_method (struct type *type, int method_id, int signature_id)
 {
   struct fn_field *f;
   char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
@@ -1459,11 +1418,11 @@ check_stub_method (type, method_id, signature_id)
   argtypetext = p;
   while (*p)
     {
-      if (*p == '(')
+      if (*p == '(' || *p == '<')
        {
          depth += 1;
        }
-      else if (*p == ')')
+      else if (*p == ')' || *p == '>')
        {
          depth -= 1;
        }
@@ -1496,17 +1455,17 @@ check_stub_method (type, method_id, signature_id)
              if (strncmp (argtypetext, "...", p - argtypetext) != 0)
                {
                  argtypes[argcount] =
-                   parse_and_eval_type (argtypetext, p - argtypetext);
+                   safe_parse_type (argtypetext, p - argtypetext);
                  argcount += 1;
                }
              argtypetext = p + 1;
            }
 
-         if (*p == '(')
+         if (*p == '(' || *p == '<')
            {
              depth += 1;
            }
-         else if (*p == ')')
+         else if (*p == ')' || *p == '>')
            {
              depth -= 1;
            }
@@ -1524,7 +1483,7 @@ check_stub_method (type, method_id, signature_id)
       argtypes[argcount] = NULL;       /* Ellist terminator */
     }
 
-  free (demangled_name);
+  xfree (demangled_name);
 
   f = TYPE_FN_FIELDLIST1 (type, method_id);
 
@@ -1541,8 +1500,7 @@ check_stub_method (type, method_id, signature_id)
 const struct cplus_struct_type cplus_struct_default;
 
 void
-allocate_cplus_struct_type (type)
-     struct type *type;
+allocate_cplus_struct_type (struct type *type)
 {
   if (!HAVE_CPLUS_STRUCT (type))
     {
@@ -1560,12 +1518,8 @@ allocate_cplus_struct_type (type)
    in particular, where init_type is called with a NULL value for NAME). */
 
 struct type *
-init_type (code, length, flags, name, objfile)
-     enum type_code code;
-     int length;
-     int flags;
-     char *name;
-     struct objfile *objfile;
+init_type (enum type_code code, int length, int flags, char *name,
+          struct objfile *objfile)
 {
   register struct type *type;
 
@@ -1614,9 +1568,7 @@ init_type (code, length, flags, name, objfile)
 
 
 struct type *
-lookup_fundamental_type (objfile, typeid)
-     struct objfile *objfile;
-     int typeid;
+lookup_fundamental_type (struct objfile *objfile, int typeid)
 {
   register struct type **typep;
   register int nbytes;
@@ -1651,8 +1603,7 @@ lookup_fundamental_type (objfile, typeid)
 }
 
 int
-can_dereference (t)
-     struct type *t;
+can_dereference (struct type *t)
 {
   /* FIXME: Should we return true for references as well as pointers?  */
   CHECK_TYPEDEF (t);
@@ -1663,8 +1614,7 @@ can_dereference (t)
 }
 
 int
-is_integral_type (t)
-     struct type *t;
+is_integral_type (struct type *t)
 {
   CHECK_TYPEDEF (t);
   return
@@ -1683,8 +1633,7 @@ is_integral_type (t)
    Return true if TYPE is such a Chill varying type. */
 
 int
-chill_varying_type (type)
-     struct type *type;
+chill_varying_type (struct type *type)
 {
   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
       || TYPE_NFIELDS (type) != 2
@@ -1700,9 +1649,7 @@ chill_varying_type (type)
    the ancestor relationship even if they're identical */
 
 int
-is_ancestor (base, dclass)
-     struct type *base;
-     struct type *dclass;
+is_ancestor (struct type *base, struct type *dclass)
 {
   int i;
 
@@ -1711,6 +1658,9 @@ is_ancestor (base, dclass)
 
   if (base == dclass)
     return 1;
+  if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
+      !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
+    return 1;
 
   for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
     if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
@@ -1726,8 +1676,7 @@ is_ancestor (base, dclass)
    runtime models.  Return 1 => Yes, 0 => No.  */
 
 int
-has_vtable (dclass)
-     struct type *dclass;
+has_vtable (struct type *dclass)
 {
   /* In the HP ANSI C++ runtime model, a class has a vtable only if it
      has virtual functions or virtual bases.  */
@@ -1769,8 +1718,7 @@ has_vtable (dclass)
    and may not work with other runtime models.  */
 
 struct type *
-primary_base_class (dclass)
-     struct type *dclass;
+primary_base_class (struct type *dclass)
 {
   /* In HP ANSI C++'s runtime model, a "primary base class" of a class
      is the first directly inherited, non-virtual base class that
@@ -1802,8 +1750,7 @@ static struct vbase *current_vbase_list = NULL;
    copies the items out in reverse order.  */
 
 static void
-virtual_base_list_aux (dclass)
-     struct type *dclass;
+virtual_base_list_aux (struct type *dclass)
 {
   struct vbase *tmp_vbase;
   register int i;
@@ -1861,8 +1808,7 @@ virtual_base_list_aux (dclass)
    and then copies the result into an array to save space.  */
 
 struct type **
-virtual_base_list (dclass)
-     struct type *dclass;
+virtual_base_list (struct type *dclass)
 {
   register struct vbase *tmp_vbase;
   register struct vbase *tmp_vbase_2;
@@ -1888,7 +1834,7 @@ virtual_base_list (dclass)
   while (tmp_vbase)
     {
       tmp_vbase = tmp_vbase->next;
-      free (tmp_vbase_2);
+      xfree (tmp_vbase_2);
       tmp_vbase_2 = tmp_vbase;
     }
 
@@ -1899,8 +1845,7 @@ virtual_base_list (dclass)
 /* Return the length of the virtual base list of the type DCLASS.  */
 
 int
-virtual_base_list_length (dclass)
-     struct type *dclass;
+virtual_base_list_length (struct type *dclass)
 {
   register int i;
   register struct vbase *tmp_vbase;
@@ -1918,8 +1863,7 @@ virtual_base_list_length (dclass)
    primary base, recursively).  */
 
 int
-virtual_base_list_length_skip_primaries (dclass)
-     struct type *dclass;
+virtual_base_list_length_skip_primaries (struct type *dclass)
 {
   register int i;
   register struct vbase *tmp_vbase;
@@ -1948,9 +1892,7 @@ virtual_base_list_length_skip_primaries (dclass)
    indicates "not found" or a problem.  */
 
 int
-virtual_base_index (base, dclass)
-     struct type *base;
-     struct type *dclass;
+virtual_base_index (struct type *base, struct type *dclass)
 {
   register struct type *vbase;
   register int i;
@@ -1980,9 +1922,7 @@ virtual_base_index (base, dclass)
    found" or a problem.  */
 
 int
-virtual_base_index_skip_primaries (base, dclass)
-     struct type *base;
-     struct type *dclass;
+virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
 {
   register struct type *vbase;
   register int i, j;
@@ -2014,8 +1954,7 @@ virtual_base_index_skip_primaries (base, dclass)
  * Position returned is 0-based. */
 
 int
-class_index_in_primary_list (dclass)
-     struct type *dclass;
+class_index_in_primary_list (struct type *dclass)
 {
   struct type *pbc;            /* primary base class */
 
@@ -2037,8 +1976,7 @@ class_index_in_primary_list (dclass)
  */
 
 int
-count_virtual_fns (dclass)
-     struct type *dclass;
+count_virtual_fns (struct type *dclass)
 {
   int fn, oi;                  /* function and overloaded instance indices */
   int vfuncs;                  /* count to return */
@@ -2047,6 +1985,8 @@ count_virtual_fns (dclass)
   struct type *pbc = primary_base_class (dclass);
   if (pbc)
     vfuncs = count_virtual_fns (pbc);
+  else
+    vfuncs = 0;
 
   for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
     for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
@@ -2067,9 +2007,7 @@ count_virtual_fns (dclass)
  * 3 => A is worse than B */
 
 int
-compare_badness (a, b)
-     struct badness_vector *a;
-     struct badness_vector *b;
+compare_badness (struct badness_vector *a, struct badness_vector *b)
 {
   int i;
   int tmp;
@@ -2112,11 +2050,7 @@ compare_badness (a, b)
  * Return a pointer to a badness vector. This has NARGS + 1 entries. */
 
 struct badness_vector *
-rank_function (parms, nparms, args, nargs)
-     struct type **parms;
-     int nparms;
-     struct type **args;
-     int nargs;
+rank_function (struct type **parms, int nparms, struct type **args, int nargs)
 {
   int i;
   struct badness_vector *bv;
@@ -2137,7 +2071,7 @@ rank_function (parms, nparms, args, nargs)
 
   /* Now rank all the parameters of the candidate function */
   for (i = 1; i <= min_len; i++)
-    bv->rank[i] = rank_one_type (parms[i - 1], args[i - 1]);
+    bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
 
   /* If more arguments than parameters, add dummy entries */
   for (i = min_len + 1; i <= nargs; i++)
@@ -2157,9 +2091,7 @@ rank_function (parms, nparms, args, nargs)
  * Generally the "bad" conversions are all uniformly assigned a 100 */
 
 int
-rank_one_type (parm, arg)
-     struct type *parm;
-     struct type *arg;
+rank_one_type (struct type *parm, struct type *arg)
 {
   /* Identical type pointers */
   /* However, this still doesn't catch all cases of same type for arg
@@ -2174,15 +2106,33 @@ rank_one_type (parm, arg)
   if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
     arg = check_typedef (arg);
 
+  /*
+     Well, damnit, if the names are exactly the same,
+     i'll say they are exactly the same. This happens when we generate
+     method stubs. The types won't point to the same address, but they
+     really are the same.
+  */
+
+  if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
+      !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
+      return 0;
+
   /* Check if identical after resolving typedefs */
   if (parm == arg)
     return 0;
 
-#if 0
-  /* Debugging only */
-  printf ("------ Arg is %s [%d], parm is %s [%d]\n",
-      TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
-#endif
+  /* See through references, since we can almost make non-references
+     references. */
+  if (TYPE_CODE (arg) == TYPE_CODE_REF)
+    return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
+           + REFERENCE_CONVERSION_BADNESS);
+  if (TYPE_CODE (parm) == TYPE_CODE_REF)
+    return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
+           + REFERENCE_CONVERSION_BADNESS);
+  if (overload_debug)
+  /* Debugging only. */
+    fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
+        TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
 
   /* x -> y means arg of type x being supplied for parameter of type y */
 
@@ -2246,16 +2196,16 @@ rank_one_type (parm, arg)
                {
                  if (TYPE_UNSIGNED (arg))
                    {
-                     if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
+                     if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
                        return 0;       /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
-                     else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long"))
+                     else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
                        return INTEGER_PROMOTION_BADNESS;       /* unsigned int -> unsigned long */
                      else
                        return INTEGER_COERCION_BADNESS;        /* unsigned long -> unsigned int */
                    }
                  else
                    {
-                     if (!strcmp (TYPE_NAME (arg), "long") && !strcmp (TYPE_NAME (parm), "int"))
+                     if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int"))
                        return INTEGER_COERCION_BADNESS;        /* signed long -> unsigned int */
                      else
                        return INTEGER_CONVERSION_BADNESS;      /* signed int/long -> unsigned int/long */
@@ -2263,9 +2213,9 @@ rank_one_type (parm, arg)
                }
              else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
                {
-                 if (!strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
+                 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
                    return 0;
-                 else if (!strcmp (TYPE_NAME (arg), "int") && !strcmp (TYPE_NAME (parm), "long"))
+                 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
                    return INTEGER_PROMOTION_BADNESS;
                  else
                    return INTEGER_COERCION_BADNESS;
@@ -2472,9 +2422,7 @@ rank_one_type (parm, arg)
 /* End of functions for overload resolution */
 
 static void
-print_bit_vector (bits, nbits)
-     B_TYPE *bits;
-     int nbits;
+print_bit_vector (B_TYPE *bits, int nbits)
 {
   int bitno;
 
@@ -2502,9 +2450,7 @@ print_bit_vector (bits, nbits)
    include it since we may get into a infinitely recursive situation. */
 
 static void
-print_arg_types (args, spaces)
-     struct type **args;
-     int spaces;
+print_arg_types (struct type **args, int spaces)
 {
   if (args != NULL)
     {
@@ -2520,9 +2466,7 @@ print_arg_types (args, spaces)
 }
 
 static void
-dump_fn_fieldlists (type, spaces)
-     struct type *type;
-     int spaces;
+dump_fn_fieldlists (struct type *type, int spaces)
 {
   int method_idx;
   int overload_idx;
@@ -2585,9 +2529,7 @@ dump_fn_fieldlists (type, spaces)
 }
 
 static void
-print_cplus_stuff (type, spaces)
-     struct type *type;
-     int spaces;
+print_cplus_stuff (struct type *type, int spaces)
 {
   printfi_filtered (spaces, "n_baseclasses %d\n",
                    TYPE_N_BASECLASSES (type));
@@ -2638,9 +2580,7 @@ print_cplus_stuff (type, spaces)
 static struct obstack dont_print_type_obstack;
 
 void
-recursive_dump_type (type, spaces)
-     struct type *type;
-     int spaces;
+recursive_dump_type (struct type *type, int spaces)
 {
   int idx;
 
@@ -2843,9 +2783,9 @@ recursive_dump_type (type, spaces)
     obstack_free (&dont_print_type_obstack, NULL);
 }
 
-static void build_gdbtypes PARAMS ((void));
+static void build_gdbtypes (void);
 static void
-build_gdbtypes ()
+build_gdbtypes (void)
 {
   builtin_type_void =
     init_type (TYPE_CODE_VOID, 1,
@@ -2988,12 +2928,9 @@ build_gdbtypes ()
   /* NOTE: At present there is no way of differentiating between at
      target address and the target C language pointer type type even
      though the two can be different (cf d10v) */
-  builtin_type_ptr =
-    init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8,
-              TYPE_FLAG_UNSIGNED,
-              "__ptr", (struct objfile *) NULL);
+  builtin_type_ptr = make_pointer_type (builtin_type_void, NULL);
   builtin_type_CORE_ADDR =
-    init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8,
+    init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
               TYPE_FLAG_UNSIGNED,
               "__CORE_ADDR", (struct objfile *) NULL);
   builtin_type_bfd_vma =
@@ -3003,10 +2940,11 @@ build_gdbtypes ()
 }
 
 
-extern void _initialize_gdbtypes PARAMS ((void));
+extern void _initialize_gdbtypes (void);
 void
-_initialize_gdbtypes ()
+_initialize_gdbtypes (void)
 {
+  struct cmd_list_element *c;
   build_gdbtypes ();
 
   /* FIXME - For the moment, handle types by swapping them in and out.
@@ -3047,4 +2985,11 @@ _initialize_gdbtypes ()
   REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
   REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
   register_gdbarch_swap (NULL, 0, build_gdbtypes);
+
+  add_show_from_set (
+                    add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
+                                 "Set debugging of C++ overloading.\n\
+                         When enabled, ranking of the functions\n\
+                         is displayed.", &setdebuglist),
+                    &showdebuglist);
 }
This page took 0.036427 seconds and 4 git commands to generate.