Add docs and arch tests to BMI.
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 3b29c54b45808a4d40053639af343ac1707c244d..00a7075ebc06c0c8f2750a19b4a0c8dc1f0ea712 100644 (file)
@@ -1,7 +1,7 @@
 /* Support routines for manipulating internal types for GDB.
 
    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
 /* Initialize BADNESS constants.  */
 
-const struct rank LENGTH_MISMATCH_BADNESS = {100};
+const struct rank LENGTH_MISMATCH_BADNESS = {100,0};
 
-const struct rank TOO_FEW_PARAMS_BADNESS = {100};
-const struct rank INCOMPATIBLE_TYPE_BADNESS = {100};
+const struct rank TOO_FEW_PARAMS_BADNESS = {100,0};
+const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0};
 
-const struct rank EXACT_MATCH_BADNESS = {0};
+const struct rank EXACT_MATCH_BADNESS = {0,0};
 
-const struct rank INTEGER_PROMOTION_BADNESS = {1};
-const struct rank FLOAT_PROMOTION_BADNESS = {1};
-const struct rank BASE_PTR_CONVERSION_BADNESS = {1};
-const struct rank INTEGER_CONVERSION_BADNESS = {2};
-const struct rank FLOAT_CONVERSION_BADNESS = {2};
-const struct rank INT_FLOAT_CONVERSION_BADNESS = {2};
-const struct rank VOID_PTR_CONVERSION_BADNESS = {2};
-const struct rank BOOL_PTR_CONVERSION_BADNESS = {3};
-const struct rank BASE_CONVERSION_BADNESS = {2};
-const struct rank REFERENCE_CONVERSION_BADNESS = {2};
+const struct rank INTEGER_PROMOTION_BADNESS = {1,0};
+const struct rank FLOAT_PROMOTION_BADNESS = {1,0};
+const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0};
+const struct rank INTEGER_CONVERSION_BADNESS = {2,0};
+const struct rank FLOAT_CONVERSION_BADNESS = {2,0};
+const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0};
+const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0};
+const struct rank BOOL_PTR_CONVERSION_BADNESS = {3,0};
+const struct rank BASE_CONVERSION_BADNESS = {2,0};
+const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
 
-const struct rank NS_POINTER_CONVERSION_BADNESS = {10};
+const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
 
 /* Floatformat pairs.  */
 const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = {
@@ -120,8 +120,8 @@ show_opaque_type_resolution (struct ui_file *file, int from_tty,
                             struct cmd_list_element *c, 
                             const char *value)
 {
-  fprintf_filtered (file, _("\
-Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
+  fprintf_filtered (file, _("Resolution of opaque struct/class/union types "
+                           "(if set before loading symbols) is %s.\n"),
                    value);
 }
 
@@ -1582,7 +1582,7 @@ check_typedef (struct type *type)
 
       if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
        {
-         /* Empty.  */
+         /* Nothing we can do.  */
        }
       else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
               && TYPE_NFIELDS (type) == 1
@@ -1967,32 +1967,50 @@ class_types_same_p (const struct type *a, const struct type *b)
              && !strcmp (TYPE_NAME (a), TYPE_NAME (b))));
 }
 
-/* Check whether BASE is an ancestor or base class of DCLASS
-   Return 1 if so, and 0 if not.  If PUBLIC is 1 then only public
-   ancestors are considered, and the function returns 1 only if
-   BASE is a public ancestor of DCLASS.  */
+/* If BASE is an ancestor of DCLASS return the distance between them.
+   otherwise return -1;
+   eg:
+
+   class A {};
+   class B: public A {};
+   class C: public B {};
+   class D: C {};
+
+   distance_to_ancestor (A, A, 0) = 0
+   distance_to_ancestor (A, B, 0) = 1
+   distance_to_ancestor (A, C, 0) = 2
+   distance_to_ancestor (A, D, 0) = 3
+
+   If PUBLIC is 1 then only public ancestors are considered,
+   and the function returns the distance only if BASE is a public ancestor
+   of DCLASS.
+   Eg:
+
+   distance_to_ancestor (A, D, 1) = -1  */
 
 static int
-do_is_ancestor (struct type *base, struct type *dclass, int public)
+distance_to_ancestor (struct type *base, struct type *dclass, int public)
 {
   int i;
+  int d;
 
   CHECK_TYPEDEF (base);
   CHECK_TYPEDEF (dclass);
 
   if (class_types_same_p (base, dclass))
-    return 1;
+    return 0;
 
   for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
     {
       if (public && ! BASETYPE_VIA_PUBLIC (dclass, i))
        continue;
 
-      if (do_is_ancestor (base, TYPE_BASECLASS (dclass, i), public))
-       return 1;
+      d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), public);
+      if (d >= 0)
+       return 1 + d;
     }
 
-  return 0;
+  return -1;
 }
 
 /* Check whether BASE is an ancestor or base class or DCLASS
@@ -2004,7 +2022,7 @@ do_is_ancestor (struct type *base, struct type *dclass, int public)
 int
 is_ancestor (struct type *base, struct type *dclass)
 {
-  return do_is_ancestor (base, dclass, 0);
+  return distance_to_ancestor (base, dclass, 0) >= 0;
 }
 
 /* Like is_ancestor, but only returns true when BASE is a public
@@ -2013,7 +2031,7 @@ is_ancestor (struct type *base, struct type *dclass)
 int
 is_public_ancestor (struct type *base, struct type *dclass)
 {
-  return do_is_ancestor (base, dclass, 1);
+  return distance_to_ancestor (base, dclass, 1) >= 0;
 }
 
 /* A helper function for is_unique_ancestor.  */
