2007-09-12 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index 672be70fb0b489903e84236c9f969d340a94220a..838bfcffeee09fc93a3a1a8b5976d23ff02f3fbd 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"
@@ -919,6 +917,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)
 {
@@ -928,7 +952,7 @@ init_vector_type (struct type *elt_type, int n)
                                  create_range_type (0, 
                                                     builtin_type_int,
                                                     0, n-1));
-  TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
+  make_vector_type (array_type);
   return array_type;
 }
 
@@ -2024,7 +2048,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 +2136,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 +2143,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))
     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,7 +2171,7 @@ 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;
 
@@ -2161,19 +2181,18 @@ virtual_base_index_skip_primaries (struct type *base,
 
   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;
 }
 
@@ -3417,6 +3436,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,
@@ -3564,11 +3587,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,
This page took 0.025501 seconds and 4 git commands to generate.