comp.lang.ada
 help / color / mirror / Atom feed
* Elaboration circularity
@ 2000-02-02  0:00 Frode Tenneboe
  2000-02-02  0:00 ` Matthew Heaney
  2000-02-02  0:00 ` Jeff Carter
  0 siblings, 2 replies; 7+ messages in thread
From: Frode Tenneboe @ 2000-02-02  0:00 UTC (permalink / raw)


I am currently looking into some legacy code which is heavily nested
with cirular dependencies. Compiling with gnat give the following message:

gnatbind -x client.ali
error: elaboration circularity detected
info:    "edhipc (body)" must be elaborated before "edhipc (body)"
info:       reason: Elaborate_All probably needed in unit "edhipc (body)"
info:       recompile "edhipc (body)" with -gnatwl for full details
info:          "edhipc (body)"
info:             is needed by its spec:
info:          "edhipc (spec)"
info:             which is withed by:
info:          "edhipclog (spec)"
info:             which is withed by:
info:          "edhipc (body)"
gnatmake: *** bind failed.
*** Error code 4
make: Fatal error: Command failed for target `client'

As you can see edhipc.adb is referring back to itself. So - I have
to unroll this mess. Are there any handy tricks when doing this?
The exact approach depends of course on the actual software, but
is it generally better to move the code out into new package(s) or
remove the circularity?

 -Frode

-- 
^ Frode Tenneb�                    | email: ft@edh.ericsson.se      ^
| Ericsson Radar AS. N-1788 Halden |                                |
| Phone: +47 69 21 41 47           | Frode@IRC                      |
| with Standard.Disclaimer; use Standard.Disclaimer;                |




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Elaboration circularity
  2000-02-02  0:00 Elaboration circularity Frode Tenneboe
@ 2000-02-02  0:00 ` Matthew Heaney
  2000-02-02  0:00 ` Jeff Carter
  1 sibling, 0 replies; 7+ messages in thread
From: Matthew Heaney @ 2000-02-02  0:00 UTC (permalink / raw)


In article <949502026.152029@edh3> , Frode Tenneboe 
<ft@alne.edh.ericsson.se>  wrote:

Did you try doing as GNAT suggested?

The body of edhipc looks something like this:

with edhipclog;
package body edhipc is


Change that by adding a pragma Elaborate_All:

with edhipclog;
pragma Elaborate_All (edhipclog);
package body edhipc is


Make sure the spec of edhipc doesn't have a categorization pragma (in
other words, don't force immediate elaboration of the body).

I think you want to the elaboration order to be:

edhipc (spec)
edhipclog (spec)
edhipclog (body)
edhipc (body)



> I am currently looking into some legacy code which is heavily nested
> with cirular dependencies. Compiling with gnat give the following message:
>
> gnatbind -x client.ali
> error: elaboration circularity detected
> info:    "edhipc (body)" must be elaborated before "edhipc (body)"
> info:       reason: Elaborate_All probably needed in unit "edhipc (body)"
> info:       recompile "edhipc (body)" with -gnatwl for full details
> info:          "edhipc (body)"
> info:             is needed by its spec:
> info:          "edhipc (spec)"
> info:             which is withed by:
> info:          "edhipclog (spec)"
> info:             which is withed by:
> info:          "edhipc (body)"
> gnatmake: *** bind failed.
> *** Error code 4
> make: Fatal error: Command failed for target `client'




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Elaboration circularity
  2000-02-02  0:00 Elaboration circularity Frode Tenneboe
  2000-02-02  0:00 ` Matthew Heaney
@ 2000-02-02  0:00 ` Jeff Carter
  2000-02-05  0:00   ` Robert Dewar
  1 sibling, 1 reply; 7+ messages in thread
From: Jeff Carter @ 2000-02-02  0:00 UTC (permalink / raw)


I've encountered similar problems with legacy code. I eliminated the
circularity using a child package. I don't know if it will work for you,
but here's how it worked for me:

There are 2 packages, A and B. The spec of A has some type declarations
and some operations. The spec of B has "with A;" and references the type
declarations in A. The body of B also references the type declarations
in A. The body of A has "with B;", "pragma Elaborate (B);" (this was
Ada-83 legacy code), and calls the operations of B during elaboration.
Thus B has to be elaborated before A. Hence the circularity: The body of
each package depends on the spec of the other.

I moved the operations of A, including the elaboration that calls B,
into a child package, A.Operations. This allows B to "with A;" and the
body of A.Operations to "with B;" without a circularity. The unit which
called the operations in A had to also be modified to "with
A.Operations;".

HTH.

-- 
Jeff Carter
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Elaboration circularity
  2000-02-02  0:00 ` Jeff Carter
