This patch implements AI12-0180, so protected subprograms and invariants
are directly visible within Invariant aspects.

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

gcc/ada/

        * sem_ch13.adb (Visible_Component): Enable this code for task
        and protected types, as well as record and private types.
        * sem_ch13.ads (Replace_Type_References_Generic): Update
        comment.  Move the efficiency comment into the body, because
        it's about the implementation.
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -14498,11 +14498,9 @@ package body Sem_Ch13 is
 
       function Visible_Component (Comp : Name_Id) return Entity_Id;
       --  Given an identifier in the expression, check whether there is a
-      --  discriminant or component of the type that is directy visible, and
-      --  rewrite it as the corresponding selected component of the formal of
-      --  the subprogram. The entity is located by a sequential search, which
-      --  seems acceptable given the typical size of component lists and check
-      --  expressions. Possible optimization ???
+      --  discriminant, component, protected procedure, or entry of the type
+      --  that is directy visible, and rewrite it as the corresponding selected
+      --  component of the formal of the subprogram.
 
       ----------------------
       -- Replace_Type_Ref --
@@ -14677,14 +14675,20 @@ package body Sem_Ch13 is
 
       function Visible_Component (Comp : Name_Id) return Entity_Id is
          E : Entity_Id;
-
       begin
-         --  Types with nameable components are records and discriminated
-         --  private types.
+         --  Types with nameable components are record, task, and protected
+         --  types, and discriminated private types.
 
-         if Ekind (T) = E_Record_Type
+         if Ekind (T) in E_Record_Type
+                       | E_Task_Type
+                       | E_Protected_Type
            or else (Is_Private_Type (T) and then Has_Discriminants (T))
          then
+            --  This is a sequential search, which seems acceptable
+            --  efficiency-wise, given the typical size of component
+            --  lists, protected operation lists, task item lists, and
+            --  check expressions.
+
             E := First_Entity (T);
             while Present (E) loop
                if Comes_From_Source (E) and then Chars (E) = Comp then
@@ -14695,7 +14699,7 @@ package body Sem_Ch13 is
             end loop;
          end if;
 
-         --  Nothing by that name, or the type has no components
+         --  Nothing by that name
 
          return Empty;
       end Visible_Component;


diff --git a/gcc/ada/sem_ch13.ads b/gcc/ada/sem_ch13.ads
--- a/gcc/ada/sem_ch13.ads
+++ b/gcc/ada/sem_ch13.ads
@@ -164,6 +164,11 @@ package Sem_Ch13 is
    --  parameter does the actual replacement of node N, which is either a
    --  simple direct reference to T, or a selected component that represents
    --  an appropriately qualified occurrence of T.
+   --
+   --  This also replaces each reference to a component, entry, or protected
+   --  procedure with a selected component whose prefix is the parameter.
+   --  For example, Component_Name becomes Parameter.Component_Name, where
+   --  Parameter is the parameter, which is of type T.
 
    function Rep_Item_Too_Late
      (T     : Entity_Id;


Reply via email to