comp.lang.ada
 help / color / mirror / Atom feed
From: "Hibou57 (Yannick Duchêne)" <yannick_duchene@yahoo.fr>
Subject: Indirect visibility of private part in child packages
Date: Wed, 3 Jun 2009 22:45:43 -0700 (PDT)
Date: 2009-06-03T22:45:43-07:00	[thread overview]
Message-ID: <77683561-2b21-42c3-8c90-6c08a0c16b99@n21g2000vba.googlegroups.com> (raw)

Hi all,

I've meet a tortuous question with a set of packages I'm converting
from Pascal (as I use Ada now, I'm taking the opportunity to re-create
a nicer design).

The question I'm facing deals with visibility of private part in child
package. More precisely, an indirect visibility of a private part. An
exemple will better show the case:

This can be reduced to three package (specs and bodies)

The root package:

>>>>> --------------------------------------------------
package P1 is
   type T1_Type is tagged private;
   -- Some primitives on T1_Type are specified here ...
private
   type T1_Type is tagged record
      Low_Level_Data : Some_Type;
   end record; -- T1_Type
end P1;
<<<<< --------------------------------------------------

The first child package (with this one, every thing's Ok):
>>>>> --------------------------------------------------
package P1.P2 is
   type T2_Type is new T1_Type with private;
   -- Some primitives on T2_Type are specified here ...
   procedure A_Primitive (Item : out T2_Type);
private
   type T2_Type is new T1_Type with null record;
end P1.P2;

package body P1.P2 is
   procedure A_Primitive (Item : out T2_Type) is
   begin
      Item.Low_Level_Data := ...;
      -- It works, beceause P1.P2 is a child
      -- package with a view on P1's private part
   end A_Primitive;
end P1.P2;
<<<<< --------------------------------------------------

The second child package (the one which turns into a subtile doubt):
>>>>> --------------------------------------------------
with P1.P2;
package P1.P3 is
   type T3_Type is new P1.P2.T2_Type with private;
   -- Some primitives on T2_Type are specified here ...
   procedure A_Primitive (Item : out T3_Type);
private
   type T3_Type is new P1.P2.T2_Type with null record;
end P1.P3;

package body P1.P3 is
   procedure A_Primitive (Item : out T3_Type) is
   begin
      Item.Low_Level_Data := ...;
      -- It fails : the compiler complains there is no
      -- selector "Low_Level_Data" defined for T3_Type
   end A_Primitive;
end P1.P3;
<<<<< --------------------------------------------------

As said in the last comment, it seems P1.P3 cannot see the
T1_Type.Low_Level_Data member. But as P3 is a child package of P1, it
has a view on P1's private part, and there is indeed no trouble about
it with P2. P3 know P2.T2_Type is derived from P1.T1_Type, and P3 has
a view on T1_Type privates. But it seems the compiler does not care
about it.

There may be interpretation matter here : does the private
specification, means "disallow access to private part" or does it
means "do not provide an access to the private part". If it means
"disallow access to private part", then it ill explain why P3 cannot
access T1_Type.Low_Level_Data member. But if it means "do no provide
an access to private" part, then P3 should still be able to access
T1.Low_Level_Data, beceause it has an access to this as a child
package of P1.

What does long experienced lawyers think about it ?

I've try to look in section 8 of the "RM 2005", but either the answer
was not there or else, I missed it.

Note #1: I hope my exemple is clear enought. If it is not, please,
tell me, so that I can attempt to reword it.

Note #2: I do not want to make P3 a child package of P2, beceause it
does not need to access any internals of T2_Type. I want to have some
types, extending each others, and doing so only relying on either
public interface or on the sole common private part defined in P1.



             reply	other threads:[~2009-06-04  5:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-04  5:45 Hibou57 (Yannick Duchêne) [this message]
2009-06-04  7:50 ` Indirect visibility of private part in child packages Ludovic Brenta
2009-06-04 11:47   ` Hibou57 (Yannick Duchêne)
2009-06-04 13:22     ` Robert A Duff
2009-06-04 14:04       ` Hibou57 (Yannick Duchêne)
2009-06-04 16:06 ` Adam Beneschan
2009-06-04 16:33   ` Hibou57 (Yannick Duchêne)
replies disabled

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