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,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,79d6bba6ba97b840 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!m35g2000prn.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Renaming of procedures in a generic instantiation Date: Mon, 27 Sep 2010 12:23:00 -0700 (PDT) Organization: http://groups.google.com Message-ID: <30fadcf5-9a20-46b9-b5ef-8a657fb98256@m35g2000prn.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1285615381 22368 127.0.0.1 (27 Sep 2010 19:23:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 27 Sep 2010 19:23:01 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m35g2000prn.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14282 Date: 2010-09-27T12:23:00-07:00 List-Id: On Sep 25, 5:43=A0pm, Gene wrote: > I'm confused about an aspect of renaming. It boils out to this little > example: > > with Ada.Containers.Ordered_Sets; > > package Foo is > > =A0 type Queue is private; > > =A0 procedure Add(Q : in out Queue; Item : in Integer); > > =A0 function Is_Empty(Q : Queue) return Boolean; > > private > > =A0 package Queues is > =A0 =A0 new Ada.Containers.Ordered_Sets(Integer, "<", "=3D"); > =A0 type Queue is new Queues.Set with null record; > > end Foo; > > package body Foo is > > =A0 =A0procedure Add(Q : in out Queue; Item : in Integer) > =A0 =A0 =A0 renames Insert; > > =A0 =A0function Is_Empty(Q : Queue) return Boolean > =A0 =A0 =A0 renames Queues.Is_Empty; > > end Foo; > > The renaming in Add "finds" the correct procedure Insert, but the > renaming of Is_Empty fails: > > gnatmake foo.adb > gcc -c foo.adb > foo.adb:6:04: no visible subprogram matches the specification for > "Is_Empty" > foo.adb:6:13: expected private type "Ada.Containers.Ordered_Sets.Set" > from insta > nce at foo.ads:14 > foo.adb:6:13: found type "Queue" defined at foo.ads:16 > gnatmake: "foo.adb" compilation error > > I guess I can see this error because a parameter type conversion is > implied in the renaming. =A0But then why does the renaming of Insert > work correctly? Because you didn't refer to the "Insert" defined in Queues, the way you did with Is_Empty. If you had declared this, it would be illegal in the same way: procedure Add(Q : in out Queue; Item : in Integer) renames Queues.Insert; Obviously, you can't solve the problem for Is_Empty by removing the "Queues." prefix: function Is_Empty(Q : in out Queue) return Boolean renames Is_Empty; I found that this compiles, but it's obnoxious: with Ada.Containers.Ordered_Sets; package Foo is type Queue is private; procedure Add(Q : in out Queue; Item : in Integer); function Is_Empty(Q : Queue) return Boolean; private package Queues is new Ada.Containers.Ordered_Sets(Integer, "<", "=3D"); package Dummy_Package is type Dummy_Queue is new Queues.Set with null record; function Rename_Empty(Q : Dummy_Queue) return Boolean renames Is_Empty; end Dummy_Package; type Queue is new Dummy_Package.Dummy_Queue with null record; end Foo; package body Foo is procedure Add(Q : in out Queue; Item : in Integer) renames Insert; function Is_Empty(Q : Queue) return Boolean renames Rename_Empty; end Foo; Just writing Is_Empty to call Queues.Is_Empty, as Niklas suggested, seems better than this. I'd also add "pragma Inline(Is_Empty)" to the private part of Foo to possibly prevent extraneous call code from being generated. I had thought that someone (possibly me) once proposed adding the ability to declare that a subprogram renames the hidden subprogram that it overrides, e.g. function Is_Empty(Q : Queue) return Boolean renames <>; but I can't find anything like that in my mail records. Randy did once mention using something like Is_Empty'Parent as a stand-in for the call to the parent routine; he wasn't thinking of a renaming context, but it might work here: function Is_Empty(Q : Queue) return Boolean renames Is_Empty'Parent; In any event, however, it seems to be a minor enough problem with a simple enough workaround that it's not worthwhile to change the language. -- Adam