Patchwork [Ada] Inherited aspects of subtypes

login
register
mail settings
Submitter Arnaud Charlet
Date Dec. 21, 2011, 1:37 p.m.
Message ID <20111221133723.GA2181@adacore.com>
Download mbox | patch
Permalink /patch/132636/
State New
Headers show

Comments

Arnaud Charlet - Dec. 21, 2011, 1:37 p.m.
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  <schonberg@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.

Patch

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 :=