aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2023-04-18 19:13:38 +0200
committerMarc Poulhiès <poulhies@adacore.com>2023-06-13 09:31:42 +0200
commit109307ebe37301412de26114cc466099ba34088e (patch)
tree3ccb4ff33e4108338c022ced1bcf638faf53685e /gcc/ada
parentfbf4140df117d28428e03a3f3c986787609d32b6 (diff)
downloadgcc-109307ebe37301412de26114cc466099ba34088e.zip
gcc-109307ebe37301412de26114cc466099ba34088e.tar.gz
gcc-109307ebe37301412de26114cc466099ba34088e.tar.bz2
ada: Cleanup expansion of locally handled exception handlers
Code cleanup related to handling exceptions in GNATprove; semantics is unaffected. gcc/ada/ * exp_ch11.ads (Find_Local_Handler): Fix typo in comment. * exp_ch11.adb (Find_Local_Handler): Remove redundant check for the Exception_Handler list being present; use membership test to eliminate local object LCN; fold nested IF statements. Remove useless ELSIF condition.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/exp_ch11.adb124
-rw-r--r--gcc/ada/exp_ch11.ads2
2 files changed, 55 insertions, 71 deletions
diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
index 753412e..da02eb9 100644
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -1803,95 +1803,79 @@ package body Exp_Ch11 is
-- Test for handled sequence of statements with at least one
-- exception handler which might be the one we are looking for.
- elsif Nkind (P) = N_Handled_Sequence_Of_Statements
- and then Present (Exception_Handlers (P))
- then
- -- Before we proceed we need to check if the node N is covered
- -- by the statement part of P rather than one of its exception
- -- handlers (an exception handler obviously does not cover its
- -- own statements).
-
- -- This test is more delicate than might be thought. It is not
- -- just a matter of checking the Statements (P), because the node
- -- might be waiting to be wrapped in a transient scope, in which
- -- case it will end up in the block statements, even though it
- -- is not there now.
-
- if Is_List_Member (N) then
- declare
- LCN : constant List_Id := List_Containing (N);
+ -- We need to check if the node N is covered by the statement part of
+ -- P rather than one of its exception handlers (an exception handler
+ -- obviously does not cover its own statements).
- begin
- if LCN = Statements (P)
- or else
- LCN = SSE.Actions_To_Be_Wrapped (Before)
- or else
- LCN = SSE.Actions_To_Be_Wrapped (After)
- or else
- LCN = SSE.Actions_To_Be_Wrapped (Cleanup)
- then
- -- Loop through exception handlers
+ -- This test is more delicate than might be thought. It is not just
+ -- a matter of checking the Statements (P), because the node might be
+ -- waiting to be wrapped in a transient scope, in which case it will
+ -- end up in the block statements, even though it is not there now.
- H := First (Exception_Handlers (P));
- while Present (H) loop
+ elsif Nkind (P) = N_Handled_Sequence_Of_Statements
+ and then Is_List_Member (N)
+ and then List_Containing (N) in Statements (P)
+ | SSE.Actions_To_Be_Wrapped (Before)
+ | SSE.Actions_To_Be_Wrapped (After)
+ | SSE.Actions_To_Be_Wrapped (Cleanup)
+ then
+ -- Loop through exception handlers
- -- Guard against other constructs appearing in the
- -- list of exception handlers.
+ H := First (Exception_Handlers (P));
+ while Present (H) loop
- if Nkind (H) = N_Exception_Handler then
+ -- Guard against other constructs appearing in the list of
+ -- exception handlers.
- -- Loop through choices in one handler
+ if Nkind (H) = N_Exception_Handler then
- C := First (Exception_Choices (H));
- while Present (C) loop
+ -- Loop through choices in one handler
- -- Deal with others case
+ C := First (Exception_Choices (H));
+ while Present (C) loop
- if Nkind (C) = N_Others_Choice then
+ -- Deal with others case
- -- Matching others handler, but we need
- -- to ensure there is no choice parameter.
- -- If there is, then we don't have a local
- -- handler after all (since we do not allow
- -- choice parameters for local handlers).
+ if Nkind (C) = N_Others_Choice then
- if No (Choice_Parameter (H)) then
- return H;
- else
- return Empty;
- end if;
+ -- Matching others handler, but we need to ensure
+ -- there is no choice parameter. If there is, then we
+ -- don't have a local handler after all (since we do
+ -- not allow choice parameters for local handlers).
- -- If not others must be entity name
+ if No (Choice_Parameter (H)) then
+ return H;
+ else
+ return Empty;
+ end if;
- elsif Nkind (C) /= N_Others_Choice then
- pragma Assert (Is_Entity_Name (C));
- pragma Assert (Present (Entity (C)));
+ -- If not others must be entity name
- -- Get exception being handled, dealing with
- -- renaming.
+ else
+ pragma Assert (Is_Entity_Name (C));
+ pragma Assert (Present (Entity (C)));
- EHandle := Get_Renamed_Entity (Entity (C));
+ -- Get exception being handled, dealing with renaming
- -- If match, then check choice parameter
+ EHandle := Get_Renamed_Entity (Entity (C));
- if ERaise = EHandle then
- if No (Choice_Parameter (H)) then
- return H;
- else
- return Empty;
- end if;
- end if;
- end if;
+ -- If match, then check choice parameter
- Next (C);
- end loop;
+ if ERaise = EHandle then
+ if No (Choice_Parameter (H)) then
+ return H;
+ else
+ return Empty;
+ end if;
end if;
+ end if;
- Next (H);
- end loop;
- end if;
- end;
- end if;
+ Next (C);
+ end loop;
+ end if;
+
+ Next (H);
+ end loop;
end if;
N := P;
diff --git a/gcc/ada/exp_ch11.ads b/gcc/ada/exp_ch11.ads
index 483c759..8d5b998 100644
--- a/gcc/ada/exp_ch11.ads
+++ b/gcc/ada/exp_ch11.ads
@@ -59,7 +59,7 @@ package Exp_Ch11 is
(Ename : Entity_Id;
Nod : Node_Id) return Node_Id;
-- This function searches for a local exception handler that will handle
- -- the exception named by Ename. If such a local hander exists, then the
+ -- the exception named by Ename. If such a local handler exists, then the
-- corresponding N_Exception_Handler is returned. If no such handler is
-- found then Empty is returned. In order to match and return True, the
-- handler may not have a choice parameter specification. Nod is the raise