comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Access to generic formal parameters in an generic package instantiation
Date: Sun, 29 Jul 2012 21:36:28 +0200
Date: 2012-07-29T21:36:28+02:00	[thread overview]
Message-ID: <1g8gnsgtfkmog$.1gs7zsxkjcxrl.dlg@40tude.net> (raw)
In-Reply-To: 87a9yi5t7j.fsf@mid.deneb.enyo.de

On Sun, 29 Jul 2012 20:16:00 +0200, Florian Weimer wrote:

> If G is a generic package and P is one of its formal parameters, it is
> legal to refer to G.P where G is visible?  Does this depend on the
> kind of entity, or whether the formal part uses <>?

Sometimes it works, sometimes it does not, I am not a language lawyer to
tell when GNAT is right or not. Facing this problem quite frequently, I
developed a custom to rename formal parameters within the declaration area,
e.g.

generic
   type Foo is ...;
   with package Bar is new Baz (<>);
package Boo is
   subtype My_Foo is Foo;
   package My_Bar is renames Bar;
   ...

Another method of making formal parameters visible is to have it a generic
child.

> that is, specify that two types in two formal packages are the same,
> without break down the formal packages to their components?

Yes. There several techniques to accomplish this.

1. You can to make that type a formal parameter and specify it among the
formal parameters of the instances:

   type T is ...
   with package P1 (T, <>);
   with package P2 (T, <>);

2. You can take the type from one package and constrain another with it:

   with package P1 (<>);
   with package P2 (P1.T, <>);

3. You can factor out a generic parameter package that defines T and other
common types and make it generic parent for the packages of interest.

> It seems that generic formal packages are unusual because GNAT shows
> some strange effects (and the occasional bug box).

There were always problems with generics in GNAT.

Though you likely won't believe me anyway, but using generics is a very bad
idea unless absolutely nothing else works. Here is an outlook what it
becomes in a relatively simple case:

   http://www.dmitry-kazakov.de/ada/fuzzy_packages.gif

Can you figure out a chain of instantiation of this for some given
floating-point type? How many instances it does? In a really complex case
there are multiple pages of such diagrams.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2012-08-03  0:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-29 18:16 Access to generic formal parameters in an generic package instantiation Florian Weimer
2012-07-29 19:36 ` Dmitry A. Kazakov [this message]
2012-07-29 21:31   ` Florian Weimer
2012-07-30 18:37     ` Adam Beneschan
2012-07-30 18:33 ` Adam Beneschan
2012-07-31  7:48 ` Georg Bauhaus
2012-07-31 15:29   ` Adam Beneschan
2012-07-31 16:50     ` Georg Bauhaus
replies disabled

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