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
This commit is contained in:
parent
f7e6fc478f
commit
cb3d8731fd
|
@ -1,3 +1,13 @@
|
|||
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>
|
||||
|
||||
* sem_attr.adb, prj-nmsc.adb, exp_aggr.adb: Minor reformatting.
|
||||
|
|
|
@ -1803,10 +1803,23 @@ package body Exp_Attr is
|
|||
-- Descriptor_Size --
|
||||
---------------------
|
||||
|
||||
-- This attribute is handled entirely by the back end
|
||||
|
||||
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 --
|
||||
|
|
|
@ -5941,9 +5941,10 @@ as a @code{Pos} value (0 for @code{High_Order_First}, 1 for
|
|||
@findex Descriptor_Size
|
||||
@noindent
|
||||
Attribute @code{Descriptor_Size} returns the size in bits of the descriptor
|
||||
allocated for an unconstrained array type. An array descriptor contains bounds
|
||||
information and is located immediately before the first element of the array.
|
||||
The value of attribute @code{Descriptor_Size} is of type universal integer.
|
||||
allocated for a type. The result is non-zero only for unconstrained array
|
||||
types and the returned value is of type universal integer. In GNAT, an array
|
||||
descriptor contains bounds information and is located immediately before the
|
||||
first element of the array.
|
||||
|
||||
@smallexample @c ada
|
||||
type Unconstr_Array is array (Positive range <>) of Boolean;
|
||||
|
@ -5953,7 +5954,7 @@ Put_Line ("Descriptor size = " & Unconstr_Array'Descriptor_Size'Img);
|
|||
@noindent
|
||||
The attribute takes into account any additional padding due to type alignment.
|
||||
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 *
|
||||
Positive'Size + 2} or 64 bits.
|
||||
|
||||
|
|
|
@ -1906,7 +1906,7 @@ package body Sem_Attr is
|
|||
end if;
|
||||
end Validate_Non_Static_Attribute_Function_Call;
|
||||
|
||||
-- Start of processing for Analyze_Attribute
|
||||
-- Start of processing for Analyze_Attribute
|
||||
|
||||
begin
|
||||
-- Immediate return if unrecognized attribute (already diagnosed
|
||||
|
@ -3021,19 +3021,10 @@ package body Sem_Attr is
|
|||
when Attribute_Descriptor_Size =>
|
||||
Check_E0;
|
||||
|
||||
-- Attribute Descriptor_Size is relevant only in the context of an
|
||||
-- unconstrained array type.
|
||||
|
||||
-- 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))
|
||||
if not Is_Entity_Name (P)
|
||||
or else not Is_Type (Entity (P))
|
||||
then
|
||||
null;
|
||||
else
|
||||
Error_Attr_P ("invalid prefix for % attribute");
|
||||
Error_Attr_P ("prefix of attribute % must denote a type");
|
||||
end if;
|
||||
|
||||
Set_Etype (N, Universal_Integer);
|
||||
|
|
Loading…
Reference in New Issue