Certain aspects on types apply to their subtypes as well. These include the
aspects involved in iterators. If the type of a container is a subtype, obtain
the iterator aspects from the base type.

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-12-21  Ed Schonberg  <schonb...@adacore.com>

        * aspects.ads: New table Base_Aspect, to indicate that an aspect
        is defined on a base type.
        * aspects.adb (Find_Aspect): If the aspect is a Base_Aspect,
        examine the representation items of the base type.

Index: aspects.adb
===================================================================
--- aspects.adb (revision 182572)
+++ aspects.adb (working copy)
@@ -125,17 +125,29 @@
 
    function Find_Aspect (Ent : Entity_Id; A : Aspect_Id) return Node_Id is
       Ritem : Node_Id;
+      Typ   : Entity_Id;
 
    begin
 
       --  If the aspect is an inherited one and the entity is a class-wide
-      --  type, use the aspect of the specific type.
+      --  type, use the aspect of the specific type. If the type is a base
+      --  aspect, examine the rep. items of the base type.
 
-      if Is_Type (Ent)
-        and then Is_Class_Wide_Type (Ent)
-        and then Inherited_Aspect (A)
-      then
-         Ritem := First_Rep_Item (Etype (Ent));
+      if Is_Type (Ent) then
+         if Base_Aspect (A) then
+            Typ := Base_Type (Ent);
+         else
+            Typ := Ent;
+         end if;
+
+         if Is_Class_Wide_Type (Typ)
+           and then Inherited_Aspect (A)
+         then
+            Ritem := First_Rep_Item (Etype (Typ));
+         else
+            Ritem := First_Rep_Item (Typ);
+         end if;
+
       else
          Ritem := First_Rep_Item (Ent);
       end if;
Index: aspects.ads
===================================================================
--- aspects.ads (revision 182572)
+++ aspects.ads (working copy)
@@ -147,6 +147,24 @@
                         Aspect_Post          => True,
                         others               => False);
 
+   --  The following array indicates aspects that a subtype inherits from
+   --  its base type. True means that the subtype inherits the aspect from
+   --  its base type. False means it is not inherited.
+
+   Base_Aspect : constant array (Aspect_Id) of Boolean :=
+                   (Aspect_Atomic                  => True,
+                    Aspect_Atomic_Components       => True,
+                    Aspect_Discard_Names           => True,
+                    Aspect_Independent_Components  => True,
+                    Aspect_Iterator_Element        => True,
+                    Aspect_Constant_Indexing       => True,
+                    Aspect_Default_Iterator        => True,
+                    Aspect_Type_Invariant          => True,
+                    Aspect_Unchecked_Union         => True,
+                    Aspect_Variable_Indexing       => True,
+                    Aspect_Volatile                => True,
+                    others                         => False);
+
    --  The following array identifies all implementation defined aspects
 
    Impl_Defined_Aspects : constant array (Aspect_Id) of Boolean :=

Reply via email to