comp.lang.ada
 help / color / mirror / Atom feed
From: "Thierry Lelegard" <lelegard@club-internet.fr>
Subject: Re: pragma Elaborate (Comp. Unit) question.
Date: 1999/05/22
Date: 1999-05-22T20:55:52+00:00	[thread overview]
Message-ID: <7i75ko$6km$1@front3.grolier.fr> (raw)
In-Reply-To: 37458C65.3393@pipeline.com

>   That is, if the compiler knows what the elaboration order needs to be
> why can't it make the relavant deterministic change and proceed with a
> warning?
> 
>   Is it because elaboratation is by definition non-deterministic and if
> so why is it that way?

The correct order of elaboration is deterministic but many
cases cannot be detected during compilation, not even during
link. The developer is the only one to know (sometimes he does
even know :-))

Example:
1) package A ...
2) with A; package body B ...
3) with B; package body C ...

Let's assume that B does not call any subprogram of A
during its elaboration. So, the author of B thinks that B
does not need a pragma Elaborate (A).

C calls some subprograms of B during its elaboration. So,
the author of C adds a pragma Elaborate (B). However, he/she
does not know that the body of B references A (he/she may even
not know the existence of A). Let's assume that the subprogram
of B which is called during elaboration of C calls a subprogram
of A.

The following elaboration order is valid for the binder but
will raise a program_error during the elaboration of C:

spec A
spec B
spec C
body B (before body C because of pragma elaborate)
body C (elab: calls B, which in turn calls A)
body A (no pragma told me to elaborate sooner)

In Ada 95, the pragma Elaborate_All fixes this: The author
of C would write pragma Elaborate_All (B). But you are using
Ada 83, too bad...

One brute force way of fixing the problem in Ada 83 is to add a
pragma elaborate for each "with" clause, everywhere. I even
once wrote a tool to do that automatically! But there can be
some circularity problems:

package A is...
package B is...
with B; package body A is...
with A; package body B is...

Although poor design, this is valid. Adding a pragma elaborate
everywhere would create a circularity which cannot be solved by
the binder. You have to know exactly which uses which during
elaboration and set only the required pragmas.

-Thierry
________________________________________________________
Thierry Lelegard, Paris, France
E-mail: lelegard@club-internet.fr






  reply	other threads:[~1999-05-22  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-21  0:00 pragma Elaborate (Comp. Unit) question Michael
1999-05-22  0:00 ` Thierry Lelegard [this message]
1999-05-22  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1999-05-24  0:00 Robert I. Eachus
1999-05-25  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