Introduce typeid_operation
[deliverable/binutils-gdb.git] / gdb / ada-typeprint.c
index 7ef8bd5ef9e154bf08fd64ab070f16fd6eee6472..54bbe0f1a011ddc21b9332cedccd29a9b6bc0c54 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for printing Ada types for GDB, the GNU debugger.
-   Copyright (C) 1986-2020 Free Software Foundation, Inc.
+   Copyright (C) 1986-2021 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -101,7 +101,7 @@ type_is_full_subrange_of_target_type (struct type *type)
 {
   struct type *subtype;
 
-  if (TYPE_CODE (type) != TYPE_CODE_RANGE)
+  if (type->code () != TYPE_CODE_RANGE)
     return 0;
 
   subtype = TYPE_TARGET_TYPE (type);
@@ -146,7 +146,7 @@ print_range (struct type *type, struct ui_file *stream,
        type = TYPE_TARGET_TYPE (type);
     }
 
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_RANGE:
     case TYPE_CODE_ENUM:
@@ -180,8 +180,8 @@ print_range (struct type *type, struct ui_file *stream,
       break;
     default:
       fprintf_filtered (stream, "%.*s",
-                       ada_name_prefix_len (TYPE_NAME (type)),
-                       TYPE_NAME (type));
+                       ada_name_prefix_len (type->name ()),
+                       type->name ());
       break;
     }
 }
