]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Factorize some duplicate code
authorRonan Desplanques <desplanques@adacore.com>
Thu, 27 Mar 2025 11:13:20 +0000 (12:13 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 10 Jun 2025 07:32:09 +0000 (09:32 +0200)
Process_Subtype can be passed either a subtype indication or a subtype
mark. Before this patch, it branched directly depending on the kind of
the argument, but there actually was processing common to the two
branches like resolving the subtype mark. This patch factorizes this
common processing out of the if statement.

gcc/ada/ChangeLog:

* sem_ch3.adb (Process_Subtype): Factorize code.

gcc/ada/sem_ch3.adb

index ff5d0bab99f26636fef7d4ebc937e8b993702425..75901bb8eff0214abc2bd547805e9541de465287 100644 (file)
@@ -22801,6 +22801,7 @@ package body Sem_Ch3 is
       --  Local variables
 
       P               : constant Node_Id := Parent (S);
+      Mark            : Node_Id;
       Def_Id          : Entity_Id;
       Error_Node      : Node_Id;
       Full_View_Id    : Entity_Id;
@@ -22809,22 +22810,28 @@ package body Sem_Ch3 is
    --  Start of processing for Process_Subtype
 
    begin
-      --  Case of no constraints present
+      if Nkind (S) = N_Subtype_Indication then
+         Mark := Subtype_Mark (S);
+      else
+         Mark := S;
+      end if;
 
-      if Nkind (S) /= N_Subtype_Indication then
-         Find_Type (S);
+      Find_Type (Mark);
 
-         --  No way to proceed if the subtype indication is malformed. This
-         --  will happen for example when the subtype indication in an object
-         --  declaration is missing altogether and the expression is analyzed
-         --  as if it were that indication.
+      --  No way to proceed if the subtype indication is malformed. This will
+      --  happen for example when the subtype indication in an object
+      --  declaration is missing altogether and the expression is analyzed as
+      --  if it were that indication.
 
-         if not Is_Entity_Name (S) then
-            return Any_Type;
-         end if;
+      if not Is_Entity_Name (Mark) then
+         return Any_Type;
+      end if;
+
+      Check_Incomplete (Mark);
 
-         Check_Incomplete (S);
+      --  Case of no constraints present
 
+      if Nkind (S) /= N_Subtype_Indication then
          if Excludes_Null then
             --  Create an Itype that is a duplicate of Entity (S) but with the
             --  null-exclusion attribute.
@@ -22886,11 +22893,7 @@ package body Sem_Ch3 is
       --  node (this node is created only if constraints are present).
 
       else
-         Find_Type (Subtype_Mark (S));
-
-         Check_Incomplete (Subtype_Mark (S));
-
-         Subtype_Mark_Id := Entity (Subtype_Mark (S));
+         Subtype_Mark_Id := Entity (Mark);
 
          --  Explicit subtype declaration case