2007-10-25 Wu Zhou <woodzltc@cn.ibm.com>
[binutils-gdb.git] / gdb / gdbtypes.c
index 3550543a46858540a4f076ceecced40491a80fd5..7400d68b4b933207271adec8a825660d43fdd9b4 100644 (file)
@@ -9,7 +9,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -18,9 +18,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "gdb_string.h"
@@ -707,8 +705,6 @@ create_range_type (struct type *result_type, struct type *index_type,
   memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
   TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
   TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
-  TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
-  TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
 
   if (low_bound >= 0)
     TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
@@ -919,6 +915,32 @@ init_flags_type (char *name, int length)
   return type;
 }
 
+/* Convert ARRAY_TYPE to a vector type.  This may modify ARRAY_TYPE
+   and any array types nested inside it.  */
+
+void
+make_vector_type (struct type *array_type)
+{
+  struct type *inner_array, *elt_type;
+  int flags;
+
+  /* Find the innermost array type, in case the array is
+     multi-dimensional.  */
+  inner_array = array_type;
+  while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
+    inner_array = TYPE_TARGET_TYPE (inner_array);
+
+  elt_type = TYPE_TARGET_TYPE (inner_array);
+  if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
+    {
+      flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_FLAG_NOTTEXT;
+      elt_type = make_qualified_type (elt_type, flags, NULL);
+      TYPE_TARGET_TYPE (inner_array) = elt_type;
+    }
+
+  TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
+}
+
 struct type *
 init_vector_type (struct type *elt_type, int n)
 {
@@ -926,9 +948,9 @@ init_vector_type (struct type *elt_type, int n)
  
   array_type = create_array_type (0, elt_type,
                                  create_range_type (0, 
-                                                    builtin_type_int,
+                                                    builtin_type_int32,
                                                     0, n-1));
-  TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
+  make_vector_type (array_type);
   return array_type;
 }
 
@@ -1196,8 +1218,8 @@ lookup_struct_elt_type (struct type *type, char *name, int noerr)
       type = TYPE_TARGET_TYPE (type);
     }
 
-  if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
-      TYPE_CODE (type) != TYPE_CODE_UNION)
+  if (TYPE_CODE (type) != TYPE_CODE_STRUCT 
+      && TYPE_CODE (type) != TYPE_CODE_UNION)
     {
       target_terminal_ours ();
       gdb_flush (gdb_stdout);
@@ -1874,8 +1896,8 @@ is_ancestor (struct type *base, struct type *dclass)
 
   if (base == dclass)
     return 1;
-  if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
-      !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
+  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++)
@@ -1918,8 +1940,8 @@ has_vtable (struct type *dclass)
      vtable.  */
   if (TYPE_FIELD_VIRTUAL_BITS (dclass))
     for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
-      if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
-         (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
+      if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) 
+         && (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
        return 1;
 
   /* Well, maybe we don't need a virtual table.  */
@@ -1947,8 +1969,8 @@ primary_base_class (struct type *dclass)
     return NULL;
 
   for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
-    if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
-       has_vtable (TYPE_FIELD_TYPE (dclass, i)))
+    if (!TYPE_FIELD_VIRTUAL (dclass, i) 
+       && has_vtable (TYPE_FIELD_TYPE (dclass, i)))
       return TYPE_FIELD_TYPE (dclass, i);
 
   return NULL;
@@ -2024,7 +2046,7 @@ virtual_base_list_aux (struct type *dclass)
    This routine merely hands off the argument to virtual_base_list_aux()
    and then copies the result into an array to save space.  */
 
-struct type **
+static struct type **
 virtual_base_list (struct type *dclass)
 {
   struct vbase *tmp_vbase;
@@ -2112,7 +2134,6 @@ virtual_base_list_length_skip_primaries (struct type *dclass)
   return i;
 }
 
-
 /* Return the index (position) of type BASE, which is a virtual base
    class of DCLASS, in the latter's virtual base list.  A return of -1
    indicates "not found" or a problem.  */
@@ -2120,27 +2141,24 @@ virtual_base_list_length_skip_primaries (struct type *dclass)
 int
 virtual_base_index (struct type *base, struct type *dclass)
 {
-  struct type *vbase;
+  struct type *vbase, **vbase_list;
   int i;
 
-  if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
-      (TYPE_CODE (base) != TYPE_CODE_CLASS))
+  if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) 
+      || (TYPE_CODE (base) != TYPE_CODE_CLASS))
     return -1;
 
