Reason => PE_Accessibility_Check_Failed));
end Check_Against_Result_Level;
- -- Local Data
-
- New_Copy_Of_Exp : Node_Id := Empty;
-
-- Start of processing for Expand_Simple_Function_Return
begin
- -- For static expression functions, the expression of the function
- -- needs to be available in a form that can be replicated later for
- -- calls, but rewriting of the return expression in the body created
- -- for expression functions will cause the original expression to no
- -- longer be properly copyable via New_Copy_Tree, because the Parent
- -- fields of the nodes will now point to nodes in the rewritten tree,
- -- and New_Copy_Tree won't copy the deeper nodes of the original tree.
- -- So we work around that by making a copy of the expression tree
- -- before any rewriting occurs, and replacing the original expression
- -- tree with this copy (see the end of this procedure). We also reset
- -- the Analyzed flags on the nodes in the tree copy to ensure that
- -- later copies of the tree will be fully reanalyzed. This copying
- -- is of course rather inelegant, to say the least, and it would be
- -- nice if there were a way to avoid it. ???
-
- if Is_Static_Expression_Function (Scope_Id) then
- New_Copy_Of_Exp := New_Copy_Tree (Exp);
- Reset_Analyzed_Flags (New_Copy_Of_Exp);
- end if;
-
if Is_Class_Wide_Type (R_Type)
and then not Is_Class_Wide_Type (Exp_Typ)
and then Nkind (Exp) /= N_Type_Conversion
Analyze_And_Resolve (Exp);
end if;
- -- If a new copy of a static expression function's expression was made
- -- (see the beginning of this procedure's statement part), then we now
- -- replace the original expression tree with the copy and also change
- -- the Original_Node field of the rewritten expression to point to that
- -- copy. It would be nice to find a way to avoid this???
-
- if Present (New_Copy_Of_Exp) then
- Set_Expression
- (Original_Node (Subprogram_Spec (Scope_Id)), New_Copy_Of_Exp);
-
- if Exp /= Original_Node (Exp) then
- Set_Original_Node (Exp, New_Copy_Of_Exp);
- end if;
- end if;
-
-- Ada 2020 (AI12-0279)
if Has_Yield_Aspect (Scope_Id)
Establish_Actual_Mapping_For_Inlined_Call (N, Subp, Decls, Func_Expr);
+ -- 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));
+
Insert_Actions (N, Decls);
-- Now substitute actuals for their corresponding formal references
Set_Checking_Potentially_Static_Expression (False);
end;
end if;
+
+ -- We also make an additional copy of the expression and
+ -- replace the expression of the expression function with
+ -- this copy, because the currently present expression is
+ -- now associated with the body created for the static
+ -- expression function, which will later be analyzed and
+ -- possibly rewritten, and we need to have the separate
+ -- unanalyzed copy available for use with later static
+ -- calls.
+
+ Set_Expression
+ (Original_Node (Subprogram_Spec (Def_Id)),
+ New_Copy_Tree (Expr));
end if;
end if;
end;