+2015-10-23 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch6.adb (Check_Missing_Return): Do not report a missing
+ return statement on a function body constructed to complete a
+ package body for a premature instantiation.
+
+2015-10-23 Ed Schonberg <schonberg@adacore.com>
+
+ * exp_ch6.adb (Build_Procedure_Body_Form): Replace body of
+ original function with that of generated procedure, to simplify
+ processing and avoid scoping problems with local declarations.
+ (Rewrite_Function_Call_For_C): Handle properly the case of a
+ parameterless function.
+
2015-10-23 Hristian Kirtchev <kirtchev@adacore.com>
* a-exextr.adb, sem_ch6.adb, sem_ch13.adb: Minor reformatting.
procedure Build_Procedure_Body_Form (Func_Id : Entity_Id);
-- Create a procedure body which emulates the behavior of function
- -- Func_Id.
+ -- Func_Id. This body replaces the original function body, which is
+ -- not needed for the C program.
----------------
-- Add_Return --
-- Start of processing for Build_Procedure_Body_Form
begin
- -- This routine performs the following expansion:
+ -- This routine replaces the original function body:
-- function F (...) return Array_Typ is
-- begin
-- return Something;
-- end F;
+ -- with the following:
+
-- procedure P (..., Result : out Array_Typ) is
-- begin
-- ...
-- Result := Something;
-- end P;
- Stmts := New_Copy_List (Statements (HSS));
+ Stmts := Statements (HSS);
Replace_Returns (Last_Entity (Proc_Id), Stmts);
- Insert_After_And_Analyze (N,
+ Replace (N,
Make_Subprogram_Body (Loc,
Specification =>
Copy_Subprogram_Spec (Specification (Proc_Decl)),
- Declarations => New_Copy_List (Declarations (N)),
+ Declarations => Declarations (N),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => Stmts)));
+
+ Analyze (N);
end Build_Procedure_Body_Form;
-- Local varaibles
procedure Build_Procedure_Form;
-- Create a procedure declaration which emulates the behavior of
- -- function Subp.
+ -- function Subp, for SPARK_To_C.
--------------------------
-- Build_Procedure_Form --
begin
Actuals := Parameter_Associations (N);
+ -- Original function amy have been parameterless.
+
+ if No (Actuals) then
+ Actuals := New_List;
+ end if;
+
-- If the function call is the expression of an assignment statement,
-- transform the assignment into a procedure call. Generate:
Set_Has_Missing_Return (Id);
end if;
+ -- Within a premature instantiation of a package with no body, we
+ -- build completions of the functions therein, with a Raise
+ -- statement. No point in complaining about a missing return in
+ -- this case.
+
+ elsif Ekind (Id) = E_Function
+ and then In_Instance
+ and then Present (Statements (HSS))
+ and then Nkind (First (Statements (HSS))) = N_Raise_Program_Error
+ then
+ null;
+
elsif Is_Generic_Subprogram (Id)
or else not Is_Machine_Code_Subprogram (Id)
then