From 46a3809b1579cb86574c6ba8e2858a8f369f8786 Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Mon, 22 Jun 2020 15:23:45 -0400 Subject: [PATCH] [Ada] Ada2020: AI12-0180 Using subprograms and entries in invariants 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. --- gcc/ada/sem_ch13.adb | 24 ++++++++++++++---------- gcc/ada/sem_ch13.ads | 5 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 60660bcbfb7..28fd1ed080c 100644 --- 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 index 3d24c04d1a8..525d3e4ad27 100644 --- 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; -- 2.30.2