gmp-utils: New API to simply use of GMP's integer/rational/float objects
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index f6043b50aff88897fddcabdc9119008f36de22b8..714227d24dd5402cb9efec6172587730cf3b61c8 100644 (file)
@@ -2012,6 +2012,17 @@ ada_is_unconstrained_packed_array_type (struct type *type)
   return 0;
 }
 
+/* Return true if TYPE is a (Gnat-encoded) constrained packed array
+   type, or if it is an ordinary (non-Gnat-encoded) packed array.  */
+
+static bool
+ada_is_any_packed_array_type (struct type *type)
+{
+  return (ada_is_constrained_packed_array_type (type)
+         || (type->code () == TYPE_CODE_ARRAY
+             && TYPE_FIELD_BITSIZE (type, 0) % 8 != 0));
+}
+
 /* Given that TYPE encodes a packed array type (constrained or unconstrained),
    return the size of its elements in bits.  */
 
@@ -2817,9 +2828,11 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
       base_low_pos = base_low;
     }
 
-  base = value_as_address (array_ptr)
-    + ((low_pos - base_low_pos)
-       * TYPE_LENGTH (TYPE_TARGET_TYPE (type0)));
+  ULONGEST stride = TYPE_FIELD_BITSIZE (slice_type, 0) / 8;
+  if (stride == 0)
+    stride = TYPE_LENGTH (TYPE_TARGET_TYPE (type0));
+
+  base = value_as_address (array_ptr) + (low_pos - base_low_pos) * stride;
   return value_at_lazy (slice_type, base);
 }
 
@@ -4385,6 +4398,10 @@ ada_value_struct_elt (struct value *arg, const char *name, int no_err)
       t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL,
                              address, NULL, check_tag);
 
+      /* Resolve the dynamic type as well.  */
+      arg = value_from_contents_and_address (t1, nullptr, address);
+      t1 = value_type (arg);
+
       if (find_struct_field (name, t1, 0,
                             &field_type, &byte_offset, &bit_offset,
                             &bit_size, NULL))
@@ -10609,7 +10626,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
          TYPE_TARGET_TYPE (value_type (array)) =
            ada_aligned_type (TYPE_TARGET_TYPE (value_type (array)));
 
-       if (ada_is_constrained_packed_array_type (value_type (array)))
+       if (ada_is_any_packed_array_type (value_type (array)))
          error (_("cannot slice a packed array"));
 
        /* If this is a reference to an array or an array lvalue,
@@ -13577,24 +13594,6 @@ static const struct op_print ada_op_print_tab[] = {
   {"'size", OP_ATR_SIZE, PREC_SUFFIX, 1},
   {NULL, OP_NULL, PREC_SUFFIX, 0}
 };
-\f
-enum ada_primitive_types {
-  ada_primitive_type_int,
-  ada_primitive_type_long,
-  ada_primitive_type_short,
-  ada_primitive_type_char,
-  ada_primitive_type_float,
-  ada_primitive_type_double,
-  ada_primitive_type_void,
-  ada_primitive_type_long_long,
-  ada_primitive_type_long_double,
-  ada_primitive_type_natural,
-  ada_primitive_type_positive,
-  ada_primitive_type_system_address,
-  ada_primitive_type_storage_offset,
-  nr_ada_primitive_types
-};
-
 \f
                                /* Language vector */
 
@@ -13821,63 +13820,51 @@ public:
   {
     const struct builtin_type *builtin = builtin_type (gdbarch);
 
-    lai->primitive_type_vector
-      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
-                               struct type *);
-
-    lai->primitive_type_vector [ada_primitive_type_int]
-      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-                          0, "integer");
-    lai->primitive_type_vector [ada_primitive_type_long]
-      = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
-                          0, "long_integer");
-    lai->primitive_type_vector [ada_primitive_type_short]
-      = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
-                          0, "short_integer");
-    lai->string_char_type
-      = lai->primitive_type_vector [ada_primitive_type_char]
-      = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
-    lai->primitive_type_vector [ada_primitive_type_float]
-      = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
-                        "float", gdbarch_float_format (gdbarch));
-    lai->primitive_type_vector [ada_primitive_type_double]
-      = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
-                        "long_float", gdbarch_double_format (gdbarch));
-    lai->primitive_type_vector [ada_primitive_type_long_long]
-      = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
-                          0, "long_long_integer");
-    lai->primitive_type_vector [ada_primitive_type_long_double]
-      = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
-                        "long_long_float", gdbarch_long_double_format (gdbarch));
-    lai->primitive_type_vector [ada_primitive_type_natural]
-      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-                          0, "natural");
-    lai->primitive_type_vector [ada_primitive_type_positive]
-      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-                          0, "positive");
-    lai->primitive_type_vector [ada_primitive_type_void]
-      = builtin->builtin_void;
-
-    lai->primitive_type_vector [ada_primitive_type_system_address]
+    /* Helper function to allow shorter lines below.  */
+    auto add = [&] (struct type *t)
+    {
+      lai->add_primitive_type (t);
+    };
+
+    add (arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+                           0, "integer"));
+    add (arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
+                           0, "long_integer"));
+    add (arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
+                           0, "short_integer"));
+    struct type *char_type = arch_character_type (gdbarch, TARGET_CHAR_BIT,
+                                                 0, "character");
+    lai->set_string_char_type (char_type);
+    add (char_type);
+    add (arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
+                         "float", gdbarch_float_format (gdbarch)));
+    add (arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
+                         "long_float", gdbarch_double_format (gdbarch)));
+    add (arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
+                           0, "long_long_integer"));
+    add (arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
+                         "long_long_float",
+                         gdbarch_long_double_format (gdbarch)));
+    add (arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+                           0, "natural"));
+    add (arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+                           0, "positive"));
+    add (builtin->builtin_void);
+
+    struct type *system_addr_ptr
       = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
                                        "void"));
-    lai->primitive_type_vector [ada_primitive_type_system_address]
-      ->set_name ("system__address");
+    system_addr_ptr->set_name ("system__address");
+    add (system_addr_ptr);
 
     /* Create the equivalent of the System.Storage_Elements.Storage_Offset
        type.  This is a signed integral type whose size is the same as
        the size of addresses.  */
-    {
-      unsigned int addr_length = TYPE_LENGTH
-       (lai->primitive_type_vector [ada_primitive_type_system_address]);
-
-      lai->primitive_type_vector [ada_primitive_type_storage_offset]
-       = arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
-                            "storage_offset");
-    }
+    unsigned int addr_length = TYPE_LENGTH (system_addr_ptr);
+    add (arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
+                           "storage_offset"));
 
-    lai->bool_type_symbol = NULL;
-    lai->bool_type_default = builtin->builtin_bool;
+    lai->set_bool_type (builtin->builtin_bool);
   }
 
   /* See language.h.  */
This page took 0.051756 seconds and 4 git commands to generate.