Commit cb3d8731 by Hristian Kirtchev Committed by Arnaud Charlet

exp_attr.adb (Expand_N_Attribute_Reference): Rewrite the processing for Descriptor_Size.

2011-09-06  Hristian Kirtchev  <kirtchev@adacore.com>

	* exp_attr.adb (Expand_N_Attribute_Reference): Rewrite the
	processing for Descriptor_Size.
	* gnat_rm.texi: Rephrase the wording for attribute Descriptor_Size
	to account for its broader usage.
	* sem_attr.adb (Analyze_Attribute): Change the error detection
	circuitry for Descriptor_Size as the attribute is now applicable
	to all types.

From-SVN: r178590
parent f7e6fc47
2011-09-06 Hristian Kirtchev <kirtchev@adacore.com>
* exp_attr.adb (Expand_N_Attribute_Reference): Rewrite the
processing for Descriptor_Size.
* gnat_rm.texi: Rephrase the wording for attribute Descriptor_Size
to account for its broader usage.
* sem_attr.adb (Analyze_Attribute): Change the error detection
circuitry for Descriptor_Size as the attribute is now applicable
to all types.
2011-09-06 Robert Dewar <dewar@adacore.com> 2011-09-06 Robert Dewar <dewar@adacore.com>
* sem_attr.adb, prj-nmsc.adb, exp_aggr.adb: Minor reformatting. * sem_attr.adb, prj-nmsc.adb, exp_aggr.adb: Minor reformatting.
......
...@@ -1803,10 +1803,23 @@ package body Exp_Attr is ...@@ -1803,10 +1803,23 @@ package body Exp_Attr is
-- Descriptor_Size -- -- Descriptor_Size --
--------------------- ---------------------
-- This attribute is handled entirely by the back end
when Attribute_Descriptor_Size => when Attribute_Descriptor_Size =>
Apply_Universal_Integer_Attribute_Checks (N);
-- Attribute Descriptor_Size is handled by the back end when applied
-- to an unconstrained array type.
if Is_Array_Type (Ptyp)
and then not Is_Constrained (Ptyp)
then
Apply_Universal_Integer_Attribute_Checks (N);
-- For any other type, the descriptor size is 0 because there is no
-- actual descriptor.
else
Rewrite (N, Make_Integer_Literal (Loc, 0));
Analyze (N);
end if;
--------------- ---------------
-- Elab_Body -- -- Elab_Body --
......
...@@ -5941,9 +5941,10 @@ as a @code{Pos} value (0 for @code{High_Order_First}, 1 for ...@@ -5941,9 +5941,10 @@ as a @code{Pos} value (0 for @code{High_Order_First}, 1 for
@findex Descriptor_Size @findex Descriptor_Size
@noindent @noindent
Attribute @code{Descriptor_Size} returns the size in bits of the descriptor Attribute @code{Descriptor_Size} returns the size in bits of the descriptor
allocated for an unconstrained array type. An array descriptor contains bounds allocated for a type. The result is non-zero only for unconstrained array
information and is located immediately before the first element of the array. types and the returned value is of type universal integer. In GNAT, an array
The value of attribute @code{Descriptor_Size} is of type universal integer. descriptor contains bounds information and is located immediately before the
first element of the array.
@smallexample @c ada @smallexample @c ada
type Unconstr_Array is array (Positive range <>) of Boolean; type Unconstr_Array is array (Positive range <>) of Boolean;
...@@ -5953,7 +5954,7 @@ Put_Line ("Descriptor size = " & Unconstr_Array'Descriptor_Size'Img); ...@@ -5953,7 +5954,7 @@ Put_Line ("Descriptor size = " & Unconstr_Array'Descriptor_Size'Img);
@noindent @noindent
The attribute takes into account any additional padding due to type alignment. The attribute takes into account any additional padding due to type alignment.
In the example above, the descriptor contains two values of type In the example above, the descriptor contains two values of type
@code{Positive} representing the low and high bound. Since @code{Positive} has @code{Positive} representing the low and high bound. Since @code{Positive} has
a size of 31 bits and an alignment of 4, the descriptor size is @code{2 * a size of 31 bits and an alignment of 4, the descriptor size is @code{2 *
Positive'Size + 2} or 64 bits. Positive'Size + 2} or 64 bits.
......
...@@ -1906,7 +1906,7 @@ package body Sem_Attr is ...@@ -1906,7 +1906,7 @@ package body Sem_Attr is
end if; end if;
end Validate_Non_Static_Attribute_Function_Call; end Validate_Non_Static_Attribute_Function_Call;
-- Start of processing for Analyze_Attribute -- Start of processing for Analyze_Attribute
begin begin
-- Immediate return if unrecognized attribute (already diagnosed -- Immediate return if unrecognized attribute (already diagnosed
...@@ -3021,19 +3021,10 @@ package body Sem_Attr is ...@@ -3021,19 +3021,10 @@ package body Sem_Attr is
when Attribute_Descriptor_Size => when Attribute_Descriptor_Size =>
Check_E0; Check_E0;
-- Attribute Descriptor_Size is relevant only in the context of an if not Is_Entity_Name (P)
-- unconstrained array type. or else not Is_Type (Entity (P))
-- Shouldn't it just return zero for types other than arrays or
-- constrained arrays ???
if Is_Entity_Name (P)
and then Is_Array_Type (Entity (P))
and then not Is_Constrained (Entity (P))
then then
null; Error_Attr_P ("prefix of attribute % must denote a type");
else
Error_Attr_P ("invalid prefix for % attribute");
end if; end if;
Set_Etype (N, Universal_Integer); Set_Etype (N, Universal_Integer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment