]> gcc.gnu.org Git - gcc.git/commitdiff
ada: Refactor common code for dynamic and static class-wide preconditions
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 1 Dec 2023 17:47:01 +0000 (18:47 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 10 Jun 2024 09:03:58 +0000 (11:03 +0200)
Code cleanup; semantics is unaffected.

gcc/ada/

* exp_ch6.adb (Install_Class_Preconditions_Check): Refactor
common code for checking if precondition fails, since the
difference is only in raising an exception or calling the
Raise_Assert_Failure procedure.

gcc/ada/exp_ch6.adb

index e43389132ae43727497379179b4e435560b8f064..b5c5865242ddf79c4538f5bde41712584f5faded 100644 (file)
@@ -7868,6 +7868,7 @@ package body Exp_Ch6 is
                         Present (Controlling_Argument (Call_Node));
       Class_Subp    : Entity_Id;
       Cond          : Node_Id;
+      Fail          : Node_Id;
       Subp          : Entity_Id;
 
    --  Start of processing for Install_Class_Preconditions_Check
@@ -7913,30 +7914,29 @@ package body Exp_Ch6 is
       end if;
 
       if Exception_Locations_Suppressed then
-         Insert_Action (Call_Node,
-           Make_If_Statement (Loc,
-             Condition       => Make_Op_Not (Loc, Cond),
-             Then_Statements => New_List (
-               Make_Raise_Statement (Loc,
-                 Name =>
-                   New_Occurrence_Of
-                     (RTE (RE_Assert_Failure), Loc)))));
+         Fail :=
+           Make_Raise_Statement (Loc,
+             Name =>
+               New_Occurrence_Of
+                 (RTE (RE_Assert_Failure), Loc));
 
       --  Failed check with message indicating the failed precondition and the
       --  call that caused it.
 
       else
-         Insert_Action (Call_Node,
-           Make_If_Statement (Loc,
-             Condition       => Make_Op_Not (Loc, Cond),
-             Then_Statements => New_List (
-               Make_Procedure_Call_Statement (Loc,
-                 Name                   =>
-                   New_Occurrence_Of
-                     (RTE (RE_Raise_Assert_Failure), Loc),
-                 Parameter_Associations =>
-                   New_List (Build_Error_Message (Subp))))));
+         Fail :=
+           Make_Procedure_Call_Statement (Loc,
+             Name                   =>
+               New_Occurrence_Of
+                 (RTE (RE_Raise_Assert_Failure), Loc),
+             Parameter_Associations =>
+               New_List (Build_Error_Message (Subp)));
       end if;
+
+      Insert_Action (Call_Node,
+        Make_If_Statement (Loc,
+          Condition       => Make_Op_Not (Loc, Cond),
+          Then_Statements => New_List (Fail)));
    end Install_Class_Preconditions_Check;
 
    ------------------------------
This page took 0.071444 seconds and 5 git commands to generate.