-  i = 0;
-  vbase = virtual_base_list (dclass)[0];
-  while (vbase)
-    {
-      if (vbase == base)
-       break;
-      vbase = virtual_base_list (dclass)[++i];
-    }
+  vbase_list = virtual_base_list (dclass);
+  for (i = 0, vbase = vbase_list[0];
+       vbase != NULL;
+       vbase = vbase_list[++i])
+    if (vbase == base)
+      break;
 
+  xfree (vbase_list);
   return vbase ? i : -1;
 }
 
-
-
 /* Return the index (position) of type BASE, which is a virtual base
    class of DCLASS, in the latter's virtual base list.  Skip over all
    bases that may appear in the virtual base list of the primary base
@@ -2151,29 +2169,28 @@ int
 virtual_base_index_skip_primaries (struct type *base, 
                                   struct type *dclass)
 {
-  struct type *vbase;
+  struct type *vbase, **vbase_list;
   int i, j;
   struct type *primary;
 
-  if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
-      (TYPE_CODE (base) != TYPE_CODE_CLASS))
+  if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) 
+      || (TYPE_CODE (base) != TYPE_CODE_CLASS))
     return -1;
 
   primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
 
-  j = -1;
-  i = 0;
-  vbase = virtual_base_list (dclass)[0];
-  while (vbase)
+  vbase_list = virtual_base_list (dclass);
+  for (i = 0, j = -1, vbase = vbase_list[0];
+       vbase != NULL;
+       vbase = vbase_list[++i])
     {
       if (!primary 
          || (virtual_base_index_skip_primaries (vbase, primary) < 0))
        j++;
       if (vbase == base)
        break;
-      vbase = virtual_base_list (dclass)[++i];
     }
-
+  xfree (vbase_list);
   return vbase ? j : -1;
 }
 
@@ -2379,8 +2396,8 @@ rank_one_type (struct type *parm, struct type *arg)
      really are the same.
   */
 
-  if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
-      !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
+  if (TYPE_NAME (parm) && TYPE_NAME (arg) 
+      && !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
     return 0;
 
   /* Check if identical after resolving typedefs.  */
@@ -3417,6 +3434,10 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
     init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
               0,
               "true character", (struct objfile *) NULL);
+  builtin_type->builtin_true_unsigned_char =
+    init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
+              TYPE_FLAG_UNSIGNED,
+              "true character", (struct objfile *) NULL);
   builtin_type->builtin_signed_char =
     init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
               0,
@@ -3485,6 +3506,21 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
               0,
               "bool", (struct objfile *) NULL);
 
+  /* The following three are about decimal floating point types, which
+     are 32-bits, 64-bits and 128-bits respectively.  */
+  builtin_type->builtin_decfloat
+    = init_type (TYPE_CODE_DECFLOAT, 32 / 8,
+               0,
+              "decimal float", (struct objfile *) NULL);
+  builtin_type->builtin_decdouble
+    = init_type (TYPE_CODE_DECFLOAT, 64 / 8,
+              0,
+              "decimal double", (struct objfile *) NULL);
+  builtin_type->builtin_declong
+    = init_type (TYPE_CODE_DECFLOAT, 128 / 8,
+              0,
+              "decimal long double", (struct objfile *) NULL);
+
   /* Pointer/Address types.  */
 
   /* NOTE: on some targets, addresses and pointers are not necessarily
@@ -3564,11 +3600,11 @@ _initialize_gdbtypes (void)
               "int0_t", (struct objfile *) NULL);
   builtin_type_int8 =
     init_type (TYPE_CODE_INT, 8 / 8,
-              0,
+              TYPE_FLAG_NOTTEXT,
               "int8_t", (struct objfile *) NULL);
   builtin_type_uint8 =
     init_type (TYPE_CODE_INT, 8 / 8,
-              TYPE_FLAG_UNSIGNED,
+              TYPE_FLAG_UNSIGNED | TYPE_FLAG_NOTTEXT,
               "uint8_t", (struct objfile *) NULL);
   builtin_type_int16 =
     init_type (TYPE_CODE_INT, 16 / 8,