gdb: Convert language la_pass_by_reference field to a method
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index e5288e2370c9128bed0864253a5b491cb8266170..654447984e5f400111d004be510106ca47ff54a8 100644 (file)
@@ -196,6 +196,8 @@ static LONGEST pos_atr (struct value *);
 
 static struct value *value_pos_atr (struct type *, struct value *);
 
+static struct value *val_atr (struct type *, LONGEST);
+
 static struct value *value_val_atr (struct type *, struct value *);
 
 static struct symbol *standard_lookup (const char *, const struct block *,
@@ -495,16 +497,6 @@ ada_get_gdb_completer_word_break_characters (void)
   return ada_completer_word_break_characters;
 }
 
-/* Print an array element index using the Ada syntax.  */
-
-static void
-ada_print_array_index (struct value *index_value, struct ui_file *stream,
-                       const struct value_print_options *options)
-{
-  LA_VALUE_PRINT (index_value, stream, options);
-  fprintf_filtered (stream, " => ");
-}
-
 /* la_watch_location_expression for Ada.  */
 
 static gdb::unique_xmalloc_ptr<char>
@@ -571,13 +563,13 @@ ada_get_field_index (const struct type *type, const char *field_name,
   int fieldno;
   struct type *struct_type = check_typedef ((struct type *) type);
 
-  for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); fieldno++)
+  for (fieldno = 0; fieldno < struct_type->num_fields (); fieldno++)
     if (field_name_match (TYPE_FIELD_NAME (struct_type, fieldno), field_name))
       return fieldno;
 
   if (!maybe_missing)
     error (_("Unable to find field %s in struct %s.  Aborting"),
-           field_name, TYPE_NAME (struct_type));
+           field_name, struct_type->name ());
 
   return -1;
 }
@@ -755,7 +747,7 @@ ada_discrete_type_high_bound (struct type *type)
     case TYPE_CODE_RANGE:
       return TYPE_HIGH_BOUND (type);
     case TYPE_CODE_ENUM:
-      return TYPE_FIELD_ENUMVAL (type, TYPE_NFIELDS (type) - 1);
+      return TYPE_FIELD_ENUMVAL (type, type->num_fields () - 1);
     case TYPE_CODE_BOOL:
       return 1;
     case TYPE_CODE_CHAR:
@@ -1461,7 +1453,7 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
 
   if (index_desc_type == NULL)
     return;
-  gdb_assert (TYPE_NFIELDS (index_desc_type) > 0);
+  gdb_assert (index_desc_type->num_fields () > 0);
 
   /* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
      to check one field only, no need to check them all).  If not, return
@@ -1470,13 +1462,13 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
      If our INDEX_DESC_TYPE was generated using the older encoding,
      the field type should be a meaningless integer type whose name
      is not equal to the field name.  */
-  if (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)) != NULL
-      && strcmp (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)),
+  if (TYPE_FIELD_TYPE (index_desc_type, 0)->name () != NULL
+      && strcmp (TYPE_FIELD_TYPE (index_desc_type, 0)->name (),
                  TYPE_FIELD_NAME (index_desc_type, 0)) == 0)
     return;
 
   /* Fixup each field of INDEX_DESC_TYPE.  */
-  for (i = 0; i < TYPE_NFIELDS (index_desc_type); i++)
+  for (i = 0; i < index_desc_type->num_fields (); i++)
    {
      const char *name = TYPE_FIELD_NAME (index_desc_type, i);
      struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
@@ -1486,18 +1478,6 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
    }
 }
 
-/* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors.  */
-
-static const char *bound_name[] = {
-  "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
-  "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
-};
-
-/* Maximum number of array dimensions we are prepared to handle.  */
-
-#define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *)))
-
-
 /* The desc_* routines return primitive portions of array descriptors
    (fat pointers).  */
 
