From: Ted Dennison <dennison@telepath.com>
Subject: Re: allocators for classwide types?
Date: 1999/12/28
Date: 1999-12-28T00:00:00+00:00 [thread overview]
Message-ID: <3868FB86.4126D0E6@telepath.com> (raw)
In-Reply-To: 3868E1B4.D5F6A23C@telepath.com
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
next prev parent reply other threads:[~1999-12-28 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-12-28 0:00 allocators for classwide types? Ted Dennison
1999-12-28 0:00 ` Robert A Duff
1999-12-28 0:00 ` Ted Dennison
1999-12-28 0:00 ` Ted Dennison [this message]
2000-01-06 0:00 ` Robert A Duff
2000-01-07 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox