Fix compile time warning messages.
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 20166722d3f3d4b8de0524f7c9c9b5f29f60fa25..0f6eef915c55e6afc95e567904fe6f35015f1aec 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.  */
@@ -75,7 +76,7 @@ struct type *builtin_type_CORE_ADDR;
 struct type *builtin_type_bfd_vma;
 
 int opaque_type_resolution = 1;
-
+int overload_debug = 0;
 
 struct extra
   {
@@ -83,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
@@ -994,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);
        }
@@ -1422,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
@@ -1459,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;
        }
@@ -1496,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;
            }
@@ -2137,7 +2162,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++)
@@ -2174,15 +2199,32 @@ 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))
+      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 (TYPE_TARGET_TYPE (arg), parm)
+           + REFERENCE_CONVERSION_BADNESS);
+  if (TYPE_CODE (parm) == TYPE_CODE_REF)
+    return (rank_one_type (arg, TYPE_TARGET_TYPE (parm))
+           + 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 +2288,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 +2305,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;
@@ -2843,7 +2885,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 ()
 {
@@ -3003,10 +3045,11 @@ build_gdbtypes ()
 }
 
 
-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.
@@ -3047,4 +3090,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.027614 seconds and 4 git commands to generate.