gdb/
[binutils-gdb.git] / gdb / ada-typeprint.c
index 17d3594250df8801e1a5cb951a6a7249205b994d..7e8a649fa2027a916edf5684083a2d70f6f68532 100644 (file)
@@ -55,7 +55,7 @@ static void
 print_dynamic_range_bound (struct type *, const char *, int,
                           const char *, struct ui_file *);
 
-static void print_range_type_named (char *, struct type *, struct ui_file *);
+static void print_range_type (struct type *, struct ui_file *);
 \f
 
 
@@ -151,6 +151,7 @@ print_range_bound (struct type *type, char *bounds, int *n,
                   struct ui_file *stream)
 {
   LONGEST B;
+
   if (ada_scan_number (bounds, *n, &B, n))
     {
       /* STABS decodes all range types which bounds are 0 .. -1 as
@@ -212,19 +213,19 @@ print_dynamic_range_bound (struct type *type, const char *name, int name_len,
     fprintf_filtered (stream, "?");
 }
 
-/* Print the range type named NAME.  If symbol lookup fails, fall back
-   to ORIG_TYPE as base type.  */
+/* Print RAW_TYPE as a range type, using any bound information
+   following the GNAT encoding (if available).  */
 
 static void
-print_range_type_named (char *name, struct type *orig_type,
-                       struct ui_file *stream)
+print_range_type (struct type *raw_type, struct ui_file *stream)
 {
-  struct type *raw_type = ada_find_any_type (name);
+  char *name;
   struct type *base_type;
   char *subtype_info;
 
-  if (raw_type == NULL)
-    raw_type = orig_type;
+  gdb_assert (raw_type != NULL);
+  name = TYPE_NAME (raw_type);
+  gdb_assert (name != NULL);
 
   if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
     base_type = TYPE_TARGET_TYPE (raw_type);
@@ -341,10 +342,12 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
     {
       if (ada_is_simple_array_type (type))
        {
-         struct type *range_desc_type =
-           ada_find_parallel_type (type, "___XA");
+         struct type *range_desc_type;
          struct type *arr_type;
 
+         range_desc_type = ada_find_parallel_type (type, "___XA");
+         ada_fixup_array_indexes_type (range_desc_type);
+
          bitsize = 0;
          if (range_desc_type == NULL)
            {
@@ -361,6 +364,7 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
          else
            {
              int k;
+
              n_indices = TYPE_NFIELDS (range_desc_type);
              for (k = 0, arr_type = type;
                   k < n_indices;
@@ -368,9 +372,8 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
                {
                  if (k > 0)
                    fprintf_filtered (stream, ", ");
-                 print_range_type_named (TYPE_FIELD_NAME
-                                         (range_desc_type, k),
-                                         TYPE_INDEX_TYPE (arr_type), stream);
+                 print_range_type (TYPE_FIELD_TYPE (range_desc_type, k),
+                                   stream);
                  if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
                    bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
                }
@@ -379,6 +382,7 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
       else
        {
          int i, i0;
+
          for (i = i0 = ada_array_arity (type); i > 0; i -= 1)
            fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", ");
        }
@@ -434,6 +438,7 @@ print_choices (struct type *type, int field_num, struct ui_file *stream,
        case 'S':
          {
            LONGEST W;
+
            if (!ada_scan_number (name, p + 1, &W, &p))
              goto Huh;
            ada_print_scalar (val_type, W, stream);
@@ -442,6 +447,7 @@ print_choices (struct type *type, int field_num, struct ui_file *stream,
        case 'R':
          {
            LONGEST L, U;
+
            if (!ada_scan_number (name, p + 1, &L, &p)
                || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p))
              goto Huh;
@@ -780,13 +786,14 @@ ada_print_type (struct type *type0, char *varstring, struct ui_file *stream,
        else
          {
            char *name = ada_type_name (type);
+
            if (!ada_is_range_type_name (name))
              fprintf_filtered (stream, _("<%d-byte integer>"),
                                TYPE_LENGTH (type));
            else
              {
                fprintf_filtered (stream, "range ");
-               print_range_type_named (name, type, stream);
+               print_range_type (type, stream);
              }
          }
        break;