]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Move standard subtype declarations generation
authorRonan Desplanques <desplanques@adacore.com>
Wed, 12 Feb 2025 09:37:30 +0000 (10:37 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 6 Jun 2025 08:37:03 +0000 (10:37 +0200)
Before this patch, the subtype declarations for Standard.Natural and
Standard.Positive were created before the entity for Standard.Integer
was complete. In preparation of a future change that will make it
impossible to call Etype on an incomplete node, this patch delays the
creation of these subtype declarations. It doesn't affect the behavior
of the compiler.

gcc/ada/ChangeLog:

* cstand.adb (Create_Standard): Delay declaration generation for
Natural and Positive.

gcc/ada/cstand.adb

index 41b0fec157fc51dc886890c75563e9da12de16a7..14c7496fa619f75c1a3878c58c779c28fc72ab60 100644 (file)
@@ -612,25 +612,14 @@ package body CStand is
       Set_Is_Pure (Standard_Standard);
       Set_Is_Compilation_Unit (Standard_Standard);
 
-      --  Create type/subtype declaration nodes for standard types
+      --  Create type declaration nodes for standard types
 
       for S in S_Types loop
-
-         --  Subtype declaration case
-
-         if S = S_Natural or else S = S_Positive then
-            Decl := New_Node (N_Subtype_Declaration, Stloc);
-            Set_Subtype_Indication (Decl,
-              New_Occurrence_Of (Standard_Integer, Stloc));
-
-         --  Full type declaration case
-
-         else
+         if S not in S_Natural | S_Positive then
             Decl := New_Node (N_Full_Type_Declaration, Stloc);
+            Set_Defining_Identifier (Decl, Standard_Entity (S));
+            Append (Decl, Decl_S);
          end if;
-
-         Set_Defining_Identifier (Decl, Standard_Entity (S));
-         Append (Decl, Decl_S);
       end loop;
 
       Create_Back_End_Float_Types;
@@ -1021,6 +1010,14 @@ package body CStand is
         Hb  => Intval (High_Bound (Scalar_Range (Standard_Integer))));
       Set_Is_Constrained (Standard_Natural);
 
+      Append_To
+        (Decl_S,
+         Make_Subtype_Declaration
+           (Stloc,
+            Standard_Natural,
+            Subtype_Indication =>
+              New_Occurrence_Of (Standard_Integer, Stloc)));
+
       --  Setup entity for Positive
 
       Mutate_Ekind (Standard_Positive, E_Signed_Integer_Subtype);
@@ -1038,6 +1035,14 @@ package body CStand is
          Hb  => Intval (High_Bound (Scalar_Range (Standard_Integer))));
       Set_Is_Constrained   (Standard_Positive);
 
+      Append_To
+        (Decl_S,
+         Make_Subtype_Declaration
+           (Stloc,
+            Standard_Positive,
+            Subtype_Indication =>
+              New_Occurrence_Of (Standard_Integer, Stloc)));
+
       --  Create declaration for package ASCII
 
       Decl := New_Node (N_Package_Declaration, Stloc);