@@ -1760,7 +1740,10 @@ fat_pntr_data_bitsize (struct type *type)
 static struct value *
 desc_one_bound (struct value *bounds, int i, int which)
 {
-  return value_struct_elt (&bounds, NULL, bound_name[2 * i + which - 2], NULL,
+  char bound_name[20];
+  xsnprintf (bound_name, sizeof (bound_name), "%cB%d",
+            which ? 'U' : 'L', i - 1);
+  return value_struct_elt (&bounds, NULL, bound_name, NULL,
                            _("Bad GNAT array descriptor bounds"));
 }
 
@@ -1798,7 +1781,11 @@ desc_index_type (struct type *type, int i)
   type = desc_base_type (type);
 
   if (type->code () == TYPE_CODE_STRUCT)
-    return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1);
+    {
+      char bound_name[20];
+      xsnprintf (bound_name, sizeof (bound_name), "LB%d", i - 1);
+      return lookup_struct_elt_type (type, bound_name, 1);
+    }
   else
     return NULL;
 }
@@ -1812,7 +1799,7 @@ desc_arity (struct type *type)
   type = desc_base_type (type);
 
   if (type != NULL)
-    return TYPE_NFIELDS (type) / 2;
+    return type->num_fields () / 2;
   return 0;
 }
 
@@ -2144,7 +2131,7 @@ constrained_packed_array_type (struct type *type, long *elt_bits)
                                   elt_bits);
   create_array_type (new_type, new_elt_type, index_type);
   TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
-  TYPE_NAME (new_type) = ada_type_name (type);
+  new_type->set_name (ada_type_name (type));
 
   if ((check_typedef (index_type)->code () == TYPE_CODE_RANGE
        && is_dynamic_type (check_typedef (index_type)))
@@ -2780,15 +2767,13 @@ ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind)
   for (k = 0; k < arity; k += 1)
     {
       LONGEST lwb, upb;
-      struct value *lwb_value;
 
       if (type->code () != TYPE_CODE_ARRAY)
         error (_("too many subscripts (%d expected)"), k);
       arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
                         value_copy (arr));
       get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb);
-      lwb_value = value_from_longest (value_type (ind[k]), lwb);
-      arr = value_ptradd (arr, pos_atr (ind[k]) - pos_atr (lwb_value));
+      arr = value_ptradd (arr, pos_atr (ind[k]) - lwb);
       type = TYPE_TARGET_TYPE (type);
     }
 
@@ -3211,12 +3196,12 @@ ada_print_symbol_signature (struct ui_file *stream, struct symbol *sym,
       || type->code () != TYPE_CODE_FUNC)
     return;
 
-  if (TYPE_NFIELDS (type) > 0)
+  if (type->num_fields () > 0)
     {
       int i;
 
       fprintf_filtered (stream, " (");
-      for (i = 0; i < TYPE_NFIELDS (type); ++i)
+      for (i = 0; i < type->num_fields (); ++i)
        {
          if (i > 0)
            fprintf_filtered (stream, "; ");
@@ -3405,7 +3390,7 @@ See set/show multiple-symbol."));
                               SYMBOL_LINE (syms[i].symbol));
            }
           else if (is_enumeral
-                   && TYPE_NAME (SYMBOL_TYPE (syms[i].symbol)) != NULL)
+                   && SYMBOL_TYPE (syms[i].symbol)->name () != NULL)
             {
               printf_filtered (("[%d] "), i + first_choice);
               ada_print_type (SYMBOL_TYPE (syms[i].symbol), NULL,
@@ -3902,7 +3887,7 @@ ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
   else if (func_type == NULL || func_type->code () != TYPE_CODE_FUNC)
     return 0;
 
-  if (TYPE_NFIELDS (func_type) != n_actuals)
+  if (func_type->num_fields () != n_actuals)
     return 0;
 
   for (i = 0; i < n_actuals; i += 1)
@@ -4963,7 +4948,7 @@ is_nondebugging_type (struct type *type)
 
    This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM
    types and that their number of enumerals is identical (in other
-   words, TYPE_NFIELDS (type1) == TYPE_NFIELDS (type2)).  */
+   words, type1->num_fields () == type2->num_fields ()).  */
 
 static int
 ada_identical_enum_types_p (struct type *type1, struct type *type2)
@@ -4976,13 +4961,13 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
      underlying value and name.  */
 
   /* All enums in the type should have an identical underlying value.  */
-  for (i = 0; i < TYPE_NFIELDS (type1); i++)
+  for (i = 0; i < type1->num_fields (); i++)
     if (TYPE_FIELD_ENUMVAL (type1, i) != TYPE_FIELD_ENUMVAL (type2, i))
       return 0;
 
   /* All enumerals should also have the same name (modulo any numerical
      suffix).  */
-  for (i = 0; i < TYPE_NFIELDS (type1); i++)
+  for (i = 0; i < type1->num_fields (); i++)
     {
       const char *name_1 = TYPE_FIELD_NAME (type1, i);
       const char *name_2 = TYPE_FIELD_NAME (type2, i);
@@ -5045,8 +5030,8 @@ symbols_are_identical_enums (const std::vector<struct block_symbol> &syms)
 
   /* Quick check: They should all have the same number of enumerals.  */
   for (i = 1; i < syms.size (); i++)
-    if (TYPE_NFIELDS (SYMBOL_TYPE (syms[i].symbol))
-        != TYPE_NFIELDS (SYMBOL_TYPE (syms[0].symbol)))
+    if (SYMBOL_TYPE (syms[i].symbol)->num_fields ()
+        != SYMBOL_TYPE (syms[0].symbol)->num_fields ())
       return 0;
 
   /* All the sanity checks passed, so we might have a set of
@@ -5158,7 +5143,7 @@ xget_renaming_scope (struct type *renaming_type)
      So, to extract the scope, we search for the "___XR" extension,
      and then backtrack until we find the first "__".  */
 
-  const char *name = TYPE_NAME (renaming_type);
+  const char *name = renaming_type->name ();
   const char *suffix = strstr (name, "___XR");
   const char *last;
 
@@ -6506,7 +6491,7 @@ ada_is_dispatch_table_ptr_type (struct type *type)
   if (type->code () != TYPE_CODE_PTR)
     return 0;
 
-  name = TYPE_NAME (TYPE_TARGET_TYPE (type));
+  name = TYPE_TARGET_TYPE (type)->name ();
   if (name == NULL)
     return 0;
 
@@ -6518,7 +6503,7 @@ ada_is_dispatch_table_ptr_type (struct type *type)
 static int
 ada_is_interface_tag (struct type *type)
 {
-  const char *name = TYPE_NAME (type);
+  const char *name = type->name ();
 
   if (name == NULL)
     return 0;
@@ -6532,7 +6517,7 @@ ada_is_interface_tag (struct type *type)
 int
 ada_is_ignored_field (struct type *type, int field_num)
 {
-  if (field_num < 0 || field_num > TYPE_NFIELDS (type))
+  if (field_num < 0 || field_num > type->num_fields ())
     return 1;
 
   /* Check the name of that field.  */
@@ -6868,7 +6853,7 @@ ada_parent_type (struct type *type)
   if (type == NULL || type->code () != TYPE_CODE_STRUCT)
     return NULL;
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     if (ada_is_parent_field (type, i))
       {
         struct type *parent_type = TYPE_FIELD_TYPE (type, i);
@@ -7231,7 +7216,7 @@ find_struct_field (const char *name, struct type *type, int offset,
   if (bit_size_p != NULL)
     *bit_size_p = 0;
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       int bit_pos = TYPE_FIELD_BITPOS (type, i);
       int fld_offset = offset + bit_pos / 8;
@@ -7283,7 +7268,7 @@ find_struct_field (const char *name, struct type *type, int offset,
           struct type *field_type
            = ada_check_typedef (TYPE_FIELD_TYPE (type, i));
 
-          for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
+          for (j = 0; j < field_type->num_fields (); j += 1)
             {
               if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j),
                                      fld_offset
@@ -7343,7 +7328,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
   int parent_offset = -1;
 
   type = ada_check_typedef (type);
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -7386,7 +7371,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
                                                                        i));
           int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
 
-          for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
+          for (j = 0; j < field_type->num_fields (); j += 1)
             {
               struct value *v = ada_search_struct_field /* Force line
                                                           break.  */
@@ -7444,7 +7429,7 @@ ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
   int i;
   type = ada_check_typedef (type);
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       if (TYPE_FIELD_NAME (type, i) == NULL)
         continue;
@@ -7537,7 +7522,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
 
   type = to_static_fixed_type (type);
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
       struct type *t;
@@ -7576,7 +7561,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
           struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
                                                                        i));
 
-          for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
+          for (j = field_type->num_fields () - 1; j >= 0; j -= 1)
             {
              /* FIXME pnh 2008/01/26: We check for a field that is
                 NOT wrapped in a struct, since the compiler sometimes
@@ -7660,7 +7645,7 @@ ada_which_variant_applies (struct type *var_type, struct value *outer)
   discrim_val = value_as_long (discrim);
 
   others_clause = -1;
-  for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
+  for (i = 0; i < var_type->num_fields (); i += 1)
     {
       if (ada_is_others_clause (var_type, i))
         others_clause = i;
@@ -7834,7 +7819,7 @@ ada_prefer_type (struct type *type0, struct type *type1)
     return 1;
   else if (type0->code () == TYPE_CODE_VOID)
     return 0;
-  else if (TYPE_NAME (type1) == NULL && TYPE_NAME (type0) != NULL)
+  else if (type1->name () == NULL && type0->name () != NULL)
     return 1;
   else if (ada_is_constrained_packed_array_type (type0))
     return 1;
@@ -7843,8 +7828,8 @@ ada_prefer_type (struct type *type0, struct type *type1)
     return 1;
   else
     {
-      const char *type0_name = TYPE_NAME (type0);
-      const char *type1_name = TYPE_NAME (type1);
+      const char *type0_name = type0->name ();
+      const char *type1_name = type1->name ();
 
       if (type0_name != NULL && strstr (type0_name, "___XR") != NULL
          && (type1_name == NULL || strstr (type1_name, "___XR") == NULL))
@@ -7861,7 +7846,7 @@ ada_type_name (struct type *type)
 {
   if (type == NULL)
     return NULL;
-  return TYPE_NAME (type);
+  return type->name ();
 }
 
 /* Search the list of "descriptive" types associated to TYPE for a type
@@ -8010,7 +7995,7 @@ variant_field_index (struct type *type)
   if (type == NULL || type->code () != TYPE_CODE_STRUCT)
     return -1;
 
-  for (f = 0; f < TYPE_NFIELDS (type); f += 1)
+  for (f = 0; f < type->num_fields (); f += 1)
     {
       if (ada_is_variant_part (type, f))
         return f;
@@ -8026,10 +8011,8 @@ empty_record (struct type *templ)
   struct type *type = alloc_type_copy (templ);
 
   type->set_code (TYPE_CODE_STRUCT);
-  TYPE_NFIELDS (type) = 0;
-  TYPE_FIELDS (type) = NULL;
   INIT_NONE_SPECIFIC (type);
-  TYPE_NAME (type) = "<empty>";
+  type->set_name ("<empty>");
   TYPE_LENGTH (type) = 0;
   return type;
 }
@@ -8070,11 +8053,11 @@ ada_template_to_fixed_record_type_1 (struct type *type,
      to be processed: unless keep_dynamic_fields, this includes only
      fields whose position and length are static will be processed.  */
   if (keep_dynamic_fields)
-    nfields = TYPE_NFIELDS (type);
+    nfields = type->num_fields ();
   else
     {
       nfields = 0;
-      while (nfields < TYPE_NFIELDS (type)
+      while (nfields < type->num_fields ()
              && !ada_is_variant_part (type, nfields)
              && !is_dynamic_field (type, nfields))
         nfields++;
@@ -8083,11 +8066,10 @@ ada_template_to_fixed_record_type_1 (struct type *type,
   rtype = alloc_type_copy (type);
   rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
-  TYPE_NFIELDS (rtype) = nfields;
-  TYPE_FIELDS (rtype) = (struct field *)
-    TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
-  TYPE_NAME (rtype) = ada_type_name (type);
+  rtype->set_num_fields (nfields);
+  rtype->set_fields
+   ((struct field *) TYPE_ZALLOC (rtype, nfields * sizeof (struct field)));
+  rtype->set_name (ada_type_name (type));
   TYPE_FIXED_INSTANCE (rtype) = 1;
 
   off = 0;
@@ -8098,7 +8080,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
     {
       off = align_up (off, field_alignment (type, f))
        + TYPE_FIELD_BITPOS (type, f);
-      SET_FIELD_BITPOS (TYPE_FIELD (rtype, f), off);
+      SET_FIELD_BITPOS (rtype->field (f), off);
       TYPE_FIELD_BITSIZE (rtype, f) = 0;
 
       if (ada_is_variant_part (type, f))
@@ -8249,9 +8231,9 @@ ada_template_to_fixed_record_type_1 (struct type *type,
          cond_offset_target (address, off / TARGET_CHAR_BIT), dval);
       if (branch_type == NULL)
         {
-          for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1)
-            TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
-          TYPE_NFIELDS (rtype) -= 1;
+          for (f = variant_field + 1; f < rtype->num_fields (); f += 1)
+            rtype->field (f - 1) = rtype->field (f);
+         rtype->set_num_fields (rtype->num_fields () - 1);
         }
       else
         {
@@ -8275,9 +8257,9 @@ ada_template_to_fixed_record_type_1 (struct type *type,
      the current RTYPE length might be good enough for our purposes.  */
   if (TYPE_LENGTH (type) <= 0)
     {
-      if (TYPE_NAME (rtype))
+      if (rtype->name ())
        warning (_("Invalid type size for `%s' detected: %s."),
-                TYPE_NAME (rtype), pulongest (TYPE_LENGTH (type)));
+                rtype->name (), pulongest (TYPE_LENGTH (type)));
       else
        warning (_("Invalid type size for <unnamed> detected: %s."),
                 pulongest (TYPE_LENGTH (type)));
@@ -8331,7 +8313,7 @@ template_to_static_fixed_type (struct type *type0)
 
   /* Don't clone TYPE0 until we are sure we are going to need a copy.  */
   type = type0;
-  nfields = TYPE_NFIELDS (type0);
+  nfields = type0->num_fields ();
 
   /* Whether or not we cloned TYPE0, cache the result so that we don't do
      recompute all over next time.  */
@@ -8358,12 +8340,16 @@ template_to_static_fixed_type (struct type *type0)
              TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
              type->set_code (type0->code ());
              INIT_NONE_SPECIFIC (type);
-             TYPE_NFIELDS (type) = nfields;
-             TYPE_FIELDS (type) = (struct field *)
-               TYPE_ALLOC (type, nfields * sizeof (struct field));
-             memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
+             type->set_num_fields (nfields);
+
+             field *fields =
+               ((struct field *)
+                TYPE_ALLOC (type, nfields * sizeof (struct field)));
+             memcpy (fields, type0->fields (),
                      sizeof (struct field) * nfields);
-             TYPE_NAME (type) = ada_type_name (type0);
+             type->set_fields (fields);
+
+             type->set_name (ada_type_name (type0));
              TYPE_FIXED_INSTANCE (type) = 1;
              TYPE_LENGTH (type) = 0;
            }
@@ -8390,7 +8376,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   struct value *dval;
   struct type *rtype;
   struct type *branch_type;
-  int nfields = TYPE_NFIELDS (type);
+  int nfields = type->num_fields ();
   int variant_field = variant_field_index (type);
 
   if (variant_field == -1)
@@ -8407,12 +8393,14 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   rtype = alloc_type_copy (type);
   rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
-  TYPE_NFIELDS (rtype) = nfields;
-  TYPE_FIELDS (rtype) =
+  rtype->set_num_fields (nfields);
+
+  field *fields =
     (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
-          sizeof (struct field) * nfields);
-  TYPE_NAME (rtype) = ada_type_name (type);
+  memcpy (fields, type->fields (), sizeof (struct field) * nfields);
+  rtype->set_fields (fields);
+
+  rtype->set_name (ada_type_name (type));
   TYPE_FIXED_INSTANCE (rtype) = 1;
   TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
 
@@ -8429,8 +8417,8 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
       int f;
 
       for (f = variant_field + 1; f < nfields; f += 1)
-        TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
-      TYPE_NFIELDS (rtype) -= 1;
+        rtype->field (f - 1) = rtype->field (f);
+      rtype->set_num_fields (rtype->num_fields () - 1);
     }
   else
     {
@@ -8563,10 +8551,10 @@ ada_is_redundant_range_encoding (struct type *range_type,
   if (is_dynamic_type (range_type))
     return 0;
 
-  if (TYPE_NAME (encoding_type) == NULL)
+  if (encoding_type->name () == NULL)
     return 0;
 
-  bounds_str = strstr (TYPE_NAME (encoding_type), "___XDLU_");
+  bounds_str = strstr (encoding_type->name (), "___XDLU_");
   if (bounds_str == NULL)
     return 0;
 
@@ -8596,7 +8584,7 @@ ada_is_redundant_index_type_desc (struct type *array_type,
   struct type *this_layer = check_typedef (array_type);
   int i;
 
-  for (i = 0; i < TYPE_NFIELDS (desc_type); i++)
+  for (i = 0; i < desc_type->num_fields (); i++)
     {
       if (!ada_is_redundant_range_encoding (TYPE_INDEX_TYPE (this_layer),
                                            TYPE_FIELD_TYPE (desc_type, i)))
@@ -8700,7 +8688,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
       struct type *elt_type0;
 
       elt_type0 = type0;
-      for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1)
+      for (i = index_type_desc->num_fields (); i > 0; i -= 1)
         elt_type0 = TYPE_TARGET_TYPE (elt_type0);
 
       /* NOTE: result---the fixed version of elt_type0---should never
@@ -8718,7 +8706,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
         ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval, 1);
 
       elt_type0 = type0;
-      for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1)
+      for (i = index_type_desc->num_fields () - 1; i >= 0; i -= 1)
         {
           struct type *range_type =
             to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, i), dval);
@@ -8734,7 +8722,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
   /* We want to preserve the type name.  This can be useful when
      trying to get the type name of a value that has already been
      printed (for instance, if the user did "print VAR; whatis $".  */
-  TYPE_NAME (result) = TYPE_NAME (type0);
+  result->set_name (type0->name ());
 
   if (constrained_packed_array_p)
     {
@@ -8978,7 +8966,7 @@ static_unwrap_type (struct type *type)
     {
       struct type *type1 = TYPE_FIELD_TYPE (ada_check_typedef (type), 0);
       if (ada_type_name (type1) == NULL)
-        TYPE_NAME (type1) = ada_type_name (type);
+       type1->set_name (ada_type_name (type));
 
       return static_unwrap_type (type1);
     }
@@ -9025,11 +9013,11 @@ ada_check_typedef (struct type *type)
   type = check_typedef (type);
   if (type == NULL || type->code () != TYPE_CODE_ENUM
       || !TYPE_STUB (type)
-      || TYPE_NAME (type) == NULL)
+      || type->name () == NULL)
     return type;
   else
     {
-      const char *name = TYPE_NAME (type);
+      const char *name = type->name ();
       struct type *type1 = ada_find_any_type (name);
 
       if (type1 == NULL)
@@ -9142,6 +9130,21 @@ value_pos_atr (struct type *type, struct value *arg)
 
 /* Evaluate the TYPE'VAL attribute applied to ARG.  */
 
+static struct value *
+val_atr (struct type *type, LONGEST val)
+{
+  gdb_assert (discrete_type_p (type));
+  if (type->code () == TYPE_CODE_RANGE)
+    type = TYPE_TARGET_TYPE (type);
+  if (type->code () == TYPE_CODE_ENUM)
+    {
+      if (val < 0 || val >= type->num_fields ())
+        error (_("argument to 'VAL out of range"));
+      val = TYPE_FIELD_ENUMVAL (type, val);
+    }
+  return value_from_longest (type, val);
+}
+
 static struct value *
 value_val_atr (struct type *type, struct value *arg)
 {
@@ -9150,16 +9153,7 @@ value_val_atr (struct type *type, struct value *arg)
   if (!integer_type_p (value_type (arg)))
     error (_("'VAL requires integral argument"));
 
-  if (type->code () == TYPE_CODE_ENUM)
-    {
-      long pos = value_as_long (arg);
-
-      if (pos < 0 || pos >= TYPE_NFIELDS (type))
-        error (_("argument to 'VAL out of range"));
-      return value_from_longest (type, TYPE_FIELD_ENUMVAL (type, pos));
-    }
-  else
-    return value_from_longest (type, value_as_long (arg));
+  return val_atr (type, value_as_long (arg));
 }
 \f
 
@@ -9235,7 +9229,7 @@ ada_is_aligner_type (struct type *type)
     return 0;
 
   return (type->code () == TYPE_CODE_STRUCT
-          && TYPE_NFIELDS (type) == 1
+          && type->num_fields () == 1
           && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0);
 }
 
@@ -9269,7 +9263,7 @@ ada_get_base_type (struct type *raw_type)
   real_type_namer = ada_find_parallel_type (raw_type, "___XVS");
   if (real_type_namer == NULL
       || real_type_namer->code () != TYPE_CODE_STRUCT
-      || TYPE_NFIELDS (real_type_namer) != 1)
+      || real_type_namer->num_fields () != 1)
     return raw_type;
 
   if (TYPE_FIELD_TYPE (real_type_namer, 0)->code () != TYPE_CODE_REF)
@@ -9420,7 +9414,7 @@ unwrap_value (struct value *val)
       struct type *val_type = ada_check_typedef (value_type (v));
 
       if (ada_type_name (val_type) == NULL)
-        TYPE_NAME (val_type) = ada_type_name (type);
+       val_type->set_name (ada_type_name (type));
 
       return unwrap_value (v);
     }
@@ -11424,8 +11418,7 @@ ada_is_gnat_encoded_fixed_point_type (struct type *type)
 int
 ada_is_system_address_type (struct type *type)
 {
-  return (TYPE_NAME (type)
-          && strcmp (TYPE_NAME (type), "system__address") == 0);
+  return (type->name () && strcmp (type->name (), "system__address") == 0);
 }
 
 /* Assuming that TYPE is the representation of an Ada fixed-point
@@ -11593,14 +11586,14 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
   const char *subtype_info;
 
   gdb_assert (raw_type != NULL);
-  gdb_assert (TYPE_NAME (raw_type) != NULL);
+  gdb_assert (raw_type->name () != NULL);
 
   if (raw_type->code () == TYPE_CODE_RANGE)
     base_type = TYPE_TARGET_TYPE (raw_type);
   else
     base_type = raw_type;
 
-  name = TYPE_NAME (raw_type);
+  name = raw_type->name ();
   subtype_info = strstr (name, "___XD");
   if (subtype_info == NULL)
     {
@@ -11674,7 +11667,7 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
          to match the size of the base_type, which is not what we want.
          Set it back to the original range type's length.  */
       TYPE_LENGTH (type) = TYPE_LENGTH (raw_type);
-      TYPE_NAME (type) = name;
+      type->set_name (name);
       return type;
     }
 }
@@ -13075,7 +13068,7 @@ catch_assert_command (const char *arg_entry, int from_tty,
 static int
 ada_is_exception_sym (struct symbol *sym)
 {
-  const char *type_name = TYPE_NAME (SYMBOL_TYPE (sym));
+  const char *type_name = SYMBOL_TYPE (sym)->name ();
 
   return (SYMBOL_CLASS (sym) != LOC_TYPEDEF
           && SYMBOL_CLASS (sym) != LOC_BLOCK
@@ -13836,8 +13829,8 @@ ada_language_arch_info (struct gdbarch *gdbarch,
   lai->primitive_type_vector [ada_primitive_type_system_address]
     = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
                                      "void"));
-  TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
-    = "system__address";
+  lai->primitive_type_vector [ada_primitive_type_system_address]
+    ->set_name ("system__address");
 
   /* Create the equivalent of the System.Storage_Elements.Storage_Offset
      type.  This is a signed integral type whose size is the same as
@@ -14030,32 +14023,15 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
     }
 }
 
-/* Implement the "la_read_var_value" language_defn method for Ada.  */
-
-static struct value *
-ada_read_var_value (struct symbol *var, const struct block *var_block,
-                   struct frame_info *frame)
-{
-  /* The only case where default_read_var_value is not sufficient
-     is when VAR is a renaming...  */
-  if (frame != nullptr)
-    {
-      const struct block *frame_block = get_frame_block (frame, NULL);
-      if (frame_block != nullptr && ada_is_renaming_symbol (var))
-       return ada_read_renaming_var_value (var, frame_block);
-    }
-
-  /* This is a typical case where we expect the default_read_var_value
-     function to work.  */
-  return default_read_var_value (var, var_block, frame);
-}
-
 static const char *ada_extensions[] =
 {
   ".adb", ".ads", ".a", ".ada", ".dg", NULL
 };
 
-extern const struct language_defn ada_language_defn = {
+/* Constant data that describes the Ada language.  */
+
+extern const struct language_data ada_language_data =
+{
   "ada",                        /* Language name */
   "Ada",
   language_ada,
@@ -14075,7 +14051,6 @@ extern const struct language_defn ada_language_defn = {
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   ada_value_print_inner,       /* la_value_print_inner */
   ada_value_print,              /* Print a top-level value */
-  ada_read_var_value,          /* la_read_var_value */
   NULL,                         /* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
@@ -14091,8 +14066,6 @@ extern const struct language_defn ada_language_defn = {
   ada_get_gdb_completer_word_break_characters,
   ada_collect_symbol_completion_matches,
   ada_language_arch_info,
-  ada_print_array_index,
-  default_pass_by_reference,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher, /* la_get_symbol_name_matcher */
   ada_iterate_over_symbols,
@@ -14104,6 +14077,53 @@ extern const struct language_defn ada_language_defn = {
   "(...)"                      /* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Ada language.  */
+
+class ada_language : public language_defn
+{
+public:
+  ada_language ()
+    : language_defn (language_ada, ada_language_data)
+  { /* Nothing.  */ }
+
+  /* Print an array element index using the Ada syntax.  */
+
+  void print_array_index (struct type *index_type,
+                         LONGEST index,
+                         struct ui_file *stream,
+                         const value_print_options *options) const override
+  {
+    struct value *index_value = val_atr (index_type, index);
+
+    LA_VALUE_PRINT (index_value, stream, options);
+    fprintf_filtered (stream, " => ");
+  }
+
+  /* Implement the "read_var_value" language_defn method for Ada.  */
+
+  struct value *read_var_value (struct symbol *var,
+                               const struct block *var_block,
+                               struct frame_info *frame) const override
+  {
+    /* The only case where default_read_var_value is not sufficient
+       is when VAR is a renaming...  */
+    if (frame != nullptr)
+      {
+       const struct block *frame_block = get_frame_block (frame, NULL);
+       if (frame_block != nullptr && ada_is_renaming_symbol (var))
+         return ada_read_renaming_var_value (var, frame_block);
+      }
+
+    /* This is a typical case where we expect the default_read_var_value
+       function to work.  */
+    return language_defn::read_var_value (var, var_block, frame);
+  }
+};
+
+/* Single instance of the Ada language class.  */
+
+static ada_language ada_language_defn;
+
 /* Command-list for the "set/show ada" prefix command.  */
 static struct cmd_list_element *set_ada_list;
 static struct cmd_list_element *show_ada_list;
This page took 0.037682 seconds and 4 git commands to generate.