Fix problems introduced with my last change.
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 85e8743472df691129942160210b7e8a142bed12..9909871633d1dc000b8ea5cda18ef5d35a38413a 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
   {
@@ -410,7 +411,7 @@ lookup_member_type (type, domain)
   return (mtype);
 }
 
-/* Allocate a stub method whose return type is TYPE.
+/* Allocate a stub method whose return type is TYPE.  
    This apparently happens for speed of symbol reading, since parsing
    out the arguments to the method is cpu-intensive, the way we are doing
    it.  So, we will fill in arguments later.
@@ -534,8 +535,8 @@ get_discrete_bounds (type, lowp, highp)
     case TYPE_CODE_CHAR:
       *lowp = 0;
       /* This round-about calculation is to avoid shifting by
-        TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
-        if TYPE_LENGTH (type) == sizeof (LONGEST). */
+         TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
+         if TYPE_LENGTH (type) == sizeof (LONGEST). */
       *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
       *highp = (*highp - 1) | *highp;
       return 0;
@@ -679,7 +680,7 @@ init_simd_type (char *name,
 }
 
 
-/* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
+/* 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
    include the offset (that's the value of the MEMBER itself), but does
@@ -750,7 +751,7 @@ type_name_no_tag (type)
   return TYPE_NAME (type);
 }
 
-/* Lookup a primitive type named NAME.
+/* Lookup a primitive type named NAME. 
    Return zero if NAME is not a primitive type. */
 
 struct type *
@@ -939,7 +940,7 @@ lookup_template_type (name, type, block)
   return (SYMBOL_TYPE (sym));
 }
 
-/* Given a type TYPE, lookup the type of the component of type named NAME.
+/* Given a type TYPE, lookup the type of the component of type named NAME.  
 
    TYPE can be either a struct or union, or a pointer or reference to a struct or
    union.  If it is a pointer or reference, its target type is automatically used.
@@ -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_IW (t_field_name, name))
+      if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
        {
          return TYPE_FIELD_TYPE (type, i);
        }
@@ -1045,7 +1046,7 @@ fill_in_vptr_fieldno (type)
       int i;
 
       /* We must start at zero in case the first (and only) baseclass is
-        virtual (and hence we cannot share the table pointer).  */
+         virtual (and hence we cannot share the table pointer).  */
       for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
        {
          fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
@@ -1100,7 +1101,7 @@ get_destructor_fn_field (t, method_indexp, field_indexp)
    be a mistake, though--we might load in more symbols which contain a
    full definition for the type.
 
-   This used to be coded as a macro, but I don't think it is called
+   This used to be coded as a macro, but I don't think it is called 
    often enough to merit such treatment.  */
 
 struct complaint stub_noname_complaint =
@@ -1168,9 +1169,9 @@ check_typedef (type)
     {
       char *name = type_name_no_tag (type);
       /* FIXME: shouldn't we separately check the TYPE_NAME and the
-        TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
-        as appropriate?  (this code was written before TYPE_NAME and
-        TYPE_TAG_NAME were separate).  */
+         TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
+         as appropriate?  (this code was written before TYPE_NAME and
+         TYPE_TAG_NAME were separate).  */
       struct symbol *sym;
       if (name == NULL)
        {
@@ -1378,7 +1379,7 @@ cfront_mangle_name (type, i, j)
 
   f = TYPE_FN_FIELDLIST1 (type, i);    /* moved from below */
 
-  /* kludge to support cfront methods - gdb expects to find "F" for
+  /* kludge to support cfront methods - gdb expects to find "F" for 
      ARM_mangled names, so when we mangle, we have to add it here */
   if (ARM_DEMANGLING)
     {
@@ -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;
            }
@@ -1693,7 +1718,7 @@ chill_varying_type (type)
   return 1;
 }
 
-/* Check whether BASE is an ancestor or base class or DCLASS
+/* Check whether BASE is an ancestor or base class or DCLASS 
    Return 1 if so, and 0 if not.
    Note: callers may want to check for identity of the types before
    calling this function -- identical types are considered to satisfy
@@ -1797,7 +1822,7 @@ static struct vbase *current_vbase_list = NULL;
    items. The vbasetype pointer of each item in the list points to the
    type information for a virtual base of the argument DCLASS.
 
-   Helper function for virtual_base_list().
+   Helper function for virtual_base_list(). 
    Note: the list goes backward, right-to-left. virtual_base_list()
    copies the items out in reverse order.  */
 
@@ -2136,8 +2161,8 @@ rank_function (parms, nparms, args, nargs)
   LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
 
   /* Now rank all the parameters of the candidate function */
-  for (i = 1; i < min_len; i++)
-    bv->rank[i] = rank_one_type (parms[i], args[i]);
+  for (i = 1; i <= min_len; i++)
+    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,21 +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;
 
-  /* See through references, since we can almost make non-references references*/
+  /* 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;
+    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;
-
-#ifdef DEBUG_OLOAD
-  /* 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
+    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 */
 
@@ -2239,7 +2275,7 @@ rank_one_type (parm, arg)
          if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
            {
              /* Deal with signed, unsigned, and plain chars and
-                signed and unsigned ints */
+                signed and unsigned ints */
              if (TYPE_NOSIGN (parm))
                {
                  /* This case only for character types */
@@ -2833,8 +2869,8 @@ recursive_dump_type (type, spaces)
 
     default:
       /* We have to pick one of the union types to be able print and test
-        the value.  Pick cplus_struct_type, even though we know it isn't
-        any particular one. */
+         the value.  Pick cplus_struct_type, even though we know it isn't
+         any particular one. */
       printfi_filtered (spaces, "type_specific ");
       gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
       if (TYPE_CPLUS_SPECIFIC (type) != NULL)
@@ -3013,6 +3049,7 @@ extern void _initialize_gdbtypes PARAMS ((void));
 void
 _initialize_gdbtypes ()
 {
+  struct cmd_list_element *c;
   build_gdbtypes ();
 
   /* FIXME - For the moment, handle types by swapping them in and out.
@@ -3053,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.028052 seconds and 4 git commands to generate.