and then Ekind (Info.Fin_Scop) = E_Package_Body
then
Set_In_Package_Body (Spec_Entity (Info.Fin_Scop), True);
+ Instantiate_Package_Body (Info);
+ Set_In_Package_Body (Spec_Entity (Info.Fin_Scop), False);
+ else
+ Instantiate_Package_Body (Info);
end if;
- Instantiate_Package_Body (Info);
+ -- No need to generate cleanups if the main unit is generic
- if Present (Info.Fin_Scop) then
+ if Present (Info.Fin_Scop)
+ and then not Is_Generic_Unit (Main_Unit_Entity)
+ then
Scop := Info.Fin_Scop;
-- If the enclosing finalization scope is dynamic, the instance
end if;
Add_Scope_To_Clean (Scop);
-
- -- Reset the In_Package_Body flag if it was set above
-
- if Ekind (Info.Fin_Scop) = E_Package_Body then
- Set_In_Package_Body (Spec_Entity (Info.Fin_Scop), False);
- end if;
end if;
-- For subprogram instances, always instantiate the body
Push_Scope (Standard_Standard);
To_Clean := New_Elmt_List;
- if Is_Generic_Unit (Cunit_Entity (Main_Unit)) then
- Start_Generic;
- end if;
-
-- A body instantiation may generate additional instantiations, so
-- the following loop must scan to the end of a possibly expanding
-- set (that's why we cannot simply use a FOR loop here). We must
Pending_Instantiations.Init;
end if;
- -- We can now complete the cleanup actions of scopes that contain
- -- pending instantiations (skipped for generic units, since we
- -- never need any cleanups in generic units).
+ -- Expand the cleanup actions of scopes that contain instantiations
- if Expander_Active
- and then not Is_Generic_Unit (Main_Unit_Entity)
- then
+ if Expander_Active then
Cleanup_Scopes;
- elsif Is_Generic_Unit (Cunit_Entity (Main_Unit)) then
- End_Generic;
end if;
Pop_Scope;