* ada-lang.c (packed_array_type): Rename to...
authorJoel Brobecker <brobecker@gnat.com>
Thu, 19 Nov 2009 22:42:48 +0000 (22:42 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Thu, 19 Nov 2009 22:42:48 +0000 (22:42 +0000)
        (constrained_packed_array_type): ...and update comment.
        (decode_packed_array, decode_constrained_packed_array): Ditto.
        (decode_packed_array_type, decode_constrained_packed_array_type):
        Ditto.
        (ada_is_constrained_packed_array_type): New function.
        (ada_is_unconstrained_packed_array_type): New function.
        (decode_packed_array_bitsize): New function, extracted from
        decode_packed_array_type.
        (ada_type_of_array): Add support for unconstrained packed arrays.
        (ada_coerce_to_simple_array_ptr, ada_coerce_to_simple_array)
        (ada_array_bound_from_type, ada_array_bound, ada_array_length)
        (ada_prefer_type, to_fixed_array_type, ada_evaluate_subexp): Resync.
        * ada-lang.h (ada_is_packed_array_type,
        ada_is_constrained_packed_array_type): Renaming.
        * ada-valprint.c (ada_val_print_1): Resync.
        * ada-typeprint.c (print_array_type, ada_print_type): Resync.

gdb/ChangeLog
gdb/ada-lang.c
gdb/ada-lang.h
gdb/ada-typeprint.c
gdb/ada-valprint.c

index 1a74a3b713847834bb1ccefad63f3995133891dd..4f89bc9d78aacadd7bc07f83b58e54e7aa7905bf 100644 (file)
@@ -1,3 +1,23 @@
+2009-11-19  Jerome Guitton  <guitton@adacore.com>
+
+       * ada-lang.c (packed_array_type): Rename to...
+       (constrained_packed_array_type): ...and update comment.
+       (decode_packed_array, decode_constrained_packed_array): Ditto.
+       (decode_packed_array_type, decode_constrained_packed_array_type):
+       Ditto.
+       (ada_is_constrained_packed_array_type): New function.
+       (ada_is_unconstrained_packed_array_type): New function.
+       (decode_packed_array_bitsize): New function, extracted from
+       decode_packed_array_type.
+       (ada_type_of_array): Add support for unconstrained packed arrays.
+       (ada_coerce_to_simple_array_ptr, ada_coerce_to_simple_array)
+       (ada_array_bound_from_type, ada_array_bound, ada_array_length)
+       (ada_prefer_type, to_fixed_array_type, ada_evaluate_subexp): Resync.
+       * ada-lang.h (ada_is_packed_array_type,
+       ada_is_constrained_packed_array_type): Renaming.
+       * ada-valprint.c (ada_val_print_1): Resync.
+       * ada-typeprint.c (print_array_type, ada_print_type): Resync.
+
 2009-11-19  Joel Brobecker  <brobecker@adacore.com>
 
        Wrong function used to perform address addition/subtraction.
index 74336d83340daa5f587a9813c212ad7ad24495bb..6cea84e83fff46986f6cabc01c4df5411242c9b3 100644 (file)
@@ -173,11 +173,17 @@ static struct type *static_unwrap_type (struct type *type);
 
 static struct value *unwrap_value (struct value *);
 
-static struct type *packed_array_type (struct type *, long *);
+static struct type *constrained_packed_array_type (struct type *, long *);
 
-static struct type *decode_packed_array_type (struct type *);
+static struct type *decode_constrained_packed_array_type (struct type *);
 
-static struct value *decode_packed_array (struct value *);
+static long decode_packed_array_bitsize (struct type *);
+
+static struct value *decode_constrained_packed_array (struct value *);
+
+static int ada_is_packed_array_type  (struct type *);
+
+static int ada_is_unconstrained_packed_array_type (struct type *);
 
 static struct value *value_subscript_packed (struct value *, int,
                                              struct value **);
@@ -1622,15 +1628,23 @@ ada_is_bogus_array_descriptor (struct type *type)
 struct type *
 ada_type_of_array (struct value *arr, int bounds)
 {
-  if (ada_is_packed_array_type (value_type (arr)))
-    return decode_packed_array_type (value_type (arr));
+  if (ada_is_constrained_packed_array_type (value_type (arr)))
+    return decode_constrained_packed_array_type (value_type (arr));
 
   if (!ada_is_array_descriptor_type (value_type (arr)))
     return value_type (arr);
 
   if (!bounds)
-    return
-      ada_check_typedef (desc_data_target_type (value_type (arr)));
+    {
+      struct type *array_type =
+       ada_check_typedef (desc_data_target_type (value_type (arr)));
+
+      if (ada_is_unconstrained_packed_array_type (value_type (arr)))
+       TYPE_FIELD_BITSIZE (array_type, 0) =
+         decode_packed_array_bitsize (value_type (arr));
+      
+      return array_type;
+    }
   else
     {
       struct type *elt_type;
@@ -1658,6 +1672,10 @@ ada_type_of_array (struct value *arr, int bounds)
                              longest_to_int (value_as_long (low)),
                              longest_to_int (value_as_long (high)));
           elt_type = create_array_type (array_type, elt_type, range_type);
+
+         if (ada_is_unconstrained_packed_array_type (value_type (arr)))
+           TYPE_FIELD_BITSIZE (elt_type, 0) =
+             decode_packed_array_bitsize (value_type (arr));
         }
 
       return lookup_pointer_type (elt_type);
@@ -1679,8 +1697,8 @@ ada_coerce_to_simple_array_ptr (struct value *arr)
         return NULL;
       return value_cast (arrType, value_copy (desc_data (arr)));
     }
