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;
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;
-- 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;
------------------------