@@ -198,17 +198,17 @@ print_range_bound (struct type *type, const char *bounds, int *n,
   if (ada_scan_number (bounds, *n, &B, n))
     {
       /* STABS decodes all range types which bounds are 0 .. -1 as
-         unsigned integers (ie. the type code is TYPE_CODE_INT, not
-         TYPE_CODE_RANGE).  Unfortunately, ada_print_scalar() relies
-         on the unsigned flag to determine whether the bound should
-         be printed as a signed or an unsigned value.  This causes
-         the upper bound of the 0 .. -1 range types to be printed as
-         a very large unsigned number instead of -1.
-         To workaround this stabs deficiency, we replace the TYPE by NULL
-         to indicate default output when we detect that the bound is negative,
-         and the type is a TYPE_CODE_INT.  The bound is negative when
-         'm' is the last character of the number scanned in BOUNDS.  */
-      if (bounds[*n - 1] == 'm' && TYPE_CODE (type) == TYPE_CODE_INT)
+        unsigned integers (ie. the type code is TYPE_CODE_INT, not
+        TYPE_CODE_RANGE).  Unfortunately, ada_print_scalar() relies
+        on the unsigned flag to determine whether the bound should
+        be printed as a signed or an unsigned value.  This causes
+        the upper bound of the 0 .. -1 range types to be printed as
+        a very large unsigned number instead of -1.
+        To workaround this stabs deficiency, we replace the TYPE by NULL
+        to indicate default output when we detect that the bound is negative,
+        and the type is a TYPE_CODE_INT.  The bound is negative when
+        'm' is the last character of the number scanned in BOUNDS.  */
+      if (bounds[*n - 1] == 'm' && type->code () == TYPE_CODE_INT)
        type = NULL;
       ada_print_scalar (type, B, stream);
       if (bounds[*n] == '_')
@@ -267,10 +267,10 @@ print_range_type (struct type *raw_type, struct ui_file *stream,
   const char *subtype_info;
 
   gdb_assert (raw_type != NULL);
-  name = TYPE_NAME (raw_type);
+  name = raw_type->name ();
   gdb_assert (name != NULL);
 
-  if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
+  if (raw_type->code () == TYPE_CODE_RANGE)
     base_type = TYPE_TARGET_TYPE (raw_type);
   else
     base_type = raw_type;
@@ -312,7 +312,7 @@ print_range_type (struct type *raw_type, struct ui_file *stream,
 static void
 print_enum_type (struct type *type, struct ui_file *stream)
 {
-  int len = TYPE_NFIELDS (type);
+  int len = type->num_fields ();
   int i;
   LONGEST lastval;
 
@@ -339,31 +339,6 @@ print_enum_type (struct type *type, struct ui_file *stream)
   fprintf_filtered (stream, ")");
 }
 
-/* Print representation of Ada fixed-point type TYPE on STREAM.  */
-
-static void
-print_fixed_point_type (struct type *type, struct ui_file *stream)
-{
-  struct value *delta = ada_delta (type);
-  struct value *small = ada_scaling_factor (type);
-
-  if (delta == nullptr)
-    fprintf_filtered (stream, "delta ??");
-  else
-    {
-      std::string str;
-      str = target_float_to_string (value_contents (delta),
-                                   value_type (delta), "%g");
-      fprintf_filtered (stream, "delta %s", str.c_str());
-      if (!value_equal (delta, small))
-       {
-         str = target_float_to_string (value_contents (small),
-                                       value_type (small), "%g");
-         fprintf_filtered (stream, " <'small = %s>", str.c_str());
-       }
-    }
-}
-
 /* Print simple (constrained) array type TYPE on STREAM.  LEVEL is the
    recursion (indentation) level, in case the element type itself has
    nested structure, and SHOW is the number of levels of internal
@@ -402,12 +377,12 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
       bitsize = 0;
       if (range_desc_type == NULL)
        {
-         for (arr_type = type; TYPE_CODE (arr_type) == TYPE_CODE_ARRAY;
+         for (arr_type = type; arr_type->code () == TYPE_CODE_ARRAY;
               arr_type = TYPE_TARGET_TYPE (arr_type))
            {
              if (arr_type != type)
                fprintf_filtered (stream, ", ");
-             print_range (TYPE_INDEX_TYPE (arr_type), stream,
+             print_range (arr_type->index_type (), stream,
                           0 /* bounds_prefered_p */);
              if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
                bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
@@ -417,14 +392,14 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
        {
          int k;
 
-         n_indices = TYPE_NFIELDS (range_desc_type);
+         n_indices = range_desc_type->num_fields ();
          for (k = 0, arr_type = type;
               k < n_indices;
               k += 1, arr_type = TYPE_TARGET_TYPE (arr_type))
            {
              if (k > 0)
                fprintf_filtered (stream, ", ");
-             print_range_type (TYPE_FIELD_TYPE (range_desc_type, k),
+             print_range_type (range_desc_type->field (k).type (),
                                stream, 0 /* bounds_prefered_p */);
              if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
                bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
@@ -549,13 +524,13 @@ print_variant_clauses (struct type *type, int field_num,
   struct type *var_type, *par_type;
   struct type *discr_type;
 
-  var_type = TYPE_FIELD_TYPE (type, field_num);
+  var_type = type->field (field_num).type ();
   discr_type = ada_variant_discrim_type (var_type, outer_type);
 
-  if (TYPE_CODE (var_type) == TYPE_CODE_PTR)
+  if (var_type->code () == TYPE_CODE_PTR)
     {
       var_type = TYPE_TARGET_TYPE (var_type);
-      if (var_type == NULL || TYPE_CODE (var_type) != TYPE_CODE_UNION)
+      if (var_type == NULL || var_type->code () != TYPE_CODE_UNION)
        return;
     }
 
@@ -563,12 +538,12 @@ print_variant_clauses (struct type *type, int field_num,
   if (par_type != NULL)
     var_type = par_type;
 
-  for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
+  for (i = 0; i < var_type->num_fields (); i += 1)
     {
       fprintf_filtered (stream, "\n%*swhen ", level + 4, "");
       if (print_choices (var_type, i, stream, discr_type))
        {
-         if (print_record_field_types (TYPE_FIELD_TYPE (var_type, i),
+         if (print_record_field_types (var_type->field (i).type (),
                                        outer_type, stream, show, level + 4,
                                        flags)
              <= 0)
@@ -594,7 +569,7 @@ print_variant_part (struct type *type, int field_num, struct type *outer_type,
                    const struct type_print_options *flags)
 {
   const char *variant
-    = ada_variant_discrim_name (TYPE_FIELD_TYPE (type, field_num));
+    = ada_variant_discrim_name (type->field (field_num).type ());
   if (*variant == '\0')
     variant = "?";
 
@@ -623,7 +598,7 @@ print_selected_record_field_types (struct type *type, struct type *outer_type,
 
   flds = 0;
 
-  if (fld0 > fld1 && TYPE_STUB (type))
+  if (fld0 > fld1 && type->is_stub ())
     return -1;
 
   for (i = fld0; i <= fld1; i += 1)
@@ -633,7 +608,7 @@ print_selected_record_field_types (struct type *type, struct type *outer_type,
       if (ada_is_parent_field (type, i) || ada_is_ignored_field (type, i))
        ;
       else if (ada_is_wrapper_field (type, i))
-       flds += print_record_field_types (TYPE_FIELD_TYPE (type, i), type,
+       flds += print_record_field_types (type->field (i).type (), type,
                                          stream, show, level, flags);
       else if (ada_is_variant_part (type, i))
        {
@@ -644,7 +619,7 @@ print_selected_record_field_types (struct type *type, struct type *outer_type,
        {
          flds += 1;
          fprintf_filtered (stream, "\n%*s", level + 4, "");
-         ada_print_type (TYPE_FIELD_TYPE (type, i),
+         ada_print_type (type->field (i).type (),
                          TYPE_FIELD_NAME (type, i),
                          stream, show - 1, level + 4, flags);
          fprintf_filtered (stream, ";");
@@ -708,7 +683,7 @@ print_variant_part (const variant_part &part,
   else
     {
       name = TYPE_FIELD_NAME (type, part.discriminant_index);
-      discr_type = TYPE_FIELD_TYPE (type, part.discriminant_index);
+      discr_type = type->field (part.discriminant_index).type ();
     }
 
   fprintf_filtered (stream, "\n%*scase %s is", level + 4, "", name);
@@ -779,20 +754,20 @@ print_record_field_types (struct type *type, struct type *outer_type,
   struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
   if (prop != nullptr)
     {
-      if (prop->kind == PROP_TYPE)
+      if (prop->kind () == PROP_TYPE)
        {
-         type = prop->data.original_type;
+         type = prop->original_type ();
          prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
        }
-      gdb_assert (prop->kind == PROP_VARIANT_PARTS);
-      print_record_field_types_dynamic (*prop->data.variant_parts,
-                                       0, TYPE_NFIELDS (type),
+      gdb_assert (prop->kind () == PROP_VARIANT_PARTS);
+      print_record_field_types_dynamic (*prop->variant_parts (),
+                                       0, type->num_fields (),
                                        type, stream, show, level, flags);
-      return TYPE_NFIELDS (type);
+      return type->num_fields ();
     }
 
   return print_selected_record_field_types (type, outer_type,
-                                           0, TYPE_NFIELDS (type) - 1,
+                                           0, type->num_fields () - 1,
                                            stream, show, level, flags);
 }
    
@@ -863,7 +838,7 @@ print_unchecked_union_type (struct type *type, struct ui_file *stream,
 {
   if (show < 0)
     fprintf_filtered (stream, "record (?) is ... end record");
-  else if (TYPE_NFIELDS (type) == 0)
+  else if (type->num_fields () == 0)
     fprintf_filtered (stream, "record (?) is null; end record");
   else
     {
@@ -871,11 +846,11 @@ print_unchecked_union_type (struct type *type, struct ui_file *stream,
 
       fprintf_filtered (stream, "record (?) is\n%*scase ? is", level + 4, "");
 
-      for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+      for (i = 0; i < type->num_fields (); i += 1)
        {
          fprintf_filtered (stream, "\n%*swhen ? =>\n%*s", level + 8, "",
                            level + 12, "");
-         ada_print_type (TYPE_FIELD_TYPE (type, i),
+         ada_print_type (type->field (i).type (),
                          TYPE_FIELD_NAME (type, i),
                          stream, show - 1, level + 12, flags);
          fprintf_filtered (stream, ";");
@@ -895,10 +870,10 @@ static void
 print_func_type (struct type *type, struct ui_file *stream, const char *name,
                 const struct type_print_options *flags)
 {
-  int i, len = TYPE_NFIELDS (type);
+  int i, len = type->num_fields ();
 
   if (TYPE_TARGET_TYPE (type) != NULL
-      && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_VOID)
+      && TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_VOID)
     fprintf_filtered (stream, "procedure");
   else
     fprintf_filtered (stream, "function");
@@ -920,7 +895,7 @@ print_func_type (struct type *type, struct ui_file *stream, const char *name,
              wrap_here ("    ");
            }
          fprintf_filtered (stream, "a%d: ", i + 1);
-         ada_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0,
+         ada_print_type (type->field (i).type (), "", stream, -1, 0,
                          flags);
        }
       fprintf_filtered (stream, ")");
@@ -928,7 +903,7 @@ print_func_type (struct type *type, struct ui_file *stream, const char *name,
 
   if (TYPE_TARGET_TYPE (type) == NULL)
     fprintf_filtered (stream, " return <unknown return type>");
-  else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
+  else if (TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_VOID)
     {
       fprintf_filtered (stream, " return ");
       ada_print_type (TYPE_TARGET_TYPE (type), "", stream, 0, 0, flags);
@@ -955,7 +930,20 @@ ada_print_type (struct type *type0, const char *varstring,
                const struct type_print_options *flags)
 {
   struct type *type = ada_check_typedef (ada_get_base_type (type0));
-  char *type_name = decoded_type_name (type0);
+  /* If we can decode the original type name, use it.  However, there
+     are cases where the original type is an internally-generated type
+     with a name that can't be decoded (and whose encoded name might
+     not actually bear any relation to the type actually declared in
+     the sources). In that case, try using the name of the base type
+     in its place.
+
+     Note that we looked at the possibility of always using the name
+     of the base type. This does not always work, unfortunately, as
+     there are situations where it's the base type which has an
+     internally-generated name.  */
+  const char *type_name = decoded_type_name (type0);
+  if (type_name == nullptr)
+    type_name = decoded_type_name (type);
   int is_var_decl = (varstring != NULL && varstring[0] != '\0');
 
   if (type == NULL)
@@ -967,10 +955,7 @@ ada_print_type (struct type *type0, const char *varstring,
       return;
     }
 
-  if (show > 0)
-    type = ada_check_typedef (type);
-
-  if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC)
+  if (is_var_decl && type->code () != TYPE_CODE_FUNC)
     fprintf_filtered (stream, "%.*s: ",
                      ada_name_prefix_len (varstring), varstring);
 
@@ -984,10 +969,10 @@ ada_print_type (struct type *type0, const char *varstring,
   if (ada_is_aligner_type (type))
     ada_print_type (ada_aligned_type (type), "", stream, show, level, flags);
   else if (ada_is_constrained_packed_array_type (type)
-          && TYPE_CODE (type) != TYPE_CODE_PTR)
+          && type->code () != TYPE_CODE_PTR)
     print_array_type (type, stream, show, level, flags);
   else
-    switch (TYPE_CODE (type))
+    switch (type->code ())
       {
       default:
        fprintf_filtered (stream, "<");
@@ -996,7 +981,11 @@ ada_print_type (struct type *type0, const char *varstring,
        break;
       case TYPE_CODE_PTR:
       case TYPE_CODE_TYPEDEF:
-       fprintf_filtered (stream, "access ");
+       /* An __XVL field is not truly a pointer, so don't print
+          "access" in this case.  */
+       if (type->code () != TYPE_CODE_PTR
+           || strstr (varstring, "___XVL") == nullptr)
+         fprintf_filtered (stream, "access ");
        ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                        flags);
        break;
@@ -1012,26 +1001,27 @@ ada_print_type (struct type *type0, const char *varstring,
        fprintf_filtered (stream, "(false, true)");
        break;
       case TYPE_CODE_INT:
-       if (ada_is_fixed_point_type (type))
-         print_fixed_point_type (type, stream);
-       else
-         {
-           const char *name = ada_type_name (type);
-
-           if (!ada_is_range_type_name (name))
-             fprintf_styled (stream, metadata_style.style (),
-                             _("<%s-byte integer>"),
-                             pulongest (TYPE_LENGTH (type)));
-           else
-             {
-               fprintf_filtered (stream, "range ");
-               print_range_type (type, stream, 1 /* bounds_prefered_p */);
-             }
-         }
+       {
+         const char *name = ada_type_name (type);
+
+         if (!ada_is_range_type_name (name))
+           fprintf_styled (stream, metadata_style.style (),
+                           _("<%s-byte integer>"),
+                           pulongest (TYPE_LENGTH (type)));
+         else
+           {
+             fprintf_filtered (stream, "range ");
+             print_range_type (type, stream, 1 /* bounds_prefered_p */);
+           }
+       }
        break;
       case TYPE_CODE_RANGE:
-       if (ada_is_fixed_point_type (type))
-         print_fixed_point_type (type, stream);
+       if (is_fixed_point_type (type))
+         {
+           fprintf_filtered (stream, "<");
+           print_type_fixed_point (type, stream);
+           fprintf_filtered (stream, ">");
+         }
        else if (ada_is_modular_type (type))
          fprintf_filtered (stream, "mod %s", 
                            int_string (ada_modulus (type), 10, 0, 0, 1));
@@ -1074,7 +1064,7 @@ ada_print_type (struct type *type0, const char *varstring,
 
 void
 ada_print_typedef (struct type *type, struct symbol *new_symbol,
-                   struct ui_file *stream)
+                  struct ui_file *stream)
 {
   type = ada_check_typedef (type);
   ada_print_type (type, "", stream, 0, 0, &type_print_raw_options);
This page took 0.030354 seconds and 4 git commands to generate.