-  else if (ada_is_packed_array_type (value_type (arr)))
-    return decode_packed_array (arr);
+  else if (ada_is_constrained_packed_array_type (value_type (arr)))
+    return decode_constrained_packed_array (arr);
   else
     return arr;
 }
@@ -1700,8 +1718,8 @@ ada_coerce_to_simple_array (struct value *arr)
       check_size (TYPE_TARGET_TYPE (value_type (arrVal)));
       return value_ind (arrVal);
     }
-  else if (ada_is_packed_array_type (value_type (arr)))
-    return decode_packed_array (arr);
+  else if (ada_is_constrained_packed_array_type (value_type (arr)))
+    return decode_constrained_packed_array (arr);
   else
     return arr;
 }
@@ -1713,8 +1731,8 @@ ada_coerce_to_simple_array (struct value *arr)
 struct type *
 ada_coerce_to_simple_array_type (struct type *type)
 {
-  if (ada_is_packed_array_type (type))
-    return decode_packed_array_type (type);
+  if (ada_is_constrained_packed_array_type (type))
+    return decode_constrained_packed_array_type (type);
 
   if (ada_is_array_descriptor_type (type))
     return ada_check_typedef (desc_data_target_type (type));
@@ -1724,8 +1742,8 @@ ada_coerce_to_simple_array_type (struct type *type)
 
 /* Non-zero iff TYPE represents a standard GNAT packed-array type.  */
 
-int
-ada_is_packed_array_type (struct type *type)
+static int
+ada_is_packed_array_type  (struct type *type)
 {
   if (type == NULL)
     return 0;
@@ -1736,6 +1754,54 @@ ada_is_packed_array_type (struct type *type)
     && strstr (ada_type_name (type), "___XP") != NULL;
 }
 
+/* Non-zero iff TYPE represents a standard GNAT constrained
+   packed-array type.  */
+
+int
+ada_is_constrained_packed_array_type (struct type *type)
+{
+  return ada_is_packed_array_type (type)
+    && !ada_is_array_descriptor_type (type);
+}
+
+/* Non-zero iff TYPE represents an array descriptor for a
+   unconstrained packed-array type.  */
+
+static int
+ada_is_unconstrained_packed_array_type (struct type *type)
+{
+  return ada_is_packed_array_type (type)
+    && ada_is_array_descriptor_type (type);
+}
+
+/* Given that TYPE encodes a packed array type (constrained or unconstrained),
+   return the size of its elements in bits.  */
+
+static long
+decode_packed_array_bitsize (struct type *type)
+{
+  char *raw_name = ada_type_name (ada_check_typedef (type));
+  char *tail;
+  long bits;
+
+  if (!raw_name)
+    raw_name = ada_type_name (desc_base_type (type));
+
+  if (!raw_name)
+    return 0;
+
+  tail = strstr (raw_name, "___XP");
+
+  if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1)
+    {
+      lim_warning
+       (_("could not understand bit size information on packed array"));
+      return 0;
+    }
+
+  return bits;
+}
+
 /* Given that TYPE is a standard GDB array type with all bounds filled
    in, and that the element size of its ultimate scalar constituents
    (that is, either its elements, or, if it is an array of arrays, its
@@ -1746,7 +1812,7 @@ ada_is_packed_array_type (struct type *type)
    in bits.  */
 
 static struct type *
-packed_array_type (struct type *type, long *elt_bits)
+constrained_packed_array_type (struct type *type, long *elt_bits)
 {
   struct type *new_elt_type;
   struct type *new_type;
@@ -1757,8 +1823,9 @@ packed_array_type (struct type *type, long *elt_bits)
     return type;
 
   new_type = alloc_type_copy (type);
-  new_elt_type = packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
-                                    elt_bits);
+  new_elt_type =
+    constrained_packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
+                                  elt_bits);
   create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type));
   TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
   TYPE_NAME (new_type) = ada_type_name (type);
@@ -1779,10 +1846,11 @@ packed_array_type (struct type *type, long *elt_bits)
   return new_type;
 }
 
-/* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE).  */
+/* The array type encoded by TYPE, where
+   ada_is_constrained_packed_array_type (TYPE).  */
 
 static struct type *
-decode_packed_array_type (struct type *type)
+decode_constrained_packed_array_type (struct type *type)
 {
   struct symbol *sym;
   struct block **blocks;
@@ -1821,24 +1889,18 @@ decode_packed_array_type (struct type *type)
       return NULL;
     }
 
-  if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1)
-    {
-      lim_warning
-       (_("could not understand bit size information on packed array"));
-      return NULL;
-    }
-
-  return packed_array_type (shadow_type, &bits);
+  bits = decode_packed_array_bitsize (type);
+  return constrained_packed_array_type (shadow_type, &bits);
 }
 
-/* Given that ARR is a struct value *indicating a GNAT packed array,
-   returns a simple array that denotes that array.  Its type is a
+/* Given that ARR is a struct value *indicating a GNAT constrained packed
+   array, returns a simple array that denotes that array.  Its type is a
    standard GDB array type except that the BITSIZEs of the array
    target types are set to the number of bits in each element, and the
    type length is set appropriately.  */
 
 static struct value *
-decode_packed_array (struct value *arr)
+decode_constrained_packed_array (struct value *arr)
 {
   struct type *type;
 
@@ -1853,7 +1915,7 @@ decode_packed_array (struct value *arr)
   if (TYPE_CODE (value_type (arr)) == TYPE_CODE_PTR)
     arr = value_ind (arr);
 
-  type = decode_packed_array_type (value_type (arr));
+  type = decode_constrained_packed_array_type (value_type (arr));
   if (type == NULL)
     {
       error (_("can't unpack array"));
@@ -2486,8 +2548,8 @@ ada_array_bound_from_type (struct type * arr_type, int n, int which)
 
   gdb_assert (which == 0 || which == 1);
 
-  if (ada_is_packed_array_type (arr_type))
-    arr_type = decode_packed_array_type (arr_type);
+  if (ada_is_constrained_packed_array_type (arr_type))
+    arr_type = decode_constrained_packed_array_type (arr_type);
 
   if (arr_type == NULL || !ada_is_simple_array_type (arr_type))
     return (LONGEST) - which;
@@ -2536,8 +2598,8 @@ ada_array_bound (struct value *arr, int n, int which)
 {
   struct type *arr_type = value_type (arr);
 
-  if (ada_is_packed_array_type (arr_type))
-    return ada_array_bound (decode_packed_array (arr), n, which);
+  if (ada_is_constrained_packed_array_type (arr_type))
+    return ada_array_bound (decode_constrained_packed_array (arr), n, which);
   else if (ada_is_simple_array_type (arr_type))
     return ada_array_bound_from_type (arr_type, n, which);
   else
@@ -2555,8 +2617,8 @@ ada_array_length (struct value *arr, int n)
 {
   struct type *arr_type = ada_check_typedef (value_type (arr));
 
-  if (ada_is_packed_array_type (arr_type))
-    return ada_array_length (decode_packed_array (arr), n);
+  if (ada_is_constrained_packed_array_type (arr_type))
+    return ada_array_length (decode_constrained_packed_array (arr), n);
 
   if (ada_is_simple_array_type (arr_type))
     return (ada_array_bound_from_type (arr_type, n, 1)
@@ -6586,7 +6648,7 @@ ada_prefer_type (struct type *type0, struct type *type1)
     return 0;
   else if (TYPE_NAME (type1) == NULL && TYPE_NAME (type0) != NULL)
     return 1;
-  else if (ada_is_packed_array_type (type0))
+  else if (ada_is_constrained_packed_array_type (type0))
     return 1;
   else if (ada_is_array_descriptor_type (type0)
            && !ada_is_array_descriptor_type (type1))
@@ -7158,14 +7220,14 @@ to_fixed_array_type (struct type *type0, struct value *dval,
 {
   struct type *index_type_desc;
   struct type *result;
-  int packed_array_p;
+  int constrained_packed_array_p;
 
   if (TYPE_FIXED_INSTANCE (type0))
     return type0;
 
-  packed_array_p = ada_is_packed_array_type (type0);
-  if (packed_array_p)
-    type0 = decode_packed_array_type (type0);
+  constrained_packed_array_p = ada_is_constrained_packed_array_type (type0);
+  if (constrained_packed_array_p)
+    type0 = decode_constrained_packed_array_type (type0);
 
   index_type_desc = ada_find_parallel_type (type0, "___XA");
   if (index_type_desc == NULL)
@@ -7187,7 +7249,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
       /* Make sure we always create a new array type when dealing with
         packed array types, since we're going to fix-up the array
         type length and element bitsize a little further down.  */
-      if (elt_type0 == elt_type && !packed_array_p)
+      if (elt_type0 == elt_type && !constrained_packed_array_p)
         result = type0;
       else
         result = create_array_type (alloc_type_copy (type0),
@@ -7230,7 +7292,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
         error (_("array type with dynamic size is larger than varsize-limit"));
     }
 
-  if (packed_array_p)
+  if (constrained_packed_array_p)
     {
       /* So far, the resulting type has been created as if the original
         type was a regular (non-packed) array type.  As a result, the
@@ -8842,7 +8904,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
             goto nosideret;
         }
 
-      if (ada_is_packed_array_type (desc_base_type (value_type (argvec[0]))))
+      if (ada_is_constrained_packed_array_type
+         (desc_base_type (value_type (argvec[0]))))
         argvec[0] = ada_coerce_to_simple_array (argvec[0]);
       else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
                && TYPE_FIELD_BITSIZE (value_type (argvec[0]), 0) != 0)
@@ -8955,7 +9018,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_packed_array_type (value_type (array)))
+        if (ada_is_constrained_packed_array_type (value_type (array)))
           error (_("cannot slice a packed array"));
 
         /* If this is a reference to an array or an array lvalue,
@@ -9120,7 +9183,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
           {
             arg1 = ada_coerce_ref (arg1);
 
-            if (ada_is_packed_array_type (value_type (arg1)))
+            if (ada_is_constrained_packed_array_type (value_type (arg1)))
               arg1 = ada_coerce_to_simple_array (arg1);
 
             type = ada_index_type (value_type (arg1), tem,
@@ -9175,8 +9238,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
           {
             LONGEST low, high;
 
-            if (ada_is_packed_array_type (type_arg))
-              type_arg = decode_packed_array_type (type_arg);
+            if (ada_is_constrained_packed_array_type (type_arg))
+              type_arg = decode_constrained_packed_array_type (type_arg);
 
             type = ada_index_type (type_arg, tem, ada_attribute_name (op));
             if (type == NULL)
index 8a465d4e95bf3ac54abedf1619a34a9d31d70fa3..cf4bebc23b675dcf9b70242e0cea91401cdb881c 100644 (file)
@@ -243,7 +243,7 @@ extern struct type *ada_parent_type (struct type *);
 
 extern int ada_is_ignored_field (struct type *, int);
 
-extern int ada_is_packed_array_type (struct type *);
+extern int ada_is_constrained_packed_array_type (struct type *);
 
 extern struct value *ada_value_primitive_packed_val (struct value *,
                                                     const gdb_byte *,
index 9fabd68515b8a4e9e7e57c3897e2cc51830a41e1..fe902e2e684e0b4fa9398eecd917cfcac4d302fb 100644 (file)
@@ -352,7 +352,7 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
   int bitsize;
   int n_indices;
 
-  if (ada_is_packed_array_type (type))
+  if (ada_is_constrained_packed_array_type (type))
     type = ada_coerce_to_simple_array_type (type);
 
   bitsize = 0;
@@ -770,7 +770,7 @@ ada_print_type (struct type *type0, char *varstring, struct ui_file *stream,
 
   if (ada_is_aligner_type (type))
     ada_print_type (ada_aligned_type (type), "", stream, show, level);
-  else if (ada_is_packed_array_type (type))
+  else if (ada_is_constrained_packed_array_type (type))
     {
       if (TYPE_CODE (type) == TYPE_CODE_PTR)
         {
index 565172c2ed4ea421016f4e283f0f46d1eaa75286..5fb44b1f3afe24bab459de608c166587a390b8ac 100644 (file)
@@ -686,7 +686,8 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
 
   type = ada_check_typedef (type);
 
-  if (ada_is_array_descriptor_type (type) || ada_is_packed_array_type (type))
+  if (ada_is_array_descriptor_type (type)
+      || ada_is_constrained_packed_array_type (type))
     {
       int retn;
       struct value *mark = value_mark ();
This page took 0.040672 seconds and 4 git commands to generate.