comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Type extension and discriminants
Date: Sat, 11 Oct 2014 20:52:49 +0200
Date: 2014-10-11T20:52:49+02:00	[thread overview]
Message-ID: <1m1grtt4tjy6m$.2tgdf5cel9tn$.dlg@40tude.net> (raw)
In-Reply-To: aa0678d5-f777-4a52-952f-dc9a2f16ed74@googlegroups.com

On Sat, 11 Oct 2014 10:45:55 -0700 (PDT), sbelmont700@gmail.com wrote:

> On Friday, October 10, 2014 6:34:54 PM UTC-4, Randy Brukardt wrote:
>> It would have helped a bit had you given an example.
> 
> Thank you for your response.  An example follows:
> 
> package A is
>    type T1 (<>) is tagged limited private;
>    function T1_Ctor return T1;
> private
>    type T1 (I_Ptr : access Integer) is tagged limited null record;
> end A;
> 
> 
> package body A is
>    function T1_Ctor return T1 is
>    begin
>       return (I_Ptr => null);
>    end T1_Ctor;
> end A;
> 
> with A;
> package B is
>    type T2 (<>) is new A.T1 with private;
>    function T2_Ctor return T2;
> private
>   type T2 is new A.T1 with null record;
> end B;
> 
> package body B is
>    function T2_Ctor return T2 is
>    begin
>       return T2'(A.T1_Ctor with null record);
>    end T2_Ctor;
>   
> end B;

Don't use this pattern, it simply does not work. Even without GNAT bugs.
However all GNAT compilers I know have serious problems with more than one
nested limited return. But if GNAT worked, this pattern will eventually hit
you back.

In short, limited return (constructing function) and limited aggregate are
not suitable for construction of parent objects which private discriminants
and components.

As an alternative consider a child package to derive the type. Also
consider using non-limited handles pointing to the reference counted
limited private implementation objects.

You can use the same interface type for both the handle type and the
implementation type. The implementation of the interface for the handle
type calls the implementation of the limited private implementation type
after dereferencing (delegation).

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

  parent reply	other threads:[~2014-10-11 18:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 20:55 Type extension and discriminants sbelmont700
2014-10-10 22:34 ` Randy Brukardt
2014-10-11 17:45   ` sbelmont700
2014-10-11 18:44     ` Simon Wright
2014-10-11 18:52     ` Dmitry A. Kazakov [this message]
2014-10-11 21:09       ` sbelmont700
2014-10-12  6:51         ` Dmitry A. Kazakov
2014-10-12 16:27     ` AdaMagica
replies disabled

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