]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Tech debt: Remove exception handling from aspects
authorBob Duff <duff@adacore.com>
Sun, 1 Feb 2026 17:47:23 +0000 (12:47 -0500)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 26 May 2026 08:38:19 +0000 (10:38 +0200)
Remove the Aspect_Exit exception and related code.
The big hammer of exceptions is not needed here,
and it gets in the way of future refactoring.
Some comments were slightly wrong; remove them instead of fixing
them.

gcc/ada/ChangeLog:

* sem_ch13.adb (Analyze_One_Aspect): Remove the exception
declaration, raises, and handler. Inline the code in
Check_Expr_Is_OK_Static_Expression, which was called only once.

gcc/ada/sem_ch13.adb

index eb4f05b20719a89a74c9e3a96d26313dd1858d6f..9d481171054afa5cf6b1d35a9cd8d90ff7e37d59 100644 (file)
@@ -2081,13 +2081,6 @@ package body Sem_Ch13 is
       Aspect := First (L);
       Aspect_Loop : while Present (Aspect) loop
          Analyze_One_Aspect : declare
-
-            Aspect_Exit : exception;
-            --  This exception is used to exit aspect processing completely. It
-            --  is used when an error is detected, and no further processing is
-            --  required. It is also used if an earlier error has left the tree
-            --  in a state where the aspect should not be processed.
-
             Expr : constant Node_Id    := Expression (Aspect);
             Id   : constant Node_Id    := Identifier (Aspect);
             Loc  : constant Source_Ptr := Sloc (Aspect);
@@ -2148,17 +2141,6 @@ package body Sem_Ch13 is
             --  object has been initialized and therefore shall not
             --  reference that object.
 
-            procedure Check_Expr_Is_OK_Static_Expression
-              (Expr : Node_Id;
-               Typ  : Entity_Id := Empty);
-            --  Check the specified expression Expr to make sure that it is a
-            --  static expression of the given type (i.e. it will be analyzed
-            --  and resolved using this type, which can be any valid argument
-            --  to Resolve, e.g. Any_Integer is OK). If not, give an error
-            --  and raise Aspect_Exit. If Typ is left Empty, then any static
-            --  expression is allowed. Includes checking that the expression
-            --  does not raise Constraint_Error.
-
             procedure Convert_Aspect_With_Assertion_Levels (Aspect : Node_Id);
             --  If an Aspect is using an association with an Assertion_Level
             --  analyze the aspect with the level and convert it into an aspect
@@ -3389,29 +3371,6 @@ package body Sem_Ch13 is
                Check_Tree_For_Bad_Reference (Expr);
             end Check_Constructor_Initialization_Expression;
 
-            ----------------------------------------
-            -- Check_Expr_Is_OK_Static_Expression --
-            ----------------------------------------
-
-            procedure Check_Expr_Is_OK_Static_Expression
-              (Expr : Node_Id; Typ : Entity_Id := Empty) is
-            begin
-               case Is_OK_Static_Expression_Of_Type (Expr, Typ) is
-                  when Static =>
-                     null;
-
-                  when Not_Static =>
-                     Error_Msg_Name_1 := Nam;
-                     Flag_Non_Static_Expr
-                       ("entity for aspect% must be a static expression!",
-                        Expr);
-                     raise Aspect_Exit;
-
-                  when Invalid =>
-                     raise Aspect_Exit;
-               end case;
-            end Check_Expr_Is_OK_Static_Expression;
-
             ------------------------------------------
             -- Convert_Aspect_With_Assertion_Levels --
             ------------------------------------------
@@ -5623,10 +5582,17 @@ package body Sem_Ch13 is
                            Aspect);
                      end if;
 
-                     --  Resolve the expression to a boolean
+                     --  Resolve the expression to a boolean, and check
+                     --  staticness.
 
-                     if Present (Expr) then
-                        Check_Expr_Is_OK_Static_Expression (Expr, Any_Boolean);
+                     if Present (Expr) and then
+                       Is_OK_Static_Expression_Of_Type (Expr, Any_Boolean) =
+                         Not_Static
+                     then
+                        Error_Msg_Name_1 := Nam;
+                        Flag_Non_Static_Expr
+                          ("entity for aspect% must be a static expression!",
+                           Expr); -- why "entity"???
                      end if;
 
                      --  Record the No_Task_Parts aspects as a rep item so it
@@ -6071,9 +6037,6 @@ package body Sem_Ch13 is
                   end loop;
                end;
             end if;
-
-         exception
-            when Aspect_Exit => null;
          end Analyze_One_Aspect;
 
          Next (Aspect);