From e1e129684cb791c6fe508737a959c84b5f6dfbfa Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Tue, 23 Jun 2020 19:50:18 +0200 Subject: [PATCH] [Ada] Avoid unnecessary (re)assignments in Make_Info gcc/ada/ * sem_ch3.adb (Array_Type_Declaration): Refine type of a local variable. (Make_Index): Simplify to avoid assignment with a type entity and then backtracking by reassigning to Empty; remove excessive whitespace. * sem_ch9.adb (Analyze_Entry_Body): Remove extra parens. --- gcc/ada/sem_ch3.adb | 27 ++++++++++++--------------- gcc/ada/sem_ch9.adb | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index a5fb045171d..c9b1f18f3cd 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -6042,7 +6042,7 @@ package body Sem_Ch3 is then declare Loc : constant Source_Ptr := Sloc (Def); - Decl : Entity_Id; + Decl : Node_Id; New_E : Entity_Id; begin @@ -19211,23 +19211,20 @@ package body Sem_Ch3 is return; end if; + -- If the range bounds are "T'Low .. T'High" where T is a name of + -- a discrete type, then use T as the type of the index. + if Nkind (Low_Bound (N)) = N_Attribute_Reference and then Attribute_Name (Low_Bound (N)) = Name_First and then Is_Entity_Name (Prefix (Low_Bound (N))) and then Is_Discrete_Type (Entity (Prefix (Low_Bound (N)))) - then - -- The type of the index will be the type of the prefix, as long - -- as the upper bound is 'Last of the same type. + and then Nkind (High_Bound (N)) = N_Attribute_Reference + and then Attribute_Name (High_Bound (N)) = Name_Last + and then Is_Entity_Name (Prefix (High_Bound (N))) + and then Entity (Prefix (High_Bound (N))) = Def_Id + then Def_Id := Entity (Prefix (Low_Bound (N))); - - if Nkind (High_Bound (N)) /= N_Attribute_Reference - or else Attribute_Name (High_Bound (N)) /= Name_Last - or else not Is_Entity_Name (Prefix (High_Bound (N))) - or else Entity (Prefix (High_Bound (N))) /= Def_Id - then - Def_Id := Empty; - end if; end if; R := N; @@ -19370,9 +19367,9 @@ package body Sem_Ch3 is Set_First_Literal (Def_Id, First_Literal (T)); end if; - Set_Size_Info (Def_Id, (T)); - Set_RM_Size (Def_Id, RM_Size (T)); - Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); + Set_Size_Info (Def_Id, (T)); + Set_RM_Size (Def_Id, RM_Size (T)); + Set_First_Rep_Item (Def_Id, First_Rep_Item (T)); Set_Scalar_Range (Def_Id, R); Conditional_Delay (Def_Id, T); diff --git a/gcc/ada/sem_ch9.adb b/gcc/ada/sem_ch9.adb index effc8586c95..bf266e08ca0 100644 --- a/gcc/ada/sem_ch9.adb +++ b/gcc/ada/sem_ch9.adb @@ -1252,7 +1252,7 @@ package body Sem_Ch9 is E := First_Entity (P_Type); while Present (E) loop if Chars (E) = Chars (Id) - and then (Ekind (E) = Ekind (Id)) + and then Ekind (E) = Ekind (Id) and then Type_Conformant (Id, E) then Entry_Name := E; -- 2.30.2