From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,12d893e9461dcfe6 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.224.219.205 with SMTP id hv13mr6219274qab.5.1344272609367; Mon, 06 Aug 2012 10:03:29 -0700 (PDT) Received: by 10.180.105.2 with SMTP id gi2mr1177486wib.4.1344262884511; Mon, 06 Aug 2012 07:21:24 -0700 (PDT) Path: c6ni65261628qas.0!nntp.google.com!r1no11379777qas.0!news-out.google.com!n2ni72434332win.0!nntp.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!border1.nntp.ams2.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!news.szaf.org!news.gnuher.de!news.enyo.de!.POSTED!not-for-mail From: Florian Weimer Newsgroups: comp.lang.ada Subject: Re: Access to generic formal parameters in an generic package instantiation Date: Sun, 29 Jul 2012 23:31:29 +0200 Message-ID: <87y5m22r0u.fsf@mid.deneb.enyo.de> References: <87a9yi5t7j.fsf@mid.deneb.enyo.de> <1g8gnsgtfkmog$.1gs7zsxkjcxrl.dlg@40tude.net> Mime-Version: 1.0 X-Trace: news.enyo.de 1343597488 19476 172.17.135.6 (29 Jul 2012 21:31:28 GMT) X-Complaints-To: news@enyo.de Cancel-Lock: sha1:zaw6F+ZAm4eN3UAdnC062a5OElU= Content-Type: text/plain; charset=us-ascii Date: 2012-07-29T23:31:29+02:00 List-Id: * Dmitry A. Kazakov: > 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. It seems that the names of the generic formal declarations are lost except if they refer to implicit declaration (those using <>). I'm not sure why implicit declarations are special-cased like this. There is sometimes no way to reference to an implicit declaration because you are not supplying the arguments. But if you want to get the arguments back reliably, you have to add declarations anyway, and those cover the implicit case as well, so I'm not sure this language feature is really necessary. > 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; > ... The same approach is used in C++ where template arguments are not accessible from outside of the template. Instead, you have to provide typedefs for alias names. > Another method of making formal parameters visible is to have it a > generic child. This smells a bit like a compiler bug. The standard doesn't seem to mention it. >> 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, <>); I got a bug box when I tried this. > 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 It's just the usual curse of the higher order. Functions call graphs aren't always pretty, either. Anyway, I'm trying to find a good way for resource management which does not rely on finalization, and I want to cut down boilerplate code.