The main part is the renaming of Freeze_Expr_Types to Freeze_Full_Expression
and Freeze_Expr_Types_Before to Freeze_Full_Expression_Before to reflect the
actual intent of the subprograms.

Tested on x86-64/Linux, applied on the mainline.


2026-09-22  Eric Botcazou  <[email protected]>

        * freeze.ads (Freeze_Entity): Move around.
        (Freeze_Before): Rename T parameter to E.
        (Freeze_Expression): Improve description.
        (Freeze_Expr_Types_Before): Rename to...
        (Freeze_Full_Expression_Before): ...this.
        * freeze.adb (Freeze_Expr_Types): Rename to...
        (Freeze_Full_Expression): ...this.
        (Freeze_Before): Rename T parameter to E and Pack variable to Scop.
        (Freeze_Entity): Adjust to above renaming.
        (Freeze_Expression): Likewise.
        (Freeze_Expr_Types_Before): Rename to...
        (Freeze_Full_Expression_Before): ...this.
        * contracts.adb (Analyze_Entry_Or_Subprogram_Contract): Adjust to
        above renaming.
        (Expand_Subprogram_Contract): Likewise.
        * sem_ch6.adb (Analyze_Expression_Function): Likewise.

-- 
Eric Botcazou
diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 0c75a24d395..fb781fd6ac3 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -755,7 +755,7 @@ package body Contracts is
                   if Freeze_Types
                     and then Present (Corresponding_Aspect (Prag))
                   then
-                     Freeze_Expr_Types_Before
+                     Freeze_Full_Expression_Before
                        (N      => Bod,
                         Expr   =>
                           Expression
@@ -3119,7 +3119,7 @@ package body Contracts is
                      if Freeze_T
                        and then Present (Corresponding_Aspect (Prag))
                      then
-                        Freeze_Expr_Types_Before
+                        Freeze_Full_Expression_Before
                           (N      => Body_Decl,
                            Expr   =>
                              Expression
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 4c516fe9667..634010e452f 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -149,14 +149,14 @@ package body Freeze is
    --  that if a foreign convention is specified, and no specific size
    --  is given, then the size must be at least Integer'Size.
 
-   procedure Freeze_Expr_Types
+   procedure Freeze_Full_Expression
      (Expr   : Node_Id;
       N      : Node_Id;
       Def_Id : Entity_Id;
       Result : in out List_Id;
       Before : Boolean := False;
       Typ    : Entity_Id := Empty);
-   --  Same as Freeze_Expr_Types_Before if Before is True, but appends the
+   --  Same as Freeze_Full_Expression_Before if Before is True, but appends the
    --  resulting list of nodes to Result if Before is False, modifying Result
    --  from No_List if necessary.
 
@@ -2746,16 +2746,12 @@ package body Freeze is
 
    procedure Freeze_Before
      (N                 : Node_Id;
-      T                 : Entity_Id;
+      E                 : Entity_Id;
       Do_Freeze_Profile : Boolean := True)
    is
-      --  Freeze T, then insert the generated Freeze nodes before the node N.
-      --  Flag Freeze_Profile is used when T is an overloadable entity, and
-      --  indicates whether its profile should be frozen at the same time.
-
       Freeze_Nodes : constant List_Id :=
-                       Freeze_Entity (T, N, Do_Freeze_Profile);
-      Pack         : constant Entity_Id := Scope (T);
+                       Freeze_Entity (E, N, Do_Freeze_Profile);
+      Scop         : constant Entity_Id := Scope (E);
 
    begin
       if Is_Non_Empty_List (Freeze_Nodes) then
@@ -2766,12 +2762,12 @@ package body Freeze is
          --  which may include generated subprograms such as predicate
          --  functions, etc.
 
-         if Is_Type (T) and then From_Nested_Package (T) then
-            Push_Scope (Pack);
-            Install_Visible_Declarations (Pack);
-            Install_Private_Declarations (Pack);
+         if Is_Type (E) and then From_Nested_Package (E) then
+            Push_Scope (Scop);
+            Install_Visible_Declarations (Scop);
+            Install_Private_Declarations (Scop);
             Insert_Actions (N, Freeze_Nodes);
-            End_Package_Scope (Pack);
+            End_Package_Scope (Scop);
 
          else
             Insert_Actions (N, Freeze_Nodes);
@@ -8274,7 +8270,7 @@ package body Freeze is
                      if Is_Expression_Function (Subp) then
                         Freeze_And_Append
                           (Subp, N, Result, Do_Freeze_Profile => False);
-                        Freeze_Expr_Types
+                        Freeze_Full_Expression
                           (Expr   => Expression_Of_Expression_Function (Subp),
                            N      => N,
                            Def_Id => Subp,
@@ -9227,7 +9223,7 @@ package body Freeze is
          --  Freeze types in expression function (RM 13.14(10.1, 10.2, 10.3))
 
          if Is_Expression_Function (Nam) then
-            Freeze_Expr_Types_Before
+            Freeze_Full_Expression_Before
               (N      => P,
                Expr   => Expression_Of_Expression_Function (Nam),
                Def_Id => Nam);
@@ -9239,11 +9235,11 @@ package body Freeze is
       In_Spec_Expression := In_Spec_Exp;
    end Freeze_Expression;
 
-   -----------------------
-   -- Freeze_Expr_Types --
-   -----------------------
+   ----------------------------
+   -- Freeze_Full_Expression --
+   ----------------------------
 
-   procedure Freeze_Expr_Types
+   procedure Freeze_Full_Expression
      (Expr   : Node_Id;
       N      : Node_Id;
       Def_Id : Entity_Id;
@@ -9526,7 +9522,7 @@ package body Freeze is
 
       procedure Freeze_References is new Traverse_Proc (Freeze_Type_Refs);
 
-   --  Start of processing for Freeze_Expr_Types
+   --  Start of processing for Freeze_Full_Expression
 
    begin
       --  Preanalyze a duplicate of the expression to have available the
@@ -9577,13 +9573,13 @@ package body Freeze is
       else
          Freeze_References (Expr);
       end if;
-   end Freeze_Expr_Types;
+   end Freeze_Full_Expression;
 
-   ------------------------------
-   -- Freeze_Expr_Types_Before --
-   ------------------------------
+   -----------------------------------
+   -- Freeze_Full_Expression_Before --
+   -----------------------------------
 
-   procedure Freeze_Expr_Types_Before
+   procedure Freeze_Full_Expression_Before
      (N      : Node_Id;
       Expr   : Node_Id;
       Def_Id : Entity_Id;
@@ -9592,14 +9588,14 @@ package body Freeze is
       Dummy : List_Id := No_List;
 
    begin
-      Freeze_Expr_Types
+      Freeze_Full_Expression
         (Expr   => Expr,
          N      => N,
          Def_Id => Def_Id,
          Result => Dummy,
          Before => True,
          Typ    => Typ);
-   end Freeze_Expr_Types_Before;
+   end Freeze_Full_Expression_Before;
 
    -----------------------------
    -- Freeze_Fixed_Point_Type --
diff --git a/gcc/ada/freeze.ads b/gcc/ada/freeze.ads
index 995ff04187b..7e5d31f92b1 100644
--- a/gcc/ada/freeze.ads
+++ b/gcc/ada/freeze.ads
@@ -96,7 +96,7 @@ package Freeze is
 
    --    Objects with dynamic address clauses
    --
-   --      These have a delayed freeze. Gigi will generate code to evaluate
+   --      These have delayed freezing. Gigi will generate code to evaluate
    --      the initialization expression if present and store it in a temp.
    --      The actual object is created at the point of the freeze, and if
    --      necessary initialized by copying the value of this temporary.
@@ -183,19 +183,6 @@ package Freeze is
    --  If Initialization_Statements (E) is an N_Compound_Statement, insert its
    --  actions at the appropriate point and clear the attribute.
 
-   function Freeze_Entity
-     (E                 : Entity_Id;
-      N                 : Node_Id;
-      Do_Freeze_Profile : Boolean := True) return List_Id;
-   --  Freeze an entity, and return Freeze nodes, to be inserted at the point
-   --  of call. N is a node whose source location corresponds to the freeze
-   --  point. This is used in placing warning messages in the situation where
-   --  it appears that a type has been frozen too early, e.g. when a primitive
-   --  operation is declared after the freezing point of its tagged type.
-   --  Returns No_List if no freeze nodes needed. Parameter Do_Freeze_Profile
-   --  is used when E is a subprogram, and determines whether the profile of
-   --  the subprogram should be frozen as well.
-
    procedure Freeze_All (From : Entity_Id; After : in out Node_Id);
    --  Before a non-instance body, or at the end of a declarative part,
    --  freeze all entities therein that are not yet frozen. Calls itself
@@ -212,28 +199,44 @@ package Freeze is
 
    procedure Freeze_Before
      (N                 : Node_Id;
-      T                 : Entity_Id;
+      E                 : Entity_Id;
       Do_Freeze_Profile : Boolean := True);
-   --  Freeze T then Insert the generated Freeze nodes before the node N. Flag
-   --  Do_Freeze_Profile is used when T is an overloadable entity and indicates
-   --  whether its profile should be frozen at the same time.
+   --  Freeze entity E and Insert the generated Freeze nodes before the node N.
+   --  The Flag Do_Freeze_Profile is used when T is an overloadable entity and
+   --  indicates whether its profile should be frozen at the same time.
+
+   function Freeze_Entity
+     (E                 : Entity_Id;
+      N                 : Node_Id;
+      Do_Freeze_Profile : Boolean := True) return List_Id;
+   --  Freeze entity E, and return Freeze nodes, to be inserted at the point
+   --  of call. N is a node whose source location corresponds to the freeze
+   --  point. This is used in placing warning messages in the situation where
+   --  it appears that a type has been frozen too early, e.g. when a primitive
+   --  operation is declared after the freezing point of its tagged type.
+   --  Returns No_List if no freeze nodes needed. Parameter Do_Freeze_Profile
+   --  is used when E is a subprogram, and determines whether the profile of
+   --  the subprogram should be frozen as well.
 
    procedure Freeze_Expression (N : Node_Id);
-   --  Freezes the required entities when the Expression N causes freezing.
+   --  Freezes the required entities when subexpression N causes freezing.
    --  The node N here is either a subexpression node (a "real" expression)
    --  or a subtype mark, or a subtype indication. The latter two cases are
    --  not really expressions, but they can appear within expressions and
-   --  so need to be similarly treated. Freeze_Expression takes care of
-   --  determining the proper insertion point for generated freeze actions.
+   --  so need to be similarly treated. Freeze_Expression must be invoked
+   --  on every subexpression along the normal processing of an expression,
+   --  and will take care of determining the proper insertion point of the
+   --  generated freeze actions.
 
-   procedure Freeze_Expr_Types_Before
+   procedure Freeze_Full_Expression_Before
      (N      : Node_Id;
       Expr   : Node_Id;
       Def_Id : Entity_Id;
       Typ    : Entity_Id := Empty);
-   --  This procedure freezes before N all the types referenced in Expr,
-   --  which is either the expression of the expression function Def_Id,
-   --  or the expression in a pre/post aspect that applies to Def_Id.
+   --  Freezes before N all the required entities when expression Expr causes
+   --  freezing, which is either the expression of the expression function
+   --  Def_Id, or the expression in a pre/post aspect that applies to Def_Id.
+   --  Freeze_Full_Expression_Before must be invoked once for an expression.
 
    --  If Typ is present, it is the type used to preanalyze and resolve a
    --  copy of Expr; if it is not, Expr is assumed to be already analyzed.
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index c4b09a22788..130cbcc7c97 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -443,7 +443,7 @@ package body Sem_Ch6 is
             --  with the function body.
 
             Ghost_Context_Checks_Disabled := True;
-            Freeze_Expr_Types_Before
+            Freeze_Full_Expression_Before
               (N      => N,
                Expr   => Expr,
                Def_Id => Def_Id,

Reply via email to