@@ -2085,6 +2103,7 @@ sum_ranks (struct rank a, struct rank b)
 {
   struct rank c;
   c.rank = a.rank + b.rank;
+  c.subrank = a.subrank + b.subrank;
   return c;
 }
 
@@ -2097,11 +2116,19 @@ int
 compare_ranks (struct rank a, struct rank b)
 {
   if (a.rank == b.rank)
-    return 0;
+    {
+      if (a.subrank == b.subrank)
+       return 0;
+      if (a.subrank < b.subrank)
+       return 1;
+      if (a.subrank > b.subrank)
+       return -1;
+    }
 
   if (a.rank < b.rank)
     return 1;
 
+  /* a.rank > b.rank  */
   return -1;
 }
 
@@ -2292,6 +2319,7 @@ types_equal (struct type *a, struct type *b)
 struct rank
 rank_one_type (struct type *parm, struct type *arg)
 {
+  struct rank rank = {0,0};
 
   if (types_equal (parm, arg))
     return EXACT_MATCH_BADNESS;
@@ -2332,9 +2360,11 @@ rank_one_type (struct type *parm, struct type *arg)
            return VOID_PTR_CONVERSION_BADNESS;
 
          /* (b) pointer to ancestor-pointer conversion.  */
-         if (is_ancestor (TYPE_TARGET_TYPE (parm),
-                                 TYPE_TARGET_TYPE (arg)))
-           return BASE_PTR_CONVERSION_BADNESS;
+         rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
+                                              TYPE_TARGET_TYPE (arg),
+                                              0);
+         if (rank.subrank >= 0)
+           return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
 
          return INCOMPATIBLE_TYPE_BADNESS;
        case TYPE_CODE_ARRAY:
@@ -2400,9 +2430,11 @@ rank_one_type (struct type *parm, struct type *arg)
                                                          "int")
                               && integer_types_same_name_p (TYPE_NAME (parm),
                                                             "long"))
-                       return INTEGER_PROMOTION_BADNESS;       /* unsigned int -> unsigned long */
+                       /* unsigned int -> unsigned long */
+                       return INTEGER_PROMOTION_BADNESS;
                      else
-                       return INTEGER_CONVERSION_BADNESS;      /* unsigned long -> unsigned int */
+                       /* unsigned long -> unsigned int */
+                       return INTEGER_CONVERSION_BADNESS;
                    }
                  else
                    {
@@ -2410,9 +2442,11 @@ rank_one_type (struct type *parm, struct type *arg)
                                                     "long")
                          && integer_types_same_name_p (TYPE_NAME (parm), 
                                                        "int"))
-                       return INTEGER_CONVERSION_BADNESS;      /* signed long -> unsigned int */
+                       /* signed long -> unsigned int */
+                       return INTEGER_CONVERSION_BADNESS;
                      else
-                       return INTEGER_CONVERSION_BADNESS;      /* signed int/long -> unsigned int/long */
+                       /* signed int/long -> unsigned int/long */
+                       return INTEGER_CONVERSION_BADNESS;
                    }
                }
              else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
@@ -2573,8 +2607,9 @@ rank_one_type (struct type *parm, struct type *arg)
        {
        case TYPE_CODE_STRUCT:
          /* Check for derivation */
-         if (is_ancestor (parm, arg))
-           return BASE_CONVERSION_BADNESS;
+         rank.subrank = distance_to_ancestor (parm, arg, 0);
+         if (rank.subrank >= 0)
+           return sum_ranks (BASE_CONVERSION_BADNESS, rank);
          /* else fall through */
        default:
          return INCOMPATIBLE_TYPE_BADNESS;
@@ -3074,7 +3109,8 @@ recursive_dump_type (struct type *type, int spaces)
                        plongest (TYPE_LOW_BOUND (type)), 
                        TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
                        plongest (TYPE_HIGH_BOUND (type)),
-                       TYPE_HIGH_BOUND_UNDEFINED (type) ? " (undefined)" : "");
+                       TYPE_HIGH_BOUND_UNDEFINED (type) 
+                       ? " (undefined)" : "");
     }
   printfi_filtered (spaces, "vptr_basetype ");
   gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
@@ -3205,7 +3241,8 @@ copy_type_recursive (struct objfile *objfile,
 
   /* We must add the new type to the hash table immediately, in case
      we encounter this type again during a recursive call below.  */
-  stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
+  stored
+    = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
   stored->old = type;
   stored->new = new_type;
   *slot = stored;
@@ -3839,20 +3876,23 @@ _initialize_gdbtypes (void)
   gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
   objfile_type_data = register_objfile_data ();
 
-  add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
-Set debugging of C++ overloading."), _("\
-Show debugging of C++ overloading."), _("\
-When enabled, ranking of the functions is displayed."),
+  add_setshow_zinteger_cmd ("overload", no_class, &overload_debug,
+                           _("Set debugging of C++ overloading."),
+                           _("Show debugging of C++ overloading."),
+                           _("When enabled, ranking of the "
+                             "functions is displayed."),
                            NULL,
                            show_overload_debug,
                            &setdebuglist, &showdebuglist);
 
   /* Add user knob for controlling resolution of opaque types.  */
   add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
-                          &opaque_type_resolution, _("\
-Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
-Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL,
-                          NULL,
+                          &opaque_type_resolution,
+                          _("Set resolution of opaque struct/class/union"
+                            " types (if set before loading symbols)."),
+                          _("Show resolution of opaque struct/class/union"
+                            " types (if set before loading symbols)."),
+                          NULL, NULL,
                           show_opaque_type_resolution,
                           &setlist, &showlist);
 }
This page took 0.028555 seconds and 4 git commands to generate.