From: Jere <jhb.chat@gmail.com>
Subject: Re: Extending a third party tagged type while adding finalization
Date: Mon, 27 Nov 2017 08:38:00 -0800 (PST)
Date: 2017-11-27T08:38:00-08:00 [thread overview]
Message-ID: <c622b340-14ce-4da4-837b-4f8962cffd0b@googlegroups.com> (raw)
In-Reply-To: <eccf6acf-34d9-47d8-8471-bd41afac3ecf@googlegroups.com>
On Monday, November 27, 2017 at 10:00:11 AM UTC-5, AdaMagica wrote:
> Am Montag, 27. November 2017 13:56:36 UTC+1 schrieb Jere:
> > The intent was to be able to provide "overridable" Initialize
> > and Finalize to descendants of the mixin which would be called
> > automatically, but now I don't think that is possible in a safe way.
>
> Why do you say this? In my paper, Final is a further derivation, and also derivations from Final will work as expected.
well, when I tried your example it didn't call the finalization routing for
any derived types. I might have mis-copied it somehow. Here is a
compilable example:
**************************************************************
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Finalization;
with Ada.Task_Attributes;
procedure Main is
generic
type Uncontrolled (<>) is abstract tagged private;
with procedure Adjust (Object: in out Uncontrolled);
with procedure Finalize (Object: in out Uncontrolled);
package To_Controlled is
type Controlled is new Uncontrolled with private;
private
type Controlled_Ptr is access all Controlled;
type Component is new Ada.Finalization.Controlled with record
Parent: Controlled_Ptr;
end record;
type Controlled is new Uncontrolled with record
Controller: Component := (Ada.Finalization.Controlled with
Controlled'Unrestricted_Access); -- Gnat only
end record;
procedure Adjust (Object: in out Component);
procedure Finalize (Object: in out Component);
end To_Controlled;
package body To_Controlled is
package Store is
new Ada.Task_Attributes (Attribute => Controlled_Ptr,
Initial_Value => null);
procedure Adjust (Object: in out Component) is
begin
Object.Parent := Store.Value;
Adjust (Uncontrolled (Object.Parent.all));
end Adjust;
procedure Finalize (Object: in out Component) is
begin
Store.Set_Value (Object.Parent);
Finalize (Uncontrolled (Object.Parent.all));
end Finalize;
end To_Controlled;
package Components is
type C1 is new Ada.Finalization.Controlled with null record;
overriding procedure Adjust (Self : in out C1);
overriding procedure Finalize (Self : in out C1);
type C2 is new Ada.Finalization.Controlled with null record;
overriding procedure Adjust (Self : in out C2);
overriding procedure Finalize (Self : in out C2);
end Components;
package body Components is
overriding procedure Adjust (Self : in out C1) is
begin
Put_Line("Adjust C1");
end Adjust;
overriding procedure Finalize (Self : in out C1) is
begin
Put_Line("Finalize C1");
end Finalize;
overriding procedure Adjust (Self : in out C2) is
begin
Put_Line("Adjust C2");
end Adjust;
overriding procedure Finalize (Self : in out C2) is
begin
Put_Line("Finalize C2");
end Finalize;
end Components;
package Types is
type Base is tagged record
c1 : Components.C1;
end record;
type Derived is new Base with null record;
procedure Adjust (Self : in out Derived);
procedure Finalize (Self : in out Derived);
package To_C is new To_Controlled
(Derived, Adjust, Finalize);
type Final is new To_C.Controlled with record
c2 : Components.C2;
end record;
overriding procedure Adjust (Self : in out Final);
overriding procedure Finalize (Self : in out Final);
end Types;
package body Types is
procedure Adjust (Self : in out Derived) is
begin
Put_Line("Adjust Derived");
end Adjust;
procedure Finalize (Self : in out Derived) is
begin
Put_Line("Finalize Derived");
end Finalize;
procedure Adjust (Self : in out Final) is
begin
Put_Line("Adjust Final");
end Adjust;
procedure Finalize (Self : in out Final) is
begin
Put_Line("Finalize Final");
end Finalize;
end Types;
v : Types.Final;
begin
Put_Line ("Starting");
end Main;
**************************************************************
with this the output is:
Starting
Finalize C2
Finalize Derived
Finalize C1
There is no "Finalize Final" as expected from inheritance
Did I put something in wrong?
next prev parent reply other threads:[~2017-11-27 16:38 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-22 12:43 Extending a third party tagged type while adding finalization Jere
2017-11-22 16:42 ` AdaMagica
2017-11-26 17:33 ` Jere
2017-11-26 18:15 ` Dmitry A. Kazakov
2017-11-26 19:31 ` Jere
2017-11-27 9:46 ` AdaMagica
2017-11-27 12:56 ` Jere
2017-11-27 15:00 ` AdaMagica
2017-11-27 16:38 ` Jere [this message]
2017-11-27 18:37 ` AdaMagica
2017-11-27 19:53 ` Jere
2017-11-28 11:48 ` AdaMagica
2017-12-03 2:22 ` Jere
2017-12-03 21:53 ` Robert Eachus
2017-12-04 7:58 ` Dmitry A. Kazakov
2017-12-04 14:59 ` Robert Eachus
2017-12-04 15:39 ` Dmitry A. Kazakov
2017-11-27 18:10 ` Shark8
2017-11-27 19:56 ` Jere
2017-11-28 1:55 ` Randy Brukardt
2017-12-03 2:47 ` Jere
2017-12-03 9:29 ` Dmitry A. Kazakov
2017-12-03 15:10 ` AdaMagica
2017-12-03 16:39 ` Dmitry A. Kazakov
2017-12-03 19:34 ` AdaMagica
2017-12-03 19:41 ` Dmitry A. Kazakov
2017-12-04 12:38 ` AdaMagica
2017-12-04 13:19 ` AdaMagica
2017-12-04 13:55 ` Dmitry A. Kazakov
2017-12-04 15:44 ` AdaMagica
2017-12-04 16:19 ` Dmitry A. Kazakov
2017-12-04 20:54 ` Randy Brukardt
2017-12-04 21:02 ` Dmitry A. Kazakov
2017-12-05 21:09 ` Randy Brukardt
2017-12-05 21:29 ` Dmitry A. Kazakov
2017-12-07 1:13 ` Randy Brukardt
2017-12-07 8:36 ` Dmitry A. Kazakov
2017-12-07 23:22 ` Randy Brukardt
2017-12-08 9:30 ` Dmitry A. Kazakov
2017-12-09 0:17 ` Randy Brukardt
2017-12-11 9:03 ` Dmitry A. Kazakov
2017-12-11 22:42 ` Randy Brukardt
2017-12-12 16:11 ` AdaMagica
2017-12-12 20:08 ` G. B.
2017-12-12 20:32 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox