comp.lang.ada
 help / color / mirror / Atom feed
* [Technical] Generic child parameterised with instance of parent
@ 1998-11-25  0:00 Michel Gauthier
  1998-11-26  0:00 ` Mats Weber
  0 siblings, 1 reply; 3+ messages in thread
From: Michel Gauthier @ 1998-11-25  0:00 UTC (permalink / raw)



Here is the need as I can identify it (possibly not in a right way).

There is a generic unit :
    generic
        type ITEM is private ;
    package G1 is ...

What I have to do is
    generic
        with package GP is new G1 ( <> ) ;
    package G1 . Child is ...
(the child depends logically on two instances of G1).
I know that something like
    generic
        with package GZ is new G1 ( <> ) ;
        with package GP is new G1 ( <> ) ;
    package NotChild is ...
would work, but I need access the private part of GZ.

Since G1 in with... would denote the current instance, I added 
    generic package G1bis renames G1 ;
and adapted
    generic
        with package GP is new G1bis ( <> ) ;
    package G1 . Child is ...
 There are also instances of G1 :
    package P1Some is new G1 ( some_type ) ;
    package P1Other is new G1 ( other_type ) ;

Then can be compiled. But the compiler rejects
    package InstChild is new P1Some . Child ( P1Other ) ;


Now, the questions :
 1 - is it intrinsicly illegal or is my compiler too ancient ?
 2 - how can I work around the problem ?
 3 - is there a known alternate design ?

----------          ----------          ----------          ---------- 
Michel Gauthier / Laboratoire d'informatique
123 avenue Albert Thomas / F-87060 Limoges
telephone +33 5 55 43 69 73
fax +33 5 55 43 69 77
----------          ----------          ----------          ----------
Hein, quoi, quelle annee dix-neuf cent nonante dix ?
What exactly about year nineteen ninety ten ?
----------          ----------          ----------          ----------




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

* Re: [Technical] Generic child parameterised with instance of parent
  1998-11-25  0:00 [Technical] Generic child parameterised with instance of parent Michel Gauthier
@ 1998-11-26  0:00 ` Mats Weber
  1998-11-29  0:00   ` Tucker Taft
  0 siblings, 1 reply; 3+ messages in thread
From: Mats Weber @ 1998-11-26  0:00 UTC (permalink / raw)


Michel Gauthier wrote:

> Here is the need as I can identify it (possibly not in a right way).

> Then can be compiled. But the compiler rejects
>     package InstChild is new P1Some . Child ( P1Other ) ;

GNAT 3.11b accepts this, and does not need the G1bis declaration, so it
does not seem to take G1 as denoting the current instance within the
generic formal part of G1.Child. I don't know if that is right or not.

Here is the exact code that I compiled:

with G1.Child;

procedure Gauthier_Generic_Child is

   type Some_Type is new Integer;
   type Other_Type is new Float;

   package P1_Some is new G1 ( some_type ) ;
   package P1_Other is new G1 ( other_type ) ;

   package InstChild is new P1_Some . Child ( P1_Other ) ;

begin
   null;
end;
---
generic
   with package GP is new G1 ( <> ) ;
package G1 . Child is
end;
---
generic
   type ITEM is private;
package G1 is
end G1;




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

* Re: [Technical] Generic child parameterised with instance of parent
  1998-11-26  0:00 ` Mats Weber
@ 1998-11-29  0:00   ` Tucker Taft
  0 siblings, 0 replies; 3+ messages in thread
From: Tucker Taft @ 1998-11-29  0:00 UTC (permalink / raw)


Mats Weber (Mats.Weber@elca-matrix.ch) wrote:

: Michel Gauthier wrote:

: > Here is the need as I can identify it (possibly not in a right way).

: > Then can be compiled. But the compiler rejects
: >     package InstChild is new P1Some . Child ( P1Other ) ;

: GNAT 3.11b accepts this, and does not need the G1bis declaration, so it
: does not seem to take G1 as denoting the current instance within the
: generic formal part of G1.Child. I don't know if that is right or not.

This sounds like a bug.  Everywhere inside the declarative region
of G1, G1 denotes the "current instance."

: Here is the exact code that I compiled:

: with G1.Child;

: procedure Gauthier_Generic_Child is

:    type Some_Type is new Integer;
:    type Other_Type is new Float;

:    package P1_Some is new G1 ( some_type ) ;
:    package P1_Other is new G1 ( other_type ) ;

:    package InstChild is new P1_Some . Child ( P1_Other ) ;

: begin
:    null;
: end;
: ---
: generic
:    with package GP is new G1 ( <> ) ;

   This is definitely wrong; G1 is not a generic inside G1.

: package G1 . Child is
: end;
: ---
: generic
:    type ITEM is private;
: package G1 is
: end G1;

I might add that, inside a child of G1, you don't normally need to
pass in an instance of G1, because an instance of G1 must
be specified as a prefix when instantiating the child, and that instance
can be referenced inside the child by simply using the name "G1."

If you need *two* instances of the parent generic inside the child, then 
you probably do need to do the generic renaming trick.

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company




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

end of thread, other threads:[~1998-11-29  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-25  0:00 [Technical] Generic child parameterised with instance of parent Michel Gauthier
1998-11-26  0:00 ` Mats Weber
1998-11-29  0:00   ` Tucker Taft

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