Type_Def : constant Node_Id := Type_Definition (Decl);
Type_Id : constant Entity_Id := Defining_Identifier (Decl);
Spec_Node : constant Node_Id :=
- New_Copy_Tree (Specification (New_Decl));
+ Copy_Subprogram_Spec (Specification (New_Decl));
+ -- This copy creates new identifiers for formals and subprogram.
Act : Node_Id;
Body_Node : Node_Id;
return;
end if;
- Set_Defining_Unit_Name (Spec_Node,
- Make_Defining_Identifier
- (Loc, Chars (Defining_Unit_Name (Spec_Node))));
-
-- Create List of actuals for indirect call. The last parameter of the
- -- subprogram is the access value itself.
+ -- subprogram declaration is the access value for the indirect call.
Act := First (Parameter_Specifications (Spec_Node));
Ptr :=
Defining_Identifier
- (Last (Parameter_Specifications (Spec_Node)));
+ (Last (Parameter_Specifications (Specification (New_Decl))));
if Nkind (Type_Def) = N_Access_Procedure_Definition then
Call_Stmt := Make_Procedure_Call_Statement (Loc,
Parms : constant List_Id := Parameter_Associations (N);
Typ : constant Entity_Id := Etype (N);
New_N : Node_Id;
+ Ptr_Act : Node_Id;
begin
-- The last actual in the call is the pointer itself.
-- If the aspect is inherited, convert the pointer to the
-- parent type that specifies the contract.
+ -- If the original access_to_subprogram has defaults for
+ -- in_parameters, the call may include named associations, so
+ -- we create one for the pointer as well.
if Is_Derived_Type (Ptr_Type)
and then Ptr_Type /= Etype (Last_Formal (Wrapper))
then
- Append
- (Make_Type_Conversion (Loc,
- New_Occurrence_Of
- (Etype (Last_Formal (Wrapper)), Loc), Ptr),
- Parms);
+ Ptr_Act :=
+ Make_Type_Conversion (Loc,
+ New_Occurrence_Of
+ (Etype (Last_Formal (Wrapper)), Loc), Ptr);
else
- Append (Ptr, Parms);
+ Ptr_Act := Ptr;
end if;
+ Append
+ (Make_Parameter_Association (Loc,
+ Selector_Name => Make_Identifier (Loc,
+ Chars (Last_Formal (Wrapper))),
+ Explicit_Actual_Parameter => Ptr_Act),
+ Parms);
+
if Nkind (N) = N_Procedure_Call_Statement then
New_N := Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Wrapper, Loc),