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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aaec211ca305e5ee X-Google-Attributes: gid103376,public From: Ted Dennison Subject: Re: allocators for classwide types? Date: 1999/12/28 Message-ID: <3868FB86.4126D0E6@telepath.com>#1/1 X-Deja-AN: 565728652 Content-Transfer-Encoding: 7bit References: <38684DEE.6CB6F268@telepath.com> <3868E1B4.D5F6A23C@telepath.com> X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii X-Complaints-To: Abuse Role , We Care X-Trace: monger.newsread.com 946404004 216.14.8.11 (Tue, 28 Dec 1999 13:00:04 EST) Organization: Telepath Systems (telepath.com) MIME-Version: 1.0 NNTP-Posting-Date: Tue, 28 Dec 1999 13:00:04 EST Newsgroups: comp.lang.ada Date: 1999-12-28T00:00:00+00:00 List-Id: Ted Dennison wrote: > Robert A Duff wrote: > > > > Gnat actually generates a compiler error on my variant of this. ... > > > > You should post the text of the message. > > It was an internal Gnat error. That's obviously a bug, of course. But 95% of > the time those are caused by my doing something illegal in a way that the > compiler didn't expect. It looks like in this case I may have been doing OK. After further playing around, it appears the problem was actually a convoluted parameter naming problem; not really anything to do with classwide types at all. In my actual code, the package "Get" existed in was a generic child package of package_1, which itself was a generic. The second parameter happened to be named the same as the parent package. It also happened to be named the same as the record field it was getting allocated and placed into. I expanded my toy example to match: ----- generic type Fred is (<>); package Package_1 is type Instance is tagged record Fred_Field : Fred := Fred'First; end record; subtype Class is Instance'Class; type Handle is access all Class; end Package_1; package Package_2 is type Instance is tagged null record; subtype Class is Instance'Class; type Handle is access all Class; end Package_2; with Package_1; with Package_2; generic Max_Fred : in Fred := Fred'Last; package Package_1.Classwide_Allocator is type Descriptor is record Field_1 : Package_1.Handle; Field_2 : Package_2.Handle; end record; function Get (Package_1 : in Package_1.Class; F2 : in Package_2.Class ) return Descriptor; end Package_1.Classwide_Allocator; package body Package_1.Classwide_Allocator is function Get (Package_1 : in Package_1.Class; F2 : in Package_2.Class ) return Descriptor is begin return (Field_1 => new Package_1.Class'(Package_1), Field_2 => new Package_2.Class'(F2) ); end Get; end Package_1.Classwide_Allocator; ---- The above complains on the declaration of Get about an attempt to use Package_1 before the child package is complete. Obviously its confusing Package_1 the parameter with Package_1 the package. Is this what its supposed to do? I suspect so. But lets add one more wrinkle that my full program has. Package_1 (and thus its child) are actually themselves children of another package: ---- package T is Global : constant := 3; end T; generic type Fred is (<>); package T.Package_1 is type Instance is tagged record Fred_Field : Fred := Fred'First; end record; subtype Class is Instance'Class; type Handle is access all Class; end T.Package_1; package Package_2 is type Instance is tagged null record; subtype Class is Instance'Class; type Handle is access all Class; end Package_2; with T.Package_1; with Package_2; generic Max_Fred : in Fred := Fred'Last; package T.Package_1.Classwide_Allocator is type Descriptor is record Field_1 : T.Package_1.Handle; Field_2 : Package_2.Handle; end record; function Get (Package_1 : in T.Package_1.Class; F2 : in Package_2.Class ) return Descriptor; end T.Package_1.Classwide_Allocator; package body T.Package_1.Classwide_Allocator is function Get (Package_1 : in T.Package_1.Class; F2 : in Package_2.Class ) return Descriptor is begin return (Field_1 => new T.Package_1.Class'(Package_1), Field_2 => new Package_2.Class'(F2) ); end Get; end T.Package_1.Classwide_Allocator; with T.Package_1; with Package_2; with T.Package_1.Classwide_Allocator; procedure Test is package P1 is new T.Package_1 (Integer); package Allocator is new P1.Classwide_Allocator; Field_1 : P1.Instance; Field_2 : Package_2.Instance; Descriptor : Allocator.Descriptor; begin Descriptor := Allocator.Get (Field_1, Field_2); end Test; ---- Compiling this with gnat 3.12p now gets the same results I get in my actual code, namely: gcc -c -Ic:/Development/Classwide_Allocator/ -I./ -g -gnatq -I- c:/Development/Classwide_Allocator/test.adb raised TYPES.UNRECOVERABLE_ERROR : comperr.adb:88 gnatmake: "c:/Development/Classwide_Allocator/test.adb" compilation error Compilation exited abnormally with code 4 at Tue Dec 28 11:57:59 I'll forwarding this message along to report@gnat.com -- T.E.D. Home - mailto:dennison@telepath.com Work - mailto:dennison@ssd.fsi.com WWW - http://www.telepath.com/dennison/Ted/TED.html ICQ - 10545591