aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHristian Kirtchev <kirtchev@adacore.com>2011-09-06 12:03:30 +0000
committerArnaud Charlet <charlet@gcc.gnu.org>2011-09-06 14:03:30 +0200
commitcb3d8731fd7316bcdeff478fbae3f54cc9757944 (patch)
treee3a85fac6597037d92c44fd45349900c0deafa72
parentf7e6fc478f26792bba6cc51a400d8ffae2373ee1 (diff)
downloadgcc-cb3d8731fd7316bcdeff478fbae3f54cc9757944.zip
gcc-cb3d8731fd7316bcdeff478fbae3f54cc9757944.tar.gz
gcc-cb3d8731fd7316bcdeff478fbae3f54cc9757944.tar.bz2
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
-rw-r--r--gcc/ada/ChangeLog10
-rw-r--r--gcc/ada/exp_attr.adb19
-rw-r--r--gcc/ada/gnat_rm.texi9
-rw-r--r--gcc/ada/sem_attr.adb17
4 files changed, 35 insertions, 20 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 9451718..02520df 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -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.
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index a98a7b93..c05385e 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -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 --
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index 7680876..4e74a32 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -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.
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index eca9836..738edda 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -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);