From c94bbfbe57de7eccec1f3b2fe0da594014ac6088 Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Thu, 16 Apr 2020 11:03:49 +0200 Subject: [PATCH] [Ada] Cleanups in code related to static expressions 2020-06-18 Piotr Trojanek gcc/ada/ * checks.adb, sem_ch3.adb: Minor refactorings. * sem_eval.adb (Eval_Qualified_Expression): Fix reference to RM rule in comment; only set a local variable Hex in the branch where it is used. --- gcc/ada/checks.adb | 8 +++----- gcc/ada/sem_ch3.adb | 2 +- gcc/ada/sem_eval.adb | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index ad60a45273d..51b73f992a6 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -6814,9 +6814,9 @@ package body Checks is else declare - A_Idx : Node_Id := Empty; + A_Idx : Node_Id; A_Range : Node_Id; - Ind : Nat; + Ind : Pos; Num : List_Id; Range_N : Node_Id; @@ -6839,9 +6839,7 @@ package body Checks is if Nkind (A_Idx) = N_Range then A_Range := A_Idx; - elsif Nkind (A_Idx) = N_Identifier - or else Nkind (A_Idx) = N_Expanded_Name - then + elsif Nkind_In (A_Idx, N_Identifier, N_Expanded_Name) then A_Range := Scalar_Range (Entity (A_Idx)); else pragma Assert (Nkind (A_Idx) = N_Subtype_Indication); diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 78de3885a15..04060baa11e 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -4204,7 +4204,7 @@ package body Sem_Ch3 is Analyze (E); -- In case of errors detected in the analysis of the expression, - -- decorate it with the expected type to avoid cascaded errors + -- decorate it with the expected type to avoid cascaded errors. if No (Etype (E)) then Set_Etype (E, T); diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index 51f18ffd98d..66710a452fa 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -2704,7 +2704,7 @@ package body Sem_Eval is -- Similarly if the indexed component appears as the prefix of an -- attribute we don't want to evaluate it, because at least for - -- some cases of attributes we need the identify (e.g. Access, Size) + -- some cases of attributes we need the identify (e.g. Access, Size). elsif Nkind (Parent (N)) = N_Attribute_Reference then return; @@ -2868,7 +2868,7 @@ package body Sem_Eval is -- and misleading warnings. if (Nkind_In (Par, N_Case_Expression_Alternative, N_If_Expression) - or else Nkind (Parent (N)) not in N_Subexpr) + or else Nkind (Par) not in N_Subexpr) and then (not Nkind_In (Par, N_Case_Expression_Alternative, N_If_Expression) or else Comes_From_Source (N)) @@ -3205,7 +3205,7 @@ package body Sem_Eval is ------------------------------- -- A qualified expression is potentially static if its subtype mark denotes - -- a static subtype and its expression is potentially static (RM 4.9 (11)). + -- a static subtype and its expression is potentially static (RM 4.9 (10)). procedure Eval_Qualified_Expression (N : Node_Id) is Operand : constant Node_Id := Expression (N); @@ -3228,7 +3228,7 @@ package body Sem_Eval is then Check_Non_Static_Context (Operand); - -- If operand is known to raise constraint_error, set the flag on the + -- If operand is known to raise Constraint_Error, set the flag on the -- expression so it does not get optimized away. if Nkind (Operand) = N_Raise_Constraint_Error then @@ -3252,14 +3252,15 @@ package body Sem_Eval is return; end if; - -- Here we will fold, save Print_In_Hex indication - - Hex := Nkind (Operand) = N_Integer_Literal - and then Print_In_Hex (Operand); - -- Fold the result of qualification if Is_Discrete_Type (Target_Type) then + + -- Save Print_In_Hex indication + + Hex := Nkind (Operand) = N_Integer_Literal + and then Print_In_Hex (Operand); + Fold_Uint (N, Expr_Value (Operand), Stat); -- Preserve Print_In_Hex indication -- 2.30.2