daily update
[external/binutils.git] / gdb / gdbtypes.c
index dc1e203..a70b6e4 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 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
+   2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
@@ -95,6 +95,10 @@ const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
   &floatformat_vax_d,
   &floatformat_vax_d
 };
+const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
+  &floatformat_ibm_long_double,
+  &floatformat_ibm_long_double
+};
 
 struct type *builtin_type_ieee_single;
 struct type *builtin_type_ieee_double;
@@ -807,8 +811,14 @@ create_array_type (struct type *result_type,
   if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
     low_bound = high_bound = 0;
   CHECK_TYPEDEF (element_type);
-  TYPE_LENGTH (result_type) =
-    TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
+  /* Be careful when setting the array length.  Ada arrays can be
+     empty arrays with the high_bound being smaller than the low_bound.
+     In such cases, the array length should be zero.  */
+  if (high_bound < low_bound)
+    TYPE_LENGTH (result_type) = 0;
+  else
+    TYPE_LENGTH (result_type) =
+      TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
   TYPE_NFIELDS (result_type) = 1;
   TYPE_FIELDS (result_type) =
     (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
@@ -1488,11 +1498,19 @@ check_typedef (struct type *type)
                   == TYPE_CODE_RANGE))
        {
          /* Now recompute the length of the array type, based on its
-            number of elements and the target type's length.  */
-         TYPE_LENGTH (type) =
-           ((TYPE_FIELD_BITPOS (range_type, 1)
-             - TYPE_FIELD_BITPOS (range_type, 0) + 1)
-            * TYPE_LENGTH (target_type));
+            number of elements and the target type's length.
+            Watch out for Ada null Ada arrays where the high bound
+            is smaller than the low bound.  */
+         const int low_bound = TYPE_FIELD_BITPOS (range_type, 0);
+         const int high_bound = TYPE_FIELD_BITPOS (range_type, 1);
+         int nb_elements;
+       
+         if (high_bound < low_bound)
+           nb_elements = 0;
+         else
+           nb_elements = high_bound - low_bound + 1;
+       
+         TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
          TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
        }
       else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
@@ -1794,65 +1812,6 @@ append_composite_type_field (struct type *t, char *name,
     }
 }
 
-/* Look up a fundamental type for the specified objfile.
-   May need to construct such a type if this is the first use.
-
-   Some object file formats (ELF, COFF, etc) do not define fundamental
-   types such as "int" or "double".  Others (stabs for example), do
-   define fundamental types.
-
-   For the formats which don't provide fundamental types, gdb can
-   create such types, using defaults reasonable for the current
-   language and the current target machine.
-
-   NOTE: This routine is obsolescent.  Each debugging format reader
-   should manage it's own fundamental types, either creating them from
-   suitable defaults or reading them from the debugging information,
-   whichever is appropriate.  The DWARF reader has already been fixed
-   to do this.  Once the other readers are fixed, this routine will go
-   away.  Also note that fundamental types should be managed on a
-   compilation unit basis in a multi-language environment, not on a
-   linkage unit basis as is done here.  */
-
-
-struct type *
-lookup_fundamental_type (struct objfile *objfile, int typeid)
-{
-  struct type **typep;
-  int nbytes;
-
-  if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
-    {
-      error (_("internal error - invalid fundamental type id %d"), 
-            typeid);
-    }
-
-  /* If this is the first time we need a fundamental type for this
-     objfile then we need to initialize the vector of type
-     pointers.  */
-
-  if (objfile->fundamental_types == NULL)
-    {
-      nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
-      objfile->fundamental_types = (struct type **)
-       obstack_alloc (&objfile->objfile_obstack, nbytes);
-      memset ((char *) objfile->fundamental_types, 0, nbytes);
-      OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
-    }
-
-  /* Look for this particular type in the fundamental type vector.  If
-     one is not found, create and install one appropriate for the
-     current language.  */
-
-  typep = objfile->fundamental_types + typeid;
-  if (*typep == NULL)
-    {
-      *typep = create_fundamental_type (objfile, typeid);
-    }
-
-  return (*typep);
-}
-
 int
 can_dereference (struct type *t)
 {
@@ -3177,15 +3136,15 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
   builtin_type->builtin_decfloat
     = init_type (TYPE_CODE_DECFLOAT, 32 / 8,
                0,
-              "decimal float", (struct objfile *) NULL);
+              "_Decimal32", (struct objfile *) NULL);
   builtin_type->builtin_decdouble
     = init_type (TYPE_CODE_DECFLOAT, 64 / 8,
               0,
-              "decimal double", (struct objfile *) NULL);
+              "_Decimal64", (struct objfile *) NULL);
   builtin_type->builtin_declong
     = init_type (TYPE_CODE_DECFLOAT, 128 / 8,
               0,
-              "decimal long double", (struct objfile *) NULL);
+              "_Decimal128", (struct objfile *) NULL);
 
   /* Pointer/Address types.  */