From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Elaboration in GNAT
Date: Fri, 4 Jan 2002 10:07:45 -0500
Date: 2002-01-04T10:07:45-05:00 [thread overview]
Message-ID: <u3bh1tiuppk9c7@corp.supernews.com> (raw)
In-Reply-To: 1010151875.216658@edh3
"Frode Tenneboe" <ft@edh.ericsson.se> wrote in message
news:1010151875.216658@edh3...
> Robert Dewar <dewar@gnat.com> wrote:
> > If this message is not intelligible, I recommend reading
> > the entire chapter on elaboration issues in the users
> > guide. Elaboration is certainly a tricky issue, and
> > generally you should not turn on -gnatwl unless you know
> > what you are doing.
I'm not sure I agree with Robert's advice here. I always use -gnatwl.
If you don't know what you're doing, then the best way to learn is to write
some programs and submit them to the compiler!
> The code is legacy code with complex dependencies and need some time
> to grow..... The warning is removed by adding (in the above example):
>
> pragma Elaborate_Body(bar)
>
> in bar.ads.
>
> However, I'm still not totatlly sure if this is the "correct"
> approach. But at least it makes more sense than adding
> pragma Elaborate_All in all clients using package bar.
My advice is to always use a categorization pragma in a package declaration,
and to use the strongest categorization possible, ie
1) pragma Pure;
2) pragma Preelaborate;
3) pragma Elaborate_Body;
The one time you cannot use a categorization pragma (say, Elaborate_Body) is
when a package withs its own children, which means a client will have to use
pragma Elaborate_All (if it needs to call operations in that package during
its own elaboration).
However, I prefer to restructure the parent package by moving the
child-dependent stuff into a new child, and then have that new child with
its siblings. That makes it possible to say pragma Elaborate_Body in the
parent.
This comes up with you declare a "protocol class" (an abstract tagged type)
with a constructor to return a concrete type in the class:
package P is
pragma Elaborate_Body; --illegal
type T is abstract tagged limited null record;
procedure Op (O : access T) is abstract;
type T_Class_Access is access all T'Class;
function New_T (S: String) return T_Class_Access;
end;
package P.C is
type NT is new T with null record;
procedure Op (O : access NT);
end;
with P.C;
package body P is
function New_T (S : String) return T_Class_Acceess is
begin
return new P.C.NT;
end;
end;
You can't use pragma Elaborate_Body in P, because the body of P withs its
own child P.C. But the workaround is easy enough: simply declare the
constructor as a child of P:
function P.New_T (S : String) return T_Class_Access;
with P.C;
function P.New_T (S : String) return T_Class_Access is
begin
return new P.C.NT;
end;
Now you can use pragma Elaborate_Body for P, because the body of P no longer
withs any of its children.
next prev parent reply other threads:[~2002-01-04 15:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-28 12:34 Elaboration in GNAT Frode Tenneboe
2001-11-28 18:13 ` Mark Johnson
2001-11-29 3:44 ` Robert Dewar
2001-11-29 13:30 ` Stephen Leake
2001-11-28 19:25 ` Robert Dewar
2002-01-04 13:21 ` Frode Tenneboe
2002-01-04 15:07 ` Matthew Heaney [this message]
2002-01-05 0:43 ` Robert Dewar
2002-01-05 0:50 ` Robert Dewar
2002-01-07 17:22 ` Mark Johnson
2002-01-08 0:00 ` Robert Dewar
2002-01-10 21:54 ` Robert A Duff
2002-01-11 4:49 ` Robert Dewar
2002-01-11 13:35 ` Robert A Duff
2002-01-11 19:18 ` Robert Dewar
2002-01-16 11:48 ` Arnaud Charlet
2002-01-05 0:40 ` Robert Dewar
2002-01-07 13:28 ` Frode Tenneboe
2002-01-11 19:25 ` Robert Dewar
2001-11-29 13:13 ` Stephen Leake
2001-11-29 13:17 ` Stephen Leake
2001-11-30 12:44 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox