elsif Ekind (Obj_Id) = E_Variable
and then not In_Library_Level_Package_Body (Obj_Id)
- and then (Is_Simple_Protected_Type (Obj_Typ)
- or else Has_Simple_Protected_Object (Obj_Typ))
+ and then Has_Simple_Protected_Object (Obj_Typ)
then
Processing_Actions (Is_Protected => True);
end if;
-- Start of processing for Process_Object_Declaration
begin
- -- Handle the object type and the reference to the object
+ -- Handle the object type and the reference to the object. Note
+ -- that objects having simple protected components must retain
+ -- their original form for the processing below to work.
Obj_Ref := New_Occurrence_Of (Obj_Id, Loc);
Obj_Typ := Base_Type (Etype (Obj_Id));
elsif Is_Concurrent_Type (Obj_Typ)
and then Present (Corresponding_Record_Type (Obj_Typ))
+ and then not Is_Protected
then
Obj_Typ := Corresponding_Record_Type (Obj_Typ);
Obj_Ref := Unchecked_Convert_To (Obj_Typ, Obj_Ref);
Fin_Stmts := New_List (Fin_Call);
end if;
- elsif Has_Simple_Protected_Object (Obj_Typ) then
- if Is_Record_Type (Obj_Typ) then
- Fin_Stmts := Cleanup_Record (Decl, Obj_Ref, Obj_Typ);
- elsif Is_Array_Type (Obj_Typ) then
- Fin_Stmts := Cleanup_Array (Decl, Obj_Ref, Obj_Typ);
- end if;
+ elsif Is_Array_Type (Obj_Typ) then
+ Fin_Stmts := Cleanup_Array (Decl, Obj_Ref, Obj_Typ);
+
+ else
+ Fin_Stmts := Cleanup_Record (Decl, Obj_Ref, Obj_Typ);
end if;
-- Generate:
-- Simple protected objects which use type System.Tasking.
-- Protected_Objects.Protection to manage their locks should be
-- treated as controlled since they require manual cleanup.
+ -- The only exception is illustrated in the following example:
+
+ -- package Pkg is
+ -- type Ctrl is new Controlled ...
+ -- procedure Finalize (Obj : in out Ctrl);
+ -- Lib_Obj : Ctrl;
+ -- end Pkg;
+
+ -- package body Pkg is
+ -- protected Prot is
+ -- procedure Do_Something (Obj : in out Ctrl);
+ -- end Prot;
+
+ -- protected body Prot is
+ -- procedure Do_Something (Obj : in out Ctrl) is ...
+ -- end Prot;
+
+ -- procedure Finalize (Obj : in out Ctrl) is
+ -- begin
+ -- Prot.Do_Something (Obj);
+ -- end Finalize;
+ -- end Pkg;
+
+ -- Since for the most part entities in package bodies depend on
+ -- those in package specs, Prot's lock should be cleaned up
+ -- first. The subsequent cleanup of the spec finalizes Lib_Obj.
+ -- This act however attempts to invoke Do_Something and fails
+ -- because the lock has disappeared.
elsif Ekind (Obj_Id) = E_Variable
- and then (Is_Simple_Protected_Type (Obj_Typ)
- or else Has_Simple_Protected_Object (Obj_Typ))
+ and then not In_Library_Level_Package_Body (Obj_Id)
+ and then Has_Simple_Protected_Object (Obj_Typ)
then
return True;
end if;