Catch and ignore empty, ineffectual alignment frags when deciding if a
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index a94093134550b243bb71ce30299ecd9d6ffb0b06..ee191cdd0bb239e47ff7e548028d8ddd711efd1f 100644 (file)
@@ -1,5 +1,6 @@
 /* Support routines for manipulating internal types for GDB.
 /* 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.
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
    This file is part of GDB.
@@ -33,6 +34,8 @@
 #include "demangle.h"
 #include "complaints.h"
 #include "gdbcmd.h"
 #include "demangle.h"
 #include "complaints.h"
 #include "gdbcmd.h"
+#include "wrapper.h"
+#include "cp-abi.h"
 
 /* These variables point to the objects
    representing the predefined C data types.  */
 
 /* These variables point to the objects
    representing the predefined C data types.  */
@@ -75,24 +78,24 @@ struct type *builtin_type_CORE_ADDR;
 struct type *builtin_type_bfd_vma;
 
 int opaque_type_resolution = 1;
 struct type *builtin_type_bfd_vma;
 
 int opaque_type_resolution = 1;
-
+int overload_debug = 0;
 
 struct extra
   {
     char str[128];
     int len;
 
 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
 #if 0
-static void cfront_mangle_name PARAMS ((struct type *, int, int));
+static void cfront_mangle_name (struct type *, int, int);
 #endif
 #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
 
 
 /* Alloc a new type structure and fill it with some defaults.  If
@@ -100,8 +103,7 @@ static void virtual_base_list_aux PARAMS ((struct type * dclass));
    in that objfile's type_obstack. */
 
 struct type *
    in that objfile's type_obstack. */
 
 struct type *
-alloc_type (objfile)
-     struct objfile *objfile;
+alloc_type (struct objfile *objfile)
 {
   register struct type *type;
 
 {
   register struct type *type;
 
@@ -135,9 +137,7 @@ alloc_type (objfile)
    We allocate new memory if needed.  */
 
 struct type *
    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;
 {
   register struct type *ntype; /* New type */
   struct objfile *objfile;
@@ -178,7 +178,9 @@ make_pointer_type (type, typeptr)
   TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
   TYPE_CODE (ntype) = TYPE_CODE_PTR;
 
   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.  */
   TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
 
   if (!TYPE_POINTER_TYPE (type))       /* Remember it, if don't have one.  */
@@ -191,8 +193,7 @@ make_pointer_type (type, typeptr)
    May need to construct such a type if this is the first use.  */
 
 struct type *
    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);
 }
 {
   return make_pointer_type (type, (struct type **) 0);
 }
@@ -203,9 +204,7 @@ lookup_pointer_type (type)
    We allocate new memory if needed.  */
 
 struct 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;
 {
   register struct type *ntype; /* New type */
   struct objfile *objfile;
@@ -256,8 +255,7 @@ make_reference_type (type, typeptr)
 /* Same as above, but caller doesn't care about memory allocation details.  */
 
 struct type *
 /* 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);
 }
 {
   return make_reference_type (type, (struct type **) 0);
 }
@@ -268,9 +266,7 @@ lookup_reference_type (type)
    We allocate new memory if needed.  */
 
 struct 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;
 {
   register struct type *ntype; /* New type */
   struct objfile *objfile;
@@ -303,8 +299,7 @@ make_function_type (type, typeptr)
    May need to construct such a type if this is the first use.  */
 
 struct type *
    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);
 }
 {
   return make_function_type (type, (struct type **) 0);
 }
@@ -321,11 +316,7 @@ lookup_function_type (type)
    We allocate new memory if needed.  */
 
 struct 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 */
 {
   register struct type *ntype; /* New type */
   register struct type *tmp_type = type;       /* tmp type */
@@ -399,9 +390,7 @@ make_cv_type (cnst, voltl, type, typeptr)
    of the aggregate that the member belongs to.  */
 
 struct type *
    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;
 
 {
   register struct type *mtype;
 
@@ -417,8 +406,7 @@ lookup_member_type (type, domain)
    This always returns a fresh type.   */
 
 struct type *
    This always returns a fresh type.   */
 
 struct type *
-allocate_stub_method (type)
-     struct type *type;
+allocate_stub_method (struct type *type)
 {
   struct type *mtype;
 
 {
   struct type *mtype;
 
@@ -442,11 +430,8 @@ allocate_stub_method (type)
    sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
 
 struct 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)
     {
 {
   if (result_type == NULL)
     {
@@ -478,9 +463,7 @@ create_range_type (result_type, index_type, low_bound, high_bound)
    will fit in LONGEST), or -1 otherwise. */
 
 int
    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))
 {
   CHECK_TYPEDEF (type);
   switch (TYPE_CODE (type))
@@ -554,10 +537,8 @@ get_discrete_bounds (type, lowp, highp)
    sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
 
 struct type *
    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;
 
 {
   LONGEST low_bound, high_bound;
 
@@ -598,9 +579,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 *
    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,
 {
   result_type = create_array_type (result_type,
                                   *current_language->string_char_type,
@@ -610,9 +589,7 @@ create_string_type (result_type, range_type)
 }
 
 struct 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)
 {
   LONGEST low_bound, high_bound, bit_length;
   if (result_type == NULL)
@@ -690,10 +667,8 @@ init_simd_type (char *name,
    allocated.  */
 
 void
    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;
 
 {
   struct objfile *objfile;
 
@@ -715,11 +690,8 @@ smash_to_member_type (type, domain, to_type)
    allocated.  */
 
 void
    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;
 
 {
   struct objfile *objfile;
 
@@ -738,8 +710,7 @@ smash_to_method_type (type, domain, to_type, args)
    "union ", or "enum ".  If the type has a NULL name, return NULL.  */
 
 char *
    "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);
 {
   if (TYPE_TAG_NAME (type) != NULL)
     return TYPE_TAG_NAME (type);
@@ -754,8 +725,7 @@ type_name_no_tag (type)
    Return zero if NAME is not a primitive type. */
 
 struct 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;
 
 {
   struct type **const *p;
 
@@ -774,10 +744,7 @@ lookup_primitive_typename (name)
    If NOERR is nonzero, return zero if NAME is not suitably defined.  */
 
 struct type *
    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;
 {
   register struct symbol *sym;
   register struct type *tmp;
@@ -803,8 +770,7 @@ lookup_typename (name, block, noerr)
 }
 
 struct type *
 }
 
 struct type *
-lookup_unsigned_typename (name)
-     char *name;
+lookup_unsigned_typename (char *name)
 {
   char *uns = alloca (strlen (name) + 10);
 
 {
   char *uns = alloca (strlen (name) + 10);
 
@@ -814,8 +780,7 @@ lookup_unsigned_typename (name)
 }
 
 struct type *
 }
 
 struct type *
-lookup_signed_typename (name)
-     char *name;
+lookup_signed_typename (char *name)
 {
   struct type *t;
   char *uns = alloca (strlen (name) + 8);
 {
   struct type *t;
   char *uns = alloca (strlen (name) + 8);
@@ -833,9 +798,7 @@ lookup_signed_typename (name)
    visible in lexical block BLOCK.  */
 
 struct type *
    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;
 
 {
   register struct symbol *sym;
 
@@ -857,9 +820,7 @@ lookup_struct (name, block)
    visible in lexical block BLOCK.  */
 
 struct type *
    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;
 {
   register struct symbol *sym;
   struct type *t;
@@ -891,9 +852,7 @@ lookup_union (name, block)
    visible in lexical block BLOCK.  */
 
 struct type *
    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;
 
 {
   register struct symbol *sym;
 
@@ -914,10 +873,7 @@ lookup_enum (name, block)
    visible in lexical block BLOCK.  */
 
 struct type *
    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);
 {
   struct symbol *sym;
   char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4);
@@ -950,10 +906,7 @@ lookup_template_type (name, type, block)
    If NAME is the name of a baseclass type, return that type.  */
 
 struct type *
    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;
 
 {
   int i;
 
@@ -1035,8 +988,7 @@ lookup_struct_elt_type (type, name, noerr)
    will remain NULL.  */
 
 void
    will remain NULL.  */
 
 void
-fill_in_vptr_fieldno (type)
-     struct type *type;
+fill_in_vptr_fieldno (struct type *type)
 {
   CHECK_TYPEDEF (type);
 
 {
   CHECK_TYPEDEF (type);
 
@@ -1065,10 +1017,7 @@ fill_in_vptr_fieldno (type)
    Return 1 if the destructor was found, otherwise, return 0.  */
 
 int
    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;
 
 {
   int i;
 
@@ -1079,7 +1028,7 @@ get_destructor_fn_field (t, method_indexp, field_indexp)
 
       for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
        {
 
       for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
        {
-         if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j)))
+         if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
            {
              *method_indexp = i;
              *field_indexp = j;
            {
              *method_indexp = i;
              *field_indexp = j;
@@ -1107,8 +1056,7 @@ struct complaint stub_noname_complaint =
 {"stub type has NULL name", 0, 0};
 
 struct type *
 {"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)
 {
   struct type *orig_type = type;
   while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
@@ -1218,14 +1166,11 @@ check_typedef (type)
 }
 
 /* New code added to support parsing of Cfront stabs strings */
 }
 
 /* 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
 #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;
 
 {
   int nlen;
 
@@ -1236,9 +1181,7 @@ add_name (pextras, n)
 }
 
 static void
 }
 
 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;
 {
   enum type_code tcode;
   int tlen, tflags;
@@ -1368,10 +1311,7 @@ add_mangled_type (pextras, t)
 
 #if 0
 void
 
 #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);
 {
   struct fn_field *f;
   char *mangled_name = gdb_mangle_name (type, i, j);
@@ -1411,9 +1351,8 @@ cfront_mangle_name (type, i, j)
          }
       ADD_EXTRA ('\0')
        printf ("add_mangled_type: %s\n", extras.str);  /* FIXME */
          }
       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;
     }
 }
       mangled_name = arm_mangled_name;
     }
 }
@@ -1422,6 +1361,30 @@ cfront_mangle_name (type, i, j)
 #undef ADD_EXTRA
 /* End of new code added to support parsing of Cfront stabs strings */
 
 #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
 /* 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 +1396,7 @@ cfront_mangle_name (type, i, j)
    the space required for them.  */
 
 void
    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);
 {
   struct fn_field *f;
   char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
@@ -1450,6 +1410,8 @@ check_stub_method (type, method_id, signature_id)
   /* Make sure we got back a function string that we can use.  */
   if (demangled_name)
     p = strchr (demangled_name, '(');
   /* Make sure we got back a function string that we can use.  */
   if (demangled_name)
     p = strchr (demangled_name, '(');
+  else
+    p = NULL;
 
   if (demangled_name == NULL || p == NULL)
     error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
 
   if (demangled_name == NULL || p == NULL)
     error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
@@ -1459,11 +1421,11 @@ check_stub_method (type, method_id, signature_id)
   argtypetext = p;
   while (*p)
     {
   argtypetext = p;
   while (*p)
     {
-      if (*p == '(')
+      if (*p == '(' || *p == '<')
        {
          depth += 1;
        }
        {
          depth += 1;
        }
-      else if (*p == ')')
+      else if (*p == ')' || *p == '>')
        {
          depth -= 1;
        }
        {
          depth -= 1;
        }
@@ -1496,17 +1458,17 @@ check_stub_method (type, method_id, signature_id)
              if (strncmp (argtypetext, "...", p - argtypetext) != 0)
                {
                  argtypes[argcount] =
              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;
            }
 
                  argcount += 1;
                }
              argtypetext = p + 1;
            }
 
-         if (*p == '(')
+         if (*p == '(' || *p == '<')
            {
              depth += 1;
            }
            {
              depth += 1;
            }
-         else if (*p == ')')
+         else if (*p == ')' || *p == '>')
            {
              depth -= 1;
            }
            {
              depth -= 1;
            }
@@ -1524,7 +1486,7 @@ check_stub_method (type, method_id, signature_id)
       argtypes[argcount] = NULL;       /* Ellist terminator */
     }
 
       argtypes[argcount] = NULL;       /* Ellist terminator */
     }
 
-  free (demangled_name);
+  xfree (demangled_name);
 
   f = TYPE_FN_FIELDLIST1 (type, method_id);
 
 
   f = TYPE_FN_FIELDLIST1 (type, method_id);
 
@@ -1541,8 +1503,7 @@ check_stub_method (type, method_id, signature_id)
 const struct cplus_struct_type cplus_struct_default;
 
 void
 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))
     {
 {
   if (!HAVE_CPLUS_STRUCT (type))
     {
@@ -1560,12 +1521,8 @@ allocate_cplus_struct_type (type)
    in particular, where init_type is called with a NULL value for NAME). */
 
 struct 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;
 
 {
   register struct type *type;
 
@@ -1614,9 +1571,7 @@ init_type (code, length, flags, name, objfile)
 
 
 struct type *
 
 
 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;
 {
   register struct type **typep;
   register int nbytes;
@@ -1651,8 +1606,7 @@ lookup_fundamental_type (objfile, typeid)
 }
 
 int
 }
 
 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);
 {
   /* FIXME: Should we return true for references as well as pointers?  */
   CHECK_TYPEDEF (t);
@@ -1663,8 +1617,7 @@ can_dereference (t)
 }
 
 int
 }
 
 int
-is_integral_type (t)
-     struct type *t;
+is_integral_type (struct type *t)
 {
   CHECK_TYPEDEF (t);
   return
 {
   CHECK_TYPEDEF (t);
   return
@@ -1683,8 +1636,7 @@ is_integral_type (t)
    Return true if TYPE is such a Chill varying type. */
 
 int
    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
 {
   if (TYPE_CODE (type) != TYPE_CODE_STRUCT
       || TYPE_NFIELDS (type) != 2
@@ -1700,9 +1652,7 @@ chill_varying_type (type)
    the ancestor relationship even if they're identical */
 
 int
    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;
 
 {
   int i;
 
@@ -1711,6 +1661,9 @@ is_ancestor (base, dclass)
 
   if (base == dclass)
     return 1;
 
   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)))
 
   for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
     if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
@@ -1726,8 +1679,7 @@ is_ancestor (base, dclass)
    runtime models.  Return 1 => Yes, 0 => No.  */
 
 int
    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.  */
 {
   /* In the HP ANSI C++ runtime model, a class has a vtable only if it
      has virtual functions or virtual bases.  */
@@ -1769,8 +1721,7 @@ has_vtable (dclass)
    and may not work with other runtime models.  */
 
 struct type *
    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
 {
   /* 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 +1753,7 @@ static struct vbase *current_vbase_list = NULL;
    copies the items out in reverse order.  */
 
 static void
    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;
 {
   struct vbase *tmp_vbase;
   register int i;
@@ -1861,8 +1811,7 @@ virtual_base_list_aux (dclass)
    and then copies the result into an array to save space.  */
 
 struct type **
    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;
 {
   register struct vbase *tmp_vbase;
   register struct vbase *tmp_vbase_2;
@@ -1888,7 +1837,7 @@ virtual_base_list (dclass)
   while (tmp_vbase)
     {
       tmp_vbase = tmp_vbase->next;
   while (tmp_vbase)
     {
       tmp_vbase = tmp_vbase->next;
-      free (tmp_vbase_2);
+      xfree (tmp_vbase_2);
       tmp_vbase_2 = tmp_vbase;
     }
 
       tmp_vbase_2 = tmp_vbase;
     }
 
@@ -1899,8 +1848,7 @@ virtual_base_list (dclass)
 /* Return the length of the virtual base list of the type DCLASS.  */
 
 int
 /* 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;
 {
   register int i;
   register struct vbase *tmp_vbase;
@@ -1918,8 +1866,7 @@ virtual_base_list_length (dclass)
    primary base, recursively).  */
 
 int
    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;
 {
   register int i;
   register struct vbase *tmp_vbase;
@@ -1948,9 +1895,7 @@ virtual_base_list_length_skip_primaries (dclass)
    indicates "not found" or a problem.  */
 
 int
    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;
 {
   register struct type *vbase;
   register int i;
@@ -1960,12 +1905,12 @@ virtual_base_index (base, dclass)
     return -1;
 
   i = 0;
     return -1;
 
   i = 0;
-  vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0];
+  vbase = virtual_base_list (dclass)[0];
   while (vbase)
     {
       if (vbase == base)
        break;
   while (vbase)
     {
       if (vbase == base)
        break;
-      vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i];
+      vbase = virtual_base_list (dclass)[++i];
     }
 
   return vbase ? i : -1;
     }
 
   return vbase ? i : -1;
@@ -1980,9 +1925,7 @@ virtual_base_index (base, dclass)
    found" or a problem.  */
 
 int
    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;
 {
   register struct type *vbase;
   register int i, j;
@@ -1996,14 +1939,14 @@ virtual_base_index_skip_primaries (base, dclass)
 
   j = -1;
   i = 0;
 
   j = -1;
   i = 0;
-  vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[0];
+  vbase = virtual_base_list (dclass)[0];
   while (vbase)
     {
       if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
        j++;
       if (vbase == base)
        break;
   while (vbase)
     {
       if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
        j++;
       if (vbase == base)
        break;
-      vbase = TYPE_VIRTUAL_BASE_LIST (dclass)[++i];
+      vbase = virtual_base_list (dclass)[++i];
     }
 
   return vbase ? j : -1;
     }
 
   return vbase ? j : -1;
@@ -2014,8 +1957,7 @@ virtual_base_index_skip_primaries (base, dclass)
  * Position returned is 0-based. */
 
 int
  * 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 */
 
 {
   struct type *pbc;            /* primary base class */
 
@@ -2037,8 +1979,7 @@ class_index_in_primary_list (dclass)
  */
 
 int
  */
 
 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 */
 {
   int fn, oi;                  /* function and overloaded instance indices */
   int vfuncs;                  /* count to return */
@@ -2047,6 +1988,8 @@ count_virtual_fns (dclass)
   struct type *pbc = primary_base_class (dclass);
   if (pbc)
     vfuncs = count_virtual_fns (pbc);
   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++)
 
   for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
     for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
@@ -2067,9 +2010,7 @@ count_virtual_fns (dclass)
  * 3 => A is worse than B */
 
 int
  * 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;
 {
   int i;
   int tmp;
@@ -2112,11 +2053,7 @@ compare_badness (a, b)
  * Return a pointer to a badness vector. This has NARGS + 1 entries. */
 
 struct badness_vector *
  * 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;
 {
   int i;
   struct badness_vector *bv;
@@ -2157,9 +2094,7 @@ rank_function (parms, nparms, args, nargs)
  * Generally the "bad" conversions are all uniformly assigned a 100 */
 
 int
  * 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
 {
   /* Identical type pointers */
   /* However, this still doesn't catch all cases of same type for arg
@@ -2174,6 +2109,17 @@ rank_one_type (parm, arg)
   if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
     arg = check_typedef (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;
   /* Check if identical after resolving typedefs */
   if (parm == arg)
     return 0;
@@ -2181,21 +2127,15 @@ rank_one_type (parm, arg)
   /* See through references, since we can almost make non-references
      references. */
   if (TYPE_CODE (arg) == TYPE_CODE_REF)
   /* See through references, since we can almost make non-references
      references. */
   if (TYPE_CODE (arg) == TYPE_CODE_REF)
-    return (rank_one_type (TYPE_TARGET_TYPE (arg), parm)
+    return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
            + REFERENCE_CONVERSION_BADNESS);
   if (TYPE_CODE (parm) == TYPE_CODE_REF)
            + REFERENCE_CONVERSION_BADNESS);
   if (TYPE_CODE (parm) == TYPE_CODE_REF)
-    return (rank_one_type (arg, TYPE_TARGET_TYPE (parm))
+    return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
            + REFERENCE_CONVERSION_BADNESS);
            + REFERENCE_CONVERSION_BADNESS);
-
-#ifdef DEBUG_OLOAD
+  if (overload_debug)
   /* Debugging only. */
   /* Debugging only. */
-  /* FIXME/FYI: cagney/2000-03-13: No need to #ifdef this sort of
-     thing.  Instead add a command like ``set debug gdbtypes <int>''.
-     (A predicate to this is the addition of the ``set debug''). Also,
-     send the output to gdb_stderr and don't use printf. */
-  printf ("------ Arg is %s [%d], parm is %s [%d]\n",
-      TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
-#endif
+    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 */
 
 
   /* x -> y means arg of type x being supplied for parameter of type y */
 
@@ -2485,9 +2425,7 @@ rank_one_type (parm, arg)
 /* End of functions for overload resolution */
 
 static void
 /* 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;
 
 {
   int bitno;
 
@@ -2515,9 +2453,7 @@ print_bit_vector (bits, nbits)
    include it since we may get into a infinitely recursive situation. */
 
 static void
    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)
     {
 {
   if (args != NULL)
     {
@@ -2533,9 +2469,7 @@ print_arg_types (args, spaces)
 }
 
 static void
 }
 
 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;
 {
   int method_idx;
   int overload_idx;
@@ -2598,9 +2532,7 @@ dump_fn_fieldlists (type, spaces)
 }
 
 static void
 }
 
 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));
 {
   printfi_filtered (spaces, "n_baseclasses %d\n",
                    TYPE_N_BASECLASSES (type));
@@ -2651,9 +2583,7 @@ print_cplus_stuff (type, spaces)
 static struct obstack dont_print_type_obstack;
 
 void
 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;
 
 {
   int idx;
 
@@ -2856,9 +2786,9 @@ recursive_dump_type (type, spaces)
     obstack_free (&dont_print_type_obstack, NULL);
 }
 
     obstack_free (&dont_print_type_obstack, NULL);
 }
 
-static void build_gdbtypes PARAMS ((void));
+static void build_gdbtypes (void);
 static void
 static void
-build_gdbtypes ()
+build_gdbtypes (void)
 {
   builtin_type_void =
     init_type (TYPE_CODE_VOID, 1,
 {
   builtin_type_void =
     init_type (TYPE_CODE_VOID, 1,
@@ -3001,12 +2931,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) */
   /* 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 =
   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 =
               TYPE_FLAG_UNSIGNED,
               "__CORE_ADDR", (struct objfile *) NULL);
   builtin_type_bfd_vma =
@@ -3016,10 +2943,11 @@ build_gdbtypes ()
 }
 
 
 }
 
 
-extern void _initialize_gdbtypes PARAMS ((void));
+extern void _initialize_gdbtypes (void);
 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.
   build_gdbtypes ();
 
   /* FIXME - For the moment, handle types by swapping them in and out.
@@ -3060,4 +2988,11 @@ _initialize_gdbtypes ()
   REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
   REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
   register_gdbarch_swap (NULL, 0, build_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.035348 seconds and 4 git commands to generate.