@ 2000-02-05  0:00   ` Robert Dewar
  2000-02-07  0:00     ` Frode Tenneboe
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Dewar @ 2000-02-05  0:00 UTC (permalink / raw)


Be sure to read the chapter in the GNAT users guide here. I am
always surprised how many people run into trouble with
elaboration and have NOT read this chapter, which is entirely
devoted to explaining how to deal with problems like this.
It can still be tricky, since a lot of legacy code is flawed
wrt elaboration.

The unique optional static approach to elaboration in GNAT
is designed to ensure that new applications are not flawed
in this manner.

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Elaboration circularity
  2000-02-05  0:00   ` Robert Dewar
@ 2000-02-07  0:00     ` Frode Tenneboe
  2000-02-07  0:00       ` Larry Kilgallen
  2000-02-07  0:00       ` Robert Dewar
  0 siblings, 2 replies; 7+ messages in thread
From: Frode Tenneboe @ 2000-02-07  0:00 UTC (permalink / raw)


Robert Dewar <robert_dewar@my-deja.com> wrote:
: Be sure to read the chapter in the GNAT users guide here. I am
: always surprised how many people run into trouble with
: elaboration and have NOT read this chapter, which is entirely
: devoted to explaining how to deal with problems like this.

I have read this chapter and it is informative and helpful.

: It can still be tricky, since a lot of legacy code is flawed
: wrt elaboration.

Tell me about it! This piece of lagacy code must be the most
ugly coded and designed piece of software ever written! There
were four separate circularities of which one was very tricky
indeed. However, I think I have found all now and just have
to solve the other problems realted to design flaws!

: The unique optional static approach to elaboration in GNAT
: is designed to ensure that new applications are not flawed
: in this manner.

Please elaborate (!) or are you referring to the static
pragma elaborate*?

 -Frode
-- 
^ Frode Tenneb�                    | email: ft@edh.ericsson.se      ^
| Ericsson Radar AS. N-1788 Halden |                                |
| Phone: +47 69 21 41 47           | Frode@IRC                      |
| with Standard.Disclaimer; use Standard.Disclaimer;                |




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Elaboration circularity
  2000-02-07  0:00     ` Frode Tenneboe
  2000-02-07  0:00       ` Larry Kilgallen
@ 2000-02-07  0:00       ` Robert Dewar
  1 sibling, 0 replies; 7+ messages in thread
From: Robert Dewar @ 2000-02-07  0:00 UTC (permalink / raw)


In article <949922875.616391@edh3>,
  Frode Tenneboe <ft@alne.edh.ericsson.se> wrote:
> Robert Dewar <robert_dewar@my-deja.com> wrote:
> Please elaborate (!) or are you referring to the static
> pragma elaborate*?

No, I am not referring to pragma Elaborate, but rather to the
static elaboration analysis performed by GNAT in default mode.
See the chapter in the GNAT user's guide for details. We find
that quite a bit of our support effort for customers moving
large legacy code involves help with cleaning up elaboration
problems.

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Elaboration circularity
  2000-02-07  0:00     ` Frode Tenneboe
@ 2000-02-07  0:00       ` Larry Kilgallen
  2000-02-07  0:00       ` Robert Dewar
  1 sibling, 0 replies; 7+ messages in thread
From: Larry Kilgallen @ 2000-02-07  0:00 UTC (permalink / raw)


In article <949922875.616391@edh3>, Frode Tenneboe <ft@alne.edh.ericsson.se> writes:

> Tell me about it! This piece of lagacy code must be the most
> ugly coded and designed piece of software ever written!

Although Ada has sufficient low level constructs to do useful
programs, it lacks some of the constructs required to make a
true contender for "most ugly coded and designed piece of software".

You may have to switch languages to win the award.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2000-02-07  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-02  0:00 Elaboration circularity Frode Tenneboe
2000-02-02  0:00 ` Matthew Heaney
2000-02-02  0:00 ` Jeff Carter
2000-02-05  0:00   ` Robert Dewar
2000-02-07  0:00     ` Frode Tenneboe
2000-02-07  0:00       ` Larry Kilgallen
2000-02-07  0:00       ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox