gdb: Convert language la_pass_by_reference field to a method
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index d4377a1a495e6e6e70d8d8245ec2f0657123b50e..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>
@@ -2775,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);
     }
 
@@ -8090,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))
@@ -8242,7 +8232,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
       if (branch_type == NULL)
         {
           for (f = variant_field + 1; f < rtype->num_fields (); f += 1)
-            TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
+            rtype->field (f - 1) = rtype->field (f);
          rtype->set_num_fields (rtype->num_fields () - 1);
         }
       else
@@ -8355,7 +8345,7 @@ template_to_static_fixed_type (struct type *type0)
              field *fields =
                ((struct field *)
                 TYPE_ALLOC (type, nfields * sizeof (struct field)));
-             memcpy (fields, TYPE_FIELDS (type0),
+             memcpy (fields, type0->fields (),
                      sizeof (struct field) * nfields);
              type->set_fields (fields);
 
@@ -8407,7 +8397,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
 
   field *fields =
     (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memcpy (fields, TYPE_FIELDS (type), sizeof (struct field) * nfields);
+  memcpy (fields, type->fields (), sizeof (struct field) * nfields);
   rtype->set_fields (fields);
 
   rtype->set_name (ada_type_name (type));
@@ -8427,7 +8417,7 @@ 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];
+        rtype->field (f - 1) = rtype->field (f);
       rtype->set_num_fields (rtype->num_fields () - 1);
     }
   else
@@ -9140,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)
 {
@@ -9148,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->num_fields ())
-        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
 
@@ -14027,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,
@@ -14072,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 */
@@ -14088,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,
@@ -14101,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.029513 seconds and 4 git commands to generate.