comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Finalization of a record containing a task
Date: Fri, 18 Feb 2005 12:27:01 +0100
Date: 2005-02-18T12:24:31+01:00	[thread overview]
Message-ID: <e9uolcr9628g$.wjmbx945n6n9.dlg@40tude.net> (raw)
In-Reply-To: wccll9mu3m7.fsf@shell01.TheWorld.com

On 17 Feb 2005 19:13:36 -0500, Robert A Duff wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>>... (Hypothetically, if there were
>> class-wide destructors, one would be able to do that.)
> 
> Sounds interesting.  Can you give details of what you mean?

The idea is to have user-defined initialization / finalization of
class-wide objects. After all, T'Class is as type as T, why shouldn't it
have ctors?

Because presently tagged objects are view-convertible to their classes,
that automatically implies, that even specific tagged objects have to be
initialized / finalized as classes.

So let us have:

type A is new Ada.Finalization....;
type B is new A with ...;

Then, to initialize B, we have to:

1. initialize B (and A from there)
2. initialize B'Class -- presently empty
3. initialize A'Class -- presently empty

To finalize B:

1. finalize A'Class -- presently empty
2. finalize B'Class -- presently empty
3. finalize B (and A from there)

Because now we have something class-wide to dispatch from that could solve
the problem of dispatching from constructors. One will just dispatch from:

Class_Initialize (Object : in out A'Class);

At this stage B (or whatsoever derived object) is fully constructed, so we
can safely dispatch on Object. Same with task components (and
hypothetically with task ancestors): Class_Finalize could call Die_At_Once
entry of its task component.

>>... So in most cases one
>> is forced to use access-to-task components rather than plain task ones.
> 
> Yes, but if you declare the object in a library package, you'll
> still have the same problem with finalization happening too late.

Yes.

----------------------------
Should Ada some day have classes for non-tagged objects, then class-wide
constructors / destructors would be called each time T is converted to
T'Class and back. That would be a real conversion then, which at least adds
/ removes the type tag.

It could become very interesting for by-reference parameter passing,
though.

For example:

   type A is ...;
   procedure Foo (Object : A); -- A is by-reference here

   type B is new A ...;

   X : constant A'Class := Some_B;
begin
   Foo (X);

upon dispatch to A.Foo, X has to be converted to plain A. For this it is
first demoted from class by finalizing A'Class and then B'Class. Now Foo is
ready to call. After Foo's completion, and even if an exception is
propagated, X need to be heighten back to B'Class and A'Class. No matter,
if it is a constant! (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2005-02-18 11:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-16 20:35 Finalization of a record containing a task Bj?rn
2005-02-16 20:49 ` Stephen Leake
2005-02-16 21:20   ` Adrien Plisson
2005-02-16 22:09     ` Robert A Duff
2005-02-17  8:24       ` Adrien Plisson
2005-02-18  0:17         ` Robert A Duff
2005-02-17  9:13     ` Dmitry A. Kazakov
2005-02-18  0:13       ` Robert A Duff
2005-02-18  2:34         ` Randy Brukardt
2005-02-18 11:27         ` Dmitry A. Kazakov [this message]
2005-02-16 22:08   ` Robert A Duff
2005-02-21 13:20     ` Craig Carey
2005-02-21 21:41       ` Robert A Duff
2005-02-22  0:15         ` Randy Brukardt
2005-02-17 17:50   ` Bj?rn
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox