]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Refactor Inline_Static_Function_Call
authorViljar Indus <indus@adacore.com>
Mon, 9 Mar 2026 14:33:19 +0000 (16:33 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 29 May 2026 08:49:47 +0000 (10:49 +0200)
gcc/ada/ChangeLog:

* inline.adb (Inline_Static_Function_Call): Reduce source code nesting.
* inline.ads (Inline_Static_Function_Call): Likewise.

gcc/ada/inline.adb
gcc/ada/inline.ads

index 94ba3b479fab650ffd7ad9825125d61af31de381..7d7eff6c91b16f431752f417adff5fbef8bd3449 100644 (file)
@@ -46,7 +46,6 @@ with Sem_Ch10;       use Sem_Ch10;
 with Sem_Ch12;       use Sem_Ch12;
 with Sem_Prag;       use Sem_Prag;
 with Sem_Res;        use Sem_Res;
-with Sem_Util;       use Sem_Util;
 with Sinfo.Nodes;    use Sinfo.Nodes;
 with Sinfo.Utils;    use Sinfo.Utils;
 with Sinput;         use Sinput;
@@ -4716,6 +4715,10 @@ package body Inline is
 
    procedure Inline_Static_Function_Call (N : Node_Id; Subp : Entity_Id) is
 
+      Decls        : constant List_Id := New_List;
+      Func_Expr    : constant Node_Id :=
+        Expression_Of_Expression_Function (Subp);
+      Expr_Copy    : constant Node_Id := New_Copy_Tree (Func_Expr);
       S_Adjustment : Sloc_Adjustment;
 
       function Adjust_Sloc (Nod : Node_Id) return Traverse_Result;
@@ -4776,70 +4779,64 @@ package body Inline is
    --  Start of processing for Inline_Static_Function_Call
 
    begin
-      pragma Assert (Is_Static_Function_Call (N));
+      --  Register the call in the list of inlined calls
 
-      declare
-         Decls     : constant List_Id := New_List;
-         Func_Expr : constant Node_Id :=
-                       Expression_Of_Expression_Function (Subp);
-         Expr_Copy : constant Node_Id := New_Copy_Tree (Func_Expr);
+      Append_New_Elmt (N, To => Inlined_Calls);
 
-      begin
-         --  Create a mapping from formals to actuals, also creating temps in
-         --  Decls, when needed, to hold the actuals.
+      --  Create a mapping from formals to actuals, also creating temps in
+      --  Decls, when needed, to hold the actuals.
 
-         Establish_Actual_Mapping_For_Inlined_Call (N, Subp, Decls, Func_Expr);
+      Establish_Actual_Mapping_For_Inlined_Call (N, Subp, Decls, Func_Expr);
 
-         --  Calculate the Adjustment for the inlined call
+      --  Calculate the Adjustment for the inlined call
 
-         Create_Instantiation_Source
-           (N, Subp, S_Adjustment, Inlined_Body => True);
+      Create_Instantiation_Source
+        (N, Subp, S_Adjustment, Inlined_Body => True);
 
-         --  Ensure that the copy has the same parent as the call (this seems
-         --  to matter when GNATprove_Mode is set and there are nested static
-         --  calls; prevents blowups in Insert_Actions, though it's not clear
-         --  exactly why this is needed???).
+      --  Ensure that the copy has the same parent as the call (this seems
+      --  to matter when GNATprove_Mode is set and there are nested static
+      --  calls; prevents blowups in Insert_Actions, though it's not clear
+      --  exactly why this is needed???).
 
-         Set_Parent (Expr_Copy, Parent (N));
+      Set_Parent (Expr_Copy, Parent (N));
 
-         Insert_Actions (N, Decls);
+      Insert_Actions (N, Decls);
 
-         --  Now substitute actuals for their corresponding formal references
-         --  within the expression.
+      --  Now substitute actuals for their corresponding formal references
+      --  within the expression.
 
-         Replace_Formals (Expr_Copy);
+      Replace_Formals (Expr_Copy);
 
-         Adjust_Slocs (Expr_Copy);
+      Adjust_Slocs (Expr_Copy);
 
-         --  Apply a qualified expression with the function's result subtype,
-         --  to ensure that we check the expression against any constraint
-         --  or predicate, which will cause the call to be illegal if the
-         --  folded expression doesn't satisfy them. (The predicate case
-         --  might not get checked if the subtype hasn't been frozen yet,
-         --  which can happen if this static expression happens to be what
-         --  causes the freezing, because Has_Static_Predicate doesn't get
-         --  set on the subtype until it's frozen and Build_Predicates is
-         --  called. It's not clear how to address this case. ???)
+      --  Apply a qualified expression with the function's result subtype,
+      --  to ensure that we check the expression against any constraint
+      --  or predicate, which will cause the call to be illegal if the
+      --  folded expression doesn't satisfy them. (The predicate case
+      --  might not get checked if the subtype hasn't been frozen yet,
+      --  which can happen if this static expression happens to be what
+      --  causes the freezing, because Has_Static_Predicate doesn't get
+      --  set on the subtype until it's frozen and Build_Predicates is
+      --  called. It's not clear how to address this case. ???)
 
-         Rewrite (Expr_Copy,
-           Make_Qualified_Expression (Sloc (Expr_Copy),
-             Subtype_Mark =>
-               New_Occurrence_Of (Etype (N), Sloc (Expr_Copy)),
-             Expression =>
-               Relocate_Node (Expr_Copy)));
+      Rewrite
+        (Expr_Copy,
+         Make_Qualified_Expression
+           (Sloc         => Sloc (Expr_Copy),
+            Subtype_Mark => New_Occurrence_Of (Etype (N), Sloc (Expr_Copy)),
+            Expression   => Relocate_Node (Expr_Copy)));
 
-         Set_Etype (Expr_Copy, Etype (N));
+      Set_Etype (Expr_Copy, Etype (N));
 
-         Analyze_And_Resolve (Expr_Copy, Etype (N));
+      Analyze_And_Resolve (Expr_Copy, Etype (N));
 
-         --  Finally rewrite the function call as the folded static result
+      --  Finally rewrite the function call as the folded static result
 
-         Rewrite (N, Expr_Copy);
+      Rewrite (N, Expr_Copy);
 
-         --  Cleanup mapping between formals and actuals for other expansions
+      --  Cleanup mapping between formals and actuals for other expansions
 
-         Reset_Actual_Mapping_For_Inlined_Call (Subp);
-      end;
+      Reset_Actual_Mapping_For_Inlined_Call (Subp);
    end Inline_Static_Function_Call;
 
    ------------------------
index 4b6814212381ad36859a275255120694099ce12a..bc21838b4321ce05d93b31e700c0261e1c229b67 100644 (file)
 --  Inline_Always subprograms, but there are fewer restrictions on the source
 --  of subprograms.
 
-with Opt;    use Opt;
-with Sem;    use Sem;
-with Types;  use Types;
-with Warnsw; use Warnsw;
+with Opt;      use Opt;
+with Sem;      use Sem;
+with Sem_Util; use Sem_Util;
+with Types;    use Types;
+with Warnsw;   use Warnsw;
 
 package Inline is
 
@@ -248,8 +249,8 @@ package Inline is
    --  Check a list of statements, Stats, that make inlining of Subp not
    --  worthwhile, including any tasking statement, nested at any level.
 
-   procedure Inline_Static_Function_Call
-     (N : Node_Id; Subp : Entity_Id);
+   procedure Inline_Static_Function_Call (N : Node_Id; Subp : Entity_Id)
+   with Pre => Is_Static_Function_Call (N);
    --  Evaluate static call to a static function Subp, substituting actuals in
    --  place of references to their corresponding formals and rewriting the
    --  call N as a fully folded and static result expression.