comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Generic child units
Date: 15 May 2003 21:08:00 -0400
Date: 2003-05-15T21:08:00-04:00	[thread overview]
Message-ID: <wccu1bv4s27.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 3ec1f6ab$1@epflnews.epfl.ch

Rodrigo Garc�a <rodrigo.garcia.ARROBA.epfl.ch> writes:

> Stephen Leake wrote:
> > Rodrigo Garc�a <rodrigo.garcia.ARROBA.epfl.ch> writes:
> >
> >>I need some enlightment in this area... Let us suppose that I have two
> >>generic packages declared in separate files and one is the parent of
> >>the other:
> >>
> >>generic
> >>    type Elem is private;
> >>package Parent is
> >>    type Vector is array (Integer range <>) of Elem;
> >>end Parent;
> >>
> >>generic
> >>package Parent.Child is
> >>    subtype Vector2D is Vector (1 .. 2);
> >>end Parent.Child;
> >>
> >> How can I instantiate the child package
> > with Parent.Child;
> > procedure Foo is
> >    package Par is new Parent (Elem => Integer);
> >    package Chi is new Par.Child;
> > begin
> > ...
> > end Foo;
> > Note that the second instantiation is "Par.Child", not "Parent.Child".
> 
>    Thanks, that is one of the things I was doing wrong.
> 
> >>within the declarative region of the parent package (as required by
> >>RM 10.1(18))?
> > There is no RM 10.1 (18), at least in the copy I have (came with
> > GNAT). And I don't understand the rest of the sentence, either. So I
> > don't know what you mean here.
> 
>    Sorry, I meant RM 10.1.1 (18) as David C. Hoos has remarked. I still
> do not understand that requirement.

Paragraph 19.b in the AARM explains it.  You are instantiating the child
*outside* the parent generic, so you want to instantiate the child of
the instance of the parent, not the child of the parent.  Make sense?

Here's the AARM text:

 18    A child of a parent generic package shall be instantiated or renamed
 only within the declarative region of the parent generic.

 19    For each declaration or renaming of a generic unit as a child of some
 parent generic package, there is a corresponding declaration nested
 immediately within each instance of the parent. [This declaration is visible
 only within the scope of a with_clause that mentions the child generic unit.]

     19.a  Implementation Note: Within the child, like anything nested in a
           generic unit, one can make up-level references to the current
           instance of its parent, and thereby gain access to the formal
           parameters of the parent, to the types declared in the parent, etc.
           This ``nesting'' model applies even within the generic_formal_part
           of the child, as it does for a generic child of a nongeneric unit.

     19.b  Ramification: Suppose P is a generic library package, and P.C is a
           generic child of P. P.C can be instantiated inside the declarative
           region of P. Outside P, P.C can be mentioned only in a with_clause.
           Conceptually, an instance I of P is a package that has a nested
           generic unit called I.C. Mentioning P.C in a with_clause allows I.C
           to be instantiated. I need not be a library unit, and the
           instantiation of I.C need not be a library unit. If I is a library
           unit, and an instance of I.C is a child of I, then this instance has
           to be called something other than C.

- Bob



  parent reply	other threads:[~2003-05-16  1:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-13 17:46 Generic child units 
2003-05-13 18:38 ` Stephen Leake
2003-05-13 19:18   ` David C. Hoos
2003-05-14  7:56   ` 
2003-05-15 16:30     ` Stephen Leake
2003-05-16  1:08     ` Robert A Duff [this message]
2003-05-16 19:24       ` Stephen Leake
2003-05-16 23:47         ` Georg Bauhaus
2003-05-17  0:57           ` Robert A Duff
2003-05-17  1:11             ` Georg Bauhaus
2003-05-17  1:04         ` Robert A Duff
2003-05-16 23:44       ` Georg Bauhaus
2003-05-17  0:23   ` Georg Bauhaus
2003-05-17  1:00     ` Robert A Duff
replies disabled

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