comp.lang.ada
 help / color / mirror / Atom feed
* Q. about generic child unit instantiation
@ 1996-06-25  0:00 david scott gibson
       [not found] ` <DtM900.1D0@world.std.com>
  0 siblings, 1 reply; 2+ messages in thread
From: david scott gibson @ 1996-06-25  0:00 UTC (permalink / raw)



Hi.  I have a question about generic child units.  I would like to
have a generic parent package with two generic child units.  In one of
the generic child units, I would like to create an instance of its
sibling unit.  However, in order to instantiate the sibling, I need to
instantiate the parent unit which doesn't seem to be legal (inside
one of its child units).  Does anyone know of a way I can instantiate
a generic child unit of a generic parent inside of its sibling?

Here's an example:

                         P[P_Item]
                         /       \
                        /         \       PC2[P_Item]
                 P.C1[C_Item]   P.C2[] 

I would like to instantiate P.C1 inside of P.C2 achieving the effect
of PC2 (which is not in the child unit hierarchy).  In this scheme, C1
and C2 provide (non-dispatching) implementations of the abstraction in
P.  The purpose of C2 is to provide C1's implementation of P but with
parameter C_Item fixed.  The only problem with PC2 (assuming it works)
is that it doesn't follow the parent:child :: abstraction:implemenation 
pattern I'd like to use.

--
Dave
dgibson@cis.ohio-state.edu

--------------------------------------------------
-- PACKAGE P

generic

   type P_Item is private;

package P is

   type T is abstract tagged null record;

   procedure Op1(x:T; y:P_Item) is abstract;

end P;

--------------------------------------------------
-- PACKAGE P.C1[C_Item]

generic

   type C_Item is private;

package P.C1 is

   type T is new P.T with private;

   procedure Op1(x:T; y:P_Item);

private

   type T is new P.T with
      record
         rep: Integer;  
      end record;

end P.C1;

--------------------------------------------------
-- PACKAGE P.C2[]

with P.C1;

generic

package P.C2 is

   type T is new P.T with private;

   procedure Op1(x:T; y:P_Item);

private
                                  -- I cannot instantiate P here.
   package P_C1_Integer is new    -- This doesn't work, but shows
      P.C1(C_Item => Integer);    -- to what I would like to do

   type T is new P.T with 
      record
         rep: P_C1_Integer.T;
      end record;

end P.C2;

--------------------------------------------------
-- PACKAGE P_C2[P_Item]

with P.C1;

generic

   type P_Item is private;  

package P_C2 is

   package PI is new P(P_Item => P_Item);

   package PI_C1_Integer is new PI.C1(C_Item => Integer);   

   type T is new PI_C1_Integer.T with null record;

end P_C2;









^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Q. about generic child unit instantiation
       [not found]   ` <4qsdjvINNsv0@bahama.cis.ohio-state.edu>
@ 1996-06-27  0:00     ` Robert A Duff
  0 siblings, 0 replies; 2+ messages in thread
From: Robert A Duff @ 1996-06-27  0:00 UTC (permalink / raw)


In article <4qsdjvINNsv0@bahama.cis.ohio-state.edu>,
david scott gibson <dgibson@bahama.cis.ohio-state.edu> wrote:
>...  For example, inside
>P.C2 I might want an instance of P.C1 with P_Item instantiated with a
>different actual than the P_Item parameter of P.C2's parent unit.  Is
>this is impossible in Ada due to the recursive instantiation rules?

Yes.  You cannot have an instance of P inside P (which includes inside
P's children).

You could have an instance (call it I) of P outside P, and have an
instance of I.C1 inside P.C2.  Sounds kind of weird to me, but I don't
really know what you're trying to do.

- Bob




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-06-27  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-25  0:00 Q. about generic child unit instantiation david scott gibson
     [not found] ` <DtM900.1D0@world.std.com>
     [not found]   ` <4qsdjvINNsv0@bahama.cis.ohio-state.edu>
1996-06-27  0:00     ` Robert A Duff

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