comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: Extending a third party tagged type while adding finalization
Date: Mon, 4 Dec 2017 07:44:26 -0800 (PST)
Date: 2017-12-04T07:44:26-08:00	[thread overview]
Message-ID: <18484b80-247e-4d01-9aea-2b60899846ac@googlegroups.com> (raw)
In-Reply-To: <p03k46$k2v$1@gioia.aioe.org>

Aha, now I see what you are talking about. That's what I meant with cryptic message. You too often just expect mind reading (especially difficult with illegal code snippets).

Am Montag, 4. Dezember 2017 14:55:23 UTC+1 schrieb Dmitry A. Kazakov:
> On 04/12/2017 14:19, AdaMagica wrote:
> 
> > There is no Initialize defined for derived S. This is defined then implicitly as:
> > 
> >    procedure Initialize (X: in out S) is
> >    begin
> >      Initialize (T (X));
> >    end Initialize;
> > 
> > This is the calling sequence:
> > Init S
> > Init T
> > Foo  S
> 
> Which is a wrong sequence per Ada design. Actually it is just
> 
>     Initialize of S
> 
> This wrong sequence is fixed in practice by applying the pattern:
> 
>     procedure Initialize (X : in out Derived) is
>     begin
>        Parent (X).Initialize; -- Ensure parent's initialization
>        <do user initialization of Derived>
>     end Initialize;
> 
> Using the pattern you get a semantically correct sequence:
> 
>        -- enter Initialize of S
>        --   enter Initialize of T
>     <do user initialization of T>
>        --   leave Initialize of T
>     <do user initialization of S>
>        -- leave Initialize of S

That's the well-known Ada pattern you find in any text book. So what's your point?

> But with Foo it becomes wrong again:
> 
>     <do user initialization of T> + call Foo of S
>     <do user initialization of S>

Yes, because you specifically request a redispatch via the classwide pointer. You can correct this with

  procedure Initialize (X: in out T) is
  begin
    T (X.Self.all).Foo; -- no more Boom!
  end Initialize;

There were some discussions in CLA about not to use dispatch in Initialize et alii.

> Which is catastrophic and there is *no* way to make it right in presence 
> of multiple derived types. You cannot announce a call to a deferred 
> implementation during initialization of a specific type T. That may 
> happen only after initializations of all derived specific types are 
> complete.
> 
> Semantically it means that it must be called in the initialization of 
> T'Class. The proper sequence must be:
> 
>     <do user initialization of T>
>     <do user initialization of S>
>     <do user initialization of S'Class>
>     <do user initialization of T'Class> + call Foo of S

What do you mean by init of S'Class? There are no components of an S'Class. Sorry, I don't understand.

  reply	other threads:[~2017-12-04 15:44 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
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 [this message]
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