In Ada2012 some aspects on tagged types are inherited, and apply to the class
wide type as well. Among these are the Default_Iterator and Iterator_Element
aspects. These allow iterations over class-wide objects, e.g. in pre- or post-
conditions.
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-11-07 Ed Schonberg <[email protected]>
* aspects.ads (Inherited_Aspect): Map that indicates type aspects
that are inherited by default, and apply to the class-wide type
as well.
* aspects.adb (Find_Aspect): If the entity is class-wide and the
aspect is inherited, use the aspect of the specific type.
Index: aspects.adb
===================================================================
--- aspects.adb (revision 181090)
+++ aspects.adb (working copy)
@@ -127,7 +127,19 @@
Ritem : Node_Id;
begin
- Ritem := First_Rep_Item (Ent);
+
+ -- If the aspect is an inherited one and the entity is a class-wide
+ -- type, use the aspect of the specific type.
+
+ if Is_Type (Ent)
+ and then Is_Class_Wide_Type (Ent)
+ and then Inherited_Aspect (A)
+ then
+ Ritem := First_Rep_Item (Etype (Ent));
+ else
+ Ritem := First_Rep_Item (Ent);
+ end if;
+
while Present (Ritem) loop
if Nkind (Ritem) = N_Aspect_Specification
and then Get_Aspect_Id (Chars (Identifier (Ritem))) = A
Index: aspects.ads
===================================================================
--- aspects.ads (revision 181090)
+++ aspects.ads (working copy)
@@ -176,6 +176,18 @@
(Aspect_Test_Case => False,
others => True);
+ -- The following array indicates type aspects that are inherited and apply
+ -- to the class-wide type as well.
+
+ Inherited_Aspect : constant array (Aspect_Id) of Boolean :=
+ (Aspect_Constant_Indexing => True,
+ Aspect_Default_Iterator => True,
+ Aspect_Implicit_Dereference => True,
+ Aspect_Iterator_Element => True,
+ Aspect_Remote_Types => True,
+ Aspect_Variable_Indexing => True,
+ others => False);
+
-- The following subtype defines aspects corresponding to library unit
-- pragmas, these can only validly appear as aspects for library units,
-- and result in a corresponding pragma being inserted immediately after