comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Protected types and visibility of their internals
Date: Wed, 9 Jul 2008 15:38:48 -0700 (PDT)
Date: 2008-07-09T15:38:48-07:00	[thread overview]
Message-ID: <efab0add-0f40-4302-8057-85bee50639d6@34g2000hsf.googlegroups.com> (raw)
In-Reply-To: uvdzed7l3.fsf@nasa.gov

On Jul 9, 3:19 pm, Stephen Leake <Stephe.Le...@nasa.gov> wrote:
> Maciej Sobczak <see.my.homep...@gmail.com> writes:
> > Consider a protected type in some package:
>
> > package P is
> >    protected type PT is
> >       procedure Foo;
> >    private
> >       X : Some_Type;
> >    end PT;
> > end P;
>
> > The protected type has a component X of Some_Type, which is entirely
> > the private business of the protected type.
>
> > Where this type should be declared?
>
> In a sibling private package:
>
> private
> package P.stuff is
>
>     type Some_Type is ...;
> end P.Stuff;
>
> private with P.stuff;
> package P is
>    protected type PT is
>       procedure Foo;
>    private
>       X : P.Stuff.Some_Type;
>    end PT;
> end P;
>
> Hmm. Maybe that's not right, since P.Stuff is used in the private part
> of a public type, not strictly in the private part of P. But it
> _should_ be ok!

It appears that private parts of protected types *can* use things
declared in packages mentioned with "private with".  However, your
example won't work because you can't have the specification of P
"with" a child of P; this creates a circular dependency.  You *could*
do this, however:

private with P.Stuff;
package P.Stuff2 is
   protected type PT is
      procedure Foo;
   private
      X : P.Stuff.Some_Type;
   end PT;
end P.Stuff2;

This still won't solve Maciej's problem if the definition of Some_Type
requires some other types declared earlier in Stuff2.  If that's the
case, he'll have to reorganize things yet further and move some of
those types to yet another package, Stuff3.  It does seem like there
ought to be a better way to accomplish all this---how about letting
private and public parts of a package spec be interspersed?

package P is
private
    type Some_Type is ...
not private  -- heh, heh, heh!
    protected type PT is
       procedure Foo;
    private
       X : Some_Type;
    end PT;
private
    .. other private stuff can go here if needed
end P;

But any solution is likely to be a huge burden on both the language
designers and implementors, at this point.  I think we're stuck.

                             -- Adam




  reply	other threads:[~2008-07-09 22:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-08  9:57 Protected types and visibility of their internals Maciej Sobczak
2008-07-08 12:52 ` Georg Bauhaus
2008-07-08 16:13 ` Robert A Duff
2008-07-09  7:53   ` christoph.grein
2008-07-08 21:03 ` Randy Brukardt
2008-07-10 21:49   ` Maciej Sobczak
2008-07-09  5:04 ` christoph.grein
2008-07-09 13:44   ` Maciej Sobczak
2008-07-09 15:12   ` Adam Beneschan
2008-07-09 22:19 ` Stephen Leake
2008-07-09 22:38   ` Adam Beneschan [this message]
2008-07-10  0:18     ` Randy Brukardt
2008-07-10  0:18     ` Randy Brukardt
2008-07-09 23:22 ` jimmaureenrogers
replies disabled

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