This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Housekeeping work in gigi (3/n)


Tested on i586-suse-linux, applied on the mainline.


2009-04-21  Eric Botcazou  <ebotcazou@adacore.com>

	* ada-tree.h (TYPE_RM_SIZE_NUM): Delete.
	(TYPE_RM_SIZE): Access TYPE_LANG_SLOT_1 directly for integral types.
	* decl.c (gnat_to_gnu_entity) <E_Modular_Integer_Type>: Remove useless
	support code for packed array types and assert its uselessness.
	<E_Signed_Integer_Subtype>: Reuse entity identifier in more places and
	adjust for TYPE_RM_SIZE change.
	<all> Fix nits in comments.  Use Original_Array_Type accessor instead
	of Associated_Node_For_Itype accessor for packed array types.
	(make_packable_type): Likewise.
	(maybe_pad_type): Likewise.
	(set_rm_size): Likewise.  Rework conditional statement.  Adjust for
	TYPE_RM_SIZE change.
	(make_type_from_size): Adjust for TYPE_RM_SIZE change.
	(rm_size): Fix nits in comments.  Rework conditional statements.
	* misc.c (gnat_print_type): Adjust for TYPE_RM_SIZE change.
	* trans.c (Attribute_to_gnu): Fix nits in comments.
	* utils.c (gnat_init_decl_processing): Use more appropriate function
	to initialize the size_type_node.  Adjust for TYPE_RM_SIZE change.


-- 
Eric Botcazou
Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 146520)
+++ gcc-interface/utils.c	(working copy)
@@ -515,18 +515,17 @@ gnat_init_decl_processing (void)
   build_common_tree_nodes (true, true);
 
   /* In Ada, we use a signed type for SIZETYPE.  Use the signed type
-     corresponding to the size of Pmode.  In most cases when ptr_mode and
-     Pmode differ, C will use the width of ptr_mode as sizetype.  But we get
-     far better code using the width of Pmode.  Make this here since we need
-     this before we can expand the GNAT types.  */
-  size_type_node = gnat_type_for_size (GET_MODE_BITSIZE (Pmode), 0);
+     corresponding to the width of Pmode.  In most cases when ptr_mode
+     and Pmode differ, C will use the width of ptr_mode for SIZETYPE.
+     But we get far better code using the width of Pmode.  */
+  size_type_node = gnat_type_for_mode (Pmode, 0);
   set_sizetype (size_type_node);
 
   /* In Ada, we use an unsigned 8-bit type for the default boolean type.  */
   boolean_type_node = make_node (BOOLEAN_TYPE);
   TYPE_PRECISION (boolean_type_node) = 1;
   fixup_unsigned_type (boolean_type_node);
-  TYPE_RM_SIZE_NUM (boolean_type_node) = bitsize_int (1);
+  TYPE_RM_SIZE (boolean_type_node) = bitsize_int (1);
 
   build_common_tree_nodes_2 (0);
 
