* gdbtypes.c (is_ancestor): Infer type equivalence from name
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index ae44fbd5c4bf38e03742988fed4cb08e57d79288..3ca1b337c511a999385413826b6025a42e5443f7 100644 (file)
@@ -33,6 +33,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.  */
@@ -65,9 +66,17 @@ struct type *builtin_type_uint32;
 struct type *builtin_type_int64;
 struct type *builtin_type_uint64;
 struct type *builtin_type_bool;
+struct type *builtin_type_v4sf;
+struct type *builtin_type_v4si;
+struct type *builtin_type_v8qi;
+struct type *builtin_type_v4hi;
+struct type *builtin_type_v2si;
+struct type *builtin_type_ptr;
+struct type *builtin_type_CORE_ADDR;
+struct type *builtin_type_bfd_vma;
 
 int opaque_type_resolution = 1;
-
+int overload_debug = 0;
 
 struct extra
   {
@@ -75,16 +84,16 @@ struct extra
     int len;
   };                           /* maximum extention 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
@@ -633,6 +642,44 @@ create_set_type (result_type, domain_type)
   return (result_type);
 }
 
+
+/* Construct and return a type of the form:
+       struct NAME { ELT_TYPE ELT_NAME[N]; }
+   We use these types for SIMD registers.  For example, the type of
+   the SSE registers on the late x86-family processors is:
+       struct __builtin_v4sf { float f[4]; }
+   built by the function call:
+       init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
+   The type returned is a permanent type, allocated using malloc; it
+   doesn't live in any objfile's obstack.  */
+static struct type *
+init_simd_type (char *name,
+               struct type *elt_type,
+               char *elt_name,
+               int n)
+{
+  struct type *t;
+  struct field *f;
+
+  /* Build the field structure.  */
+  f = xmalloc (sizeof (*f));
+  memset (f, 0, sizeof (*f));
+  f->loc.bitpos = 0;
+  f->type = create_array_type (0, elt_type,
+                              create_range_type (0, builtin_type_int,
+                                                 0, n-1));
+  f->name = elt_name;
+
+  /* Build a struct type with that field.  */
+  t = init_type (TYPE_CODE_STRUCT, n * TYPE_LENGTH (elt_type), 0, 0, 0);
+  t->nfields = 1;
+  t->fields = f;
+  t->tag_name = name;
+
+  return t;
+}
+
+
 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. 
    A MEMBER is a wierd thing -- it amounts to a typed offset into
    a struct, e.g. "an int at offset 8".  A MEMBER TYPE doesn't
@@ -948,7 +995,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);
        }
@@ -1376,6 +1423,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
@@ -1413,11 +1484,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;
        }
@@ -1450,17 +1521,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;
            }
@@ -1665,6 +1736,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)))
@@ -2091,7 +2165,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++)
@@ -2128,15 +2202,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 */
 
@@ -2200,16 +2292,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 */
@@ -2217,9 +2309,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;
@@ -2797,7 +2889,7 @@ 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 ()
 {
@@ -2925,13 +3017,43 @@ build_gdbtypes ()
      &showlist);
   opaque_type_resolution = 1;
 
+
+  /* Build SIMD types.  */
+  builtin_type_v4sf
+    = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
+  builtin_type_v4si
+    = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
+  builtin_type_v8qi
+    = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
+  builtin_type_v4hi
+    = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
+  builtin_type_v2si
+    = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
+
+  /* Pointer/Address types. */
+  /* 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_CORE_ADDR =
+    init_type (TYPE_CODE_INT, TARGET_PTR_BIT / 8,
+              TYPE_FLAG_UNSIGNED,
+              "__CORE_ADDR", (struct objfile *) NULL);
+  builtin_type_bfd_vma =
+    init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
+              TYPE_FLAG_UNSIGNED,
+              "__bfd_vma", (struct objfile *) NULL);
 }
 
 
-extern void _initialize_gdbtypes PARAMS ((void));
+extern void _initialize_gdbtypes (void);
 void
 _initialize_gdbtypes ()
 {
+  struct cmd_list_element *c;
   build_gdbtypes ();
 
   /* FIXME - For the moment, handle types by swapping them in and out.
@@ -2963,5 +3085,20 @@ _initialize_gdbtypes ()
   register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
   register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
   register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
+  register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
+  register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
+  register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
+  register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
+  register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
+  REGISTER_GDBARCH_SWAP (builtin_type_ptr);
+  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.027776 seconds and 4 git commands to generate.