@@ -2230,7 +2229,7 @@ gnat_types_compatible_p (tree t1, tree t
       && TREE_TYPE (t1) == TREE_TYPE (t2)
       && (TYPE_DOMAIN (t1) == TYPE_DOMAIN (t2)
 	  || (TYPE_DOMAIN (t1)
-	      && TYPE_DOMAIN (t2)      
+	      && TYPE_DOMAIN (t2)
 	      && tree_int_cst_equal (TYPE_MIN_VALUE (TYPE_DOMAIN (t1)),
 				     TYPE_MIN_VALUE (TYPE_DOMAIN (t2)))
 	      && tree_int_cst_equal (TYPE_MAX_VALUE (TYPE_DOMAIN (t1)),
@@ -5176,10 +5175,10 @@ handle_type_generic_attribute (tree *nod
 			       bool * ARG_UNUSED (no_add_attrs))
 {
   tree params;
-  
+
   /* Ensure we have a function type.  */
   gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
-  
+
   params = TYPE_ARG_TYPES (*node);
   while (params && ! VOID_TYPE_P (TREE_VALUE (params)))
     params = TREE_CHAIN (params);
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 146520)
+++ gcc-interface/decl.c	(working copy)
@@ -310,7 +310,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 		      || kind == E_Anonymous_Access_Protected_Subprogram_Type
 		      || kind == E_Access_Subtype)));
 
-  /* RM_Size must be specified for all discrete and fixed-point types.  */
+  /* The RM size must be specified for all discrete and fixed-point types.  */
   gcc_assert (!IN (kind, Discrete_Or_Fixed_Point_Kind)
 	      || !Unknown_RM_Size (gnat_entity));
 
@@ -1465,28 +1465,23 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
       break;
 
     case E_Modular_Integer_Type:
-      /* For modular types, make the unsigned type of the proper number of
-	 bits and then set up the modulus, if required.  */
       {
+	/* For modular types, make the unsigned type of the proper number
+	   of bits and then set up the modulus, if required.  */
+	tree gnu_modulus, gnu_high = NULL_TREE;
 	enum machine_mode mode;
-	tree gnu_modulus;
-	tree gnu_high = 0;
 
-	if (Is_Packed_Array_Type (gnat_entity))
-	  esize = UI_To_Int (RM_Size (gnat_entity));
+	/* Packed array types are supposed to be subtypes only.  */
+	gcc_assert (!Is_Packed_Array_Type (gnat_entity));
 
 	/* Find the smallest mode at least ESIZE bits wide and make a class
 	   using that mode.  */
-
 	for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
 	     GET_MODE_BITSIZE (mode) < esize;
 	     mode = GET_MODE_WIDER_MODE (mode))
 	  ;
 
 	gnu_type = make_unsigned_type (GET_MODE_BITSIZE (mode));
-	TYPE_PACKED_ARRAY_TYPE_P (gnu_type)
-	  = (Is_Packed_Array_Type (gnat_entity)
-	     && Is_Bit_Packed_Array (Original_Array_Type (gnat_entity)));
 
 	/* Get the modulus in this type.  If it overflows, assume it is because
 	   it is equal to 2**Esize.  Note that there is no overflow checking
@@ -1510,7 +1505,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 		&& !tree_int_cst_equal (TYPE_MAX_VALUE (gnu_type), gnu_high)))
 	  {
 	    tree gnu_subtype = make_node (INTEGER_TYPE);
-
 	    TYPE_NAME (gnu_type) = create_concat_name (gnat_entity, "UMT");
 	    TREE_TYPE (gnu_subtype) = gnu_type;
 	    TYPE_MIN_VALUE (gnu_subtype) = TYPE_MIN_VALUE (gnu_type);
@@ -1520,11 +1514,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	    TYPE_PRECISION (gnu_subtype) = esize;
 	    TYPE_UNSIGNED (gnu_subtype) = 1;
 	    TYPE_EXTRA_SUBTYPE_P (gnu_subtype) = 1;
-	    TYPE_PACKED_ARRAY_TYPE_P (gnu_subtype)
-	      = (Is_Packed_Array_Type (gnat_entity)
-		 && Is_Bit_Packed_Array (Original_Array_Type (gnat_entity)));
 	    layout_type (gnu_subtype);
-
 	    gnu_type = gnu_subtype;
 	  }
       }
@@ -1556,8 +1546,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	  && !In_Extended_Main_Code_Unit (Ancestor_Subtype (gnat_entity))
 	  && (!Compile_Time_Known_Value (Type_Low_Bound (gnat_entity))
 	      || !Compile_Time_Known_Value (Type_High_Bound (gnat_entity))))
-	gnat_to_gnu_entity (Ancestor_Subtype (gnat_entity),
-			    gnu_expr, 0);
+	gnat_to_gnu_entity (Ancestor_Subtype (gnat_entity), gnu_expr, 0);
 
       gnu_type = make_node (INTEGER_TYPE);
       TREE_TYPE (gnu_type) = get_unpadded_type (Etype (gnat_entity));
@@ -1627,7 +1616,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	  tree gnu_field_type, gnu_field;
 
 	  /* Set the RM size before wrapping up the type.  */
-	  TYPE_RM_SIZE_NUM (gnu_type)
+	  TYPE_RM_SIZE (gnu_type)
 	    = UI_To_gnu (RM_Size (gnat_entity), bitsizetype);
 	  TYPE_PACKED_ARRAY_TYPE_P (gnu_type) = 1;
 	  gnu_field_type = gnu_type;
@@ -1644,8 +1633,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 
 	  /* Create a stripped-down declaration of the original type, mainly
 	     for debugging.  */
-	  create_type_decl (get_entity_name (gnat_entity), gnu_field_type,
-			    NULL, true, debug_info_p, gnat_entity);
+	  create_type_decl (gnu_entity_id, gnu_field_type, NULL, true,
+			    debug_info_p, gnat_entity);
 
 	  /* Don't notify the field as "addressable", since we won't be taking
 	     it's address and it would prevent create_field_decl from making a
@@ -1670,7 +1659,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 	  tree gnu_field_type, gnu_field;
 
 	  /* Set the RM size before wrapping up the type.  */
-	  TYPE_RM_SIZE_NUM (gnu_type)
+	  TYPE_RM_SIZE (gnu_type)
 	    = UI_To_gnu (RM_Size (gnat_entity), bitsizetype);
 	  gnu_field_type = gnu_type;
 
@@ -1682,8 +1671,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 
 	  /* Create a stripped-down declaration of the original type, mainly
 	     for debugging.  */
-	  create_type_decl (get_entity_name (gnat_entity), gnu_field_type,
-			    NULL, true, debug_info_p, gnat_entity);
+	  create_type_decl (gnu_entity_id, gnu_field_type, NULL, true,
+			    debug_info_p, gnat_entity);
 
 	  /* Don't notify the field as "addressable", since we won't be taking
 	     it's address and it would prevent create_field_decl from making a
@@ -4750,11 +4739,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
   if (this_global)
     force_global--;
 
+  /* If this is a packed array type whose original array type is itself
+     an Itype without freeze node, make sure the latter is processed.  */
   if (Is_Packed_Array_Type (gnat_entity)
-      && Is_Itype (Associated_Node_For_Itype (gnat_entity))
-      && No (Freeze_Node (Associated_Node_For_Itype (gnat_entity)))
-      && !present_gnu_tree (Associated_Node_For_Itype (gnat_entity)))
-    gnat_to_gnu_entity (Associated_Node_For_Itype (gnat_entity), NULL_TREE, 0);
+      && Is_Itype (Original_Array_Type (gnat_entity))
+      && No (Freeze_Node (Original_Array_Type (gnat_entity)))
+      && !present_gnu_tree (Original_Array_Type (gnat_entity)))
+    gnat_to_gnu_entity (Original_Array_Type (gnat_entity), NULL_TREE, 0);
 
   return gnu_decl;
 }
@@ -5818,7 +5809,7 @@ make_packable_type (tree type, bool in_r
 	new_field_type = make_packable_type (new_field_type, true);
 
       /* However, for the last field in a not already packed record type
-	 that is of an aggregate type, we need to use the RM_Size in the
+	 that is of an aggregate type, we need to use the RM size in the
 	 packable version of the record type, see finish_record_type.  */
       if (!TREE_CHAIN (old_field)
 	  && !TYPE_PACKED (type)
@@ -5895,8 +5886,8 @@ make_packable_type (tree type, bool in_r
 
    DEFINITION is true if this type is being defined.
 
-   SAME_RM_SIZE is true if the RM_Size of the resulting type is to be set
-   to SIZE too; otherwise, it's set to the RM_Size of the original type.  */
+   SAME_RM_SIZE is true if the RM size of the resulting type is to be set
+   to SIZE too; otherwise, it's set to the RM size of the original type.  */
 
 tree
 maybe_pad_type (tree type, tree size, unsigned int align,
@@ -6017,8 +6008,8 @@ maybe_pad_type (tree type, tree size, un
   /* Do not finalize it until after the auxiliary record is built.  */
   finish_record_type (record, field, 1, true);
 
-  /* Set the same size for its RM_size if requested; otherwise reuse
-     the RM_size of the original type.  */
+  /* Set the same size for its RM size if requested; otherwise reuse
+     the RM size of the original type.  */
   SET_TYPE_ADA_SIZE (record, same_rm_size ? size : orig_rm_size);
 
   /* Unless debugging information isn't being written for the input type,
@@ -7256,7 +7247,7 @@ validate_size (Uint uint_size, tree gnu_
   return size;
 }
 
-/* Similarly, but both validate and process a value of RM_Size.  This
+/* Similarly, but both validate and process a value of RM size.  This
    routine is only called for types.  */
 
 static void
@@ -7270,7 +7261,7 @@ set_rm_size (Uint uint_size, tree gnu_ty
   tree size;
 
   /* Get the size as a tree.  Do nothing if none was specified, either
-     because RM_Size was not Present or if the specified size was zero.
+     because RM size was not Present or if the specified size was zero.
      Give an error if a size was specified, but cannot be represented as
      in sizetype.  */
   if (No (uint_size) || uint_size == No_Uint)
@@ -7315,13 +7306,14 @@ set_rm_size (Uint uint_size, tree gnu_ty
       return;
     }
 
-  /* Otherwise, set the RM_Size.  */
-  if (TREE_CODE (gnu_type) == INTEGER_TYPE
-      && Is_Discrete_Or_Fixed_Point_Type (gnat_entity))
-    TYPE_RM_SIZE_NUM (gnu_type) = size;
-  else if (TREE_CODE (gnu_type) == ENUMERAL_TYPE
-	   || TREE_CODE (gnu_type) == BOOLEAN_TYPE)
-    TYPE_RM_SIZE_NUM (gnu_type) = size;
+  /* Otherwise, set the RM size proper for numerical types...  */
+  if ((TREE_CODE (gnu_type) == INTEGER_TYPE
+       && Is_Discrete_Or_Fixed_Point_Type (gnat_entity))
+      || (TREE_CODE (gnu_type) == ENUMERAL_TYPE
+	  || TREE_CODE (gnu_type) == BOOLEAN_TYPE))
+    TYPE_RM_SIZE (gnu_type) = size;
+
+  /* ...or the Ada size for record and union types.  */
   else if ((TREE_CODE (gnu_type) == RECORD_TYPE
 	    || TREE_CODE (gnu_type) == UNION_TYPE
 	    || TREE_CODE (gnu_type) == QUAL_UNION_TYPE)
@@ -7383,7 +7375,7 @@ make_type_from_size (tree type, tree siz
 	    TYPE_NAME (new_type) = TYPE_NAME (type);
 	}
       TYPE_BIASED_REPRESENTATION_P (new_type) = biased_p;
-      TYPE_RM_SIZE_NUM (new_type) = bitsize_int (size);
+      TYPE_RM_SIZE (new_type) = bitsize_int (size);
       return new_type;
 
     case RECORD_TYPE:
@@ -7727,32 +7719,34 @@ substitute_in_type (tree t, tree f, tree
     }
 }
 
-/* Return the "RM size" of GNU_TYPE.  This is the actual number of bits
+/* Return the RM size of GNU_TYPE.  This is the actual number of bits
    needed to represent the object.  */
 
 tree
 rm_size (tree gnu_type)
 {
-  /* For integer types, this is the precision.  For record types, we store
-     the size explicitly.  For other types, this is just the size.  */
-
+  /* For integer types, this is the precision.  */
   if (INTEGRAL_TYPE_P (gnu_type) && TYPE_RM_SIZE (gnu_type))
     return TYPE_RM_SIZE (gnu_type);
-  else if (TREE_CODE (gnu_type) == RECORD_TYPE
-	   && TYPE_CONTAINS_TEMPLATE_P (gnu_type))
-    /* Return the rm_size of the actual data plus the size of the template.  */
+
+  /* Return the RM size of the actual data plus the size of the template.  */
+  if (TREE_CODE (gnu_type) == RECORD_TYPE
+      && TYPE_CONTAINS_TEMPLATE_P (gnu_type))
     return
       size_binop (PLUS_EXPR,
 		  rm_size (TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_type)))),
 		  DECL_SIZE (TYPE_FIELDS (gnu_type)));
-  else if ((TREE_CODE (gnu_type) == RECORD_TYPE
-	    || TREE_CODE (gnu_type) == UNION_TYPE
-	    || TREE_CODE (gnu_type) == QUAL_UNION_TYPE)
-	   && !TYPE_IS_FAT_POINTER_P (gnu_type)
-	   && TYPE_ADA_SIZE (gnu_type))
+
+  /* For record types, we store the size explicitly.  */
+  if ((TREE_CODE (gnu_type) == RECORD_TYPE
+       || TREE_CODE (gnu_type) == UNION_TYPE
+       || TREE_CODE (gnu_type) == QUAL_UNION_TYPE)
+      && !TYPE_IS_FAT_POINTER_P (gnu_type)
+      && TYPE_ADA_SIZE (gnu_type))
     return TYPE_ADA_SIZE (gnu_type);
-  else
-    return TYPE_SIZE (gnu_type);
+
+  /* For other types, this is just the size.  */
+  return TYPE_SIZE (gnu_type);
 }
 
 /* Return an identifier representing the external name to be used for
Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 146520)
+++ gcc-interface/trans.c	(working copy)
@@ -1297,7 +1297,7 @@ Attribute_to_gnu (Node_Id gnat_node, tre
       /* If we're looking for the size of a field, return the field size.
 	 Otherwise, if the prefix is an object, or if 'Object_Size or
 	 'Max_Size_In_Storage_Elements has been specified, the result is the
-	 GCC size of the type.  Otherwise, the result is the RM_Size of the
+	 GCC size of the type.  Otherwise, the result is the RM size of the
 	 type.  */
       if (TREE_CODE (gnu_prefix) == COMPONENT_REF)
 	gnu_result = DECL_SIZE (TREE_OPERAND (gnu_prefix, 1));
@@ -1306,7 +1306,7 @@ Attribute_to_gnu (Node_Id gnat_node, tre
 	       || attribute == Attr_Max_Size_In_Storage_Elements)
 	{
 	  /* If this is a padded type, the GCC size isn't relevant to the
-	     programmer.  Normally, what we want is the RM_Size, which was set
+	     programmer.  Normally, what we want is the RM size, which was set
 	     from the specified size, but if it was not set, we want the size
 	     of the relevant field.  Using the MAX of those two produces the
 	     right result in all case.  Don't use the size of the field if it's
Index: gcc-interface/ada-tree.h
===================================================================
--- gcc-interface/ada-tree.h	(revision 146520)
+++ gcc-interface/ada-tree.h	(working copy)
@@ -6,7 +6,7 @@
  *                                                                          *
  *                              C Header File                               *
  *                                                                          *
- *          Copyright (C) 1992-2008, Free Software Foundation, Inc.         *
+ *          Copyright (C) 1992-2009, Free Software Foundation, Inc.         *
  *                                                                          *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
@@ -162,6 +162,10 @@ struct lang_type GTY(()) {tree t; };
    cico parameter passing mechanism refer to the routine gnat_to_gnu_entity. */
 #define TYPE_CI_CO_LIST(NODE)  TYPE_LANG_SLOT_1 (FUNCTION_TYPE_CHECK (NODE))
 
+/* For integral types, this is the RM Size of the type.  */
+#define TYPE_RM_SIZE(NODE)  \
+  TYPE_LANG_SLOT_1 (TREE_CHECK3 (NODE, ENUMERAL_TYPE, BOOLEAN_TYPE, INTEGER_TYPE))
+
 /* For an INTEGER_TYPE with TYPE_MODULAR_P, this is the value of the
    modulus. */
 #define TYPE_MODULUS(NODE) GET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE))
@@ -182,13 +186,6 @@ struct lang_type GTY(()) {tree t; };
 #define SET_TYPE_DIGITS_VALUE(NODE, X)  \
   SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
 
-/* For numeric types, stores the RM_Size of the type.  */
-#define TYPE_RM_SIZE_NUM(NODE)	TYPE_LANG_SLOT_1 (NUMERICAL_TYPE_CHECK (NODE))
-
-#define TYPE_RM_SIZE(NODE)					\
-  (INTEGRAL_TYPE_P (NODE) || TREE_CODE (NODE) == REAL_TYPE	\
-   ? TYPE_RM_SIZE_NUM (NODE) : 0)
-
 /* For a RECORD_TYPE that is a fat pointer, point to the type for the
    unconstrained object.  Likewise for a RECORD_TYPE that is pointed
    to by a thin pointer.  */
Index: gcc-interface/misc.c
===================================================================
--- gcc-interface/misc.c	(revision 146520)
+++ gcc-interface/misc.c	(working copy)
@@ -544,7 +544,7 @@ gnat_print_type (FILE *file, tree node, 
 
     case ENUMERAL_TYPE:
     case BOOLEAN_TYPE:
-      print_node (file, "RM size", TYPE_RM_SIZE_NUM (node), indent + 4);
+      print_node (file, "RM size", TYPE_RM_SIZE (node), indent + 4);
       break;
 
     case INTEGER_TYPE:
@@ -558,7 +558,7 @@ gnat_print_type (FILE *file, tree node, 
       else
 	print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
 
-      print_node (file, "RM size", TYPE_RM_SIZE_NUM (node), indent + 4);
+      print_node (file, "RM size", TYPE_RM_SIZE (node), indent + 4);
       break;
 
     case ARRAY_TYPE:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]